Skip to content

Commit

Permalink
Merge pull request #7 from freestraws/master
Browse files Browse the repository at this point in the history
fixed uv coords code so they apply to faces correctly
  • Loading branch information
edemaine authored Jul 23, 2019
2 parents 2bdf389 + 0e2af0e commit 481cf2f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions js/saveSTL.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function saveOBJ(){
// first get bounds for normalization
var min = [Infinity, Infinity];
var max = [-Infinity, -Infinity];
for (var i=0;i<flatGeo.vertices.length;i++){
for (var i=0;i<flatGeo.vertices_coords.length;i++){
var vertex = flatGeo.vertices_coords[i];
if (vertex[0] < min[0]) min[0] = vertex[0];
if (vertex[2] < min[1]) min[1] = vertex[2];
Expand All @@ -134,14 +134,15 @@ function saveOBJ(){
}
var scale = max[0] - min[0];
if (max[1] - min[1] > scale) scale = max[1] - min[1];
for (var i=0;i<flatGeo.vertices.length;i++){
for (var i=0;i<flatGeo.vertices_coords.length;i++){
var vertex = flatGeo.vertices_coords[i];
obj += "vt " + (vertex[0] - min[0]) / scale + " " + (vertex[2] - min[1]) / scale + "\n"
}
obj += "# "+ fold.faces_vertices.length + " faces\n";
for (var i=0;i<fold.faces_vertices.length;i++){
var face = fold.faces_vertices[i];//triangular faces
obj += "f " + (face[0]+1) + " " + (face[1]+1) + " " + (face[2]+1) + "\n"
obj += "f " + (face[0]+1) + "/" + (face[0]+1) + " " + (face[1]+1) + "/" + (face[1]+1)+ " " +
(face[2]+1) + "/" + (face[2]+1) + "\n"
}

obj += "# "+ fold.edges_vertices.length + " edges\n";
Expand Down

0 comments on commit 481cf2f

Please sign in to comment.