I am trying to create an office scene in which I have an office with editable rooms to showcase. I have many edit options per room, and a floorplan view that shows everything from a top-down view. When I am in the office space, I use a UniversalCamera. When I am in the floorplan-view mode, I use an ArcRotateCamera. In order to showcase the spaces in a focused manner, I created empty transform nodes in Blender that act as camera anchors that focus on the room being edited in the camera’s FOV. I have a camera anchor for the floorplan view as well. This is where the issue comes in.
When the floorplan mode is clicked, I would like to smoothly animate the Universal Camera to the floorplan camera anchor transform node, and then switch to the arc rotate camera in the same position and rotation as the universal camera, so that I can then rotate around the model as a whole. However, when I move the universal camera to the floorplan camera anchor transform node’s position and rotation, it shows up with the correct rotation, but I cannot get the arc rotate camera to do the same. This causes a very noticeable SNAP in rotation when changing the active camera from the universal camera to the arc rotate camera, which creates a UX issue. I have thought about fading to black and then switching, but I would still like the arc rotate camera to share the same rotation as the camera anchor that I placed in Blender, which it seems to never be able to do so.
Right now, I am using this setup:
var newCameraPosition = new Vector3(0, 0, 0);
configAreaCameraAnchor.computeWorldMatrix(true);
newCameraPosition.copyFrom(configAreaCameraAnchor.absolutePosition);
var dir = configAreaCameraAnchor.getDirection(new Vector3(0, -1, 0));
var newCameraTarget = (newCameraPosition.add(dir)).add(new Vector3(0, (-1) * newCameraPosition.y, 0))
var positionKeys = [
{
frame: 0,
value: this._camera.position.clone(), //pos
},
{
frame: 100,
value: newCameraPosition, //move
},
];
this.animCameraPosition.setKeys(positionKeys);
var targetKeys = [
{
frame: 0,
value: this._camera.getTarget(),
},
{
frame: 100,
value: newCameraTarget,
},
];
this.animCameraTarget.setKeys(targetKeys);
this._camera.animations = ;
this._camera.animations.push(this.animCameraPosition);
this._camera.animations.push(this.animCameraTarget);
this._camera.detachControl(this._canvas);
this._scene.beginDirectAnimation(
this._camera,
this._camera.animations,
0,
100,
false,
2,
() => {
this._arcCamera = new ArcRotateCamera(
“arcCamera”,
(-1) * this._camera.rotation.x,
this._camera.rotation.y,
newCameraPosition.y,
newCameraTarget,
this._scene
);
this._arcCamera.position.copyFrom(this._camera.position);
this._arcCamera.lowerRadiusLimit = newCameraPosition.y * 0.25;
this._arcCamera.upperRadiusLimit = newCameraPosition.y * 1.1;
this._arcCamera.attachControl(true);
this.animationFinished = true;
}
);
The issue of the arc rotate camera always being skewed off of the correct rotation that the floorplan camera anchor has seems to be with the alpha and beta rotation values of the arc rotate camera. However, I have tried MANY different combinations of x and y and z rotation values and have not been able to replicate the universal camera rotation for the arc rotate camera across multiple models. (It might work for one, but not all of them).
It also doesn’t help that the camera anchor transform node’s rotation values are either all 0 or skewed due to the transform node being a descendant of many other empty nodes in my scene graph hierarchy. When I setTarget for the universal camera in the manner displayed above, it changes the rotation of the universal camera, which I try to grab for the arc rotate camera’s alpha and beta values, but doing so often alters the universal camera’s rotation value around the x axis 90 degrees, for whatever reason, even though the camera still looks at the target.
Any help with these rotation conversions would be most appreciated. I have read the rotation conventions doc and the Universal and ArcRotate cameras docs extensively, but to no avail. I also looked at other ArcRotate <-> Universal camera questions on forums as well, but none quite talk about this problem specifically.
Thanks in advance!