Commit d9f9ae2a authored by amandaghassaei's avatar amandaghassaei
Browse files

fixed object3d stuff

parent e8deb63d
......@@ -84,12 +84,12 @@ function init3DUI(globals) {
function setHighlightedObj(object){
if (highlightedObj && (object != highlightedObj)) {
highlightedObj.unhighlight();
// highlightedObj.unhighlight();
highlighter1.getObject3D().visible = false;
}
highlightedObj = object;
if (highlightedObj) {
highlightedObj.highlight();
// highlightedObj.highlight();
highlighter1.getObject3D().visible = true;
}
}
......
......@@ -2,8 +2,8 @@
* Created by ghassaei on 9/16/16.
*/
var beamMaterialHighlight = new THREE.LineBasicMaterial({color: 0xff0000, linewidth: 1});
var beamMaterial = new THREE.LineBasicMaterial({color: 0x000000, linewidth: 1});
// var beamMaterialHighlight = new THREE.LineBasicMaterial({color: 0xff0000, linewidth: 1});
// var beamMaterial = new THREE.LineBasicMaterial({color: 0x000000, linewidth: 1});
function Beam(nodes){
......@@ -11,26 +11,25 @@ function Beam(nodes){
nodes[0].addBeam(this);
nodes[1].addBeam(this);
this.vertices = [nodes[0].getPosition(), nodes[1].getPosition()];
this.vertices = [nodes[0]._originalPosition, nodes[1]._originalPosition];
this.nodes = nodes;
var lineGeometry = new THREE.Geometry();
lineGeometry.dynamic = true;
lineGeometry.vertices = this.vertices;
// var lineGeometry = new THREE.Geometry();
// lineGeometry.dynamic = true;
// lineGeometry.vertices = this.vertices;
this.object3D = new THREE.Line(lineGeometry, beamMaterial);
this.object3D._myBeam = this;
// this.object3D = new THREE.Line(lineGeometry, beamMaterial);
this.originalLength = this.getLength();
}
Beam.prototype.highlight = function(){
this.object3D.material = beamMaterialHighlight;
};
Beam.prototype.unhighlight = function(){
this.object3D.material = beamMaterial;
};
// Beam.prototype.highlight = function(){
// this.object3D.material = beamMaterialHighlight;
// };
//
// Beam.prototype.unhighlight = function(){
// this.object3D.material = beamMaterial;
// };
Beam.prototype.getLength = function(){
return this.getVector().length();
......@@ -51,9 +50,9 @@ Beam.prototype.getVector = function(fromNode){
return this.vertices[1].clone().sub(this.vertices[0]);
};
Beam.prototype.setVisibility = function(state){
this.object3D.visible = state;
};
// Beam.prototype.setVisibility = function(state){
// this.object3D.visible = state;
// };
......@@ -82,29 +81,29 @@ Beam.prototype.getOtherNode = function(node){
return this.nodes[0];
};
var valleyColor = new THREE.LineBasicMaterial({color:0x0000ff});
var mtnColor = new THREE.LineBasicMaterial({color:0xff0000});
// var valleyColor = new THREE.LineBasicMaterial({color:0x0000ff});
// var mtnColor = new THREE.LineBasicMaterial({color:0xff0000});
Beam.prototype.setMountain = function(){
this.object3D.material = mtnColor;
};
Beam.prototype.setValley = function(){
this.object3D.material = valleyColor;
};
// Beam.prototype.setMountain = function(){
// this.object3D.material = mtnColor;
// };
//
// Beam.prototype.setValley = function(){
// this.object3D.material = valleyColor;
// };
//render
Beam.prototype.getObject3D = function(){
return this.object3D;
};
// Beam.prototype.getObject3D = function(){
// return this.object3D;
// };
Beam.prototype.render = function(shouldComputeLineDistance){
this.object3D.geometry.verticesNeedUpdate = true;
this.object3D.geometry.computeBoundingSphere();
if (shouldComputeLineDistance) this.object3D.geometry.computeLineDistances();//for dashed lines
};
// Beam.prototype.render = function(shouldComputeLineDistance){
// this.object3D.geometry.verticesNeedUpdate = true;
// this.object3D.geometry.computeBoundingSphere();
// if (shouldComputeLineDistance) this.object3D.geometry.computeLineDistances();//for dashed lines
// };
......@@ -117,7 +116,6 @@ Beam.prototype.destroy = function(){
node.removeBeam(self);
});
this.vertices = null;
this.object3D._myBeam = null;
this.object3D = null;
// this.object3D = null;
this.nodes = null;
};
\ No newline at end of file
......@@ -236,7 +236,7 @@ function initModel(globals){
vertices = [];
for (var i=0;i<nodes.length;i++){
vertices.push(nodes[i].getPosition());
vertices.push(nodes[i].getOriginalPosition());
}
if (globals.noCreasePatternAvailable() && globals.navMode == "pattern"){
......@@ -283,15 +283,14 @@ function initModel(globals){
_.each(lineGeometries, function(lineGeometry){
lineGeometry.addAttribute('position', positionsAttribute);
lineGeometry.setIndex(new THREE.BufferAttribute(lineIndices, 1));
lineGeometry.computeBoundingBox();
lineGeometry.computeBoundingSphere();
lineGeometry.center();
// lineGeometry.computeBoundingBox();
// lineGeometry.computeBoundingSphere();
// lineGeometry.center();
});
var scale = 1/geometry.boundingSphere.radius;
globals.scale = scale;
//scale geometry
for (var i=0;i<positions.length;i++){
positions[i] *= scale;
......
......@@ -17,44 +17,33 @@ function Node(position, index){
this.index = index;
this._originalPosition = position.clone();
this.object3D = new THREE.Mesh(nodeGeo, nodeMaterial);
this.object3D._myNode = this;
this.object3D.visible = false;
this.beams = [];
this.creases = [];
this.invCreases = [];
this.externalForce = null;
this.fixed = false;
this.render(new THREE.Vector3(0,0,0));
// this.render(new THREE.Vector3(0,0,0));
}
Node.prototype.setFixed = function(fixed){
this.fixed = fixed;
if (fixed) {
this.object3D.material = nodeMaterialFixed;
this.object3D.geometry = nodeFixedGeo;
if (this.externalForce) this.externalForce.hide();
}
else {
this.object3D.material = nodeMaterial;
this.object3D.geometry = nodeGeo;
if (this.externalForce) this.externalForce.show();
}
// if (fixed) {
// this.object3D.material = nodeMaterialFixed;
// this.object3D.geometry = nodeFixedGeo;
// if (this.externalForce) this.externalForce.hide();
// }
// else {
// this.object3D.material = nodeMaterial;
// this.object3D.geometry = nodeGeo;
// if (this.externalForce) this.externalForce.show();
// }
};
Node.prototype.isFixed = function(){
return this.fixed;
};
Node.prototype.moveManually = function(position){
this.object3D.position.set(position.x, position.y, position.z);
_.each(this.beams, function(beam){
beam.render();
});
};
......@@ -130,49 +119,57 @@ Node.prototype.getObject3D = function(){
return this.object3D;
};
Node.prototype.highlight = function(){
this.object3D.material = nodeMaterialHighlight;
};
Node.prototype.unhighlight = function(){
if (!this.object3D) return;
if (this.fixed) {
this.object3D.material = nodeMaterialFixed;
}
else {
this.object3D.material = nodeMaterial;
}
};
// Node.prototype.highlight = function(){
// this.object3D.material = nodeMaterialHighlight;
// };
//
// Node.prototype.unhighlight = function(){
// if (!this.object3D) return;
// if (this.fixed) {
// this.object3D.material = nodeMaterialFixed;
// }
// else {
// this.object3D.material = nodeMaterial;
// }
// };
Node.prototype.setTransparent = function(){
if (!this.object3D){
this.object3D = new THREE.Mesh(nodeGeo, nodeMaterial);
this.object3D.visible = false;
}
this.object3D.material = transparentMaterial;
};
Node.prototype.setTransparentVR = function(){
if (!this.object3D){
this.object3D = new THREE.Mesh(nodeGeo, nodeMaterial);
this.object3D.visible = false;
}
this.object3D.material = transparentVRMaterial;
this.object3D.scale.set(0.4, 0.4, 0.4);
};
Node.prototype.hide = function(){
this.object3D.visible = false;
};
// Node.prototype.hide = function(){
// this.object3D.visible = false;
// };
Node.prototype.render = function(position){
// Node.prototype.render = function(position){
// if (this.fixed) return;
position.add(this.getOriginalPosition());
// position.add(this.getOriginalPosition());
// console.log(position);
this.object3D.position.set(position.x, position.y, position.z);//todo need this?
return position;
};
Node.prototype.renderDelta = function(delta){
// if (this.fixed) return;
this.object3D.position.add(delta);
return this.object3D.position;
};
// this.object3D.position.set(position.x, position.y, position.z);
// return position;
// };
// Node.prototype.renderDelta = function(delta){
// // if (this.fixed) return;
// this.object3D.position.add(delta);
// return this.object3D.position;
// };
Node.prototype.renderChange = function(change){
this.object3D.position.add(change);
};
// Node.prototype.renderChange = function(change){
// this.object3D.position.add(change);
// };
......@@ -191,11 +188,21 @@ Node.prototype.setOriginalPosition = function(x, y, z){
};
Node.prototype.getPosition = function(){
return this.object3D.position;
var positions = globals.model.getPositionsArray();
var i = this.getIndex();
return new THREE.Vector3(positions[3*i], positions[3*i+1], positions[3*i+2]);
};
Node.prototype.moveManually = function(position){
var positions = globals.model.getPositionsArray();
var i = this.getIndex();
positions[3*i] = position.x;
positions[3*i+1] = position.y;
positions[3*i+2] = position.z;
};
Node.prototype.getRelativePosition = function(){
return this.object3D.position.clone().sub(this._originalPosition);
return this.getPosition().sub(this._originalPosition);
};
Node.prototype.getSimMass = function(){
......@@ -210,7 +217,6 @@ Node.prototype.getSimMass = function(){
Node.prototype.destroy = function(){
//object3D is removed in outer scope
this.object3D._myNode = null;
this.object3D = null;
this.beams = null;
this.creases = null;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment