27TypeHandle AnimChannelMatrixXfmTable::_type_handle;
32AnimChannelMatrixXfmTable::
33AnimChannelMatrixXfmTable() {
34 for (
int i = 0; i < num_matrix_components; i++) {
44AnimChannelMatrixXfmTable::
48 for (
int i = 0; i < num_matrix_components; i++) {
49 _tables[i] = copy._tables[i];
56AnimChannelMatrixXfmTable::
57AnimChannelMatrixXfmTable(
AnimGroup *parent,
const std::string &name)
60 for (
int i = 0; i < num_matrix_components; i++) {
68AnimChannelMatrixXfmTable::
69~AnimChannelMatrixXfmTable() {
80 int this_frame,
double this_frac) {
81 if (last_frame != this_frame) {
82 for (
int i = 0; i < num_matrix_components; i++) {
83 if (_tables[i].size() > 1) {
84 if (_tables[i][last_frame % _tables[i].size()] !=
85 _tables[i][this_frame % _tables[i].size()]) {
92 if (last_frac != this_frac) {
95 for (
int i = 0; i < num_matrix_components; i++) {
96 if (_tables[i].size() > 1) {
97 if (_tables[i][last_frame % _tables[i].size()] !=
98 _tables[i][(this_frame + 1) % _tables[i].size()]) {
113 PN_stdfloat components[num_matrix_components];
115 for (
int i = 0; i < num_matrix_components; i++) {
116 if (_tables[i].empty()) {
117 components[i] = get_default_value(i);
119 components[i] = _tables[i][frame % _tables[i].size()];
123 compose_matrix(mat, components);
132 PN_stdfloat components[num_matrix_components];
133 components[0] = 1.0f;
134 components[1] = 1.0f;
135 components[2] = 1.0f;
136 components[3] = 0.0f;
137 components[4] = 0.0f;
138 components[5] = 0.0f;
140 for (
int i = 6; i < num_matrix_components; i++) {
141 if (_tables[i].empty()) {
142 components[i] = get_default_value(i);
144 components[i] = _tables[i][frame % _tables[i].size()];
148 compose_matrix(mat, components);
156 for (
int i = 0; i < 3; i++) {
157 if (_tables[i].empty()) {
160 scale[i] = _tables[i][frame % _tables[i].size()];
170get_hpr(
int frame, LVecBase3 &hpr) {
171 for (
int i = 0; i < 3; i++) {
172 if (_tables[i + 6].empty()) {
175 hpr[i] = _tables[i + 6][frame % _tables[i + 6].size()];
186get_quat(
int frame, LQuaternion &quat) {
188 for (
int i = 0; i < 3; i++) {
189 if (_tables[i + 6].empty()) {
192 hpr[i] = _tables[i + 6][frame % _tables[i + 6].size()];
204get_pos(
int frame, LVecBase3 &pos) {
205 for (
int i = 0; i < 3; i++) {
206 if (_tables[i + 9].empty()) {
209 pos[i] = _tables[i + 9][frame % _tables[i + 9].size()];
220 for (
int i = 0; i < 3; i++) {
221 if (_tables[i + 3].empty()) {
224 shear[i] = _tables[i + 3][frame % _tables[i + 3].size()];
237 int num_frames = _root->get_num_frames();
239 if (table.size() > 1 && (
int)table.size() < num_frames) {
242 nassert_raise(
"mismatched number of frames");
246 int i = get_table_index(table_id);
261 for (
int i = 0; i < num_matrix_components; i++) {
270write(std::ostream &out,
int indent_level)
const {
272 << get_type() <<
" " << get_name() <<
" ";
275 bool found_any =
false;
276 for (
int i = 0; i < num_matrix_components; i++) {
277 if (!_tables[i].empty()) {
278 out << get_table_id(i) << _tables[i].size();
287 if (!_children.empty()) {
289 write_descendants(out, indent_level + 2);
290 indent(out, indent_level) <<
"}";
311int AnimChannelMatrixXfmTable::
312get_table_index(
char table_id) {
313 for (
int i = 0; i < num_matrix_components; i++) {
314 if (table_id == get_table_id(i)) {
330 if (compress_channels) {
332 <<
"FFT compression of animations is deprecated. For compatibility "
333 "with future versions of Panda3D, set compress-channels to false.\n";
337 <<
"Compression is not available; writing uncompressed channels.\n";
338 compress_channels =
false;
347 if (!compress_channels) {
349 for (
int i = 0; i < num_matrix_components; i++) {
351 for(
int j = 0; j < (int)_tables[i].size(); j++) {
365 for (i = 0; i < 6; i++) {
366 compressor.
write_reals(me, _tables[i], _tables[i].size());
372 int hprs_length = std::max(std::max(_tables[6].size(), _tables[7].size()), _tables[8].size());
373 hprs.reserve(hprs_length);
374 for (i = 0; i < hprs_length; i++) {
375 PN_stdfloat h = _tables[6].empty() ? 0.0f : _tables[6][i % _tables[6].size()];
376 PN_stdfloat p = _tables[7].empty() ? 0.0f : _tables[7][i % _tables[7].size()];
377 PN_stdfloat r = _tables[8].empty() ? 0.0f : _tables[8][i % _tables[8].size()];
378 hprs.push_back(LVecBase3(h, p, r));
380 const LVecBase3 *hprs_array =
nullptr;
381 if (hprs_length != 0) {
382 hprs_array = &hprs[0];
384 compressor.
write_hprs(me, hprs_array, hprs_length);
387 for(i = 9; i < num_matrix_components; i++) {
388 compressor.
write_reals(me, _tables[i], _tables[i].size());
398void AnimChannelMatrixXfmTable::
400 AnimChannelMatrix::fillin(scan, manager);
402 bool wrote_compressed = scan.
get_bool();
408 if (!wrote_compressed) {
411 for (
int i = 0; i < num_matrix_components; i++) {
413 PTA_stdfloat ind_table(get_class_type());
414 for (
int j = 0; j < size; j++) {
417 _tables[i] = ind_table;
422 size_t num_hprs = std::max(std::max(_tables[6].size(), _tables[7].size()),
425 LVecBase3 default_hpr(0.0, 0.0, 0.0);
426 if (!_tables[6].empty()) {
427 default_hpr[0] = _tables[6][0];
429 if (!_tables[7].empty()) {
430 default_hpr[1] = _tables[7][0];
432 if (!_tables[8].empty()) {
433 default_hpr[2] = _tables[8][0];
436 PTA_stdfloat h_table = PTA_stdfloat::empty_array(num_hprs, get_class_type());
437 PTA_stdfloat p_table = PTA_stdfloat::empty_array(num_hprs, get_class_type());
438 PTA_stdfloat r_table = PTA_stdfloat::empty_array(num_hprs, get_class_type());
440 for (
size_t hi = 0; hi < num_hprs; hi++) {
441 PN_stdfloat h = (hi < _tables[6].size() ? _tables[6][hi] : default_hpr[0]);
442 PN_stdfloat p = (hi < _tables[7].size() ? _tables[7][hi] : default_hpr[1]);
443 PN_stdfloat r = (hi < _tables[8].size() ? _tables[8][hi] : default_hpr[2]);
445 LVecBase3 hpr = old_to_new_hpr(LVecBase3(h, p, r));
446 h_table[hi] = hpr[0];
447 p_table[hi] = hpr[1];
448 r_table[hi] = hpr[2];
450 _tables[6] = h_table;
451 _tables[7] = p_table;
452 _tables[8] = r_table;
457 if (!read_compressed_channels) {
459 <<
"Not reading compressed animation channels.\n";
469 for (i = 0; i < 6; i++) {
470 PTA_stdfloat ind_table = PTA_stdfloat::empty_array(0, get_class_type());
472 _tables[i] = ind_table;
477 compressor.
read_hprs(scan, hprs, new_hpr);
478 PTA_stdfloat h_table = PTA_stdfloat::empty_array(hprs.size(), get_class_type());
479 PTA_stdfloat p_table = PTA_stdfloat::empty_array(hprs.size(), get_class_type());
480 PTA_stdfloat r_table = PTA_stdfloat::empty_array(hprs.size(), get_class_type());
482 for (i = 0; i < (int)hprs.size(); i++) {
485 LVecBase3 hpr = old_to_new_hpr(hprs[i]);
492 h_table[i] = hprs[i][0];
493 p_table[i] = hprs[i][1];
494 r_table[i] = hprs[i][2];
497 _tables[6] = h_table;
498 _tables[7] = p_table;
499 _tables[8] = r_table;
502 for (i = 9; i < num_matrix_components; i++) {
503 PTA_stdfloat ind_table = PTA_stdfloat::empty_array(0, get_class_type());
505 _tables[i] = ind_table;
520 me->fillin(scan, manager);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
An animation channel that issues a matrix each frame, read from a table such as might have been read ...
virtual void get_value_no_scale_shear(int frame, LMatrix4 &value)
Gets the value of the channel at the indicated frame, without any scale or shear information.
set_table
Assigns the indicated table.
static void register_with_read_factory()
Factory method to generate an AnimChannelMatrixXfmTable object.
virtual void get_quat(int frame, LQuaternion &quat)
Returns the rotation component associated with the current frame, expressed as a quaternion.
void clear_all_tables()
Removes all the tables from the channel, and resets it to its initial state.
static TypedWritable * make_AnimChannelMatrixXfmTable(const FactoryParams ¶ms)
Factory method to generate an AnimChannelMatrixXfmTable object.
virtual void get_scale(int frame, LVecBase3 &scale)
Gets the scale value at the indicated frame.
virtual void get_hpr(int frame, LVecBase3 &hpr)
Returns the h, p, and r components associated with the current frame.
virtual void get_pos(int frame, LVecBase3 &pos)
Returns the x, y, and z translation components associated with the current frame.
virtual bool has_changed(int last_frame, double last_frac, int this_frame, double this_frac)
Returns true if the value has changed since the last call to has_changed().
virtual void get_value(int frame, LMatrix4 &mat)
Gets the value of the channel at the indicated frame.
virtual void write(std::ostream &out, int indent_level) const
Writes a brief description of the table and all of its descendants.
virtual void get_shear(int frame, LVecBase3 &shear)
Returns the a, b, and c shear components associated with the current frame.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
This is the base class for AnimChannel and AnimBundle.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Similar to PointerToArray, except that its contents may not be modified.
A class to retrieve the individual data elements previously stored in a Datagram.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
bool get_bool()
Extracts a boolean value.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void add_bool(bool value)
Adds a boolean value to the datagram.
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
This class manages a lossy compression and decompression of a stream of floating-point numbers to a d...
bool read_reals(DatagramIterator &di, vector_stdfloat &array)
Reads an array of floating-point numbers.
void set_use_error_threshold(bool use_error_threshold)
Enables or disables the use of the error threshold measurement to put a cap on the amount of damage d...
bool read_hprs(DatagramIterator &di, pvector< LVecBase3 > &array, bool new_hpr)
Reads an array of HPR angles.
void set_quality(int quality)
Sets the quality factor for the compression.
bool read_header(DatagramIterator &di, int bam_minor_version)
Reads the compression header that was written previously.
static bool is_compression_available()
Returns true if the FFTW library is compiled in, so that this class is actually capable of doing usef...
void write_header(Datagram &datagram)
Writes the compression parameters to the indicated datagram.
void write_reals(Datagram &datagram, const PN_stdfloat *array, int length)
Writes an array of floating-point numbers to the indicated datagram.
void write_hprs(Datagram &datagram, const LVecBase3 *array, int length)
Writes an array of HPR angles to the indicated datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
This is our own Panda specialization on the default STL vector.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.