Autodesk Forge:通过fitToView()在关注对象后以编程方式缩小

时间:2017-11-17 03:10:12

标签: autodesk-forge autodesk-viewer

选择并使用fitToView(objectIds,model)聚焦对象后, 我想以编程方式缩小相机,而不是通过鼠标事件。

我尝试了以下代码并且能够缩小,但3D空间被扭曲了。 如果你知道如何正确缩小,请告诉我。

// select and isolate target object
let dbid = [1137]
viewer.impl.visibilityManager.isolate(dbid, viewer.model)
viewer.select(dbid)

//focus on target object
viewer.getAggregateSelection((data) => {
    let rootId = data.selector.getInstanceTree().nodeAccess.rootId
    viewer.fitToView(rootId, viewer.model)
})

//zoom out camera
let cam = viewer.getCamera().perspectiveCamera
cam.zoom *= 0.05
viewer.impl.syncCamera();

1 个答案:

答案 0 :(得分:0)

这不是您需要更改的缩放属性,而是相机位置:

var nav = viewer.navigation

var pos = nav.getPosition()

var target = nav.getTarget()

var viewdir = new THREE.Vector3()

viewdir.subVectors (pos, target).normalize()

// zooms out by 100 along the view direction
viewdir.multiplyScalar (100)

pos.add(viewdir)

nav.setPosition(pos)