diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index 7e643426968229b2b3de5b2c73380090ddc72871..f38bcb3017c71963f923fbba58425a2d76d3f065 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -44,7 +44,7 @@ this.scale = scale; this.position = this._calcPosition(scale, indices); this.cellMesh = this._buildCellMesh(this.position, indices.z); - window.three.sceneAdd(this.cellMesh); + window.three.sceneAdd(this.cellMesh, "cell"); this.parts = this._initParts(this.position, indices.z); this.drawForMode(mode); diff --git a/js/fea/dmaNode.js b/js/fea/dmaNode.js index 5547b6c0c701d0ded7e76fbe2d3244d6c509d7b8..83f2057fedfc9f5020d87ddb64b4a082daa638a6 100644 --- a/js/fea/dmaNode.js +++ b/js/fea/dmaNode.js @@ -18,7 +18,7 @@ BeamNode.prototype.render = function(){ geometry.applyMatrix( new THREE.Matrix4().makeTranslation(this.x, this.y, this.z) ); var mesh = new THREE.Mesh(geometry); - window.three.sceneAdd(mesh); +// window.three.sceneAdd(mesh); }; diff --git a/js/fea/dmaPart.js b/js/fea/dmaPart.js index 2e3f0e9e251bd6a413a45d1d58baff3a0d00530e..0ece174553f8ade4bd5213894e021f134afbb71d 100644 --- a/js/fea/dmaPart.js +++ b/js/fea/dmaPart.js @@ -34,7 +34,7 @@ DMAPart.prototype._draw = function(){ this.mesh = this._makeMeshForType(this.type); - window.three.sceneAdd(this.mesh, false); + window.three.sceneAdd(this.mesh, "part"); }; DMAPart.prototype._makeMeshForType = function(type){ diff --git a/js/models/extrudeVisualizer.js b/js/models/extrudeVisualizer.js index e58d4c02b13ada65f7747cf1772a116c64e9e41a..10cf1691c2ee26898ff184454065329ed2835178 100644 --- a/js/models/extrudeVisualizer.js +++ b/js/models/extrudeVisualizer.js @@ -18,7 +18,7 @@ function ExtrudeVisualizer(){ mesh.position.x = profilePos.x; mesh.position.y = profilePos.y; mesh.position.z = profilePos.z; - window.three.sceneAdd(mesh, false); +// window.three.sceneAdd(mesh, false); meshes.push(mesh); }); window.three.render(); diff --git a/js/models/fillGeometry.js b/js/models/fillGeometry.js index dc9728532c7f221e0d3345fc8fc7b779f083f8d3..4c487024e7746f4f2d00c7a3504c99781b81a424 100644 --- a/js/models/fillGeometry.js +++ b/js/models/fillGeometry.js @@ -33,7 +33,7 @@ FillGeometry = Backbone.Model.extend({ var mesh = new THREE.Mesh(this.get("geometry"), this.get("material")); this.makeBoundingBoxHelper(mesh); this.set({mesh: mesh}); - window.three.sceneAdd(mesh); + window.three.sceneAdd(mesh, null); window.three.render(); //send new geometry out to workers diff --git a/js/models/threeModel.js b/js/models/threeModel.js index 627b5b8ba0ec70fa5db327a22ec6131008fb3607..cc38a6c7d2cfc4b7dc1e3a3d8f0c71359e9acc16 100644 --- a/js/models/threeModel.js +++ b/js/models/threeModel.js @@ -8,7 +8,11 @@ function ThreeModel(){ var camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 1, 4000); var scene = new THREE.Scene(); var renderer = new THREE.WebGLRenderer({antialias:false}); - var objects = []; + + //store all meshes to highlight + var cells = []; + var parts = []; + var basePlane = []; initialize(); @@ -45,19 +49,47 @@ function ThreeModel(){ render(); } - function sceneAdd(object, noInteraction){ + function sceneAdd(object, type){ scene.add(object); - if (noInteraction) return; - objects.push(object); + + if (type == "cell"){ + cells.push(object); + } else if (type == "part"){ + parts.push(object); + } else if (type == "basePlane"){ + basePlane.push(object); + } + } - function sceneRemove(object){ + function sceneRemove(object, type){ + var objectToRemove = object; if (object.parent && object.parent.type != "Scene") { objectToRemove = object.parent; } + + if (type == "cell"){ + cells.splice(cells.indexOf(objectToRemove), 1); + } else if (type == "part"){ + parts.splice(parts.indexOf(objectToRemove), 1); + } else if (type == "basePlane"){ + console.log("not sure if i should be hitting this") + basePlane.splice(basePlane.indexOf(objectToRemove), 1); + } + scene.remove(objectToRemove); - objects.splice(objects.indexOf(objectToRemove), 1); + } + + function removeAllCells(){ + _.each(cells, function(cell){ + sceneRemove(cell, "cell"); + }); + _.each(parts, function(part){ + sceneRemove(part, "part"); + }); + cells = []; + parts = []; } function render(){ @@ -66,11 +98,14 @@ function ThreeModel(){ } return {//return public properties/methods - render:render, - sceneRemove:sceneRemove, - sceneAdd:sceneAdd, - domElement:renderer.domElement, - camera:camera, - objects:objects + render: render, + sceneRemove: sceneRemove, + sceneAdd: sceneAdd, + domElement: renderer.domElement, + camera: camera, + cells: cells, + parts: parts, + basePlane: basePlane, + removeAllCells: removeAllCells } } \ No newline at end of file diff --git a/js/threeViews/fillGeometryView.js b/js/threeViews/fillGeometryView.js deleted file mode 100644 index 3d5f0a459482b9a705a5a324f0f8924f8c2894eb..0000000000000000000000000000000000000000 --- a/js/threeViews/fillGeometryView.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Created by aghassaei on 1/16/15. - */ - - -FillGeometryView = PushPullMeshView.extend({ - - events: { - }, - - defaultColor: 0xf25536, - - initialize: function(options){ - - PushPullMeshView.prototype.initialize.apply(this, arguments); - - //bind events - this.listenTo(this.model, "change:geometry", this.newFillGeometry); - this.listenTo(this.model, "change:orientation", this.render); - - this.newFillGeometry(); - }, - - newFillGeometry: function(){ - if (this.model.previous("mesh")) this.three.sceneRemove(this.model.previous("mesh")); - this.three.sceneAdd(this.model.get("mesh")); - this.three.render(); - }, - - - - render: function(){ - this.three.render(); - } -}); \ No newline at end of file diff --git a/js/threeViews/pushPullMeshView.js b/js/threeViews/pushPullMeshView.js index 06d1b4da8403831a3210ca9e89f9829a787b221d..a1e2a53030efecbadb3afc4776d54ddb903b1e3a 100644 --- a/js/threeViews/pushPullMeshView.js +++ b/js/threeViews/pushPullMeshView.js @@ -34,7 +34,7 @@ PushPullMeshView = Backbone.View.extend({ this.boxHelper = new THREE.BoxHelper(this.boundsBox); this.boxHelper.material.color.set(this.defaultColor); - this.three.sceneAdd(this.boxHelper); +// this.three.sceneAdd(this.boxHelper); // this.three.sceneAdd(this.boundsBox); this.updateBounds(); }, diff --git a/js/threeViews/threeView.js b/js/threeViews/threeView.js index 646ee2cec2b3a89f97a35f3de25d7f839bc37603..7b33d5a44d490da3728369905c7d2340bd5a6a36 100644 --- a/js/threeViews/threeView.js +++ b/js/threeViews/threeView.js @@ -42,7 +42,7 @@ ThreeView = Backbone.View.extend({ //init highlighter this.highlighter = this._initHighlighter(); - window.three.sceneAdd(this.highlighter, true); + window.three.sceneAdd(this.highlighter, null); this.model.render(); this._animate(); @@ -105,7 +105,7 @@ ThreeView = Backbone.View.extend({ //check if we're intersecting anything - var intersections = this.mouseProjection.intersectObjects(this.model.objects, true); + var intersections = this.mouseProjection.intersectObjects(this.model.cells.concat(this.model.basePlane), true); if (intersections.length == 0) { this.currentIntersectedObject = null; this._hideHighlighter(); @@ -234,7 +234,7 @@ ThreeView = Backbone.View.extend({ geometry.computeFaceNormals(); var basePlane = new THREE.Mesh(geometry, planeMaterial); - window.three.sceneAdd(basePlane); + window.three.sceneAdd(basePlane, "basePlane"); window.three.render(); if (this.basePlane) this.basePlane = basePlane;