Panda3D

daeCharacter.cxx

00001 // Filename: daeCharacter.cxx
00002 // Created by:  pro-rsoft (24Nov08)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "daeCharacter.h"
00016 #include "config_daeegg.h"
00017 #include "fcollada_utils.h"
00018 #include "pt_EggVertex.h"
00019 #include "eggXfmSAnim.h"
00020 
00021 #include "FCDocument/FCDocument.h"
00022 #include "FCDocument/FCDController.h"
00023 #include "FCDocument/FCDSceneNodeTools.h"
00024 
00025 TypeHandle DaeCharacter::_type_handle;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: DaeCharacter::Constructor
00029 //       Access: Public
00030 //  Description: 
00031 ////////////////////////////////////////////////////////////////////
00032 DaeCharacter::
00033 DaeCharacter(const string name, const FCDControllerInstance* controller_instance) {
00034   _controller_instance = (FCDControllerInstance*) controller_instance;
00035   _name = name;
00036   _frame_rate = 0;
00037   _skin_controller = NULL;
00038   // If it's a skin controller, add the controller joints.
00039   FCDController* controller = (FCDController*) controller_instance->GetEntity();
00040   if (controller == NULL) return;
00041   if (controller->IsSkin()) {
00042     _skin_controller = controller->GetSkinController();
00043     if (_skin_controller == NULL) return;
00044     for (size_t j = 0; j < _skin_controller->GetJointCount(); ++j) {
00045       _controller_joints[FROM_FSTRING(_skin_controller->GetJoint(j)->GetId())] = (FCDSkinControllerJoint*) _skin_controller->GetJoint(j);
00046     }
00047   }
00048 }
00049 
00050 ////////////////////////////////////////////////////////////////////
00051 //     Function: DaeCharacter::as_egg_bundle
00052 //       Access: Public
00053 //  Description: Returns the character as a <Bundle> element,
00054 //               suited for the animation table.
00055 ////////////////////////////////////////////////////////////////////
00056 PT(EggTable) DaeCharacter::
00057 as_egg_bundle() {
00058   PT(EggTable) bundle = new EggTable(_name);
00059   bundle->set_table_type(EggTable::TT_bundle);
00060   PT(EggTable) skeleton = new EggTable("<skeleton>");
00061   skeleton->set_table_type(EggTable::TT_table);
00062   bundle->add_child(skeleton);
00063   // Loop through the joint hierarchy
00064 #if FCOLLADA_VERSION < 0x00030005
00065   FCDSceneNodeList roots = _controller_instance->FindSkeletonNodes();
00066 #else
00067   FCDSceneNodeList roots;
00068   _controller_instance->FindSkeletonNodes(roots);
00069 #endif
00070   for (FCDSceneNodeList::iterator it = roots.begin(); it != roots.end(); ++it) {
00071     process_joint(skeleton, *it);
00072   }
00073   return bundle;
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: DaeCharacter::process_joint
00078 //       Access: Public
00079 //  Description: Processes a joint node and its transforms.
00080 ////////////////////////////////////////////////////////////////////
00081 void DaeCharacter::
00082 process_joint(PT(EggTable) parent, FCDSceneNode* node) {
00083   nassertv(node != NULL);
00084   string node_id = FROM_FSTRING(node->GetDaeId());
00085   PT(EggTable) joint = new EggTable(node_id);
00086   joint->set_table_type(EggTable::TT_table);
00087   parent->add_child(joint);
00088   PT(EggXfmSAnim) xform = new EggXfmSAnim("xform");
00089   joint->add_child(xform);
00090   xform->set_fps(_frame_rate);
00091   // Generate the sampled animation and loop through the matrices
00092   FCDSceneNodeTools::GenerateSampledAnimation(node);
00093   FMMatrix44List matrices = FCDSceneNodeTools::GetSampledAnimationMatrices();
00094   for (FMMatrix44List::const_iterator it = matrices.begin(); it != matrices.end(); ++it) {
00095     LMatrix4d matr = DAEToEggConverter::convert_matrix(*it);
00096     assert(xform->add_data(matr));
00097   }
00098   // Loop through the children joints
00099   for (size_t ch = 0; ch < node->GetChildrenCount(); ++ch) {
00100     if (node->GetChild(ch)->IsJoint()) {
00101       process_joint(joint, node->GetChild(ch));
00102     }
00103   }
00104 }
 All Classes Functions Variables Enumerations