Skip to content

Commit

Permalink
Cleanup options.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcy committed Jul 30, 2018
1 parent bd4cdbf commit b8ec29b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
12 changes: 6 additions & 6 deletions example/example.cpp
Expand Up @@ -110,11 +110,7 @@ int main(int argc, char *argv[])
// Create atlas.
if (verbose)
xatlas::SetPrint(Print);
xatlas::Options options;
options.packer.resolution = 1024;
options.packer.conservative = true;
options.packer.padding = 1;
xatlas::Atlas *atlas = xatlas::Create(options);
xatlas::Atlas *atlas = xatlas::Create();
// Add meshes to atlas.
Stopwatch stopwatch;
uint32_t totalVertices = 0, totalFaces = 0;
Expand Down Expand Up @@ -183,7 +179,11 @@ int main(int argc, char *argv[])
// Generate output meshes.
printf("Generating atlas...\n");
stopwatch.reset();
xatlas::Generate(atlas);
xatlas::PackerOptions packerOptions;
packerOptions.resolution = 1024;
packerOptions.conservative = true;
packerOptions.padding = 1;
xatlas::Generate(atlas, xatlas::CharterOptions(), packerOptions);
elapsedMs = stopwatch.elapsed();
printf(" %.2f seconds elapsed (%g milliseconds)\n", elapsedMs / 1000.0, elapsedMs);
printf(" %d charts\n", xatlas::GetNumCharts(atlas));
Expand Down
16 changes: 7 additions & 9 deletions xatlas.cpp
Expand Up @@ -7422,7 +7422,6 @@ struct AtlasPacker

struct Atlas
{
Options options;
internal::param::Atlas atlas;
std::vector<internal::halfedge::Mesh *> heMeshes;
uint32_t width = 0;
Expand All @@ -7435,11 +7434,9 @@ void SetPrint(PrintFunc print)
internal::s_print = print;
}

Atlas *Create(const Options &options)
Atlas *Create()
{
xaAssert(options.packer.texelArea > 0);
Atlas *atlas = new Atlas();
atlas->options = options;
return atlas;
}

Expand Down Expand Up @@ -7492,7 +7489,7 @@ static float EdgeLength(internal::Vector3 pos1, internal::Vector3 pos2)
return internal::length(pos2 - pos1);
}

AddMeshError AddMesh(Atlas *atlas, const InputMesh &mesh)
AddMeshError AddMesh(Atlas *atlas, const InputMesh &mesh, bool useColocalVertices)
{
xaAssert(atlas);
AddMeshError error;
Expand Down Expand Up @@ -7525,7 +7522,7 @@ AddMeshError AddMesh(Atlas *atlas, const InputMesh &mesh)
vertex->tex = DecodeUv(mesh, i);
// Link colocals. You probably want to do this more efficiently! Sort by one axis or use a hash or grid.
uint32_t firstColocal = i;
if (atlas->options.useMeshColocalVertices) {
if (useColocalVertices) {
for (uint32_t j = 0; j < i; j++) {
if (vertex->pos != DecodePosition(mesh, j))
continue;
Expand Down Expand Up @@ -7599,17 +7596,18 @@ AddMeshError AddMesh(Atlas *atlas, const InputMesh &mesh)
return error;
}

void Generate(Atlas *atlas)
void Generate(Atlas *atlas, CharterOptions charterOptions, PackerOptions packerOptions)
{
xaAssert(atlas);
xaAssert(packerOptions.texelArea > 0);
// Chart meshes.
for (int i = 0; i < (int)atlas->heMeshes.size(); i++) {
std::vector<uint32_t> uncharted_materials;
atlas->atlas.computeCharts(atlas->heMeshes[i], atlas->options.charter, uncharted_materials);
atlas->atlas.computeCharts(atlas->heMeshes[i], charterOptions, uncharted_materials);
}
atlas->atlas.parameterizeCharts();
internal::param::AtlasPacker packer(&atlas->atlas);
packer.packCharts(atlas->options.packer);
packer.packCharts(packerOptions);
//float utilization = return packer.computeAtlasUtilization();
atlas->width = packer.getWidth();
atlas->height = packer.getHeight();
Expand Down
16 changes: 4 additions & 12 deletions xatlas.h
Expand Up @@ -81,15 +81,6 @@ struct PackerOptions
}
};

struct Options
{
CharterOptions charter;
PackerOptions packer;

// Generates fewer charts (good), but is more sensitive to bad geometry.
bool useMeshColocalVertices = true;
};

struct AddMeshErrorCode
{
enum Enum
Expand Down Expand Up @@ -167,10 +158,11 @@ struct OutputMesh
};

void SetPrint(PrintFunc print);
Atlas *Create(const Options &options = Options());
Atlas *Create();
void Destroy(Atlas *atlas);
AddMeshError AddMesh(Atlas *atlas, const InputMesh &mesh);
void Generate(Atlas *atlas);
// useColocalVertices - generates fewer charts (good), but is more sensitive to bad geometry.
AddMeshError AddMesh(Atlas *atlas, const InputMesh &mesh, bool useColocalVertices = true);
void Generate(Atlas *atlas, CharterOptions charterOptions = CharterOptions(), PackerOptions packerOptions = PackerOptions());
uint32_t GetWidth(const Atlas *atlas);
uint32_t GetHeight(const Atlas *atlas);
uint32_t GetNumCharts(const Atlas *atlas);
Expand Down

0 comments on commit b8ec29b

Please sign in to comment.