heremaps / harp.gl

3D web map rendering engine written in TypeScript using three.js
Apache License 2.0
1.29k stars 197 forks source link

How can I change the camera near or far? #2028

Closed aoyaZY closed 3 years ago

aoyaZY commented 3 years ago

I tried to change camera frustum near plane, I set
map.camera.near = 200; map.camera.updateProjectionMatrix(); but it dosen't work. What is the default value of the camera frustum near plane? How can I set it or change it?

nzjony commented 3 years ago

@aoyaZY , thanks for your issue.

Changing the camera's near plane won't work, because we have a special class which takes care of computing the correct near / far plane.

get clipPlanesEvaluator(): ClipPlanesEvaluator in MapView. Which defaults to TiltViewClipPlanesEvaluator.

If you want to control this yourself directly, you can use a FixedClipPlanesEvaluator and pass it to the MapView during construction and set the near / far plane as you want.

Please let me know what you think.

aoyaZY commented 3 years ago

@nzjony , thanks for your answer. I've tried to pass a new FixedClipPlanesEvaluator(1, 10) to the MapViewduring construction,but the map goes wrong without reporting error. By the way, I've checked the MapView's near plane, default TiltViewClipPlanesEvaluator.near is 1, camera.near is 1500, camera.near seems to be the one that's working the one that's working image

FraukeF commented 3 years ago

@aoyaZY The FixedClipPlanesEvaluator wont work for most cases, as for the tilted map the frustum needs adjustments depending on the tilt angle, to get an acceptable view of the map. The TiltViewClipPlanesEvaluator(which is the default) will do this adjustments, so if you move the camera tilt angle, it will most probably show you different near and far plane values, unfortunately it assumes the world to be flat and probably therefor cuts your buildings You can try to set ClipPlanesEvaluator.maxElevation to a value that works for you.

aoyaZY commented 3 years ago

@nzjony , thanks for your explanation. I just found that vue maybe the key. I initialized map and added model both on vue project and single html page by the same way, in single html page, TiltViewClipPlanesEvaluator works well, but vue not Maybe you can test it on vue

nzjony commented 3 years ago

Hi @aoyaZY,

@FraukeF is correct, setting the maxElevation is the best way to fix this issue, and the FixedClipPlanesEvaluator shouldn't be used. Sorry, I should have asked what your use case is.

aoyaZY commented 3 years ago

@nzjony , @FraukeF , I tried to set maxElevation to different value ,but nothing change

FraukeF commented 3 years ago

@aoyaZY yes, you are right, sorrry for the wrong information, I checked and the maxElevation is actually overridden by a calculation based on the DataSource.maxGeometryHight and some scale factor, see https://github.com/heremaps/harp.gl/blob/master/%40here/harp-mapview/lib/MapView.ts#L3210 , please try to modify the `maxGeometryHeight' property of your datasource (or the VectorTileDataSource) instead

aoyaZY commented 3 years ago

@FraukeF , the building is not base on VectorTileDataSource , it's a .fbx model. And the datasource is WebTileDataSource , the problem will show up image image

FraukeF commented 3 years ago

@aoyaZY, unfortunately we have no other way at the moment to achieve this behaviour with the default ClipPlaneEvaluator... If you use some other DataSource as a baselayer, you could still modify the maxGeometryHeight of that one in the mean time to match the height of your fbx models.... I ll create an internal task to support the geometryHeight independent of DataSources, I ll let you know when we have some other solution for it.

aoyaZY commented 3 years ago

@FraukeF , thanks a lot ! Now I get what you really mean, and work it out. This problem is indeed difficult to solve, thank you bro! Hope you guys are all healthy, good luck!