diff --git a/index.html b/index.html index 01585df1fa1d012c5210eaa531340520a9b08f62..8baea581f23490ca3f6d27d25e249bb183e235d7 100644 --- a/index.html +++ b/index.html @@ -73,7 +73,7 @@ <script src="js/parts/OctaFaceTriPart.js"></script> <!--models--> - <script src="js/models/ThreeModel.js"></script> + <script src="js/three/ThreeModel.js"></script> <script src="js/lattice/Lattice.js"></script> <script src="js/lattice/CubeLattice.js"></script> @@ -86,9 +86,8 @@ <script src="js/lattice/OctaVertexLattice.js"></script> <script src="js/lattice/TruncatedCubeLattice.js"></script> - <script src="js/models/FillGeometry.js"></script> - <script src="js/models/BasePlane.js"></script> - <script src="js/models/extrudeVisualizer.js"></script> + <script src="js/three/FillGeometry.js"></script> + <script src="js/three/BasePlane.js"></script> <script src="js/models/AppState.js"></script> <script src="js/cam/assemblers/Component.js"></script> <script src="js/cam/assemblers/Assembler.js"></script> @@ -120,8 +119,8 @@ <script src="js/menus/CamMenuView.js"></script> <script src="js/menus/SendMenuView.js"></script> - <script src="js/threeViews/Highlighter.js"></script> - <script src="js/threeViews/ThreeView.js"></script> + <script src="js/three/Highlighter.js"></script> + <script src="js/three/ThreeView.js"></script> <script src="js/main.js"></script> <link rel="stylesheet" type="text/css" href="css/main.css"> diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 9c05d63369cf39cc22943404ada26ff72026bdda..bd5b8fde63092f2dc77158020b0fa85901f3b1fc 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -35,9 +35,6 @@ Lattice = Backbone.Model.extend({ _.extend(this, latticeSubclasses); //bind events - this.listenTo(this, "change:gikLength", this._gikLengthDidChange); - this.listenTo(globals.appState, "change:superCellIndex", this._gikLengthDidChange); - this.listenTo(this, "change:partType", this._updatePartType); this.listenTo(this, "change:cellType change:connectionType", this._updateLatticeType); this.listenTo(this, "change:cellSeparation", this._updateCellSeparation); @@ -338,10 +335,6 @@ Lattice = Backbone.Model.extend({ globals.three.render(); }, - _gikLengthDidChange: function(){ - if (globals.highlighter.updateGikLength) globals.highlighter.updateGikLength(); - }, - _setCellVisibility: function(){ if (globals.appState.get("cellsVisible")) this.showCells(); else this.hideCells(); diff --git a/js/models/extrudeVisualizer.js b/js/models/extrudeVisualizer.js deleted file mode 100644 index 2d31fa5d367acf64db0be13021bee46d9f9d70c2..0000000000000000000000000000000000000000 --- a/js/models/extrudeVisualizer.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Created by aghassaei on 1/22/15. - */ - - -function ExtrudeVisualizer(){ - - var triRad = 30*Math.sqrt(3)/4; - var geometry = new THREE.CylinderGeometry(triRad, triRad, 1, 3);//1 unit tall - geometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2)); - var material = new THREE.MeshBasicMaterial({color:0xff0000, transparent:true, opacity:0.2}); - var meshes = []; - - function makeMeshFromProfile(profiles){//profiles is an array of meshes - _.each(profiles, function(profile){ - var mesh = new THREE.Mesh(geometry, material); - var profilePos = profile.geometry.vertices[0]; - mesh.position.x = profilePos.x; - mesh.position.y = profilePos.y; - mesh.position.z = profilePos.z; -// globals.three.sceneAdd(mesh, false); - meshes.push(mesh); - }); - globals.three.render(); - } - - function makeHandle(){ - - } - - function getMeshNum(){ - return meshes.length; - } - - function dragHandle(height){ - _.each(meshes, function(mesh){ - mesh.scale.z = height; - }) - globals.three.render(); - } - - function renderIntoCells(){ - - } - - return {//return public properties/methods - makeMeshFromProfile:makeMeshFromProfile, - getMeshNum:getMeshNum, - dragHandle:dragHandle - } -} \ No newline at end of file diff --git a/js/models/BasePlane.js b/js/three/BasePlane.js similarity index 100% rename from js/models/BasePlane.js rename to js/three/BasePlane.js diff --git a/js/models/FillGeometry.js b/js/three/FillGeometry.js similarity index 100% rename from js/models/FillGeometry.js rename to js/three/FillGeometry.js diff --git a/js/threeViews/Highlighter.js b/js/three/Highlighter.js similarity index 96% rename from js/threeViews/Highlighter.js rename to js/three/Highlighter.js index b137c913429d487912646115dc8d3ded0b9d272b..93a59b8dfde63309384ba4c7d5097d4d012468d9 100644 --- a/js/threeViews/Highlighter.js +++ b/js/three/Highlighter.js @@ -25,6 +25,8 @@ Highlighter = Backbone.View.extend({ this.hide(); //bind events + this.listenTo(globals.lattice, "change:gikLength", this._superCellParamDidChange); + this.listenTo(globals.appState, "change:superCellIndex", this._superCellParamDidChange); }, /////////////////////////////////////////////////////////////////////////////////// @@ -106,6 +108,10 @@ Highlighter = Backbone.View.extend({ this.mesh.rotation.set(direction.y*Math.PI/2, direction.x*Math.PI/2, 0); }, + _superCellParamDidChange: function(){ + if (this.updateGikLength) this.updateGikLength(); + }, + /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////ADD REMOVE//////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// diff --git a/js/models/ThreeModel.js b/js/three/ThreeModel.js similarity index 100% rename from js/models/ThreeModel.js rename to js/three/ThreeModel.js diff --git a/js/threeViews/ThreeView.js b/js/three/ThreeView.js similarity index 100% rename from js/threeViews/ThreeView.js rename to js/three/ThreeView.js diff --git a/js/threeViews/meshHandle.js b/js/threeViews/meshHandle.js deleted file mode 100644 index 8fa49ce7549f2276f380e2b5a1eb049143f7b69a..0000000000000000000000000000000000000000 --- a/js/threeViews/meshHandle.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Created by aghassaei on 1/18/15. - */ - -//a draggable vector that moves a mesh face, singleton for now - -function MeshHandle(three){ - //init invisible arrow and add to scene - this.arrow = new THREE.ArrowHelper(new THREE.Vector3(0,0,1), new THREE.Vector3(0,0,0), 10, 0x000000); -// this.arrow.visibility = false; -// three.sceneAdd(this.arrow); -} - -MeshHandle.prototype.updatePosition = function(origin, normal){ - this.arrow.position.set(origin); - this.arrow.setDirection(normal); -}; - -MeshHandle.prototype.setForFaces = function(faces, vertices){ - if (!faces || faces.length<1) console.warn("no faces passed in to mesh handle"); - - var mutuallyExclusiveVertices = [faces[1].a, faces[1].b, faces[1].c]; - _.each([faces[0].a, faces[0].b, faces[0].c], function(vertex){ - if (mutuallyExclusiveVertices.indexOf(vertex) == -1) mutuallyExclusiveVertices.push(vertex); - else mutuallyExclusiveVertices.remove(vertex); - }); - if (mutuallyExclusiveVertices.length != 2) console.warn("not a square face"); - var origin = numeric.mul(numeric.add(vertices[mutuallyExclusiveVertices[0]], vertices[mutuallyExclusiveVertices[1]]), 0.5); - - this.arrow.position.set(origin); - this.arrow.setDirection(faces[0].normal); - this.arrow.visibility = true; -}; - -MeshHandle.prototype.hide = function(){ - this.arrow.visibility = false; -}; \ No newline at end of file diff --git a/js/threeViews/pushPullMeshView.js b/js/threeViews/pushPullMeshView.js deleted file mode 100644 index a1e2a53030efecbadb3afc4776d54ddb903b1e3a..0000000000000000000000000000000000000000 --- a/js/threeViews/pushPullMeshView.js +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Created by aghassaei on 1/17/15. - */ - -//this is a parent class for other threeJS VCs that allows push and pull scale changes in the threeJS scene - -PushPullMeshView = Backbone.View.extend({ - - el: "#threeContainer", - - events: { - }, - - boundsBox: null, - boxHelper: null, - currentHighlightedFaces:[], - shouldReceiveHighlight: true, - highlightPlane: null, - - initialize: function(options){ - - this.three = options.three; - - //bind events - this.listenTo(this.model, "change:bounds change:scale change:orientation", this.updateBounds); - - this.drawBounds(); -// this.createHighlightPlane(); - }, - - drawBounds: function(){ - this.boundsBox = new THREE.Mesh(new THREE.BoxGeometry(100, 100, 100), - new THREE.MeshLambertMaterial({color:0x0000ff, shading:THREE.FlatShading, transparent:true, opacity:0.0, vertexColors:THREE.FaceColors})); - this.boxHelper = new THREE.BoxHelper(this.boundsBox); - - this.boxHelper.material.color.set(this.defaultColor); -// this.three.sceneAdd(this.boxHelper); -// this.three.sceneAdd(this.boundsBox); - this.updateBounds(); - }, - - updateBounds: function(){ - var bounds = this.model.get("bounds");//this has not been scaled or rotated, as is when model was first imported - var max = bounds.max.toArray(); - var min = bounds.min.toArray(); - var size = numeric.sub(max, min); - var translation = numeric.mul(numeric.add(max, min), 0.5); - var geometry = new THREE.BoxGeometry(size[0], size[1], size[2]); - geometry.applyMatrix(new THREE.Matrix4().makeTranslation(translation[0], translation[1], translation[2])); - this.boundsBox.geometry = geometry; - this.boxHelper.update(this.boundsBox); - this.render(); - }, - -// createHighlightPlane: function(){ -// var squareGeometry = new THREE.Geometry(); -// squareGeometry.vertices.push(new THREE.Vector3()); -// squareGeometry.vertices.push(new THREE.Vector3()); -// squareGeometry.vertices.push(new THREE.Vector3()); -// squareGeometry.vertices.push(new THREE.Vector3()); -// squareGeometry.faces.push(new THREE.Face3(0, 1, 2)); -// squareGeometry.faces.push(new THREE.Face3(0, 2, 3)); -// var squareMaterial = new THREE.MeshBasicMaterial({color:0xffffff, shading:THREE.FlatShading, transparent:true, opacity:0.0, vertexColors:THREE.FaceColors}); -// this.highlightPlane = new THREE.Mesh(squareGeometry, squareMaterial); -// this.three.sceneAdd(this.highlightPlane); -// }, - - checkHighlight: function(intersections){ - if (intersections.length>0){ - var face = intersections[0].face; - if (this.currentHighlightedFaces.indexOf(face) != -1) return;//stay the same - this.setHighlightColor(this.currentHighlightedFaces, 0x0000ff); - - var faceIndex = intersections[0].object.geometry.faces.indexOf(face); - var face2Index = faceIndex-1; - if (faceIndex%2==0) face2Index = faceIndex+1; - this.currentHighlightedFaces = [face, intersections[0].object.geometry.faces[face2Index]]; - this.setHighlightColor(this.currentHighlightedFaces, 0xffffff); - - this.render(); - } else if (this.currentHighlightedFaces.length > 0){ - this.setHighlightColor(this.currentHighlightedFaces, 0x0000ff); - this.currentHighlightedFaces = []; - this.render(); - } - }, - - setHighlightColor: function(faces, color){ - _.each(faces, function(face){ - face.color.setHex(color); - }); - this.boundsBox.geometry.colorsNeedUpdate = true; -// this.boundsBox.geometry.__dirtyColors = true -// this.boundsBox.geometry.dynamic = true - } - -}); \ No newline at end of file