I'm trying to scale my geometry to fit a real world scaling onto my 3D scene.
I get the top left corner of my map and the top right corner of my map.
I then convert those to points using the Google maps projection and then subtract those points from each other to get the delta of the map.
Then I use that number and divide it by my geometries bounding box deltaX.
The problem is that the code doesn't produce a right scaling.
The more I zoom into the map, the smaller the scaling gets and the more I zoom out, the larger to scaling gets. It should be the opposite.
I also don't know if this is actually scaling it correctly as it would be in real life.
Right now I do this:
var bounds = MAP3D.map.getBounds();
var projection = MAP3D.map.getProjection();
var x1Length = projection.fromLatLngToPoint(new google.maps.LatLng(
bounds.getNorthEast().lat(),
bounds.getSouthWest().lng()
));
var x2Length = projection.fromLatLngToPoint(new google.maps.LatLng(
bounds.getNorthEast().lat(),
bounds.getNorthEast().lng()
));
var ThreeUnitsX = Math.abs(x2Length.x - x1Length.x);
if (
MAP3D.ObjectManager.WellList[i].LOD.objects[0]
.object.geometry.boundingBox == null
) {
MAP3D.ObjectManager.WellList[i].LOD.objects[0]
.object.geometry.computeBoundingBox();
}
var boundingBox = MAP3D.ObjectManager.WellList[i].LOD.objects[0]
.object.geometry.boundingBox;
var deltaX = boundingBox.max.x - boundingBox.min.x;
var scaleX = ThreeUnitsX / deltaX;
me.WellList[i].LOD.scale.set(scaleX, scaleX, scaleX);
I want to thank chandlerp
from the #THREE.JS
irc for helping me a lot.
var scaleX = ThreeUnitsX / deltaX;
should be
var scaleX = deltaX / ThreeUnitsX ;
But that is only correct if your object should always be 111km long.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.