jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.63k stars 512 forks source link

SVG import should work for a logo example #460

Open WolfgangFahl opened 5 years ago

WolfgangFahl commented 5 years ago

Expected Behavior

SVG import should work

Actual Behavior

//
  // producer: OpenJSCAD.org 1.9.0 SVG Importer
  // date: Mon Aug 26 2019 11:14:38 GMT+0200 (Mitteleuropäische Sommerzeit)
  // source: BITPlanLogo2012FontLess.svg
  //
  function main(params) {
  var cag0 = new CAG();
    var cag1 = new CAG();
      var cag2 = new CAG();
        var cag3 = new CAG();
          var cag4 = new CAG();
        var cag30 = cag4;
        cag3 = cag3.union(cag30);
      var cag20 = cag3;
      cag20 = cag20.translate([5.644443999999999,-5.644443999999999]);
      cag2 = cag2.union(cag20);
    var cag10 = cag2;
    cag1 = cag1.union(cag10);
      var cag2 = new CAG();
        var cag3 = new CAG();
          var cag4 = new CAG();
        var cag30 = cag4;
        cag30 = cag30.translate([0,0]);
        cag3 = cag3.union(cag30);
      var cag20 = cag3;
      cag2 = cag2.union(cag20);
    var cag11 = cag2;
    cag11 = cag11.translate([342.05330639999994,-279.399978]);
    cag1 = cag1.union(cag11);
  var cag00 = cag1;
  cag00 = cag00.scale([0.29333,0.29333]);
  cag00 = cag00.translate([-47.977774,-10.1599992]);
  cag0 = cag0.union(cag00);
  return cag0;
}

does not show as grafik

Steps to Reproduce the Problem

  1. Drag and Drop http://wiki.bitplan.com/images/wiki/7/7a/BITPlanLogo2012FontLess.svg or try https://openjscad.org/#http://wiki.bitplan.com/images/wiki/7/7a/BITPlanLogo2012FontLess.svg

Specifications

gilboonet commented 5 years ago

To maximize compatibility, you could deep ungroup, unlink clones, add points (enough to keep your curves) and turn it to lines, then it should import correctly.

WolfgangFahl commented 5 years ago

@gilboonet - this is already the "fontless" version using no external references as the original would do. Further "simplifying" it would certainly be possible. And indeed i was already able to create an STL of the logo using other tools. I'd rather see the importer being improved and that's what my issue is about.

z3dev commented 5 years ago

@WolfgangFahl thanks. I’m looking at this now for V2. I’ll report back if a fix is possible for V1.

z3dev commented 5 years ago

@WolfgangFahl congradulations. you found a bug.

sadly, it's not an easy bug to fix because the support for 'defs' was intermixed with the support for 'groups'. the solution was to handle the 'defs' specifically.

the example SVG file includes this.

  <def>
    ...
    <g id='heureka0'>
      <g transform='translate(1335.6224155638808,423.01254844961903) rotate(29.5)'>
        <use xlink:href='#kopf0' />
      </g>
      <g transform='translate(0,0)'>
        <use xlink:href='#heurekabody' />
      </g>
    </g>
    ...
  </def>

the nesting of 'defs' causes the issues. you can fix this by replacing the 'use' with the SVG entity.

z3dev commented 4 years ago

V2 fixes most of the issues, except #523. I have never seen ‘mirror’ before in SVG files so I’m not sure when this will be totally supported.

@WolfgangFahl a simple question... what application produced the SVG?