Path: blob/master/scene/animation/animation_blend_space_2d.h
9896 views
/**************************************************************************/1/* animation_blend_space_2d.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/animation/animation_tree.h"3334class AnimationNodeBlendSpace2D : public AnimationRootNode {35GDCLASS(AnimationNodeBlendSpace2D, AnimationRootNode);3637public:38enum BlendMode {39BLEND_MODE_INTERPOLATED,40BLEND_MODE_DISCRETE,41BLEND_MODE_DISCRETE_CARRY,42};4344protected:45enum {46MAX_BLEND_POINTS = 6447};4849struct BlendPoint {50StringName name;51Ref<AnimationRootNode> node;52Vector2 position;53};5455BlendPoint blend_points[MAX_BLEND_POINTS];56int blend_points_used = 0;5758struct BlendTriangle {59int points[3] = {};60};6162Vector<BlendTriangle> triangles;6364StringName blend_position = "blend_position";65StringName closest = "closest";66Vector2 max_space = Vector2(1, 1);67Vector2 min_space = Vector2(-1, -1);68Vector2 snap = Vector2(0.1, 0.1);69String x_label = "x";70String y_label = "y";71BlendMode blend_mode = BLEND_MODE_INTERPOLATED;7273void _add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node);74void _set_triangles(const Vector<int> &p_triangles);75Vector<int> _get_triangles() const;7677void _blend_triangle(const Vector2 &p_pos, const Vector2 *p_points, float *r_weights);7879bool auto_triangles = true;80bool triangles_dirty = false;8182void _update_triangles();83void _queue_auto_triangles();8485bool sync = false;8687void _validate_property(PropertyInfo &p_property) const;88static void _bind_methods();8990virtual void _tree_changed() override;91virtual void _animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) override;92virtual void _animation_node_removed(const ObjectID &p_oid, const StringName &p_node) override;9394public:95virtual void get_parameter_list(List<PropertyInfo> *r_list) const override;96virtual Variant get_parameter_default_value(const StringName &p_parameter) const override;9798virtual void get_child_nodes(List<ChildNode> *r_child_nodes) override;99100void add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index = -1);101void set_blend_point_position(int p_point, const Vector2 &p_position);102void set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node);103Vector2 get_blend_point_position(int p_point) const;104Ref<AnimationRootNode> get_blend_point_node(int p_point) const;105void remove_blend_point(int p_point);106int get_blend_point_count() const;107108bool has_triangle(int p_x, int p_y, int p_z) const;109void add_triangle(int p_x, int p_y, int p_z, int p_at_index = -1);110int get_triangle_point(int p_triangle, int p_point);111void remove_triangle(int p_triangle);112int get_triangle_count() const;113114void set_min_space(const Vector2 &p_min);115Vector2 get_min_space() const;116117void set_max_space(const Vector2 &p_max);118Vector2 get_max_space() const;119120void set_snap(const Vector2 &p_snap);121Vector2 get_snap() const;122123void set_x_label(const String &p_label);124String get_x_label() const;125126void set_y_label(const String &p_label);127String get_y_label() const;128129virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override;130virtual String get_caption() const override;131132Vector2 get_closest_point(const Vector2 &p_point);133134void set_auto_triangles(bool p_enable);135bool get_auto_triangles() const;136137void set_blend_mode(BlendMode p_blend_mode);138BlendMode get_blend_mode() const;139140void set_use_sync(bool p_sync);141bool is_using_sync() const;142143virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name) const override;144145AnimationNodeBlendSpace2D();146~AnimationNodeBlendSpace2D();147};148149VARIANT_ENUM_CAST(AnimationNodeBlendSpace2D::BlendMode)150151152