私は3.js
ライブラリを利用して、実際にこのようにレンダリングする画面にオブジェクト/形状をレンダリングする段階で午前てる:矢印関数に渡されたときのパラメータとしての機能を実行する - ES6
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
これは動作します。私はそれを利用していtutorialで
はそれにキューブを回転させるためのいくつかのコードを、xとy軸のしています:
var render =() => {
requestAnimationFrame(render);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
this.renderer.render(this.scene, this.camera);
};
しかし、私はアニメーションのアプローチに柔軟性を持たせ、回転機能などをレンダリング機能内で実行する関数として渡したいと考えています。私はこれを行うにしようとしました:
var render = (animation) => {
requestAnimationFrame(render);
animation();
this.renderer.render(this.scene, this.camera);
};
render(this.animation(cube));
私は、コードが正しく機能が、後続の各時間として、それは、その後のは、それは関数ではありませんと言う一度実行されるこれを見ることができますどのような。
私はここで何が間違っていますか、これが毎回機能として実行されるようにするにはどうすればよいですか?
おかげ
EDIT
エンジニアとsdgluckの答えから、これは私は、彼らが意味だと思うが、それはまだ動作しませんでしたです:
var render = (animation) => {
requestAnimationFrame(render);
animation();
this.renderer.render(this.scene, this.camera);
};
render(() => this.animation(cube));
EDIT 2
これはキューブとattempを作成するサービス内のすべてのコードですそれをアニメーション化するTS:
export class ThreeService {
constructor() {
this.scene;
this.aspect;
this.camera;
this.renderer;
}
/*
Creates the scene, the camera and the renderer
*/
setup() {
this.createScene();
this.createCamera();
this.createRenderer();
}
createScene() {
this.scene = new THREE.Scene();
}
createCamera() {
// This is the viewpoint that the users are looking from
this.camera = new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight, 1,10000);
}
createRenderer() {
this.renderer = new THREE.WebGLRenderer();
this.renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('model').appendChild(this.renderer.domElement);
}
createCube() {
// Creates the basic structure of the cube
var geometry = new THREE.BoxGeometry(700, 700, 700, 10, 10, 10);
// Adds colour to the cube using materials
var material = new THREE.MeshBasicMaterial({color: 0xfffff, wireframe: true});
// Cubes needs a geometry and a material to be rendered
var cube = new THREE.Mesh(geometry, material);
this.addObjToScene(cube);
this.positionCamera(1000);
var render = (animation) => {
debugger
requestAnimationFrame(render);
animation();
this.renderer.render(this.scene, this.camera);
};
render(() => {this.animation(cube)});
}
animation(obj) {
obj.rotation.x += 0.01;
obj.rotation.y += 0.01;
}
addObjToScene(obj) {
// They then needed added to the scene
if(!this.scene)
this.setup();
// By default the add function adds the obj to the coordinates 0,0,0
this.scene.add(obj);
}
positionCamera(zPos) {
if(!this.camera)
this.setup();
this.camera.position.z = zPos;
}
rotateObj(obj,x,y) {
obj.rotation.x += x;
obj.rotation.y += y;
}
}
そして、これが表示されているエラーコード:
EXCEPTION: TypeError: animation is not a function
browser_adapter.js:84EXCEPTION: TypeError: animation is not a functionBrowserDomAdapter.logError @ browser_adapter.js:84
browser_adapter.js:84STACKTRACE:BrowserDomAdapter.logError @ browser_adapter.js:84
browser_adapter.js:84TypeError: animation is not a function
at render (three.service.js:49)
at ZoneDelegate.invokeTask (zone.js:356)
at Object.onInvokeTask (ng_zone_impl.js:44)
at ZoneDelegate.invokeTask (zone.js:355)
at Zone.runTask (zone.js:256)
at ZoneTask.invoke (zone.js:423)
BrowserDomAdapter.logError @ browser_adapter.js:84
Subscriber.js:229
Uncaught TypeError: animation is not a function
あなたは毎回同じ方法で 'render'を呼び出していますか?レンダリングの呼び出しの周りにもっとコンテキスト(コード)を付けることができますか?これはすべてあなたが持っていますか? – sdgluck
@sdgluckこれは私が持っているもののすべてです – Katana24