diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index 9690ce5fff3eef6646649bc9890e7b87565fb221..e6a48f3e33bb6be5e8784ad5693ec2e4c0731683 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -98,7 +98,7 @@ _.each(this.parts, function(part){ part.hide(); }); - } else if (mode == "parts"){ + } else if (mode == "part"){ this._setCellMeshVisibility(false); _.each(this.parts, function(part){ part.show(); diff --git a/js/fea/dmaPart.js b/js/fea/dmaPart.js index 833117b373784b20a87eb2db8a0bd4f855c50ea9..dae36c09f68413357cd121671e7039c688327d9d 100644 --- a/js/fea/dmaPart.js +++ b/js/fea/dmaPart.js @@ -7,20 +7,35 @@ (function () { - var unitPartGeo; + var unitPartGeo1, unitPartGeo2, unitPartGeo3, unitPartGeo4, unitPartGeo5,unitPartGeo6; //import part geometry var loader = new THREE.STLLoader(); loader.load("data/trianglePart.stl", function(geometry){ console.log("part loaded"); - unitPartGeo = geometry - unitPartGeo.dynamic = true; - unitPartGeo.computeBoundingBox(); - var unitScale = 1/unitPartGeo.boundingBox.max.y; - unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); - unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0.2,-0.5, 0)); - unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(-Math.PI/6)); - unitPartGeo.dynamic = true; + unitPartGeo1 = geometry + unitPartGeo1.dynamic = true; + unitPartGeo1.computeBoundingBox(); + var unitScale = 1/unitPartGeo1.boundingBox.max.y; + unitPartGeo1.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); + unitPartGeo1.applyMatrix(new THREE.Matrix4().makeTranslation(0.2,-0.5, 0)); + unitPartGeo1.applyMatrix(new THREE.Matrix4().makeRotationZ(-Math.PI/6)); + unitPartGeo1.dynamic = true; + + unitPartGeo2 = unitPartGeo1.clone(); + unitPartGeo2.applyMatrix(new THREE.Matrix4().makeRotationZ(2*Math.PI/3)); + + unitPartGeo3 = unitPartGeo1.clone(); + unitPartGeo3.applyMatrix(new THREE.Matrix4().makeRotationZ(-2*Math.PI/3)); + + unitPartGeo4 = unitPartGeo1.clone(); + unitPartGeo4.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); + + unitPartGeo5 = unitPartGeo2.clone(); + unitPartGeo5.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); + + unitPartGeo6 = unitPartGeo3.clone(); + unitPartGeo6.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); }); var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THREE.FlatShading }); @@ -39,19 +54,24 @@ DMAPart.prototype._makeMeshForType = function(type){ - var mesh = new THREE.Mesh(unitPartGeo, partMaterial); - mesh = this._setMeshPosition(mesh); - mesh = this._setMeshScale(mesh); - + var mesh; switch(type){ + case 0: + if (this.oddZFlag) mesh = new THREE.Mesh(unitPartGeo4, partMaterial.clone()); + else mesh = new THREE.Mesh(unitPartGeo1, partMaterial.clone()); + break; case 1: - mesh.rotateZ(2*Math.PI/3); + if (this.oddZFlag) mesh = new THREE.Mesh(unitPartGeo5, partMaterial.clone()); + else mesh = new THREE.Mesh(unitPartGeo2, partMaterial.clone()); break; case 2: - mesh.rotateZ(-2*Math.PI/3); + if (this.oddZFlag) mesh = new THREE.Mesh(unitPartGeo6, partMaterial.clone()); + else mesh = new THREE.Mesh(unitPartGeo3, partMaterial.clone()); break; } - if (this.oddZFlag) mesh.rotateZ(Math.PI); + + mesh = this._setMeshPosition(mesh); + mesh = this._setMeshScale(mesh); return mesh; }; @@ -65,6 +85,7 @@ if (this.oddZFlag){//adjust some offsets for odd z layers mesh.position.y += 7*scale/6; } + mesh.myPart = this;//need a ref back to this part return mesh; }; @@ -91,9 +112,18 @@ if (this.mesh) this.mesh.visible = false; }; + DMAPart.prototype.highlight = function(){ + this.mesh.material.color.setRGB(1,0,0); + }; + + DMAPart.prototype.unhighlight = function(){ + this.mesh.material.color.setRGB(0.9619657144369509, 0.6625466032079207, 0.20799727886007258); + }; + DMAPart.prototype.destroy = function(){ if (this.mesh) { window.three.sceneRemove(this.mesh, "part"); + this.mesh.myPart = null; // this.mesh.dispose(); // geometry.dispose(); // material.dispose(); diff --git a/js/models/AppState.js b/js/models/AppState.js index 7f38eb9db25cb586d867ff9b147a85463c934a45..1442e706c0fc24564a7777b62b78eff03e349018 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -51,7 +51,7 @@ AppState = Backbone.Model.extend({ if (currentTab == "lattice") this.lattice.set("cellMode", "cell"); else if (currentTab == "import") this.lattice.set("cellMode", "cell"); else if (currentTab == "sketch") this.lattice.set("cellMode", "cell"); - else if (currentTab == "part") this.lattice.set("cellMode", "parts"); + else if (currentTab == "part") this.lattice.set("cellMode", "part"); }, //update to last tab open in that section diff --git a/js/models/threeModel.js b/js/models/threeModel.js index cc38a6c7d2cfc4b7dc1e3a3d8f0c71359e9acc16..bcc512040fc33f3f1258960f3aa104ae05515b46 100644 --- a/js/models/threeModel.js +++ b/js/models/threeModel.js @@ -101,6 +101,7 @@ function ThreeModel(){ render: render, sceneRemove: sceneRemove, sceneAdd: sceneAdd, +// scene: scene, domElement: renderer.domElement, camera: camera, cells: cells, diff --git a/js/threeViews/threeView.js b/js/threeViews/threeView.js index 6e5c4774688e6ffc1ca65ae2fb595a7d010abf87..23498dfcf7a4cc136787ec7dea4cdade3ae598bc 100644 --- a/js/threeViews/threeView.js +++ b/js/threeViews/threeView.js @@ -104,6 +104,7 @@ ThreeView = Backbone.View.extend({ var cellIntersections = this.mouseProjection.intersectObjects(this.model.cells.concat(this.model.basePlane), true); if (cellIntersections.length == 0) { this._setNoCellIntersections(); + this._setNoPartIntersections(); return; } this._handleCellIntersections(cellIntersections); @@ -120,17 +121,25 @@ ThreeView = Backbone.View.extend({ _setNoCellIntersections: function(){ this.currentIntersectedCell = null; - this.currentIntersectedPart = null; this._hideHighlighter(); }, _setNoPartIntersections: function(){ - this.currentIntersectedPart = null; + if (this.currentIntersectedPart){ + this.currentIntersectedPart.unhighlight(); + this.currentIntersectedPart = null; + window.three.render(); + } }, _handlePartIntersections: function(intersections){ - - + var part = intersections[0].object.myPart; + if (part!= this.currentIntersectedPart){ + if (this.currentIntersectedPart) this.currentIntersectedPart.unhighlight(); + part.highlight(); + this.currentIntersectedPart = part; + window.three.render(); + } }, _handleCellIntersections: function(intersections){