I have a tilted triangle on a scene (represented in blue):
// Original mesh
var points = [
new THREE.Vector3(-50, 0, 10),
new THREE.Vector3(-10, 0, 10),
new THREE.Vector3(-30, 50, 80),
new THREE.Vector3(-50, 0, 10),
];
var geometry = new THREE.BufferGeometry().setFromPoints(points);
var material = new THREE.MeshBasicMaterial({color: 0x0000ff});
var original = new THREE.Mesh(geometry, material);
scene.add(original);
I then rotate it with a quaternion to make the mesh parallel to the horizontal X-Y plane, and then rotate it again around the global vertical Z axis:
// Transformed mesh
var plane = new THREE.Plane().setFromCoplanarPoints(...points);
var quaternion = new THREE.Quaternion().setFromUnitVectors(
plane.normal,
new THREE.Vector3(0, 0, 1),
);
var transformed = original.clone().applyQuaternion(quaternion);
transformed.rotateOnWorldAxis(new THREE.Vector3(0, 0, 1), Math.PI);
transformed.material = transformed.material.clone()
transformed.material.color.set(0xff0000)
scene.add(transformed);
How can I get the coordinates of the transformed geometry? They should all have positive X values, negative Y values and the same positive Z value.
Fiddle: https://jsfiddle.net/Peque/21xjvtp5/
I have tried to access the transformed.geometry
, only to find out that the coordinates where those of the original geometry. I also tried to compute the bounding box:
var box = new THREE.Box3().setFromObject(transformed);
Which gave me expected X-Y values, so I am guessing what I am looking for is possible. Unexpectedly, the bounding box Z values were way off (I would expect the difference between max and min to be almost zero), but that is another question I guess…