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
Get world scale #7116
Get world scale #7116
Conversation
commented code is removed |
Looks good. Another thing, looking at the // if determine is negative, we need to invert one scale
var det = this.determinant();
if ( det < 0 ) {
sx = - sx;
}
// ...
scale.x = sx;
scale.y = sy;
scale.z = sz; |
function checkIfDecomposeAndGetWorldScaleAreEqual(obj) { | ||
var result = new THREE.Vector3(); | ||
|
||
// this is the old way to get scale: decompose the complete matrix and return scale part |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could re-phrase these comments, removing the reference to old and new ways, which are quite specific to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
Yeah I was wondering about the same but it should also be implemented in setFromMatrixScale but it's not. Don't know why. |
|
||
checkIfDecomposeAndGetWorldScaleAreEqual(obj); | ||
|
||
obj.scale.set(0, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why zero scale?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test all ways of how an object can be scaled. It does not really matter in production code but should be checked what happens if a matrix is empty (other than the 1 on 3,3)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
three.js does not support zero-determinant transforms. Most of your tests have a zero scale in at least one dimension. We only need to test what is supported.
However, if you would like to improve the library so zero-determinant transforms work, that might be useful. I am not sure if there is a compelling reason to do so, however...
Your approach can get a different answer in cases like the following: mesh.scale.set( - 1, 1, 1 );
mesh.updateMatrix();
var vec1 = mesh.getWorldScale();
var vec2 = new THREE.Vector3().setFromMatrixScale( mesh.matrix ); three.js does not officially support reflections in the object matrix, but we have done our best to do something reasonable in the math library. If anyone wants to try to break the library, that would be helpful, and we can figure out what to do about it. |
this.matrixWorld.decompose( position, quaternion, result ); | ||
|
||
return result; | ||
return result.setFromMatrixScale( this.matrixWorld ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not make this change at this point. It can produce a different answer from the current method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because the decompose generates a -sx at negative determinant. But why isn't that necessary on setFromMatrixScale? @mrdoob
@mrdoob Do you know why vector.setFromMatrixScale doesn't contain the xScale switching ? var det = this.determinant();
if ( det < 0 ) {
sx = - sx;
} |
@simonThiele See #4272 for a discussion of the issues involved. Also, experiment with this example.
|
I'll wait for @WestLangley approval on this one 😉 |
The examples of this pullrequest are now built and visible in threejsworker. To view them, go to the following link: |
Maybe I'm getting it wrong, but why is the hole matrix being decomposed if only the scale part is needed?
If it's not necessary, this PR just uses setFromMatrixScale to extract the scale from worldMatrix. Please check unit test if I missed any situation where decomposing and setFromMatrixScale may differ and please ignore first two commits (the second one reverts the first one) I just forgot to create a branch. Thx.