My virtual world receives position updates for the other players in the world from my server. I then have to take the update and reposition the avatar for the remote player to keep the worlds in sync. Therefore, I am sending position
and rotation
values “over the wire”.
The problem I’m having is that if I try to use the object’s rotation.set()
function using the values in the received object, it doesn’t work and the object disappears off the screen:
// This does NOT work.
self.threeJsAvatar.rotation.set(newRotation._x, newRotation._y, newRotation._z, newRotation._order);
However, If I use the received object's values to create a **new** `Euler` object, and then set the object's `rotation` from that, it works fine:
```js
// This WORKS.
const reusableEulerObj = new THREE.Euler(newRotation._x, newRotation._y, newRotation._z, newRotation._order);
self.threeJsAvatar.rotation.set(reusableEulerObj.x, reusableEulerObj.y, reusableEulerObj.z);
But, that means I’m creating tons of new Euler
objects over time and I was told to avoid that and to reuse a module scope object instead. Apparently the Euler
object constructor is doing something I need to emulate or use a different approach that avoid this problem altogether.
How can I update the object’s rotation
using the private variables that got sent "over the wire in the form of a plain JSON object, without creating a new Euler
object,? Or is there a better way to do this overall?