2016-10-07 122 views
0

如何獲取當前視圖並將視圖設置爲正確視圖?將正視圖設置爲視圖

我嘗試使用viewer.getCamera()來獲取當前設置視圖的參數,然後使用viewer.applyCamera()進行設置。

var camera = viewer.getCamera(); 
console.log('Camera: ' + JSON.stringify(camera)); 

它返回:

Camera: { 
    "metadata": {"version":4.3,"type":"Object","generator":"ObjectExporter"}, 
    "object":{"uuid":"78D2EA86-853B-473F-9E0E-E3F0C8874E40", 
    "type":"Camera", 
    "matrix":[1,0,0,0,0,1,0.00009999999747378752,0,0,-0.00009999999747378752,1,0,114010.796875,88329.0078125,135503.609375,1], 
    "children":[ 
     {"uuid":"53C7FA49-B00C-4616-9E7A-CCB94A661A45", 
     "type":"DirectionalLight", 
     "color":8355711,"intensity":0, 
     "matrix":1,0,0,0,0,1,0,0,0,0,1,0,-0.5,0.20000000298023224,0.05999999865889549,1]}, 
     { 
      "uuid":"7D5EC244-7268-4190-8480-4BD1DD56F8CB", 
      "type":"Object3D","matrix":[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1] 
     }]}} 

然後我試圖設定,隨着 「矩陣」 數組作爲參數,可以但視圖跳躍。

viewer.setViewFromArray(params); 

回答

1

我遵循數組的格式與來自當前攝像頭的數據並通過viewer.setViewFromArray應用它們。我保留了所有其他參數,但只將最後一個參數設置爲1(正值)。它看起來很適合我。

viewerApp.myCurrentViewer.setViewFromArray([ 
    viewerApp.myCurrentViewer.getCamera().position.x, 
    viewerApp.myCurrentViewer.getCamera().position.y, 
    viewerApp.myCurrentViewer.getCamera().position.z, 
    viewerApp.myCurrentViewer.getCamera().target.x, 
    viewerApp.myCurrentViewer.getCamera().target.y, 
    viewerApp.myCurrentViewer.getCamera().target.z, 
    viewerApp.myCurrentViewer.getCamera().up.x, 
    viewerApp.myCurrentViewer.getCamera().up.y, 
    viewerApp.myCurrentViewer.getCamera().up.z, 
    viewerApp.myCurrentViewer.getCamera().aspect, 
    viewerApp.myCurrentViewer.getCamera().fov, 
    1, 
    1 
]); 

您還可以檢查源Viewer3D.js以獲取工作流如何setViewFromArray工作。

Viewer3D.prototype.setViewFromArray =函數(參數,可以名稱){....}

如果只想切換透視圖和正視之間的視圖中,可以使用直接API:

Viewer.navigation.toOrthographic()

Viewer.navigation.toPerspective()

+0

嗨曉東, 只是想知道爲什麼Viewer.navigation.toOrthographic(),使相機動物園m變成對象(並讀取代碼,它實際上移動了相機的位置)? – Afshin