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.

getWorldScale and getWorldQuaternion return incorrect values when object scale has three negative components

See original GitHub issue

Describe the bug

mesh.getWorldScale and mesh.getWorldQuaternion return incorrect values for a mesh with negative x, y, and z scale components.

If mesh.scale is (-1, -1, -1), getWorldScale returns (-1, 1, 1), losing two minus signs. If mesh.quaternion is (0, 0, 0, 1), getWorldQuaternion returns (1, 0, 0, 0).

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://codepen.io/bennlich/pen/NWXyLKm
  2. Click anywhere on the canvas
  3. Notice how the image texture flips, and look at the console to see how the values of mesh.scale differ before and after.
  4. Go to https://codepen.io/bennlich/pen/MWrQPWE to see the analogous bug with getWorldQuaternion

Expected behavior

In the live example above, I would not expect the mesh to flip. I would expect getWorldScale to return the same value as the mesh’s current local scale. Same with getWorldQuaternion.

Platform:

  • Device: Desktop
  • OS: Linux
  • Browser: Chrome
  • Three.js version: 0.139.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
WestLangleycommented, Apr 7, 2022

Scaling by ( - 1, - 1, 1 ), for example, is equivalent to a rotation-only around the z-axis.

quaternion and scale are coupled in such cases and you can’t consider them individually.

1reaction
donmccurdycommented, Apr 7, 2022

Related:

…it is possible to compute a choice of translation 𝑇, rotation 𝑅, and scale 𝑆 with the same combined result as [matrix] 𝑀. But there is no guarantee that these will be the same values originally used to create 𝑀, as we’ll see below…

https://gamedev.stackexchange.com/questions/117528/calculate-matrix-transformation-components-separately

Matrix decomposition (or higher-level methods like getWorldScale) cannot be guaranteed to return the same translation/rotation/scale (TRS) components as the originals. Repeated round-trip conversions between matrixes and TRS components should be avoided.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object3D#getWorldQuaternion – three.js docs
When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every frame and also recalculates the matrixWorld property....
Read more >
Three.js object returns wrong values for position/rotation/scale
I'm having a three.js object in my scene, which you can rotate/scale/move with the THREE.TransformControls. After positioning the object in ...
Read more >
three.js - Apple Open Source
isInteger = function ( value ) { return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value; };...
Read more >
Transformations, Coordinate Systems, and the Scene Graph
Moving objects around in 3D space is a fundamental skill on your path of learning three.js. We'll break this skill down into two...
Read more >
UNPKG - @google/model-viewer
node_modules/has/src/index.js",". ... lib/three-components/CachingGLTFLoader.js",". ... '[object Symbol]') { return false; }\n\n\t// temp disabled per ...
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