Setting camera.matrixWorld by hand

I am trying to set the matrixWorld of my camera by hand (it’s computed elsewhere). However, no matter what is the setting of my camera.matrixAutoUpdate or scene.autoUpdate variables, the render loop always overwrites the matrixWorld with its own computation: before I enter render the matrix is fine, but after render it is back to the default setting. I am probably misreading the docs on how this is supposed to work, but any help is appreciated. Thanks!

You need to set matrixAutoUpdate to false on every object you don’t want it to, you can also set Object3D.DefaultMatrixAutoUpdate = false; in order for just every object by default not doing it automatically.

1 Like

Yes, but I have set camera.matrixAutoUpdate=false for my camera, yet camera.matrixWorld still gets updated. Seems to work differently for camera than for other objects?

Please demonstrate this issue with a live example. I can’t find a place in WebGLRenderer where the camera’s world matrix is overwritten (except when using WebXR).

I’m trying to create a minimal example, so far without luck. It’s really bizarre, I literally do

console.log(JSON.parse(JSON.stringify(camera.matrixWorld));
renderer.render( scene, camera );
console.log(JSON.parse(JSON.stringify(camera.matrixWorld));

and I can see the two lines differ: the first one has my matrix, while the second line has the default. I’ll dig further, but if any bells ring, let me know. Thanks!

1 Like

Minimal example attached. The key thing that triggers it is if you first set the camera position/lookat/fov using the convenience setters, and then set matrixWorld explicitly. In that case, render will recompute matrixWorld no matter what is the setting of matrixAutoUpdate.

Maybe this behaviour is intentional, but it might be worth documenting in that case.

index.html (1.4 KB)

Did you find a solution here?

1 Like

I simply don’t use the convenience setters (position/lookat/fov) if I know I’m going to set the model & projection matrices explicitly later.

1 Like