mirror of
https://github.com/Relintai/mesh_utils.git
synced 2024-11-12 10:25:24 +01:00
Work on fixing compile.
This commit is contained in:
parent
30d5e204e5
commit
ffea461bf8
@ -396,7 +396,7 @@ void MeshMerger::remove_doubles() {
|
|||||||
for (int j = 0; j < indices.size(); ++j) {
|
for (int j = 0; j < indices.size(); ++j) {
|
||||||
int index = indices[j];
|
int index = indices[j];
|
||||||
|
|
||||||
_vertices.remove(index);
|
_vertices.remove_at(index);
|
||||||
|
|
||||||
//make all indices that were bigger than the one we replaced one lower
|
//make all indices that were bigger than the one we replaced one lower
|
||||||
for (int k = 0; k < _indices.size(); ++k) {
|
for (int k = 0; k < _indices.size(); ++k) {
|
||||||
@ -448,8 +448,8 @@ void MeshMerger::remove_doubles_hashed() {
|
|||||||
for (int j = 0; j < indices.size(); ++j) {
|
for (int j = 0; j < indices.size(); ++j) {
|
||||||
int index = indices[j];
|
int index = indices[j];
|
||||||
|
|
||||||
hashes.remove(index);
|
hashes.remove_at(index);
|
||||||
_vertices.remove(index);
|
_vertices.remove_at(index);
|
||||||
|
|
||||||
//make all indices that were bigger than the one we replaced one lower
|
//make all indices that were bigger than the one we replaced one lower
|
||||||
for (int k = 0; k < _indices.size(); ++k) {
|
for (int k = 0; k < _indices.size(); ++k) {
|
||||||
@ -755,7 +755,7 @@ Vector3 MeshMerger::get_vertex(const int idx) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MeshMerger::remove_vertex(const int idx) {
|
void MeshMerger::remove_vertex(const int idx) {
|
||||||
_vertices.remove(idx);
|
_vertices.remove_at(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector<Vector3> MeshMerger::get_normals() const {
|
PoolVector<Vector3> MeshMerger::get_normals() const {
|
||||||
@ -917,7 +917,7 @@ int MeshMerger::get_index(const int idx) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MeshMerger::remove_index(const int idx) {
|
void MeshMerger::remove_index(const int idx) {
|
||||||
_indices.remove(idx);
|
_indices.remove_at(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshMerger::MeshMerger() {
|
MeshMerger::MeshMerger() {
|
||||||
@ -974,7 +974,7 @@ void MeshMerger::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("add_mesh_data_resource_bone", "mesh", "bones", "wrights", "transform", "uv_rect"), &MeshMerger::add_mesh_data_resource_bone, DEFVAL(Transform()), DEFVAL(Rect2(0, 0, 1, 1)));
|
ClassDB::bind_method(D_METHOD("add_mesh_data_resource_bone", "mesh", "bones", "wrights", "transform", "uv_rect"), &MeshMerger::add_mesh_data_resource_bone, DEFVAL(Transform()), DEFVAL(Rect2(0, 0, 1, 1)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BIND_VMETHOD(MethodInfo("_add_mesher", PropertyInfo(Variant::OBJECT, "mesher", PROPERTY_HINT_RESOURCE_TYPE, "MeshMerger")));
|
//BIND_VMETHOD(MethodInfo("_add_mesher", PropertyInfo(Variant::OBJECT, "mesher", PROPERTY_HINT_RESOURCE_TYPE, "MeshMerger")));
|
||||||
ClassDB::bind_method(D_METHOD("add_mesher", "mesher"), &MeshMerger::add_mesher);
|
ClassDB::bind_method(D_METHOD("add_mesher", "mesher"), &MeshMerger::add_mesher);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_vertices"), &MeshMerger::get_vertices);
|
ClassDB::bind_method(D_METHOD("get_vertices"), &MeshMerger::get_vertices);
|
||||||
|
@ -28,20 +28,19 @@ SOFTWARE.
|
|||||||
#include "core/version.h"
|
#include "core/version.h"
|
||||||
|
|
||||||
#if VERSION_MAJOR > 3
|
#if VERSION_MAJOR > 3
|
||||||
#include "core/object/reference.h"
|
|
||||||
#include "core/templates/vector.h"
|
|
||||||
#include "core/math/color.h"
|
#include "core/math/color.h"
|
||||||
|
#include "core/object/ref_counted.h"
|
||||||
|
#include "core/templates/vector.h"
|
||||||
#else
|
#else
|
||||||
|
#include "core/color.h"
|
||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
#include "core/vector.h"
|
#include "core/vector.h"
|
||||||
#include "core/color.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
#include pool_vector_h
|
#include pool_vector_h
|
||||||
include_pool_vector
|
include_pool_vector
|
||||||
|
|
||||||
#include mesh_instance_h
|
#include mesh_instance_h
|
||||||
|
|
||||||
#include "core/math/rect2.h"
|
#include "core/math/rect2.h"
|
||||||
@ -55,12 +54,11 @@ include_pool_vector
|
|||||||
#include "../mesh_data_resource/mesh_data_resource.h"
|
#include "../mesh_data_resource/mesh_data_resource.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class MeshMerger : public Reference {
|
class MeshMerger : public RefCounted {
|
||||||
GDCLASS(MeshMerger, Reference);
|
GDCLASS(MeshMerger, RefCounted);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
|
|
||||||
Vector3 vertex;
|
Vector3 vertex;
|
||||||
Color color;
|
Color color;
|
||||||
Vector3 normal; // normal, binormal, tangent
|
Vector3 normal; // normal, binormal, tangent
|
||||||
|
@ -21,8 +21,8 @@ SOFTWARE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mesh_utils.h"
|
#include "mesh_utils.h"
|
||||||
#include "core/local_vector.h"
|
#include "core/templates/local_vector.h"
|
||||||
#include "core/variant.h"
|
#include "core/variant/variant.h"
|
||||||
#include "scene/resources/mesh.h"
|
#include "scene/resources/mesh.h"
|
||||||
|
|
||||||
#include visual_server_h
|
#include visual_server_h
|
||||||
@ -77,25 +77,25 @@ Array MeshUtils::merge_mesh_array(Array arr) const {
|
|||||||
int rem = equals[k];
|
int rem = equals[k];
|
||||||
int remk = rem - k;
|
int remk = rem - k;
|
||||||
|
|
||||||
verts.remove(remk);
|
verts.remove_at(remk);
|
||||||
if (normals.size() > 0)
|
if (normals.size() > 0)
|
||||||
normals.remove(remk);
|
normals.remove_at(remk);
|
||||||
if (uvs.size() > 0)
|
if (uvs.size() > 0)
|
||||||
uvs.remove(remk);
|
uvs.remove_at(remk);
|
||||||
if (colors.size() > 0)
|
if (colors.size() > 0)
|
||||||
colors.remove(remk);
|
colors.remove_at(remk);
|
||||||
|
|
||||||
if (bones.size() > 0) {
|
if (bones.size() > 0) {
|
||||||
int bindex = remk * 4;
|
int bindex = remk * 4;
|
||||||
for (int l = 0; l < 4; ++l) {
|
for (int l = 0; l < 4; ++l) {
|
||||||
bones.remove(bindex);
|
bones.remove_at(bindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weights.size() > 0) {
|
if (weights.size() > 0) {
|
||||||
int bindex = remk * 4;
|
int bindex = remk * 4;
|
||||||
for (int l = 0; l < 4; ++l) {
|
for (int l = 0; l < 4; ++l) {
|
||||||
weights.remove(bindex);
|
weights.remove_at(bindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ Array MeshUtils::bake_mesh_array_uv(Array arr, Ref<Texture> tex, float mul_color
|
|||||||
ERR_FAIL_COND_V(arr.size() != VisualServer::ARRAY_MAX, arr);
|
ERR_FAIL_COND_V(arr.size() != VisualServer::ARRAY_MAX, arr);
|
||||||
ERR_FAIL_COND_V(!tex.is_valid(), arr);
|
ERR_FAIL_COND_V(!tex.is_valid(), arr);
|
||||||
|
|
||||||
Ref<Image> img = tex->get_data();
|
Ref<Image> img = tex->get_image();
|
||||||
|
|
||||||
ERR_FAIL_COND_V(!img.is_valid(), arr);
|
ERR_FAIL_COND_V(!img.is_valid(), arr);
|
||||||
|
|
||||||
@ -271,25 +271,25 @@ Array MeshUtils::remove_doubles(Array arr) const {
|
|||||||
int rem = equals[k];
|
int rem = equals[k];
|
||||||
int remk = rem - k;
|
int remk = rem - k;
|
||||||
|
|
||||||
verts.remove(remk);
|
verts.remove_at(remk);
|
||||||
|
|
||||||
if (normals.size() > 0) {
|
if (normals.size() > 0) {
|
||||||
normals.remove(remk);
|
normals.remove_at(remk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvs.size() > 0) {
|
if (uvs.size() > 0) {
|
||||||
uvs.remove(remk);
|
uvs.remove_at(remk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colors.size() > 0) {
|
if (colors.size() > 0) {
|
||||||
colors.remove(remk);
|
colors.remove_at(remk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bones.size() > 0) {
|
if (bones.size() > 0) {
|
||||||
int bindex = remk * 4;
|
int bindex = remk * 4;
|
||||||
for (int l = 0; l < 4; ++l) {
|
for (int l = 0; l < 4; ++l) {
|
||||||
bones.remove(bindex);
|
bones.remove_at(bindex);
|
||||||
weights.remove(bindex);
|
weights.remove_at(bindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,32 +423,32 @@ Array MeshUtils::remove_doubles_interpolate_normals(Array arr) const {
|
|||||||
int rem = equals[k];
|
int rem = equals[k];
|
||||||
int remk = rem - k;
|
int remk = rem - k;
|
||||||
|
|
||||||
verts.remove(remk);
|
verts.remove_at(remk);
|
||||||
|
|
||||||
if (normals.size() > 0) {
|
if (normals.size() > 0) {
|
||||||
Vector3 n = normals[remk];
|
Vector3 n = normals[remk];
|
||||||
normals.remove(remk);
|
normals.remove_at(remk);
|
||||||
|
|
||||||
if (k == 0) {
|
if (k == 0) {
|
||||||
normal = n;
|
normal = n;
|
||||||
} else {
|
} else {
|
||||||
normal = normal.linear_interpolate(n, 0.5);
|
normal = normal.lerp(n, 0.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvs.size() > 0) {
|
if (uvs.size() > 0) {
|
||||||
uvs.remove(remk);
|
uvs.remove_at(remk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colors.size() > 0) {
|
if (colors.size() > 0) {
|
||||||
colors.remove(remk);
|
colors.remove_at(remk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bones.size() > 0) {
|
if (bones.size() > 0) {
|
||||||
int bindex = remk * 4;
|
int bindex = remk * 4;
|
||||||
for (int l = 0; l < 4; ++l) {
|
for (int l = 0; l < 4; ++l) {
|
||||||
bones.remove(bindex);
|
bones.remove_at(bindex);
|
||||||
weights.remove(bindex);
|
weights.remove_at(bindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,12 +491,12 @@ PoolVector2Array MeshUtils::uv_unwrap(Array arrays, bool p_block_align, float p_
|
|||||||
LocalVector<float> normals;
|
LocalVector<float> normals;
|
||||||
LocalVector<int> indices;
|
LocalVector<int> indices;
|
||||||
|
|
||||||
PoolVector<Vector3> rvertices = arrays[Mesh::ARRAY_VERTEX];
|
Vector<Vector3> rvertices = arrays[Mesh::ARRAY_VERTEX];
|
||||||
int vc = rvertices.size();
|
int vc = rvertices.size();
|
||||||
PoolVector<Vector3>::Read r = rvertices.read();
|
const Vector3 *r = rvertices.ptr();
|
||||||
|
|
||||||
PoolVector<Vector3> rnormals = arrays[Mesh::ARRAY_NORMAL];
|
Vector<Vector3> rnormals = arrays[Mesh::ARRAY_NORMAL];
|
||||||
PoolVector<Vector3>::Read rn = rnormals.read();
|
const Vector3 *rn = rnormals.ptr();
|
||||||
|
|
||||||
int vertex_ofs = vertices.size() / 3;
|
int vertex_ofs = vertices.size() / 3;
|
||||||
|
|
||||||
@ -515,7 +515,7 @@ PoolVector2Array MeshUtils::uv_unwrap(Array arrays, bool p_block_align, float p_
|
|||||||
normals[(j + vertex_ofs) * 3 + 2] = n.z;
|
normals[(j + vertex_ofs) * 3 + 2] = n.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector<int> rindices = arrays[Mesh::ARRAY_INDEX];
|
Vector<int> rindices = arrays[Mesh::ARRAY_INDEX];
|
||||||
int ic = rindices.size();
|
int ic = rindices.size();
|
||||||
|
|
||||||
if (ic == 0) {
|
if (ic == 0) {
|
||||||
@ -526,7 +526,7 @@ PoolVector2Array MeshUtils::uv_unwrap(Array arrays, bool p_block_align, float p_
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PoolVector<int>::Read ri = rindices.read();
|
const int *ri = rindices.ptr();
|
||||||
|
|
||||||
for (int j = 0; j < ic / 3; j++) {
|
for (int j = 0; j < ic / 3; j++) {
|
||||||
indices.push_back(vertex_ofs + ri[j * 3 + 0]);
|
indices.push_back(vertex_ofs + ri[j * 3 + 0]);
|
||||||
@ -581,7 +581,7 @@ PoolVector2Array MeshUtils::uv_unwrap(Array arrays, bool p_block_align, float p_
|
|||||||
PoolVector2Array retarr;
|
PoolVector2Array retarr;
|
||||||
retarr.resize(output.vertexCount);
|
retarr.resize(output.vertexCount);
|
||||||
|
|
||||||
PoolVector2Array::Write retarrw = retarr.write();
|
Vector2 *retarrw = retarr.ptrw();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < output.vertexCount; i++) {
|
for (uint32_t i = 0; i < output.vertexCount; i++) {
|
||||||
int vind = output.vertexArray[i].xref;
|
int vind = output.vertexArray[i].xref;
|
||||||
@ -589,8 +589,6 @@ PoolVector2Array MeshUtils::uv_unwrap(Array arrays, bool p_block_align, float p_
|
|||||||
retarrw[vind] = Vector2(output.vertexArray[i].uv[0] / w, output.vertexArray[i].uv[1] / h);
|
retarrw[vind] = Vector2(output.vertexArray[i].uv[0] / w, output.vertexArray[i].uv[1] / h);
|
||||||
}
|
}
|
||||||
|
|
||||||
retarrw.release();
|
|
||||||
|
|
||||||
xatlas_mu::Destroy(atlas);
|
xatlas_mu::Destroy(atlas);
|
||||||
|
|
||||||
return retarr;
|
return retarr;
|
||||||
@ -601,7 +599,7 @@ PoolIntArray MeshUtils::delaunay3d_tetrahedralize(const Vector<Vector3> &p_point
|
|||||||
|
|
||||||
PoolIntArray ret;
|
PoolIntArray ret;
|
||||||
ret.resize(data.size() * 4);
|
ret.resize(data.size() * 4);
|
||||||
PoolIntArray::Write w = ret.write();
|
int64_t *w = ret.ptrw();
|
||||||
|
|
||||||
for (int i = 0; i < data.size(); ++i) {
|
for (int i = 0; i < data.size(); ++i) {
|
||||||
int indx = i * 4;
|
int indx = i * 4;
|
||||||
@ -614,8 +612,6 @@ PoolIntArray MeshUtils::delaunay3d_tetrahedralize(const Vector<Vector3> &p_point
|
|||||||
w[indx + 3] = s.points[3];
|
w[indx + 3] = s.points[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
w.release();
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ SOFTWARE.
|
|||||||
#ifndef MESH_UTILS_H
|
#ifndef MESH_UTILS_H
|
||||||
#define MESH_UTILS_H
|
#define MESH_UTILS_H
|
||||||
|
|
||||||
#include "core/variant.h"
|
#include "core/variant/variant.h"
|
||||||
#include "core/version.h"
|
#include "core/version.h"
|
||||||
|
|
||||||
#if VERSION_MAJOR > 3
|
#if VERSION_MAJOR > 3
|
||||||
|
@ -49,7 +49,7 @@ void initialize_mesh_utils_module(ModuleInitializationLevel p_level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize_mesh_utils_module(ModuleInitializationLevel p_level) {
|
void uninitialize_mesh_utils_module(ModuleInitializationLevel p_level) {
|
||||||
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
|
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||||
if (mesh_utils) {
|
if (mesh_utils) {
|
||||||
memdelete(mesh_utils);
|
memdelete(mesh_utils);
|
||||||
|
Loading…
Reference in New Issue
Block a user