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

explain the custom layer threejs examples scale factor #8508

Closed
jvntf opened this issue Jul 18, 2019 · 5 comments
Closed

explain the custom layer threejs examples scale factor #8508

jvntf opened this issue Jul 18, 2019 · 5 comments

Comments

@jvntf
Copy link

jvntf commented Jul 18, 2019

mapbox-gl-js version: N/A

Question

Thanks for the great example of loading a GLTF 3D model with 3JS here. Can anyone explain how the scale factor that was used, was chosen? I cannot find any information on where 5.41843220338983e-8 comes from. Thanks!

Links to related documentation

Live demo of the the same example

@ryanhamley
Copy link
Contributor

@ryanbaumann do you remember how you arrived at that number?

@1ec5
Copy link
Contributor

1ec5 commented Jul 18, 2019

@andrewharvey
Copy link
Collaborator

The scale from the example, was found by hand (I had a slider and manually found the right value so that the model lined up with the map).

I'm working on a PR to improve the example to remove this magic number, but essentially if your model is in meters, then:

var scaleFactor = 1 / Math.cos(modelOrigin[1] * Math.PI / 180);
var mercatorExtent = 2 * Math.PI * 6378137;
var modelScale = 1 / mercatorExtent * scaleFactor;

Of course if you're just loading a building this is fine, if your model is a whole country, then you'll still have errors since you're not projecting the model, but that's a whole different matter.

@andrewharvey andrewharvey changed the title Scale factor - load 3D model with 3JS explain the custom layer threejs examples scale factor Jul 19, 2019
@peterqliu
Copy link
Contributor

closing, barring further actions

@andrewharvey
Copy link
Collaborator

I agree, the explanation here should suffice. We'll have #8524 in the next release which together with https://github.com/mapbox/mapbox-gl-js-docs/pull/23 does away with the magic number for the scale factor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants