Skip to content
Snippets Groups Projects
Commit df631ee6 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

threeView edits

parent 5eae1456
No related branches found
No related tags found
No related merge requests found
......@@ -8,12 +8,15 @@ $(function(){
three = new ThreeView();
//init models and views
fillGeometry = new FillGeometry();//init a singleton, add to global scope
new ImportView({model: window.fillGeometry});
var fillGeometry = new FillGeometry();//singleton
new ImportView({model: fillGeometry});
lattice = new Lattice();
three.setFillGeometry(fillGeometry);
//window.fillGeometry.set({geometry:"stuff"});
setupNavBar();
......
......@@ -24,17 +24,13 @@ FillGeometry = Backbone.Model.extend({
this.on("change:mesh", this.makeBoundingBoxHelper);
this.on("change:orientation", this.updateBoundingBox);
this.on("change:geometry", this.buildNewMesh);
this.on("change:mesh change:orientation", this.render);
this.buildNewMesh();
},
buildNewMesh:function(){
if (this.previous("mesh")) three.scene.remove(this.previous("mesh"));//remove current mesh from scene
this.set({orientation:this.defaults.orientation}, {silent:true});//restore defaults
var mesh = new THREE.Mesh(this.get("geometry"), this.get("material"));
three.scene.add(mesh);
this.set({mesh: mesh});
//send new geometry out to workers
......@@ -61,10 +57,6 @@ FillGeometry = Backbone.Model.extend({
this.trigger("change:boundingBoxHelper");
},
render: function(){
three.render();
},
rotate: function(axis){
var orientation = this.get("orientation");
var mesh = this.get("mesh");
......
......@@ -4,11 +4,6 @@ ThreeView = Backbone.View.extend({
el: "#threeContainer",
events: {
},
camera: new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 1, 1000),
scene: new THREE.Scene(),
renderer: new THREE.WebGLRenderer({antialias:false}),
......@@ -50,7 +45,6 @@ ThreeView = Backbone.View.extend({
var material = new THREE.MeshLambertMaterial( { color:0xffffff, shading: THREE.FlatShading } );
for ( var i = 0; i < 500; i ++ ) {
var mesh = new THREE.Mesh( geometry, material );
mesh.position.x = ( Math.random() - 0.5 ) * 1000;
mesh.position.y = ( Math.random() - 0.5 ) * 1000;
......@@ -58,10 +52,20 @@ ThreeView = Backbone.View.extend({
mesh.updateMatrix();
mesh.matrixAutoUpdate = false;
this.scene.add(mesh);
}
},
setFillGeometry: function(fillGeometry){
var self = this;
fillGeometry.bind("change:geometry", function(){
if (fillGeometry.previous("mesh")) self.scene.remove(fillGeometry.previous("mesh"));
self.render();
});
this.scene.add(fillGeometry.get("mesh"));
fillGeometry.bind("change:mesh change:orientation", this.render);
this.render();
},
onWindowResize: function(){
this.camera.aspect = window.innerWidth/window.innerHeight;
this.camera.updateProjectionMatrix();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment