Commit 52ee52b4 authored by amandaghassaei's avatar amandaghassaei

adding in creases

parent 86707218
'use strict';
module.exports = earcut;
// module.exports = earcut;
function earcut(data, holeIndices, dim) {
......
......@@ -28,31 +28,25 @@ function initModel(globals){
var creases = [];
creases.push(new Crease(edges[2], 1, 0, Math.PI/2, 1, nodes[3], nodes[1], 0));
function buildModel(_faces, _vertices, _allEdges, numOutline, numMountians, numValleys, numCuts){
function buildModel(_faces, _vertices, _allEdges, allCreaseParams, numOutline, numMountians, numValleys, numCuts){
var _nodes = [];
for (var i=0;i<_vertices.length;i++){
_nodes.push(new Node(_vertices[i].clone(), _nodes.length));
}
// _nodes[0].setFixed(true);
// _nodes[1].setFixed(true);
// _nodes[2].setFixed(true);
_nodes[0].setFixed(true);
_nodes[1].setFixed(true);
_nodes[2].setFixed(true);
var _edges = [];
var _creases = [];
for (var i=0;i<_allEdges.length;i++){
for (var i=0;i<_allEdges.length;i++) {
_edges.push(new Beam([_nodes[_allEdges[i][0]], _nodes[_allEdges[i][1]]]));
if (i<numOutline){
//no crease
} else if (i<numMountians){
// _creases.push(new Crease(_edges[i], 1, 0, Math.PI, 1, nodes[3], nodes[1], 0));
} else if (i<numValleys){
} else if (i<numCuts){
} else {
console.warn("unknown edge type");
}
var _creases = [];
for (var i=0;i<allCreaseParams.length;i++) {
var creaseParams = allCreaseParams[i];//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle
_creases.push(new Crease(_edges[creaseParams[4]], creaseParams[0], creaseParams[2], creaseParams[5], 1, _nodes[creaseParams[1]], _nodes[creaseParams[3]], _creases.length));
}
globals.threeView.sceneClearModel();
......
......@@ -165,10 +165,55 @@ function initPattern(globals){
drawPattern(faces);
globals.threeView.render();
globals.model.buildModel(faces, vertices, allEdges, outlines.length, outlines.length+mountains.length,
var allCreaseParams = getFacesAndVerticesForEdges(faces, allEdges);
globals.model.buildModel(faces, vertices, allEdges, allCreaseParams, outlines.length, outlines.length+mountains.length,
outlines.length+mountains.length+valleys.length, outlines.length+mountains.length+valleys.length+cuts.length);
}
function getFacesAndVerticesForEdges(faces, allEdges){
var allCreaseParams = [];//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle
for (var i=outlines.length;i<outlines.length+mountains.length+valleys.length;i++){
var v1 = allEdges[i][0];
var v2 = allEdges[i][1];
var creaseParams = [];
for (var j=0;j<faces.length;j++){
var face = faces[j];
var faceVerts = [face.a, face.b, face.c];
var v1Index = faceVerts.indexOf(v1);
if (v1Index>=0){
var v2Index = faceVerts.indexOf(v2);
if (v2Index>=0){
creaseParams.push(j);
if (v2Index>v1Index) {
faceVerts.splice(v2Index, 1);
faceVerts.splice(v1Index, 1);
} else {
faceVerts.splice(v1Index, 1);
faceVerts.splice(v2Index, 1);
}
creaseParams.push(faceVerts[0]);
if (creaseParams.length == 4) {
creaseParams.push(i);
if (i<(outlines.length+mountains.length+valleys.length)){
var angle = Math.PI;
if (i<(outlines.length+mountains.length)){
angle *= -1;
}
creaseParams.push(angle);
} else {
creaseParams.push(0);
}
allCreaseParams.push(creaseParams);
break;
}
}
}
}
}
return allCreaseParams;
}
function mergeVertices(){
vertices = verticesRaw.slice();
......
Markdown is supported
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