Commit a60838a9 authored by amandaghassaei's avatar amandaghassaei
Browse files

debugging

parent 57c070f8
...@@ -259,17 +259,50 @@ ...@@ -259,17 +259,50 @@
if (sign < 0.0) theta *= -1.0; if (sign < 0.0) theta *= -1.0;
float diff = theta-lastTheta[0]; float diff = theta-lastTheta[0];
float projectedTheta = lastTheta[0] + lastTheta[1]*u_dt; float projectedTheta = lastTheta[0] + lastTheta[1]*u_dt;
if (diff < -5.5 || (diff < -3.0 && projectedTheta > 6.0)) { if (diff < -5.0) {
diff += TWO_PI; diff += TWO_PI;
theta = lastTheta[0] + diff; theta = lastTheta[0] + diff;
} else if (diff > 5.5 || (diff > 3.0 && projectedTheta < -6.0)) { } else if (diff > 5.0) {
diff -= TWO_PI; diff -= TWO_PI;
theta = lastTheta[0] + diff; theta = lastTheta[0] + diff;
} }
gl_FragColor = vec4(theta, diff, lastTheta[2], lastTheta[3]);//[theta, w, normal1Index, normal2Index] gl_FragColor = vec4(theta, diff, lastTheta[2], lastTheta[3]);//[theta, w, normal1Index, normal2Index]
} }
</script> </script>
<script id="normalCalc" type="x-shader/x-fragment">
precision mediump float;
uniform vec2 u_textureDim;
uniform vec2 u_textureDimFaces;
uniform sampler2D u_faceVertexIndices;
uniform sampler2D u_lastPosition;
uniform sampler2D u_originalPosition;
void main(){
vec2 fragCoord = gl_FragCoord.xy;
vec2 scaledFragCoord = fragCoord/u_textureDimFaces;
vec3 indices = texture2D(u_faceVertexIndices, scaledFragCoord).xyz;
float nodeIndex1D = indices[0];
vec2 nodeIndex = vec2(mod(nodeIndex1D, u_textureDim.x)+0.5, floor(nodeIndex1D/u_textureDim.x)+0.5);
vec2 scaledNodeIndex = nodeIndex/u_textureDim;
vec3 a = texture2D(u_lastPosition, scaledNodeIndex).xyz + texture2D(u_originalPosition, scaledNodeIndex).xyz;
nodeIndex1D = indices[1];
nodeIndex = vec2(mod(nodeIndex1D, u_textureDim.x)+0.5, floor(nodeIndex1D/u_textureDim.x)+0.5);
scaledNodeIndex = nodeIndex/u_textureDim;
vec3 b = texture2D(u_lastPosition, scaledNodeIndex).xyz + texture2D(u_originalPosition, scaledNodeIndex).xyz;
nodeIndex1D = indices[2];
nodeIndex = vec2(mod(nodeIndex1D, u_textureDim.x)+0.5, floor(nodeIndex1D/u_textureDim.x)+0.5);
scaledNodeIndex = nodeIndex/u_textureDim;
vec3 c = texture2D(u_lastPosition, scaledNodeIndex).xyz + texture2D(u_originalPosition, scaledNodeIndex).xyz;
gl_FragColor = vec4(normalize(cross(b-a, c-a)), 0.0);
}
</script>
<script type="text/javascript" src="dependencies/jquery-3.1.1.min.js"></script> <script type="text/javascript" src="dependencies/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="dependencies/jquery-ui.min.js"></script> <script type="text/javascript" src="dependencies/jquery-ui.min.js"></script>
<script type="text/javascript" src="dependencies/flat-ui.min.js"></script> <script type="text/javascript" src="dependencies/flat-ui.min.js"></script>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
function initDynamicModel(globals){ function initDynamicModel(globals){
var material = new THREE.MeshNormalMaterial({shading: THREE.FlatShading, side: THREE.DoubleSide}); var material = new THREE.MeshNormalMaterial({shading: THREE.FlatShading, side: THREE.FrontSide});
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
geometry.dynamic = true; geometry.dynamic = true;
var object3D = new THREE.Mesh(geometry, material); var object3D = new THREE.Mesh(geometry, material);
...@@ -29,6 +29,7 @@ function initDynamicModel(globals){ ...@@ -29,6 +29,7 @@ function initDynamicModel(globals){
var beamMeta;//[K, D, length, otherNodeIndex] var beamMeta;//[K, D, length, otherNodeIndex]
var normals; var normals;
var faceVertexIndices;//[a,b,c]
var creaseMeta;//[k, d, targetTheta] var creaseMeta;//[k, d, targetTheta]
var creaseMeta2;//[creaseIndex (thetaIndex), length to node, nodeIndex (1/2), ] var creaseMeta2;//[creaseIndex (thetaIndex), length to node, nodeIndex (1/2), ]
//[creaseIndex (thetaIndex), length to node1, length to node2, -1] //[creaseIndex (thetaIndex), length to node1, length to node2, -1]
...@@ -95,6 +96,7 @@ function initDynamicModel(globals){ ...@@ -95,6 +96,7 @@ function initDynamicModel(globals){
if (!globals.dynamicSimVisible) { if (!globals.dynamicSimVisible) {
return; return;
} }
// steps = 1;
for (var j=0;j<steps;j++){ for (var j=0;j<steps;j++){
solveStep(); solveStep();
} }
...@@ -142,6 +144,10 @@ function initDynamicModel(globals){ ...@@ -142,6 +144,10 @@ function initDynamicModel(globals){
var gpuMath = globals.gpuMath; var gpuMath = globals.gpuMath;
gpuMath.setProgram("normalCalc");
gpuMath.setSize(textureDimFaces, textureDimFaces);
gpuMath.step("normalCalc", ["u_faceVertexIndices", "u_lastPosition", "u_originalPosition"], "u_normals");
gpuMath.setProgram("thetaCalc"); gpuMath.setProgram("thetaCalc");
gpuMath.setSize(textureDimCreases, textureDimCreases); gpuMath.setSize(textureDimCreases, textureDimCreases);
gpuMath.step("thetaCalc", ["u_normals", "u_lastTheta", "u_creaseVectors"], "u_theta"); gpuMath.step("thetaCalc", ["u_normals", "u_lastTheta", "u_creaseVectors"], "u_theta");
...@@ -159,11 +165,29 @@ function initDynamicModel(globals){ ...@@ -159,11 +165,29 @@ function initDynamicModel(globals){
function render(){ function render(){
// var vectorLength = 1; var vectorLength = 1;
globals.gpuMath.setProgram("packToBytes");
globals.gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
globals.gpuMath.setSize(textureDimCreases*vectorLength, textureDimCreases);
globals.gpuMath.step("packToBytes", ["u_lastTheta"], "outputBytes");
if (globals.gpuMath.readyToRead()) {
var numPixels = creases.length*vectorLength;
var height = Math.ceil(numPixels/(textureDimCreases*vectorLength));
var pixels = new Uint8Array(height*textureDimCreases*4*vectorLength);
globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels);
var parsedPixels = new Float32Array(pixels.buffer);
for (var i = 0; i < 1; i++) {
console.log(parsedPixels);
}
} else {
console.log("here");
}
// var vectorLength = 3;
// globals.gpuMath.setProgram("packToBytes"); // globals.gpuMath.setProgram("packToBytes");
// globals.gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f"); // globals.gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
// globals.gpuMath.setSize(textureDim*vectorLength, textureDim); // globals.gpuMath.setSize(textureDim*vectorLength, textureDim);
// globals.gpuMath.step("packToBytes", ["u_theta"], "outputBytes"); // globals.gpuMath.step("packToBytes", ["u_normals"], "outputBytes");
// if (globals.gpuMath.readyToRead()) { // if (globals.gpuMath.readyToRead()) {
// var numPixels = creases.length*vectorLength; // var numPixels = creases.length*vectorLength;
// var height = Math.ceil(numPixels/(textureDimCreases*vectorLength)); // var height = Math.ceil(numPixels/(textureDimCreases*vectorLength));
...@@ -171,7 +195,7 @@ function initDynamicModel(globals){ ...@@ -171,7 +195,7 @@ function initDynamicModel(globals){
// globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels); // globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels);
// var parsedPixels = new Float32Array(pixels.buffer); // var parsedPixels = new Float32Array(pixels.buffer);
// for (var i = 0; i < 1; i++) { // for (var i = 0; i < 1; i++) {
// console.log(parsedPixels[i]) // console.log(parsedPixels[i] + " " + parsedPixels[i+1] + " " + parsedPixels[i+2] + " ");
// } // }
// } else { // } else {
// console.log("here"); // console.log("here");
...@@ -199,7 +223,6 @@ function initDynamicModel(globals){ ...@@ -199,7 +223,6 @@ function initDynamicModel(globals){
} }
geometry.verticesNeedUpdate = true; geometry.verticesNeedUpdate = true;
geometry.computeFaceNormals(); geometry.computeFaceNormals();
updateNormals();
} else { } else {
console.log("here"); console.log("here");
} }
...@@ -238,6 +261,7 @@ function initDynamicModel(globals){ ...@@ -238,6 +261,7 @@ function initDynamicModel(globals){
gpuMath.initTextureFromData("u_lastVelocity", textureDim, textureDim, "FLOAT", lastVelocity, !firstTime); gpuMath.initTextureFromData("u_lastVelocity", textureDim, textureDim, "FLOAT", lastVelocity, !firstTime);
gpuMath.initTextureFromData("u_theta", textureDimCreases, textureDimCreases, "FLOAT", theta, !firstTime); gpuMath.initTextureFromData("u_theta", textureDimCreases, textureDimCreases, "FLOAT", theta, !firstTime);
gpuMath.initTextureFromData("u_lastTheta", textureDimCreases, textureDimCreases, "FLOAT", lastTheta, !firstTime); gpuMath.initTextureFromData("u_lastTheta", textureDimCreases, textureDimCreases, "FLOAT", lastTheta, !firstTime);
gpuMath.initTextureFromData("u_normals", textureDimFaces, textureDimFaces, "FLOAT", normals, !firstTime);
gpuMath.initFrameBufferForTexture("u_position", !firstTime); gpuMath.initFrameBufferForTexture("u_position", !firstTime);
gpuMath.initFrameBufferForTexture("u_lastPosition", !firstTime); gpuMath.initFrameBufferForTexture("u_lastPosition", !firstTime);
...@@ -245,9 +269,11 @@ function initDynamicModel(globals){ ...@@ -245,9 +269,11 @@ function initDynamicModel(globals){
gpuMath.initFrameBufferForTexture("u_lastVelocity", !firstTime); gpuMath.initFrameBufferForTexture("u_lastVelocity", !firstTime);
gpuMath.initFrameBufferForTexture("u_theta", !firstTime); gpuMath.initFrameBufferForTexture("u_theta", !firstTime);
gpuMath.initFrameBufferForTexture("u_lastTheta", !firstTime); gpuMath.initFrameBufferForTexture("u_lastTheta", !firstTime);
gpuMath.initFrameBufferForTexture("u_normals", !firstTime);
gpuMath.initTextureFromData("u_meta", textureDim, textureDim, "FLOAT", meta, true); gpuMath.initTextureFromData("u_meta", textureDim, textureDim, "FLOAT", meta, true);
gpuMath.initTextureFromData("u_creaseMeta2", textureDimNodeCreases, textureDimNodeCreases, "FLOAT", creaseMeta2, true); gpuMath.initTextureFromData("u_creaseMeta2", textureDimNodeCreases, textureDimNodeCreases, "FLOAT", creaseMeta2, true);
gpuMath.initTextureFromData("u_faceVertexIndices", textureDimFaces, textureDimFaces, "FLOAT", faceVertexIndices, true);
gpuMath.createProgram("positionCalc", vertexShader, document.getElementById("positionCalcShader").text); gpuMath.createProgram("positionCalc", vertexShader, document.getElementById("positionCalcShader").text);
gpuMath.setUniformForProgram("positionCalc", "u_velocity", 0, "1i"); gpuMath.setUniformForProgram("positionCalc", "u_velocity", 0, "1i");
...@@ -281,6 +307,13 @@ function initDynamicModel(globals){ ...@@ -281,6 +307,13 @@ function initDynamicModel(globals){
gpuMath.setUniformForProgram("thetaCalc", "u_textureDimFaces", [textureDimFaces, textureDimFaces], "2f"); gpuMath.setUniformForProgram("thetaCalc", "u_textureDimFaces", [textureDimFaces, textureDimFaces], "2f");
gpuMath.setUniformForProgram("thetaCalc", "u_textureDimCreases", [textureDimCreases, textureDimCreases], "2f"); gpuMath.setUniformForProgram("thetaCalc", "u_textureDimCreases", [textureDimCreases, textureDimCreases], "2f");
gpuMath.createProgram("normalCalc", vertexShader, document.getElementById("normalCalc").text);
gpuMath.setUniformForProgram("normalCalc", "u_faceVertexIndices", 0, "1i");
gpuMath.setUniformForProgram("normalCalc", "u_lastPosition", 1, "1i");
gpuMath.setUniformForProgram("normalCalc", "u_originalPosition", 2, "1i");
gpuMath.setUniformForProgram("normalCalc", "u_textureDim", [textureDim, textureDim], "2f");
gpuMath.setUniformForProgram("normalCalc", "u_textureDimFaces", [textureDimFaces, textureDimFaces], "2f");
gpuMath.createProgram("packToBytes", vertexShader, document.getElementById("packToBytesShader").text); gpuMath.createProgram("packToBytes", vertexShader, document.getElementById("packToBytesShader").text);
gpuMath.initTextureFromData("outputBytes", textureDim*4, textureDim, "UNSIGNED_BYTE", null, !firstTime); gpuMath.initTextureFromData("outputBytes", textureDim*4, textureDim, "UNSIGNED_BYTE", null, !firstTime);
gpuMath.initFrameBufferForTexture("outputBytes", !firstTime); gpuMath.initFrameBufferForTexture("outputBytes", !firstTime);
...@@ -355,17 +388,6 @@ function initDynamicModel(globals){ ...@@ -355,17 +388,6 @@ function initDynamicModel(globals){
globals.gpuMath.initTextureFromData("u_originalPosition", textureDim, textureDim, "FLOAT", originalPosition, true); globals.gpuMath.initTextureFromData("u_originalPosition", textureDim, textureDim, "FLOAT", originalPosition, true);
} }
function updateNormals(){
var numFaces = geometry.faces.length;
for (var i=0;i<numFaces;i++){
var normal = geometry.faces[i].normal;
normals[i*4] = normal.x;
normals[i*4+1] = normal.y;
normals[i*4+2] = normal.z;
}
globals.gpuMath.initTextureFromData("u_normals", textureDimFaces, textureDimFaces, "FLOAT", normals, true);
}
function updateCreaseVectors(){ function updateCreaseVectors(){
for (var i=0;i<creases.length;i++){ for (var i=0;i<creases.length;i++){
var rgbaIndex = i*4; var rgbaIndex = i*4;
...@@ -437,18 +459,26 @@ function initDynamicModel(globals){ ...@@ -437,18 +459,26 @@ function initDynamicModel(globals){
beamMeta = new Float32Array(textureDimEdges*textureDimEdges*4); beamMeta = new Float32Array(textureDimEdges*textureDimEdges*4);
normals = new Float32Array(textureDimFaces*textureDimFaces*4); normals = new Float32Array(textureDimFaces*textureDimFaces*4);
faceVertexIndices = new Float32Array(textureDimFaces*textureDimFaces*4);
creaseMeta = new Float32Array(textureDimCreases*textureDimCreases*4); creaseMeta = new Float32Array(textureDimCreases*textureDimCreases*4);
creaseMeta2 = new Float32Array(textureDimNodeCreases*textureDimNodeCreases*4); creaseMeta2 = new Float32Array(textureDimNodeCreases*textureDimNodeCreases*4);
creaseVectors = new Float32Array(textureDimCreases*textureDimCreases*4); creaseVectors = new Float32Array(textureDimCreases*textureDimCreases*4);
theta = new Float32Array(textureDimCreases*textureDimCreases*4); theta = new Float32Array(textureDimCreases*textureDimCreases*4);
lastTheta = new Float32Array(textureDimCreases*textureDimCreases*4); lastTheta = new Float32Array(textureDimCreases*textureDimCreases*4);
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;
}
for (var i=0;i<textureDim*textureDim;i++){ for (var i=0;i<textureDim*textureDim;i++){
mass[4*i+1] = 1;//set all fixed by default mass[4*i+1] = 1;//set all fixed by default
} }
_.each(nodes, function(node, index){ _.each(nodes, function(node, index){
mass[4*index] = node.getSimMass(); mass[4*index] = node.getSimMass();//todo move into bottom loop?
}); });
for (var i=0;i<textureDimCreases*textureDimCreases;i++){ for (var i=0;i<textureDimCreases*textureDimCreases;i++){
...@@ -489,7 +519,6 @@ function initDynamicModel(globals){ ...@@ -489,7 +519,6 @@ function initDynamicModel(globals){
updateExternalForces(); updateExternalForces();
updateCreasesMeta(true); updateCreasesMeta(true);
updateCreaseVectors(); updateCreaseVectors();
updateNormals();
} }
function pause(){ function pause(){
......
...@@ -121,7 +121,7 @@ $(function() { ...@@ -121,7 +121,7 @@ $(function() {
globals.model = initModel(globals); globals.model = initModel(globals);
globals.staticSolver = initStaticSolver(globals); globals.staticSolver = initStaticSolver(globals);
globals.dynamicModel = initDynamicModel(globals); globals.dynamicModel = initDynamicModel(globals);
// global.dynamicModel.syncNodesAndEdges(true); globals.dynamicModel.syncNodesAndEdges(true);
// globals.staticSolver.syncNodesAndEdges(); // globals.staticSolver.syncNodesAndEdges();
globals.pattern = initPattern(globals); globals.pattern = initPattern(globals);
globals.threeView.render(); globals.threeView.render();
......
...@@ -13,12 +13,15 @@ function initModel(globals){ ...@@ -13,12 +13,15 @@ function initModel(globals){
nodes.push(new Node(new THREE.Vector3(10,0,0), nodes.length)); nodes.push(new Node(new THREE.Vector3(10,0,0), nodes.length));
nodes.push(new Node(new THREE.Vector3(0,0,-10), nodes.length)); nodes.push(new Node(new THREE.Vector3(0,0,-10), nodes.length));
nodes.push(new Node(new THREE.Vector3(10,0,-10), nodes.length)); nodes.push(new Node(new THREE.Vector3(10,0,-10), nodes.length));
// nodes[0].setFixed(true);
// nodes[1].setFixed(true); // nodes.push(new Node(new THREE.Vector3(-10,0,0), nodes.length));
// nodes[2].setFixed(true);
nodes[0].setFixed(true);
nodes[1].setFixed(true);
nodes[2].setFixed(true);
var edges = []; var edges = [];
edges.push(new Beam([nodes[0], nodes[1]])); edges.push(new Beam([nodes[1], nodes[0]]));
edges.push(new Beam([nodes[1], nodes[2]])); edges.push(new Beam([nodes[1], nodes[2]]));
edges.push(new Beam([nodes[2], nodes[0]])); edges.push(new Beam([nodes[2], nodes[0]]));
edges.push(new Beam([nodes[3], nodes[0]])); edges.push(new Beam([nodes[3], nodes[0]]));
...@@ -26,34 +29,47 @@ function initModel(globals){ ...@@ -26,34 +29,47 @@ function initModel(globals){
edges.push(new Beam([nodes[3], nodes[4]])); edges.push(new Beam([nodes[3], nodes[4]]));
edges.push(new Beam([nodes[2], nodes[4]])); edges.push(new Beam([nodes[2], nodes[4]]));
// edges.push(new Beam([nodes[4], nodes[0]]));
// edges.push(new Beam([nodes[4], nodes[1]]));
// edges.push(new Beam([nodes[3], nodes[4]]));
var faces = []; var faces = [];
faces.push(new THREE.Face3(0,1,2)); faces.push(new THREE.Face3(0,1,2));
faces.push(new THREE.Face3(0,2,3)); faces.push(new THREE.Face3(0,2,3));
faces.push(new THREE.Face3(4,3,2)); faces.push(new THREE.Face3(4,3,2));
// faces.push(new THREE.Face3(4,1,0));
// faces.push(new THREE.Face3(3,4,0));
var creases = []; var creases = [];
creases.push(new Crease(edges[2], 0, 1, Math.PI-0.001, 1, nodes[1], nodes[3], 0)); creases.push(new Crease(edges[2], 0, 1, Math.PI-0.001, 1, nodes[1], nodes[3], 0));
creases.push(new Crease(edges[4], 2, 1, -(Math.PI-0.001), 1, nodes[4], nodes[0], 1)); creases.push(new Crease(edges[4], 2, 1, -(Math.PI-0.001), 1, nodes[4], nodes[0], 1));
// creases.push(new Crease(edges[5], 3, 2, -(Math.PI-0.001), 1, nodes[3], nodes[1], 1));
// creases.push(new Crease(edges[0], 3, 0, (Math.PI-0.001), 1, nodes[4], nodes[2], 2));
var _allNodeObject3Ds = []; var _allNodeObject3Ds = [];
_.each(nodes, function(node){ _.each(nodes, function(node){
var obj3D = node.getObject3D(); var obj3D = node.getObject3D();
_allNodeObject3Ds.push(obj3D); _allNodeObject3Ds.push(obj3D);
globals.threeView.sceneAddModel(obj3D); globals.threeView.sceneAddModel(obj3D);
}); });
allNodeObject3Ds = _allNodeObject3Ds;
_.each(edges, function(edge){ _.each(edges, function(edge){
globals.threeView.sceneAddModel(edge.getObject3D()); globals.threeView.sceneAddModel(edge.getObject3D());
}); });
function buildModel(_faces, _vertices, _allEdges, allCreaseParams){ function buildModel(_faces, _vertices, _allEdges, allCreaseParams){
// console.log(_allEdges);
var _nodes = []; var _nodes = [];
for (var i=0;i<_vertices.length;i++){ for (var i=0;i<_vertices.length;i++){
_nodes.push(new Node(_vertices[i].clone(), _nodes.length)); _nodes.push(new Node(_vertices[i].clone(), _nodes.length));
} }
_nodes[_faces[0].a].setFixed(true); // _nodes[_faces[0].a].setFixed(true);
_nodes[_faces[0].b].setFixed(true); // _nodes[_faces[0].b].setFixed(true);
_nodes[_faces[0].c].setFixed(true); // _nodes[_faces[0].c].setFixed(true);
var _edges = []; var _edges = [];
for (var i=0;i<_allEdges.length;i++) { for (var i=0;i<_allEdges.length;i++) {
......
...@@ -32,46 +32,46 @@ function initPattern(globals){ ...@@ -32,46 +32,46 @@ function initPattern(globals){
}); });
} }
loadSVG("assets/Tessellations/SimpleVertex.svg", function(svg){ // loadSVG("assets/Tessellations/SimpleVertex2.svg", function(svg){
var _$svg = $(svg); // var _$svg = $(svg);
//
//format all lines // //format all lines
var $paths = _$svg.children("path"); // var $paths = _$svg.children("path");
$paths.css({fill:"none", 'stroke-width':3, 'stroke-dasharray':"none"}); // $paths.css({fill:"none", 'stroke-width':3, 'stroke-dasharray':"none"});
//
var $outlines = $paths.filter(function(){ // var $outlines = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase(); // var stroke = $(this).attr("stroke").toLowerCase();
return stroke == "#000000" || stroke == "#000"; // return stroke == "#000000" || stroke == "#000";
}); // });
// $outlines.css({fill:'#ffffff'}); // // $outlines.css({fill:'#ffffff'});
//
var $mountains = $paths.filter(function(){ // var $mountains = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase(); // var stroke = $(this).attr("stroke").toLowerCase();
return stroke == "#ff0000" || stroke == "#f00"; // return stroke == "#ff0000" || stroke == "#f00";
}); // });
$mountains.css({'stroke-dasharray':'12, 6, 3, 6'}); // $mountains.css({'stroke-dasharray':'12, 6, 3, 6'});
//
var $valleys = $paths.filter(function(){ // var $valleys = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase(); // var stroke = $(this).attr("stroke").toLowerCase();
return stroke == "#0000ff" || stroke == "#00f"; // return stroke == "#0000ff" || stroke == "#00f";
}); // });
$valleys.css({'stroke-dasharray':'7, 6, 7, 6'}); // $valleys.css({'stroke-dasharray':'7, 6, 7, 6'});
//
var $cuts = $paths.filter(function(){ // var $cuts = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase(); // var stroke = $(this).attr("stroke").toLowerCase();
return stroke == "#00ff00" || stroke == "#0f0"; // return stroke == "#00ff00" || stroke == "#0f0";
}); // });
//
var $svg = $('<svg version="1.1" viewBox="'+_$svg.attr("viewBox")+'" id="mySVG" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> </svg>'); // var $svg = $('<svg version="1.1" viewBox="'+_$svg.attr("viewBox")+'" id="mySVG" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> </svg>');
$svg.append($outlines); // $svg.append($outlines);
$svg.append($mountains); // $svg.append($mountains);
$svg.append($valleys); // $svg.append($valleys);
$svg.append($cuts); // $svg.append($cuts);
//
$("#svgViewer").html($svg); // $("#svgViewer").html($svg);
//
parseSVG($outlines, $mountains, $valleys, $cuts); // parseSVG($outlines, $mountains, $valleys, $cuts);
}); // });
function parsePath(_verticesRaw, _segmentsRaw, $paths){ function parsePath(_verticesRaw, _segmentsRaw, $paths){
for (var i=0;i<$paths.length;i++){ for (var i=0;i<$paths.length;i++){
...@@ -193,16 +193,23 @@ function initPattern(globals){ ...@@ -193,16 +193,23 @@ function initPattern(globals){
} }
creaseParams.push(faceVerts[0]); creaseParams.push(faceVerts[0]);
if (creaseParams.length == 4) { if (creaseParams.length == 4) {
if (v2Index-v1Index == 1 || v2Index-v1Index == -2) {
creaseParams = [creaseParams[2], creaseParams[3], creaseParams[0], creaseParams[1]];
}
creaseParams.push(i); creaseParams.push(i);
if (i<(outlines.length+mountains.length+valleys.length)){ if (i<(outlines.length+mountains.length+valleys.length)){
var angle = Math.PI; var angle = Math.PI/2;
if (i<(outlines.length+mountains.length)){ if (i<(outlines.length+mountains.length)){
angle *= -1; angle *= -1;
} }
creaseParams.push(angle); creaseParams.push(angle);
} else { } else {
console.log("panel");
creaseParams.push(0); creaseParams.push(0);
} }
console.log(creaseParams);
allCreaseParams.push(creaseParams); allCreaseParams.push(creaseParams);
break; break;
} }
...@@ -210,36 +217,37 @@ function initPattern(globals){ ...@@ -210,36 +217,37 @@ function initPattern(globals){
} }
} }
} }
for (var i=outlines.length+mountains.length+valleys.length+cuts.length;i<allEdges.length;i++){ //panels
var v1 = allEdges[i][0]; // for (var i=outlines.length+mountains.length+valleys.length+cuts.length;i<allEdges.length;i++){
var v2 = allEdges[i][1]; // var v1 = allEdges[i][0];
var creaseParams = []; // var v2 = allEdges[i][1];
for (var j=0;j<faces.length;j++){ // var creaseParams = [];
var face = faces[j]; // for (var j=0;j<faces.length;j++){
var faceVerts = [face.a, face.b, face.c]; // var face = faces[j];
var v1Index = faceVerts.indexOf(v1); // var faceVerts = [face.a, face.b, face.c];
if (v1Index>=0){ // var v1Index = faceVerts.indexOf(v1);
var v2Index = faceVerts.indexOf(v2); // if (v1Index>=0){
if (v2Index>=0){ // var v2Index = faceVerts.indexOf(v2);
creaseParams.push(j); // if (v2Index>=0){
if (v2Index>v1Index) { // creaseParams.push(j);
faceVerts.splice(v2Index, 1); // if (v2Index>v1Index) {
faceVerts.splice(v1Index, 1); // faceVerts.splice(v2Index, 1);
} else { // faceVerts.splice(v1Index, 1);
faceVerts.splice(v1Index, 1); // } else {
faceVerts.splice(v2Index, 1); // faceVerts.splice(v1Index, 1);
} // faceVerts.splice(v2Index, 1);
creaseParams.push(faceVerts[0]); // }
if (creaseParams.length == 4) { // creaseParams.push(faceVerts[0]);
creaseParams.push(i); // if (creaseParams.length == 4) {