Get Pivot Point (/Translation) of an object3D

transform
#1

Background: Object can be pivoted using their buffer geometries by using by applying .translate() method. It is different than setting the position, meaning it doesn’t change the origin, and only offsets all vertices.

What if I want to know this translation? It is a good assumption to make (also as per experience) to get objects which are composed of multiple objects themselves all of which have the origin set to (0, 0, 0) but pivoted. This is all the more valid for multi-geometry objects fetched from 3D warehouses.

Question: How can I know the object translation vector?

Note: Answer on SO seems computationally intensive at the face of it. I am hoping there is a better solution. https://stackoverflow.com/questions/35611985/threejs-how-to-find-pivot-point

eurecaStudio™ built on the back of threeJS - our new product
#2

Is geometry.boundingSphere.center good to use for this? What is there are nested geometries?

#3

It serves the purpose as per various objects (native or loaded) I have used.

#4

This statement needs a clarification. You are not using .makeTranslation() which is actually a method of Matrix4 but BufferGeometry.translate(). This method will offset the vertices of a geometry and thus changing the pivot point.

I personally tend to avoid this approach since it’s more flexibel to keep the geometry in its original state. The other option is to use an additional Object3D in order to represent the pivot point. The approach looks like so:

mesh.position.set( 1, 1, 1 );
var pivot = new THREE.Object3D();
pivot.add( mesh );

Have you considered to use this option in your app?

2 Likes
#5

My bad. I should have been clearer in my statement. I have come to know what it does, and hence I will edit that.

Yeah there were two approaches to have that done, as you rightly pointed out. I just chose the first one since I didn’t encounter any use case till now where the second one, what you highlighted, was a clear winner. My choice was a coin toss until now. I will give it a try as I am sure you are speaking from your experience.