Path: blob/master/scene/3d/bone_twist_disperser_3d.h
14709 views
/**************************************************************************/1/* bone_twist_disperser_3d.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/3d/skeleton_modifier_3d.h"3334class BoneTwistDisperser3D : public SkeletonModifier3D {35GDCLASS(BoneTwistDisperser3D, SkeletonModifier3D);3637bool mutable_bone_axes = true;3839public:40enum DisperseMode {41DISPERSE_MODE_EVEN,42DISPERSE_MODE_WEIGHTED,43DISPERSE_MODE_CUSTOM,44};4546struct BoneJoint {47StringName name;48int bone = -1;49};5051struct DisperseJointSetting {52BoneJoint joint;53double custom_amount = 1.0;54// For processing.55double amount = 1.0;56Vector3 axis;57};5859struct BoneTwistDisperser3DSetting {60bool joints_dirty = false;6162DisperseMode disperse_mode = DISPERSE_MODE_EVEN;63bool twist_from_rest = true;64Quaternion twist_from;6566BoneJoint root_bone;67BoneJoint end_bone;68LocalVector<DisperseJointSetting> joints;6970bool extend_end_bone = false;71BoneDirection end_bone_direction = BONE_DIRECTION_FROM_PARENT;7273float weight_position = 0.5;74Ref<Curve> damping_curve;7576BoneJoint reference_bone; // To cache.7778~BoneTwistDisperser3DSetting() {79joints.clear();80damping_curve.unref();81}82};8384protected:85LocalVector<BoneTwistDisperser3DSetting *> settings;8687bool _get(const StringName &p_path, Variant &r_ret) const;88bool _set(const StringName &p_path, const Variant &p_value);89void _get_property_list(List<PropertyInfo> *p_list) const;90void _validate_dynamic_prop(PropertyInfo &p_property) const;9192void _notification(int p_what);93static void _bind_methods();9495virtual void _set_active(bool p_active) override;96virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) override;97virtual void _validate_bone_names() override;9899void _make_all_joints_dirty();100101void _make_joints_dirty(int p_index);102void _update_joints(int p_index);103void _update_reference_bone(int p_index);104void _update_curve(int p_index);105106virtual void _process_modification(double p_delta) override;107108public:109void set_mutable_bone_axes(bool p_enabled);110bool are_bone_axes_mutable() const;111112int get_setting_count() const;113void set_setting_count(int p_count);114void clear_settings();115116// Setting.117void set_root_bone_name(int p_index, const String &p_bone_name);118String get_root_bone_name(int p_index) const;119void set_root_bone(int p_index, int p_bone);120int get_root_bone(int p_index) const;121122void set_end_bone_name(int p_index, const String &p_bone_name);123String get_end_bone_name(int p_index) const;124void set_end_bone(int p_index, int p_bone);125int get_end_bone(int p_index) const;126127void set_extend_end_bone(int p_index, bool p_enabled);128bool is_end_bone_extended(int p_index) const;129void set_end_bone_direction(int p_index, BoneDirection p_bone_direction);130BoneDirection get_end_bone_direction(int p_index) const;131132void set_twist_from_rest(int p_index, bool p_enabled);133bool is_twist_from_rest(int p_index) const;134void set_twist_from(int p_index, const Quaternion &p_from);135Quaternion get_twist_from(int p_index) const;136137String get_reference_bone_name(int p_index) const;138int get_reference_bone(int p_index) const;139140void set_disperse_mode(int p_index, DisperseMode p_disperse_mode);141DisperseMode get_disperse_mode(int p_index) const;142void set_weight_position(int p_index, float p_position);143float get_weight_position(int p_index) const;144void set_damping_curve(int p_index, const Ref<Curve> &p_damping_curve);145Ref<Curve> get_damping_curve(int p_index) const;146147// Individual joints.148void set_joint_bone_name(int p_index, int p_joint, const String &p_bone_name);149String get_joint_bone_name(int p_index, int p_joint) const;150void set_joint_bone(int p_index, int p_joint, int p_bone);151int get_joint_bone(int p_index, int p_joint) const;152153void set_joint_twist_amount(int p_index, int p_joint, float p_amount);154float get_joint_twist_amount(int p_index, int p_joint) const;155156void set_joint_count(int p_index, int p_count);157int get_joint_count(int p_index) const;158159~BoneTwistDisperser3D();160};161162VARIANT_ENUM_CAST(BoneTwistDisperser3D::DisperseMode);163164165