2018-09-29 12:46:26 +00:00
|
|
|
// This code is in the public domain -- castanyo@yahoo.es
|
|
|
|
#pragma once
|
|
|
|
#ifndef XATLAS_H
|
|
|
|
#define XATLAS_H
|
|
|
|
#include <float.h> // FLT_MAX
|
2019-04-19 10:40:01 +00:00
|
|
|
// -- GODOT start --
|
|
|
|
#include <limits.h> // INT_MAX, UINT_MAX
|
|
|
|
// -- GODOT end --
|
2019-04-19 10:03:12 +00:00
|
|
|
|
2018-09-29 12:46:26 +00:00
|
|
|
namespace xatlas {
|
|
|
|
|
|
|
|
typedef void (*PrintFunc)(const char *, ...);
|
|
|
|
|
|
|
|
struct Atlas;
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct CharterOptions
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
float proxyFitMetricWeight;
|
|
|
|
float roundnessMetricWeight;
|
|
|
|
float straightnessMetricWeight;
|
|
|
|
float normalSeamMetricWeight;
|
|
|
|
float textureSeamMetricWeight;
|
|
|
|
float maxChartArea;
|
|
|
|
float maxBoundaryLength;
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
CharterOptions()
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
// These are the default values we use on The Witness.
|
|
|
|
proxyFitMetricWeight = 2.0f;
|
|
|
|
roundnessMetricWeight = 0.01f;
|
|
|
|
straightnessMetricWeight = 6.0f;
|
|
|
|
normalSeamMetricWeight = 4.0f;
|
|
|
|
textureSeamMetricWeight = 0.5f;
|
|
|
|
/*
|
|
|
|
proxyFitMetricWeight = 1.0f;
|
|
|
|
roundnessMetricWeight = 0.1f;
|
|
|
|
straightnessMetricWeight = 0.25f;
|
|
|
|
normalSeamMetricWeight = 1.0f;
|
|
|
|
textureSeamMetricWeight = 0.1f;
|
|
|
|
*/
|
|
|
|
maxChartArea = FLT_MAX;
|
|
|
|
maxBoundaryLength = FLT_MAX;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct PackMethod
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
TexelArea, // texel_area determines resolution
|
|
|
|
ApproximateResolution, // guess texel_area to approximately match desired resolution
|
|
|
|
ExactResolution // run the packer multiple times to exactly match the desired resolution (slow)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct PackerOptions
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
PackMethod::Enum method;
|
|
|
|
|
|
|
|
// 0 - brute force
|
|
|
|
// 1 - 4096 attempts
|
|
|
|
// 2 - 2048
|
|
|
|
// 3 - 1024
|
|
|
|
// 4 - 512
|
|
|
|
// other - 256
|
|
|
|
// Avoid brute force packing, since it can be unusably slow in some situations.
|
|
|
|
int quality;
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
float texelArea; // This is not really texel area, but 1 / texel width?
|
2018-09-29 12:46:26 +00:00
|
|
|
uint32_t resolution;
|
2019-04-19 10:03:12 +00:00
|
|
|
bool blockAlign; // Align charts to 4x4 blocks.
|
|
|
|
bool conservative; // Pack charts with extra padding.
|
2018-09-29 12:46:26 +00:00
|
|
|
int padding;
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
PackerOptions()
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
method = PackMethod::ApproximateResolution;
|
|
|
|
quality = 1;
|
|
|
|
texelArea = 8;
|
|
|
|
resolution = 512;
|
|
|
|
blockAlign = false;
|
|
|
|
conservative = false;
|
|
|
|
padding = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct AddMeshErrorCode
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
Success,
|
|
|
|
AlreadyAddedEdge, // index0 and index1 are the edge indices
|
|
|
|
DegenerateColocalEdge, // index0 and index1 are the edge indices
|
|
|
|
DegenerateEdge, // index0 and index1 are the edge indices
|
|
|
|
DuplicateEdge, // index0 and index1 are the edge indices
|
|
|
|
IndexOutOfRange, // index0 is the index
|
|
|
|
InvalidIndexCount, // not evenly divisible by 3 - expecting triangles
|
|
|
|
ZeroAreaFace,
|
|
|
|
ZeroLengthEdge // index0 and index1 are the edge indices
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct AddMeshError
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
AddMeshErrorCode::Enum code;
|
|
|
|
uint32_t face;
|
|
|
|
uint32_t index0, index1;
|
|
|
|
};
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct IndexFormat
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
HalfFloat,
|
|
|
|
Float
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct InputMesh
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
uint32_t vertexCount;
|
|
|
|
const void *vertexPositionData;
|
|
|
|
uint32_t vertexPositionStride;
|
|
|
|
const void *vertexNormalData; // optional
|
|
|
|
uint32_t vertexNormalStride; // optional
|
|
|
|
|
|
|
|
// optional
|
|
|
|
// The input UVs are provided as a hint to the chart generator.
|
|
|
|
const void *vertexUvData;
|
|
|
|
uint32_t vertexUvStride;
|
|
|
|
|
|
|
|
uint32_t indexCount;
|
|
|
|
const void *indexData;
|
|
|
|
IndexFormat::Enum indexFormat;
|
|
|
|
|
|
|
|
// optional. indexCount / 3 in length.
|
|
|
|
// Charter also uses material boundaries as a hint to cut charts.
|
|
|
|
const uint16_t *faceMaterialData;
|
|
|
|
};
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct OutputChart
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
uint32_t *indexArray;
|
|
|
|
uint32_t indexCount;
|
|
|
|
};
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct OutputVertex
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
float uv[2];
|
2019-04-19 10:03:12 +00:00
|
|
|
uint32_t xref; // Index of input vertex from which this output vertex originated.
|
2018-09-29 12:46:26 +00:00
|
|
|
};
|
|
|
|
|
2019-04-19 10:03:12 +00:00
|
|
|
struct OutputMesh
|
|
|
|
{
|
2018-09-29 12:46:26 +00:00
|
|
|
OutputChart *chartArray;
|
|
|
|
uint32_t chartCount;
|
|
|
|
uint32_t *indexArray;
|
|
|
|
uint32_t indexCount;
|
|
|
|
OutputVertex *vertexArray;
|
|
|
|
uint32_t vertexCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetPrint(PrintFunc print);
|
|
|
|
Atlas *Create();
|
|
|
|
void Destroy(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);
|
2019-04-19 10:03:12 +00:00
|
|
|
const OutputMesh * const *GetOutputMeshes(const Atlas *atlas);
|
2018-09-29 12:46:26 +00:00
|
|
|
const char *StringForEnum(AddMeshErrorCode::Enum error);
|
|
|
|
|
|
|
|
} // namespace xatlas
|
|
|
|
|
|
|
|
#endif // XATLAS_H
|