babylon.js 尝试前进路径时相机回到初始点

babylon.js camera back to initial point when trying to forward a path

我创建了一个将相机移动到特定目标的函数:

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

        });   

效果很好,但是当相机位置到达特定目标时, 它从初始点重新开始

有什么想法吗?

谢谢

阿内斯

我解决了这个问题。 它在 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(相机, 0, 200, 假);

属性 "false" 是 "true" 然后循环场景。

谢谢

阿内斯