question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Matrix4: Don't require all inputs for decompose() or add other way to extract position

See original GitHub issue

I often find myself getting the world position of an object via object.matrixWorld.decompose(position, quaternion, scale), without any need to get the quaternion or scale. However, not passing in a valid quaternion/euler or scale results in an error.

https://github.com/mrdoob/three.js/blob/c23b245814ac71999d8303c07434fcfd244288dd/src/math/Matrix4.js#L785-L789

Would it be possible ignore undefined parameters with something like the following pseudo code?

if (position) {
    calculate and set position;
}

if (quaternion) {
    calculate and set quaternion;
}

if (scale) {
    calculate and set scale;
}

Alternatively, could a extractPosition() function and maybe a extractScale() function be added to go along with extractRotation()?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
WestLangleycommented, Feb 21, 2020

You can use these Vector3 methods:

vector.setFromMatrixPosition( matrix );

vector.setFromMatrixScale( matrix );
2reactions
sam6321commented, Feb 28, 2020

Added to the docs in #18767

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decomposing a Matrix4 does not result in the same scale as ...
Create a random Quaternion for rotation. Compose a Matrix4 with the above inputs. Decompose this same matrix to other scale, rotation and ...
Read more >
Matrix4#decompose – three.js docs
Matrix4. A class representing a 4x4 matrix. The most common use of a 4x4 ... decompose can be used to extract position, rotation...
Read more >
How to extract position, rotation and scale from matrix SVG
To decompose separately rotation and the skew you can check those examples: ... else scaleY = -scaleY // Renormalize matrix to remove scale....
Read more >
How to Get World Position with the Decompose Matrix Utility ...
Sometimes you want to know the world rotation or translation position of an object instead of it's local position and use that to...
Read more >
Math::Matrix4 class | Magnum C++ docs
This function is a counterpart to rotation() const that does not require orthogonal input. See also rotationScaling() and scaling() const for extracting other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found