summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/thekla_unwrap/config.py3
-rw-r--r--modules/xatlas_unwrap/SCsub46
-rw-r--r--modules/xatlas_unwrap/config.py5
-rw-r--r--modules/xatlas_unwrap/register_types.cpp133
-rw-r--r--modules/xatlas_unwrap/register_types.h32
5 files changed, 218 insertions, 1 deletions
diff --git a/modules/thekla_unwrap/config.py b/modules/thekla_unwrap/config.py
index bd092bdc16..fad6095064 100644
--- a/modules/thekla_unwrap/config.py
+++ b/modules/thekla_unwrap/config.py
@@ -1,5 +1,6 @@
def can_build(env, platform):
- return (env['tools'] and platform not in ["android", "ios"])
+ #return (env['tools'] and platform not in ["android", "ios"])
+ return False
def configure(env):
pass
diff --git a/modules/xatlas_unwrap/SCsub b/modules/xatlas_unwrap/SCsub
new file mode 100644
index 0000000000..9272f5692e
--- /dev/null
+++ b/modules/xatlas_unwrap/SCsub
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+import platform
+
+Import('env')
+Import('env_modules')
+
+env_xatlas_unwrap = env_modules.Clone()
+
+# Thirdparty source files
+if env['builtin_xatlas']:
+ thirdparty_dir = "#thirdparty/xatlas/"
+ thirdparty_sources = [
+ "xatlas.cpp",
+ ]
+ 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_thirdparty = env_xatlas_unwrap.Clone()
+ env_thirdparty.disable_warnings()
+ env_thirdparty.add_source_files(env.modules_sources, thirdparty_sources)
+
+# Godot source files
+env_xatlas_unwrap.add_source_files(env.modules_sources, "*.cpp")
diff --git a/modules/xatlas_unwrap/config.py b/modules/xatlas_unwrap/config.py
new file mode 100644
index 0000000000..bd092bdc16
--- /dev/null
+++ b/modules/xatlas_unwrap/config.py
@@ -0,0 +1,5 @@
+def can_build(env, platform):
+ return (env['tools'] and platform not in ["android", "ios"])
+
+def configure(env):
+ pass
diff --git a/modules/xatlas_unwrap/register_types.cpp b/modules/xatlas_unwrap/register_types.cpp
new file mode 100644
index 0000000000..9df16aac70
--- /dev/null
+++ b/modules/xatlas_unwrap/register_types.cpp
@@ -0,0 +1,133 @@
+/*************************************************************************/
+/* register_types.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* 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. */
+/*************************************************************************/
+
+#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);
+ 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.vertexCount = p_vertex_count;
+ input_mesh.vertexPositionData = malloc(sizeof(float) * p_vertex_count * 3);
+ 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.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::CharterOptions chart_options;
+ xatlas::PackerOptions pack_options;
+
+ pack_options.texelArea = 1.0 / p_texel_size;
+ pack_options.quality = 4;
+
+ 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("generate..\n");
+ xatlas::Generate(atlas, chart_options, pack_options);
+
+ *r_size_hint_x = xatlas::GetWidth(atlas);
+ *r_size_hint_y = xatlas::GetHeight(atlas);
+
+ float w = *r_size_hint_x;
+ float h = *r_size_hint_y;
+
+ printf("final texsize: %f,%f\n", w, h);
+ const xatlas::OutputMesh *const *output_meshes = xatlas::GetOutputMeshes(atlas);
+
+ const xatlas::OutputMesh *output = output_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);
+
+ for (int i = 0; i < output->vertexCount; i++) {
+ (*r_vertex)[i] = output->vertexArray[i].xref;
+ (*r_uv)[i * 2 + 0] = output->vertexArray[i].uv[0];
+ (*r_uv)[i * 2 + 1] = output->vertexArray[i].uv[1];
+ }
+ *r_vertex_count = output->vertexCount;
+
+ for (int i = 0; i < output->indexCount; i++) {
+ (*r_index)[i] = output->indexArray[i];
+ }
+
+ *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");
+ return true;
+}
+
+void register_xatlas_unwrap_types() {
+
+ array_mesh_lightmap_unwrap_callback = xatlas_mesh_lightmap_unwrap_callback;
+}
+
+void unregister_xatlas_unwrap_types() {
+}
diff --git a/modules/xatlas_unwrap/register_types.h b/modules/xatlas_unwrap/register_types.h
new file mode 100644
index 0000000000..fd8d56fa53
--- /dev/null
+++ b/modules/xatlas_unwrap/register_types.h
@@ -0,0 +1,32 @@
+/*************************************************************************/
+/* register_types.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* 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. */
+/*************************************************************************/
+
+void register_xatlas_unwrap_types();
+void unregister_xatlas_unwrap_types();