Moved Skeleton and it's related classes to a module.

This commit is contained in:
Relintai 2022-08-28 15:46:12 +02:00
parent 546929e85b
commit dc28777321
101 changed files with 2195 additions and 1870 deletions

View File

@ -128,7 +128,6 @@
#include "editor/plugins/navigation_polygon_editor_plugin.h"
#include "editor/plugins/path_2d_editor_plugin.h"
#include "editor/plugins/path_editor_plugin.h"
#include "editor/plugins/physical_bone_plugin.h"
#include "editor/plugins/polygon_2d_editor_plugin.h"
#include "editor/plugins/ray_cast_2d_editor_plugin.h"
#include "editor/plugins/resource_preloader_editor_plugin.h"
@ -137,7 +136,6 @@
#include "editor/plugins/script_editor_plugin.h"
#include "editor/plugins/script_text_editor.h"
#include "editor/plugins/shader_editor_plugin.h"
#include "editor/plugins/skeleton_ik_editor_plugin.h"
#include "editor/plugins/spatial_editor_plugin.h"
#include "editor/plugins/sprite_editor_plugin.h"
#include "editor/plugins/sprite_frames_editor_plugin.h"
@ -6823,8 +6821,6 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(TextureEditorPlugin(this)));
add_editor_plugin(memnew(AudioStreamEditorPlugin(this)));
add_editor_plugin(memnew(AudioBusesEditorPlugin(audio_bus_editor)));
add_editor_plugin(memnew(SkeletonIKEditorPlugin(this)));
add_editor_plugin(memnew(PhysicalBonePlugin(this)));
add_editor_plugin(memnew(MeshEditorPlugin(this)));
add_editor_plugin(memnew(MaterialEditorPlugin(this)));
add_editor_plugin(memnew(ViewportPreviewEditorPlugin(this)));

View File

