diff --git a/mesh_merger.cpp b/mesh_merger.cpp index e10d9b7..809ffab 100644 --- a/mesh_merger.cpp +++ b/mesh_merger.cpp @@ -396,7 +396,7 @@ void MeshMerger::remove_doubles() { for (int j = 0; j < indices.size(); ++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 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) { int index = indices[j]; - hashes.remove(index); - _vertices.remove(index); + hashes.remove_at(index); + _vertices.remove_at(index); //make all indices that were bigger than the one we replaced one lower 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) { - _vertices.remove(idx); + _vertices.remove_at(idx); } PoolVector MeshMerger::get_normals() const { @@ -917,7 +917,7 @@ int MeshMerger::get_index(const int idx) const { } void MeshMerger::remove_index(const int idx) { - _indices.remove(idx); + _indices.remove_at(idx); } 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))); #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("get_vertices"), &MeshMerger::get_vertices); diff --git a/mesh_merger.h b/mesh_merger.h index a07bb39..11ee2e7 100644 --- a/mesh_merger.h +++ b/mesh_merger.h @@ -28,20 +28,19 @@ SOFTWARE. #include "core/version.h" #if VERSION_MAJOR > 3 -#include "core/object/reference.h" -#include "core/templates/vector.h" #include "core/math/color.h" +#include "core/object/ref_counted.h" +#include "core/templates/vector.h" #else +#include "core/color.h" #include "core/reference.h" #include "core/vector.h" -#include "core/color.h" #endif #include "defines.h" #include pool_vector_h include_pool_vector - #include mesh_instance_h #include "core/math/rect2.h" @@ -55,12 +54,11 @@ include_pool_vector #include "../mesh_data_resource/mesh_data_resource.h" #endif - class MeshMerger : public Reference { - GDCLASS(MeshMerger, Reference); + class MeshMerger : public RefCounted { + GDCLASS(MeshMerger, RefCounted); public: struct Vertex { - Vector3 vertex; Color color; Vector3 normal; // normal, binormal, tangent diff --git a/mesh_utils.cpp b/mesh_utils.cpp index ccbeea3..7b04cd6 100644 --- a/mesh_utils.cpp +++ b/mesh_utils.cpp @@ -21,8 +21,8 @@ SOFTWARE. */ #include "mesh_utils.h" -#include "core/local_vector.h" -#include "core/variant.h" +#include "core/templates/local_vector.h" +#include "core/variant/variant.h" #include "scene/resources/mesh.h" #include visual_server_h @@ -77,25 +77,25 @@ Array MeshUtils::merge_mesh_array(Array arr) const { int rem = equals[k]; int remk = rem - k; - verts.remove(remk); + verts.remove_at(remk); if (normals.size() > 0) - normals.remove(remk); + normals.remove_at(remk); if (uvs.size() > 0) - uvs.remove(remk); + uvs.remove_at(remk); if (colors.size() > 0) - colors.remove(remk); + colors.remove_at(remk); if (bones.size() > 0) { int bindex = remk * 4; for (int l = 0; l < 4; ++l) { - bones.remove(bindex); + bones.remove_at(bindex); } } if (weights.size() > 0) { int bindex = remk * 4; 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 tex, float mul_color ERR_FAIL_COND_V(arr.size() != VisualServer::ARRAY_MAX, arr); ERR_FAIL_COND_V(!tex.is_valid(), arr); - Ref img = tex->get_data(); + Ref img = tex->get_image(); ERR_FAIL_COND_V(!img.is_valid(), arr); @@ -271,25 +271,25 @@ Array MeshUtils::remove_doubles(Array arr) const { int rem = equals[k]; int remk = rem - k; - verts.remove(remk); + verts.remove_at(remk); if (normals.size() > 0) { - normals.remove(remk); + normals.remove_at(remk); } if (uvs.size() > 0) { - uvs.remove(remk); + uvs.remove_at(remk); } if (colors.size() > 0) { - colors.remove(remk); + colors.remove_at(remk); } if (bones.size() > 0) { int bindex = remk * 4; for (int l = 0; l < 4; ++l) { - bones.remove(bindex); - weights.remove(bindex); + bones.remove_at(bindex); + weights.remove_at(bindex); } } @@ -423,32 +423,32 @@ Array MeshUtils::remove_doubles_interpolate_normals(Array arr) const { int rem = equals[k]; int remk = rem - k; - verts.remove(remk); + verts.remove_at(remk); if (normals.size() > 0) { Vector3 n = normals[remk]; - normals.remove(remk); + normals.remove_at(remk); if (k == 0) { normal = n; } else { - normal = normal.linear_interpolate(n, 0.5); + normal = normal.lerp(n, 0.5); } } if (uvs.size() > 0) { - uvs.remove(remk); + uvs.remove_at(remk); } if (colors.size() > 0) { - colors.remove(remk); + colors.remove_at(remk); } if (bones.size() > 0) { int bindex = remk * 4; for (int l = 0; l < 4; ++l) { - bones.remove(bindex); - weights.remove(bindex); + bones.remove_at(bindex); + weights.remove_at(bindex); } } @@ -491,12 +491,12 @@ PoolVector2Array MeshUtils::uv_unwrap(Array arrays, bool p_block_align, float p_ LocalVector normals; LocalVector indices; - PoolVector rvertices = arrays[Mesh::ARRAY_VERTEX]; + Vector rvertices = arrays[Mesh::ARRAY_VERTEX]; int vc = rvertices.size(); - PoolVector::Read r = rvertices.read(); + const Vector3 *r = rvertices.ptr(); - PoolVector rnormals = arrays[Mesh::ARRAY_NORMAL]; - PoolVector::Read rn = rnormals.read(); + Vector rnormals = arrays[Mesh::ARRAY_NORMAL]; + const Vector3 *rn = rnormals.ptr(); 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; } - PoolVector rindices = arrays[Mesh::ARRAY_INDEX]; + Vector rindices = arrays[Mesh::ARRAY_INDEX]; int ic = rindices.size(); if (ic == 0) { @@ -526,7 +526,7 @@ PoolVector2Array MeshUtils::uv_unwrap(Array arrays, bool p_block_align, float p_ } } else { - PoolVector::Read ri = rindices.read(); + const int *ri = rindices.ptr(); for (int j = 0; j < ic / 3; j++) { 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; retarr.resize(output.vertexCount); - PoolVector2Array::Write retarrw = retarr.write(); + Vector2 *retarrw = retarr.ptrw(); for (uint32_t i = 0; i < output.vertexCount; i++) { 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.release(); - xatlas_mu::Destroy(atlas); return retarr; @@ -601,7 +599,7 @@ PoolIntArray MeshUtils::delaunay3d_tetrahedralize(const Vector &p_point PoolIntArray ret; ret.resize(data.size() * 4); - PoolIntArray::Write w = ret.write(); + int64_t *w = ret.ptrw(); for (int i = 0; i < data.size(); ++i) { int indx = i * 4; @@ -614,8 +612,6 @@ PoolIntArray MeshUtils::delaunay3d_tetrahedralize(const Vector &p_point w[indx + 3] = s.points[3]; } - w.release(); - return ret; } diff --git a/mesh_utils.h b/mesh_utils.h index 7138ab6..e026801 100644 --- a/mesh_utils.h +++ b/mesh_utils.h @@ -23,7 +23,7 @@ SOFTWARE. #ifndef MESH_UTILS_H #define MESH_UTILS_H -#include "core/variant.h" +#include "core/variant/variant.h" #include "core/version.h" #if VERSION_MAJOR > 3 diff --git a/register_types.cpp b/register_types.cpp index 29fefdd..aad25fc 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -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 (mesh_utils) { memdelete(mesh_utils);