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?

- 149
- 1
- 1
- 13
2 Answers
Just to be clear - you want to add this to the scene or to an OBJ file that is produced by Three.js?
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.
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.
To export an OBJ of your scene, you could try Exporting Threejs Scene to Obj Format

- 1
- 1

- 137
- 6
-
I am trying to add it to the scene, but only on the obj. I have a plane at the middle of the obj but I don't understand how to do this for the entire obj. I can read the x,y,z coordinates and save the positions that way, is that correct? – RPBruiser Feb 02 '16 at 00:45
-
I'm still confused as to what you mean by 'only on the OBJ' - You may maintain the global scene and export a subset of the elements by ID, though the code above will support by default exporting the entire scene. The x,y,z coordinates that you are recording in screen space will not necessarily correlate to the scene space. See http://stackoverflow.com/questions/13055214/mouse-canvas-x-y-to-three-js-world-x-y-z – Michael S Bergin Feb 02 '16 at 15:00
-
I mean something like what [this example](http://www.moczys.com/webGL/Experiment_02_V05.html) does but on an OBJ rather than a geometry. – RPBruiser Feb 02 '16 at 16:25
-
An OBJ is geometry - I'm sorry but I still don't quite understand your problem. – Michael S Bergin Feb 05 '16 at 02:13
-
Is it? I assumed that geometry was THREE.Geometry, I did not think that this included OBJs. I am new to three.js and am still really confused by how to do much of it. But what you are saying is that an obj is geometry and can be selected just the same as if I were to have made a sphere and added to the scene? – RPBruiser Feb 05 '16 at 19:54
-
Okay so I believe I have found a solution that should work, however, it is not detecting a collision with the OBJ file. So I guess my real question is how can I detect a collision with the OBJ. – RPBruiser Feb 05 '16 at 22:30
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.

- 284
- 2
- 8