[英]Rotate camera around model in Autodesk Forge
I have created an extension that rotates the camera around a Revit model that was uploaded in a bucket made, but how do I make the camera constantly rotate around the model after the button in the toolbar has been clicked on. 我创建了一个扩展程序,该扩展程序可以使相机围绕Revit模型旋转,该Revit模型是在存储桶中上传的,但是如何在单击工具栏上的按钮之后使相机不断围绕模型旋转。 In addition, how do I click the same button again to stop the rotation?
另外,如何再次单击同一按钮停止旋转? The code below is what I used to rotate the camera once the button is clicked on.
下面的代码是单击按钮后我用来旋转相机的代码。
var _this = this;
var _viewer = _this.viewer;
var turnTableToolbarButton = new Autodesk.Viewing.UI.Button('turnTableButton');
turnTableToolbarButton.onClick = function (e) {
const nav = _viewer.navigation;
const up = nav.getCameraUpVector();
var pos = nav.getPosition();
const axis = new THREE.Vector3(0, 0, 1);
const speed = 10.0 * Math.PI / 180;
const matrix = new THREE.Matrix4().makeRotationAxis(axis, speed * 0.1);
pos.applyMatrix4(matrix);
up.applyMatrix4(matrix);
nav.setView(pos, new THREE.Vector3(0, 0, 0));
nav.setCameraUpVector(up);
var viewState = _viewer.getState();
_viewer.restoreState(viewState);
};
I think what you would need here is use of requestAnimation, with your button stopping or starting the request for the new frame: 我认为您在这里需要使用requestAnimation,而您的按钮将停止或启动对新框架的请求:
let started = false;
let rotateCamera = () => {
if (started) {
requestAnimationFrame(rotateCamera);
}
const nav = viewer.navigation;
const up = nav.getCameraUpVector();
const axis = new THREE.Vector3(0, 0, 1);
const speed = 10.0 * Math.PI / 180;
const matrix = new THREE.Matrix4().makeRotationAxis(axis, speed * 0.1);
let pos = nav.getPosition();
pos.applyMatrix4(matrix);
up.applyMatrix4(matrix);
nav.setView(pos, new THREE.Vector3(0, 0, 0));
nav.setCameraUpVector(up);
var viewState = viewer.getState();
// viewer.restoreState(viewState);
};
turnTableToolbarButton.onClick = function (e) {
started = !started;
if (started) rotateCamera()
};
Check my repo of extensions for full code based on your snippet and a live illustration. 根据您的代码段和现场插图,查看我的扩展库回购以获取完整代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.