1 /* 2 Copyright (c) 2008-2009 NetAllied Systems GmbH 3 4 This file is part of COLLADASaxFrameworkLoader. 5 6 Licensed under the MIT Open Source License, 7 for details please see LICENSE file or the website 8 http://www.opensource.org/licenses/mit-license.php 9 */ 10 11 #include "COLLADASaxFWLStableHeaders.h" 12 #include "COLLADASaxFWLJointsLoader.h" 13 #include "COLLADASaxFWLFileLoader.h" 14 #include "COLLADASaxFWLFilePartLoader.h" 15 16 #include "COLLADAFWJoint.h" 17 18 19 namespace COLLADASaxFWL 20 { 21 22 //------------------------------ JointsLoader()23 JointsLoader::JointsLoader( ) 24 : mCurrentJoint(0) 25 , mCurrentJointPrimitive(0) 26 , mAxisNumbersReceived(0) 27 { 28 } 29 30 //------------------------------ ~JointsLoader()31 JointsLoader::~JointsLoader() 32 { 33 } 34 35 //------------------------------ getUniqueId()36 const COLLADAFW::UniqueId& JointsLoader::getUniqueId () 37 { 38 if ( mCurrentJoint ) 39 return mCurrentJoint->getUniqueId (); 40 return COLLADAFW::UniqueId::INVALID; 41 } 42 43 //------------------------------ beginJointPrimitive(COLLADAFW::JointPrimitive::Type jointPrimitiveType,const char * sid)44 bool JointsLoader::beginJointPrimitive( COLLADAFW::JointPrimitive::Type jointPrimitiveType, const char * sid) 45 { 46 mCurrentJointPrimitive = FW_NEW COLLADAFW::JointPrimitive( getHandlingFilePartLoader()->createUniqueId( COLLADAFW::JointPrimitive::ID()), jointPrimitiveType ); 47 mCurrentJoint->getJointPrimitives().append( mCurrentJointPrimitive ); 48 getHandlingFilePartLoader()->addToSidTree(0, sid, mCurrentJointPrimitive); 49 return true; 50 } 51 52 //------------------------------ endJointPrimitive()53 bool JointsLoader::endJointPrimitive() 54 { 55 mCurrentJointPrimitive = 0; 56 getHandlingFilePartLoader()->moveUpInSidTree(); 57 return true; 58 } 59 60 //------------------------------ begin__joint(const joint__AttributeData & attributeData)61 bool JointsLoader::begin__joint( const joint__AttributeData& attributeData ) 62 { 63 mCurrentJoint = FW_NEW COLLADAFW::Joint( getHandlingFilePartLoader()->createUniqueIdFromId( attributeData.id, COLLADAFW::Joint::ID()) ); 64 if ( attributeData.name ) 65 { 66 mCurrentJoint->setName(attributeData.name); 67 } 68 else if ( attributeData.id ) 69 { 70 mCurrentJoint->setName(attributeData.id); 71 } 72 73 if ( attributeData.id ) 74 { 75 mCurrentJoint->setOriginalId(attributeData.id); 76 } 77 getHandlingFilePartLoader()->addToSidTree( attributeData.id, attributeData.sid, mCurrentJoint); 78 return true; 79 } 80 81 //------------------------------ end__joint()82 bool JointsLoader::end__joint() 83 { 84 getHandlingFilePartLoader()->getFileLoader()->addJoint(mCurrentJoint); 85 mCurrentJoint = 0; 86 getHandlingFilePartLoader()->moveUpInSidTree(); 87 return true; 88 } 89 90 //------------------------------ begin__prismatic(const prismatic__AttributeData & attributeData)91 bool JointsLoader::begin__prismatic( const prismatic__AttributeData& attributeData ) 92 { 93 return beginJointPrimitive( COLLADAFW::JointPrimitive::PRISMATIC, attributeData.sid); 94 } 95 96 //------------------------------ end__prismatic()97 bool JointsLoader::end__prismatic() 98 { 99 return endJointPrimitive(); 100 } 101 102 //------------------------------ begin__revolute(const revolute__AttributeData & attributeData)103 bool JointsLoader::begin__revolute( const revolute__AttributeData& attributeData ) 104 { 105 return beginJointPrimitive( COLLADAFW::JointPrimitive::REVOLUTE, attributeData.sid); 106 } 107 108 //------------------------------ end__revolute()109 bool JointsLoader::end__revolute() 110 { 111 return endJointPrimitive(); 112 } 113 114 //------------------------------ begin__axis____axis_type(const axis____axis_type__AttributeData & attributeData)115 bool JointsLoader::begin__axis____axis_type( const axis____axis_type__AttributeData& attributeData ) 116 { 117 getHandlingFilePartLoader()->addToSidTree( 0, attributeData.sid); 118 return true; 119 } 120 121 //------------------------------ end__axis____axis_type()122 bool JointsLoader::end__axis____axis_type() 123 { 124 getHandlingFilePartLoader()->moveUpInSidTree(); 125 mAxisNumbersReceived = 0; 126 return true; 127 } 128 129 //------------------------------ data__axis____axis_type(const float * data,size_t length)130 bool JointsLoader::data__axis____axis_type( const float* data, size_t length ) 131 { 132 COLLADABU::Math::Vector3& axis = mCurrentJointPrimitive->getAxis(); 133 for ( size_t i = 0; i < length; ++i ) 134 { 135 axis[mAxisNumbersReceived++] = data[i]; 136 } 137 return true; 138 } 139 140 //------------------------------ data__min____minmax_type(float value)141 bool JointsLoader::data__min____minmax_type( float value ) 142 { 143 COLLADABU_ASSERT(mCurrentJointPrimitive); 144 if ( mCurrentJointPrimitive ) 145 { 146 mCurrentJointPrimitive->setHardLimitMin(value); 147 } 148 return true; 149 } 150 151 //------------------------------ data__max____minmax_type(float value)152 bool JointsLoader::data__max____minmax_type( float value ) 153 { 154 COLLADABU_ASSERT(mCurrentJointPrimitive); 155 if ( mCurrentJointPrimitive ) 156 { 157 mCurrentJointPrimitive->setHardLimitMax(value); 158 } 159 return true; 160 } 161 162 163 } // namespace COLLADASaxFWL 164