After moving my object with the "w" key and then rotating it with the "x" key, I noticed that my object rotates around the world origin instead of its own center. How can I update the object's pivot after moving it? I've come across suggestions to use geometry.center(), but unfortunately, that solution doesn't seem to work for me.
var tMatrix = new THREE.Matrix4()
var radian = 5*Math.PI/180
function keyDown(event){
if(event.key == 'x'){
r5 = Math.cos(radian);
r6 = -Math.sin(radian);
r8 = Math.sin(radian);
r9 = Math.cos(radian);
tMatrix.set( 1, 0, 0, 0,
0, r5, r6, 0,
0, r8, r9, 0,
0, 0, 0, 1 );
mesh.applyMatrix4(tMatrix);
}
if(event.key == 'w'){
tMatrix.set( 1, 0, 0, 0,
0, 1, 0, 1,
0, 0, 1, 0,
0, 0, 0, 1 );
mesh.applyMatrix4(tMatrix);
}
}
var pivot = new THREE.Object3D();
let loader = new THREE.STLLoader();
var material = new THREE.MeshLambertMaterial({color: 0x818181});
loader.load('STL/test.stl', function (geometry) {
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
});
window.addEventListener("keypress", keyDown);