I'm trying to learn more about three.js so I can perform testing on a simple mechanism. Ultimately the desired output would be board tilt (front view) to axle orientation (plan view) for different designs. (XY plot), but that's obviously step five or six.. I'm stuck on step one, trying to understand how to obtain an axis of rotation, represented by a small diameter cylinder.
Obviously this photo represents a fail.
- I'm hoping to utilize the existing matrix tooling within Three.js to perform data charting / system analysis.
- Its not clear on what the worldMatrix object within a mesh object really represents. I would think that contains location, orientation and scaling factors, but it not clear on how to extract that info for translation / 3d rotations of other components in the world space.
- I'm guessing I'm better off making a copy of original component locations and matrix values, then working off of the copies. When you tilt left and back again, you don't end up in the original place.
The model represents a simple skateboard. I want to rotate the front truck hanger (which contains an axle and two wheels) about a tilted axis, according to a user selected slider element.
var euler;
const rotateMeshGroup =( meshGroup, rotationAxis, angleOfRotation) =>{
euler = new THREE.Euler().setFromRotationMatrix(rotationAxis.matrixWorld);
meshGroup.children.forEach(item => {
item.rotateOnAxis(euler, THREE.MathUtils.degToRad(angleOfRotation));
})
}
I don't understand how one creates an axis of rotation. The 3D angle I understand, but what about distance from the axis? Is that a matrix cross product calculation (shortest distance to a 3D axis, with distance perpendicular to the axis? )
edit: Still trying to figure this one out. Been wading thru lots of console.logs and I don't see anything in the canned matrices that would work. I've converted the pivot axis from a small diameter cylinder mesh object into a simple line defined by two vector endpoints. I'm now thinking delta-x, delta-y, delta-z calculations (translate, rotation, translate back) within RotateMeshGroup function.
Any tips and hints here?