Three.js: SVGLoader

Created on 2 Mar 2018  路  27Comments  路  Source: mrdoob/three.js

Currently, SVGLoader only returns the nodes.

I hink it'll be a great improvement if the loader could convert svg nodes to THREE.Shape which could then be used by THREE.ShapeGeometry or THREE.ExtrudeGeometry. With that in place, adding svg support to the editor would make a few designers happy.

We happen to have some basic code already in webgl_geometry_extrude_shapes2:

https://github.com/mrdoob/three.js/blob/dev/examples/webgl_geometry_extrude_shapes2.html#L49-L389

Also, for reference, @jonobr1 has been tackling this same issue for two.js for a while now:

https://github.com/jonobr1/two.js/blob/dev/src/two.js#L798-L1475

Enhancement Loaders

Most helpful comment

I've implemented now the rotate and the scale also. There's only left the skew.

My implementation only supports orthonormal matrices for circles, ellipses and arcs. That's why I've not implemented skew. The rest of curves/paths work OK with any matrix.

Let me 1 more day to prepare the PR... 馃槈

All 27 comments

I'd be happy to translate the Two.js logic over.

@jonobr1 馃槏

@mrdoob I know this is still a WIP but I got some strange results trying to use the SVGLoader even though it works fine with the example tiger.svg.

Using the d3-threeD implementation from webgl_geometry_extrude_shapes2's example worked fine though.

Please, share the files that are giving you strange results.

Some examples I had issues with:

Updated with more examples/detail

@paulbrzeski After d82442aedc15d726b2bbf280ce93a98c093a8ebe, your files are starting to appear 馃榿

Not sure where SVGLoader is at with the styles but I noticed the current copy of SVG on the dev branch wasn't parsing the style attributes so I made some changes.

https://github.com/paulbrzeski/manifold/pull/3/files#diff-951105ef94046da2301be208fa86ff54R513

@paulbrzeski Would you like to do a PR with that improvement?

Following the example here, some shapes come out okay and some do not. This svg from google material design isn't formed correctly at the end. (threejs v93)

Also, this similar svg image is not constructed in the right way.

I can take a look at this. I recently fixed an issue with Two.js SVG parsing that might be related to this.

PR for partial fix for @iambumblehead's referenced SVGs here: https://github.com/mrdoob/three.js/pull/14276

I need some help from someone that knows the THREE.ShapePath and THREE.Path to vet how I'm accessing the initial x, y coordinate vector of a path.

Hello, I've implemented the transform node attribute (only translate and matrix, which are the ones Inkscape produces)

Would you like a PR with this?

@yomboprime yes please! 馃槉

I've implemented now the rotate and the scale also. There's only left the skew.

My implementation only supports orthonormal matrices for circles, ellipses and arcs. That's why I've not implemented skew. The rest of curves/paths work OK with any matrix.

Let me 1 more day to prepare the PR... 馃槈

@yomboprime it looks like this only uses the first transform:
var transformType = transformAttr.substr( 0, openParPos );
However, my SVG has two transforms, a translate and scale but only the transform is being applied:
<g transform="translate(0.000000,558.466321) scale(0.022383,-0.022383)" fill="#000000" stroke="none">

I hope I understood that right. Is that something that can be fixed?
Thanks

Can you share your svg file?

@mrdoob here it is. I tested removing the _translate_ and then the _scale_ works but when both transforms are present, is only executing the _translate_. So it appears is just doing the first transform when two are present.

c2fab75fbb234c1abf41c7f2669e1fa0_outer.bmp.zip

@mrdoob @yomboprime I think perhaps I should have commented that on 14418 instead. It is an issue with the implementation of transforms in SVG.

I implemented these changes that _seem_ to fix it. However, I am not familiar with the code and it is very naively implemented. I pretty much just changed all the places that return "transform" to return "transforms", a list of transforms, and then loop over it. I am not sure what the currentTransform and whether my changes handled that ok.

I think it should be better to compose the two transforms (or N of them) into one, inside the getNodeTransform function.

SVGLoader doesn't seem to color Path nodes correctly.

Here's a link to the whatsapp SVG file: https://www.flaticon.com/free-icon/whatsapp-logo_33447

And here's what trying to use it in the loader gets me:
image

It renders fine in Inkscape. This also only seems to be an issue with paths.

SVGLoader doesn't seem to color Path nodes correctly.

I've checked that this happens with versions previous to my modifications of transforms (8fcef653cff8394278437eda1494948c2947629b)

@yomboprime I'm still having these issues, even using the most recent version of three.js and your version of transforms

Closing. It's best to create a new issue if the latest SVGLoader is not able to correctly load a SVG file.

@yomboprime I'm still having these issues, even using the most recent version of three.js and your version of transforms

Ops, I missed this comment, sorry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danieljack picture danieljack  路  3Comments

ghost picture ghost  路  3Comments

akshaysrin picture akshaysrin  路  3Comments

scrubs picture scrubs  路  3Comments

clawconduce picture clawconduce  路  3Comments