Merge pull request #28196 from akien-mga/xatlas-cleanup
xatlas: Document provenance, copyright and custom changes
This commit is contained in:
commit
8269ed9cdf
8 changed files with 1629 additions and 984 deletions
|
@ -386,6 +386,13 @@ Copyright: 2011, Khaled Mamou
|
|||
2003-2009, Erwin Coumans
|
||||
License: BSD-3-clause
|
||||
|
||||
Files: ./thirdparty/xatlas/
|
||||
Comment: xatlas
|
||||
Copyright: 2018, Jonathan Young
|
||||
2013, Thekla, Inc
|
||||
2006, NVIDIA Corporation, Ignacio Castano
|
||||
License: Expat
|
||||
|
||||
Files: ./thirdparty/zlib/
|
||||
Comment: zlib
|
||||
Copyright: 1995-2017, Jean-loup Gailly and Mark Adler
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
def can_build(env, platform):
|
||||
#return False #xatlas is buggy
|
||||
return (env['tools'] and platform not in ["android", "ios"])
|
||||
|
||||
def configure(env):
|
||||
|
|
14
thirdparty/README.md
vendored
14
thirdparty/README.md
vendored
|
@ -530,6 +530,20 @@ They can be reapplied using the patches included in the `vhacd`
|
|||
folder.
|
||||
|
||||
|
||||
## xatlas
|
||||
|
||||
- Upstream: https://github.com/jpcy/xatlas
|
||||
- Version: git (b8ec29b, 2018)
|
||||
- License: MIT
|
||||
|
||||
Files extracted from upstream source:
|
||||
|
||||
- `xatlas.{cpp,h}`
|
||||
|
||||
Note: License is marked as Public Domain in the files, but it was
|
||||
later clarified upstream to MIT license.
|
||||
|
||||
|
||||
## zlib
|
||||
|
||||
- Upstream: http://www.zlib.net
|
||||
|
|
14
thirdparty/xatlas/LICENSE
vendored
Normal file
14
thirdparty/xatlas/LICENSE
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
xatlas
|
||||
https://github.com/jpcy/xatlas
|
||||
Copyright (c) 2018 Jonathan Young
|
||||
|
||||
thekla_atlas
|
||||
https://github.com/Thekla/thekla_atlas
|
||||
Copyright (c) 2013 Thekla, Inc
|
||||
Copyright NVIDIA Corporation 2006 -- Ignacio Castano <icastano@nvidia.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
157
thirdparty/xatlas/avoid-failing-on-bad-geometry.patch
vendored
Normal file
157
thirdparty/xatlas/avoid-failing-on-bad-geometry.patch
vendored
Normal file
|
@ -0,0 +1,157 @@
|
|||
diff --git a/thirdparty/xatlas/xatlas.cpp b/thirdparty/xatlas/xatlas.cpp
|
||||
index df5ef94db..eb0824a51 100644
|
||||
--- a/thirdparty/xatlas/xatlas.cpp
|
||||
+++ b/thirdparty/xatlas/xatlas.cpp
|
||||
@@ -1276,6 +1276,9 @@ class Vertex
|
||||
{
|
||||
public:
|
||||
uint32_t id;
|
||||
+ // -- GODOT start --
|
||||
+ uint32_t original_id;
|
||||
+ // -- GODOT end --
|
||||
Edge *edge;
|
||||
Vertex *next;
|
||||
Vertex *prev;
|
||||
@@ -1283,7 +1286,10 @@ public:
|
||||
Vector3 nor;
|
||||
Vector2 tex;
|
||||
|
||||
- Vertex(uint32_t id) : id(id), edge(NULL), pos(0.0f), nor(0.0f), tex(0.0f)
|
||||
+ // -- GODOT start --
|
||||
+ //Vertex(uint32_t id) : id(id), edge(NULL), pos(0.0f), nor(0.0f), tex(0.0f)
|
||||
+ Vertex(uint32_t id) : id(id), original_id(id), edge(NULL), pos(0.0f), nor(0.0f), tex(0.0f)
|
||||
+ // -- GODOT end --
|
||||
{
|
||||
next = this;
|
||||
prev = this;
|
||||
@@ -1934,6 +1940,64 @@ public:
|
||||
return f;
|
||||
}
|
||||
|
||||
+ // -- GODOT start --
|
||||
+ Face *addUniqueFace(uint32_t v0, uint32_t v1, uint32_t v2) {
|
||||
+
|
||||
+ int base_vertex = m_vertexArray.size();
|
||||
+
|
||||
+ uint32_t ids[3] = { v0, v1, v2 };
|
||||
+
|
||||
+ Vector3 base[3] = {
|
||||
+ m_vertexArray[v0]->pos,
|
||||
+ m_vertexArray[v1]->pos,
|
||||
+ m_vertexArray[v2]->pos,
|
||||
+ };
|
||||
+
|
||||
+ //make sure its not a degenerate
|
||||
+ bool degenerate = distanceSquared(base[0], base[1]) < NV_EPSILON || distanceSquared(base[0], base[2]) < NV_EPSILON || distanceSquared(base[1], base[2]) < NV_EPSILON;
|
||||
+ xaDebugAssert(!degenerate);
|
||||
+
|
||||
+ float min_x = 0;
|
||||
+
|
||||
+ for (int i = 0; i < 3; i++) {
|
||||
+ if (i == 0 || m_vertexArray[v0]->pos.x < min_x) {
|
||||
+ min_x = m_vertexArray[v0]->pos.x;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ float max_x = 0;
|
||||
+
|
||||
+ for (int j = 0; j < m_vertexArray.size(); j++) {
|
||||
+ if (j == 0 || m_vertexArray[j]->pos.x > max_x) { //vertex already exists
|
||||
+ max_x = m_vertexArray[j]->pos.x;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ //separate from everything else, in x axis
|
||||
+ for (int i = 0; i < 3; i++) {
|
||||
+
|
||||
+ base[i].x -= min_x;
|
||||
+ base[i].x += max_x + 10.0;
|
||||
+ }
|
||||
+
|
||||
+ for (int i = 0; i < 3; i++) {
|
||||
+ Vertex *v = new Vertex(m_vertexArray.size());
|
||||
+ v->pos = base[i];
|
||||
+ v->nor = m_vertexArray[ids[i]]->nor,
|
||||
+ v->tex = m_vertexArray[ids[i]]->tex,
|
||||
+
|
||||
+ v->original_id = ids[i];
|
||||
+ m_vertexArray.push_back(v);
|
||||
+ }
|
||||
+
|
||||
+ uint32_t indexArray[3];
|
||||
+ indexArray[0] = base_vertex + 0;
|
||||
+ indexArray[1] = base_vertex + 1;
|
||||
+ indexArray[2] = base_vertex + 2;
|
||||
+ return addFace(indexArray, 3, 0, 3);
|
||||
+ }
|
||||
+ // -- GODOT end --
|
||||
+
|
||||
// These functions disconnect the given element from the mesh and delete it.
|
||||
|
||||
// @@ We must always disconnect edge pairs simultaneously.
|
||||
@@ -2915,6 +2979,14 @@ Mesh *triangulate(const Mesh *inputMesh)
|
||||
Vector2 p0 = polygonPoints[i0];
|
||||
Vector2 p1 = polygonPoints[i1];
|
||||
Vector2 p2 = polygonPoints[i2];
|
||||
+
|
||||
+ // -- GODOT start --
|
||||
+ bool degenerate = distance(p0, p1) < NV_EPSILON || distance(p0, p2) < NV_EPSILON || distance(p1, p2) < NV_EPSILON;
|
||||
+ if (degenerate) {
|
||||
+ continue;
|
||||
+ }
|
||||
+ // -- GODOT end --
|
||||
+
|
||||
float d = clamp(dot(p0 - p1, p2 - p1) / (length(p0 - p1) * length(p2 - p1)), -1.0f, 1.0f);
|
||||
float angle = acosf(d);
|
||||
float area = triangleArea(p0, p1, p2);
|
||||
@@ -2938,6 +3010,11 @@ Mesh *triangulate(const Mesh *inputMesh)
|
||||
}
|
||||
}
|
||||
}
|
||||
+ // -- GODOT start --
|
||||
+ if (!bestIsValid)
|
||||
+ break;
|
||||
+ // -- GODOT end --
|
||||
+
|
||||
xaDebugAssert(minAngle <= 2 * PI);
|
||||
// Clip best ear:
|
||||
uint32_t i0 = (bestEar + size - 1) % size;
|
||||
@@ -5606,7 +5683,10 @@ public:
|
||||
}
|
||||
if (chartMeshIndices[vertex->id] == ~0) {
|
||||
chartMeshIndices[vertex->id] = m_chartMesh->vertexCount();
|
||||
- m_chartToOriginalMap.push_back(vertex->id);
|
||||
+ // -- GODOT start --
|
||||
+ //m_chartToOriginalMap.push_back(vertex->id);
|
||||
+ m_chartToOriginalMap.push_back(vertex->original_id);
|
||||
+ // -- GODOT end --
|
||||
m_chartToUnifiedMap.push_back(unifiedMeshIndices[unifiedVertex->id]);
|
||||
halfedge::Vertex *v = m_chartMesh->addVertex(vertex->pos);
|
||||
v->nor = vertex->nor;
|
||||
@@ -5699,7 +5779,10 @@ public:
|
||||
const halfedge::Vertex *vertex = it.current()->vertex;
|
||||
if (chartMeshIndices[vertex->id] == ~0) {
|
||||
chartMeshIndices[vertex->id] = m_chartMesh->vertexCount();
|
||||
- m_chartToOriginalMap.push_back(vertex->id);
|
||||
+ // -- GODOT start --
|
||||
+ //m_chartToOriginalMap.push_back(vertex->id);
|
||||
+ m_chartToOriginalMap.push_back(vertex->original_id);
|
||||
+ // -- GODOT end --
|
||||
halfedge::Vertex *v = m_chartMesh->addVertex(vertex->pos);
|
||||
v->nor = vertex->nor;
|
||||
v->tex = vertex->tex; // @@ Not necessary.
|
||||
@@ -7573,6 +7656,14 @@ AddMeshError AddMesh(Atlas *atlas, const InputMesh &mesh, bool useColocalVertice
|
||||
}
|
||||
}
|
||||
internal::halfedge::Face *face = heMesh->addFace(tri[0], tri[1], tri[2]);
|
||||
+
|
||||
+ // -- GODOT start --
|
||||
+ if (!face && heMesh->errorCode == internal::halfedge::Mesh::ErrorCode::AlreadyAddedEdge) {
|
||||
+ //there is still hope for this, no reason to not add, at least add as separate
|
||||
+ face = heMesh->addUniqueFace(tri[0], tri[1], tri[2]);
|
||||
+ }
|
||||
+ // -- GODOT end --
|
||||
+
|
||||
if (!face) {
|
||||
if (heMesh->errorCode == internal::halfedge::Mesh::ErrorCode::AlreadyAddedEdge)
|
||||
error.code = AddMeshErrorCode::AlreadyAddedEdge;
|
14
thirdparty/xatlas/build-fix-limits.patch
vendored
Normal file
14
thirdparty/xatlas/build-fix-limits.patch
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
diff --git a/thirdparty/xatlas/xatlas.h b/thirdparty/xatlas/xatlas.h
|
||||
index 7e556c6c3..dbf8ca08c 100644
|
||||
--- a/thirdparty/xatlas/xatlas.h
|
||||
+++ b/thirdparty/xatlas/xatlas.h
|
||||
@@ -3,6 +3,9 @@
|
||||
#ifndef XATLAS_H
|
||||
#define XATLAS_H
|
||||
#include <float.h> // FLT_MAX
|
||||
+// -- GODOT start --
|
||||
+#include <limits.h> // INT_MAX, UINT_MAX
|
||||
+// -- GODOT end --
|
||||
|
||||
namespace xatlas {
|
||||
|
2345
thirdparty/xatlas/xatlas.cpp
vendored
2345
thirdparty/xatlas/xatlas.cpp
vendored
File diff suppressed because it is too large
Load diff
61
thirdparty/xatlas/xatlas.h
vendored
61
thirdparty/xatlas/xatlas.h
vendored
|
@ -3,15 +3,18 @@
|
|||
#ifndef XATLAS_H
|
||||
#define XATLAS_H
|
||||
#include <float.h> // FLT_MAX
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
// -- GODOT start --
|
||||
#include <limits.h> // INT_MAX, UINT_MAX
|
||||
// -- GODOT end --
|
||||
|
||||
namespace xatlas {
|
||||
|
||||
typedef void (*PrintFunc)(const char *, ...);
|
||||
|
||||
struct Atlas;
|
||||
|
||||
struct CharterOptions {
|
||||
struct CharterOptions
|
||||
{
|
||||
float proxyFitMetricWeight;
|
||||
float roundnessMetricWeight;
|
||||
float straightnessMetricWeight;
|
||||
|
@ -20,7 +23,8 @@ struct CharterOptions {
|
|||
float maxChartArea;
|
||||
float maxBoundaryLength;
|
||||
|
||||
CharterOptions() {
|
||||
CharterOptions()
|
||||
{
|
||||
// These are the default values we use on The Witness.
|
||||
proxyFitMetricWeight = 2.0f;
|
||||
roundnessMetricWeight = 0.01f;
|
||||
|
@ -39,15 +43,18 @@ struct CharterOptions {
|
|||
}
|
||||
};
|
||||
|
||||
struct PackMethod {
|
||||
enum Enum {
|
||||
struct PackMethod
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
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)
|
||||
};
|
||||
};
|
||||
|
||||
struct PackerOptions {
|
||||
struct PackerOptions
|
||||
{
|
||||
PackMethod::Enum method;
|
||||
|
||||
// 0 - brute force
|
||||
|
@ -59,13 +66,14 @@ struct PackerOptions {
|
|||
// Avoid brute force packing, since it can be unusably slow in some situations.
|
||||
int quality;
|
||||
|
||||
float texelArea; // This is not really texel area, but 1 / texel width?
|
||||
float texelArea; // This is not really texel area, but 1 / texel width?
|
||||
uint32_t resolution;
|
||||
bool blockAlign; // Align charts to 4x4 blocks.
|
||||
bool conservative; // Pack charts with extra padding.
|
||||
bool blockAlign; // Align charts to 4x4 blocks.
|
||||
bool conservative; // Pack charts with extra padding.
|
||||
int padding;
|
||||
|
||||
PackerOptions() {
|
||||
PackerOptions()
|
||||
{
|
||||
method = PackMethod::ApproximateResolution;
|
||||
quality = 1;
|
||||
texelArea = 8;
|
||||
|
@ -76,8 +84,10 @@ struct PackerOptions {
|
|||
}
|
||||
};
|
||||
|
||||
struct AddMeshErrorCode {
|
||||
enum Enum {
|
||||
struct AddMeshErrorCode
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
Success,
|
||||
AlreadyAddedEdge, // index0 and index1 are the edge indices
|
||||
DegenerateColocalEdge, // index0 and index1 are the edge indices
|
||||
|
@ -90,20 +100,24 @@ struct AddMeshErrorCode {
|
|||
};
|
||||
};
|
||||
|
||||
struct AddMeshError {
|
||||
struct AddMeshError
|
||||
{
|
||||
AddMeshErrorCode::Enum code;
|
||||
uint32_t face;
|
||||
uint32_t index0, index1;
|
||||
};
|
||||
|
||||
struct IndexFormat {
|
||||
enum Enum {
|
||||
struct IndexFormat
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
HalfFloat,
|
||||
Float
|
||||
};
|
||||
};
|
||||
|
||||
struct InputMesh {
|
||||
struct InputMesh
|
||||
{
|
||||
uint32_t vertexCount;
|
||||
const void *vertexPositionData;
|
||||
uint32_t vertexPositionStride;
|
||||
|
@ -124,17 +138,20 @@ struct InputMesh {
|
|||
const uint16_t *faceMaterialData;
|
||||
};
|
||||
|
||||
struct OutputChart {
|
||||
struct OutputChart
|
||||
{
|
||||
uint32_t *indexArray;
|
||||
uint32_t indexCount;
|
||||
};
|
||||
|
||||
struct OutputVertex {
|
||||
struct OutputVertex
|
||||
{
|
||||
float uv[2];
|
||||
uint32_t xref; // Index of input vertex from which this output vertex originated.
|
||||
uint32_t xref; // Index of input vertex from which this output vertex originated.
|
||||
};
|
||||
|
||||
struct OutputMesh {
|
||||
struct OutputMesh
|
||||
{
|
||||
OutputChart *chartArray;
|
||||
uint32_t chartCount;
|
||||
uint32_t *indexArray;
|
||||
|
@ -152,7 +169,7 @@ void Generate(Atlas *atlas, CharterOptions charterOptions = CharterOptions(), Pa
|
|||
uint32_t GetWidth(const Atlas *atlas);
|
||||
uint32_t GetHeight(const Atlas *atlas);
|
||||
uint32_t GetNumCharts(const Atlas *atlas);
|
||||
const OutputMesh *const *GetOutputMeshes(const Atlas *atlas);
|
||||
const OutputMesh * const *GetOutputMeshes(const Atlas *atlas);
|
||||
const char *StringForEnum(AddMeshErrorCode::Enum error);
|
||||
|
||||
} // namespace xatlas
|
||||
|
|
Loading…
Reference in a new issue