@ -30,25 +30,24 @@
#include "animation_blend_tree_editor_plugin.h"
#include "core/variant/array.h"
#include "core/object/class_db.h"
#include "core/math/color.h"
#include "core/error/error_macros.h"
#include "core/containers/hash_map.h"
#include "core/io/resource_loader.h"
#include "core/containers/list.h"
#include "core/string/node_path.h"
#include "core/os/memory.h"
#include "core/containers/set.h"
#include "core/typedefs.h"
#include "core/error/error_macros.h"
#include "core/io/resource_loader.h"
#include "core/math/color.h"
#include "core/object/class_db.h"
#include "core/object/undo_redo.h"
#include "core/os/memory.h"
#include "core/string/node_path.h"
#include "core/typedefs.h"
#include "core/variant/array.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_inspector.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/2d/canvas_item.h"
#include "scene/3d/skeleton.h"
#include "scene/animation/animation_blend_tree.h"
#include "scene/animation/animation_player.h"
#include "scene/gui/box_container.h"
@ -70,6 +69,12 @@
#include "scene/resources/animation.h"
#include "scene/resources/style_box.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/nodes/skeleton.h"
#endif
void AnimationNodeBlendTreeEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script) {
for (int i = 0; i < add_options.size(); i++) {
ERR_FAIL_COND(add_options[i].script == p_script);
@ -662,6 +667,7 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano
}
if (path.get_subname_count()) {
#ifdef MODULE_SKELETON_3D_ENABLED
String concat = path.get_concatenated_subnames();
Skeleton *skeleton = Object::cast_to<Skeleton>(node);
@ -701,7 +707,7 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano
ti->set_checked(0, anode->is_path_filtered(path));
ti->set_icon(0, get_theme_icon("BoneAttachment", "EditorIcons"));
ti->set_metadata(0, path);
#endif
} else {
//just a property
ti = filters->create_item(ti);

View File

@ -30,18 +30,16 @@
#include "root_motion_editor_plugin.h"
#include "editor/editor_node.h"
#include "scene/3d/skeleton.h"
#include "scene/main/viewport.h"
#include "core/object/class_db.h"
#include "core/error/error_macros.h"
#include "core/containers/list.h"
#include "core/containers/map.h"
#include "core/os/memory.h"
#include "core/object/reference.h"
#include "core/containers/set.h"
#include "core/error/error_macros.h"
#include "core/object/class_db.h"
#include "core/object/reference.h"
#include "core/os/memory.h"
#include "core/string/string_name.h"
#include "core/typedefs.h"
#include "editor/editor_node.h"
#include "scene/animation/animation_player.h"
#include "scene/animation/animation_tree.h"
#include "scene/gui/box_container.h"
@ -51,9 +49,16 @@
#include "scene/gui/tree.h"
#include "scene/main/node.h"
#include "scene/main/scene_tree.h"
#include "scene/main/viewport.h"
#include "scene/resources/animation.h"
#include "scene/resources/texture.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/nodes/skeleton.h"
#endif
void EditorPropertyRootMotion::_confirmed() {
TreeItem *ti = filters->get_selected();
if (!ti) {
@ -145,6 +150,7 @@ void EditorPropertyRootMotion::_node_assign() {
}
if (path.get_subname_count()) {
#ifdef MODULE_SKELETON_3D_ENABLED
String concat = path.get_concatenated_subnames();
Skeleton *skeleton = Object::cast_to<Skeleton>(node);
@ -196,6 +202,7 @@ void EditorPropertyRootMotion::_node_assign() {
ti->select(0);
}
}
#endif
} else {
if (ti) {
//just a node, likely call or animation track

View File

@ -6987,7 +6987,6 @@ void SpatialEditor::_register_all_gizmos() {
add_gizmo_plugin(Ref<CollisionPolygonSpatialGizmoPlugin>(memnew(CollisionPolygonSpatialGizmoPlugin)));
add_gizmo_plugin(Ref<NavigationMeshSpatialGizmoPlugin>(memnew(NavigationMeshSpatialGizmoPlugin)));
add_gizmo_plugin(Ref<JointSpatialGizmoPlugin>(memnew(JointSpatialGizmoPlugin)));
add_gizmo_plugin(Ref<PhysicalBoneSpatialGizmoPlugin>(memnew(PhysicalBoneSpatialGizmoPlugin)));
}
void SpatialEditor::_bind_methods() {

View File

@ -36,7 +36,6 @@
#include "scene/gui/container.h"
#include "scene/gui/control.h"
#include "scene/3d/skeleton.h"
#include "scene/gui/spin_box.h"
#include "core/containers/hash_map.h"

View File

@ -74,7 +74,6 @@
#include "scene/3d/reflection_probe.h"
#include "scene/3d/room.h"
#include "scene/3d/shape_cast.h"
#include "scene/3d/skeleton.h"
#include "scene/3d/soft_body.h"
#include "scene/3d/spatial.h"
#include "scene/3d/spring_arm.h"
@ -100,12 +99,15 @@
#include "scene/resources/primitive_meshes.h"
#include "scene/resources/ray_shape.h"
#include "scene/resources/shape.h"
#include "scene/resources/skin.h"
#include "scene/resources/sphere_shape.h"
#include "scene/resources/surface_tool.h"
#include "scene/resources/world.h"
#include "servers/rendering_server.h"
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/nodes/skeleton.h"
#endif
#define HANDLE_HALF_SIZE 9.5
bool EditorSpatialGizmo::is_editable() const {
@ -278,25 +280,36 @@ void EditorSpatialGizmo::Instance::create_instance(Spatial *p_base, bool p_hidde
instance = RS::get_singleton()->instance_create2(mesh->get_rid(), p_base->get_world()->get_scenario());
RS::get_singleton()->instance_set_portal_mode(instance, RenderingServer::INSTANCE_PORTAL_MODE_GLOBAL);
RS::get_singleton()->instance_attach_object_instance_id(instance, p_base->get_instance_id());
#ifdef MODULE_SKELETON_3D_ENABLED
if (skin_reference.is_valid()) {
RS::get_singleton()->instance_attach_skeleton(instance, skin_reference->get_skeleton());
}
#endif
if (extra_margin) {
RS::get_singleton()->instance_set_extra_visibility_margin(instance, 1);
}
RS::get_singleton()->instance_geometry_set_cast_shadows_setting(instance, RS::SHADOW_CASTING_SETTING_OFF);
int layer = p_hidden ? 0 : 1 << SpatialEditorViewport::GIZMO_EDIT_LAYER;
RS::get_singleton()->instance_set_layer_mask(instance, layer); //gizmos are 26
}
#ifdef MODULE_SKELETON_3D_ENABLED
void EditorSpatialGizmo::add_mesh(const Ref<Mesh> &p_mesh, const Ref<Material> &p_material, const Transform &p_xform, const Ref<SkinReference> &p_skin_reference) {
#else
void EditorSpatialGizmo::add_mesh(const Ref<Mesh> &p_mesh, const Ref<Material> &p_material, const Transform &p_xform) {
#endif
ERR_FAIL_COND(!spatial_node);
ERR_FAIL_COND_MSG(!p_mesh.is_valid(), "EditorSpatialGizmo.add_mesh() requires a valid Mesh resource.");
Instance ins;
ins.mesh = p_mesh;
#ifdef MODULE_SKELETON_3D_ENABLED
ins.skin_reference = p_skin_reference;
#endif
ins.material = p_material;
ins.xform = p_xform;
@ -2181,139 +2194,6 @@ void Position3DSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
p_gizmo->add_collision_segments(cursor_points);
}
////
PhysicalBoneSpatialGizmoPlugin::PhysicalBoneSpatialGizmoPlugin() {
create_material("joint_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1)));
}
bool PhysicalBoneSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
return Object::cast_to<PhysicalBone>(p_spatial) != nullptr;
}
String PhysicalBoneSpatialGizmoPlugin::get_gizmo_name() const {
return "PhysicalBones";
}
int PhysicalBoneSpatialGizmoPlugin::get_priority() const {
return -1;
}
void PhysicalBoneSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
p_gizmo->clear();
PhysicalBone *physical_bone = Object::cast_to<PhysicalBone>(p_gizmo->get_spatial_node());
if (!physical_bone) {
return;
}
Skeleton *sk(physical_bone->find_skeleton_parent());
if (!sk) {
return;
}
PhysicalBone *pb(sk->get_physical_bone(physical_bone->get_bone_id()));
if (!pb) {
return;
}
PhysicalBone *pbp(sk->get_physical_bone_parent(physical_bone->get_bone_id()));
if (!pbp) {
return;
}
Vector<Vector3> points;
switch (physical_bone->get_joint_type()) {
case PhysicalBone::JOINT_TYPE_PIN: {
JointSpatialGizmoPlugin::CreatePinJointGizmo(physical_bone->get_joint_offset(), points);
} break;
case PhysicalBone::JOINT_TYPE_CONE: {
const PhysicalBone::ConeJointData *cjd(static_cast<const PhysicalBone::ConeJointData *>(physical_bone->get_joint_data()));
JointSpatialGizmoPlugin::CreateConeTwistJointGizmo(
physical_bone->get_joint_offset(),
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
pb->get_global_transform(),
pbp->get_global_transform(),
cjd->swing_span,
cjd->twist_span,
&points,
&points);
} break;
case PhysicalBone::JOINT_TYPE_HINGE: {
const PhysicalBone::HingeJointData *hjd(static_cast<const PhysicalBone::HingeJointData *>(physical_bone->get_joint_data()));
JointSpatialGizmoPlugin::CreateHingeJointGizmo(
physical_bone->get_joint_offset(),
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
pb->get_global_transform(),
pbp->get_global_transform(),
hjd->angular_limit_lower,
hjd->angular_limit_upper,
hjd->angular_limit_enabled,
points,
&points,
&points);
} break;
case PhysicalBone::JOINT_TYPE_SLIDER: {
const PhysicalBone::SliderJointData *sjd(static_cast<const PhysicalBone::SliderJointData *>(physical_bone->get_joint_data()));
JointSpatialGizmoPlugin::CreateSliderJointGizmo(
physical_bone->get_joint_offset(),
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
pb->get_global_transform(),
pbp->get_global_transform(),
sjd->angular_limit_lower,
sjd->angular_limit_upper,
sjd->linear_limit_lower,
sjd->linear_limit_upper,
points,
&points,
&points);
} break;
case PhysicalBone::JOINT_TYPE_6DOF: {
const PhysicalBone::SixDOFJointData *sdofjd(static_cast<const PhysicalBone::SixDOFJointData *>(physical_bone->get_joint_data()));
JointSpatialGizmoPlugin::CreateGeneric6DOFJointGizmo(
physical_bone->get_joint_offset(),
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
pb->get_global_transform(),
pbp->get_global_transform(),
sdofjd->axis_data[0].angular_limit_lower,
sdofjd->axis_data[0].angular_limit_upper,
sdofjd->axis_data[0].linear_limit_lower,
sdofjd->axis_data[0].linear_limit_upper,
sdofjd->axis_data[0].angular_limit_enabled,
sdofjd->axis_data[0].linear_limit_enabled,
sdofjd->axis_data[1].angular_limit_lower,
sdofjd->axis_data[1].angular_limit_upper,
sdofjd->axis_data[1].linear_limit_lower,
sdofjd->axis_data[1].linear_limit_upper,
sdofjd->axis_data[1].angular_limit_enabled,
sdofjd->axis_data[1].linear_limit_enabled,
sdofjd->axis_data[2].angular_limit_lower,
sdofjd->axis_data[2].angular_limit_upper,
sdofjd->axis_data[2].linear_limit_lower,
sdofjd->axis_data[2].linear_limit_upper,
sdofjd->axis_data[2].angular_limit_enabled,
sdofjd->axis_data[2].linear_limit_enabled,
points,
&points,
&points);
} break;
default:
return;
}
Ref<Material> material = get_material("joint_material", p_gizmo);
p_gizmo->add_collision_segments(points);
p_gizmo->add_lines(points, material);
}
/////
RayCastSpatialGizmoPlugin::RayCastSpatialGizmoPlugin() {

View File

@ -47,11 +47,16 @@
#include "scene/resources/mesh.h"
#include "modules/modules_enabled.gen.h"
class Camera;
class Spatial;
class Timer;
struct Transform;
class Timer;
#ifdef MODULE_SKELETON_3D_ENABLED
class SkinReference;
#endif
class EditorSpatialGizmo : public SpatialGizmo {
GDCLASS(EditorSpatialGizmo, SpatialGizmo);
@ -61,7 +66,9 @@ public:
RID instance;
Ref<Mesh> mesh;
Ref<Material> material;
#ifdef MODULE_SKELETON_3D_ENABLED
Ref<SkinReference> skin_reference;
#endif
bool extra_margin;
Transform xform;
@ -90,7 +97,9 @@ public:
Vector<Instance> instances;
Spatial *spatial_node;
void _set_spatial_node(Node *p_node) { set_spatial_node(Object::cast_to<Spatial>(p_node)); }
void _set_spatial_node(Node *p_node) {
set_spatial_node(Object::cast_to<Spatial>(p_node));
}
protected:
static void _bind_methods();
@ -100,7 +109,11 @@ protected:
public:
void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1));
void add_vertices(const Vector<Vector3> &p_vertices, const Ref<Material> &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1));
#ifdef MODULE_SKELETON_3D_ENABLED
void add_mesh(const Ref<Mesh> &p_mesh, const Ref<Material> &p_material = Ref<Material>(), const Transform &p_xform = Transform(), const Ref<SkinReference> &p_skin_reference = Ref<SkinReference>());
#else
void add_mesh(const Ref<Mesh> &p_mesh, const Ref<Material> &p_material = Ref<Material>(), const Transform &p_xform = Transform());
#endif
void add_collision_segments(const Vector<Vector3> &p_lines);
void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh);
void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1, const Color &p_modulate = Color(1, 1, 1));
@ -119,12 +132,20 @@ public:
virtual void set_subgizmo_transform(int p_id, Transform p_transform) const;
virtual void commit_subgizmos(const Vector<int> &p_ids, const Vector<Transform> &p_restore, bool p_cancel = false) const;
void set_selected(bool p_selected) { selected = p_selected; }
bool is_selected() const { return selected; }
void set_selected(bool p_selected) {
selected = p_selected;
}
bool is_selected() const {
return selected;
}
void set_spatial_node(Spatial *p_node);
Spatial *get_spatial_node() const { return spatial_node; }
Ref<EditorSpatialGizmoPlugin> get_plugin() const { return gizmo_plugin; }
Spatial *get_spatial_node() const {
return spatial_node;
}
Ref<EditorSpatialGizmoPlugin> get_plugin() const {
return gizmo_plugin;
}
bool intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum);
void handles_intersect_ray(Camera *p_camera, const Vector2 &p_point, bool p_shift_pressed, int &r_id, bool &r_secondary);
bool intersect_ray(Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal);
@ -316,18 +337,6 @@ public:
Position3DSpatialGizmoPlugin();
};
class PhysicalBoneSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(PhysicalBoneSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
bool has_gizmo(Spatial *p_spatial);
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
PhysicalBoneSpatialGizmoPlugin();
};
class RayCastSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(RayCastSpatialGizmoPlugin, EditorSpatialGizmoPlugin);

View File

@ -32,7 +32,6 @@
#include "editor_scene_importer_gltf.h"
#include "scene/resources/animation.h"
#include "scene/resources/skin.h"
#include "gltf_state.h"
#include "packed_scene_gltf.h"

View File

@ -30,6 +30,14 @@
#include "gltf_document.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/nodes/bone_attachment.h"
#include "modules/skeleton_3d/nodes/skeleton.h"
#include "modules/skeleton_3d/resources/skin.h"
#endif
#include "gltf_accessor.h"
#include "gltf_animation.h"
#include "gltf_camera.h"
@ -51,7 +59,7 @@
#include "core/version.h"
#include "drivers/png/png_driver_common.h"
#include "scene/2d/node_2d.h"
#include "scene/3d/bone_attachment.h"
#include "scene/3d/mesh_instance.h"
#include "scene/3d/multimesh_instance.h"
#include "scene/3d/spatial.h"
@ -59,7 +67,6 @@
#include "scene/main/node.h"
#include "scene/resources/animation.h"
#include "scene/resources/multimesh.h"
#include "scene/resources/skin.h"
#include "scene/resources/surface_tool.h"
#include "modules/modules_enabled.gen.h" // For csg, gridmap, regex.
@ -4308,6 +4315,7 @@ Error GLTFDocument::_determine_skeleton_roots(Ref<GLTFState> state, const GLTFSk
return OK;
}
#ifdef MODULE_SKELETON_3D_ENABLED
Error GLTFDocument::_create_skeletons(Ref<GLTFState> state) {
for (GLTFSkeletonIndex skel_i = 0; skel_i < state->skeletons.size(); ++skel_i) {
Ref<GLTFSkeleton> gltf_skeleton = state->skeletons.write[skel_i];
@ -4380,6 +4388,7 @@ Error GLTFDocument::_create_skeletons(Ref<GLTFState> state) {
return OK;
}
#endif
Error GLTFDocument::_map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFState> state) {
for (GLTFSkinIndex skin_i = 0; skin_i < state->skins.size(); ++skin_i) {
@ -5058,6 +5067,7 @@ void GLTFDocument::_assign_scene_names(Ref<GLTFState> state) {
state->scene_name = _gen_unique_name(state, state->scene_name);
}
#ifdef MODULE_SKELETON_3D_ENABLED
BoneAttachment *GLTFDocument::_generate_bone_attachment(Ref<GLTFState> state, Skeleton *skeleton, const GLTFNodeIndex node_index, const GLTFNodeIndex bone_index) {
Ref<GLTFNode> gltf_node = state->nodes[node_index];
Ref<GLTFNode> bone_node = state->nodes[bone_index];
@ -5071,6 +5081,7 @@ BoneAttachment *GLTFDocument::_generate_bone_attachment(Ref<GLTFState> state, Sk
return bone_attachment;
}
#endif
GLTFMeshIndex GLTFDocument::_convert_mesh_to_gltf(Ref<GLTFState> state, MeshInstance *p_mesh_instance) {
ERR_FAIL_NULL_V(p_mesh_instance, -1);
@ -5309,11 +5320,13 @@ void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, co
BoneAttachment *bone = cast_to<BoneAttachment>(p_current);
_convert_bone_attachment_to_gltf(bone, state, p_gltf_parent, p_gltf_root, gltf_node);
return;
#ifdef MODULE_SKELETON_3D_ENABLED
} else if (cast_to<Skeleton>(p_current)) {
Skeleton *skel = cast_to<Skeleton>(p_current);
_convert_skeleton_to_gltf(skel, state, p_gltf_parent, p_gltf_root, gltf_node);
// We ignore the Pandemonium Engine node that is the skeleton.
return;
#endif
} else if (cast_to<MultiMeshInstance>(p_current)) {
MultiMeshInstance *multi = cast_to<MultiMeshInstance>(p_current);
_convert_mult_mesh_instance_to_gltf(multi, p_gltf_parent, p_gltf_root, gltf_node, state);
@ -5433,6 +5446,7 @@ void GLTFDocument::_convert_mult_mesh_instance_to_gltf(MultiMeshInstance *p_mult
}
}
#ifdef MODULE_SKELETON_3D_ENABLED
void GLTFDocument::_convert_skeleton_to_gltf(Skeleton *p_skeleton3d, Ref<GLTFState> state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node) {
Skeleton *skeleton = p_skeleton3d;
Ref<GLTFSkeleton> gltf_skeleton;
@ -5486,7 +5500,9 @@ void GLTFDocument::_convert_skeleton_to_gltf(Skeleton *p_skeleton3d, Ref<GLTFSta
_convert_scene_node(state, skeleton->get_child(node_i), p_parent_node_index, p_root_node_index);
}
}
#endif
#ifdef MODULE_SKELETON_3D_ENABLED
void GLTFDocument::_convert_bone_attachment_to_gltf(BoneAttachment *p_bone_attachment, Ref<GLTFState> state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node) {
Skeleton *skeleton;
// Note that relative transforms to external skeletons and pose overrides are not supported.
@ -5517,6 +5533,7 @@ void GLTFDocument::_convert_bone_attachment_to_gltf(BoneAttachment *p_bone_attac
_convert_scene_node(state, p_bone_attachment->get_child(node_i), par_node_index, p_root_node_index);
}
}
#endif
void GLTFDocument::_convert_mesh_instance_to_gltf(MeshInstance *p_scene_parent, Ref<GLTFState> state, Ref<GLTFNode> gltf_node) {
GLTFMeshIndex gltf_mesh_index = _convert_mesh_to_gltf(state, p_scene_parent);
@ -5535,6 +5552,7 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> state, Node *scene_parent
Spatial *current_node = nullptr;
#ifdef MODULE_SKELETON_3D_ENABLED
// Is our parent a skeleton
Skeleton *active_skeleton = Object::cast_to<Skeleton>(scene_parent);
@ -5555,6 +5573,8 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> state, Node *scene_parent
// and attach it to the bone_attachment
scene_parent = bone_attachment;
}
#endif
if (gltf_node->mesh >= 0) {
current_node = _generate_mesh_instance(state, scene_parent, node_index);
} else if (gltf_node->camera >= 0) {
@ -5582,6 +5602,7 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> state, Node *scene_parent
}
}
#ifdef MODULE_SKELETON_3D_ENABLED
void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> state, Node *scene_parent, Spatial *scene_root, const GLTFNodeIndex node_index) {
Ref<GLTFNode> gltf_node = state->nodes[node_index];
@ -5664,6 +5685,7 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> state, Node *scen
_generate_scene_node(state, active_skeleton, scene_root, gltf_node->children[i]);
}
}
#endif
template <class T>
struct EditorSceneImporterGLTFInterpolate {
@ -5823,12 +5845,14 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
node_path = root->get_path_to(node_element->get());
if (gltf_node->skeleton >= 0) {
#ifdef MODULE_SKELETON_3D_ENABLED
const Skeleton *sk = state->skeletons[gltf_node->skeleton]->pandemonium_skeleton;
ERR_FAIL_COND(sk == nullptr);
const String path = root->get_path_to(sk);
const String bone = gltf_node->get_name();
transform_node_path = path + ":" + bone;
#endif
} else {
transform_node_path = node_path;
}
@ -6035,6 +6059,7 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) {
node->rotation = mi_xform.basis.get_rotation_quaternion();
node->translation = mi_xform.origin;
#ifdef MODULE_SKELETON_3D_ENABLED
Skeleton *skeleton = Object::cast_to<Skeleton>(mi->get_node(mi->get_skeleton_path()));
if (!skeleton) {
continue;
@ -6116,6 +6141,7 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) {
node->skeleton = skeleton_gltf_i;
}
}
#endif
}
float GLTFDocument::solve_metallic(float p_dielectric_specular, float diffuse, float specular, float p_one_minus_specular_strength) {
@ -6150,6 +6176,7 @@ float GLTFDocument::get_max_component(const Color &p_color) {
}
void GLTFDocument::_process_mesh_instances(Ref<GLTFState> state, Node *scene_root) {
#ifdef MODULE_SKELETON_3D_ENABLED
for (GLTFNodeIndex node_i = 0; node_i < state->nodes.size(); ++node_i) {
Ref<GLTFNode> node = state->nodes[node_i];
@ -6176,6 +6203,7 @@ void GLTFDocument::_process_mesh_instances(Ref<GLTFState> state, Node *scene_roo
mi->set_transform(Transform());
}
}
#endif
}
GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, int32_t p_track_i, GLTFNodeIndex p_node_i) {
@ -6487,6 +6515,7 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
}
tracks[mesh_index] = track;
}
#ifdef MODULE_SKELETON_3D_ENABLED
} else if (String(orig_track_path).find(":") != -1) {
//Process skeleton
const Vector<String> node_suffix = String(orig_track_path).split(":");
@ -6521,6 +6550,7 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
gltf_animation->get_tracks()[node_i] = track;
}
}
#endif
} else if (String(orig_track_path).find(":") == -1) {
Node *ap_root = ap->get_node_or_null(ap->get_root());
ERR_CONTINUE(!ap_root);

View File

@ -30,11 +30,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/3d/bone_attachment.h"
#include "scene/3d/camera.h"
#include "scene/3d/light.h"
#include "scene/3d/mesh_instance.h"
#include "scene/3d/skeleton.h"
#include "scene/3d/spatial.h"
#include "scene/animation/animation_player.h"
#include "scene/resources/material.h"
@ -44,6 +42,9 @@
#include "modules/modules_enabled.gen.h" // For csg, gridmap.
class Skeleton;
class BoneAttachment;
class GLTFState;
class GLTFSkin;
class GLTFNode;
@ -243,12 +244,13 @@ private:
Error _verify_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin);
Error _parse_skins(Ref<GLTFState> state);
Error _determine_skeletons(Ref<GLTFState> state);
Error _reparent_non_joint_skeleton_subtrees(
Ref<GLTFState> state, Ref<GLTFSkeleton> skeleton,
const Vector<GLTFNodeIndex> &non_joints);
Error _determine_skeleton_roots(Ref<GLTFState> state,
const GLTFSkeletonIndex skel_i);
Error _reparent_non_joint_skeleton_subtrees(Ref<GLTFState> state, Ref<GLTFSkeleton> skeleton, const Vector<GLTFNodeIndex> &non_joints);
Error _determine_skeleton_roots(Ref<GLTFState> state, const GLTFSkeletonIndex skel_i);
#ifdef MODULE_SKELETON_3D_ENABLED
Error _create_skeletons(Ref<GLTFState> state);
#endif
Error _map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFState> state);
Error _serialize_skins(Ref<GLTFState> state);
Error _create_skins(Ref<GLTFState> state);
@ -259,10 +261,11 @@ private:
Error _parse_lights(Ref<GLTFState> state);
Error _parse_animations(Ref<GLTFState> state);
Error _serialize_animations(Ref<GLTFState> state);
BoneAttachment *_generate_bone_attachment(Ref<GLTFState> state,
Skeleton *skeleton,
const GLTFNodeIndex node_index,
const GLTFNodeIndex bone_index);
#ifdef MODULE_SKELETON_3D_ENABLED
BoneAttachment *_generate_bone_attachment(Ref<GLTFState> state, Skeleton *skeleton, const GLTFNodeIndex node_index, const GLTFNodeIndex bone_index);
#endif
Spatial *_generate_mesh_instance(Ref<GLTFState> state, Node *scene_parent, const GLTFNodeIndex node_index);
Camera *_generate_camera(Ref<GLTFState> state, Node *scene_parent,
const GLTFNodeIndex node_index);
@ -367,7 +370,11 @@ public:
void _generate_scene_node(Ref<GLTFState> state, Node *scene_parent,
Spatial *scene_root,
const GLTFNodeIndex node_index);
#ifdef MODULE_SKELETON_3D_ENABLED
void _generate_skeleton_bone_node(Ref<GLTFState> state, Node *scene_parent, Spatial *scene_root, const GLTFNodeIndex node_index);
#endif
void _import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
const GLTFAnimationIndex index, const int bake_fps);
void _convert_mesh_instances(Ref<GLTFState> state);
@ -398,16 +405,19 @@ public:
GLTFNodeIndex p_parent_node_index,
GLTFNodeIndex p_root_node_index,
Ref<GLTFNode> gltf_node, Ref<GLTFState> state);
void _convert_skeleton_to_gltf(
Skeleton *p_scene_parent, Ref<GLTFState> state,
GLTFNodeIndex p_parent_node_index,
GLTFNodeIndex p_root_node_index,
Ref<GLTFNode> gltf_node);
#ifdef MODULE_SKELETON_3D_ENABLED
void _convert_skeleton_to_gltf(Skeleton *p_scene_parent, Ref<GLTFState> state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node);
#endif
#ifdef MODULE_SKELETON_3D_ENABLED
void _convert_bone_attachment_to_gltf(BoneAttachment *p_bone_attachment,
Ref<GLTFState> state,
GLTFNodeIndex p_parent_node_index,
GLTFNodeIndex p_root_node_index,
Ref<GLTFNode> gltf_node);
#endif
void _convert_mesh_instance_to_gltf(MeshInstance *p_mesh_instance,
Ref<GLTFState> state,
Ref<GLTFNode> gltf_node);

