1 回答

TA貢獻1813條經(jīng)驗 獲得超2個贊
可以的,在 Forge Viewer 里頭有很多方法可以做到這點,這邊我會以 AutoCam.goToView() 來示范,以下樣例假設(shè)相機的新位置是 ( x1, y1, z1 ):
// 獲取當(dāng)前相機信息
const currentView = viewer.autocam.getCurrentView();
cosnt eye = viewer.navigation.getEyeVector();
const eyeDir = viewVec.normalize();
const distance = eye.length(); //!<<< 相機與焦點的距離
const newPosition = new THREE.Vector3( x1, y1, z1 ); //!<<< 相機的新位置
const target = eye.add( newPosition ); //!<<< 計算新焦點位置
// 產(chǎn)生新相機信息
const newView = {
position: newPosition.clone(), //!<<< 相機的新位置
up: currentView.up.clone(),
center: target.clone(), //!<<< 相機的新焦點
pivot: target.clone(), //!<<< 相機的新環(huán)繞(Orbit)中心
fov: currentView.fov,
worldUp: currentView.worldUp.clone(),
isOrtho: (currentView.isOrtho === false)
};
// 將信息更新到相機上
viewer.autocam.goToView( newView );
以上希望對你幫助~
添加回答
舉報