Blender  V2.93
BCAnimationCurve.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
22 #include "BCSampleData.h"
23 #include "collada_utils.h"
24 
25 #include "MEM_guardedalloc.h"
26 
27 #include "BKE_armature.h"
28 #include "BKE_fcurve.h"
29 #include "BKE_material.h"
30 
31 #include "ED_anim_api.h"
32 #include "ED_keyframes_edit.h"
33 #include "ED_keyframing.h"
34 
35 typedef float(TangentPoint)[2];
36 
37 typedef std::set<float> BCFrameSet;
38 typedef std::vector<float> BCFrames;
39 typedef std::vector<float> BCValues;
40 typedef std::vector<float> BCTimes;
41 typedef std::map<int, float> BCValueMap;
42 
43 typedef enum BC_animation_type {
50 
51 class BCCurveKey {
52  private:
53  BC_animation_type key_type;
54  std::string rna_path;
55  int curve_array_index;
56  int curve_subindex; /* only needed for materials */
57 
58  public:
59  BCCurveKey();
61  const std::string path,
62  const int array_index,
63  const int subindex = -1);
64  void operator=(const BCCurveKey &other);
65  std::string get_full_path() const;
66  std::string get_path() const;
67  int get_array_index() const;
68  int get_subindex() const;
69  void set_object_type(BC_animation_type object_type);
71  bool operator<(const BCCurveKey &other) const;
72 };
73 
74 class BCBezTriple {
75  public:
77 
79  float get_frame() const;
80  float get_time(Scene *scene) const;
81  float get_value() const;
82  float get_angle() const;
83  void get_in_tangent(Scene *scene, float point[2], bool as_angle) const;
84  void get_out_tangent(Scene *scene, float point[2], bool as_angle) const;
85  void get_tangent(Scene *scene, float point[2], bool as_angle, int index) const;
86 };
87 
89  private:
90  BCCurveKey curve_key;
91  float min = 0;
92  float max = 0;
93 
94  bool curve_is_local_copy = false;
95  FCurve *fcurve;
96  PointerRNA id_ptr;
97  void init_pointer_rna(Object *ob);
98  void delete_fcurve(FCurve *fcu);
99  FCurve *create_fcurve(int array_index, const char *rna_path);
100  void create_bezt(float frame, float output);
101  void update_range(float val);
102  void init_range(float val);
103 
104  public:
106  BCAnimationCurve(const BCAnimationCurve &other);
107  BCAnimationCurve(const BCCurveKey &key, Object *ob);
108  BCAnimationCurve(BCCurveKey key, Object *ob, FCurve *fcu);
110 
112  int get_interpolation_type(float sample_frame) const;
113  bool is_animated();
114  bool is_transform_curve() const;
115  bool is_rotation_curve() const;
116  bool is_keyframe(int frame);
117  void adjust_range(int frame);
118 
119  std::string get_animation_name(Object *ob) const; /* xxx: this is collada specific */
120  std::string get_channel_target() const;
121  std::string get_channel_type() const;
122  std::string get_channel_posebone() const; /* returns "" if channel is not a bone channel */
123 
124  int get_channel_index() const;
125  int get_subindex() const;
126  std::string get_rna_path() const;
127  FCurve *get_fcurve() const;
128  int sample_count() const;
129 
130  float get_value(const float frame);
131  void get_values(BCValues &values) const;
132  void get_value_map(BCValueMap &value_map);
133 
134  void get_frames(BCFrames &frames) const;
135 
136  /* Curve edit functions create a copy of the underlying #FCurve. */
138  bool add_value_from_rna(const int frame);
139  bool add_value_from_matrix(const BCSample &sample, const int frame);
140  void add_value(const float val, const int frame);
141  void clean_handles();
142 
143  /* experimental stuff */
144  int closest_index_above(const float sample_frame, const int start_at) const;
145  int closest_index_below(const float sample_frame) const;
146 };
147 
148 typedef std::map<BCCurveKey, BCAnimationCurve *> BCAnimationCurveMap;
std::vector< float > BCValues
typedef float(TangentPoint)[2]
std::vector< float > BCTimes
std::map< int, float > BCValueMap
BC_animation_type
@ BC_ANIMATION_TYPE_MATERIAL
@ BC_ANIMATION_TYPE_LIGHT
@ BC_ANIMATION_TYPE_OBJECT
@ BC_ANIMATION_TYPE_BONE
@ BC_ANIMATION_TYPE_CAMERA
std::map< BCCurveKey, BCAnimationCurve * > BCAnimationCurveMap
std::vector< float > BCFrames
std::set< float > BCFrameSet
General operations, lookup, etc. for materials.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
#define output
std::string get_rna_path() const
FCurve * get_edit_fcurve()
FCurve * get_fcurve() const
int closest_index_below(const float sample_frame) const
bool add_value_from_matrix(const BCSample &sample, const int frame)
float get_value(const float frame)
void get_values(BCValues &values) const
std::string get_channel_type() const
void adjust_range(int frame)
bool is_rotation_curve() const
void get_value_map(BCValueMap &value_map)
bool is_keyframe(int frame)
int get_interpolation_type(float sample_frame) const
bool is_of_animation_type(BC_animation_type type) const
void get_frames(BCFrames &frames) const
bool is_transform_curve() const
std::string get_channel_posebone() const
bool add_value_from_rna(const int frame)
int get_subindex() const
int sample_count() const
std::string get_channel_target() const
void add_value(const float val, const int frame)
int get_channel_index() const
std::string get_animation_name(Object *ob) const
int closest_index_above(const float sample_frame, const int start_at) const
void get_tangent(Scene *scene, float point[2], bool as_angle, int index) const
float get_frame() const
BezTriple & bezt
BCBezTriple(BezTriple &bezt)
float get_time(Scene *scene) const
void get_out_tangent(Scene *scene, float point[2], bool as_angle) const
void get_in_tangent(Scene *scene, float point[2], bool as_angle) const
float get_value() const
float get_angle() const
std::string get_path() const
int get_subindex() const
std::string get_full_path() const
void set_object_type(BC_animation_type object_type)
int get_array_index() const
void operator=(const BCCurveKey &other)
BC_animation_type get_animation_type() const
bool operator<(const BCCurveKey &other) const
Scene scene
static void sample(SocketReader *reader, int x, int y, float color[4])