如何在three.js中向obj文件添加一个点?

时间:2022-04-03 05:30:44

How can I add a point (when I say point I mean a sphere to show that this is where you clicked) to an obj file in three.js onClick? I want it to add to the obj file such that it rotates with it and I would also like to be able to read/save the data of where this point was placed. Is this possible in three.js, and if so how?

我怎么能在一个点上添加一个点(当我说点我的意思是一个球体来表明这是你点击的地方)到一个ob.文件中的onClick?我希望它添加到obj文件,使其随之旋转,我还希望能够读取/保存此点所在位置的数据。这有可能在three.js中,如果是这样,怎么样?

2 个解决方案

#1


0  

Just to be clear - you want to add this to the scene or to an OBJ file that is produced by Three.js?

只是要清楚 - 你想将它添加到场景或由Three.js生成的OBJ文件?

To add a point to the scene you will need to have a 'work plane' where you are intending the point (as the center of the sphere) to be placed. You would capture the relevant coordinates based on user mouse position within the scene and assign these values the appropriate X, Y or Z value, creating a vector and adding the Sphere to the scene.

要为场景添加一个点,您需要有一个“工作平面”,您可以在此处放置该点(作为球体的中心)。您将根据场景中的用户鼠标位置捕获相关坐标,并为这些值分配适当的X,Y或Z值,创建矢量并将球体添加到场景中。

To add this to an OBJ file would require that you are writing the file out... or procedurally creating an OBJ in memory, and then writing this out which would be more tedious.

要将其添加到OBJ文件中,需要将文件写出来......或者在程序中在内存中创建OBJ,然后将其写出来会更加繁琐。

To export an OBJ of your scene, you could try Exporting Threejs Scene to Obj Format

要导出场景的OBJ,可以尝试将Threejs场景导出为Obj格式

#2


0  

Hii you have to follow below steps to do what you want :-

你必须按照以下步骤做你想做的事:

when mouse click on the object :- add a child mesh in object . when mouse click else on screen ,remove that mesh object

当鼠标单击对象时: - 在对象中添加子网格。当鼠标在屏幕上单击否则,删除该网格对象

when mouse interact with now mesh (mouse down event ) ,rotate the object or else you want

当鼠标与现在网格(鼠标按下事件)交互时,旋转对象或您想要的其他内容

Hope it helps you.

希望它能帮到你。

#1


0  

Just to be clear - you want to add this to the scene or to an OBJ file that is produced by Three.js?

只是要清楚 - 你想将它添加到场景或由Three.js生成的OBJ文件?

To add a point to the scene you will need to have a 'work plane' where you are intending the point (as the center of the sphere) to be placed. You would capture the relevant coordinates based on user mouse position within the scene and assign these values the appropriate X, Y or Z value, creating a vector and adding the Sphere to the scene.

要为场景添加一个点,您需要有一个“工作平面”,您可以在此处放置该点(作为球体的中心)。您将根据场景中的用户鼠标位置捕获相关坐标,并为这些值分配适当的X,Y或Z值,创建矢量并将球体添加到场景中。

To add this to an OBJ file would require that you are writing the file out... or procedurally creating an OBJ in memory, and then writing this out which would be more tedious.

要将其添加到OBJ文件中,需要将文件写出来......或者在程序中在内存中创建OBJ,然后将其写出来会更加繁琐。

To export an OBJ of your scene, you could try Exporting Threejs Scene to Obj Format

要导出场景的OBJ,可以尝试将Threejs场景导出为Obj格式

#2


0  

Hii you have to follow below steps to do what you want :-

你必须按照以下步骤做你想做的事:

when mouse click on the object :- add a child mesh in object . when mouse click else on screen ,remove that mesh object

当鼠标单击对象时: - 在对象中添加子网格。当鼠标在屏幕上单击否则,删除该网格对象

when mouse interact with now mesh (mouse down event ) ,rotate the object or else you want

当鼠标与现在网格(鼠标按下事件)交互时,旋转对象或您想要的其他内容

Hope it helps you.

希望它能帮到你。