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

mesh bounding box

parent 177bf60f
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ ImportMenuView = Backbone.View.extend({
initialize: function(){
this.fillGeometry = new FillGeometry({lattice:dmaGlobals.lattice});
this.fillGeometry = new FillGeometry();
this.listenTo(this.fillGeometry, "change", this.render);
},
......@@ -62,7 +62,7 @@ ImportMenuView = Backbone.View.extend({
var self = this;
var loader = new THREE.STLLoader();
loader.load(url, function(geometry){
self.fillGeometry.set("geometry", geometry);
self.fillGeometry.buildNewMesh(geometry);
});
},
......@@ -78,8 +78,7 @@ ImportMenuView = Backbone.View.extend({
_removeMesh: function(e){
e.preventDefault();
this.fillGeometry.remove();
this.fillGeometry.set("filename", this.model.defaults.filename);
this.fillGeometry.removeMesh();
},
render: function(){
......@@ -134,7 +133,6 @@ ImportMenuView = Backbone.View.extend({
<div class="btn-group fullWidth">\
<button data-toggle="dropdown" class="btn btn-lg btn-default dropdown-toggle fullWidth" type="button">Select Model <span class="caret"></span></button>\
<ul role="menu" class="dropdown-menu">\
<li><a class="selectMesh" data-file="meshes-airbus/Airbus_A300-600.stl" href="#">Plane</a></li>\
<li><a class="selectMesh" data-file="meshes-airbus/wingCrossection.stl" href="#">Wing</a></li>\
</ul>\
</div><!-- /btn-group -->\
......@@ -145,4 +143,5 @@ ImportMenuView = Backbone.View.extend({
//<a href="#" id="doSubtractGeo" class=" btn btn-block btn-lg btn-default">Subtract Mesh</a><br/>\
//<li><a id="selectWall" href="#">Wall</a></li>\
//<li><a class="selectMesh cutTerrain" data-file="river.stl" href="#">Landscape 1</a></li>\
//<li><a class="selectMesh cutTerrain" data-file="terrain.stl" href="#">Landscape 2</a></li>\
\ No newline at end of file
//<li><a class="selectMesh cutTerrain" data-file="terrain.stl" href="#">Landscape 2</a></li>\
//<li><a class="selectMesh" data-file="meshes-airbus/Airbus_A300-600.stl" href="#">Plane</a></li>\
\ No newline at end of file
......@@ -6,60 +6,41 @@
FillGeometry = Backbone.Model.extend({
defaults: {
material: new THREE.MeshLambertMaterial(
{color:0xf25536,
shading: THREE.FlatShading,
transparent:true,
opacity:0.4,
side:THREE.DoubleSide}),
geometry: null,
filename: "No File Loaded",
orientation: [0,0,0],
scale: [1.0,1.0,1.0],
mesh: null,
boundingBox: null//show bounding box for mesh
},
initialize: function(options){
this.lattice = options.lattice;
initialize: function(){
//bind events
this.on("change:mesh", this.getBounds);
this.on("change:orientation change:scale", this.updateBoundingBox);
this.on("change:geometry", this.buildNewMesh);
},
buildNewMesh:function(){
this.remove();
buildNewMesh:function(geometry){
this.removeMesh();
//center geometry in x and y
var geometry = this.get("geometry");
geometry.computeBoundingBox();
geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-geometry.boundingBox.max.x/2,-geometry.boundingBox.max.y/2,0));
geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,-geometry.boundingBox.min.z));//set on top of baseplane
geometry.computeBoundingBox();
this.set({orientation:this.defaults.orientation, scale:this.defaults.scale}, {silent:true});//restore defaults
var mesh = new THREE.Mesh(this.get("geometry"), this.get("material"));
this.makeBoundingBoxHelper(mesh);
var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial(
{color:0xf25536,
shading: THREE.FlatShading,
transparent:true,
opacity:0.4,
side:THREE.DoubleSide}));
this.makeBoundingBox(mesh);
this.set({mesh: mesh});
dmaGlobals.three.sceneAdd(mesh, null);
dmaGlobals.three.render();
//send new geometry out to workers
// _.each(workers.allWorkers, function(worker){
// worker.postMessage({model: this.toJSON});
// });
},
getBounds: function(){//bounds is the bounding box of the mesh geometry (before scaling)
// this.get("mesh").geometry.computeBoundingBox();
// this.set("bounds", this.get("geometry").boundingBox.clone());
},
makeBoundingBoxHelper: function(mesh){
// var helper = new THREE.BoundingBoxHelper(mesh, 0x000000);
// helper.update();
// this.set("boundingBoxHelper", helper);
makeBoundingBox: function(mesh){
var box = new THREE.BoxHelper(mesh);
box.material.color.setRGB(0,0,0);
this.set("boundingBox", box);
dmaGlobals.three.sceneAdd(box);
},
updateBoundingBox: function(){
......@@ -68,13 +49,16 @@ FillGeometry = Backbone.Model.extend({
},
subtractGeo: function(){
this.lattice.subtractMesh(this.get("mesh"));
dmaGlobals.lattice.subtractMesh(this.get("mesh"));
},
remove: function(){
removeMesh: function(){
if (!this.get("mesh")) return;
dmaGlobals.three.sceneRemove(this.get("mesh"), null);
dmaGlobals.three.sceneRemove(this.get("mesh"));
dmaGlobals.three.sceneRemove(this.get("boundingBox"));
this.set("mesh", null);
this.set("boundingBox", null);
this.set("filename", this.defaults.filename);
dmaGlobals.three.render();
},
......
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