- Implemented a much more efficient bone weight calculation.
- Added debug messages for measuring the time each step of a mesh slice takes.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "godot_cpp/classes/time.hpp"
|
||||
#include "godot_cpp/variant/utility_functions.hpp"
|
||||
using namespace godot;
|
||||
|
||||
@@ -25,11 +26,17 @@ MeshEditingLibrary::~MeshEditingLibrary()
|
||||
|
||||
PackedVector3Array MeshEditingLibrary::slice_mesh(const MeshInstance3D *original_mesh_instance, const Skeleton3D *original_skeleton, const Plane &local_plane, ArrayMesh *out_first_half, ArrayMesh *out_other_half, const MeshEditCapUV cap_option, const Ref<StandardMaterial3D> cap_material)
|
||||
{
|
||||
const Time *time = Time::get_singleton();
|
||||
|
||||
UtilityFunctions::print("Started slicing mesh at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
const Mesh *original_mesh = original_mesh_instance->get_mesh().ptr();
|
||||
const uint8_t num_surfaces = original_mesh->get_surface_count();
|
||||
|
||||
const SkinnedSurfaces &skinned_vertex_positions = MeshEditingLibrary::get_skinned_vertex_positions(original_mesh, original_skeleton);
|
||||
|
||||
UtilityFunctions::print("Got skinned vertices at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
PackedVector3Array impact_points;
|
||||
|
||||
PackedVector3Array cap_section_vertices;
|
||||
@@ -158,6 +165,8 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(const MeshInstance3D *original
|
||||
PackedInt32Array other_half_section_indices;
|
||||
const PackedInt32Array &surface_index_array = surface_arrays[ArrayMesh::ARRAY_INDEX];
|
||||
|
||||
UtilityFunctions::print("Surface ", surface, " sorted by plane distance at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
if (!(first_half_section_vertices.size() > 0 && other_half_section_vertices.size() > 0))
|
||||
{
|
||||
if (first_half_section_vertices.size() > 0)
|
||||
@@ -453,6 +462,8 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(const MeshInstance3D *original
|
||||
out_other_half->surface_set_material(surface, original_mesh->surface_get_material(surface));
|
||||
}
|
||||
|
||||
UtilityFunctions::print("Surface ", surface, " split edges at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
if (clip_edges.size() > 0)
|
||||
{
|
||||
std::vector<MeshEditEdge2D> edges_2d;
|
||||
@@ -535,6 +546,8 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(const MeshInstance3D *original
|
||||
impact_points.append(polygon_centroid);
|
||||
}
|
||||
}
|
||||
|
||||
UtilityFunctions::print("Surface ", surface, " created cap surface at ", time->get_ticks_msec(), "ms");
|
||||
}
|
||||
|
||||
if (cap_section_vertices.size() > 0 && cap_section_indices.size() > 0)
|
||||
@@ -576,6 +589,8 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(const MeshInstance3D *original
|
||||
out_other_half->surface_set_material(out_other_half->get_surface_count()-1, cap_material);
|
||||
}
|
||||
|
||||
UtilityFunctions::print("Generated final cap surface at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
return impact_points;
|
||||
}
|
||||
|
||||
@@ -585,6 +600,16 @@ SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mes
|
||||
SkinnedSurfaces skinned_vertex_surfaces;
|
||||
skinned_vertex_surfaces.resize(num_surfaces);
|
||||
|
||||
TypedArray<Transform3D> bone_transforms;
|
||||
if (skeleton)
|
||||
{
|
||||
const uint16_t bone_count = skeleton->get_bone_count();
|
||||
bone_transforms.resize(bone_count);
|
||||
for (uint8_t bone_index = 0; bone_index < bone_count; bone_index++)
|
||||
{
|
||||
bone_transforms[bone_index] = skeleton->get_bone_global_pose(bone_index) * skeleton->get_bone_global_rest(bone_index).inverse();
|
||||
}
|
||||
|
||||
for (uint8_t surface = 0; surface < num_surfaces; surface++)
|
||||
{
|
||||
const Array &mesh_arrays = mesh->surface_get_arrays(surface);
|
||||
@@ -607,9 +632,9 @@ SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mes
|
||||
const uint32_t bone_index_start = (vertex_index * num_bones_per_vertex);
|
||||
for (uint8_t bone_index_offset = 0; bone_index_offset < num_bones_per_vertex; bone_index_offset++)
|
||||
{
|
||||
const uint32_t bone = mesh_bones_array[bone_index_start + bone_index_offset];
|
||||
const float weight = mesh_weights_array[bone_index_start + bone_index_offset];
|
||||
transforms[bone_index_offset] = skeleton->get_bone_global_pose(bone) * skeleton->get_bone_global_rest(bone).inverse() * weight;
|
||||
const uint32_t bone = mesh_bones_array[bone_index_start + bone_index_offset];
|
||||
transforms[bone_index_offset] = ((Transform3D)bone_transforms[bone]) * weight;
|
||||
}
|
||||
|
||||
Vector3 x_basis, y_basis, z_basis, origin;
|
||||
@@ -635,18 +660,34 @@ SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mes
|
||||
delete transforms;
|
||||
}
|
||||
}
|
||||
|
||||
skinned_vertex_surfaces[surface] = skinned_vertex_array;
|
||||
}
|
||||
|
||||
return skinned_vertex_surfaces;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint8_t surface = 0; surface < num_surfaces; surface++)
|
||||
{
|
||||
const Array &mesh_arrays = mesh->surface_get_arrays(surface);
|
||||
|
||||
const PackedVector3Array &mesh_vertex_array = mesh_arrays[ArrayMesh::ARRAY_VERTEX];
|
||||
const uint32_t mesh_vertex_array_size = mesh_vertex_array.size();
|
||||
|
||||
SkinnedVertices skinned_vertex_array;
|
||||
skinned_vertex_array.resize(mesh_vertex_array_size);
|
||||
|
||||
for (uint32_t vertex_index = 0; vertex_index < mesh_vertex_array_size; vertex_index++)
|
||||
{
|
||||
skinned_vertex_array[vertex_index] = mesh_vertex_array[vertex_index];
|
||||
}
|
||||
}
|
||||
|
||||
skinned_vertex_surfaces[surface] = skinned_vertex_array;
|
||||
return skinned_vertex_surfaces;
|
||||
}
|
||||
|
||||
return skinned_vertex_surfaces;
|
||||
return SkinnedSurfaces();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user