Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00332be60c | ||
|
|
1a38b7bf19 | ||
|
|
4e0b756000 |
+1
-1
@@ -3,7 +3,7 @@ env.Append(CPPPATH="liborng/")
|
||||
env.Append(CPPPATH="liborng/data_assets")
|
||||
env.Append(CPPPATH="liborng/nodes/interfaces")
|
||||
env.Append(CPPPATH="liborng/nodes")
|
||||
env.Append(CPPPATH="liborng/nodes/character_nodes")
|
||||
env.Append(CPPPATH="liborng/nodes/damageables")
|
||||
env.Append(CPPPATH="liborng/resources")
|
||||
env.Append(CPPPATH="liborng/singletons")
|
||||
env.Append(CPPPATH="liborng/singletons/vendor_service")
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* ©2026 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||
*
|
||||
* If this source code makes it to the public internet, this software can be
|
||||
* considered to be protected by the MIT licence. Have fun with it.
|
||||
*/
|
||||
|
||||
#include "i_damageable.h"
|
||||
|
||||
#include "orng_macros.h"
|
||||
|
||||
#include "godot_cpp/classes/scene_tree.hpp"
|
||||
#include "godot_cpp/classes/scene_tree_timer.hpp"
|
||||
|
||||
|
||||
void IDamageable::_slice_meshes(Ref<MeshEditSliceInput> data)
|
||||
{
|
||||
this->_is_slicing = true;
|
||||
this->_input_queue.emplace_back(data);
|
||||
if (this->_slice_state_queue.empty())
|
||||
this->_new_slice_loop();
|
||||
}
|
||||
|
||||
void IDamageable::_new_slice_loop()
|
||||
{
|
||||
this->_slice_state_queue.emplace_back(MeshEditingLibrary::slice_mesh(this->_input_queue.front()));
|
||||
this->_slice_loop();
|
||||
}
|
||||
|
||||
void IDamageable::_slice_loop()
|
||||
{
|
||||
Ref<MeshSliceState> current_state = this->_slice_state_queue.front();
|
||||
switch(current_state->current_stage)
|
||||
{
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_INIT:
|
||||
MeshEditingLibrary::slice_mesh_init(current_state);
|
||||
break;
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_PLANE_SPLIT:
|
||||
MeshEditingLibrary::slice_mesh_plane_split(current_state);
|
||||
break;
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_EDGE_SPLIT:
|
||||
MeshEditingLibrary::slice_mesh_edge_split(current_state);
|
||||
break;
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_APPLY_CAP:
|
||||
MeshEditingLibrary::slice_mesh_apply_cap(current_state);
|
||||
break;
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_COMPLETE:
|
||||
this->_slice_complete(current_state->output);
|
||||
this->_input_queue.erase(this->_input_queue.begin());
|
||||
this->_slice_state_queue.erase(this->_slice_state_queue.begin());
|
||||
if (!this->_input_queue.empty())
|
||||
return this->_new_slice_loop();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this->_input_queue.empty())
|
||||
CALL_NEXT_FRAME(callable_mp(this, &IDamageable::_slice_loop));
|
||||
else
|
||||
this->_is_slicing = false;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* ©2026 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||
*
|
||||
* If this source code makes it to the public internet, this software can be
|
||||
* considered to be protected by the MIT licence. Have fun with it.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "nodes/mesh_editing_library.h"
|
||||
|
||||
#include "godot_cpp/classes/node.hpp"
|
||||
using namespace godot;
|
||||
|
||||
|
||||
class IDamageable : public Node3D
|
||||
{
|
||||
public:
|
||||
virtual void take_damage(const struct HurtboxDamage &hit_data) = 0;
|
||||
|
||||
protected:
|
||||
void _slice_meshes(Ref<MeshEditSliceInput> data);
|
||||
|
||||
virtual void _slice_complete(Ref<MeshEditSliceOutput> data) = 0;
|
||||
|
||||
private:
|
||||
void _new_slice_loop();
|
||||
void _slice_loop();
|
||||
|
||||
bool _is_slicing = false;
|
||||
|
||||
std::vector<Ref<MeshSliceState>> _slice_state_queue;
|
||||
std::vector<Ref<MeshEditSliceInput>> _input_queue;
|
||||
|
||||
// Godot boilerplate below
|
||||
protected:
|
||||
static void _bind_methods() {}
|
||||
};
|
||||
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
* ©2026 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||
*
|
||||
* If this source code makes it to the public internet, this software can be
|
||||
* considered to be protected by the MIT licence. Have fun with it.
|
||||
*/
|
||||
|
||||
#include "character_3d.h"
|
||||
|
||||
#include "orng_macros.h"
|
||||
|
||||
#include "nodes/debug_draw3d.h"
|
||||
#include "nodes/mesh_editing_library.h"
|
||||
#include "nodes/hurtbox/hurtbox_base.h"
|
||||
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/mesh_instance3d.hpp>
|
||||
#include <godot_cpp/classes/physical_bone3d.hpp>
|
||||
#include <godot_cpp/classes/physical_bone_simulator3d.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/variant/utility_functions.hpp>
|
||||
using namespace godot;
|
||||
|
||||
|
||||
void Character3D::_ready()
|
||||
{
|
||||
if (this->character_skeleton)
|
||||
{
|
||||
this->_rebuild_mesh_instances();
|
||||
}
|
||||
}
|
||||
|
||||
void Character3D::set_meshes(TypedArray<ArrayMesh> m)
|
||||
{
|
||||
this->meshes = m;
|
||||
this->_full_aabb = AABB();
|
||||
this->_rebuild_mesh_instances();
|
||||
}
|
||||
|
||||
void Character3D::set_character_skeleton(CharacterSkeleton3D *cs)
|
||||
{
|
||||
if (cs)
|
||||
{
|
||||
if (this->character_skeleton)
|
||||
{
|
||||
this->skeleton_set.erase(this->character_skeleton);
|
||||
this->character_skeleton->queue_free();
|
||||
}
|
||||
this->character_skeleton = cs;
|
||||
this->skeleton_set.emplace(this->character_skeleton);
|
||||
this->_rebuild_mesh_instances();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Character3D::take_damage(const HurtboxDamage &hit_data)
|
||||
{
|
||||
if (this->_hurtbox_queue.empty())
|
||||
CALL_NEXT_FRAME(callable_mp(this, &Character3D::_next_hurtbox_in_queue));
|
||||
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));
|
||||
|
||||
TypedArray<MeshInstance3D> sliced_mesh_instances = character_skeleton->get_mesh_instances();
|
||||
const uint32_t num_mesh_instances = sliced_mesh_instances.size();
|
||||
TypedArray<ArrayMesh> first_half_meshes_to_add;
|
||||
TypedArray<ArrayMesh> other_half_meshes_to_add;
|
||||
|
||||
Ref<MeshEditSliceInput> input; input.instantiate();
|
||||
input->mesh_instance = cast_to<MeshInstance3D>(sliced_mesh_instances[0]);
|
||||
input->skeleton = skeleton;
|
||||
input->full_aabb = this->_full_aabb;
|
||||
input->local_plane = local_slice_plane;
|
||||
input->cap_option = MeshEditingLibrary::CAP_UV_FILL_MESH_BOUNDS;
|
||||
input->cap_materials = this->inner_materials;
|
||||
this->_slice_meshes(input);
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
void Character3D::_slice_complete(Ref<MeshEditSliceOutput> data)
|
||||
{
|
||||
if (data->main_half->get_surface_count() <= 0 && data->secondary_half->get_surface_count() > 0)
|
||||
{
|
||||
Ref<ArrayMesh> temp = data->main_half;
|
||||
data->main_half = data->secondary_half;
|
||||
data->secondary_half = temp;
|
||||
}
|
||||
|
||||
TypedArray<ArrayMesh> first_half_meshes_to_add;
|
||||
TypedArray<ArrayMesh> other_half_meshes_to_add;
|
||||
|
||||
if (data->main_half->get_surface_count() > 0)
|
||||
{
|
||||
first_half_meshes_to_add.append(data->main_half);
|
||||
}
|
||||
|
||||
if (data->secondary_half->get_surface_count() > 0)
|
||||
{
|
||||
other_half_meshes_to_add.append(data->secondary_half);
|
||||
}
|
||||
|
||||
for (CharacterSkeleton3D *skeleton : this->skeleton_set)
|
||||
{
|
||||
if (skeleton->get_skeleton() == data->original_skeleton)
|
||||
{
|
||||
skeleton->set_meshes(first_half_meshes_to_add);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (other_half_meshes_to_add.size() > 0)
|
||||
{
|
||||
RandomNumberGenerator *rng = memnew(RandomNumberGenerator);
|
||||
const float random_x = rng->randf_range(-0.05f, 0.05f);
|
||||
const float random_z = rng->randf_range(-0.05f, 0.05f);
|
||||
|
||||
CharacterSkeleton3D *new_character_skeleton = cast_to<CharacterSkeleton3D>(this->character_skeleton->duplicate());
|
||||
this->character_skeleton->add_sibling(new_character_skeleton);
|
||||
new_character_skeleton->set_position(Vector3(random_x, 0.0f, random_z));
|
||||
|
||||
PRINT_LOG(CHARACTER3D_TAG, "Adding new meshes:");
|
||||
for (uint16_t i = 0; i < other_half_meshes_to_add.size(); i++)
|
||||
{
|
||||
const Ref<ArrayMesh> &new_array_mesh = other_half_meshes_to_add[i];
|
||||
PRINT_LOG(CHARACTER3D_TAG, " Mesh ", i+1, " size: ", new_array_mesh->get_surface_count());
|
||||
}
|
||||
new_character_skeleton->set_meshes(other_half_meshes_to_add);
|
||||
|
||||
this->skeleton_set.emplace(new_character_skeleton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Character3D::_on_fell_out_of_world()
|
||||
{
|
||||
this->emit_signal("fell_out_of_world");
|
||||
}
|
||||
|
||||
|
||||
void Character3D::_rebuild_mesh_instances()
|
||||
{
|
||||
if (!this->character_skeleton || !this->is_node_ready())
|
||||
return;
|
||||
|
||||
TypedArray<MeshInstance3D> mesh_instances = this->character_skeleton->set_meshes(this->meshes);
|
||||
const uint32_t num_meshes = mesh_instances.size();
|
||||
this->_full_aabb = AABB();
|
||||
for (uint32_t i = 0; i < num_meshes; i++)
|
||||
{
|
||||
const MeshInstance3D *mesh_instance = cast_to<MeshInstance3D>(mesh_instances[i]);
|
||||
|
||||
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 Vector3 &aabb_position = aabb.get_position();
|
||||
const Vector3 &aabb_size = aabb.get_size();
|
||||
|
||||
this->_full_aabb.set_position(Vector3(
|
||||
UtilityFunctions::minf(full_aabb_position.x, aabb_position.x),
|
||||
UtilityFunctions::minf(full_aabb_position.y, aabb_position.y),
|
||||
UtilityFunctions::minf(full_aabb_position.z, aabb_position.z)
|
||||
));
|
||||
|
||||
this->_full_aabb.set_size(Vector3(
|
||||
UtilityFunctions::maxf(full_aabb_position.x, aabb_size.x),
|
||||
UtilityFunctions::maxf(full_aabb_position.y, aabb_size.y),
|
||||
UtilityFunctions::maxf(full_aabb_position.z, aabb_size.z)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* ©2026 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||
*
|
||||
* If this source code makes it to the public internet, this software can be
|
||||
* considered to be protected by the MIT licence. Have fun with it.
|
||||
*/
|
||||
|
||||
#include "character_3d.h"
|
||||
|
||||
#include "orng_macros.h"
|
||||
|
||||
#include "nodes/debug_draw3d.h"
|
||||
#include "nodes/hurtbox/hurtbox_base.h"
|
||||
#include "singletons/mesh_editing_library.h"
|
||||
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/mesh_instance3d.hpp>
|
||||
#include <godot_cpp/classes/physical_bone3d.hpp>
|
||||
#include <godot_cpp/classes/physical_bone_simulator3d.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/variant/utility_functions.hpp>
|
||||
using namespace godot;
|
||||
|
||||
|
||||
void Character3D::set_character_skeleton(CharacterSkeleton3D *cs)
|
||||
{
|
||||
if (cs)
|
||||
{
|
||||
if (this->character_skeleton)
|
||||
{
|
||||
this->_skeleton_set.erase(this->character_skeleton);
|
||||
this->character_skeleton->queue_free();
|
||||
}
|
||||
this->character_skeleton = cs;
|
||||
this->_skeleton_set.emplace(this->character_skeleton);
|
||||
this->_rebuild_mesh_instance();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Character3D::take_damage(const HurtboxDamage &hit_data)
|
||||
{
|
||||
if (this->_hurtbox_queue.empty())
|
||||
CALL_NEXT_FRAME(callable_mp(this, &Character3D::_next_hurtbox_in_queue));
|
||||
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));
|
||||
|
||||
Ref<MeshEditSliceInput> input; input.instantiate();
|
||||
input->mesh_instance = character_skeleton->get_mesh_instance();
|
||||
input->skeleton = skeleton;
|
||||
input->full_aabb = this->_aabb;
|
||||
input->local_plane = local_slice_plane;
|
||||
input->cap_option = MeshEditingLibrary::CAP_UV_FILL_MESH_BOUNDS;
|
||||
input->cap_materials = this->inner_materials;
|
||||
this->_slice_meshes(input);
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
void Character3D::_slice_complete(Ref<MeshEditSliceOutput> data)
|
||||
{
|
||||
if (data->main_half->get_surface_count() <= 0)
|
||||
{
|
||||
if (data->secondary_half->get_surface_count() <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<ArrayMesh> temp = data->main_half;
|
||||
data->main_half = data->secondary_half;
|
||||
data->secondary_half = temp;
|
||||
}
|
||||
|
||||
if (data->original_skeleton)
|
||||
{
|
||||
for (CharacterSkeleton3D *skeleton : this->_skeleton_set)
|
||||
{
|
||||
if (skeleton->get_skeleton() == data->original_skeleton)
|
||||
{
|
||||
MeshInstance3D *new_mesh_instance = memnew(MeshInstance3D);
|
||||
new_mesh_instance->set_mesh(data->main_half);
|
||||
skeleton->set_mesh(new_mesh_instance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (data->secondary_half.is_valid())
|
||||
{
|
||||
RandomNumberGenerator *rng = memnew(RandomNumberGenerator);
|
||||
const float random_x = rng->randf_range(-0.01f, 0.01f);
|
||||
const float random_z = rng->randf_range(-0.01f, 0.01f);
|
||||
|
||||
CharacterSkeleton3D *new_character_skeleton = cast_to<CharacterSkeleton3D>(this->character_skeleton->duplicate());
|
||||
this->character_skeleton->add_sibling(new_character_skeleton);
|
||||
new_character_skeleton->set_position(Vector3(random_x, 0.0f, random_z));
|
||||
|
||||
MeshInstance3D *new_mesh_instance = memnew(MeshInstance3D);
|
||||
new_mesh_instance->set_mesh(data->secondary_half);
|
||||
new_character_skeleton->set_mesh(new_mesh_instance);
|
||||
|
||||
this->_skeleton_set.emplace(new_character_skeleton);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Character3D::_on_fell_out_of_world()
|
||||
{
|
||||
this->emit_signal("fell_out_of_world");
|
||||
}
|
||||
|
||||
|
||||
MeshInstance3D *Character3D::_rebuild_mesh_instance()
|
||||
{
|
||||
if (MeshInstance3D *returned_instance = DamageableNode3D::_rebuild_mesh_instance())
|
||||
{
|
||||
this->character_skeleton->set_mesh(returned_instance);
|
||||
return returned_instance;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
+6
-20
@@ -9,8 +9,8 @@
|
||||
|
||||
#include "orng_macros.h"
|
||||
|
||||
#include "interfaces/i_damageable.h"
|
||||
#include "nodes/character_nodes/character_skeleton3d.h"
|
||||
#include "nodes/damageables/damageable_node3d.h"
|
||||
#include "nodes/damageables/character_skeleton3d.h"
|
||||
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
@@ -25,42 +25,30 @@ using namespace godot;
|
||||
#define CHARACTER3D_TAG "Character3D"
|
||||
|
||||
|
||||
class Character3D : public IDamageable
|
||||
class Character3D : public DamageableNode3D
|
||||
{
|
||||
GDCLASS(Character3D, IDamageable);
|
||||
GDCLASS(Character3D, DamageableNode3D);
|
||||
|
||||
public:
|
||||
virtual void _ready() override;
|
||||
|
||||
virtual void take_damage(const HurtboxDamage &hit_data) override;
|
||||
|
||||
TypedArray<ArrayMesh> get_meshes() const { return this->meshes; }
|
||||
CharacterSkeleton3D *get_character_skeleton() const { return this->character_skeleton; }
|
||||
|
||||
TypedArray<Material> get_inner_materials() const { return this->inner_materials; }
|
||||
|
||||
virtual void _on_fell_out_of_world();
|
||||
|
||||
protected:
|
||||
void set_meshes(TypedArray<ArrayMesh> m);
|
||||
void set_character_skeleton(CharacterSkeleton3D *cs);
|
||||
|
||||
void set_inner_materials(TypedArray<Material> materials) { this->inner_materials = materials; }
|
||||
virtual MeshInstance3D *_rebuild_mesh_instance() override;
|
||||
|
||||
private:
|
||||
void _rebuild_mesh_instances();
|
||||
void _next_hurtbox_in_queue();
|
||||
|
||||
virtual void _slice_complete(Ref<MeshEditSliceOutput> data) override;
|
||||
|
||||
TypedArray<ArrayMesh> meshes;
|
||||
CharacterSkeleton3D *character_skeleton = nullptr;
|
||||
|
||||
std::unordered_set<CharacterSkeleton3D*> skeleton_set;
|
||||
|
||||
AABB _full_aabb;
|
||||
TypedArray<Material> inner_materials;
|
||||
|
||||
std::unordered_set<CharacterSkeleton3D*> _skeleton_set;
|
||||
std::vector<HurtboxDamage> _hurtbox_queue;
|
||||
|
||||
// Godot boilerplate below
|
||||
@@ -71,8 +59,6 @@ protected:
|
||||
|
||||
ADD_SIGNAL(MethodInfo("fell_out_of_world"));
|
||||
|
||||
ADD_GETTER_SETTER_HINTED(Character3D, meshes, Variant::ARRAY, PROPERTY_HINT_ARRAY_TYPE, "ArrayMesh");
|
||||
ADD_GETTER_SETTER_HINTED(Character3D, character_skeleton, Variant::OBJECT, PROPERTY_HINT_NODE_TYPE, "CharacterSkeleton3D");
|
||||
ADD_GETTER_SETTER_HINTED(Character3D, inner_materials, Variant::ARRAY, PROPERTY_HINT_ARRAY_TYPE, "Material");
|
||||
}
|
||||
};
|
||||
+9
-20
@@ -16,34 +16,23 @@
|
||||
using namespace godot;
|
||||
|
||||
|
||||
TypedArray<MeshInstance3D> CharacterSkeleton3D::set_meshes(TypedArray<ArrayMesh> meshes)
|
||||
void CharacterSkeleton3D::set_mesh(MeshInstance3D *mesh)
|
||||
{
|
||||
if (this->skeleton)
|
||||
{
|
||||
this->_old_mesh_instances = this->_mesh_instances.duplicate(true);
|
||||
this->_mesh_instances.clear();
|
||||
this->_old_mesh_instance = this->_mesh_instance;
|
||||
|
||||
uint16_t num_new_meshes = meshes.size();
|
||||
this->_mesh_instances.resize(num_new_meshes);
|
||||
for (uint16_t i = 0; i < num_new_meshes; i++)
|
||||
{
|
||||
MeshInstance3D *mesh_instance = memnew(MeshInstance3D);
|
||||
mesh_instance->set_mesh(meshes[i]);
|
||||
mesh_instance->set_skeleton_path(this->skeleton->get_path());
|
||||
this->skeleton->add_child(mesh_instance, false, Node::INTERNAL_MODE_BACK);
|
||||
this->_mesh_instances[i] = mesh_instance;
|
||||
}
|
||||
this->_mesh_instance = mesh;
|
||||
_mesh_instance->set_skeleton_path(this->skeleton->get_path());
|
||||
this->skeleton->add_child(this->_mesh_instance, false, Node::INTERNAL_MODE_BACK);
|
||||
|
||||
CALL_NEXT_FRAME(callable_mp(this, &CharacterSkeleton3D::_delete_old_meshes));
|
||||
CALL_NEXT_FRAME(callable_mp(this, &CharacterSkeleton3D::_delete_old_mesh));
|
||||
}
|
||||
|
||||
return this->_mesh_instances;
|
||||
}
|
||||
void CharacterSkeleton3D::_delete_old_meshes()
|
||||
void CharacterSkeleton3D::_delete_old_mesh()
|
||||
{
|
||||
for (uint16_t i = 0; i < this->_old_mesh_instances.size(); i++)
|
||||
cast_to<MeshInstance3D>(this->_old_mesh_instances[i])->queue_free();
|
||||
this->_old_mesh_instances.clear();
|
||||
if (this->_old_mesh_instance)
|
||||
this->_old_mesh_instance->queue_free();
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -26,15 +26,14 @@ class CharacterSkeleton3D : public Node3D
|
||||
GDCLASS(CharacterSkeleton3D, Node3D);
|
||||
|
||||
public:
|
||||
TypedArray<MeshInstance3D> set_meshes(TypedArray<ArrayMesh> meshes);
|
||||
void set_mesh(MeshInstance3D *mesh);
|
||||
|
||||
Skeleton3D *get_skeleton() const { return this->skeleton; }
|
||||
PhysicalBoneSimulator3D *get_physical_bone_simulator() const { return this->physical_bone_simulator; }
|
||||
AnimationPlayer *get_animation_player() const { return this->animation_player; }
|
||||
AnimationTree *get_animation_tree() const { return this->animation_tree; }
|
||||
|
||||
void replace_mesh_instance(const uint16_t index, Ref<ArrayMesh> new_mesh) { cast_to<MeshInstance3D>(this->_mesh_instances[index])->set_mesh(new_mesh); }
|
||||
TypedArray<MeshInstance3D> get_mesh_instances() const { return this->_mesh_instances; }
|
||||
MeshInstance3D *get_mesh_instance() const { return this->_mesh_instance; }
|
||||
|
||||
protected:
|
||||
void set_skeleton(Skeleton3D *s) { this->skeleton = s; }
|
||||
@@ -44,7 +43,7 @@ protected:
|
||||
|
||||
private:
|
||||
// void _refresh_skins_and_meshes();
|
||||
void _delete_old_meshes();
|
||||
void _delete_old_mesh();
|
||||
|
||||
void _activate_ragdoll();
|
||||
|
||||
@@ -53,8 +52,8 @@ private:
|
||||
AnimationPlayer *animation_player = nullptr;
|
||||
AnimationTree *animation_tree = nullptr;
|
||||
|
||||
TypedArray<MeshInstance3D> _mesh_instances;
|
||||
TypedArray<MeshInstance3D> _old_mesh_instances;
|
||||
MeshInstance3D *_mesh_instance = nullptr;
|
||||
MeshInstance3D *_old_mesh_instance = nullptr;
|
||||
|
||||
// Godot boilerplate below
|
||||
protected:
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* ©2026 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||
*
|
||||
* If this source code makes it to the public internet, this software can be
|
||||
* considered to be protected by the MIT licence. Have fun with it.
|
||||
*/
|
||||
|
||||
#include "damageable_node3d.h"
|
||||
|
||||
#include "orng_macros.h"
|
||||
|
||||
#include "godot_cpp/classes/scene_tree.hpp"
|
||||
#include "godot_cpp/classes/scene_tree_timer.hpp"
|
||||
|
||||
|
||||
void DamageableNode3D::_ready()
|
||||
{
|
||||
this->_rebuild_mesh_instance();
|
||||
}
|
||||
|
||||
void DamageableNode3D::set_mesh(Ref<ArrayMesh> m)
|
||||
{
|
||||
this->mesh = m;
|
||||
this->_aabb = AABB();
|
||||
this->_rebuild_mesh_instance();
|
||||
}
|
||||
|
||||
|
||||
void DamageableNode3D::_slice_meshes(Ref<MeshEditSliceInput> data)
|
||||
{
|
||||
this->_is_slicing = true;
|
||||
if (this->_validate_input(data))
|
||||
{
|
||||
this->_input_queue.emplace_back(data);
|
||||
if (this->_slice_state_queue.empty())
|
||||
this->_new_slice_loop();
|
||||
}
|
||||
}
|
||||
|
||||
void DamageableNode3D::_new_slice_loop()
|
||||
{
|
||||
Ref<MeshEditSliceInput> next_in_queue = this->_input_queue.front();
|
||||
Ref<MeshEditSliceState> new_state = MeshEditingLibrary::slice_mesh(next_in_queue);
|
||||
this->_slice_state_queue.emplace_back(new_state);
|
||||
this->_slice_loop();
|
||||
}
|
||||
|
||||
void DamageableNode3D::_slice_loop()
|
||||
{
|
||||
Ref<MeshEditSliceState> current_state = this->_slice_state_queue.front();
|
||||
switch(current_state->current_stage)
|
||||
{
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_INIT:
|
||||
if (MeshEditingLibrary::slice_mesh_init(current_state) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
||||
break;
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_PLANE_SPLIT:
|
||||
if (MeshEditingLibrary::slice_mesh_plane_split(current_state) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
||||
break;
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_EDGE_SPLIT:
|
||||
if (MeshEditingLibrary::slice_mesh_edge_split(current_state) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
||||
break;
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_APPLY_CAP:
|
||||
if (MeshEditingLibrary::slice_mesh_apply_cap(current_state) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
||||
break;
|
||||
case MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_COMPLETE:
|
||||
if (this->_slice_loop_end(current_state))
|
||||
return this->_new_slice_loop();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this->_input_queue.empty())
|
||||
CALL_NEXT_FRAME(callable_mp(this, &DamageableNode3D::_slice_loop));
|
||||
else
|
||||
this->_is_slicing = false;
|
||||
}
|
||||
|
||||
bool DamageableNode3D::_slice_loop_end(Ref<MeshEditSliceState> current_state)
|
||||
{
|
||||
this->_slice_complete(current_state->output);
|
||||
this->_input_queue.erase(this->_input_queue.begin());
|
||||
this->_slice_state_queue.erase(this->_slice_state_queue.begin());
|
||||
if (!this->_input_queue.empty())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool DamageableNode3D::_validate_input(Ref<MeshEditSliceInput> input)
|
||||
{
|
||||
if (this->_input_queue.size() >= MAX_SLICE_QUEUE_SIZE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Ref<MeshEditSliceInput> &queued_input : this->_input_queue)
|
||||
{
|
||||
if (queued_input->skeleton == input->skeleton)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
MeshInstance3D *DamageableNode3D::_rebuild_mesh_instance()
|
||||
{
|
||||
if (!this->is_node_ready())
|
||||
return nullptr;
|
||||
|
||||
this->_active_mesh_instance = memnew(MeshInstance3D);
|
||||
this->_active_mesh_instance->set_mesh(this->mesh);
|
||||
this->_aabb = this->_active_mesh_instance->get_aabb();
|
||||
|
||||
return this->_active_mesh_instance;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* ©2026 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||
*
|
||||
* If this source code makes it to the public internet, this software can be
|
||||
* considered to be protected by the MIT licence. Have fun with it.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "orng_macros.h"
|
||||
#include "singletons/mesh_editing_library.h"
|
||||
|
||||
#include "godot_cpp/classes/node.hpp"
|
||||
using namespace godot;
|
||||
|
||||
#define MAX_SLICE_QUEUE_SIZE 3
|
||||
|
||||
#define DAMAGEABLE_NODE3D_TAG "DamageableNode3D"
|
||||
|
||||
|
||||
class DamageableNode3D : public Node3D
|
||||
{
|
||||
GDCLASS(DamageableNode3D, Node3D);
|
||||
|
||||
public:
|
||||
virtual void _ready() override;
|
||||
|
||||
Ref<ArrayMesh> get_mesh() const { return this->mesh; }
|
||||
TypedArray<Material> get_inner_materials() const { return this->inner_materials; }
|
||||
|
||||
virtual void take_damage(const struct HurtboxDamage &hit_data) = 0;
|
||||
|
||||
protected:
|
||||
void set_mesh(Ref<ArrayMesh> m);
|
||||
void set_inner_materials(TypedArray<Material> materials) { this->inner_materials = materials; }
|
||||
|
||||
virtual MeshInstance3D *_rebuild_mesh_instance();
|
||||
|
||||
void _slice_meshes(Ref<MeshEditSliceInput> data);
|
||||
virtual void _slice_complete(Ref<MeshEditSliceOutput> data) = 0;
|
||||
|
||||
Ref<ArrayMesh> mesh;
|
||||
TypedArray<Material> inner_materials;
|
||||
|
||||
AABB _aabb;
|
||||
|
||||
private:
|
||||
void _new_slice_loop();
|
||||
void _slice_loop();
|
||||
bool _slice_loop_end(Ref<MeshEditSliceState> current_state);
|
||||
|
||||
bool _validate_input(Ref<MeshEditSliceInput> input);
|
||||
|
||||
MeshInstance3D *_active_mesh_instance = nullptr;
|
||||
|
||||
bool _is_slicing = false;
|
||||
std::vector<Ref<MeshEditSliceState>> _slice_state_queue;
|
||||
std::vector<Ref<MeshEditSliceInput>> _input_queue;
|
||||
|
||||
// Godot boilerplate below
|
||||
protected:
|
||||
static void _bind_methods()
|
||||
{
|
||||
ADD_GETTER_SETTER_HINTED(DamageableNode3D, mesh, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "ArrayMesh");
|
||||
ADD_GETTER_SETTER_HINTED(DamageableNode3D, inner_materials, Variant::ARRAY, PROPERTY_HINT_ARRAY_TYPE, "Material");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* ©2026 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||
*
|
||||
* If this source code makes it to the public internet, this software can be
|
||||
* considered to be protected by the MIT licence. Have fun with it.
|
||||
*/
|
||||
|
||||
#include "sliceable_rigid_body3d.h"
|
||||
|
||||
#include "orng_macros.h"
|
||||
|
||||
#include <godot_cpp/classes/scene_tree.hpp>
|
||||
#include <godot_cpp/classes/scene_tree_timer.hpp>
|
||||
using namespace godot;
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* ©2026 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||
*
|
||||
* If this source code makes it to the public internet, this software can be
|
||||
* considered to be protected by the MIT licence. Have fun with it.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "orng_macros.h"
|
||||
|
||||
#include "nodes/damageables/damageable_node3d.h"
|
||||
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <godot_cpp/classes/material.hpp>
|
||||
#include <godot_cpp/classes/mesh_instance3d.hpp>
|
||||
using namespace godot;
|
||||
|
||||
#define SLICEABLE_RIGID_BODY3D_TAG "SliceableRigidBody3D"
|
||||
|
||||
|
||||
class SliceableRigidBody3D : public DamageableNode3D
|
||||
{
|
||||
GDCLASS(SliceableRigidBody3D, DamageableNode3D);
|
||||
|
||||
public:
|
||||
virtual void take_damage(const HurtboxDamage &hit_data) override {}
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
virtual void _slice_complete(Ref<MeshEditSliceOutput> data) override {}
|
||||
|
||||
// Godot boilerplate below
|
||||
protected:
|
||||
static void _bind_methods(){}
|
||||
};
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "hurtbox_base.h"
|
||||
#include "orng_macros.h"
|
||||
|
||||
#include "nodes/character_nodes/character_3d.h"
|
||||
#include "nodes/damageables/character_3d.h"
|
||||
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/physical_bone3d.hpp>
|
||||
@@ -60,7 +60,7 @@ void HurtboxBase::_physics_process(double delta)
|
||||
const TypedArray<Node3D> &bodies = this->get_overlapping_bodies();
|
||||
const uint32_t num_bodies = bodies.size();
|
||||
|
||||
std::unordered_set<IDamageable*> new_hit_bodies;
|
||||
std::unordered_set<DamageableNode3D*> new_hit_bodies;
|
||||
std::vector<CharacterSkeleton3D*> new_hit_skeletons;
|
||||
|
||||
for (uint32_t i = 0; i < num_bodies; i++)
|
||||
@@ -99,7 +99,7 @@ void HurtboxBase::_physics_process(double delta)
|
||||
}
|
||||
}
|
||||
|
||||
for (IDamageable *damageable : new_hit_bodies)
|
||||
for (DamageableNode3D *damageable : new_hit_bodies)
|
||||
this->hit_bodies.emplace_back(damageable);
|
||||
|
||||
if (this->remaining_life <= 0.0f)
|
||||
@@ -110,14 +110,14 @@ void HurtboxBase::_physics_process(double delta)
|
||||
|
||||
void HurtboxBase::_send_next_in_queue()
|
||||
{
|
||||
if (!this->hit_data_queue.empty())
|
||||
for (uint8_t i = 0; i < MAX_HITS_PER_QUEUE_LOOP && !this->hit_data_queue.empty(); i++)
|
||||
{
|
||||
IDamageable *closest_damageable = nullptr;
|
||||
DamageableNode3D *closest_damageable = nullptr;
|
||||
float shortest_distance_from_hurtbox = FLT_MAX;
|
||||
bool found_character_3d = false;
|
||||
for (const auto &[damageable, hit_data_list] : this->hit_data_queue)
|
||||
{
|
||||
if (const Character3D *node = (Character3D*)(damageable))
|
||||
if (const Character3D *node = cast_to<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)
|
||||
|
||||
@@ -9,14 +9,16 @@
|
||||
|
||||
#include "orng_macros.h"
|
||||
|
||||
#include "nodes/character_nodes/character_3d.h"
|
||||
#include "nodes/character_nodes/character_skeleton3d.h"
|
||||
#include "nodes/damageables/character_3d.h"
|
||||
#include "nodes/damageables/character_skeleton3d.h"
|
||||
|
||||
#include <godot_cpp/classes/collision_shape3d.hpp>
|
||||
#include <godot_cpp/classes/shape3d.hpp>
|
||||
#include <godot_cpp/classes/area3d.hpp>
|
||||
using namespace godot;
|
||||
|
||||
#define MAX_HITS_PER_QUEUE_LOOP 3
|
||||
|
||||
#define HURTBOX_BASE_TAG "HurtboxBase"
|
||||
|
||||
|
||||
@@ -48,7 +50,7 @@ public:
|
||||
int32_t get_hit_points() const { return this->hit_points; }
|
||||
|
||||
protected:
|
||||
std::map<class IDamageable*, std::vector<HurtboxDamage>> hit_data_queue;
|
||||
std::map<class DamageableNode3D*, std::vector<HurtboxDamage>> hit_data_queue;
|
||||
|
||||
private:
|
||||
Dictionary _create_hit_data_struct() const;
|
||||
@@ -61,7 +63,7 @@ private:
|
||||
float remaining_life = 0.0f;
|
||||
int32_t hit_points = 0;
|
||||
|
||||
std::vector<class IDamageable*> hit_bodies;
|
||||
std::vector<class DamageableNode3D*> hit_bodies;
|
||||
|
||||
|
||||
// Godot boilerplate below
|
||||
|
||||
@@ -21,17 +21,17 @@
|
||||
#include "nodes/player_spawn.h"
|
||||
#include "nodes/sublevel_loader.h"
|
||||
#include "nodes/sublevel_scene.h"
|
||||
#include "nodes/character_nodes/character_3d.h"
|
||||
#include "nodes/character_nodes/character_skeleton3d.h"
|
||||
#include "nodes/damageables/character_3d.h"
|
||||
#include "nodes/damageables/character_skeleton3d.h"
|
||||
#include "nodes/damageables/sliceable_rigid_body3d.h"
|
||||
|
||||
#include "nodes/hurtbox/hurtbox_base.h"
|
||||
|
||||
#include "resources/level_metadata_map.h"
|
||||
#include "resources/level_metadata_resource.h"
|
||||
|
||||
#include "nodes/mesh_editing_library.h"
|
||||
|
||||
#include "singletons/input_handler.h"
|
||||
#include "singletons/mesh_editing_library.h"
|
||||
#include "singletons/save_manager.h"
|
||||
#include "singletons/scene_loader.h"
|
||||
// #include "singletons/vendor_service/vendor_service.h"
|
||||
@@ -66,7 +66,10 @@ void initialize_orng_module(ModuleInitializationLevel p_level) {
|
||||
|
||||
ClassDB::register_class<MovementHandler>();
|
||||
|
||||
ClassDB::register_abstract_class<DamageableNode3D>();
|
||||
ClassDB::register_class<Character3D>();
|
||||
ClassDB::register_class<SliceableRigidBody3D>();
|
||||
|
||||
ClassDB::register_class<CharacterSkeleton3D>();
|
||||
ClassDB::register_class<GameClasses>();
|
||||
ClassDB::register_class<LevelScene>();
|
||||
@@ -80,7 +83,7 @@ void initialize_orng_module(ModuleInitializationLevel p_level) {
|
||||
ClassDB::register_class<MeshEditingLibrary>();
|
||||
ClassDB::register_class<MeshEditSliceInput>();
|
||||
ClassDB::register_class<MeshEditSliceOutput>();
|
||||
ClassDB::register_class<MeshSliceState>();
|
||||
ClassDB::register_class<MeshEditSliceState>();
|
||||
|
||||
GDSINGLETON_REGISTER_CLASS(InputHandler, _input_handler_singleton);
|
||||
GDSINGLETON_REGISTER_CLASS(SaveManager, _save_manager_singleton);
|
||||
|
||||
+64
-42
@@ -16,9 +16,9 @@
|
||||
using namespace godot;
|
||||
|
||||
|
||||
Ref<MeshSliceState> MeshEditingLibrary::slice_mesh(const Ref<MeshEditSliceInput> input)
|
||||
Ref<MeshEditSliceState> MeshEditingLibrary::slice_mesh(const Ref<MeshEditSliceInput> input)
|
||||
{
|
||||
Ref<MeshSliceState> fresh_state;
|
||||
Ref<MeshEditSliceState> fresh_state;
|
||||
fresh_state.instantiate();
|
||||
|
||||
fresh_state->input = input;
|
||||
@@ -31,18 +31,17 @@ Ref<MeshSliceState> MeshEditingLibrary::slice_mesh(const Ref<MeshEditSliceInput>
|
||||
return fresh_state;
|
||||
}
|
||||
|
||||
void MeshEditingLibrary::slice_mesh_init(Ref<MeshSliceState> state)
|
||||
float MeshEditingLibrary::slice_mesh_init(Ref<MeshEditSliceState> state)
|
||||
{
|
||||
const Time *time = Time::get_singleton();
|
||||
const float start_time = time->get_ticks_msec();
|
||||
|
||||
{ // Initialise the state here
|
||||
// const Time *time = Time::get_singleton();
|
||||
|
||||
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Started slicing mesh at ", time->get_ticks_msec(), "ms");
|
||||
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Started slicing mesh at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
state->original_mesh = state->input->mesh_instance->get_mesh();
|
||||
state->num_surfaces = state->original_mesh->get_surface_count();
|
||||
|
||||
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Got skinned vertices at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
state->surface_arrays_list.resize(state->num_surfaces);
|
||||
state->skinned_vertex_positions.resize(state->num_surfaces);
|
||||
state->skinned_vertex_transforms.resize(state->num_surfaces);
|
||||
@@ -90,7 +89,8 @@ void MeshEditingLibrary::slice_mesh_init(Ref<MeshSliceState> state)
|
||||
|
||||
for (state->surface; state->surface < state->num_surfaces; state->surface++)
|
||||
{
|
||||
state->skinned_vertex_positions[state->surface] = MeshEditingLibrary::get_skinned_vertex_positions(state->surface, state->original_mesh, state->input->skeleton, state->skinned_vertex_transforms[state->surface]);
|
||||
// if ((time->get_ticks_msec() - start_time) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
||||
// return time->get_ticks_msec() - start_time;
|
||||
|
||||
state->surface_arrays_list[state->surface] = state->original_mesh->surface_get_arrays(state->surface);
|
||||
const PackedVector3Array &surface_vertex_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_VERTEX];
|
||||
@@ -127,15 +127,24 @@ void MeshEditingLibrary::slice_mesh_init(Ref<MeshSliceState> state)
|
||||
state->num_custom0_per_vertex[state->surface] = surface_num_custom0_per_vertex;
|
||||
|
||||
state->vertex_distances[state->surface].resize(num_vertices);
|
||||
|
||||
state->skinned_vertex_positions[state->surface] = MeshEditingLibrary::get_skinned_vertex_positions(state->surface, state->original_mesh, state->input->skeleton, state->skinned_vertex_transforms[state->surface]);
|
||||
}
|
||||
|
||||
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Got skinned vertices at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
state->surface = 0;
|
||||
state->element = 0;
|
||||
state->current_stage = MeshEditSliceStage::SLICE_STAGE_PLANE_SPLIT;
|
||||
|
||||
return time->get_ticks_msec() - start_time;
|
||||
}
|
||||
|
||||
void MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshSliceState> state)
|
||||
float MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshEditSliceState> state)
|
||||
{
|
||||
const Time *time = Time::get_singleton();
|
||||
const float start_time = time->get_ticks_msec();
|
||||
|
||||
for (state->surface; state->surface < state->num_surfaces; state->surface++)
|
||||
{
|
||||
const PackedVector3Array &surface_vertex_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_VERTEX];
|
||||
@@ -170,6 +179,9 @@ void MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshSliceState> state)
|
||||
|
||||
for (state->element; state->element < num_vertices; state->element++)
|
||||
{
|
||||
if ((time->get_ticks_msec() - start_time) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
||||
return time->get_ticks_msec() - start_time;
|
||||
|
||||
vertex_distances[state->element] = state->input->local_plane.distance_to(state->skinned_vertex_positions[state->surface][state->element]);
|
||||
|
||||
if (vertex_distances[state->element] >= 0.0f)
|
||||
@@ -246,7 +258,7 @@ void MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshSliceState> state)
|
||||
}
|
||||
}
|
||||
|
||||
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", surface, " sorted by plane distance at ", time->get_ticks_msec(), "ms");
|
||||
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", state->surface, " sorted by plane distance at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
state->element = 0;
|
||||
}
|
||||
@@ -255,14 +267,17 @@ void MeshEditingLibrary::slice_mesh_plane_split(Ref<MeshSliceState> state)
|
||||
|
||||
state->surface = 0;
|
||||
state->current_stage = MeshEditSliceStage::SLICE_STAGE_EDGE_SPLIT;
|
||||
|
||||
return time->get_ticks_msec() - start_time;
|
||||
}
|
||||
|
||||
void MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
||||
float MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshEditSliceState> state)
|
||||
{
|
||||
const Time *time = Time::get_singleton();
|
||||
const float start_time = time->get_ticks_msec();
|
||||
|
||||
for (state->surface; state->surface < state->num_surfaces; state->surface++)
|
||||
{
|
||||
Ref<Material> original_material = state->original_mesh->surface_get_material(state->surface);
|
||||
|
||||
const PackedVector3Array &surface_vertex_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_VERTEX];
|
||||
const PackedVector3Array &surface_normal_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_NORMAL];
|
||||
const PackedFloat32Array &surface_tangent_array = state->surface_arrays_list[state->surface][ArrayMesh::ARRAY_TANGENT];
|
||||
@@ -307,6 +322,9 @@ void MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
||||
const uint32_t num_triangles = surface_index_array.size();
|
||||
for (state->element; state->element < num_triangles; state->element += 3)
|
||||
{
|
||||
if ((time->get_ticks_msec() - start_time) > MESH_EDITING_SLICE_LOOP_LIMIT)
|
||||
return time->get_ticks_msec() - start_time;
|
||||
|
||||
uint32_t base_v[3];
|
||||
std::map<uint32_t, uint32_t>::iterator sliced_v[3];
|
||||
std::map<uint32_t, uint32_t>::iterator sliced_other_v[3];
|
||||
@@ -541,9 +559,12 @@ void MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
if (state->input->skeleton)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -570,6 +591,8 @@ void MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
||||
state->element = 0;
|
||||
}
|
||||
|
||||
Ref<Material> original_material = state->original_mesh->surface_get_material(state->surface);
|
||||
|
||||
int64_t array_format_bit_mask = Mesh::ARRAY_FORMAT_VERTEX;
|
||||
if (has_normal) array_format_bit_mask |= Mesh::ARRAY_FORMAT_NORMAL;
|
||||
if (has_tangent) array_format_bit_mask |= Mesh::ARRAY_FORMAT_TANGENT;
|
||||
@@ -621,28 +644,29 @@ void MeshEditingLibrary::slice_mesh_edge_split(Ref<MeshSliceState> state)
|
||||
state->other_half->surface_set_material(next_surface, original_material);
|
||||
}
|
||||
|
||||
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", surface, " split edges at ", time->get_ticks_msec(), "ms");
|
||||
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Surface ", state->surface, " split edges at ", time->get_ticks_msec(), "ms");
|
||||
}
|
||||
|
||||
state->surface = 0;
|
||||
state->current_stage = MeshEditSliceStage::SLICE_STAGE_APPLY_CAP;
|
||||
|
||||
return time->get_ticks_msec() - start_time;
|
||||
}
|
||||
|
||||
void MeshEditingLibrary::slice_mesh_apply_cap(Ref<MeshSliceState> state)
|
||||
float MeshEditingLibrary::slice_mesh_apply_cap(Ref<MeshEditSliceState> state)
|
||||
{
|
||||
const Time *time = Time::get_singleton();
|
||||
const float start_time = time->get_ticks_msec();
|
||||
|
||||
if (state->clip_edges.size() > 0)
|
||||
{
|
||||
MeshSlicePlaneOrientation uv_plane = MeshSlicePlaneOrientation::Z;
|
||||
const Basis &mesh_instance_basis = state->input->mesh_instance->get_basis();
|
||||
const Vector3 &local_plane_normal = state->input->local_plane.get_normal();
|
||||
if (UtilityFunctions::absf(local_plane_normal.dot(mesh_instance_basis.xform(Vector3(0.0f, 1.0f, 0.0f)))) > 0.5f)
|
||||
{
|
||||
uv_plane = MeshSlicePlaneOrientation::Y;
|
||||
}
|
||||
else if (UtilityFunctions::absf(local_plane_normal.dot(mesh_instance_basis.xform(Vector3(1.0f, 0.0f, 0.0f)))) > 0.5f)
|
||||
{
|
||||
uv_plane = MeshSlicePlaneOrientation::X;
|
||||
}
|
||||
|
||||
SurfaceTool *surface_tool_first_half = memnew(SurfaceTool);
|
||||
SurfaceTool *surface_tool_other_half = memnew(SurfaceTool);
|
||||
@@ -677,8 +701,8 @@ void MeshEditingLibrary::slice_mesh_apply_cap(Ref<MeshSliceState> state)
|
||||
for (const MeshEditVert2D &vertex : polygon_set[state->element].vertices)
|
||||
{
|
||||
const Vector3 &position = state->first_half_vertices[vertex.surface][vertex.index];
|
||||
|
||||
const Transform3D &skinned_vertex_transform = state->skinned_vertex_transforms[vertex.surface][vertex.index];
|
||||
// const Vector3 &skinned_position = state->skinned_vertex_positions[vertex.surface][vertex.index];
|
||||
// const Transform3D &skinned_vertex_transform = state->skinned_vertex_transforms[vertex.surface][vertex.index];
|
||||
|
||||
const Vector2 &uv = MeshEditingLibrary::calculate_planar_uv(position, mesh_bounds, uv_plane);
|
||||
surface_tool_first_half->set_uv(uv);
|
||||
@@ -770,17 +794,17 @@ void MeshEditingLibrary::slice_mesh_apply_cap(Ref<MeshSliceState> state)
|
||||
|
||||
memdelete(surface_tool_first_half);
|
||||
memdelete(surface_tool_other_half);
|
||||
|
||||
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Created cap surfaces at ", time->get_ticks_msec(), "ms");
|
||||
}
|
||||
|
||||
// PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Generated final cap surface at ", time->get_ticks_msec(), "ms");
|
||||
PRINT_LOG(MESH_EDITING_LIBRARY_TAG, "Generated final cap surface at ", time->get_ticks_msec(), "ms");
|
||||
|
||||
state->output->original_skeleton = state->input->skeleton;
|
||||
state->output->main_half = state->first_half;
|
||||
state->output->secondary_half = state->other_half;
|
||||
|
||||
state->current_stage = MeshEditSliceStage::SLICE_STAGE_COMPLETE;
|
||||
|
||||
return time->get_ticks_msec() - start_time;
|
||||
}
|
||||
|
||||
|
||||
@@ -790,6 +814,7 @@ SkinnedVertices MeshEditingLibrary::get_skinned_vertex_positions(const uint8_t s
|
||||
if (surface > 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!");
|
||||
return SkinnedVertices();
|
||||
}
|
||||
|
||||
SkinnedVertices skinned_vertex_array;
|
||||
@@ -797,7 +822,7 @@ SkinnedVertices MeshEditingLibrary::get_skinned_vertex_positions(const uint8_t s
|
||||
if (skeleton)
|
||||
{
|
||||
const uint16_t bone_count = skeleton->get_bone_count();
|
||||
std::vector<Transform3D> bone_transforms;
|
||||
SkinnedVertexTransforms bone_transforms;
|
||||
bone_transforms.resize(bone_count);
|
||||
for (uint8_t bone_index = 0; bone_index < bone_count; bone_index++)
|
||||
{
|
||||
@@ -851,20 +876,17 @@ SkinnedVertices MeshEditingLibrary::get_skinned_vertex_positions(const uint8_t s
|
||||
}
|
||||
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++)
|
||||
{
|
||||
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_array[vertex_index] = mesh_vertex_array[vertex_index];
|
||||
}
|
||||
|
||||
return skinned_vertex_array;
|
||||
+12
-9
@@ -18,10 +18,13 @@ using namespace godot;
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#define MESH_EDITING_SLICE_LOOP_LIMIT 5.555555555555555f
|
||||
|
||||
#define MESH_EDITING_LIBRARY_TAG "MeshEditingLibrary"
|
||||
|
||||
typedef PackedVector3Array SkinnedVertices;
|
||||
typedef std::vector<SkinnedVertices> SkinnedSurfaces;
|
||||
typedef std::vector<Transform3D> SkinnedVertexTransforms;
|
||||
|
||||
|
||||
struct MeshEditVert3D
|
||||
@@ -58,7 +61,7 @@ struct MeshEditPolygon2D
|
||||
|
||||
class MeshEditSliceInput;
|
||||
class MeshEditSliceOutput;
|
||||
class MeshSliceState;
|
||||
class MeshEditSliceState;
|
||||
|
||||
|
||||
class MeshEditingLibrary : public Node
|
||||
@@ -85,12 +88,12 @@ public:
|
||||
CAP_UV_TILED
|
||||
};
|
||||
|
||||
static Ref<class MeshSliceState> slice_mesh(const Ref<class MeshEditSliceInput> input);
|
||||
static Ref<class MeshEditSliceState> slice_mesh(const Ref<class MeshEditSliceInput> input);
|
||||
|
||||
static void slice_mesh_init(Ref<class MeshSliceState> state);
|
||||
static void slice_mesh_plane_split(Ref<class MeshSliceState> state);
|
||||
static void slice_mesh_edge_split(Ref<class MeshSliceState> state);
|
||||
static void slice_mesh_apply_cap(Ref<class MeshSliceState> state);
|
||||
static float slice_mesh_init(Ref<class MeshEditSliceState> state);
|
||||
static float slice_mesh_plane_split(Ref<class MeshEditSliceState> state);
|
||||
static float slice_mesh_edge_split(Ref<class MeshEditSliceState> state);
|
||||
static float slice_mesh_apply_cap(Ref<class MeshEditSliceState> state);
|
||||
|
||||
protected:
|
||||
enum MeshSlicePlaneOrientation
|
||||
@@ -172,9 +175,9 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class MeshSliceState : public RefCounted
|
||||
class MeshEditSliceState : public RefCounted
|
||||
{
|
||||
GDCLASS(MeshSliceState, RefCounted);
|
||||
GDCLASS(MeshEditSliceState, RefCounted);
|
||||
|
||||
public:
|
||||
MeshEditingLibrary::MeshEditSliceStage current_stage = MeshEditingLibrary::MeshEditSliceStage::SLICE_STAGE_INIT;
|
||||
@@ -193,7 +196,7 @@ public:
|
||||
|
||||
std::vector<Array> surface_arrays_list;
|
||||
std::vector<SkinnedVertices> skinned_vertex_positions;
|
||||
std::vector<std::vector<Transform3D>> skinned_vertex_transforms;
|
||||
std::vector<SkinnedVertexTransforms> skinned_vertex_transforms;
|
||||
|
||||
std::vector<bool> has_normal;
|
||||
std::vector<bool> has_tangent;
|
||||
Reference in New Issue
Block a user