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.

Object3D.worldToLocal() returning incorrect vectors

See original GitHub issue

Describe the bug

Object3D.worldToLocal() sometimes returns [NaN, NaN, NaN]

To Reproduce

Steps to reproduce the behavior: Call Object3D.worldToLocal()

Code

function animate(t) {
  requestAnimationFrame( animate );
  
  let start = new THREE.Vector3(0,-10,0);
  let end = new THREE.Vector3(5,-10,0);
  let offset = new THREE.Vector3(0,0,0);
  start.lerp(end, t / 1000).add(offset);


  if (t < 1000) {
  	// Restuls in start = [NaN, NaN, NaN]
    circle.worldToLocal(start);
    console.log(start);
    
    let matrixWorldCopy = new THREE.Matrix4().copy(circle.matrixWorld);
    // These are different in the console.
    console.log(matrixWorldCopy);
    console.log(circle.matrixWorld);
  }
	circle.position.copy(start);

  renderer.render( scene, camera );
  stats.update();

}

Live example

Expected behavior

The input vector should be converted to the local coordinates of the Object3D.

Platform:

  • Device: Desktop
  • OS: Linux
  • Browser: Chrome
  • Three.js version: dev and latest release

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, Jan 3, 2021

Please no. This is an issue in your app. GitHub is for bugs and feature requests only. Please use the forum.

0reactions
eulertourcommented, Jan 4, 2021

The example from the documentation uses requestAnimationFrame if you decide to change it there https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object3D.worldToLocal() causes jittering - three.js forum
I found that the jittering was caused because worldToLocal() would alternate between first returning the offset of the mesh, then after copying that...
Read more >
rotated child object looking at Camera, using lookaAt() and ...
Object3D.prototype.worldToLocal = function ( vector ) { if ( !this.__inverseMatrixWorld ) this.__inverseMatrixWorld = new THREE.Matrix4(); return vector.
Read more >
Absolute Object3D.lookAt? #1752 - mrdoob/three.js - GitHub
if we were to support hierarchy lookAt(), there's a question of which up vector to use - the object's local up, the parent's...
Read more >
Introduction to Computer Graphics, Section 5.3 -- Other Features
The return value from intersectObjects is an array of JavaScript objects. Each item in the array represents an intersection of the ray with...
Read more >
three - npm
(bhickey); Renamed Object3D 's getChildByName() to ... (mrdoob); Optimized the PCF shadow map filtering to use vector comparisons.
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