jscastro76 / threebox

A Three.js plugin for Mapbox GL JS, with support for animations and advanced 3D rendering.
Other
549 stars 145 forks source link

How to obtain the world coordinates of intersections? #384

Closed younggis closed 1 year ago

younggis commented 1 year ago

queryRenderedFeatures returns the screen coordinates of the intersection, but how to convert them to world coordinates?

jscastro76 commented 1 year ago

Check the documentation for utils.projectToWorld

younggis commented 1 year ago

Thank you. The method you gave is to turn WGS84 into the world coordinates of three. Now I want to turn the intersection into the world coordinates, like the following code. this.mapgl.on('click', (evt) => { let intersects = tb.queryRenderedFeatures(evt.point) if (intersects.length) { let feature = intersects[0]['object']; let worldcoordinate = tb.unprojectFromWorld(intersects[0]['point']); } }) I need to save the geographic coordinates corresponding to this intersection.

younggis commented 1 year ago

@jscastro76 Please take a look

younggis commented 1 year ago

I solved it let p = new THREE.Vector3(intersects[0]['point']['x'], intersects[0]['point']['y'], intersects[0]['point']['z']) let marinverse = new THREE.Matrix4(); marinverse.copy(tb.world.matrix).invert() console.log(tb.unprojectFromWorld(p.applyMatrix4(marinverse)));