24 #include <FCDocument/FCDocument.h> 25 #include <FCDocument/FCDController.h> 26 #include <FCDocument/FCDGeometry.h> 27 #include <FCDocument/FCDSceneNodeTools.h> 29 #include <FCDocument/FCDSceneNode.h> 30 #include <FCDocument/FCDTransform.h> 31 #include <FCDocument/FCDAnimated.h> 32 #include <FCDocument/FCDAnimationCurve.h> 33 #include <FCDocument/FCDAnimationKey.h> 41 DaeCharacter(
EggGroup *node_group,
const FCDControllerInstance *instance) :
42 _node_group(node_group),
43 _name(node_group->get_name()),
45 _skin_controller(nullptr),
48 _bind_shape_mat = LMatrix4d::ident_mat();
51 const FCDController *controller = (
const FCDController *)instance->GetEntity();
52 if (controller ==
nullptr) {
55 _skin_mesh = controller->GetBaseGeometry()->GetMesh();
57 if (controller->IsSkin()) {
58 _skin_controller = controller->GetSkinController();
59 _bind_shape_mat = DAEToEggConverter::convert_matrix(_skin_controller->GetBindShapeTransform());
73 size_t num_joints = _skin_controller->GetJointCount();
74 _joints.reserve(num_joints);
77 for (
size_t j = 0; j < num_joints; ++j) {
78 const FCDSkinControllerJoint *skin_joint = _skin_controller->GetJoint(j);
79 std::string sid = FROM_FSTRING(skin_joint->GetId());
81 bind_pose.invert_from(DAEToEggConverter::convert_matrix(
82 skin_joint->GetBindPoseInverse()));
85 JointMap::iterator ji = joint_map.find(sid);
86 if (ji != joint_map.end()) {
87 Joint &joint = ji->second;
89 if (joint._character !=
nullptr) {
93 if (!joint._bind_pose.almost_equal(bind_pose, 0.0001)) {
96 <<
"Multiple controllers share joint with sid " << sid
97 <<
", with different bind poses.\n";
101 joint._bind_pose = bind_pose;
102 joint._character =
this;
105 _joints.push_back(joint);
108 <<
"Unknown joint sid being referenced: '" << sid <<
"'\n";
111 _joints.push_back(
Joint(
nullptr,
nullptr));
124 const LMatrix4d &transform) {
126 LMatrix4d this_transform = transform;
128 if (node->IsJoint()) {
129 std::string sid = FROM_FSTRING(node->GetSubId());
131 JointMap::const_iterator ji = joint_map.find(sid);
132 if (ji != joint_map.end()) {
133 const Joint &joint = ji->second;
139 if (joint._character ==
this) {
140 LMatrix4d bind_pose = joint._bind_pose * _bind_shape_mat *
145 this_transform = bind_pose * this_transform;
146 joint._group->set_default_pose(*joint._group);
147 joint._group->set_transform3d(bind_pose);
163 for (
size_t ch = 0; ch < node->GetChildrenCount(); ++ch) {
165 adjust_joints(node->GetChild(ch), joint_map, this_transform);
175 const FCDSkinControllerVertex *influence = _skin_controller->GetVertexInfluence(index);
177 for (
size_t pa = 0; pa < influence->GetPairCount(); ++pa) {
178 const FCDJointWeightPair* jwpair = influence->GetPair(pa);
180 if (jwpair->jointIndex >= 0 && jwpair->jointIndex < (
int)_joints.size()) {
181 EggGroup *joint = _joints[jwpair->jointIndex]._group.p();
182 if (joint !=
nullptr) {
187 <<
"Invalid joint index: " << jwpair->jointIndex <<
"\n";
197 #if FCOLLADA_VERSION < 0x00030005 198 FCDSceneNodeList roots = _instance->FindSkeletonNodes();
200 FCDSceneNodeList roots;
201 _instance->FindSkeletonNodes(roots);
204 for (FCDSceneNodeList::iterator it = roots.begin(); it != roots.end(); ++it) {
214 FCDAnimatedList animateds;
217 for (
size_t t = 0; t < node->GetTransformCount(); ++t) {
218 FCDTransform *transform = node->GetTransform(t);
219 FCDAnimated *animated = transform->GetAnimated();
221 if (animated !=
nullptr) {
222 const FCDAnimationCurveListList &all_curves = animated->GetCurves();
224 for (
size_t ci = 0; ci < all_curves.size(); ++ci) {
225 const FCDAnimationCurveTrackList &curves = all_curves[ci];
226 if (curves.empty()) {
230 size_t num_keys = curves.front()->GetKeyCount();
231 const FCDAnimationKey **curve_keys = curves.front()->GetKeys();
233 for (
size_t c = 0; c < num_keys; ++c) {
234 keys.insert(curve_keys[c]->input);
246 nassertv(node !=
nullptr);
248 if (!node->IsJoint()) {
249 for (
size_t ch = 0; ch < node->GetChildrenCount(); ++ch) {
255 std::string node_id = FROM_FSTRING(node->GetDaeId());
257 table->set_table_type(EggTable::TT_table);
261 table->add_child(xform);
264 FCDAnimatedList animateds;
267 for (
size_t t = 0; t < node->GetTransformCount(); ++t) {
268 FCDTransform *transform = node->GetTransform(t);
269 FCDAnimated *animated = transform->GetAnimated();
270 if (animated !=
nullptr) {
271 if (animated->HasCurve()) {
272 animateds.push_back(animated);
279 float timing_total = 0;
281 for (ki = keys.begin(); ki != keys.end(); ++ki) {
282 for (FCDAnimatedList::iterator it = animateds.begin(); it != animateds.end(); ++it) {
284 (*it)->Evaluate(*ki);
287 if (ki != keys.begin()) {
288 timing_total += (*ki - last_key);
293 FMMatrix44 fmat = node->ToMatrix();
296 if (IS_NEARLY_ZERO(fmat[3][3])) {
300 xform->add_data(DAEToEggConverter::convert_matrix(fmat));
304 float fps = cfloor(((keys.size() - 1) / timing_total) * 100 + 0.5f) * 0.01f;
308 for (
size_t ch = 0; ch < node->GetChildrenCount(); ++ch) {
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void r_collect_keys(FCDSceneNode *node, pset< float > &keys)
Collects all animation keys found for the given node tree.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
void influence_vertex(int index, EggVertex *vertex)
Adds the influences for the given vertex.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
void bind_joints(JointMap &joint_map)
Binds the joints to the character.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This corresponds to an <Xfm$Anim_S$> entry, which is a collection of up to nine <S$Anim> entries that...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
void ref_vertex(EggVertex *vert, double membership=1.0)
Adds the vertex to the set of those referenced by the group, at the indicated membership level.
This is our own Panda specialization on the default STL set.
void build_table(EggTable *parent, FCDSceneNode *node, const pset< float > &keys)
Processes a joint node and its transforms.
TypeHandle is the identifier used to differentiate C++ class types.
void collect_keys(pset< float > &keys)
Collects all animation keys of animations applied to this character.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void adjust_joints(FCDSceneNode *node, const JointMap &joint_map, const LMatrix4d &transform=LMatrix4d::ident_mat())
Traverses through the character hierarchy in order to bind the mesh to the character.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.