Drew Noakes
Drew Noakes

Reputation: 310832

Immutable Object3D properties in ThreeJS r68

The migration notes for r67 to r68 state:

Object3D's position, rotation, quaternion and scale properties are now immutable.

What does this mean in practice? I'd like some more details about this. I couldn't find an issue or pull request for details.

For example, how would the following code snippets need to change?

obj.position.x = 10;

Also, how is this immutability enforced? Is there a moment in time when the object is frozen, or are the Vector3 etc instances immutable once constructed?

Upvotes: 3

Views: 544

Answers (1)

Drew Noakes
Drew Noakes

Reputation: 310832

After some experimentation, it seems that the the properties are readonly, and they access mutable objects.

So this is valid:

obj.position.x = 10;

But this will be ignored:

obj.position = new THREE.Vector3(10, 0, 0);

Unfortunately this does not cause any observable error or warning — it just silently doesn't do what you ask it to.

The following would work:

obj.position.set(10, 0, 0);

To find violations of this new restriction, try searching for the following strings (you may like to use a regex to make the whitespace optional):

  • .position =
  • .rotation =
  • .quaternion =
  • .scale =

Upvotes: 4

Related Questions