summaryrefslogtreecommitdiff
path: root/modules/xatlas_unwrap
diff options
context:
space:
mode:
Diffstat (limited to 'modules/xatlas_unwrap')
-rw-r--r--modules/xatlas_unwrap/SCsub25
-rw-r--r--modules/xatlas_unwrap/config.py1
-rw-r--r--modules/xatlas_unwrap/register_types.cpp102
3 files changed, 40 insertions, 88 deletions
diff --git a/modules/xatlas_unwrap/SCsub b/modules/xatlas_unwrap/SCsub
index ad364d5aaf..b242fd4673 100644
--- a/modules/xatlas_unwrap/SCsub
+++ b/modules/xatlas_unwrap/SCsub
@@ -1,7 +1,5 @@
#!/usr/bin/env python
-import platform
-
Import('env')
Import('env_modules')
@@ -15,28 +13,7 @@ if env['builtin_xatlas']:
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
- env_xatlas_unwrap.Append(CPPPATH=[thirdparty_dir])
-
- # upstream uses c++11
- if (not env.msvc):
- env_xatlas_unwrap.Append(CXXFLAGS="-std=c++11")
-
- if env["platform"] == 'x11':
- # if not specifically one of the *BSD, then use LINUX as default
- if platform.system() == "FreeBSD":
- env_xatlas_unwrap.Append(CCFLAGS=["-DNV_OS_FREEBSD", "-DPOSH_COMPILER_GCC"])
- elif platform.system() == "OpenBSD":
- env_xatlas_unwrap.Append(CCFLAGS=["-DNV_OS_OPENBSD", "-DPOSH_COMPILER_GCC"])
- else:
- env_xatlas_unwrap.Append(CCFLAGS=["-DNV_OS_LINUX", "-DPOSH_COMPILER_GCC"])
- elif env["platform"] == 'osx':
- env_xatlas_unwrap.Append(CCFLAGS=["-DNV_OS_DARWIN", "-DPOSH_COMPILER_GCC"])
- elif env["platform"] == 'windows':
- if env.msvc:
- env_xatlas_unwrap.Append(CCFLAGS=["-DNV_OS_WIN32", "-DNV_CC_MSVC", "-DPOSH_COMPILER_MSVC" ])
- else:
- env_xatlas_unwrap.Append(CCFLAGS=["-DNV_OS_MINGW", "-DNV_CC_GNUC", "-DPOSH_COMPILER_GCC", "-U__STRICT_ANSI__"])
- env.Append(LIBS=["dbghelp"])
+ env_xatlas_unwrap.Prepend(CPPPATH=[thirdparty_dir])
env_thirdparty = env_xatlas_unwrap.Clone()
env_thirdparty.disable_warnings()
diff --git a/modules/xatlas_unwrap/config.py b/modules/xatlas_unwrap/config.py
index 2dda5db7e0..bd092bdc16 100644
--- a/modules/xatlas_unwrap/config.py
+++ b/modules/xatlas_unwrap/config.py
@@ -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):
diff --git a/modules/xatlas_unwrap/register_types.cpp b/modules/xatlas_unwrap/register_types.cpp
index 903b57f017..2fc554fe7a 100644
--- a/modules/xatlas_unwrap/register_types.cpp
+++ b/modules/xatlas_unwrap/register_types.cpp
@@ -29,108 +29,84 @@
/*************************************************************************/
#include "register_types.h"
+
#include "core/error_macros.h"
+
#include "thirdparty/xatlas/xatlas.h"
#include <stdio.h>
#include <stdlib.h>
+
extern bool (*array_mesh_lightmap_unwrap_callback)(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, const int *p_face_materials, int p_index_count, float **r_uv, int **r_vertex, int *r_vertex_count, int **r_index, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y);
bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, const int *p_face_materials, int p_index_count, float **r_uv, int **r_vertex, int *r_vertex_count, int **r_index, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y) {
//set up input mesh
- xatlas::InputMesh input_mesh;
- input_mesh.indexData = malloc(sizeof(int) * p_index_count);
+ xatlas::MeshDecl input_mesh;
+ input_mesh.indexData = p_indices;
input_mesh.indexCount = p_index_count;
- input_mesh.indexFormat = xatlas::IndexFormat::Float; //really xatlas?
- input_mesh.faceMaterialData = (uint16_t *)malloc(sizeof(uint16_t) * p_index_count);
-
- for (int i = 0; i < p_index_count; i++) {
- int *index = (int *)input_mesh.indexData;
- index[i] = p_indices[i];
- }
- for (int i = 0; i < p_index_count / 3; i++) {
- uint16_t *mat_index = (uint16_t *)input_mesh.faceMaterialData;
- mat_index[i] = p_face_materials[i];
- }
+ input_mesh.indexFormat = xatlas::IndexFormat::UInt32;
input_mesh.vertexCount = p_vertex_count;
- input_mesh.vertexPositionData = malloc(sizeof(float) * p_vertex_count * 3);
+ input_mesh.vertexPositionData = p_vertices;
input_mesh.vertexPositionStride = sizeof(float) * 3;
- input_mesh.vertexNormalData = malloc(sizeof(float) * p_vertex_count * 3);
- input_mesh.vertexNormalStride = sizeof(float) * 3;
-
- //material is a better hint than this i guess?
+ input_mesh.vertexNormalData = p_normals;
+ input_mesh.vertexNormalStride = sizeof(uint32_t) * 3;
input_mesh.vertexUvData = NULL;
input_mesh.vertexUvStride = 0;
- for (int i = 0; i < p_vertex_count * 3; i++) {
- float *vertex_ptr = (float *)input_mesh.vertexPositionData;
- float *normal_ptr = (float *)input_mesh.vertexNormalData;
-
- vertex_ptr[i] = p_vertices[i];
- normal_ptr[i] = p_normals[i];
- }
+ xatlas::ChartOptions chart_options;
+ xatlas::PackOptions pack_options;
- xatlas::CharterOptions chart_options;
- xatlas::PackerOptions pack_options;
-
- pack_options.method = xatlas::PackMethod::TexelArea;
- pack_options.texelArea = 1.0 / p_texel_size;
- pack_options.quality = 3;
+ pack_options.maxChartSize = 4096;
+ pack_options.blockAlign = true;
+ pack_options.texelsPerUnit = 1.0 / p_texel_size;
xatlas::Atlas *atlas = xatlas::Create();
- printf("adding mesh..\n");
- xatlas::AddMeshError err = xatlas::AddMesh(atlas, input_mesh);
- ERR_EXPLAINC(xatlas::StringForEnum(err.code));
- ERR_FAIL_COND_V(err.code != xatlas::AddMeshErrorCode::Success, false);
+ printf("Adding mesh..\n");
+ xatlas::AddMeshError::Enum err = xatlas::AddMesh(atlas, input_mesh, 1);
+ ERR_FAIL_COND_V_MSG(err != xatlas::AddMeshError::Enum::Success, false, xatlas::StringForEnum(err));
- printf("generate..\n");
- xatlas::Generate(atlas, chart_options, pack_options);
+ printf("Generate..\n");
+ xatlas::Generate(atlas, chart_options, NULL, pack_options);
- *r_size_hint_x = xatlas::GetWidth(atlas);
- *r_size_hint_y = xatlas::GetHeight(atlas);
+ *r_size_hint_x = atlas->width;
+ *r_size_hint_y = atlas->height;
float w = *r_size_hint_x;
float h = *r_size_hint_y;
if (w == 0 || h == 0) {
- return false; //could not bake
+ return false; //could not bake because there is no area
}
- const xatlas::OutputMesh *const *output_meshes = xatlas::GetOutputMeshes(atlas);
-
- const xatlas::OutputMesh *output = output_meshes[0];
+ const xatlas::Mesh &output = atlas->meshes[0];
- *r_vertex = (int *)malloc(sizeof(int) * output->vertexCount);
- *r_uv = (float *)malloc(sizeof(float) * output->vertexCount * 2);
- *r_index = (int *)malloc(sizeof(int) * output->indexCount);
+ *r_vertex = (int *)malloc(sizeof(int) * output.vertexCount);
+ *r_uv = (float *)malloc(sizeof(float) * output.vertexCount * 2);
+ *r_index = (int *)malloc(sizeof(int) * output.indexCount);
float max_x = 0;
float max_y = 0;
- for (uint32_t i = 0; i < output->vertexCount; i++) {
- (*r_vertex)[i] = output->vertexArray[i].xref;
- (*r_uv)[i * 2 + 0] = output->vertexArray[i].uv[0] / w;
- (*r_uv)[i * 2 + 1] = output->vertexArray[i].uv[1] / h;
- max_x = MAX(max_x, output->vertexArray[i].uv[0]);
- max_y = MAX(max_y, output->vertexArray[i].uv[1]);
+ for (uint32_t i = 0; i < output.vertexCount; i++) {
+ (*r_vertex)[i] = output.vertexArray[i].xref;
+ (*r_uv)[i * 2 + 0] = output.vertexArray[i].uv[0] / w;
+ (*r_uv)[i * 2 + 1] = output.vertexArray[i].uv[1] / h;
+ max_x = MAX(max_x, output.vertexArray[i].uv[0]);
+ max_y = MAX(max_y, output.vertexArray[i].uv[1]);
}
- printf("final texsize: %f,%f - max %f,%f\n", w, h, max_x, max_y);
- *r_vertex_count = output->vertexCount;
+ printf("Final texture size: %f,%f - max %f,%f\n", w, h, max_x, max_y);
+ *r_vertex_count = output.vertexCount;
- for (uint32_t i = 0; i < output->indexCount; i++) {
- (*r_index)[i] = output->indexArray[i];
+ for (uint32_t i = 0; i < output.indexCount; i++) {
+ (*r_index)[i] = output.indexArray[i];
}
- *r_index_count = output->indexCount;
+ *r_index_count = output.indexCount;
- //xatlas::Destroy(atlas);
- free((void *)input_mesh.indexData);
- free((void *)input_mesh.vertexPositionData);
- free((void *)input_mesh.vertexNormalData);
- free((void *)input_mesh.faceMaterialData);
- printf("done");
+ xatlas::Destroy(atlas);
+ printf("Done\n");
return true;
}