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
Chrome + Safari tested and behave the same.
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?
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.
Perhaps someone needs to help the author of #10371 to make 3rd PR if his parsing method is better.
@makc Maybe there is a way to detect the above pattern with a new regular expression. Have you considered something like this?
@Mugen87 see for yourself, I mean it's not impossible, but any "fix" like that is duct tape. It will only make things worse.
https://github.com/mrdoob/three.js/issues/5391
https://github.com/mrdoob/three.js/issues/8282#issuecomment-191817784
https://github.com/mrdoob/three.js/issues/9514 (probably)
All those are bad parser issues. In addition, this parser has performance problems
At least, it is now clear why X3D
was based on XML. Way easier to parse :wink:
Anyway, with @makc's comment in mind the options are:
VRMLLoader
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)
@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
.
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.
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.
I also think that three.js
is primarily designed for the browser. Not node.js
.
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.
I see. May i ask how you are performing this conversion?
I save object.toJSON() result.
@mrdoob It's actually tempting to kill
VRMLLoader
and try to introduce aX3DLoader
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.
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...
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 https://github.com/mrdoob/three.js/issues/12209#issuecomment-331478564).
Maybe at some point there will be a javascript open source VRML to X3D converter...
It looks like meshlab (open-source :raised_hands:) can do this conversion, too: https://stackoverflow.com/questions/14849593/vrml-to-x3d-conversion
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.
Probably the most widely used open source CAD tool is FreeCAD, that writes VRML but not X3D.
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
also see #7125
This first PR does not solve the parsing problems but at least the faces of the cube are drawn correctly now.
Yeh, STL is an option and we have that already as a place holder until we can get a full colour flow working.
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...
Brillant! It works not just with the cube but with FreeCAD output of our more complex parts.
Thank you Mugen87.
How can we convert STEP file to VRML so that we can load selected STEP file in browser
You should not use VRML
anymore. Instead, try to convert your STEP files to glTF. Read https://github.com/mrdoob/three.js/issues/7125 for more information.