diff --git a/js/cells/OctaRotEdgeCell.js b/js/cells/OctaRotEdgeCell.js index 8348f9748c5e8555b6639b2757a114a89c214e0b..c41c0a5626714a449cdd35b7f6705fdff62c32cc 100644 --- a/js/cells/OctaRotEdgeCell.js +++ b/js/cells/OctaRotEdgeCell.js @@ -14,18 +14,20 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], } OctaRotEdgeCell.prototype = Object.create(DMACell.prototype); - OctaRotEdgeCell.prototype._initParts = function(){ - var type = globals.lattice.get("partType"); - var newParts = []; - if (type == "vox"){ - newParts.push(new OctaEdgeVoxPart(0, this)); - } else if (type == "voxLowPoly"){ - newParts.push(new OctaEdgeVoxPartLowPoly(0, this)); - } else { - console.warn("part type " + type + " not recognized"); - return; - } - return newParts; + OctaRotEdgeCell.prototype._initParts = function(callback){ + var self = this; + var type = lattice.get("partType"); + if (type == "vox") type = "octaEdgeVoxPart"; + else if (type == "voxLowPoly") type = "octaEdgeVoxPartLowPoly"; + else console.warn("no part type " + type); + + require([type], function(OctaEdgeVoxPart){ + var parts = []; + for (var i=0;i<3;i++){ + parts.push(new OctaEdgeVoxPart(0, self)); + } + callback(parts); + }); }; OctaRotEdgeCell.prototype._getGeometry = function(){ diff --git a/js/main.js b/js/main.js index 747616d71cfc64331f5b2fc88a02f0f60d40b792..353360c4b276be1d92dbb03e39c91fb8780078df 100644 --- a/js/main.js +++ b/js/main.js @@ -71,6 +71,8 @@ require.config({ //parts part: 'parts/DMAPart', octaFaceTriPart: 'parts/OctaFaceTriPart', + octaEdgeVoxPart: 'parts/OctaEdgeVoxPart', + octaEdgeVoxPartLowPoly: 'parts/OctaEdgeVoxPartLowPoly', //materials materials: 'materials/DMAMaterials', @@ -96,7 +98,10 @@ require.config({ sendMenu: 'menus/SendMenuView', //stls - octaFaceTrianglePart: '../assets/stls/parts/trianglePart.stl' + bin: 'bin', + octaFaceTrianglePartSTL: '../assets/stls/parts/trianglePart.stl', + octaEdgeVoxPartSTL: '../assets/stls/parts/edgeVoxPart.stl', + octaEdgeVoxPartLowPolySTL: '../assets/stls/parts/edgeVoxPartLowPoly.stl' }, diff --git a/js/parts/OctaEdgeVoxPart.js b/js/parts/OctaEdgeVoxPart.js index 792e1c5c96c982bc946bbfd2d34ff720f88de721..96965123377d3371c2b062d80d2edd229d04e802 100644 --- a/js/parts/OctaEdgeVoxPart.js +++ b/js/parts/OctaEdgeVoxPart.js @@ -2,22 +2,16 @@ * Created by aghassaei on 5/26/15. */ +define(['underscore', 'three', 'part', 'bin!octaEdgeVoxPartSTL', 'stlLoader'], function(_, THREE, DMAPart, voxPart){ -(function () { - - var unitPartGeo; - - //import part geometry var loader = new THREE.STLLoader(); - loader.load("assets/stls/parts/edgeVoxPart.stl", function(geometry){ - - unitPartGeo = geometry; - unitPartGeo.computeBoundingBox(); - var unitScale = 0.706/unitPartGeo.boundingBox.max.y; - unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); - unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationY(Math.PI)); - unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,0.09)); - }); + var unitGeo = loader.parse(voxPart); + unitGeo.computeBoundingBox(); + var unitScale = 0.706/unitGeo.boundingBox.max.y; + unitGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); + unitGeo.applyMatrix(new THREE.Matrix4().makeRotationY(Math.PI)); + unitGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,0.09)); + unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4)); function OctaEdgeVoxPart(type, parent){ DMAPart.call(this, type, parent); @@ -25,36 +19,8 @@ OctaEdgeVoxPart.prototype = Object.create(DMAPart.prototype); OctaEdgeVoxPart.prototype._getGeometry = function(){ - return unitPartGeo; - }; - - self.OctaEdgeVoxPart = OctaEdgeVoxPart; - -})(); - -(function () { - - var unitPartGeo; - - //import part geometry - var loader = new THREE.STLLoader(); - loader.load("assets/stls/parts/edgeVoxPartLowPoly.stl", function(geometry){ - - unitPartGeo = geometry; - unitPartGeo.computeBoundingBox(); - var unitScale = 0.706/unitPartGeo.boundingBox.max.y; - unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); - }); - - function OctaEdgeVoxPartLowPoly(type, parent){ - DMAPart.call(this, type, parent); - } - OctaEdgeVoxPartLowPoly.prototype = Object.create(DMAPart.prototype); - - OctaEdgeVoxPartLowPoly.prototype._getGeometry = function(){ - return unitPartGeo; + return unitGeo; }; - self.OctaEdgeVoxPartLowPoly = OctaEdgeVoxPartLowPoly; - -})(); \ No newline at end of file + return OctaEdgeVoxPart; +}); \ No newline at end of file diff --git a/js/parts/OctaEdgeVoxPartLowPoly.js b/js/parts/OctaEdgeVoxPartLowPoly.js new file mode 100644 index 0000000000000000000000000000000000000000..8f6d785a758b8070042dcab132bdfa96362ec732 --- /dev/null +++ b/js/parts/OctaEdgeVoxPartLowPoly.js @@ -0,0 +1,24 @@ +/** + * Created by aghassaei on 6/8/15. + */ + + +define(['underscore', 'three', 'part', 'bin!octaEdgeVoxPartLowPolySTL', 'stlLoader'], function(_, THREE, DMAPart, voxLowPoly){ + + var loader = new THREE.STLLoader(); + var unitGeo = loader.parse(voxLowPoly); + unitGeo.computeBoundingBox(); + var unitScale = 0.706/unitGeo.boundingBox.max.y; + unitGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); + + function OctaEdgeVoxPartLowPoly(type, parent){ + DMAPart.call(this, type, parent); + } + OctaEdgeVoxPartLowPoly.prototype = Object.create(DMAPart.prototype); + + OctaEdgeVoxPartLowPoly.prototype._getGeometry = function(){ + return unitGeo; + }; + + return OctaEdgeVoxPartLowPoly; +}); \ No newline at end of file diff --git a/js/parts/OctaFaceTriPart.js b/js/parts/OctaFaceTriPart.js index 339f49ada0846a0149b536933d4653ee9d4ad3e8..b9c63dc7ec72b8ee4a8c39a6dbef7c9fd3c83171 100644 --- a/js/parts/OctaFaceTriPart.js +++ b/js/parts/OctaFaceTriPart.js @@ -3,7 +3,7 @@ */ -define(['underscore', 'three', 'part', 'bin!octaFaceTrianglePart', 'stlLoader'], function(_, THREE, DMAPart, trianglePart){ +define(['underscore', 'three', 'part', 'bin!octaFaceTrianglePartSTL', 'stlLoader'], function(_, THREE, DMAPart, trianglePart){ var loader = new THREE.STLLoader(); var unitGeo = loader.parse(trianglePart); @@ -19,7 +19,6 @@ define(['underscore', 'three', 'part', 'bin!octaFaceTrianglePart', 'stlLoader'], OctaFaceTriPart.prototype = Object.create(DMAPart.prototype); OctaFaceTriPart.prototype._getGeometry = function(){ - if (!unitGeo || unitGeo === undefined) console.warn("geo not loaded yet"); return unitGeo; };