View File

@ -35,13 +35,17 @@ void GLTFSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_joints", "joints"), &GLTFSkeleton::set_joints);
ClassDB::bind_method(D_METHOD("get_roots"), &GLTFSkeleton::get_roots);
ClassDB::bind_method(D_METHOD("set_roots", "roots"), &GLTFSkeleton::set_roots);
#ifdef MODULE_SKELETON_3D_ENABLED
ClassDB::bind_method(D_METHOD("get_pandemonium_skeleton"), &GLTFSkeleton::get_pandemonium_skeleton);
ClassDB::bind_method(D_METHOD("get_bone_attachment", "idx"), &GLTFSkeleton::get_bone_attachment);
#endif
ClassDB::bind_method(D_METHOD("get_unique_names"), &GLTFSkeleton::get_unique_names);
ClassDB::bind_method(D_METHOD("set_unique_names", "unique_names"), &GLTFSkeleton::set_unique_names);
ClassDB::bind_method(D_METHOD("get_pandemonium_bone_node"), &GLTFSkeleton::get_pandemonium_bone_node);
ClassDB::bind_method(D_METHOD("set_pandemonium_bone_node", "pandemonium_bone_node"), &GLTFSkeleton::set_pandemonium_bone_node);
ClassDB::bind_method(D_METHOD("get_bone_attachment_count"), &GLTFSkeleton::get_bone_attachment_count);
ClassDB::bind_method(D_METHOD("get_bone_attachment", "idx"), &GLTFSkeleton::get_bone_attachment);
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints"), "set_joints", "get_joints"); // PoolVector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "roots"), "set_roots", "get_roots"); // PoolVector<GLTFNodeIndex>
@ -65,9 +69,15 @@ void GLTFSkeleton::set_roots(PoolVector<GLTFNodeIndex> p_roots) {
roots = p_roots;
}
#ifdef MODULE_SKELETON_3D_ENABLED
Skeleton *GLTFSkeleton::get_pandemonium_skeleton() {
return pandemonium_skeleton;
}
BoneAttachment *GLTFSkeleton::get_bone_attachment(int idx) {
ERR_FAIL_INDEX_V(idx, bone_attachments.size(), nullptr);
return bone_attachments[idx];
}
#endif
Array GLTFSkeleton::get_unique_names() {
return GLTFDocument::to_array(unique_names);
@ -85,11 +95,10 @@ void GLTFSkeleton::set_pandemonium_bone_node(Dictionary p_indict) {
GLTFDocument::set_from_dict(pandemonium_bone_node, p_indict);
}
BoneAttachment *GLTFSkeleton::get_bone_attachment(int idx) {
ERR_FAIL_INDEX_V(idx, bone_attachments.size(), nullptr);
return bone_attachments[idx];
}
int32_t GLTFSkeleton::get_bone_attachment_count() {
#ifdef MODULE_SKELETON_3D_ENABLED
return bone_attachments.size();
#else
return 0;
#endif
}

View File

@ -34,6 +34,13 @@
#include "gltf_document.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/nodes/bone_attachment.h"
#include "modules/skeleton_3d/nodes/skeleton.h"
#endif
class GLTFSkeleton : public Resource {
GDCLASS(GLTFSkeleton, Resource);
friend class GLTFDocument;
@ -54,7 +61,9 @@ private:
Map<int32_t, GLTFNodeIndex> pandemonium_bone_node;
#ifdef MODULE_SKELETON_3D_ENABLED
PoolVector<BoneAttachment *> bone_attachments;
#endif
protected:
static void _bind_methods();
@ -66,7 +75,10 @@ public:
PoolVector<GLTFNodeIndex> get_roots();
void set_roots(PoolVector<GLTFNodeIndex> p_roots);
#ifdef MODULE_SKELETON_3D_ENABLED
Skeleton *get_pandemonium_skeleton();
BoneAttachment *get_bone_attachment(int idx);
#endif
Array get_unique_names();
void set_unique_names(Array p_unique_names);
@ -74,8 +86,6 @@ public:
Dictionary get_pandemonium_bone_node();
void set_pandemonium_bone_node(Dictionary p_indict);
BoneAttachment *get_bone_attachment(int idx);
int32_t get_bone_attachment_count();
};

View File

@ -30,7 +30,11 @@
#include "gltf_skin.h"
#include "scene/resources/skin.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/resources/skin.h"
#endif
void GLTFSkin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_skin_root"), &GLTFSkin::get_skin_root);
@ -51,8 +55,12 @@ void GLTFSkin::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_joint_i_to_bone_i", "joint_i_to_bone_i"), &GLTFSkin::set_joint_i_to_bone_i);
ClassDB::bind_method(D_METHOD("get_joint_i_to_name"), &GLTFSkin::get_joint_i_to_name);
ClassDB::bind_method(D_METHOD("set_joint_i_to_name", "joint_i_to_name"), &GLTFSkin::set_joint_i_to_name);
#ifdef MODULE_SKELETON_3D_ENABLED
ClassDB::bind_method(D_METHOD("get_pandemonium_skin"), &GLTFSkin::get_pandemonium_skin);
ClassDB::bind_method(D_METHOD("set_pandemonium_skin", "pandemonium_skin"), &GLTFSkin::set_pandemonium_skin);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "pandemonium_skin"), "set_pandemonium_skin", "get_pandemonium_skin"); // Ref<Skin>
#endif
ADD_PROPERTY(PropertyInfo(Variant::INT, "skin_root"), "set_skin_root", "get_skin_root"); // GLTFNodeIndex
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints_original"), "set_joints_original", "get_joints_original"); // Vector<GLTFNodeIndex>
@ -63,7 +71,6 @@ void GLTFSkin::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "skeleton"), "set_skeleton", "get_skeleton"); // int
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_bone_i", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_bone_i", "get_joint_i_to_bone_i"); // Map<int,
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_name", "get_joint_i_to_name"); // Map<int,
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "pandemonium_skin"), "set_pandemonium_skin", "get_pandemonium_skin"); // Ref<Skin>
}
GLTFNodeIndex GLTFSkin::get_skin_root() {
@ -148,6 +155,7 @@ void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) {
}
}
#ifdef MODULE_SKELETON_3D_ENABLED
Ref<Skin> GLTFSkin::get_pandemonium_skin() {
return pandemonium_skin;
}
@ -155,6 +163,7 @@ Ref<Skin> GLTFSkin::get_pandemonium_skin() {
void GLTFSkin::set_pandemonium_skin(Ref<Skin> p_pandemonium_skin) {
pandemonium_skin = p_pandemonium_skin;
}
#endif
GLTFSkin::GLTFSkin() {
}

View File

@ -34,7 +34,13 @@
#include "gltf_document.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_3D_ENABLED
class Skin;
#endif
class GLTFSkin : public Resource {
GDCLASS(GLTFSkin, Resource);
@ -70,9 +76,11 @@ private:
Map<int, int> joint_i_to_bone_i;
Map<int, StringName> joint_i_to_name;
#ifdef MODULE_SKELETON_3D_ENABLED
// The Actual Skin that will be created as a mapping between the IBM's of
// this skin to the generated skeleton for the mesh instances.
Ref<Skin> pandemonium_skin;
#endif
protected:
static void _bind_methods();
@ -105,8 +113,10 @@ public:
Dictionary get_joint_i_to_name();
void set_joint_i_to_name(Dictionary p_joint_i_to_name);
#ifdef MODULE_SKELETON_3D_ENABLED
Ref<Skin> get_pandemonium_skin();
void set_pandemonium_skin(Ref<Skin> p_pandemonium_skin);
#endif
GLTFSkin();
~GLTFSkin();

View File

@ -30,8 +30,6 @@
#include "gltf_state.h"
#include "scene/resources/skin.h"
void GLTFState::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_json"), &GLTFState::get_json);
ClassDB::bind_method(D_METHOD("set_json", "json"), &GLTFState::set_json);

View File

@ -36,7 +36,6 @@
#include "scene/3d/spatial.h"
#include "scene/animation/animation_player.h"
#include "scene/resources/mesh.h"
#include "scene/resources/skin.h"
#include "gltf_document.h"

View File

@ -1,7 +0,0 @@
Import('env')
env.add_source_files(env.modules_sources,"register_types.cpp")
if env["tools"]:
env.add_source_files(env.modules_sources, "skeleton_editor_plugin.cpp")

View File

@ -1,13 +0,0 @@
def can_build(env, platform):
return env["tools"]
def configure(env):
pass
def get_doc_classes():
return [
]
def get_doc_path():
return "doc_classes"

View File

@ -1,36 +0,0 @@
/*
Copyright (c) 2021 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "register_types.h"
#ifdef TOOLS_ENABLED
#include "skeleton_editor_plugin.h"
#endif
void register_skeleton_editor_types() {
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<SkeletonEditorPlugin>();
#endif
}
void unregister_skeleton_editor_types() {
}

View File

@ -1,24 +0,0 @@
/*
Copyright (c) 2021 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
void register_skeleton_editor_types();
void unregister_skeleton_editor_types();

View File

@ -9,7 +9,6 @@ module_env.add_source_files(env.modules_sources,"register_types.cpp")
module_env.add_source_files(env.modules_sources,"nodes/skeleton_2d.cpp")
module_env.add_source_files(env.modules_sources,"nodes/physical_bone_2d.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d_ccdik.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d_fabrik.cpp")

View File

@ -12,6 +12,7 @@ def get_doc_classes():
return [
"Skeleton2D",
"PhysicalBone2D",
"Bone2D",
"SkeletonModificationStack2D",

View File

Before

Width:  |  Height:  |  Size: 614 B

After

Width:  |  Height:  |  Size: 614 B

View File

@ -2,7 +2,6 @@
*.d
*.o
*.meta
*.pyc
*.obj
*.pyc
*.bc

31
modules/skeleton_3d/SCsub Normal file
View File

@ -0,0 +1,31 @@
import os
Import('env')
module_env = env.Clone()
module_env.add_source_files(env.modules_sources,"register_types.cpp")
module_env.add_source_files(env.modules_sources,"nodes/skeleton.cpp")
module_env.add_source_files(env.modules_sources,"resources/skin.cpp")
module_env.add_source_files(env.modules_sources,"nodes/physical_bone.cpp")
module_env.add_source_files(env.modules_sources,"nodes/bone_attachment.cpp")
module_env.add_source_files(env.modules_sources,"nodes/skeleton_ik.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_3d.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_3d_ccdik.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_3d_fabrik.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_3d_jiggle.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_3d_lookat.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_3d_stackholder.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_3d_twoboneik.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_stack_3d.cpp")
if env["tools"]:
env.add_source_files(env.modules_sources, "editor/physical_bone_editor_plugin.cpp")
env.add_source_files(env.modules_sources, "editor/skeleton_editor_plugin.cpp")
env.add_source_files(env.modules_sources, "editor/skeleton_ik_editor_plugin.cpp")
env.add_source_files(env.modules_sources, "editor/physical_bone_plugin.cpp")

View File

@ -0,0 +1,35 @@
def can_build(env, platform):
return True
def configure(env):
pass
def get_doc_classes():
return [
"Skeleton",
"Skin",
"SkinReference",
"BoneAttachment",
"PhysicalBone",
"SkeletonIK",
"SkeletonModificationStack3D",
"SkeletonModification3D",
"SkeletonModification3DCCDIK",
"SkeletonModification3DFABRIK",
"SkeletonModification3DJiggle",
"SkeletonModification3DLookAt",
"SkeletonModification3DStackHolder",
"SkeletonModification3DTwoBoneIK",
]
def get_doc_path():
return "doc_classes"

View File

@ -0,0 +1,139 @@
#include "physical_bone_editor_plugin.h"
#include "editor/editor_settings.h"
#include "../nodes/skeleton.h"
#include "../resources/skin.h"
#include "../nodes/physical_bone.h"
PhysicalBoneSpatialGizmoPlugin::PhysicalBoneSpatialGizmoPlugin() {
create_material("joint_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1)));
}
bool PhysicalBoneSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
return Object::cast_to<PhysicalBone>(p_spatial) != nullptr;
}
String PhysicalBoneSpatialGizmoPlugin::get_gizmo_name() const {
return "PhysicalBones";
}
int PhysicalBoneSpatialGizmoPlugin::get_priority() const {
return -1;
}
void PhysicalBoneSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
p_gizmo->clear();
PhysicalBone *physical_bone = Object::cast_to<PhysicalBone>(p_gizmo->get_spatial_node());
if (!physical_bone) {
return;
}
Skeleton *sk(physical_bone->find_skeleton_parent());
if (!sk) {
return;
}
PhysicalBone *pb(sk->get_physical_bone(physical_bone->get_bone_id()));
if (!pb) {
return;
}
PhysicalBone *pbp(sk->get_physical_bone_parent(physical_bone->get_bone_id()));
if (!pbp) {
return;
}
Vector<Vector3> points;
switch (physical_bone->get_joint_type()) {
case PhysicalBone::JOINT_TYPE_PIN: {
JointSpatialGizmoPlugin::CreatePinJointGizmo(physical_bone->get_joint_offset(), points);
} break;
case PhysicalBone::JOINT_TYPE_CONE: {
const PhysicalBone::ConeJointData *cjd(static_cast<const PhysicalBone::ConeJointData *>(physical_bone->get_joint_data()));
JointSpatialGizmoPlugin::CreateConeTwistJointGizmo(
physical_bone->get_joint_offset(),
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
pb->get_global_transform(),
pbp->get_global_transform(),
cjd->swing_span,
cjd->twist_span,
&points,
&points);
} break;
case PhysicalBone::JOINT_TYPE_HINGE: {
const PhysicalBone::HingeJointData *hjd(static_cast<const PhysicalBone::HingeJointData *>(physical_bone->get_joint_data()));
JointSpatialGizmoPlugin::CreateHingeJointGizmo(
physical_bone->get_joint_offset(),
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
pb->get_global_transform(),
pbp->get_global_transform(),
hjd->angular_limit_lower,
hjd->angular_limit_upper,
hjd->angular_limit_enabled,
points,
&points,
&points);
} break;
case PhysicalBone::JOINT_TYPE_SLIDER: {
const PhysicalBone::SliderJointData *sjd(static_cast<const PhysicalBone::SliderJointData *>(physical_bone->get_joint_data()));
JointSpatialGizmoPlugin::CreateSliderJointGizmo(
physical_bone->get_joint_offset(),
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
pb->get_global_transform(),
pbp->get_global_transform(),
sjd->angular_limit_lower,
sjd->angular_limit_upper,
sjd->linear_limit_lower,
sjd->linear_limit_upper,
points,
&points,
&points);
} break;
case PhysicalBone::JOINT_TYPE_6DOF: {
const PhysicalBone::SixDOFJointData *sdofjd(static_cast<const PhysicalBone::SixDOFJointData *>(physical_bone->get_joint_data()));
JointSpatialGizmoPlugin::CreateGeneric6DOFJointGizmo(
physical_bone->get_joint_offset(),
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
pb->get_global_transform(),
pbp->get_global_transform(),
sdofjd->axis_data[0].angular_limit_lower,
sdofjd->axis_data[0].angular_limit_upper,
sdofjd->axis_data[0].linear_limit_lower,
sdofjd->axis_data[0].linear_limit_upper,
sdofjd->axis_data[0].angular_limit_enabled,
sdofjd->axis_data[0].linear_limit_enabled,
sdofjd->axis_data[1].angular_limit_lower,
sdofjd->axis_data[1].angular_limit_upper,
sdofjd->axis_data[1].linear_limit_lower,
sdofjd->axis_data[1].linear_limit_upper,
sdofjd->axis_data[1].angular_limit_enabled,
sdofjd->axis_data[1].linear_limit_enabled,
sdofjd->axis_data[2].angular_limit_lower,
sdofjd->axis_data[2].angular_limit_upper,
sdofjd->axis_data[2].linear_limit_lower,
sdofjd->axis_data[2].linear_limit_upper,
sdofjd->axis_data[2].angular_limit_enabled,
sdofjd->axis_data[2].linear_limit_enabled,
points,
&points,
&points);
} break;
default:
return;
}
Ref<Material> material = get_material("joint_material", p_gizmo);
p_gizmo->add_collision_segments(points);
p_gizmo->add_lines(points, material);
}

View File

@ -0,0 +1,21 @@
#ifndef PHYSICAL_BONE_EDITOR_PLUGIN_H
#define PHYSICAL_BONE_EDITOR_PLUGIN_H
#include "core/string/ustring.h"
#include "editor/spatial_editor_gizmos.h"
class PhysicalBoneSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(PhysicalBoneSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
bool has_gizmo(Spatial *p_spatial);
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
PhysicalBoneSpatialGizmoPlugin();
};
#endif

View File

@ -32,6 +32,7 @@
#include "editor/plugins/spatial_editor_plugin.h"
#include "scene/3d/physics_body.h"
#include "../nodes/physical_bone.h"
#include "core/object/class_db.h"
#include "core/error/error_macros.h"
#include "core/os/memory.h"

View File

@ -30,6 +30,7 @@
#include "skeleton_editor_plugin.h"
#include "../resources/skin.h"
#include "core/io/resource_saver.h"
#include "core/os/keyboard.h"
#include "editor/animation_track_editor.h"
@ -44,6 +45,7 @@
#include "scene/3d/collision_shape.h"
#include "scene/3d/mesh_instance.h"
#include "scene/3d/physics_body.h"
#include "../nodes/physical_bone.h"
#include "scene/3d/physics_joint.h"
#include "scene/gui/check_box.h"
#include "scene/gui/grid_container.h"
@ -54,10 +56,11 @@
#include "scene/gui/tree.h"
#include "scene/main/viewport.h"
#include "scene/resources/capsule_shape.h"
#include "scene/resources/skin.h"
#include "scene/resources/sphere_shape.h"
#include "scene/resources/surface_tool.h"
#include "physical_bone_editor_plugin.h"
#define DISTANCE_DEFAULT 4
#define GIZMO_ARROW_SIZE 0.35
@ -1293,6 +1296,7 @@ void SkeletonEditor::_bone_enabled_changed(const int p_bone_id) {
void SkeletonEditorPlugin::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
add_spatial_gizmo_plugin(Ref<SkeletonGizmoPlugin>(memnew(SkeletonGizmoPlugin)));
add_spatial_gizmo_plugin(Ref<PhysicalBoneSpatialGizmoPlugin>(memnew(PhysicalBoneSpatialGizmoPlugin)));
}
}

View File

@ -37,7 +37,7 @@
#include "editor/spatial_editor_gizmos.h"
#include "scene/3d/camera.h"
#include "scene/3d/mesh_instance.h"
#include "scene/3d/skeleton.h"
#include "../nodes/skeleton.h"
#include "scene/resources/immediate_mesh.h"
class EditorInspectorPluginSkeleton;

View File

@ -30,8 +30,8 @@
#include "skeleton_ik_editor_plugin.h"
#include "scene/3d/skeleton.h"
#include "scene/animation/skeleton_ik.h"
#include "../nodes/skeleton.h"
#include "../nodes/skeleton_ik.h"
#include "core/object/class_db.h"
#include "core/os/memory.h"
#include "editor/editor_node.h"

View File

Before

Width:  |  Height:  |  Size: 170 B

After

Width:  |  Height:  |  Size: 170 B

View File

Before

Width:  |  Height:  |  Size: 918 B

After

Width:  |  Height:  |  Size: 918 B

View File

Before

Width:  |  Height:  |  Size: 546 B

After

Width:  |  Height:  |  Size: 546 B

View File

Before

Width:  |  Height:  |  Size: 594 B

After

Width:  |  Height:  |  Size: 594 B

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 237 B

After

Width:  |  Height:  |  Size: 237 B

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 797 B

After

Width:  |  Height:  |  Size: 797 B

View File

@ -30,7 +30,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/3d/skeleton.h"
#include "skeleton.h"
class BoneAttachment : public Spatial {
GDCLASS(BoneAttachment, Spatial);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,321 @@
#ifndef PHYSICAL_BONE_H
#define PHYSICAL_BONE_H
/*************************************************************************/
/* physics_body.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "core/object/reference.h"
#include "core/containers/vset.h"
#include "scene/3d/collision_object.h"
#include "servers/physics_server.h"
#include "scene/3d/physics_body.h"
class PhysicsMaterial;
class Skeleton;
class PhysicalBone : public PhysicsBody {
GDCLASS(PhysicalBone, PhysicsBody);
public:
enum JointType {
JOINT_TYPE_NONE,
JOINT_TYPE_PIN,
JOINT_TYPE_CONE,
JOINT_TYPE_HINGE,
JOINT_TYPE_SLIDER,
JOINT_TYPE_6DOF
};
struct JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_NONE; }
/// "j" is used to set the parameter inside the PhysicsServer
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
virtual ~JointData() {}
};
struct PinJointData : public JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_PIN; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
real_t bias;
real_t damping;
real_t impulse_clamp;
PinJointData() :
bias(0.3),
damping(1.),
impulse_clamp(0) {}
};
struct ConeJointData : public JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_CONE; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
real_t swing_span;
real_t twist_span;
real_t bias;
real_t softness;
real_t relaxation;
ConeJointData() :
swing_span(Math_PI * 0.25),
twist_span(Math_PI),
bias(0.3),
softness(0.8),
relaxation(1.) {}
};
struct HingeJointData : public JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_HINGE; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
bool angular_limit_enabled;
real_t angular_limit_upper;
real_t angular_limit_lower;
real_t angular_limit_bias;
real_t angular_limit_softness;
real_t angular_limit_relaxation;
HingeJointData() :
angular_limit_enabled(false),
angular_limit_upper(Math_PI * 0.5),
angular_limit_lower(-Math_PI * 0.5),
angular_limit_bias(0.3),
angular_limit_softness(0.9),
angular_limit_relaxation(1.) {}
};
struct SliderJointData : public JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_SLIDER; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
real_t linear_limit_upper;
real_t linear_limit_lower;
real_t linear_limit_softness;
real_t linear_limit_restitution;
real_t linear_limit_damping;
real_t angular_limit_upper;
real_t angular_limit_lower;
real_t angular_limit_softness;
real_t angular_limit_restitution;
real_t angular_limit_damping;
SliderJointData() :
linear_limit_upper(1.),
linear_limit_lower(-1.),
linear_limit_softness(1.),
linear_limit_restitution(0.7),
linear_limit_damping(1.),
angular_limit_upper(0),
angular_limit_lower(0),
angular_limit_softness(1.),
angular_limit_restitution(0.7),
angular_limit_damping(1.) {}
};
struct SixDOFJointData : public JointData {
struct SixDOFAxisData {
bool linear_limit_enabled;
real_t linear_limit_upper;
real_t linear_limit_lower;
real_t linear_limit_softness;
real_t linear_restitution;
real_t linear_damping;
bool linear_spring_enabled;
real_t linear_spring_stiffness;
real_t linear_spring_damping;
real_t linear_equilibrium_point;
bool angular_limit_enabled;
real_t angular_limit_upper;
real_t angular_limit_lower;
real_t angular_limit_softness;
real_t angular_restitution;
real_t angular_damping;
real_t erp;
bool angular_spring_enabled;
real_t angular_spring_stiffness;
real_t angular_spring_damping;
real_t angular_equilibrium_point;
SixDOFAxisData() :
linear_limit_enabled(true),
linear_limit_upper(0),
linear_limit_lower(0),
linear_limit_softness(0.7),
linear_restitution(0.5),
linear_damping(1.),
linear_spring_enabled(false),
linear_spring_stiffness(0),
linear_spring_damping(0),
linear_equilibrium_point(0),
angular_limit_enabled(true),
angular_limit_upper(0),
angular_limit_lower(0),
angular_limit_softness(0.5),
angular_restitution(0),
angular_damping(1.),
erp(0.5),
angular_spring_enabled(false),
angular_spring_stiffness(0),
angular_spring_damping(0.),
angular_equilibrium_point(0) {}
};
virtual JointType get_joint_type() { return JOINT_TYPE_6DOF; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
SixDOFAxisData axis_data[3];
SixDOFJointData() {}
};
private:
#ifdef TOOLS_ENABLED
// if false gizmo move body
bool gizmo_move_joint;
#endif
JointData *joint_data;
Transform joint_offset;
RID joint;
Skeleton *parent_skeleton;
Transform body_offset;
Transform body_offset_inverse;
bool simulate_physics;
bool _internal_simulate_physics;
int bone_id;
String bone_name;
real_t bounce;
real_t mass;
real_t friction;
real_t gravity_scale;
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
void _direct_state_changed(Object *p_state);
static void _bind_methods();
private:
static Skeleton *find_skeleton_parent(Node *p_parent);
void _fix_joint_offset();
void _reload_joint();
public:
void _on_bone_parent_changed();
void _set_gizmo_move_joint(bool p_move_joint);
public:
#ifdef TOOLS_ENABLED
virtual Transform get_global_gizmo_transform() const;
virtual Transform get_local_gizmo_transform() const;
#endif
const JointData *get_joint_data() const;
Skeleton *find_skeleton_parent();
int get_bone_id() const { return bone_id; }
void set_joint_type(JointType p_joint_type);
JointType get_joint_type() const;
void set_joint_offset(const Transform &p_offset);
const Transform &get_joint_offset() const;
void set_body_offset(const Transform &p_offset);
const Transform &get_body_offset() const;
void set_simulate_physics(bool p_simulate);
bool get_simulate_physics();
bool is_simulating_physics();
void set_bone_name(const String &p_name);
const String &get_bone_name() const;
void set_mass(real_t p_mass);
real_t get_mass() const;
void set_weight(real_t p_weight);
real_t get_weight() const;
void set_friction(real_t p_friction);
real_t get_friction() const;
void set_bounce(real_t p_bounce);
real_t get_bounce() const;
void set_gravity_scale(real_t p_gravity_scale);
real_t get_gravity_scale() const;
void apply_central_impulse(const Vector3 &p_impulse);
void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
void reset_physics_simulation_state();
void reset_to_rest_position();
PhysicalBone();
~PhysicalBone();
private:
void update_bone_id();
void update_offset();
void _start_physics_simulation();
void _stop_physics_simulation();
};
VARIANT_ENUM_CAST(PhysicalBone::JointType);
#endif // PHYSICS_BODY__H

View File

@ -34,10 +34,10 @@
#include "core/config/engine.h"
#include "core/config/project_settings.h"
#include "scene/3d/physics_body.h"
#include "scene/resources/skeleton_modification_3d.h"
#include "scene/resources/skeleton_modification_stack_3d.h"
#include "scene/resources/skin.h"
#include "physical_bone.h"
#include "../resources/skeleton_modification_3d.h"
#include "../resources/skeleton_modification_stack_3d.h"
#include "../resources/skin.h"
#include "scene/resources/surface_tool.h"
#include "scene/scene_string_names.h"

View File

@ -36,7 +36,7 @@
#ifndef _3D_DISABLED
#include "scene/3d/skeleton.h"
#include "skeleton.h"
FabrikInverseKinematic::ChainItem *FabrikInverseKinematic::ChainItem::find_child(const BoneId p_bone_id) {
for (int i = children.size() - 1; 0 <= i; --i) {

View File

@ -0,0 +1,55 @@
#include "register_types.h"
#include "nodes/skeleton.h"
#include "resources/skin.h"
#include "nodes/bone_attachment.h"
#include "nodes/skeleton_ik.h"
#include "nodes/physical_bone.h"
#include "resources/skeleton_modification_3d.h"
#include "resources/skeleton_modification_3d_ccdik.h"
#include "resources/skeleton_modification_3d_fabrik.h"
#include "resources/skeleton_modification_3d_jiggle.h"
#include "resources/skeleton_modification_3d_lookat.h"
#include "resources/skeleton_modification_3d_stackholder.h"
#include "resources/skeleton_modification_3d_twoboneik.h"
#include "resources/skeleton_modification_stack_3d.h"
#ifdef TOOLS_ENABLED
#include "editor/skeleton_editor_plugin.h"
#include "editor/skeleton_ik_editor_plugin.h"
#include "editor/physical_bone_plugin.h"
#endif
void register_skeleton_3d_types() {
ClassDB::register_class<Skeleton>();
ClassDB::register_class<Skin>();
ClassDB::register_class<SkinReference>();
ClassDB::register_class<BoneAttachment>();
ClassDB::register_class<SkeletonIK>();
ClassDB::register_class<PhysicalBone>();
ClassDB::register_class<SkeletonModificationStack3D>();
ClassDB::register_class<SkeletonModification3D>();
ClassDB::register_class<SkeletonModification3DLookAt>();
ClassDB::register_class<SkeletonModification3DCCDIK>();
ClassDB::register_class<SkeletonModification3DFABRIK>();
ClassDB::register_class<SkeletonModification3DJiggle>();
ClassDB::register_class<SkeletonModification3DTwoBoneIK>();
ClassDB::register_class<SkeletonModification3DStackHolder>();
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<SkeletonEditorPlugin>();
EditorPlugins::add_by_type<SkeletonIKEditorPlugin>();
EditorPlugins::add_by_type<PhysicalBonePlugin>();
#endif
}
void unregister_skeleton_3d_types() {
}

View File

@ -0,0 +1,3 @@
void register_skeleton_3d_types();
void unregister_skeleton_3d_types();

View File

@ -29,9 +29,9 @@
/*************************************************************************/
#include "skeleton_modification_3d.h"
#include "scene/3d/skeleton.h"
#include "../nodes/skeleton.h"
#include "scene/resources/skeleton_modification_stack_3d.h"
#include "skeleton_modification_stack_3d.h"
void SkeletonModification3D::set_enabled(bool p_enabled) {
enabled = p_enabled;

View File

@ -32,7 +32,7 @@
#define SKELETON_MODIFICATION_3D_H
#include "core/object/reference.h"
#include "scene/3d/skeleton.h"
#include "../nodes/skeleton.h"
class SkeletonModificationStack3D;

View File

@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_3d_ccdik.h"
#include "scene/3d/skeleton.h"
#include "scene/resources/skeleton_modification_stack_3d.h"
#include "skeleton_modification_3d_ccdik.h"
#include "../nodes/skeleton.h"
#include "skeleton_modification_stack_3d.h"
bool SkeletonModification3DCCDIK::_set(const StringName &p_path, const Variant &p_value) {
String path = p_path;

View File

@ -33,8 +33,8 @@
/*************************************************************************/
#include "core/containers/local_vector.h"
#include "scene/3d/skeleton.h"
#include "scene/resources/skeleton_modification_3d.h"
#include "../nodes/skeleton.h"
#include "skeleton_modification_3d.h"
class SkeletonModification3DCCDIK : public SkeletonModification3D {
GDCLASS(SkeletonModification3DCCDIK, SkeletonModification3D);

View File

@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_3d_fabrik.h"
#include "scene/3d/skeleton.h"
#include "scene/resources/skeleton_modification_stack_3d.h"
#include "skeleton_modification_3d_fabrik.h"
#include "../nodes/skeleton.h"
#include "skeleton_modification_stack_3d.h"
bool SkeletonModification3DFABRIK::_set(const StringName &p_path, const Variant &p_value) {
String path = p_path;

View File

@ -32,7 +32,7 @@
/*************************************************************************/
#include "core/containers/local_vector.h"
#include "scene/resources/skeleton_modification_3d.h"
#include "skeleton_modification_3d.h"
class SkeletonModification3DFABRIK : public SkeletonModification3D {
GDCLASS(SkeletonModification3DFABRIK, SkeletonModification3D);

View File

@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_3d_jiggle.h"
#include "scene/3d/skeleton.h"
#include "scene/resources/skeleton_modification_stack_3d.h"
#include "skeleton_modification_3d_jiggle.h"
#include "../nodes/skeleton.h"
#include "skeleton_modification_stack_3d.h"
#include "servers/physics_server.h"
#include "scene/resources/world.h"

View File

@ -32,7 +32,7 @@
/*************************************************************************/
#include "core/containers/local_vector.h"
#include "scene/resources/skeleton_modification_3d.h"
#include "skeleton_modification_3d.h"
class SkeletonModification3DJiggle : public SkeletonModification3D {
GDCLASS(SkeletonModification3DJiggle, SkeletonModification3D);

View File

@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_3d_lookat.h"
#include "scene/3d/skeleton.h"
#include "scene/resources/skeleton_modification_stack_3d.h"
#include "skeleton_modification_3d_lookat.h"
#include "../nodes/skeleton.h"
#include "skeleton_modification_stack_3d.h"
bool SkeletonModification3DLookAt::_set(const StringName &p_path, const Variant &p_value) {
if (p_path == "lock_rotation_to_plane") {

View File

@ -31,7 +31,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_3d.h"
#include "skeleton_modification_3d.h"
class SkeletonModification3DLookAt : public SkeletonModification3D {
GDCLASS(SkeletonModification3DLookAt, SkeletonModification3D);

View File

@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_3d_stackholder.h"
#include "scene/3d/skeleton.h"
#include "scene/resources/skeleton_modification_stack_3d.h"
#include "skeleton_modification_3d_stackholder.h"
#include "../nodes/skeleton.h"
#include "skeleton_modification_stack_3d.h"
bool SkeletonModification3DStackHolder::_set(const StringName &p_path, const Variant &p_value) {
String path = p_path;

View File

@ -31,7 +31,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_3d.h"
#include "skeleton_modification_3d.h"
class SkeletonModification3DStackHolder : public SkeletonModification3D {
GDCLASS(SkeletonModification3DStackHolder, SkeletonModification3D);

View File

@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_3d_twoboneik.h"
#include "scene/3d/skeleton.h"
#include "scene/resources/skeleton_modification_stack_3d.h"
#include "skeleton_modification_3d_twoboneik.h"
#include "../nodes/skeleton.h"
#include "skeleton_modification_stack_3d.h"
bool SkeletonModification3DTwoBoneIK::_set(const StringName &p_path, const Variant &p_value) {
String path = p_path;

View File

@ -32,7 +32,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_3d.h"
#include "skeleton_modification_3d.h"
class Skeleton;

View File

@ -29,7 +29,7 @@
/*************************************************************************/
#include "skeleton_modification_stack_3d.h"
#include "scene/3d/skeleton.h"
#include "../nodes/skeleton.h"
#include "skeleton_modification_3d.h"

View File

@ -32,7 +32,7 @@
/*************************************************************************/
#include "core/containers/vector.h"
#include "scene/3d/skeleton.h"
#include "core/object/resource.h"
class Skeleton;
class SkeletonModification3D;

View File

@ -39,12 +39,14 @@ Ref<ImporterMesh> ImporterMeshInstance3D::get_mesh() const {
return mesh;
}
#ifdef MODULE_SKELETON_3D_ENABLED
void ImporterMeshInstance3D::set_skin(const Ref<Skin> &p_skin) {
skin = p_skin;
}
Ref<Skin> ImporterMeshInstance3D::get_skin() const {
return skin;
}
#endif
void ImporterMeshInstance3D::set_surface_material(int p_idx, const Ref<Material> &p_material) {
ERR_FAIL_COND(p_idx < 0);
@ -72,14 +74,15 @@ NodePath ImporterMeshInstance3D::get_skeleton_path() const {
void ImporterMeshInstance3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &ImporterMeshInstance3D::set_mesh);
ClassDB::bind_method(D_METHOD("get_mesh"), &ImporterMeshInstance3D::get_mesh);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "ImporterMesh"), "set_mesh", "get_mesh");
#ifdef MODULE_SKELETON_3D_ENABLED
ClassDB::bind_method(D_METHOD("set_skin", "skin"), &ImporterMeshInstance3D::set_skin);
ClassDB::bind_method(D_METHOD("get_skin"), &ImporterMeshInstance3D::get_skin);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
#endif
ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &ImporterMeshInstance3D::set_skeleton_path);
ClassDB::bind_method(D_METHOD("get_skeleton_path"), &ImporterMeshInstance3D::get_skeleton_path);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "ImporterMesh"), "set_mesh", "get_mesh");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path");
}

View File

@ -32,7 +32,12 @@
#define IMPORTER_MESH_INSTANCE_3D_H
#include "scene/3d/spatial.h"
#include "scene/resources/skin.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/resources/skin.h"
#endif
class ImporterMesh;
@ -51,8 +56,10 @@ public:
void set_mesh(const Ref<ImporterMesh> &p_mesh);
Ref<ImporterMesh> get_mesh() const;
#ifdef MODULE_SKELETON_3D_ENABLED
void set_skin(const Ref<Skin> &p_skin);
Ref<Skin> get_skin() const;
#endif
void set_surface_material(int p_idx, const Ref<Material> &p_material);
Ref<Material> get_surface_material(int p_idx) const;

View File

@ -31,16 +31,20 @@
#include "mesh_instance.h"
#include "collision_shape.h"
#include "core/core_string_names.h"
#include "core/config/project_settings.h"
#include "core/core_string_names.h"
#include "physics_body.h"
#include "scene/3d/skeleton.h"
#include "scene/resources/material.h"
#include "scene/resources/mesh.h"
#include "scene/resources/skin.h"
#include "scene/scene_string_names.h"
#include "servers/rendering/rendering_server_globals.h"
#include "skeleton.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/nodes/skeleton.h"
#include "modules/skeleton_3d/resources/skin.h"
#endif
bool MeshInstance::_set(const StringName &p_name, const Variant &p_value) {
//this is not _too_ bad performance wise, really. it only arrives here if the property was not set anywhere else.
@ -125,10 +129,12 @@ void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) {
skin_ref->get_skeleton_node()->disconnect("pose_updated", this, "_update_skinning");
}
#ifdef MODULE_SKELETON_3D_ENABLED
if (software_skinning) {
memdelete(software_skinning);
software_skinning = nullptr;
}
#endif
mesh = p_mesh;
@ -144,7 +150,9 @@ void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) {
mesh->connect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->_mesh_changed);
materials.resize(mesh->get_surface_count());
#ifdef MODULE_SKELETON_3D_ENABLED
_initialize_skinning(false, true);
#endif
} else {
set_base(RID());
}
@ -157,6 +165,7 @@ Ref<Mesh> MeshInstance::get_mesh() const {
return mesh;
}
#ifdef MODULE_SKELETON_3D_ENABLED
void MeshInstance::_resolve_skeleton_path() {
Ref<SkinReference> new_skin_reference;
@ -523,7 +532,9 @@ void MeshInstance::_update_skinning() {
software_skinning_flags |= SoftwareSkinning::FLAG_BONES_READY;
}
#endif
#ifdef MODULE_SKELETON_3D_ENABLED
void MeshInstance::set_skin(const Ref<Skin> &p_skin) {
skin_internal = p_skin;
skin = p_skin;
@ -548,6 +559,7 @@ void MeshInstance::set_skeleton_path(const NodePath &p_skeleton) {
NodePath MeshInstance::get_skeleton_path() {
return skeleton_path;
}
#endif
AABB MeshInstance::get_aabb() const {
if (!mesh.is_null()) {
@ -665,6 +677,7 @@ void MeshInstance::create_convex_collision(bool p_clean, bool p_simplify) {
}
void MeshInstance::_notification(int p_what) {
#ifdef MODULE_SKELETON_3D_ENABLED
if (p_what == NOTIFICATION_ENTER_TREE) {
_resolve_skeleton_path();
}
@ -679,6 +692,7 @@ void MeshInstance::_notification(int p_what) {
}
}
}
#endif
}
int MeshInstance::get_surface_material_count() const {
@ -696,9 +710,11 @@ void MeshInstance::set_surface_material(int p_surface, const Ref<Material> &p_ma
RS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, RID());
}
#ifdef MODULE_SKELETON_3D_ENABLED
if (software_skinning) {
_initialize_skinning(true);
}
#endif
}
Ref<Material> MeshInstance::get_surface_material(int p_surface) const {
@ -746,6 +762,7 @@ void MeshInstance::set_material_overlay(const Ref<Material> &p_material) {
GeometryInstance::set_material_overlay(p_material);
}
#ifdef MODULE_SKELETON_3D_ENABLED
void MeshInstance::set_software_skinning_transform_normals(bool p_enabled) {
if (p_enabled == is_software_skinning_transform_normals_enabled()) {
return;
@ -765,14 +782,17 @@ void MeshInstance::set_software_skinning_transform_normals(bool p_enabled) {
bool MeshInstance::is_software_skinning_transform_normals_enabled() const {
return 0 != (software_skinning_flags & SoftwareSkinning::FLAG_TRANSFORM_NORMALS);
}
#endif
void MeshInstance::_mesh_changed() {
ERR_FAIL_COND(mesh.is_null());
materials.resize(mesh->get_surface_count());
#ifdef MODULE_SKELETON_3D_ENABLED
if (software_skinning) {
_initialize_skinning(true);
}
#endif
}
void MeshInstance::create_debug_tangents() {
@ -1343,18 +1363,29 @@ void MeshInstance::_merge_log(String p_string) const {
void MeshInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MeshInstance::set_mesh);
ClassDB::bind_method(D_METHOD("get_mesh"), &MeshInstance::get_mesh);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
#ifdef MODULE_SKELETON_3D_ENABLED
ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &MeshInstance::set_skeleton_path);
ClassDB::bind_method(D_METHOD("get_skeleton_path"), &MeshInstance::get_skeleton_path);
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path");
ClassDB::bind_method(D_METHOD("set_skin", "skin"), &MeshInstance::set_skin);
ClassDB::bind_method(D_METHOD("get_skin"), &MeshInstance::get_skin);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
#endif
ClassDB::bind_method(D_METHOD("get_surface_material_count"), &MeshInstance::get_surface_material_count);
ClassDB::bind_method(D_METHOD("set_surface_material", "surface", "material"), &MeshInstance::set_surface_material);
ClassDB::bind_method(D_METHOD("get_surface_material", "surface"), &MeshInstance::get_surface_material);
ClassDB::bind_method(D_METHOD("get_active_material", "surface"), &MeshInstance::get_active_material);
#ifdef MODULE_SKELETON_3D_ENABLED
ADD_GROUP("Software Skinning", "software_skinning");
ClassDB::bind_method(D_METHOD("set_software_skinning_transform_normals", "enabled"), &MeshInstance::set_software_skinning_transform_normals);
ClassDB::bind_method(D_METHOD("is_software_skinning_transform_normals_enabled"), &MeshInstance::is_software_skinning_transform_normals_enabled);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "software_skinning_transform_normals"), "set_software_skinning_transform_normals", "is_software_skinning_transform_normals_enabled");
#endif
ClassDB::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance::create_trimesh_collision);
ClassDB::set_method_flags("MeshInstance", "create_trimesh_collision", METHOD_FLAGS_DEFAULT);
@ -1363,7 +1394,10 @@ void MeshInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("create_convex_collision", "clean", "simplify"), &MeshInstance::create_convex_collision, DEFVAL(true), DEFVAL(false));
ClassDB::set_method_flags("MeshInstance", "create_convex_collision", METHOD_FLAGS_DEFAULT);
ClassDB::bind_method(D_METHOD("_mesh_changed"), &MeshInstance::_mesh_changed);
#ifdef MODULE_SKELETON_3D_ENABLED
ClassDB::bind_method(D_METHOD("_update_skinning"), &MeshInstance::_update_skinning);
#endif
ClassDB::bind_method(D_METHOD("create_debug_tangents"), &MeshInstance::create_debug_tangents);
ClassDB::set_method_flags("MeshInstance", "create_debug_tangents", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
@ -1371,24 +1405,21 @@ void MeshInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_mergeable_with", "other_mesh_instance"), &MeshInstance::is_mergeable_with);
ClassDB::bind_method(D_METHOD("merge_meshes", "mesh_instances", "use_global_space", "check_compatibility"), &MeshInstance::merge_meshes, DEFVAL(Vector<Variant>()), DEFVAL(false), DEFVAL(true));
ClassDB::set_method_flags("MeshInstance", "merge_meshes", METHOD_FLAGS_DEFAULT);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path");
ADD_GROUP("Software Skinning", "software_skinning");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "software_skinning_transform_normals"), "set_software_skinning_transform_normals", "is_software_skinning_transform_normals_enabled");
}
MeshInstance::MeshInstance() {
#ifdef MODULE_SKELETON_3D_ENABLED
skeleton_path = NodePath("..");
software_skinning = nullptr;
software_skinning_flags = SoftwareSkinning::FLAG_TRANSFORM_NORMALS;
#endif
}
MeshInstance::~MeshInstance() {
#ifdef MODULE_SKELETON_3D_ENABLED
if (software_skinning) {
memdelete(software_skinning);
software_skinning = nullptr;
}
#endif
}

View File

@ -35,9 +35,14 @@
#include "core/containers/local_vector.h"
#include "core/object/reference.h"
class Mesh;
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_3D_ENABLED
class Skin;
class SkinReference;
#endif
class Mesh;
class NodePath;
class MeshInstance : public GeometryInstance {
@ -45,6 +50,8 @@ class MeshInstance : public GeometryInstance {
protected:
Ref<Mesh> mesh;
#ifdef MODULE_SKELETON_3D_ENABLED
Ref<Skin> skin;
Ref<Skin> skin_internal;
Ref<SkinReference> skin_ref;
@ -74,6 +81,7 @@ protected:
SoftwareSkinning *software_skinning;
uint32_t software_skinning_flags;
#endif
struct BlendShapeTrack {
int idx;
@ -88,6 +96,8 @@ protected:
Vector<Ref<Material>> materials;
void _mesh_changed();
#ifdef MODULE_SKELETON_3D_ENABLED
void _resolve_skeleton_path();
bool _is_software_skinning_enabled() const;
@ -95,6 +105,7 @@ protected:
void _initialize_skinning(bool p_force_reset = false, bool p_call_attach_skeleton = true);
void _update_skinning();
#endif
private:
// merging
@ -118,11 +129,13 @@ public:
void set_mesh(const Ref<Mesh> &p_mesh);
Ref<Mesh> get_mesh() const;
#ifdef MODULE_SKELETON_3D_ENABLED
void set_skin(const Ref<Skin> &p_skin);
Ref<Skin> get_skin() const;
void set_skeleton_path(const NodePath &p_skeleton);
NodePath get_skeleton_path();
#endif
int get_surface_material_count() const;
void set_surface_material(int p_surface, const Ref<Material> &p_material);

File diff suppressed because it is too large Load Diff

View File

@ -30,8 +30,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "core/object/reference.h"
#include "core/containers/vset.h"
#include "core/object/reference.h"
#include "scene/3d/collision_object.h"
#include "servers/physics_server.h"
@ -383,282 +383,4 @@ public:
~KinematicCollision();
};
class PhysicalBone : public PhysicsBody {
GDCLASS(PhysicalBone, PhysicsBody);
public:
enum JointType {
JOINT_TYPE_NONE,
JOINT_TYPE_PIN,
JOINT_TYPE_CONE,
JOINT_TYPE_HINGE,
JOINT_TYPE_SLIDER,
JOINT_TYPE_6DOF
};
struct JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_NONE; }
/// "j" is used to set the parameter inside the PhysicsServer
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
virtual ~JointData() {}
};
struct PinJointData : public JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_PIN; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
real_t bias;
real_t damping;
real_t impulse_clamp;
PinJointData() :
bias(0.3),
damping(1.),
impulse_clamp(0) {}
};
struct ConeJointData : public JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_CONE; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
real_t swing_span;
real_t twist_span;
real_t bias;
real_t softness;
real_t relaxation;
ConeJointData() :
swing_span(Math_PI * 0.25),
twist_span(Math_PI),
bias(0.3),
softness(0.8),
relaxation(1.) {}
};
struct HingeJointData : public JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_HINGE; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
bool angular_limit_enabled;
real_t angular_limit_upper;
real_t angular_limit_lower;
real_t angular_limit_bias;
real_t angular_limit_softness;
real_t angular_limit_relaxation;
HingeJointData() :
angular_limit_enabled(false),
angular_limit_upper(Math_PI * 0.5),
angular_limit_lower(-Math_PI * 0.5),
angular_limit_bias(0.3),
angular_limit_softness(0.9),
angular_limit_relaxation(1.) {}
};
struct SliderJointData : public JointData {
virtual JointType get_joint_type() { return JOINT_TYPE_SLIDER; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
real_t linear_limit_upper;
real_t linear_limit_lower;
real_t linear_limit_softness;
real_t linear_limit_restitution;
real_t linear_limit_damping;
real_t angular_limit_upper;
real_t angular_limit_lower;
real_t angular_limit_softness;
real_t angular_limit_restitution;
real_t angular_limit_damping;
SliderJointData() :
linear_limit_upper(1.),
linear_limit_lower(-1.),
linear_limit_softness(1.),
linear_limit_restitution(0.7),
linear_limit_damping(1.),
angular_limit_upper(0),
angular_limit_lower(0),
angular_limit_softness(1.),
angular_limit_restitution(0.7),
angular_limit_damping(1.) {}
};
struct SixDOFJointData : public JointData {
struct SixDOFAxisData {
bool linear_limit_enabled;
real_t linear_limit_upper;
real_t linear_limit_lower;
real_t linear_limit_softness;
real_t linear_restitution;
real_t linear_damping;
bool linear_spring_enabled;
real_t linear_spring_stiffness;
real_t linear_spring_damping;
real_t linear_equilibrium_point;
bool angular_limit_enabled;
real_t angular_limit_upper;
real_t angular_limit_lower;
real_t angular_limit_softness;
real_t angular_restitution;
real_t angular_damping;
real_t erp;
bool angular_spring_enabled;
real_t angular_spring_stiffness;
real_t angular_spring_damping;
real_t angular_equilibrium_point;
SixDOFAxisData() :
linear_limit_enabled(true),
linear_limit_upper(0),
linear_limit_lower(0),
linear_limit_softness(0.7),
linear_restitution(0.5),
linear_damping(1.),
linear_spring_enabled(false),
linear_spring_stiffness(0),
linear_spring_damping(0),
linear_equilibrium_point(0),
angular_limit_enabled(true),
angular_limit_upper(0),
angular_limit_lower(0),
angular_limit_softness(0.5),
angular_restitution(0),
angular_damping(1.),
erp(0.5),
angular_spring_enabled(false),
angular_spring_stiffness(0),
angular_spring_damping(0.),
angular_equilibrium_point(0) {}
};
virtual JointType get_joint_type() { return JOINT_TYPE_6DOF; }
virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
virtual bool _get(const StringName &p_name, Variant &r_ret) const;
virtual void _get_property_list(List<PropertyInfo> *p_list) const;
SixDOFAxisData axis_data[3];
SixDOFJointData() {}
};
private:
#ifdef TOOLS_ENABLED
// if false gizmo move body
bool gizmo_move_joint;
#endif
JointData *joint_data;
Transform joint_offset;
RID joint;
Skeleton *parent_skeleton;
Transform body_offset;
Transform body_offset_inverse;
bool simulate_physics;
bool _internal_simulate_physics;
int bone_id;
String bone_name;
real_t bounce;
real_t mass;
real_t friction;
real_t gravity_scale;
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
void _direct_state_changed(Object *p_state);
static void _bind_methods();
private:
static Skeleton *find_skeleton_parent(Node *p_parent);
void _fix_joint_offset();
void _reload_joint();
public:
void _on_bone_parent_changed();
void _set_gizmo_move_joint(bool p_move_joint);
public:
#ifdef TOOLS_ENABLED
virtual Transform get_global_gizmo_transform() const;
virtual Transform get_local_gizmo_transform() const;
#endif
const JointData *get_joint_data() const;
Skeleton *find_skeleton_parent();
int get_bone_id() const { return bone_id; }
void set_joint_type(JointType p_joint_type);
JointType get_joint_type() const;
void set_joint_offset(const Transform &p_offset);
const Transform &get_joint_offset() const;
void set_body_offset(const Transform &p_offset);
const Transform &get_body_offset() const;
void set_simulate_physics(bool p_simulate);
bool get_simulate_physics();
bool is_simulating_physics();
void set_bone_name(const String &p_name);
const String &get_bone_name() const;
void set_mass(real_t p_mass);
real_t get_mass() const;
void set_weight(real_t p_weight);
real_t get_weight() const;
void set_friction(real_t p_friction);
real_t get_friction() const;
void set_bounce(real_t p_bounce);
real_t get_bounce() const;
void set_gravity_scale(real_t p_gravity_scale);
real_t get_gravity_scale() const;
void apply_central_impulse(const Vector3 &p_impulse);
void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
void reset_physics_simulation_state();
void reset_to_rest_position();
PhysicalBone();
~PhysicalBone();
private:
void update_bone_id();
void update_offset();
void _start_physics_simulation();
void _stop_physics_simulation();
};
VARIANT_ENUM_CAST(PhysicalBone::JointType);
#endif // PHYSICS_BODY__H

View File

@ -35,7 +35,6 @@
#include "core/containers/rid.h"
#include "scene/3d/collision_object.h"
#include "scene/3d/physics_body.h"
#include "scene/3d/skeleton.h"
#include "scene/resources/mesh.h"
#include "scene/resources/world.h"
#include "servers/physics_server.h"

View File

@ -34,7 +34,7 @@
#include "scene/resources/world.h"
#include "scene/scene_string_names.h"
#include "servers/rendering_server.h"
#include "skeleton.h"
//#include "skeleton.h"
AABB VisualInstance::get_transformed_aabb() const {
return get_global_transform().xform(get_aabb());

View File

@ -30,8 +30,6 @@
#include "animation_blend_space_1d.h"
#include "scene/3d/skeleton.h"
void AnimationNodeBlendSpace1D::get_parameter_list(List<PropertyInfo> *r_list) const {
r_list->push_back(PropertyInfo(Variant::REAL, blend_position));
}

View File

@ -33,7 +33,6 @@
#include "core/config/engine.h"
#include "core/object/message_queue.h"
#include "scene/2d/node_2d.h"
#include "scene/3d/skeleton.h"
#include "scene/3d/spatial.h"
#include "scene/resources/animation.h"
#include "scene/scene_string_names.h"
@ -43,17 +42,21 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_2D_ENABLED
#include "modules/skeleton_2d/nodes/skeleton_2d.h"
#endif
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/nodes/skeleton.h"
#endif
void AnimatedValuesBackup::update_skeletons() {
for (int i = 0; i < entries.size(); i++) {
if (entries[i].bone_idx != -1) {
#ifdef MODULE_SKELETON_3D_ENABLED
// 3D bone
Object::cast_to<Skeleton>(entries[i].object)->notification(Skeleton::NOTIFICATION_UPDATE_SKELETON);
#endif
} else {
#ifdef MODULE_SKELETON_2D_ENABLED
Bone2D *bone = Object::cast_to<Bone2D>(entries[i].object);
@ -71,7 +74,9 @@ void AnimatedValuesBackup::restore() const {
const AnimatedValuesBackup::Entry *entry = &entries[i];
if (entry->bone_idx == -1) {
entry->object->set_indexed(entry->subpath, entry->value);
} else {
}
#ifdef MODULE_SKELETON_3D_ENABLED
else {
Array arr = entry->value;
if (arr.size() == 3) {
Object::cast_to<Skeleton>(entry->object)->set_bone_pose_position(entry->bone_idx, arr[0]);
@ -79,6 +84,7 @@ void AnimatedValuesBackup::restore() const {
Object::cast_to<Skeleton>(entry->object)->set_bone_pose_scale(entry->bone_idx, arr[2]);
}
}
#endif
}
}
@ -275,6 +281,7 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim, Node *p_root_ov
uint32_t id = resource.is_valid() ? resource->get_instance_id() : child->get_instance_id();
int bone_idx = -1;
#ifdef MODULE_SKELETON_3D_ENABLED
if (a->track_get_path(i).get_subname_count() == 1 && Object::cast_to<Skeleton>(child)) {
Skeleton *sk = Object::cast_to<Skeleton>(child);
bone_idx = sk->find_bone(a->track_get_path(i).get_subname(0));
@ -282,6 +289,7 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim, Node *p_root_ov
continue;
}
}
#endif
{
if (!child->is_connected("tree_exiting", this, "_node_removed")) {
@ -317,6 +325,8 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim, Node *p_root_ov
// cache spatial
node_cache->spatial = Object::cast_to<Spatial>(child);
#ifdef MODULE_SKELETON_3D_ENABLED
// cache skeleton
node_cache->skeleton = Object::cast_to<Skeleton>(child);
if (node_cache->skeleton) {
@ -339,6 +349,7 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim, Node *p_root_ov
node_cache->skeleton = nullptr;
}
}
#endif
switch (a->track_get_type(i)) {
case Animation::TYPE_POSITION_3D: {
@ -958,6 +969,7 @@ void AnimationPlayer::_animation_update_transforms() {
#ifndef _3D_DISABLED
#ifdef MODULE_SKELETON_3D_ENABLED
if (nc->skeleton && nc->bone_idx >= 0) {
if (nc->loc_used) {
nc->skeleton->set_bone_pose_position(nc->bone_idx, nc->loc_accum);
@ -969,7 +981,9 @@ void AnimationPlayer::_animation_update_transforms() {
nc->skeleton->set_bone_pose_scale(nc->bone_idx, nc->scale_accum);
}
} else if (nc->spatial) {
} else
#endif
if (nc->spatial) {
if (nc->loc_used) {
nc->spatial->set_translation(nc->loc_accum);
}
@ -1649,6 +1663,7 @@ Ref<AnimatedValuesBackup> AnimationPlayer::backup_animated_values(Node *p_root_o
continue;
}
#ifdef MODULE_SKELETON_3D_ENABLED
if (nc->skeleton) {
if (nc->bone_idx == -1) {
continue;
@ -1664,7 +1679,9 @@ Ref<AnimatedValuesBackup> AnimationPlayer::backup_animated_values(Node *p_root_o
entry.value = nc;
backup->entries.push_back(entry);
} else {
} else
#endif
{
if (nc->spatial) {
AnimatedValuesBackup::Entry entry;
entry.object = nc->spatial;

View File

@ -33,10 +33,14 @@
#include "core/object/reference.h"
#include "scene/main/node.h"
#include "modules/modules_enabled.gen.h"
class Resource;
class Spatial;
class Node2D;
#ifdef MODULE_SKELETON_3D_ENABLED
class Skeleton;
#endif
class Animation;
#ifdef TOOLS_ENABLED
@ -102,7 +106,9 @@ private:
Node *node;
Spatial *spatial;
Node2D *node_2d;
#ifdef MODULE_SKELETON_3D_ENABLED
Skeleton *skeleton;
#endif
int bone_idx;
// accumulated transforms

View File

@ -34,11 +34,14 @@
#include "animation_player.h"
#include "core/config/engine.h"
#include "core/object/method_bind_ext.gen.inc"
#include "scene/3d/skeleton.h"
#include "scene/3d/spatial.h"
#include "scene/scene_string_names.h"
#include "servers/audio/audio_stream.h"
#ifdef MODULE_SKELETON_3D_ENABLED
#include "modules/skeleton_3d/nodes/skeleton.h"
#endif
void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const {
if (get_script_instance()) {
Array parameters = get_script_instance()->call("get_parameter_list");
@ -626,10 +629,14 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
TrackCacheTransform *track_xform = memnew(TrackCacheTransform);
track_xform->spatial = spatial;
#ifdef MODULE_SKELETON_3D_ENABLED
track_xform->skeleton = nullptr;
track_xform->bone_idx = -1;
#endif
bool has_rest = false;
#ifdef MODULE_SKELETON_3D_ENABLED
if (path.get_subname_count() == 1 && Object::cast_to<Skeleton>(spatial)) {
Skeleton *sk = Object::cast_to<Skeleton>(spatial);
track_xform->skeleton = sk;
@ -644,6 +651,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
track_xform->init_scale = rest.basis.get_scale();
}
}
#endif
track_xform->object = spatial;
track_xform->object_id = track_xform->object->get_instance_id();
@ -1480,7 +1488,9 @@ void AnimationTree::_process_graph(float p_delta) {
xform.basis.set_quaternion_scale(t->rot, t->scale);
root_motion_transform = xform;
} else if (t->skeleton && t->bone_idx >= 0) {
}
#ifdef MODULE_SKELETON_3D_ENABLED
else if (t->skeleton && t->bone_idx >= 0) {
if (t->loc_used) {
t->skeleton->set_bone_pose_position(t->bone_idx, t->loc);
}
@ -1502,6 +1512,7 @@ void AnimationTree::_process_graph(float p_delta) {
t->spatial->set_scale(t->scale);
}
}
#endif
#endif // _3D_DISABLED
} break;
case Animation::TYPE_VALUE: {

View File

@ -34,8 +34,12 @@
#include "scene/main/node.h"
#include "scene/resources/animation.h"
#include "modules/modules_enabled.gen.h"
class Spatial;
#ifdef MODULE_SKELETON_3D_ENABLED
class Skeleton;
#endif
class AnimationNodeBlendTree;
class AnimationPlayer;
class AnimationTree;
@ -186,8 +190,10 @@ private:
struct TrackCacheTransform : public TrackCache {
Spatial *spatial;
#ifdef MODULE_SKELETON_3D_ENABLED
Skeleton *skeleton;
int bone_idx;
#endif
bool loc_used;
bool rot_used;
bool scale_used;

Some files were not shown because too many files have changed in this diff Show More