From 904666f2287756d128d070ee20c617d7551e5484 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sun, 22 Feb 2015 23:41:46 -0500 Subject: [PATCH] middle of some lattice structure changes --- js/fea/DmaCell.js | 8 ++++---- js/models/AppState.js | 2 +- js/models/BasePlane.js | 34 +++++++++++++--------------------- js/models/ThreeModel.js | 10 ++++------ js/threeViews/Highlighter.js | 6 +++--- js/threeViews/ThreeView.js | 1 + 6 files changed, 26 insertions(+), 35 deletions(-) diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 832589f9..5b7bd1e2 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -75,7 +75,7 @@ DMACell.prototype.getPosition = function(){//need for part relay DMACell.prototype.destroy = function(){ if (this.cellMesh) { window.three.sceneRemove(this.cellMesh, "cell"); - this.cellMesh.myCell = null; + this.cellMesh.myParent = null; // this.cellMesh.dispose(); // geometry.dispose(); // material.dispose(); @@ -144,7 +144,7 @@ DMACell.prototype.destroy = function(){ } else { mesh = THREE.SceneUtils.createMultiMaterialObject(unitCellGeo2, cellMaterials); } - mesh.myCell = this;//we need a reference to this instance from the mesh for intersection selection stuff + mesh.myParent = this;//we need a reference to this instance from the mesh for intersection selection stuff return mesh; }; @@ -192,7 +192,7 @@ DMACell.prototype.destroy = function(){ DMAVertexOctaCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell var mesh = THREE.SceneUtils.createMultiMaterialObject(unitCellGeo, cellMaterials); - mesh.myCell = this;//we need a reference to this instance from the mesh for intersection selection stuff + mesh.myParent = this;//we need a reference to this instance from the mesh for intersection selection stuff return mesh; }; @@ -238,7 +238,7 @@ DMACell.prototype.destroy = function(){ DMACubeCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell var mesh = THREE.SceneUtils.createMultiMaterialObject(unitCellGeo, cellMaterials); - mesh.myCell = this;//we need a reference to this instance from the mesh for intersection selection stuff + mesh.myParent = this;//we need a reference to this instance from the mesh for intersection selection stuff return mesh; }; diff --git a/js/models/AppState.js b/js/models/AppState.js index ae3513fa..0563a71d 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -22,7 +22,7 @@ AppState = Backbone.Model.extend({ cellMode: "cell",//show cells vs parts inverseMode: false,//show negative space cellType: "octa", - connectionType: "vertex", + connectionType: "face", partType: "triangle", allCellTypes: {octa:"Octahedron", cube:"Cube"}, diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index 4a40bd9d..4b53f068 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -47,21 +47,28 @@ BasePlane = Backbone.Model.extend({ }, _showMesh: function(){ + var self = this; _.each(this.get("mesh"), function(mesh){ - window.three.sceneAdd(mesh, "basePlane"); + window.three.sceneAdd(mesh, self._checkIsHighlightable(mesh)); }); window.three.render(); }, _removeMesh: function(){ + var self = this; _.each(this.get("mesh"), function(mesh){ - window.three.sceneRemove(mesh, "basePlane"); + window.three.sceneRemove(mesh, self._checkIsHighlightable(mesh)); }); window.three.render(); }, + _checkIsHighlightable: function(mesh){ + if (mesh.type == "Mesh") return "basePlane"; + return null; + }, + destroy: function(){ -// this.stopListening(); + this.stopListening(); this.set("zIndex", null, {silent:true}); this._removeMesh(); this.set("mesh", null, {silent:true}); @@ -181,25 +188,10 @@ SquareBasePlane = BasePlane.extend({ planeGeometry.vertices.push( new THREE.Vector3(dimX, dimX, 0)); planeGeometry.faces.push(new THREE.Face3(0, 1, 3)); planeGeometry.faces.push(new THREE.Face3(0, 3, 2)); + planeGeometry.computeFaceNormals(); - return [new THREE.Line(planeGeometry, new THREE.MeshBasicMaterial({color:0x000000, transparent:true, opacity:0.0, side:THREE.DoubleSide})), - new THREE.Line(geometry, this.get("material"), THREE.LinePieces)]; - }, - - _calcVertices: function(){ - - var vertices = []; - var dimX = this.get("dimX"); - var dimY = this.get("dimY"); - - for (var j=-dimX;j<=dimX;j++){ - for (var i=-dimY;i<=dimY;i++){ - - vertices.push(new THREE.Vector3(i,j,0)); - } - - } - return vertices; + return [new THREE.Mesh(planeGeometry, new THREE.MeshBasicMaterial({color:0x000000, transparent:true, opacity:0.0, side:THREE.DoubleSide})), + new THREE.Line(geometry, new THREE.LineBasicMaterial({color:0x000000, transparent:true, linewidth:1, opacity:this.get("material").opacity}), THREE.LinePieces)]; } }); \ No newline at end of file diff --git a/js/models/ThreeModel.js b/js/models/ThreeModel.js index 4d9966d5..a6e8b17a 100644 --- a/js/models/ThreeModel.js +++ b/js/models/ThreeModel.js @@ -7,7 +7,7 @@ function ThreeModel(){ var camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 1, 10000); var scene = new THREE.Scene(); - var renderer = new THREE.WebGLRenderer({antialias:false}); + var renderer = new THREE.WebGLRenderer({antialias:true});//antialiasing is not supported in ff and on mac+chrome //store all meshes to highlight var cells = []; @@ -59,7 +59,6 @@ function ThreeModel(){ } else if (type == "basePlane"){ basePlane.push(object); } - } function sceneRemove(object, type){ @@ -74,9 +73,8 @@ function ThreeModel(){ } else if (type == "part"){ parts.splice(parts.indexOf(objectToRemove), 1); } else if (type == "basePlane"){ - basePlane = []; + basePlane.splice(0, basePlane.length);//delete array without removing reference } - scene.remove(objectToRemove); } @@ -87,8 +85,8 @@ function ThreeModel(){ _.each(parts, function(part){ sceneRemove(part, "part"); }); - cells = []; - parts = []; + cells.splice(0, cells.length);; + parts.splice(0, parts.length); } function render(){ diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 338fa8db..7b234b9b 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -46,13 +46,13 @@ Highlighter = Backbone.View.extend({ highlightCell: function(object, face){ - if (object.parent && object.parent.myCell) { - this.intersectedCell = object.parent.myCell; + if (object.parent && object.parent.myParent) { + this.intersectedCell = object.parent.myParent; } else { this.intersectedCell = null;//we're on the base plane } - if (this.isVisible() && this._isHighlighting(face)) return;//nothing has changed +// if (this.isVisible() && this._isHighlighting(face)) return;//nothing has changed this.intersectedFace = face; diff --git a/js/threeViews/ThreeView.js b/js/threeViews/ThreeView.js index 8480e98a..3e290b18 100644 --- a/js/threeViews/ThreeView.js +++ b/js/threeViews/ThreeView.js @@ -92,6 +92,7 @@ ThreeView = Backbone.View.extend({ //check if we're intersecting anything var cellIntersections = this.mouseProjection.intersectObjects(this.model.cells.concat(this.model.basePlane), true); + console.log(this.model.basePlane); if (cellIntersections.length == 0) {//no intersections this.highlighter.setNoCellIntersections(); this._setNoPartIntersections(); -- GitLab