我创建了一个功能,可以通过特定目标移动摄像机:
var createScene2=function()
{
var MyCurve;
var MyGoal = new BABYLON.Vector3(0,10,5);
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 5, new BABYLON.Vector3(0,0,0), scene);
camera.attachControl(canvas, true);
var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene);
var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {}, scene);
MyCurve= MyPath(camera.position, MyGoal);
MoveCameraThrough(scene, camera , MyCurve);
return scene
}
当我调用渲染器时:
var scenee= createScene2();
engine.runRenderLoop(function () {
scenee.render();
});
它可以正常工作,但是当摄像机位置达到特定目标时, 从起始点重新开始
任何想法?
谢谢
Anes
答案 0 :(得分:0)
我解决了这个问题。 它在MoveCameraThrough()函数中
function MoveCameraThrough( scene , camera, MyCurve)
{
const path3d = new BABYLON.Path3D(MyCurve.getPoints());
const tangents = path3d.getTangents(); // array of tangents to the curve
const normals = path3d.getNormals(); // array of normals to the curve
const binormals = path3d.getBinormals(); // array of binormals to curve
const speed = 50*Math.floor(Math.random() * (7 - 3 + 1)) + 3; // const speed = 1
const animationPosition = new BABYLON.Animation('animPos', 'position', speed, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
const animationRotation = new BABYLON.Animation('animRot', 'rotation', speed, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
const keysPosition = [];
const keysRotation = [];
for (let p = 0; p < MyCurve.getPoints().length; p++) {
keysPosition.push({
frame: p,
value: MyCurve.getPoints()[p]
});
keysRotation.push({
frame: p,
value: BABYLON.Vector3.RotationFromAxis(normals[p], binormals[p], tangents[p])
});
}
animationPosition.setKeys(keysPosition);
animationRotation.setKeys(keysRotation);
camera.animations=[
animationPosition,
animationRotation
];
scene.beginAnimation(camera, 0, 200, false);
}
并完全位于
scene.beginAnimation(camera,0,200,false);
属性“ false”为“ true”,然后循环播放场景。
谢谢
Anes