'Get absolute Camera Position and Rotation

I've set up a very simple script system where I can change the position and rotation of the camera in space through string commands in the browser like this

setCameraPosition(0,0,0); setCameraRotation(1,0,1); 

When I recreate the current camera position into a command and then reexecute this command the camera position is as expected. Even when I change the camera position with Mouse or Touchscreen and execute the command. When I reload the webpage and execute the command again the camera position/rotation is then different from what I saw earlier.

I am sure it is some kind of misunderstanding on my part.

I'll recreate the current camera position like this:

const pos = camera.position
const rot = camera.rotation
const args: string[] = []
args.push(`setCameraPosition(${pos.x}, ${pos.y}, ${pos.z})`)
args.push(`setCameraRotation(${rot.x}, ${rot.y}, ${rot.z})`)
return args.join('; ') + ';'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source