Commit 6eb3f4bb authored by amandaghassaei's avatar amandaghassaei
Browse files

merge vertices working

parent 1dd6e504
...@@ -159,30 +159,38 @@ function initPattern(globals){ ...@@ -159,30 +159,38 @@ function initPattern(globals){
var tolSq = globals.vertTol*globals.vertTol; var tolSq = globals.vertTol*globals.vertTol;
var combined = []; var combined = [];
var mergedVertices = []; var mergedVertices = [];
var weededVertices = vertices.slice(); var _weededVertices = vertices.slice();
var diff = 0; var js = [];
for (var i=0;i<vertices.length;i++){
js.push(i);
}
for (var i=vertices.length-1;i>=0;i--){ for (var i=vertices.length-1;i>=0;i--){
var _combined = []; var _combined = [];
for (var j=i-1+diff;j>=0;j--){ var indicesToRemove = [];
if ((weededVertices[i].clone().sub(vertices[j])).lengthSq()<tolSq){ for (var j=i-1;j>=0;j--){
_combined.push(j); if ((_weededVertices[i].clone().sub(_weededVertices[j])).lengthSq()<tolSq){
_combined.push(js[j]);
indicesToRemove.push(j);
} }
} }
var numCombined = _combined.length; var numCombined = _combined.length;
if (numCombined>0){ if (numCombined>0){
_combined.push(i+diff); _combined.push(js[i]);
mergedVertices.push(weededVertices[i]); mergedVertices.push(_weededVertices[i]);
combined.push(_combined); combined.push(_combined);
console.log(_combined); _weededVertices.splice(i, 1);
weededVertices.splice(i, 1); js.splice(i, 1);
for (var k=0;k<numCombined;k++){ for (var k=0;k<numCombined;k++){
weededVertices.splice(_combined[k], 1); _weededVertices.splice(indicesToRemove[k], 1);
js.splice(indicesToRemove[k], 1);
} }
diff += numCombined;
i -= numCombined; i -= numCombined;
} }
} }
console.log(combined.length);
if (_weededVertices.length > 0){
console.warn("not all vertices merged");
}
outlines = outlinesRaw.slice(); outlines = outlinesRaw.slice();
mountains = mountainsRaw.slice(); mountains = mountainsRaw.slice();
...@@ -194,20 +202,28 @@ function initPattern(globals){ ...@@ -194,20 +202,28 @@ function initPattern(globals){
removeCombinedFromSet(combined, valleys); removeCombinedFromSet(combined, valleys);
removeCombinedFromSet(combined, cuts); removeCombinedFromSet(combined, cuts);
console.log(outlines);
vertices = mergedVertices; vertices = mergedVertices;
//find cycles //find cycles
//triangulate //triangulate
drawPattern(); drawPattern();
//make mesh
} }
function removeCombinedFromSet(combined, set){ function removeCombinedFromSet(combined, set){
for (var i=0;i<combined.length;i++){ for (var j=0;j<set.length;j++){
for (var j=0;j<set.length;j++){ for (var i=0;i<combined.length;i++){
if (combined[i].indexOf(set[j][0]) >= 0) set[j][0] = i; if (combined[i].indexOf(set[j][0]) >= 0) {
if (combined[i].indexOf(set[j][1]) >= 0) set[j][1] = i; set[j][0] = i;
break;
}
}
for (var i=0;i<combined.length;i++) {
if (combined[i].indexOf(set[j][1]) >= 0) {
set[j][1] = i;
break;
}
} }
} }
} }
......
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