-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutating a node's rotation array doesn't update the node #1538
Comments
Primarily this is a limitation in the https://gltf.report/ website — it does change detection, and can't tell changes were made if no setters were called, so it does not sync the scene in three.js. Still, marking the returned array as |
I figured the visual aspect of this was from the "Observer" code in Another fix would be making the returned getter objects a custom class or a Proxy which would notify the observer, but I frankly hate it. I think the right thing to do here is to use value semantics and not expose the mutable array object. I'm not a huge fan of the getters in three.js and ml-matrix that require you to pass in a container for the result; it tends to hurt readability IMO. |
What do you mean by "value semantics" – would I do agree that the |
Reference semantics: The getter and setter take and return an array object which has shared state with the node. Value semantics: The getter and setter copy the rotation so there is no shared state after the getter/setter is called.
I might call it
I think I have found that returning plain number-keyed objects |
In experimenting with my own code, I'm becoming very fond of this convention:
You get the simplicity of calling it as a regular getter plus the option name serves as inline documentation. And you can use it as a drop-in optimization to extract allocation from a loop. e.g. for (const mesh of meshes){
let rot = mesh.getRotation()
// ...
}
let temp = new Float32Array(4)
for (const mesh of meshes){
let rot = mesh.getRotation({into: temp})
// ...
}
const product1 = vec4.multiply(a, b)
const temp = [0, 0, 0, 0]
const product2 = vec4.multiply(a, b, {into: temp}) |
Describe the bug
The array returned by
c.getRotation
is mutable and live but updates aren't reflectedTo Reproduce
Steps to reproduce the behavior:
Expected behavior
Either mutating the scale array has no effect or mutating the scale array updates the visible scene.
Versions:
Additional context
It's not clear from documentation whether
getScale
andsetScale
operate by value or by reference. It seems thatgetScale
is by reference butsetScale
is by value.It might be sufficient to mark the returned
vec3
with the TypeScriptreadonly
modifier and/orObject.freeze()
the array so the distinction does not matter.The text was updated successfully, but these errors were encountered: