Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert coordinate in threebox.scene to threebox.world or longitude /latitude? #422

Open
huangzhe2015 opened this issue Apr 1, 2024 · 3 comments
Labels
❓ question Further information is requested

Comments

@huangzhe2015
Copy link

Hello

I am using Raycaster to locate the intersect point when I click a 3D model on map with threebox.
var intersects = raycaster.intersectObjects(tb.scene.children, true);
Then I get the intersects[0].point which seems the coordinate in threebox.scene space.
I am wondering how can I convert intersects[0].point to some coordinate in threebox.world space or longitude /latitude?

Thanks.

@huangzhe2015 huangzhe2015 added the ❓ question Further information is requested label Apr 1, 2024
@harriputterr
Copy link

Hello @huangzhe2015

Were you able to find a solution to your problem?

I am kind of trying to achieve the same thing.

If you were able to find a solution, it would be wonderful if you can reply to this comment

Thank you so much

@huangzhe2015
Copy link
Author

Hello @harriputterr
I am still working on this issue.
I have tried to calculate below way but it failed.

  1. Get the center of map by map.getCenter() which is lng and lat format.
  2. Convert center to world position by projectToWorld(), that is a Vector3
  3. Use Vector3.add() method to add the position in scene system. Also I consider how many meters are equal to a pixel, according to https://docs.mapbox.com/help/glossary/zoom-level/#zoom-levels-and-geographical-distance.
    But I can't get correct result.

@huangzhe2015
Copy link
Author

  1. get the coordinate of center on map:
    var coordMapCenter = map.getCenter();
    var coordMapCenterArray = [coordMapCenter.lng, coordMapCenter.lat, 0];

  2. place the object to the center:
    obj.setCoords( coordMapCenterArray );

  3. move the object to intersect point by below code.
    obj.translateX(intersectPoint.x/tb.world.matrixWorld.elements[0]);
    obj.translateY(intersectPoint.y/tb.world.matrixWorld.elements[5]);
    obj.translateZ(intersectPoint.z/tb.world.matrixWorld.elements[10]);

That is how I find to convert coordinate in threebox.scene to threebox.world by chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants