Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting World coordinates to Screen coordinates in Three.js using Projection
    primarykey
    data
    text
    <p>There are several excellent stack questions (<a href="https://stackoverflow.com/questions/11036106/three-js-projector-and-ray-objects">1</a>, <a href="https://stackoverflow.com/questions/7956442/detect-clicked-object-in-three-js">2</a>) about unprojecting in Three.js, that is how to convert (x,y) mouse coordinates in the browser to the (x,y,z) coordinates in Three.js canvas space. Mostly they follow this pattern:</p> <pre><code> var elem = renderer.domElement, boundingRect = elem.getBoundingClientRect(), x = (event.clientX - boundingRect.left) * (elem.width / boundingRect.width), y = (event.clientY - boundingRect.top) * (elem.height / boundingRect.height); var vector = new THREE.Vector3( ( x / WIDTH ) * 2 - 1, - ( y / HEIGHT ) * 2 + 1, 0.5 ); projector.unprojectVector( vector, camera ); var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() ); var intersects = ray.intersectObjects( scene.children ); </code></pre> <p>I have been attempting to do the reverse - instead of going from "screen to world" space, to go from "world to screen" space. If I know the position of the object in Three.js, how do I determine its position on the screen?</p> <p>There does not seem to be any published solution to this problem. <a href="https://stackoverflow.com/questions/11534000/three-js-converting-3d-position-to-2d-screen-position">Another question about this just showed up on Stack</a>, but the author claims to have solved the problem with a function that is not working for me. Their solution does not use a projected Ray, and I am pretty sure that since 2D to 3D uses unprojectVector(), that the 3D to 2D solution will require projectVector().</p> <p>There is also <a href="https://github.com/mrdoob/three.js/issues/899" rel="nofollow noreferrer">this issue</a> opened on Github.</p> <p>Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload