当在手机上启动VR工具并直接在前方观看时,我想让视图在屏幕中央显示整个模型。 视角应该略微倾斜,所以我可以看到整个建筑楼层。 目前它是直接向前,这使您看不到整个模型的视图。 我怎么能实现这个目标?
例如,在此Autodesk示例中,当您输入VR时,模型位于中心。
http://viewervr.herokuapp.com/
目前的代码,与我试图调整相机位置
document.getElementById("toolbar-vrTool").addEventListener("click", function () { let _navapi = viewer.navigation; let _camera = _navapi.getCamera(); let xValue = viewer.getCamera().position.x; let yValue = viewer.getCamera().position.y; let zValue = viewer.getCamera().position.z; zValue = zValue * 0.5; yValue = (zValue * 0.7071) * -1; _camera.position.set(xValue, yValue, zValue); });目前来看
查看我想要的
When starting VR tool on mobile and watching directly ahead, I would like to have the view to show the whole model in the center of the screen. The view should be at a slight angle, so I could see the whole building floor. Currently it is directly ahead, which leaves you with a view where you cannot see the whole model. How could I achieve this?
For example, in this Autodesk example, the model is in the center when you enter VR.
http://viewervr.herokuapp.com/
Current code, with what I am trying to adjust the camera position
document.getElementById("toolbar-vrTool").addEventListener("click", function () { let _navapi = viewer.navigation; let _camera = _navapi.getCamera(); let xValue = viewer.getCamera().position.x; let yValue = viewer.getCamera().position.y; let zValue = viewer.getCamera().position.z; zValue = zValue * 0.5; yValue = (zValue * 0.7071) * -1; _camera.position.set(xValue, yValue, zValue); });Current view
View I would like to have
最满意答案
有一个名为fitToView()的函数可以完全按照您的意愿执行。 但是在使用之前,您需要等待几何体完全加载。 我还在下面的示例中添加了对setHomeViewFrom()的调用,将Home位置重置为fitToView()位置结果以供稍后导航。
oViewer.addEventListener (Autodesk.Viewing.GEOMETRY_LOADED_EVENT, onViewerGeometryLoaded) ; function onViewerGeometryLoaded () { oViewer.removeEventListener (Autodesk.Viewing.GEOMETRY_LOADED_EVENT, onViewerGeometryLoaded) ; oViewer.fitToView (true) ; setTimeout (function () { oViewer.autocam.setHomeViewFrom (oViewer.navigation.getCamera ()) ; }, 1000) ; }There is a function named fitToView() which will do exactly what you want. But you need to wait for the geometry to be fully loaded before using it. I also added a call to setHomeViewFrom() in the example below to reset the Home position to the fitToView() position result for later navigation.
oViewer.addEventListener (Autodesk.Viewing.GEOMETRY_LOADED_EVENT, onViewerGeometryLoaded) ; function onViewerGeometryLoaded () { oViewer.removeEventListener (Autodesk.Viewing.GEOMETRY_LOADED_EVENT, onViewerGeometryLoaded) ; oViewer.fitToView (true) ; setTimeout (function () { oViewer.autocam.setHomeViewFrom (oViewer.navigation.getCamera ()) ; }, 1000) ; }更多推荐
发布评论