41 _new_parent =
nullptr;
42 _has_rest_frame =
false;
43 _rest_frames_differ =
false;
53 if (back ==
nullptr) {
54 return LMatrix4d::ident_mat();
58 DCAST_INTO_R(joint, back, LMatrix4d::ident_mat());
60 return joint->get_frame(n);
70 if (back ==
nullptr) {
71 return LMatrix4d::ident_mat();
75 DCAST_INTO_R(joint, back, LMatrix4d::ident_mat());
78 if (!db.
get_matrix(joint, EggCharacterDb::TT_net_frame, n, mat)) {
81 if (_parent !=
nullptr) {
84 db.
set_matrix(joint, EggCharacterDb::TT_net_frame, n, mat);
96 if (back ==
nullptr) {
97 return LMatrix4d::ident_mat();
101 DCAST_INTO_R(joint, back, LMatrix4d::ident_mat());
104 if (!db.
get_matrix(joint, EggCharacterDb::TT_net_frame_inv, n, mat)) {
107 mat.invert_in_place();
108 db.
set_matrix(joint, EggCharacterDb::TT_net_frame_inv, n, mat);
126 for (
int model_index = 0; model_index < num_models; model_index++) {
129 DCAST_INTO_V(joint,
get_model(model_index));
130 if (joint->
is_of_type(EggJointNodePointer::get_class_type())) {
135 _rest_frames_differ =
false;
146 if (new_owner ==
nullptr) {
147 for (
int model_index = 0; model_index < num_models; model_index++) {
150 DCAST_INTO_V(joint,
get_model(model_index));
155 for (
int model_index = 0; model_index < num_models; model_index++) {
158 DCAST_INTO_V(joint,
get_model(model_index));
159 DCAST_INTO_V(new_joint, new_owner->
get_model(model_index));
184 vector_stdfloat i, j, k, a, b, c, x, y, z;
189 for (
int model_index = 0; model_index < num_models; model_index++) {
191 if (back !=
nullptr) {
193 DCAST_INTO_R(joint, back,
false);
196 for (
int n = 0; n < num_frames; n++) {
198 if (_parent == new_parent) {
200 transform = LMatrix4d::ident_mat();
202 }
else if (_parent ==
nullptr) {
206 }
else if (new_parent ==
nullptr) {
217 transform = joint->get_frame(n) * transform;
218 LVecBase3d scale, shear, hpr, translate;
219 if (!decompose_matrix(transform, scale, shear, hpr, translate)) {
223 i.push_back(scale[0]);
224 j.push_back(scale[1]);
225 k.push_back(scale[2]);
226 a.push_back(shear[0]);
227 b.push_back(shear[1]);
228 c.push_back(shear[2]);
229 hprs.push_back(LCAST(PN_stdfloat, hpr));
230 x.push_back(translate[0]);
231 y.push_back(translate[1]);
232 z.push_back(translate[2]);
254 compressor.
write_hprs(dg, &hprs[0], num_rows);
266 std::ostringstream sstr;
267 OCompressStream zstr(&sstr,
false);
270 return sstr.str().length();
282 BackPointers::iterator bpi;
283 for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) {
285 if (back !=
nullptr) {
287 DCAST_INTO_R(joint, back,
false);
294 Children::iterator ci;
295 for (ci = _children.begin(); ci != _children.end(); ++ci) {
311 BackPointers::iterator bpi;
312 for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) {
314 if (back !=
nullptr) {
316 DCAST_INTO_V(joint, back);
321 Children::iterator ci;
322 for (ci = _children.begin(); ci != _children.end(); ++ci) {
334 BackPointers::iterator bpi;
335 for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) {
337 if (back !=
nullptr) {
339 DCAST_INTO_V(joint, back);
351 BackPointers::iterator bpi;
352 for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) {
354 if (back !=
nullptr) {
356 DCAST_INTO_V(joint, back);
368 BackPointers::iterator bpi;
369 for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) {
371 if (back !=
nullptr) {
373 DCAST_INTO_V(joint, back);
378 Children::iterator ci;
379 for (ci = _children.begin(); ci != _children.end(); ++ci) {
394 DCAST_INTO_V(source_joint, _back_pointers[source_model]);
395 BackPointers::iterator bpi;
396 for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) {
398 if (back !=
nullptr) {
400 DCAST_INTO_V(joint, back);
406 Children::iterator ci;
407 for (ci = _children.begin(); ci != _children.end(); ++ci) {
418 nassertv(egg_object !=
nullptr);
419 if (egg_object->
is_of_type(EggGroup::get_class_type())) {
423 if (!_has_rest_frame) {
425 _has_rest_frame =
true;
430 if (!_rest_frame.almost_equal(joint->
get_frame(0), 0.0001)) {
431 _rest_frames_differ =
true;
435 }
else if (egg_object->
is_of_type(EggTable::get_class_type())) {
441 nout <<
"Invalid object added to joint for back pointer.\n";
449 write(std::ostream &out,
int indent_level)
const {
451 <<
"Joint " << get_name()
454 for (
int model_index = 0; model_index < num_models; model_index++) {
456 out <<
" " << model_index;
461 Children::const_iterator ci;
462 for (ci = _children.begin(); ci != _children.end(); ++ci) {
463 (*ci)->write(out, indent_level + 2);
466 indent(out, indent_level) <<
"}\n";
474 do_begin_reparent() {
475 _got_new_parent_depth =
false;
492 if (_got_new_parent_depth) {
495 if (_new_parent ==
nullptr) {
497 _got_new_parent_depth =
true;
498 _new_parent_depth = 0;
501 if (!chain.insert(
this).second) {
505 bool cycle = _new_parent->calc_new_parent_depth(chain);
506 _new_parent_depth = _new_parent->_new_parent_depth + 1;
515 do_begin_compute_reparent() {
516 _got_new_net_frame =
false;
517 _got_new_net_frame_inv =
false;
518 _computed_reparent =
false;
528 if (_computed_reparent) {
534 _computed_reparent =
true;
536 if (_parent == _new_parent) {
544 if (back ==
nullptr) {
551 DCAST_INTO_R(joint, back,
false);
554 if (_parent ==
nullptr) {
556 transform = _new_parent->get_new_net_frame_inv(model_index, n, db);
558 }
else if (_new_parent ==
nullptr) {
566 _new_parent->get_new_net_frame_inv(model_index, n, db);
569 db.
set_matrix(joint, EggCharacterDb::TT_rebuild_frame, n,
570 joint->get_frame(n) * transform);
585 if (_new_parent !=
nullptr && _new_parent->
has_model(model_index)) {
586 DCAST_INTO_R(parent_joint, _new_parent->
get_model(model_index),
false);
591 DCAST_INTO_R(joint,
get_model(model_index),
false);
605 do_finish_reparent() {
607 for (
int model_index = 0; model_index < num_models; model_index++) {
609 if (_new_parent !=
nullptr && _new_parent->
has_model(model_index)) {
610 DCAST_INTO_V(parent_joint, _new_parent->
get_model(model_index));
615 DCAST_INTO_V(joint,
get_model(model_index));
616 joint->do_finish_reparent(parent_joint);
620 _parent = _new_parent;
621 if (_parent !=
nullptr) {
622 _parent->_children.push_back(
this);
631 make_new_joint(
const string &name) {
633 child->set_name(name);
634 child->_parent =
this;
635 child->_new_parent =
this;
636 _children.push_back(child);
640 for (
int i = 0; i < num_models; i++) {
643 DCAST_INTO_R(joint,
get_model(i),
nullptr);
657 find_joint_exact(
const string &name) {
658 Children::const_iterator ci;
659 for (ci = _children.begin(); ci != _children.end(); ++ci) {
661 if (child->get_name() == name) {
665 if (result !=
nullptr) {
678 find_joint_matches(
const string &name) {
679 Children::const_iterator ci;
680 for (ci = _children.begin(); ci != _children.end(); ++ci) {
686 if (result !=
nullptr) {
705 if (child->_new_parent ==
nullptr) {
709 return is_new_ancestor(child->_new_parent);
717 const LMatrix4d &EggJointData::
719 if (!_got_new_net_frame) {
720 _new_net_frame = get_new_frame(model_index, n, db);
721 if (_new_parent !=
nullptr) {
722 _new_net_frame = _new_net_frame * _new_parent->get_new_net_frame(model_index, n, db);
724 _got_new_net_frame =
true;
726 return _new_net_frame;
732 const LMatrix4d &EggJointData::
733 get_new_net_frame_inv(
int model_index,
int n,
EggCharacterDb &db) {
734 if (!_got_new_net_frame_inv) {
735 _new_net_frame_inv.invert_from(get_new_frame(model_index, n, db));
736 if (_new_parent !=
nullptr) {
737 _new_net_frame_inv = _new_parent->get_new_net_frame_inv(model_index, n, db) * _new_net_frame_inv;
739 _got_new_net_frame_inv =
true;
741 return _new_net_frame_inv;
749 LMatrix4d EggJointData::
751 do_compute_reparent(model_index, n, db);
754 if (back ==
nullptr) {
755 return LMatrix4d::ident_mat();
759 DCAST_INTO_R(joint, back, LMatrix4d::ident_mat());
762 if (!db.
get_matrix(joint, EggCharacterDb::TT_rebuild_frame, n, mat)) {
764 return joint->get_frame(n);