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

VRMLLoader problem suspected #12209

Closed
2 tasks done
Sonander opened this issue Sep 15, 2017 · 26 comments
Closed
2 tasks done

VRMLLoader problem suspected #12209

Sonander opened this issue Sep 15, 2017 · 26 comments
Labels

Comments

@Sonander
Copy link

As discussed here this file cube.wrl.zip contains a single solid cube and loads fine in other tools, e.g. view3dscene, FreeCAD, sketchfab.

However VRMLLoader shows an empty scene. Example here

Three.js version

  • r87
Browser

Chrome + Safari tested and behave the same.

OS
  • macOS
@mrdoob mrdoob added the Bug label Sep 15, 2017
@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 15, 2017

This is primarily a parsing error and can maybe fixed in the .getTree() function. The problematic file contains patterns like that:

appearance 
Appearance {
   material 
   Material {
      diffuseColor 0.8 0.8 0.8
   }
}

But the loader expects it in this way:

appearance Appearance {
   material Material {
      diffuseColor 0.8 0.8 0.8
   }
}

So the break lines after appearance or material are not correctly processed and the actual content of this section (material with diffuse color) is not respected. This happens at other parts of the file too (geometry, coord etc.). I'm not sure how we can fix this problem in a generic way. Any ideas?

@makc
Copy link
Contributor

makc commented Sep 22, 2017

I had spent some time in VRMLLoader before, and I don't think it can be fixed. You need to replace current method with tokenizer or some other way that would treat line breaks like other whitespace.

@makc
Copy link
Contributor

makc commented Sep 22, 2017

Perhaps someone needs to help the author of #10371 to make 3rd PR if his parsing method is better.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 22, 2017

@makc Maybe there is a way to detect the above pattern with a new regular expression. Have you considered something like this?

@makc
Copy link
Contributor

makc commented Sep 22, 2017

@Mugen87 see for yourself, I mean it's not impossible, but any "fix" like that is duct tape. It will only make things worse.

#5391
#8282 (comment)
#9514 (probably)

All those are bad parser issues. In addition, this parser has performance problems

#5719

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 22, 2017

At least, it is now clear why X3D was based on XML. Way easier to parse 😉

Anyway, with @makc's comment in mind the options are:

  • Try to patch VRMLLoader
  • Rewrite the whole parsing logic
  • Use some external lib like VRMLParser
  • Leave it as it is

Considering that VRML is over twenty years old and has an official successor (X3D), i am not sure it makes sense to invest a lot of time in this standard.

Also see:
https://github.com/jonaskello/three-x3d-loader
https://www.x3dom.org/vrmlx3d-to-x3dom-online-converter/ (VRML -> X3D converter)

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 22, 2017

@mrdoob It's actually tempting to kill VRMLLoader and try to introduce a X3DLoader based on the above project instead. Because Blender supports X3D exports, it should be easy to provide new models. And old .wrl files could be converted to .x3d.

@makc
Copy link
Contributor

makc commented Sep 22, 2017

xml is only "easier to parse" in the browser. current collada loader does not work under node, for example.

the project I worked in needed wrl files because - strangely enough - 3D printing software was using it.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 22, 2017

node.js users can try to work with https://www.npmjs.com/package/xmldom or similar projects.

I have not tested it but it is more or less a replacement for the browsers native DomParser API.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 22, 2017

I also think that three.js is primarily designed for the browser. Not node.js.

@makc
Copy link
Contributor

makc commented Sep 22, 2017

It's just sometimes people ask for server-side rendering for fall-back or whatever, and I then have to convert their daes into jsons.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 22, 2017

I see. May i ask how you are performing this conversion?

@makc
Copy link
Contributor

makc commented Sep 22, 2017

I save object.toJSON() result.

@mrdoob
Copy link
Owner

mrdoob commented Sep 22, 2017

@mrdoob It's actually tempting to kill VRMLLoader and try to introduce a X3DLoader based on the above project instead.

You would be surprised. There are still institutions out there using VRML beacuse it's a ISO standard. I know CERN is still using it, I don't know if that's the reason though.

@mrdoob
Copy link
Owner

mrdoob commented Sep 22, 2017

I think doing a X3DLoader would be a good start.
Maybe at some point there will be a javascript open source VRML to X3D converter...

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 23, 2017

There are still institutions out there using VRML beacuse it's a ISO standard. I know CERN is still using it, I don't know if that's the reason though.

Interesting. I'm actually curious why they work with VRML because X3D is also a ISO standard. Maybe they using some kind of tool/library that only produces VRML (see @makc #12209 (comment)).

Maybe at some point there will be a javascript open source VRML to X3D converter...

It looks like meshlab (open-source 🙌) can do this conversion, too: https://stackoverflow.com/questions/14849593/vrml-to-x3d-conversion

@Sonander
Copy link
Author

I am interested in a reader for VRML because I have tools that write it. I have nothing that writes x3d so cannot see the use of a reader for it yet.

My main goal is to visualise STEP in a browser, but there is nothing I can find to do that. But there are converters from STEP to VRML.

@Sonander
Copy link
Author

Probably the most widely used open source CAD tool is FreeCAD, that writes VRML but not X3D.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 23, 2017

Is it possible to produce STL with FreeCAD as well? This might be a good alternative...

see https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/STLLoader.js

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 23, 2017

also see #7125

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 23, 2017

This first PR does not solve the parsing problems but at least the faces of the cube are drawn correctly now.

@Sonander
Copy link
Author

Yeh, STL is an option and we have that already as a place holder until we can get a full colour flow working.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 23, 2017

I've added a commit to the PR that should solve the parsing problems with VRMLLoader. It's just a simple fix and not a complete re-write. Still, hope it helps...

@Sonander
Copy link
Author

Brillant! It works not just with the cube but with FreeCAD output of our more complex parts.
Thank you Mugen87.

mrdoob added a commit that referenced this issue Sep 23, 2017
@saujanpromech
Copy link

How can we convert STEP file to VRML so that we can load selected STEP file in browser

@Mugen87
Copy link
Collaborator

Mugen87 commented May 17, 2018

You should not use VRML anymore. Instead, try to convert your STEP files to glTF. Read #7125 for more information.

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

No branches or pull requests

5 participants