diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index bd26ec84a7468b66b674bd3705c593c5f27c6d72..ac736405c0b4bdae8078c7feef88b8e77469d489 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -3,8 +3,8 @@ */ -define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], - function(_, THREE, three, lattice, appState){ +define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], + function(_, THREE, three, lattice, appState, globals){ var wireframeMaterial = new THREE.MeshBasicMaterial({color:0x000000, wireframe:true}); @@ -12,12 +12,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], if (index) this.index = new THREE.Vector3(index.x, index.y, index.z); if (superCell) this.superCell = superCell; - this.material = this.getMaterial();//material key, not a Material object + if (!this.cells) this.material = lattice.get("materialType"); //object 3d is parent to all 3d elements owned by cell: cell mesh and wireframe, parts, beams, nodes, etc this.object3D = this._buildObject3D(); this.addChildren(this._buildMesh(), this.object3D);//build cell meshes - this.superCell.addChildren(this.object3D);//add as child of supercell + + if (this.superCell) this.superCell.addChildren(this.object3D);//add as child of supercell if (superCell === undefined) { if (this.index) three.sceneAdd(this.object3D); @@ -59,7 +60,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], var geometry = this._getGeometry(); var meshes = []; - var mesh = new THREE.Mesh(geometry, this.getMaterial()); + var mesh = new THREE.Mesh(geometry, this._getMaterial()); mesh.name = this._getMeshName(); meshes.push(mesh); @@ -85,10 +86,18 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], //position/index/rotation DMACell.prototype.getIndex = function(){ + if (!this.index) { + console.warn("no index for this cell"); + return null; + } return this.index.clone(); }; DMACell.prototype.getAbsoluteIndex = function(){ + if (!this.index) { + console.warn("no index for this cell"); + return null; + } if (!this.superCell) return this.getIndex(); return this.superCell.getAbsoluteIndex().add(this.superCell.applyRotation(this.getIndex())); }; @@ -165,8 +174,19 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], this.setMode(mode); }; - DMACell.prototype.getMaterial = function(){ - return lattice.get("materialType"); + DMACell.prototype._getMaterial = function(){ + if (!this.material) console.warn("no material for cell"); + var materialClass = lattice.get("materialClass"); + if (!globals.materials[materialClass]) { + console.warn("no material class found of type " + materialClass); + return null; + } + var material = globals.materials[materialClass].materials[this.material]; + if (!material){ + console.warn("no material "+ this.material + " found for class "+ materialClass); + return null; + } + return material; }; DMACell.prototype.setOpacity = function(opacity){ @@ -203,7 +223,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], _.each(this.object3D.children, function(child){ if (child.name == "object3D") return; - child.visible = child.name == visible && mode; + child.visible = visible && (child.name == mode); }); }; diff --git a/js/cells/OctaFaceCell.js b/js/cells/OctaFaceCell.js index 245b5881c5757f27c9ec9c6351c8236f75403e3d..db85c6402f5c1012bd70f1832442e508d1866b81 100644 --- a/js/cells/OctaFaceCell.js +++ b/js/cells/OctaFaceCell.js @@ -15,21 +15,22 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], } OctaFaceCell.prototype = Object.create(DMACell.prototype); - OctaFaceCell.prototype._initParts = function(){ - var parts = []; - for (var i=0;i<3;i++){ - parts.push(new OctaFaceTriPart(i, this)); - } - return parts; + OctaFaceCell.prototype._getGeometry = function(){ + return unitGeo; }; OctaFaceCell.prototype._rotateCell = function(object3D){ - if (this.index && this.index.z%2!=0) object3D.rotation.set(0, 0, Math.PI); + if (!this.index) return object3D; + if (this.getAbsoluteIndex().z%2 != 0) object3D.rotation.set(0, 0, Math.PI); return object3D; }; - OctaFaceCell.prototype._getGeometry = function(){ - return unitGeo; + OctaFaceCell.prototype._initParts = function(){ + var parts = []; + for (var i=0;i<3;i++){ + parts.push(new OctaFaceTriPart(i, this)); + } + return parts; }; OctaFaceCell.prototype.calcHighlighterPosition = function(face){ diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index f2493b379014d554377a7cce60f33a5df5314d97..dac2e1fe82c9cf64a0605221ca4bbdec7e5243ce 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -23,10 +23,11 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //spacing for connectors/joints cellSeparation: {xy:0, z:0}, - cellType: "cube", - connectionType: "gik", - partType: "lego", - materialType: "fiberGlass", + cellType: "octa", + connectionType: "face", + partType: "triangle", + materialType: "brass", + materialClass: "electronic", superCellRange: new THREE.Vector3(4,1,1) }, @@ -44,6 +45,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this.listenTo(appState, "change:cellMode", this._updateForMode); this.listenTo(appState, "change:cellsVisible", this._setCellVisibility); + this.listenTo(this, "change:materialClass", this._loadMaterialClass); + this._updateLatticeType(false); }, @@ -368,6 +371,14 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre else console.warn("placing a cell that does not exist"); }, + _loadMaterialClass: function(){ + var materialClass = this.get("materialClass"); + if (globals.materials[materialClass]) return;//already loaded + require([materialClass + "Materials"], function(MaterialClass){ + globals.materials[materialClass] = MaterialClass; + }); + }, + //////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////CONNECTION TYPE////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// @@ -376,6 +387,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this._setToDefaultsSilently(); this._setDefaultCellMode(); + this._loadMaterialClass(); if (loadingFromFile === undefined) loadingFromFile = false; if (loadingFromFile) console.warn('loading from file'); diff --git a/js/main.js b/js/main.js index 2e3812e3338c3003bf6a840d837373f8b2cf00b3..a46871011155c26285e2b7ba7ae92c96eaf6bc15 100644 --- a/js/main.js +++ b/js/main.js @@ -33,7 +33,7 @@ require.config({ octaEdgeLattice: 'lattice/OctaEdgeLattice', octaFaceLattice: 'lattice/OctaFaceLattice', octaRotEdgeLattice: 'lattice/OctaRotEdgeLattice', - octavertexLattice: 'lattice/OctaVertexLattice', + octaVertexLattice: 'lattice/OctaVertexLattice', truncatedCubeLattice: 'lattice/TruncatedCubeLattice', //baseplane diff --git a/js/models/Globals.js b/js/models/Globals.js index fed044454058ac650002c795dcf400d333c5d224..beea4614ad4145e87ca1faaeb2b496f921df8558 100644 --- a/js/models/Globals.js +++ b/js/models/Globals.js @@ -4,9 +4,9 @@ //globals namespace, not sure if there's a way to get around this -define(function() { - return { +define({ baseplane: null, - highlighter: null - }; -}); \ No newline at end of file + highlighter: null, + materials: {} + } +); \ No newline at end of file