27 TypeHandle AnimChannelMatrixXfmTable::_type_handle;
32 AnimChannelMatrixXfmTable::
33 AnimChannelMatrixXfmTable() {
34 for (
int i = 0; i < num_matrix_components; i++) {
44 AnimChannelMatrixXfmTable::
48 for (
int i = 0; i < num_matrix_components; i++) {
49 _tables[i] = copy._tables[i];
56 AnimChannelMatrixXfmTable::
57 AnimChannelMatrixXfmTable(
AnimGroup *parent,
const std::string &name)
60 for (
int i = 0; i < num_matrix_components; i++) {
68 AnimChannelMatrixXfmTable::
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()];
170 get_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()];
186 get_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()];
204 get_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++) {
270 write(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) <<
"}";
311 int AnimChannelMatrixXfmTable::
312 get_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());
398 void 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);