I am using JSModeler with three.js extension. My viewer is JSM.ThreeViewer(). The codepen is: https://codepen.io/Dharnidharka/pen/QRzBQa
What I am trying to achieve is a rotation of the concentric circles around their center, but currently the rotation is about the world center.
- In three.js, this could be done by having a parent Object3D, and adding all the meshes to that object, centering that object by using geometry.center() and then having the rotation. But I could not find an Object3D extension for JSModeler.
- Another way in three.js could be to group objects around a common pivot but even that approach did not work for me.
- A third approach I tried was the solution in What's the right way to rotate an object around a point in three.js?, in the Update() loop but that doesn't work as well
I used the following to move the object to the pivot point:
meshes = JSM.ConvertModelToThreeMeshes (model);
viewer.AddMeshes (meshes);
for(var i =3; i<10; i++) {
meshes[i].geometry.computeBoundingBox();
meshes[i].geometry.boundingBox.getCenter(center);
meshes[i].geometry.center();
var newPos = new THREE.Vector3(-center.x, -center.y, -center.z);
meshes[i].position.copy(newPos);
}
The expected output is that the 2 circles are rotating about the common center, which also would be the world center. Currently, they are rotating about the world center, but not about their common center.