Skip to content
Snippets Groups Projects
Commit 438c42b5 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

face connected octahedra lattice

parent 53529de3
No related branches found
No related tags found
No related merge requests found
//a node, two for each dmaBeam, not to be confused with node.js //a node, two for each dmaBeam, not to be confused with node.js
function BeamNode() { function BeamNode(x, y, z) {
this._beams = [];//store all beams attached to this node, eventually this will be used to calc global stiffness K this._beams = [];//store all beams attached to this node, eventually this will be used to calc global stiffness K
this.x = x;
this.y = y;
this.z = z;
this.render();
} }
BeamNode.prototype.addBeam = function(beam){ BeamNode.prototype.addBeam = function(beam){
this._beams.push(beam); this._beams.push(beam);
}; };
BeamNode.prototype.render = function(scene){ BeamNode.prototype.render = function(){
var geometry = new THREE.SphereGeometry(2);
geometry.applyMatrix( new THREE.Matrix4().makeTranslation(this.x, this.y, this.z) );
var mesh = new THREE.Mesh(geometry);
window.three.sceneAdd(mesh);
}; };
...@@ -16,12 +26,20 @@ BeamNode.prototype.deflect = function(dx, dy, dz){ ...@@ -16,12 +26,20 @@ BeamNode.prototype.deflect = function(dx, dy, dz){
}; };
BeamNode.prototype.translate = function(dx, dy, dz){ BeamNode.prototype.translate = function(dx, dy, dz){
this.x += dx;
this.y += dy;
this.z += dz;
};
BeamNode.prototype.translateAbsolute = function(x, y, z){
this.x = x;
this.y = y;
this.z = z;
}; };
BeamNode.prototype.rotate = function(rx, ry, rz){ BeamNode.prototype.rotate = function(rx, ry, rz){
}; };
BeamNode.prototype.destroy = function(){ BeamNode.prototype.destroy = function(){
this._beam = null;//be sure to remove cyclic reference this._beams = null;//be sure to remove cyclic reference
this = null;
}; };
...@@ -10,15 +10,16 @@ $(function(){ ...@@ -10,15 +10,16 @@ $(function(){
//init threeJS //init threeJS
var threeModel = new ThreeModel(); var threeModel = new ThreeModel();
window.three = threeModel;
//backbone models and views //backbone models and views
var fillGeometry = new FillGeometry();//singleton, mesh to fill with lattice var fillGeometry = new FillGeometry();//singleton, mesh to fill with lattice
new ImportView({model: fillGeometry}); // new ImportView({model: fillGeometry});
var fillGeometryView = new FillGeometryView({model: fillGeometry, three:threeModel}); // var fillGeometryView = new FillGeometryView({model: fillGeometry, three:threeModel});
var lattice = new Lattice(); var lattice = new Lattice({fillGeometry:fillGeometry});
var latticeView = new LatticeView({model:lattice, three:threeModel, fillGeometry:fillGeometry}); var latticeView = new LatticeView({model:lattice, three:threeModel});
var highlightTargets = [latticeView]; var highlightTargets = [latticeView];
......
...@@ -6,21 +6,70 @@ ...@@ -6,21 +6,70 @@
Lattice = Backbone.Model.extend({ Lattice = Backbone.Model.extend({
defaults: { defaults: {
scale: 1.0, scale: 30.0,
translation: new THREE.Vector3(0,0,0), translation: new THREE.Vector3(0,0,0),
rotation: new THREE.Vector3(0,0,0), rotation: new THREE.Vector3(0,0,0),
type: "cube" type: "octagonFace",
nodes: [],
min: new THREE.Vector3(0,0,0),
max: new THREE.Vector3(0,0,0)
}, },
//pass in fillGeometry
initialize: function(){ initialize: function(){
//bind events
this.layoutNodes();
},
//bind events layoutNodes: function(type){
type = type || this.get("type");
var boundingBox = this.get("fillGeometry").get("boundingBoxHelper").box;
var scale = this.get("scale");
var nodes;
if (type == "octagonFace"){
nodes = this.faceConnectedOctahedra(boundingBox, scale);
} else {
console.log("no type");
} }
this.set("nodes", nodes);
},
faceConnectedOctahedra: function(boundingBox, scale){
var scaleSqrt3 = scale/2*Math.sqrt(3);
var dimX = Math.round((boundingBox.max.x-boundingBox.min.x)/scale);
var dimY = Math.round((boundingBox.max.y-boundingBox.min.y)/scaleSqrt3);
var dimZ = Math.round((boundingBox.max.z-boundingBox.min.z)/scaleSqrt3);
var nodes = [];
for (var x=0; x<=dimX; x++){
if (nodes.length<=x) nodes[x] = [];
for (var y=0; y<=dimY; y++){
if (nodes[x].length<=y) nodes[x][y] = [];
for (var z=0; z<=dimZ; z++){
var xOffset = 0;
if (y%2 == 1) xOffset = scale/2;
var yOffset = 0;
if (z%2 == 1) yOffset = scaleSqrt3/2;
nodes[x][y][z] = new BeamNode(boundingBox.min.x+ xOffset + scale*x,
boundingBox.min.y + yOffset + scaleSqrt3*y,
boundingBox.min.z + z*scaleSqrt3);
}
}
}
return nodes;
}
}); });
\ No newline at end of file
...@@ -48,32 +48,32 @@ ThreeView = Backbone.View.extend({ ...@@ -48,32 +48,32 @@ ThreeView = Backbone.View.extend({
mouseDown: function(e){ mouseDown: function(e){
this.mouseIsDown = true; this.mouseIsDown = true;
//
var vector = new THREE.Vector2(2*(e.pageX-this.$el.offset().left)/this.$el.width()-1, 1-2*(e.pageY-this.$el.offset().top)/this.$el.height()); // var vector = new THREE.Vector2(2*(e.pageX-this.$el.offset().left)/this.$el.width()-1, 1-2*(e.pageY-this.$el.offset().top)/this.$el.height());
var camera = this.model.camera; // var camera = this.model.camera;
this.mouseProjection.setFromCamera(vector, camera); // this.mouseProjection.setFromCamera(vector, camera);
var intersections = this.mouseProjection.intersectObjects(this.model.objects); // var intersections = this.mouseProjection.intersectObjects(this.model.objects);
//
console.log(intersections); // console.log(intersections);
//
if (intersections.length>1){ // if (intersections.length>1){
var voxel = new THREE.Mesh(this.cubeGeometry); // var voxel = new THREE.Mesh(this.cubeGeometry);
voxel.position.copy(intersections[1].point); // voxel.position.copy(intersections[1].point);
if (intersections[1].face) voxel.position.add(intersections[1].face.normal); // if (intersections[1].face) voxel.position.add(intersections[1].face.normal);
voxel.position.divideScalar(5).floor().multiplyScalar(5).addScalar(2.5); // voxel.position.divideScalar(5).floor().multiplyScalar(5).addScalar(2.5);
this.model.sceneAdd(voxel); // this.model.sceneAdd(voxel);
this.model.render(); // this.model.render();
} // }
}, },
mouseMoved: function(e){ mouseMoved: function(e){
if (this.mouseIsDown) return;//in the middle of a drag event // if (this.mouseIsDown) return;//in the middle of a drag event
var vector = new THREE.Vector2(2*(e.pageX-this.$el.offset().left)/this.$el.width()-1, 1-2*(e.pageY-this.$el.offset().top)/this.$el.height()); // var vector = new THREE.Vector2(2*(e.pageX-this.$el.offset().left)/this.$el.width()-1, 1-2*(e.pageY-this.$el.offset().top)/this.$el.height());
var camera = this.model.camera; // var camera = this.model.camera;
this.mouseProjection.setFromCamera(vector, camera); // this.mouseProjection.setFromCamera(vector, camera);
var intersections = this.mouseProjection.intersectObjects(this.model.objects); // var intersections = this.mouseProjection.intersectObjects(this.model.objects);
//
//
// _.each(this.highlightTargets, function(target){ // _.each(this.highlightTargets, function(target){
// target.checkHighlight(intersections); // target.checkHighlight(intersections);
// }); // });
......
...@@ -39,6 +39,12 @@ ...@@ -39,6 +39,12 @@
<script src="js/worker.js"></script> <script src="js/worker.js"></script>
<script src="js/persistentWorkers.js"></script><!--global workers--> <script src="js/persistentWorkers.js"></script><!--global workers-->
<!--fea stuff-->
<script src="js/fea/dmaCell.js"></script>
<!--<script src="js/fea/dmaPart.js"></script>-->
<!--<script src="js/fea/dmaBeam.js"></script>-->
<script src="js/fea/dmaNode.js"></script>
<!--models--> <!--models-->
<script src="js/models/threeModel.js"></script> <script src="js/models/threeModel.js"></script>
<script src="js/models/fillGeometry.js"></script> <script src="js/models/fillGeometry.js"></script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment