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); 
4

1 回答 1

2

我使用当前相机的数据遵循数组的格式,并通过 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 = function(params, name){....}

如果您只是想在透视和正交视图之间切换视图,可以使用直接 API:

Viewer.navigation.toOrthographic()

Viewer.navigation.toPerspective()

于 2016-10-08T10:12:02.640 回答