jscad / io

DEPRECATED : Input Output handling for JSCAD (see the link below)
https://github.com/jscad/OpenJSCAD.org/tree/V2/packages
34 stars 13 forks source link

svg deserialize not working? #57

Closed jtoy closed 4 years ago

jtoy commented 6 years ago

I was testing svg-deserializer and I get an error on this svg file: https://cl.ly/1G1A382X2l3x I also tried other SVGs.

require('@jscad/csg');
const svgDeSerializer = require('@jscad/svg-deserializer')

var fs = require('fs');
const rawData = fs.readFileSync('./puzzle-piece-outline.svg')
const cagData = svgDeSerializer.deserialize(rawData, undefined, {output: 'csg'})

I get this output:

node svgDeserialiser.js 
/Users/jtoy/Downloads/vishnu/node_modules/@jscad/svg-deserializer/index.js:314
      if ('id' in obj) {
               ^

TypeError: Cannot use 'in' operator to search for 'id' in undefined
    at SAXParser.parser.onopentag (/Users/jtoy/Downloads/vishnu/node_modules/@jscad/svg-deserializer/index.js:314:16)
    at emit (/Users/jtoy/Downloads/vishnu/node_modules/sax/lib/sax.js:624:35)
    at emitNode (/Users/jtoy/Downloads/vishnu/node_modules/sax/lib/sax.js:629:5)
    at openTag (/Users/jtoy/Downloads/vishnu/node_modules/sax/lib/sax.js:825:5)
    at SAXParser.write (/Users/jtoy/Downloads/vishnu/node_modules/sax/lib/sax.js:1292:13)
    at createSvgParser (/Users/jtoy/Downloads/vishnu/node_modules/@jscad/svg-deserializer/index.js:370:10)
    at deserializeToCSG (/Users/jtoy/Downloads/vishnu/node_modules/@jscad/svg-deserializer/index.js:59:3)
    at Object.deserialize (/Users/jtoy/Downloads/vishnu/node_modules/@jscad/svg-deserializer/index.js:37:77)
    at Object.<anonymous> (/Users/jtoy/Downloads/vishnu/svgDeserialiser.js:6:33)
    at Module._compile (module.js:660:30)
z3dev commented 6 years ago

@jtoy Please attach the SVG file to this issue. Tanks

jtoy commented 6 years ago

github doesnt allow me up to upload SVGS. that link I gave is basically a direct download link

jtoy commented 6 years ago

I also tried with multiple SVGs and got the same error. node -v v9.3.0

 cat package-lock.json 
{
  "requires": true,
  "lockfileVersion": 1,
  "dependencies": {
    "@jscad/csg": {
      "version": "0.5.3",
      "resolved": "https://registry.npmjs.org/@jscad/csg/-/csg-0.5.3.tgz",
      "integrity": "sha512-yEnA8Whd+MaEwMb0H9YzcAUiswEpXO60fa+zNFgec+RyaqorAmbW5uwK9+FGBBKnxkzJ+TGlwjv8R1X180mMlg=="
    },
    "@jscad/svg-deserializer": {
      "version": "0.4.1",
      "resolved": "https://registry.npmjs.org/@jscad/svg-deserializer/-/svg-deserializer-0.4.1.tgz",
      "integrity": "sha512-Lrb5Z0qKKyP7TIn0wZeXJrgZpZEEE9IkwxS7IrxoFQvrjYBjeG7gMPbnz5EEAc4oTvBoxjT4jMTkcMfJ1DYKZg==",
      "requires": {
        "@jscad/csg": "0.3.6",
        "sax": "1.2.4"
      },
      "dependencies": {
        "@jscad/csg": {
          "version": "0.3.6",
          "resolved": "https://registry.npmjs.org/@jscad/csg/-/csg-0.3.6.tgz",
          "integrity": "sha512-GoUXhTwO0L+Cxba8VfFFLGm+ECd0xZKoIAPpeUYsDiCVsIZ6XK+3GLgBgn5waeumQNh+H6WsHjMMRKXBrDBreA=="
        }
      }
    },
    "better-log": {
      "version": "1.3.3",
      "resolved": "https://registry.npmjs.org/better-log/-/better-log-1.3.3.tgz",
      "integrity": "sha1-IZocA4Oo+cRBaJfto6z5tNaZDo8="
    },
    "g": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/g/-/g-2.0.1.tgz",
      "integrity": "sha1-C1lj69DKcOO8jGdmk0oCGCHIuFc="
    },
    "jscad": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/jscad/-/jscad-1.1.0.tgz",
      "integrity": "sha1-5Oq2MQm5SVUC7cuL7ceW2ZYtia0=",
      "requires": {
        "better-log": "1.3.3",
        "g": "2.0.1"
      }
    },
    "sax": {
      "version": "1.2.4",
      "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
      "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
    }
  }
}
jtoy commented 6 years ago

I see I gave the wrong link before, here are the SVGs I tested: https://cl.ly/3R2i2N3n0D2z https://cl.ly/0s0G0f1r3x3h

z3dev commented 5 years ago

@jtoy Can you try again?

z3dev commented 4 years ago

Fixed in V1.