Looking for a way to create a getWorldPosition function in Three.js that will return a vector?
This is the code I have to obtain the World Position of an object (obj) and store it in the vector vec.
obj.updateMatrixWorld();
var vec = new THREE.Vector3();
vec.setFromMatrixPosition(obj.matrixWorld);
Now, I would like to turn these three lines into a function so it can be used like this:
var vector = getWorldPosition(obj);
Does this approach seem correct to you?
function getWorldPosition(obj)
{
obj.updateMatrixWorld();
var vec = new THREE.Vector3();
vec.setFromMatrixPosition(obj.matrixWorld);
return {vec.x, vec.y, vec.z}; // Is this how you would write it?
}