Compare commits
2
Commits
52c2aab73c
...
306db05bfc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
306db05bfc | ||
|
|
a9fd36efa6 |
@@ -18,6 +18,8 @@
|
|||||||
#include <godot_cpp/classes/physical_bone3d.hpp>
|
#include <godot_cpp/classes/physical_bone3d.hpp>
|
||||||
#include <godot_cpp/classes/physical_bone_simulator3d.hpp>
|
#include <godot_cpp/classes/physical_bone_simulator3d.hpp>
|
||||||
#include <godot_cpp/classes/random_number_generator.hpp>
|
#include <godot_cpp/classes/random_number_generator.hpp>
|
||||||
|
#include <godot_cpp/classes/scene_tree.hpp>
|
||||||
|
#include <godot_cpp/classes/scene_tree_timer.hpp>
|
||||||
#include <godot_cpp/classes/skin.hpp>
|
#include <godot_cpp/classes/skin.hpp>
|
||||||
#include <godot_cpp/variant/utility_functions.hpp>
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
@@ -25,7 +27,6 @@ using namespace godot;
|
|||||||
|
|
||||||
void Character3D::_ready()
|
void Character3D::_ready()
|
||||||
{
|
{
|
||||||
this->skeleton_list.clear();
|
|
||||||
if (this->character_skeleton)
|
if (this->character_skeleton)
|
||||||
{
|
{
|
||||||
this->_rebuild_mesh_instances();
|
this->_rebuild_mesh_instances();
|
||||||
@@ -35,7 +36,7 @@ void Character3D::_ready()
|
|||||||
void Character3D::set_meshes(TypedArray<ArrayMesh> m)
|
void Character3D::set_meshes(TypedArray<ArrayMesh> m)
|
||||||
{
|
{
|
||||||
this->meshes = m;
|
this->meshes = m;
|
||||||
this->full_aabb = AABB();
|
this->_full_aabb = AABB();
|
||||||
this->_rebuild_mesh_instances();
|
this->_rebuild_mesh_instances();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,10 +49,21 @@ void Character3D::set_character_skeleton(CharacterSkeleton3D *cs)
|
|||||||
|
|
||||||
void Character3D::take_damage(const HurtboxDamage &hit_data)
|
void Character3D::take_damage(const HurtboxDamage &hit_data)
|
||||||
{
|
{
|
||||||
for (const auto &[character_skeleton, bones] : hit_data.bones)
|
if (this->_hurtbox_queue.empty())
|
||||||
{
|
CALL_NEXT_FRAME(callable_mp(this, &Character3D::_next_hurtbox_in_queue));
|
||||||
Skeleton3D *skeleton = character_skeleton->get_skeleton();
|
this->_hurtbox_queue.emplace_back(hit_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Character3D::_next_hurtbox_in_queue()
|
||||||
|
{
|
||||||
|
HurtboxDamage &hit_data = this->_hurtbox_queue.front();
|
||||||
|
if (!hit_data.bones.empty())
|
||||||
|
{
|
||||||
|
CharacterSkeleton3D *character_skeleton = hit_data.bones.begin()->first;
|
||||||
|
const std::vector<int32_t> &bone_hits = hit_data.bones.begin()->second;
|
||||||
|
hit_data.bones.erase(this->_hurtbox_queue.begin()->bones.begin());
|
||||||
|
|
||||||
|
Skeleton3D *skeleton = character_skeleton->get_skeleton();
|
||||||
const Plane &local_slice_plane = skeleton->get_global_transform().inverse().xform(Plane(hit_data.global_hit_transform.get_basis().get_column(1), hit_data.global_hit_transform.origin));
|
const Plane &local_slice_plane = skeleton->get_global_transform().inverse().xform(Plane(hit_data.global_hit_transform.get_basis().get_column(1), hit_data.global_hit_transform.origin));
|
||||||
|
|
||||||
std::vector<MeshInstance3D*> sliced_mesh_instances = character_skeleton->get_mesh_instances();
|
std::vector<MeshInstance3D*> sliced_mesh_instances = character_skeleton->get_mesh_instances();
|
||||||
@@ -63,7 +75,7 @@ void Character3D::take_damage(const HurtboxDamage &hit_data)
|
|||||||
MeshInstance3D *original_mesh_instance = sliced_mesh_instances[i];
|
MeshInstance3D *original_mesh_instance = sliced_mesh_instances[i];
|
||||||
Ref<ArrayMesh> first_half; first_half.instantiate();
|
Ref<ArrayMesh> first_half; first_half.instantiate();
|
||||||
Ref<ArrayMesh> other_half; other_half.instantiate();
|
Ref<ArrayMesh> other_half; other_half.instantiate();
|
||||||
PackedVector3Array &impact_points = MeshEditingLibrary::slice_mesh(original_mesh_instance, skeleton, this->full_aabb, local_slice_plane, first_half, other_half, MeshEditingLibrary::CAP_UV_FILL_MESH_BOUNDS, this->inner_materials);
|
PackedVector3Array &impact_points = MeshEditingLibrary::slice_mesh(original_mesh_instance, skeleton, this->_full_aabb, local_slice_plane, first_half, other_half, MeshEditingLibrary::CAP_UV_FILL_MESH_BOUNDS, this->inner_materials);
|
||||||
|
|
||||||
if (first_half->get_surface_count() <= 0 && other_half->get_surface_count() > 0)
|
if (first_half->get_surface_count() <= 0 && other_half->get_surface_count() > 0)
|
||||||
{
|
{
|
||||||
@@ -103,6 +115,13 @@ void Character3D::take_damage(const HurtboxDamage &hit_data)
|
|||||||
new_character_skeleton->set_meshes(other_half_meshes_to_add);
|
new_character_skeleton->set_meshes(other_half_meshes_to_add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->_hurtbox_queue.erase(this->_hurtbox_queue.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this->_hurtbox_queue.empty())
|
||||||
|
CALL_NEXT_FRAME(callable_mp(this, &Character3D::_next_hurtbox_in_queue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -114,34 +133,28 @@ void Character3D::_on_fell_out_of_world()
|
|||||||
|
|
||||||
void Character3D::_rebuild_mesh_instances()
|
void Character3D::_rebuild_mesh_instances()
|
||||||
{
|
{
|
||||||
if (!this->is_node_ready()) return;
|
if (!this->character_skeleton || !this->is_node_ready())
|
||||||
|
return;
|
||||||
|
|
||||||
uint16_t num_mesh_instances = this->_mesh_instances.size();
|
std::vector<MeshInstance3D*> mesh_instances = this->character_skeleton->set_meshes(this->meshes);
|
||||||
for (uint16_t i = 0; i < num_mesh_instances; i++)
|
const uint32_t num_meshes = mesh_instances.size();
|
||||||
|
this->_full_aabb = AABB();
|
||||||
|
for (const MeshInstance3D *mesh_instance : mesh_instances)
|
||||||
{
|
{
|
||||||
this->_mesh_instances[i]->queue_free();
|
const Vector3 &full_aabb_position = this->_full_aabb.get_position();
|
||||||
}
|
const Vector3 &full_aabb_size = this->_full_aabb.get_size();
|
||||||
|
|
||||||
if (!this->character_skeleton) return;
|
|
||||||
|
|
||||||
this->_mesh_instances = this->character_skeleton->set_meshes(this->meshes);
|
|
||||||
const uint32_t num_meshes = this->_mesh_instances.size();
|
|
||||||
for (const MeshInstance3D *mesh_instance : this->_mesh_instances)
|
|
||||||
{
|
|
||||||
const Vector3 &full_aabb_position = this->full_aabb.get_position();
|
|
||||||
const Vector3 &full_aabb_size = this->full_aabb.get_size();
|
|
||||||
|
|
||||||
const AABB &aabb = mesh_instance->get_aabb();
|
const AABB &aabb = mesh_instance->get_aabb();
|
||||||
const Vector3 &aabb_position = aabb.get_position();
|
const Vector3 &aabb_position = aabb.get_position();
|
||||||
const Vector3 &aabb_size = aabb.get_size();
|
const Vector3 &aabb_size = aabb.get_size();
|
||||||
|
|
||||||
this->full_aabb.set_position(Vector3(
|
this->_full_aabb.set_position(Vector3(
|
||||||
UtilityFunctions::minf(full_aabb_position.x, aabb_position.x),
|
UtilityFunctions::minf(full_aabb_position.x, aabb_position.x),
|
||||||
UtilityFunctions::minf(full_aabb_position.y, aabb_position.y),
|
UtilityFunctions::minf(full_aabb_position.y, aabb_position.y),
|
||||||
UtilityFunctions::minf(full_aabb_position.z, aabb_position.z)
|
UtilityFunctions::minf(full_aabb_position.z, aabb_position.z)
|
||||||
));
|
));
|
||||||
|
|
||||||
this->full_aabb.set_size(Vector3(
|
this->_full_aabb.set_size(Vector3(
|
||||||
UtilityFunctions::maxf(full_aabb_position.x, aabb_size.x),
|
UtilityFunctions::maxf(full_aabb_position.x, aabb_size.x),
|
||||||
UtilityFunctions::maxf(full_aabb_position.y, aabb_size.y),
|
UtilityFunctions::maxf(full_aabb_position.y, aabb_size.y),
|
||||||
UtilityFunctions::maxf(full_aabb_position.z, aabb_size.z)
|
UtilityFunctions::maxf(full_aabb_position.z, aabb_size.z)
|
||||||
|
|||||||
@@ -47,15 +47,15 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void _rebuild_mesh_instances();
|
void _rebuild_mesh_instances();
|
||||||
|
void _next_hurtbox_in_queue();
|
||||||
|
|
||||||
TypedArray<ArrayMesh> meshes;
|
TypedArray<ArrayMesh> meshes;
|
||||||
CharacterSkeleton3D *character_skeleton = nullptr;
|
CharacterSkeleton3D *character_skeleton = nullptr;
|
||||||
|
|
||||||
AABB full_aabb;
|
AABB _full_aabb;
|
||||||
TypedArray<Material> inner_materials;
|
TypedArray<Material> inner_materials;
|
||||||
|
|
||||||
std::vector<MeshInstance3D*> _mesh_instances;
|
std::vector<HurtboxDamage> _hurtbox_queue;
|
||||||
std::vector<CharacterSkeleton3D*> skeleton_list;
|
|
||||||
|
|
||||||
// Godot boilerplate below
|
// Godot boilerplate below
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include "orng_macros.h"
|
#include "orng_macros.h"
|
||||||
|
|
||||||
|
#include <godot_cpp/classes/scene_tree.hpp>
|
||||||
|
#include <godot_cpp/classes/scene_tree_timer.hpp>
|
||||||
#include <godot_cpp/classes/physical_bone3d.hpp>
|
#include <godot_cpp/classes/physical_bone3d.hpp>
|
||||||
#include <godot_cpp/variant/utility_functions.hpp>
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
@@ -18,27 +20,30 @@ std::vector<MeshInstance3D*> CharacterSkeleton3D::set_meshes(TypedArray<ArrayMes
|
|||||||
{
|
{
|
||||||
if (this->skeleton)
|
if (this->skeleton)
|
||||||
{
|
{
|
||||||
uint16_t num_mesh_instances = this->_mesh_instances.size();
|
this->_old_mesh_instances = this->_mesh_instances;
|
||||||
for (uint16_t i = 0; i < num_mesh_instances; i++)
|
|
||||||
{
|
|
||||||
this->_mesh_instances[i]->queue_free();
|
|
||||||
}
|
|
||||||
this->_mesh_instances.clear();
|
this->_mesh_instances.clear();
|
||||||
|
|
||||||
uint16_t num_new_meshes = meshes.size();
|
uint16_t num_new_meshes = meshes.size();
|
||||||
for (uint16_t i = 0; i < num_new_meshes; i++)
|
for (uint16_t i = 0; i < num_new_meshes; i++)
|
||||||
{
|
{
|
||||||
MeshInstance3D *mesh_instance = memnew(MeshInstance3D);
|
MeshInstance3D *mesh_instance = memnew(MeshInstance3D);
|
||||||
this->skeleton->add_child(mesh_instance, false, Node::INTERNAL_MODE_BACK);
|
|
||||||
mesh_instance->set_owner(this->get_owner());
|
|
||||||
mesh_instance->set_mesh(meshes[i]);
|
mesh_instance->set_mesh(meshes[i]);
|
||||||
mesh_instance->set_skeleton_path(this->skeleton->get_path());
|
mesh_instance->set_skeleton_path(this->skeleton->get_path());
|
||||||
|
this->skeleton->add_child(mesh_instance, false, Node::INTERNAL_MODE_BACK);
|
||||||
this->_mesh_instances.emplace_back(mesh_instance);
|
this->_mesh_instances.emplace_back(mesh_instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CALL_NEXT_FRAME(callable_mp(this, &CharacterSkeleton3D::_delete_old_meshes));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->_mesh_instances;
|
return this->_mesh_instances;
|
||||||
}
|
}
|
||||||
|
void CharacterSkeleton3D::_delete_old_meshes()
|
||||||
|
{
|
||||||
|
for (MeshInstance3D *old_mesh : this->_old_mesh_instances)
|
||||||
|
old_mesh->queue_free();
|
||||||
|
this->_old_mesh_instances.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CharacterSkeleton3D::_activate_ragdoll()
|
void CharacterSkeleton3D::_activate_ragdoll()
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ protected:
|
|||||||
void set_animation_tree(AnimationTree *at) { this->animation_tree = at; }
|
void set_animation_tree(AnimationTree *at) { this->animation_tree = at; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _refresh_skins_and_meshes();
|
// void _refresh_skins_and_meshes();
|
||||||
|
void _delete_old_meshes();
|
||||||
|
|
||||||
void _activate_ragdoll();
|
void _activate_ragdoll();
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ private:
|
|||||||
AnimationTree *animation_tree = nullptr;
|
AnimationTree *animation_tree = nullptr;
|
||||||
|
|
||||||
std::vector<MeshInstance3D*> _mesh_instances;
|
std::vector<MeshInstance3D*> _mesh_instances;
|
||||||
|
std::vector<MeshInstance3D*> _old_mesh_instances;
|
||||||
|
|
||||||
// Godot boilerplate below
|
// Godot boilerplate below
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#include <godot_cpp/variant/utility_functions.hpp>
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
|
||||||
void HurtboxBase::_enter_tree()
|
void HurtboxBase::_enter_tree()
|
||||||
{
|
{
|
||||||
@@ -58,7 +60,7 @@ void HurtboxBase::_physics_process(double delta)
|
|||||||
const TypedArray<Node3D> &bodies = this->get_overlapping_bodies();
|
const TypedArray<Node3D> &bodies = this->get_overlapping_bodies();
|
||||||
const uint32_t num_bodies = bodies.size();
|
const uint32_t num_bodies = bodies.size();
|
||||||
|
|
||||||
std::vector<IDamageable*> new_hit_bodies;
|
std::unordered_set<IDamageable*> new_hit_bodies;
|
||||||
std::vector<CharacterSkeleton3D*> new_hit_skeletons;
|
std::vector<CharacterSkeleton3D*> new_hit_skeletons;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < num_bodies; i++)
|
for (uint32_t i = 0; i < num_bodies; i++)
|
||||||
@@ -71,7 +73,7 @@ void HurtboxBase::_physics_process(double delta)
|
|||||||
{
|
{
|
||||||
if (std::find(this->hit_bodies.begin(), this->hit_bodies.end(), body) == this->hit_bodies.end())
|
if (std::find(this->hit_bodies.begin(), this->hit_bodies.end(), body) == this->hit_bodies.end())
|
||||||
{
|
{
|
||||||
new_hit_bodies.emplace_back(body);
|
new_hit_bodies.emplace(body);
|
||||||
|
|
||||||
if (std::find(new_hit_skeletons.begin(), new_hit_skeletons.end(), character_skeleton) == new_hit_skeletons.end())
|
if (std::find(new_hit_skeletons.begin(), new_hit_skeletons.end(), character_skeleton) == new_hit_skeletons.end())
|
||||||
{
|
{
|
||||||
@@ -110,12 +112,32 @@ void HurtboxBase::_send_next_in_queue()
|
|||||||
{
|
{
|
||||||
if (!this->hit_data_queue.empty())
|
if (!this->hit_data_queue.empty())
|
||||||
{
|
{
|
||||||
const std::map<IDamageable*, std::vector<HurtboxDamage>>::iterator &first_in_queue = this->hit_data_queue.begin();
|
IDamageable *closest_damageable = nullptr;
|
||||||
for (const HurtboxDamage &damage : first_in_queue->second)
|
float shortest_distance_from_hurtbox = FLT_MAX;
|
||||||
|
bool found_character_3d = false;
|
||||||
|
for (const auto &[damageable, hit_data_list] : this->hit_data_queue)
|
||||||
{
|
{
|
||||||
first_in_queue->first->take_damage(damage);
|
if (const Character3D *node = (Character3D*)(damageable))
|
||||||
|
{
|
||||||
|
const float distance_to_hurtbox = node->get_global_position().distance_squared_to(this->get_global_position());
|
||||||
|
if (distance_to_hurtbox < shortest_distance_from_hurtbox)
|
||||||
|
{
|
||||||
|
closest_damageable = damageable;
|
||||||
|
shortest_distance_from_hurtbox = distance_to_hurtbox;
|
||||||
|
found_character_3d = true;
|
||||||
|
}
|
||||||
|
// if (!found_character_3d && const SliceablePhysicsObject3D *node = (SliceablePhysicsObject3D*)(damageable) )
|
||||||
|
// {
|
||||||
|
// // This is where we handle regular physics objects.
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (closest_damageable)
|
||||||
|
{
|
||||||
|
for (const HurtboxDamage &damage : this->hit_data_queue[closest_damageable])
|
||||||
|
closest_damageable->take_damage(damage);
|
||||||
|
this->hit_data_queue.erase(closest_damageable);
|
||||||
}
|
}
|
||||||
this->hit_data_queue.erase(this->hit_data_queue.begin());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->hit_data_queue.empty() && this->remaining_life <= 0.0f)
|
if (this->hit_data_queue.empty() && this->remaining_life <= 0.0f)
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(MeshInstance3D *original_mesh_
|
|||||||
const Mesh *original_mesh = original_mesh_instance->get_mesh().ptr();
|
const Mesh *original_mesh = original_mesh_instance->get_mesh().ptr();
|
||||||
const uint8_t num_surfaces = original_mesh->get_surface_count();
|
const uint8_t num_surfaces = original_mesh->get_surface_count();
|
||||||
|
|
||||||
std::vector<std::vector<Transform3D>> skinned_vertex_transforms;
|
|
||||||
const SkinnedSurfaces &skinned_vertex_positions = MeshEditingLibrary::get_skinned_vertex_positions(original_mesh, original_skeleton, skinned_vertex_transforms);
|
|
||||||
|
|
||||||
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Got skinned vertices at ", time->get_ticks_msec(), "ms");
|
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Got skinned vertices at ", time->get_ticks_msec(), "ms");
|
||||||
|
|
||||||
PackedVector3Array impact_points;
|
PackedVector3Array impact_points;
|
||||||
@@ -77,13 +74,15 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(MeshInstance3D *original_mesh_
|
|||||||
PackedFloat32Array cap_section_weights;
|
PackedFloat32Array cap_section_weights;
|
||||||
PackedInt32Array cap_section_indices;
|
PackedInt32Array cap_section_indices;
|
||||||
|
|
||||||
|
std::vector<std::vector<Transform3D>> skinned_vertex_transforms;
|
||||||
std::vector<MeshEditEdge3D> clip_edges;
|
std::vector<MeshEditEdge3D> clip_edges;
|
||||||
|
|
||||||
for (uint8_t surface = 0; surface < num_surfaces; surface++)
|
for (uint8_t surface = 0; surface < num_surfaces; surface++)
|
||||||
{
|
{
|
||||||
Ref<Material> original_material = original_mesh->surface_get_material(surface);
|
Ref<Material> original_material = original_mesh->surface_get_material(surface);
|
||||||
|
|
||||||
const SkinnedVertices &surface_skinned_vertex_positions = skinned_vertex_positions[surface];
|
std::vector<Transform3D> surface_skinned_vertex_transforms;
|
||||||
|
const SkinnedVertices &surface_skinned_vertex_positions = MeshEditingLibrary::get_skinned_vertex_positions(surface, original_mesh, original_skeleton, surface_skinned_vertex_transforms);
|
||||||
|
|
||||||
const Array &surface_arrays = original_mesh->surface_get_arrays(surface);
|
const Array &surface_arrays = original_mesh->surface_get_arrays(surface);
|
||||||
const PackedVector3Array &surface_vertex_array = surface_arrays[ArrayMesh::ARRAY_VERTEX];
|
const PackedVector3Array &surface_vertex_array = surface_arrays[ArrayMesh::ARRAY_VERTEX];
|
||||||
@@ -414,6 +413,10 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(MeshInstance3D *original_mesh_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Transform3D &interp_bone_transform = surface_skinned_vertex_transforms[base_v[this_vert]].interpolate_with(
|
||||||
|
surface_skinned_vertex_transforms[base_v[next_vert]], alpha);
|
||||||
|
surface_skinned_vertex_transforms.emplace_back(interp_bone_transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,6 +479,8 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(MeshInstance3D *original_mesh_
|
|||||||
out_other_half->surface_set_material(next_surface, original_material);
|
out_other_half->surface_set_material(next_surface, original_material);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skinned_vertex_transforms.emplace_back(surface_skinned_vertex_transforms);
|
||||||
|
|
||||||
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", surface, " split edges at ", time->get_ticks_msec(), "ms");
|
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", surface, " split edges at ", time->get_ticks_msec(), "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,6 +521,7 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(MeshInstance3D *original_mesh_
|
|||||||
for (const MeshEditVert2D &vertex : polygon_set[polygon_index].vertices)
|
for (const MeshEditVert2D &vertex : polygon_set[polygon_index].vertices)
|
||||||
{
|
{
|
||||||
const Vector3 &position = first_half_vertices[vertex.surface][vertex.index];
|
const Vector3 &position = first_half_vertices[vertex.surface][vertex.index];
|
||||||
|
|
||||||
const Transform3D &skinned_vertex_transform = skinned_vertex_transforms[vertex.surface][vertex.index];
|
const Transform3D &skinned_vertex_transform = skinned_vertex_transforms[vertex.surface][vertex.index];
|
||||||
const Vector3 &local_plane_transformed_normal = skinned_vertex_transform.xform(local_plane_normal).normalized();
|
const Vector3 &local_plane_transformed_normal = skinned_vertex_transform.xform(local_plane_normal).normalized();
|
||||||
|
|
||||||
@@ -615,11 +621,15 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(MeshInstance3D *original_mesh_
|
|||||||
return impact_points;
|
return impact_points;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mesh, const Skeleton3D *skeleton, std::vector<std::vector<Transform3D>> &vertex_transforms)
|
SkinnedVertices MeshEditingLibrary::get_skinned_vertex_positions(const uint8_t surface, const Mesh *mesh, const Skeleton3D *skeleton, std::vector<Transform3D> &vertex_transforms)
|
||||||
{
|
{
|
||||||
const uint8_t num_surfaces = mesh->get_surface_count();
|
const uint8_t num_surfaces = mesh->get_surface_count();
|
||||||
SkinnedSurfaces skinned_vertex_surfaces;
|
if (surface > num_surfaces)
|
||||||
skinned_vertex_surfaces.resize(num_surfaces);
|
{
|
||||||
|
PRINT_ERROR(MESH_EDITING_LIBRARY_TAG, "This mesh doesn't have that many surfaces! You wrote ", surface, ", but there's only ", num_surfaces, "here!");
|
||||||
|
}
|
||||||
|
|
||||||
|
SkinnedVertices skinned_vertex_array;
|
||||||
|
|
||||||
if (skeleton)
|
if (skeleton)
|
||||||
{
|
{
|
||||||
@@ -631,61 +641,50 @@ SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mes
|
|||||||
bone_transforms[bone_index] = skeleton->get_bone_global_pose(bone_index) * skeleton->get_bone_global_rest(bone_index).inverse();
|
bone_transforms[bone_index] = skeleton->get_bone_global_pose(bone_index) * skeleton->get_bone_global_rest(bone_index).inverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
vertex_transforms.resize(num_surfaces);
|
const Array &mesh_arrays = mesh->surface_get_arrays(surface);
|
||||||
|
|
||||||
for (uint8_t surface = 0; surface < num_surfaces; surface++)
|
const PackedVector3Array &mesh_vertex_array = mesh_arrays[ArrayMesh::ARRAY_VERTEX];
|
||||||
|
const uint32_t mesh_vertex_array_size = mesh_vertex_array.size();
|
||||||
|
|
||||||
|
skinned_vertex_array.resize(mesh_vertex_array_size);
|
||||||
|
vertex_transforms.resize(mesh_vertex_array_size);
|
||||||
|
|
||||||
|
const PackedInt32Array &mesh_bones_array = mesh_arrays[ArrayMesh::ARRAY_BONES];
|
||||||
|
const PackedFloat32Array &mesh_weights_array = mesh_arrays[ArrayMesh::ARRAY_WEIGHTS];
|
||||||
|
const uint8_t num_bones_per_vertex = mesh_bones_array.size() / mesh_vertex_array_size;
|
||||||
|
for (uint32_t vertex_index = 0; vertex_index < mesh_vertex_array_size; vertex_index++)
|
||||||
{
|
{
|
||||||
const Array &mesh_arrays = mesh->surface_get_arrays(surface);
|
const Vector3 &vertex = mesh_vertex_array[vertex_index];
|
||||||
|
Transform3D *transforms = new Transform3D[num_bones_per_vertex];
|
||||||
const PackedVector3Array &mesh_vertex_array = mesh_arrays[ArrayMesh::ARRAY_VERTEX];
|
const uint32_t bone_index_start = (vertex_index * num_bones_per_vertex);
|
||||||
const uint32_t mesh_vertex_array_size = mesh_vertex_array.size();
|
for (uint8_t bone_index_offset = 0; bone_index_offset < num_bones_per_vertex; bone_index_offset++)
|
||||||
|
|
||||||
SkinnedVertices skinned_vertex_array;
|
|
||||||
skinned_vertex_array.resize(mesh_vertex_array_size);
|
|
||||||
|
|
||||||
std::vector<Transform3D> skinned_vertex_transforms;
|
|
||||||
skinned_vertex_transforms.resize(mesh_vertex_array_size);
|
|
||||||
|
|
||||||
const PackedInt32Array &mesh_bones_array = mesh_arrays[ArrayMesh::ARRAY_BONES];
|
|
||||||
const PackedFloat32Array &mesh_weights_array = mesh_arrays[ArrayMesh::ARRAY_WEIGHTS];
|
|
||||||
const uint8_t num_bones_per_vertex = mesh_bones_array.size() / mesh_vertex_array_size;
|
|
||||||
for (uint32_t vertex_index = 0; vertex_index < mesh_vertex_array_size; vertex_index++)
|
|
||||||
{
|
{
|
||||||
const Vector3 &vertex = mesh_vertex_array[vertex_index];
|
const float weight = mesh_weights_array[bone_index_start + bone_index_offset];
|
||||||
Transform3D *transforms = new Transform3D[num_bones_per_vertex];
|
const uint32_t bone = mesh_bones_array[bone_index_start + bone_index_offset];
|
||||||
const uint32_t bone_index_start = (vertex_index * num_bones_per_vertex);
|
transforms[bone_index_offset] = ((Transform3D)bone_transforms[bone]) * weight;
|
||||||
for (uint8_t bone_index_offset = 0; bone_index_offset < num_bones_per_vertex; bone_index_offset++)
|
|
||||||
{
|
|
||||||
const float weight = mesh_weights_array[bone_index_start + bone_index_offset];
|
|
||||||
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;
|
|
||||||
for (uint8_t transform = 0; transform < num_bones_per_vertex; transform++)
|
|
||||||
{
|
|
||||||
x_basis += transforms[transform].basis.rows[0];
|
|
||||||
y_basis += transforms[transform].basis.rows[1];
|
|
||||||
z_basis += transforms[transform].basis.rows[2];
|
|
||||||
origin += transforms[transform].origin;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Transform3D &final_bone_transform = Transform3D(
|
|
||||||
x_basis.x, x_basis.y, x_basis.z,
|
|
||||||
y_basis.x, y_basis.y, y_basis.z,
|
|
||||||
z_basis.x, z_basis.y, z_basis.z,
|
|
||||||
origin.x, origin.y, origin.z);
|
|
||||||
skinned_vertex_transforms[vertex_index] = final_bone_transform;
|
|
||||||
skinned_vertex_array[vertex_index] = final_bone_transform.xform(vertex);
|
|
||||||
|
|
||||||
delete transforms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
skinned_vertex_surfaces[surface] = skinned_vertex_array;
|
Vector3 x_basis, y_basis, z_basis, origin;
|
||||||
vertex_transforms[surface] = skinned_vertex_transforms;
|
for (uint8_t transform = 0; transform < num_bones_per_vertex; transform++)
|
||||||
|
{
|
||||||
|
x_basis += transforms[transform].basis.rows[0];
|
||||||
|
y_basis += transforms[transform].basis.rows[1];
|
||||||
|
z_basis += transforms[transform].basis.rows[2];
|
||||||
|
origin += transforms[transform].origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Transform3D &final_bone_transform = Transform3D(
|
||||||
|
x_basis.x, x_basis.y, x_basis.z,
|
||||||
|
y_basis.x, y_basis.y, y_basis.z,
|
||||||
|
z_basis.x, z_basis.y, z_basis.z,
|
||||||
|
origin.x, origin.y, origin.z);
|
||||||
|
vertex_transforms[vertex_index] = final_bone_transform;
|
||||||
|
skinned_vertex_array[vertex_index] = final_bone_transform.xform(vertex);
|
||||||
|
|
||||||
|
delete transforms;
|
||||||
}
|
}
|
||||||
|
|
||||||
return skinned_vertex_surfaces;
|
return skinned_vertex_array;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -703,14 +702,12 @@ SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mes
|
|||||||
{
|
{
|
||||||
skinned_vertex_array[vertex_index] = mesh_vertex_array[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_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SkinnedSurfaces();
|
return SkinnedVertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
static const Vector2 calculate_planar_uv(const Vector3 &vertex, const Vector3 &mesh_bounds, const MeshSlicePlaneOrientation &axis);
|
static const Vector2 calculate_planar_uv(const Vector3 &vertex, const Vector3 &mesh_bounds, const MeshSlicePlaneOrientation &axis);
|
||||||
|
|
||||||
static SkinnedSurfaces get_skinned_vertex_positions(const Mesh *mesh, const Skeleton3D *skeleton = nullptr, std::vector<std::vector<Transform3D>> &bone_transforms = std::vector<std::vector<Transform3D>>());
|
static SkinnedVertices get_skinned_vertex_positions(const uint8_t surface, const Mesh *mesh, const Skeleton3D *skeleton = nullptr, std::vector<Transform3D> &bone_transforms = std::vector<Transform3D>());
|
||||||
|
|
||||||
static const Transform3D project_edges(std::vector<MeshEditEdge2D> &out_2d_edges, const std::vector<MeshEditEdge3D> &in_3d_edges, const Plane &plane);
|
static const Transform3D project_edges(std::vector<MeshEditEdge2D> &out_2d_edges, const std::vector<MeshEditEdge3D> &in_3d_edges, const Plane &plane);
|
||||||
static void build_2d_polygons_from_edges(std::vector<MeshEditPolygon2D> &out_polygons, const std::vector<MeshEditEdge2D> &in_edges, std::vector<MeshEditPolygon2D> &error_polygons);
|
static void build_2d_polygons_from_edges(std::vector<MeshEditPolygon2D> &out_polygons, const std::vector<MeshEditEdge2D> &in_edges, std::vector<MeshEditPolygon2D> &error_polygons);
|
||||||
|
|||||||
Reference in New Issue
Block a user