1

I have a JSON model that is a box and I use the Three.JSONLoader in my project. I can see in the ThreeJS Editor that the pivot Point or origin is near the centre of the model in both the X and Z directions. In the ThreeJS Editor after loading the JSON model, rotating around the Y spins from near the centre as expected.

I need to find the position of the pivot. I have used a bounding box which gives me the min/max values so I can get the actual size (I think scale gives the same) and I was expecting that the mesh position would be the position of the pivot or origin but it isn't. In Unity, I Believe you use the transform.

How can I find (or calculate) the pivot?

I added some code

var cube = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.1, 0.1), 
                      new THREE.MeshBasicMaterial({ color: 0xff0000 }));

mesh.add(cube);

And I can see the box attached to the model at the pivot point. Obviously different places for different models but whether I use matrix or matrixWorld on either the model or the cube I have just added, the numbers are the same for position. So maybe the position is correct. In which case, turning this on its head, how do I calculate the distance from the position to the edge of the model? I thought the bounding box min/max could be used, but this doesn't seem to work either.

Soviut
  • 88,194
  • 49
  • 192
  • 260
  • I could be wrong, but it sounds like the mesh is translated off origin and the editor is allowing you to spin it as a child object offset to a parent origin. It's difficult to answer. It sounds possibly familiar though, to set a specific pivot point you can use a pivot shim: http://stackoverflow.com/questions/28848863/threejs-how-to-rotate-around-objects-own-center-instend-of-world-center The answer also include the geometry.translate method which I think you might be implying with the unity transform solution. – Radio Feb 24 '16 at 20:25
  • I haven't created the models but yes, some models have the origin (or pivot point) at the bottom, left hand corner, or at x=0 y=0 and z=0 and some have them at x=width/2, y=0 and z=0. Others in other places. I need to know the origin offsets for transformations. – Paul Gregory Feb 24 '16 at 20:47
  • I believe then what you need is the matrix of the mesh. see this document: http://threejs.org/docs/#Manual/Introduction/Matrix_transformations – Radio Feb 24 '16 at 20:59

1 Answers1

2

Figured it. It was as I thought. The position of the mesh gives the position of the origin, even if it is offset. Using the box.min/max values and adding or subtracting those values from the position gives the values I need.