Skip to content

Commit

Permalink
The --ids option now re-orders faces by charts and dumps a JSON file.
Browse files Browse the repository at this point in the history
  • Loading branch information
prideout committed Dec 30, 2015
1 parent edc5ee4 commit 021110d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build
*.png
*.obj
*.bin
*.json
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ add_subdirectory(thekla)
add_subdirectory(vendor/poshlib)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-fopenmp -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -std=c++11")
else()
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

add_definitions(
Expand Down
5 changes: 5 additions & 0 deletions aobaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ int aobaker_bake(
printf("Atlas mesh has %d verts\n", output_mesh->vertex_count);
printf("Atlas mesh has %d triangles\n", output_mesh->index_count / 3);

// Reorder faces according to their respective charts.
if (chartinfo) {
atlas_reorder_faces(output_mesh, "chartids.json");
}

// Transform the data produced by the Thekla library.
float* coordsdata = 0;
float* normsdata = 0;
Expand Down
2 changes: 1 addition & 1 deletion cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main(int argc, const char **argv)
flag_int(&sizehint, "sizehint", "Controls resolution of atlas");
flag_int(&nsamples, "nsamples", "Quality of ambient occlusion");
flag_bool(&gbuffer, "gbuffer", "Generate diagnostic images");
flag_bool(&chartinfo, "ids", "Add a chart id to the alpha channel");
flag_bool(&chartinfo, "ids", "Group faces by charts, add alpha channel");
flag_parse(argc, argv, "v" AOBAKER_VERSION, 1);
char const* inmesh = flagset_singleton()->argv[0];
return aobaker_bake(inmesh, outmesh, atlas, sizehint, nsamples, gbuffer,
Expand Down
44 changes: 40 additions & 4 deletions thekla/thekla/thekla_atlas.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@

#include "thekla_atlas.h"

#include <cfloat>
#include <cstdio>
#include <vector>
#include <map>

#include "nvmesh/halfedge/Edge.h"
#include "nvmesh/halfedge/Mesh.h"
#include "nvmesh/halfedge/Face.h"
#include "nvmesh/halfedge/Vertex.h"
#include "nvmesh/param/Atlas.h"
#include "nvmesh/raster/Raster.h"

#include "nvmath/Vector.inl"

#include "nvcore/Array.inl"

#define STB_IMAGE_WRITE_IMPLEMENTATION
Expand All @@ -21,7 +20,6 @@
using namespace Thekla;
using namespace nv;


inline Atlas_Output_Mesh * set_error(Atlas_Error * error, Atlas_Error code) {
if (error) *error = code;
return NULL;
Expand Down Expand Up @@ -309,6 +307,44 @@ static bool idSolidCallback(
return true;
}

void Thekla::atlas_reorder_faces(Atlas_Output_Mesh * atlas_mesh, const char* outputfile)
{
printf("Writing %s...\n", outputfile);
std::map<int, std::vector<int> > chart_to_faces;
std::map<int, std::vector<int> >::const_iterator chart_iter;
int nfaces = atlas_mesh->index_count / 3;
for (int nface = 0; nface < nfaces; nface++) {
int a = atlas_mesh->index_array[nface * 3];
Atlas_Output_Vertex& v = atlas_mesh->vertex_array[a];
chart_to_faces[v.chart_index].push_back(nface);
}
FILE* json = fopen(outputfile, "wt");
putc('[', json);
chart_iter = chart_to_faces.begin();
int* indices = new int[nfaces * 3], *pindex = indices;
while (chart_iter != chart_to_faces.end()) {
const std::vector<int>& faces = chart_iter->second;
for (size_t i = 0; i < faces.size(); i++) {
int nface = faces[i];
int a = atlas_mesh->index_array[nface * 3];
int b = atlas_mesh->index_array[nface * 3 + 1];
int c = atlas_mesh->index_array[nface * 3 + 2];
*pindex++ = a;
*pindex++ = b;
*pindex++ = c;
}
fprintf(json, "%d", (int) faces.size());
if (++chart_iter != chart_to_faces.end()) {
fputc(',', json);
}
}
putc(']', json);
putc('\n', json);
fclose(json);
delete[] atlas_mesh->index_array;
atlas_mesh->index_array = indices;
}

void Thekla::atlas_dump(
const Atlas_Output_Mesh * atlas_mesh,
const Atlas_Input_Mesh * obj_mesh,
Expand Down
2 changes: 2 additions & 0 deletions thekla/thekla/thekla_atlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Atlas_Output_Mesh * atlas_generate(
const Atlas_Options * options,
Atlas_Error * error);

void atlas_reorder_faces(Atlas_Output_Mesh * atlas_mesh, const char* outputfile);

void atlas_dump(
const Atlas_Output_Mesh * atlas_mesh,
const Atlas_Input_Mesh * object_mesh,
Expand Down

0 comments on commit 021110d

Please sign in to comment.