How can I have a custom default scene in the three.js editor?

天涯浪子 提交于 2019-12-10 11:48:52

问题


I'm trying to use the Three.js editor to have the population participate in the town planning process. For that, I would like the editor to load with a 3D Version of the town, without the user having to load it manually. Clicking on "New" should also load that default model again.

I already copied the code on our server, it works. Which part of that code should I modify to do have the town model already loaded on startup?


回答1:


The source code for the threejs editor is available here , you can just download it from it here, add your code to display the default model at appropriate place and host it.

Update 1: Adding a custom model in the Editor's Scene

After reviewing the code of the Editor.js I found that you can add custom objects in the scenevariable defined in the Editor using the addObject() function

I am assuming that you need to add an object which is exported out of blender in .obj format, but using this addObject() function you can add any object/mesh into the editor.

So in index.html add the following lines of code to add a model manually.

var manager = new THREE.LoadingManager();

var loader = new THREE.OBJLoader( manager );
   loader.load( '../obj/male02/male02.obj', function ( object ) {
   object.position.y =0;
   editor.addObject( object );// THIS WAY YOU CAN MANUALLY ADD ANY MESH/OBJECT3D IN THE EDITOR

});

I have made and hosted an example here you can visit it and look around line 123 to see the custom code.



来源:https://stackoverflow.com/questions/21862226/how-can-i-have-a-custom-default-scene-in-the-three-js-editor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!