0
我是Three.js和一般3D編程的新手,但我試圖讓this three.js example的馬從固定攝像頭在屏幕上移動。翻譯自定義幾何三,js
的代碼,「負載」馬是在這裏:
var loader = new THREE.JSONLoader();
loader.load("models/animated/horse.js", function(geometry) {
mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({
vertexColors: THREE.FaceColors,
morphTargets: true
}));
mesh.scale.set(1.5, 1.5, 1.5);
scene.add(mesh);
mixer = new THREE.AnimationMixer(mesh);
var clip = THREE.AnimationClip.CreateFromMorphTargetSequence('gallop', geometry.morphTargets, 30);
mixer.addAction(new THREE.AnimationAction(clip).warpToDuration(1));
});
在我的渲染功能,我可以在不增加對象的X和Z poisition以同樣的方式,我可以用相機的:
var radius = 600;
var theta = 0;
var prevTime = Date.now();
function render() {
theta += 0.1;
camera.position.x = radius * Math.sin(THREE.Math.degToRad(90));
camera.position.z = radius * Math.cos(THREE.Math.degToRad(90));
mesh.position.x = theta;
mesh.position.z = theta;
}
即使mesh.position.x
在Javascript控制檯中輸入時,我也會得到一個Uncaught TypeError: Cannot set property 'x' of undefined
。我如何翻譯這個對象?
是你的'camera'還是'mesh'定義爲全局變量? – gaitat
@gaitat是的,他們是:/ – trembling
'if(mesh){mesh.position.x = theta; 「工作? – WestLangley