我正在尝试找到一种方法,通过单击场景外的按钮来启动/停止babylonjs场景中的相机autoRotation。
var createScene = function () {
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3(0, 0, 0);
var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 2, new BABYLON.Vector3(0,0,200), scene);
camera.attachControl(canvas, true);
var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 100), scene);
var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene);
light1.intensity = 10;
light2.intensity = 24;
BABYLON.SceneLoader.ImportMesh("", "samples/79115-0_10MB/", "79115-0_100.obj", scene, function (newMeshes) {
camera.target = newMeshes[0];
});
////// set the behaviour here /////
camera.useAutoRotationBehavior = false;
return scene;
};我曾尝试使用createScene函数外部的切换函数进行更改,但没有成功:
function toggleRotate(){
if(autoR==0){
autoR=1;
camera.useAutoRotationBehavior = true;
}else{
autoR=0;
camera.useAutoRotationBehavior = false;
}
}发布于 2019-05-21 16:26:57
好的,对于你正在尝试做的事情,解决方案有点棘手。
实际上,你需要将你的相机旋转绑定到引擎渲染循环。
例如,您可以使用以下呈现循环:
var scene = new BABYLON.Scene(engine);
engine.runRenderLoop(() => {
scene.render();
rotateCamera();
});然后,您的rotateCamera方法包含以下指令:
rotateCamera() {
if(autoR==1){
camera.alpha = (camera.alpha % (2*Math.PI)) + (offset);
}
}偏移变量是要为每一帧旋转摄影机(以弧度为单位)的值。
然后,您的按钮必须调用一个切换autoR值的函数
要获得更多信息,请不要犹豫,前往BabylonJS论坛。https://forum.babylonjs.com/c/questions
https://stackoverflow.com/questions/56223844
复制相似问题