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 based on vrmlParser, easier to use. #10371

Closed
wants to merge 6 commits into from

Conversation

bartmcleod
Copy link
Contributor

This is my second version of a VRMLLoader based on VrmlParser.

It adheres to the interface of other loaders, but it does require libs/js/vrml.min.js and some controls, from the examples. It has limited support for lights, which is new. Therefore I have removed setting up default lighting.

I also re-added the improved house.wrl example.

@mrdoob
Copy link
Owner

mrdoob commented Dec 16, 2016

Looking good!

animation = new VrmlParser.Renderer.ThreeJs.Animation(debug);
animation.addClickSupport(camera, renderer);

var vrmlLoader = new THREE.VRMLLoader(new THREE.LoadingManager(), camera, controls, 'viewpoints', true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind explaining why the loader constructor requires these extra parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The controls, not 100% sure if still needed with the latest version.

camera and a viewpointsContainer id are needed to be able to present a list of ViewPoints that can be clicked to animate the camera to that ViewPoint and set properties such as field of view (currently not variable).

animation.addClickSupport(camera, renderer);

var vrmlLoader = new THREE.VRMLLoader(new THREE.LoadingManager(), camera, controls, 'viewpoints', true);
vrmlLoader.load('models/vrml/house.wrl');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the result gets added to the scene?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VrmlParser.Renderer.ThreeJs adds the nodes to the scene.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if I want to add things to specific object, or nowhere at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makc Thanks for commenting. It's good to get some discussion going I think.

First, if you want to add things to nowhere, I think you could try /dev/null

If you want to add things to a specific object, you could either add them to the VRML source file or call scene.getObjectByName and use its original name in the VRML file as the argument, if it has a name. If it does not have a name, give it one. After that, you can add objects to the object you get back.

<script src="js/libs/vrml.min.js"></script>

<script src="js/loaders/VRMLLoader.js"></script>
<script src="js/renderers/Projector.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is Projector used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in VrmlParser.Renderer.ThreeJs.Animation to add support for clicks to trigger a TouchSensor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes zero sense :S

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makc please specify "this" and where did I not make sense? I am very willing to clarify things or to program it better if you give me any pointers as to where exactly you suffered from brain fade.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noticed the fade somewhere around touch sensor, but I'm affraid it happened well before. My brain keeps telling me that parsers job is to parse data and just give it back to calling code, neither to add it to random scene nor to do stuff with camera I did not ask it for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makc Okay, now I'm getting it and I totally agree, but this is just an example. You can use all of the components separately. This example is just trying to demonstrate that you can load a VRML file using Three. If for example you would want to just get back the tree, you can use the vrmlParser from the VrmlParser project. And it is up to you if you want to use the ThreeJs renderer that it offers and if you want animation support or not. The whole VrmlParser by the way is somewhat experimental and needs improvement, but it is better than what we had as a Vrml example in three so far. As it improves, I will also update the example here.

It also won't do stuff with the camera, unless your VRML file specifies ViewPoint. In that case, if you click one of the ViewPoints, the camera will go there, if you specified a container id for the ViewPoints list.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 6, 2017

Closing, since #12055 has changed some core components of the existing VRMLLoader.

@bartmcleod I respect your work at the loader but the discussion of this PR highlighted some basic problems of your approach. First, the implementation of loaders should be generally as lean as possible. Many dependencies to other files are undesirable. It's also important that the loaders of three.js follow some common rules, so their usage is consistent for users. For example a loader does not add objects to the scene. It also provides a common interface like a constructor and .load() method with identical parameters. Check GLTFLoader, FBXLoader or ColladaLoader2 for more information.

@Mugen87 Mugen87 closed this Sep 6, 2017
@makc makc mentioned this pull request Sep 22, 2017
2 tasks
@bartmcleod
Copy link
Contributor Author

@Mugen87 I have created a new PR that addresses your issues with this one: #13402

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

Successfully merging this pull request may close these issues.

None yet

5 participants