Commit 8da8f6bb authored by amandaghassaei's avatar amandaghassaei
Browse files

remove face3

parent a55eebe7
......@@ -219,7 +219,7 @@ function initControls(globals){
var creaseParams = [];
for (var j=0;j<faces.length;j++){
var face = faces[j];
var faceVerts = [face.a, face.b, face.c];
var faceVerts = [face[0], face[1], face[2]];
var v1Index = faceVerts.indexOf(v1);
if (v1Index>=0){
var v2Index = faceVerts.indexOf(v2);
......@@ -269,10 +269,6 @@ function initControls(globals){
function parseTXTjson(json){
_.each(json.faceNodeIndices, function(face, i){
json.faceNodeIndices[i] = new THREE.Face3(face[0], face[1], face[2]);
});
var faces = json.faceNodeIndices;
var allCreaseParams = [];
......@@ -282,7 +278,7 @@ function initControls(globals){
var creaseParams = [];
for (var j=0;j<faces.length;j++){
var face = faces[j];
var faceVerts = [face.a, face.b, face.c];
var faceVerts = [face[0], face[1], face[2]];
var v1Index = faceVerts.indexOf(v1);
if (v1Index>=0){
var v2Index = faceVerts.indexOf(v2);
......
......@@ -10,6 +10,8 @@ function initDynamicSolver(globals){
var edges;
var faces;
var creases;
var positions;
var colors;
var originalPosition;
var position;
......@@ -36,6 +38,10 @@ function initDynamicSolver(globals){
faces = globals.model.getFaces();
creases = globals.model.getCreases();
globals.model.sync();
positions = globals.model.getPositionsArray();
colors = globals.model.getColorsArray();
initTypedArrays();
initTexturesAndPrograms(globals.gpuMath);
steps = parseInt(setSolveParams());
......@@ -163,12 +169,8 @@ function initDynamicSolver(globals){
var pixels = new Uint8Array(height*textureDim*4*vectorLength);
globals.gpuMath.readPixels(0, 0, textureDim * vectorLength, height, pixels);
var parsedPixels = new Float32Array(pixels.buffer);
var positions = globals.model.getPositionsArray();
var globalError = 0;
var colors;
if (globals.colorMode == "axialStrain"){
colors = globals.model.getColorsArray();
}
var shouldUpdateColors = globals.colorMode == "axialStrain";
for (var i = 0; i < nodes.length; i++) {
var rgbaIndex = i * vectorLength;
var nodeError = parsedPixels[rgbaIndex+3];
......@@ -178,7 +180,7 @@ function initDynamicSolver(globals){
positions[3*i] = nexPos.x;
positions[3*i+1] = nexPos.y;
positions[3*i+2] = nexPos.z;
if (colors){
if (shouldUpdateColors){
var scaledVal = (1-100*nodeError/globals.strainClip) * 0.7;
var color = new THREE.Color();
color.setHSL(scaledVal, 1, 0.5);
......@@ -438,9 +440,9 @@ function initDynamicSolver(globals){
for (var i=0;i<faces.length;i++){
var face = faces[i];
faceVertexIndices[4*i] = face.a;
faceVertexIndices[4*i+1] = face.b;
faceVertexIndices[4*i+2] = face.c;
faceVertexIndices[4*i] = face[0];
faceVertexIndices[4*i+1] = face[1];
faceVertexIndices[4*i+2] = face[2];
}
for (var i=0;i<textureDim*textureDim;i++){
......
......@@ -122,5 +122,5 @@ $(function() {
globals.dynamicSolver = initDynamicSolver(globals);
globals.pattern = initPattern(globals);
// globals.threeView.sceneAdd(raycasterPlane);
$(".demo[data-url='Tessellations/miura-ori.svg']").click();
$(".demo[data-url='Tessellations/waterbomb.svg']").click();
});
\ No newline at end of file
......@@ -16,6 +16,7 @@ function initModel(globals){
var positions;//place to store buffer geo vertex data
var colors;//place to store buffer geo vertex colors
var indices;
var nodes = [];
var faces = [];
var edges = [];
......@@ -29,7 +30,6 @@ function initModel(globals){
material = new THREE.MeshBasicMaterial({vertexColors: THREE.VertexColors, side:THREE.DoubleSide});
object3D2.visible = false;
} else {
//todo can't do this
material = new THREE.MeshPhongMaterial({shading:THREE.FlatShading, color:0xff0000, side:THREE.FrontSide});
material2 = new THREE.MeshPhongMaterial({shading:THREE.FlatShading, color:0x0000ff, side:THREE.BackSide});
material.color.setStyle( "#" + globals.color1);
......@@ -204,15 +204,33 @@ function initModel(globals){
}
oldCreases = null;
globals.threeView.sceneAddModel(object3D);
globals.threeView.sceneAddModel(object3D2);
globals.shouldSyncWithModel = true;
inited = true;
updateEdgeVisibility();
updateMeshVisibility();
if (globals.noCreasePatternAvailable() && globals.navMode == "pattern"){
//switch to simulation mode
$("#navSimulation").parent().addClass("open");
$("#navPattern").parent().removeClass("open");
$("#svgViewer").hide();
globals.navMode = "simulation";
}
}
function sync(){
var vertices = [];
for (var i=0;i<nodes.length;i++){
vertices.push(nodes[i].getPosition());
}
console.log(vertices.length);
positions = new Float32Array(vertices.length*3);
// var normals = new Float32Array(vertices.length*3);
colors = new Float32Array(vertices.length*3);
var indices = new Uint16Array(faces.length*3);
indices = new Uint16Array(faces.length*3);
for (var i=0;i<vertices.length;i++){
positions[3*i] = vertices[i].x;
......@@ -224,16 +242,15 @@ function initModel(globals){
}
for (var i=0;i<faces.length;i++){
var face = faces[i];
indices[3*i] = face.a;
indices[3*i+1] = face.b;//todo no need to make Face3
indices[3*i+2] = face.c;
// var vecA = vertices[face.c].clone().sub(vertices[face.b]);
// var vecB = vertices[face.a].clone().sub(vertices[face.b]);
// var normal = (vecA.cross(vecB)).normalize();
indices[3*i] = face[0];
indices[3*i+1] = face[1];
indices[3*i+2] = face[2];
}
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
// geometry.addAttribute('normal', new THREE.BufferAttribute(normals, 3));
geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3));
geometry.attributes.position.needsUpdate = true;
geometry.attributes.color.needsUpdate = true;
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
geometry.computeVertexNormals();
......@@ -245,22 +262,6 @@ function initModel(globals){
for (var i=0;i<vertices.length;i++){
nodes[i].setOriginalPosition(positions[3*i], positions[3*i+1], positions[3*i+2]);
}
globals.threeView.sceneAddModel(object3D);
globals.threeView.sceneAddModel(object3D2);
globals.shouldSyncWithModel = true;
inited = true;
updateEdgeVisibility();
updateMeshVisibility();
if (globals.noCreasePatternAvailable() && globals.navMode == "pattern"){
//switch to simulation mode
$("#navSimulation").parent().addClass("open");
$("#navPattern").parent().removeClass("open");
$("#svgViewer").hide();
globals.navMode = "simulation";
}
}
function getNodes(){
......@@ -292,6 +293,7 @@ function initModel(globals){
updateMeshVisibility: updateMeshVisibility,
getGeometry: getGeometry,//for save stl
getPositionsArray: getPositionsArray,
getColorsArray: getColorsArray
getColorsArray: getColorsArray,
sync: sync
}
}
\ No newline at end of file
......@@ -184,7 +184,7 @@ function initPattern(globals){
var creaseParams = [];
for (var j=0;j<faces.length;j++){
var face = faces[j];
var faceVerts = [face.a, face.b, face.c];
var faceVerts = [face[0], face[1], face[2]];
var v1Index = faceVerts.indexOf(v1);
if (v1Index>=0){
var v2Index = faceVerts.indexOf(v2);
......@@ -309,7 +309,7 @@ function initPattern(globals){
var triangles = earcut(polyVerts);
for (var j=0;j<triangles.length;j+=3){
var face = new THREE.Face3(polygons[i][triangles[j+2]], polygons[i][triangles[j+1]], polygons[i][triangles[j]]);
var face = [polygons[i][triangles[j+2]], polygons[i][triangles[j+1]], polygons[i][triangles[j]]];
var foundEdges = [false, false, false];//ab, bc, ca
for (var k=0;k<polygonEdges[i].length;k++){
......@@ -317,9 +317,9 @@ function initPattern(globals){
if (edgeIndex<0) edgeIndex = -edgeIndex-1;
var _edgeVertices = allEdges[edgeIndex];
var aIndex = _edgeVertices.indexOf(face.a);
var bIndex = _edgeVertices.indexOf(face.b);
var cIndex = _edgeVertices.indexOf(face.c);
var aIndex = _edgeVertices.indexOf(face[0]);
var bIndex = _edgeVertices.indexOf(face[1]);
var cIndex = _edgeVertices.indexOf(face[2]);
if (aIndex >= 0){
if (bIndex >= 0) {
......@@ -343,13 +343,13 @@ function initPattern(globals){
if (foundEdges[k]) continue;
if (k==0){
polygonEdges[i].push(allEdges.length);
allEdges.push([face.a, face.b]);
allEdges.push([face[0], face[1]]);
} else if (k==1){
polygonEdges[i].push(allEdges.length);
allEdges.push([face.c, face.b]);
allEdges.push([face[2], face[1]]);
} else if (k==2){
polygonEdges[i].push(allEdges.length);
allEdges.push([face.c, face.a]);
allEdges.push([face[2], face[0]]);
}
}
......
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