如何在three.js编辑器中创建自定义默认场景? [英] How can I have a custom default scene in the three.js editor?
问题描述
我正在尝试使用Three.js编辑器让人们参与城镇规划过程。为此,我希望编辑器可以加载城镇的3D版本,而无需用户手动加载。单击新建也应再次加载该默认模型。
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?
推荐答案
Threejs的源代码您可以在此处使用该编辑器,只需在此处下载它,然后添加您的代码以在默认位置显示默认模型并将其托管。
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.
更新1:在编辑器场景中添加自定义模型
查看 Editor.js
的代码后,我发现您可以在中添加自定义对象场景
编辑器
中使用 addObject()
函数
After reviewing the code of the Editor.js
I found that you can add custom objects in the scene
variable defined in the Editor
using the addObject()
function
我假设您需要添加一个对象,该对象以 .obj
格式从搅拌机中导出,但是使用此 addObject()
函数,您可以在编辑器中添加任何对象/网格。
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.
因此在 index.html 强>添加关注ng代码行以手动添加模型。
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
});
我已经制作并托管了一个示例此处,您可以访问它并查看123行以查看自定义代码。
I have made and hosted an example here you can visit it and look around line 123 to see the custom code.
这篇关于如何在three.js编辑器中创建自定义默认场景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!