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

part scaling

parent b6dcbe2c
No related branches found
No related tags found
No related merge requests found
......@@ -34,20 +34,8 @@
globalCellScale = scale;
cellGeometry1 = unitCellGeo1.clone();
cellGeometry1.applyMatrix(new THREE.Matrix4().makeScale(scale, scale, scale));
setFlags(cellGeometry1);
cellGeometry2 = unitCellGeo2.clone();
cellGeometry2.applyMatrix(new THREE.Matrix4().makeScale(scale, scale, scale));
setFlags(cellGeometry2);
}
function setFlags(geometry){
geometry.verticesNeedUpdate = true;
geometry.elementsNeedUpdate = true;
geometry.morphTargetsNeedUpdate = true;
geometry.uvsNeedUpdate = true;
geometry.normalsNeedUpdate = true;
geometry.colorsNeedUpdate = true;
geometry.tangentsNeedUpdate = true;
}
function DMACell(mode, indices, scale) {
......@@ -125,7 +113,17 @@
};
DMACell.prototype.changeScale = function(scale){
if (globalCellScale != scale) setGlobalCellScale(scale);
//update geometry
if (globalCellScale != scale) {
setGlobalCellScale(scale);
}
if (this.indices.z%2==0){
this._updateVertices(cellGeometry1.vertices);
} else {
this._updateVertices(cellGeometry2.vertices);
}
var position = this._calcPosition(scale, this.indices);
this._setMeshPosition(this.cellMesh, position);
_.each(this.parts, function(part){
......@@ -133,6 +131,13 @@
});
};
DMACell.prototype._updateVertices = function(vertices){
_.each(this.cellMesh.children, function(mesh){
mesh.geometry.vertices = vertices;
mesh.geometry.verticesNeedUpdate = true;
});
};
DMACell.prototype.remove = function(){
if (this.cellMesh) window.three.sceneRemove(this.cellMesh);
};
......
......@@ -12,16 +12,25 @@
loader.addEventListener('load', onMeshLoad);
loader.load("data/trianglePart.stl");
var unitPartGeo;
var partGeometry;
var globalPartScale = 30;
function onMeshLoad(e){
console.log("part loaded");
partGeometry = e.content;
partGeometry.computeBoundingBox();
var unitScale = 1/partGeometry.boundingBox.max.y;
partGeometry.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
partGeometry.applyMatrix(new THREE.Matrix4().makeTranslation(0.2,-0.5, 0));
partGeometry.applyMatrix(new THREE.Matrix4().makeRotationZ(-Math.PI/6));
partGeometry.applyMatrix(new THREE.Matrix4().makeScale(30,30,30));
unitPartGeo = e.content;
unitPartGeo.dynamic = true;
unitPartGeo.computeBoundingBox();
var unitScale = 1/unitPartGeo.boundingBox.max.y;
unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0.2,-0.5, 0));
unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(-Math.PI/6));
setGlobalPartScale(globalPartScale)
}
function setGlobalPartScale(scale){
globalPartScale = scale;
partGeometry = unitPartGeo.clone();
partGeometry.applyMatrix(new THREE.Matrix4().makeScale(scale,scale,scale));
}
function DMAPart(type, position, oddZFlag) {
......@@ -65,8 +74,13 @@
};
DMAPart.prototype.changeScale = function(scale, position){
if (globalPartScale != scale) setGlobalPartScale(scale);
this.position = position;
if (this.mesh) this._setMeshPosition(this.mesh, scale, position);
if (this.mesh) {
this._setMeshPosition(this.mesh, scale, position);
this.mesh.geometry.vertices = partGeometry.vertices;
this.mesh.geometry.verticesNeedUpdate = true;
}
};
DMAPart.prototype.show = function(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment