我在前端使用 angularJS 和 Three.js。
我已经像这样创建了我的 three.js 对象:
var ThreeObject = (function() {
//constructor
function ThreeObject() {}
ThreeObject.prototype.init = functio init (){
//init scene,renderer,....
};
ThreeObject.prototype.update = function update(){
//update various objects attatched to scene
};
ThreeObject.prototype.draw = function draw(){
this.renderer.render(this.scene,this.camera);
};
return ThreeObject;
})();
在我的角度控制器中,我正在调用:
app.controller('Controller', ['$scope', '$http', function($scope,$http) {
var foo = new ThreeObject(800,600);
foo.init(document.getElementById('container'));
function loop() {
foo.update();
foo.draw();
requestAnimationFrame(loop);
};
requestAnimationFrame(loop);
}]);
由于 Angular 促进了 MVC,我的第一个反应是将所有 three.js 行为封装到一个模型中。我不确定你是否这是一个正确的方法?
创建一个处理循环的指令会更好吗?这对我使用的方法有什么好处吗?