I've been tasked with updating a simulation project that was initiated several years ago. The previous developers used older versions of three.js and tween.js libraries, but I had to upgrade them for various reasons. However, I'm encountering an issue now where a piece of code that used to function properly is no longer working, and I can't seem to pinpoint the reason...
Let me delve into the problem at hand. When the application starts, meshes are loaded by invoking this function for each mesh:
function loadMesh(objPath, objName, worldScene, initPosition) {
if (initPosition == undefined) {
initPosition = new THREE.Vector3();
}
var loader = new THREE.JSONLoader();
loader.load(objPath, function (geometry, materials) {
for (var material in materials) {
materials[material].shading = THREE.FlatShading;
}
var mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
mesh.scale.set(1, 1, 1);
mesh.name = objName;
mesh.position = initPosition;
mesh.positionO = initPosition.clone();
worldScene.add(mesh);
objects.push(mesh);
objDict[objName] = mesh;
loadCounter--;
});
}
NOTE: I will only demonstrate animation creation here, as I call the "start" method on them later. At present, when I attempt to move an object by altering its position using something like this:
new TWEEN.Tween(objDict["Screws"].position)
.to({y: 5}, 1000)
.delay(500);
it works without issues. However, when I try to rotate an object in a similar fashion:
new TWEEN.Tween(objDict["ms_LidUpper"].rotation)
.to({x: -1.571}, 1000)
.delay(500);
I encounter problems and couldn't find a solution. It's important to note that this code previously worked! My hunch is that the JSONLoader might be causing the issue because during debugging, the mesh object seemed to lack the matrixRotationWorld attribute and had the matrixWorldNeedsUpdate attribute set to false. In the earlier version of the application, matrixWorldNeedsUpdate was true, and there existed a matrixRotationWorld attribute.
Any assistance would be highly appreciated!