0

我在前端使用 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 行为封装到一个模型中。我不确定你是否这是一个正确的方法?

创建一个处理循环的指令会更好吗?这对我使用的方法有什么好处吗?

4

1 回答 1

1

这是我使用工厂而不是指令使用 AngularJS 和 THREEjs 制作的示例。我在这个例子中使用了工厂内部的渲染循环。

http://blog.tempt3d.com/2014/02/angularjs-threejs-servicefactory.html

希望这可以帮助。

于 2014-02-09T22:23:10.983 回答