Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG Loader: incorrect rendering in complex SVGs #21330

Open
dciug opened this issue Feb 21, 2021 · 10 comments
Open

SVG Loader: incorrect rendering in complex SVGs #21330

dciug opened this issue Feb 21, 2021 · 10 comments

Comments

@dciug
Copy link

dciug commented Feb 21, 2021

Describe the bug

I'm trying to use SVGLoader to load a more complex SVG generated from Illustrator

I get hundreds of warnings:

  • THREE.Color: Unknown color url(#linear-gradient-26)
  • SVGLoader: url access in attributes is not implemented.
  • SVGLoader: Elliptic arc or ellipse rotation or skewing is not implemented.

And a few errors:

  • THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.

To Reproduce

It occurs when I'm trying to load a complex svg, the code is the same. Unfortunately, I cannot share this SVG. I'll just upload parts of it, I suppose.

This is how the browser renders it:
image

This is how Three.js renders it:
image

Expected behavior

It should look exactly the same as the browser would render it natively, but the colors are undefined and the z-order of the elements seems wrong. The wireframe visualization is correct, though.
The SVG also contains subtle elements with small opacity values. SVGLoader seems to ignore the shapes that are supposed to be visible through the transparent layers.

Platform:

  • Device: Desktop
  • OS: Windows
  • Browser: Chrome, Firefox, Edge
  • Three.js version: main branch
@dciug dciug changed the title SVG Loader SVG Loader: incorrect rendering in complex SVGs Feb 21, 2021
@yomboprime
Copy link
Collaborator

Sorry, I don't have anything useful to apport at this moment, and can't reproduce without the svg file.

@dciug
Copy link
Author

dciug commented Feb 22, 2021

I suppose most of the problems arise from the warnings, as Three.js cannot link the defs using the url.

@yomboprime
Copy link
Collaborator

Yes, there are lots of SVG features not implemented in the parser, like gradients, correct painting order, urls...

@yomboprime
Copy link
Collaborator

But, now that I think of it, you only want an image of the SVG, right? For that use case you can just convert the SVG to canvas and load into a texture (I think there's an example of that in the repo)

@dciug
Copy link
Author

dciug commented Feb 22, 2021

The first version used SVG interactivity using Snap.svg to click on the elements. Each click would get the coordinates of the element, convert them into screen-space and show some contextual information at that point. However, the performance was quite poor and unstable, which is why I looked into Three.js. I could convert it into canvas, but I would still need to get the coordinates of the elements. Can I do that in Canvas?

@mrdoob
Copy link
Owner

mrdoob commented Feb 22, 2021

Closing this. We can reopen when the svg file is provided.

@mrdoob mrdoob closed this as completed Feb 22, 2021
@dciug
Copy link
Author

dciug commented Feb 22, 2021

Here's a stripped down version of the svg: three.svg.zip

All I'm doing is just trying out the https://threejs.org/examples/#webgl_loader_svg demo

@yomboprime
Copy link
Collaborator

I've spent some time on this. It seems some bugs have been solved with previous PRs, and the errors about NaN values in the console are gone.

The mentioned warnings are still shown. These are the features that need to be implemented in SVGLoader to address them:

  • Textures
  • URL access in attributes
  • URL-encoded PNG textures
  • Fill gradients
  • Elliptic arc or ellipse rotation or skewing
  • Paint order

@iambarnaby
Copy link

This still doesn't seem to work. Unless I'm missing something.

@LeviPesin
Copy link
Contributor

Because not all points of #21330 (comment) are solved yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants