Path: blob/master/scene/3d/bone_twist_disperser_3d.h
22205 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"33#include "scene/resources/curve.h"3435class BoneTwistDisperser3D : public SkeletonModifier3D {36GDCLASS(BoneTwistDisperser3D, SkeletonModifier3D);3738bool mutable_bone_axes = true;3940public:41enum DisperseMode {42DISPERSE_MODE_EVEN,43DISPERSE_MODE_WEIGHTED,44DISPERSE_MODE_CUSTOM,45};4647struct BoneJoint {48StringName name;49int bone = -1;50};5152struct DisperseJointSetting {53BoneJoint joint;54double custom_amount = 1.0;55// For processing.56double amount = 1.0;57Vector3 axis;58};5960struct BoneTwistDisperser3DSetting {61bool joints_dirty = false;6263DisperseMode disperse_mode = DISPERSE_MODE_EVEN;64bool twist_from_rest = true;65Quaternion twist_from;6667BoneJoint root_bone;68BoneJoint end_bone;69LocalVector<DisperseJointSetting> joints;7071bool extend_end_bone = false;72BoneDirection end_bone_direction = BONE_DIRECTION_FROM_PARENT;7374float weight_position = 0.5;75Ref<Curve> damping_curve;7677BoneJoint reference_bone; // To cache.7879~BoneTwistDisperser3DSetting() {80joints.clear();81damping_curve.unref();82}83};8485protected:86LocalVector<BoneTwistDisperser3DSetting *> settings;8788bool _get(const StringName &p_path, Variant &r_ret) const;89bool _set(const StringName &p_path, const Variant &p_value);90void _get_property_list(List<PropertyInfo> *p_list) const;91void _validate_dynamic_prop(PropertyInfo &p_property) const;9293void _notification(int p_what);94static void _bind_methods();9596virtual void _set_active(bool p_active) override;97virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) override;98virtual void _validate_bone_names() override;99100void _make_all_joints_dirty();101102void _make_joints_dirty(int p_index);103void _update_joints(int p_index);104void _set_joint_bone(int p_index, int p_joint, int p_bone);105106void _update_reference_bone(int p_index);107void _update_curve(int p_index);108109virtual void _process_modification(double p_delta) override;110111public:112void set_mutable_bone_axes(bool p_enabled);113bool are_bone_axes_mutable() const;114115int get_setting_count() const;116void set_setting_count(int p_count);117void clear_settings();118119// Setting.120void set_root_bone_name(int p_index, const String &p_bone_name);121String get_root_bone_name(int p_index) const;122void set_root_bone(int p_index, int p_bone);123int get_root_bone(int p_index) const;124125void set_end_bone_name(int p_index, const String &p_bone_name);126String get_end_bone_name(int p_index) const;127void set_end_bone(int p_index, int p_bone);128int get_end_bone(int p_index) const;129130void set_extend_end_bone(int p_index, bool p_enabled);131bool is_end_bone_extended(int p_index) const;132void set_end_bone_direction(int p_index, BoneDirection p_bone_direction);133BoneDirection get_end_bone_direction(int p_index) const;134135void set_twist_from_rest(int p_index, bool p_enabled);136bool is_twist_from_rest(int p_index) const;137void set_twist_from(int p_index, const Quaternion &p_from);138Quaternion get_twist_from(int p_index) const;139140String get_reference_bone_name(int p_index) const;141int get_reference_bone(int p_index) const;142143void set_disperse_mode(int p_index, DisperseMode p_disperse_mode);144DisperseMode get_disperse_mode(int p_index) const;145void set_weight_position(int p_index, float p_position);146float get_weight_position(int p_index) const;147void set_damping_curve(int p_index, const Ref<Curve> &p_damping_curve);148Ref<Curve> get_damping_curve(int p_index) const;149150// Individual joints.151String get_joint_bone_name(int p_index, int p_joint) const;152int get_joint_bone(int p_index, int p_joint) const;153154void set_joint_twist_amount(int p_index, int p_joint, float p_amount);155float get_joint_twist_amount(int p_index, int p_joint) const;156157void set_joint_count(int p_index, int p_count);158int get_joint_count(int p_index) const;159160~BoneTwistDisperser3D();161};162163VARIANT_ENUM_CAST(BoneTwistDisperser3D::DisperseMode);164165166