/****************************************************************************** libx42.net - skinned vertex animation library (.NET API) Copyright (C) 2007 HermitWorks Entertainment Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA. ******************************************************************************/ #include "Stdafx.h" #include "Bone.h" #include "Model.h" #include "Influence.h" #include "AnimationGroup.h" #include "Tag.h" #include "UtilTypes.h" using namespace System; using namespace System::Collections::Generic; using namespace System::IO; namespace Libx42 { Bone::Bone( Model ^owner, int index ) : owner( owner ), index( index ) { } const x42bone_t& Bone::RawBone::get( void ) { return owner->m->bones[index]; } String^ Bone::Name::get( void ) { return owner->GetModelString( RawBone.name ); } Bone^ Bone::Parent::get( void ) { if( RawBone.parentIdx == X42_MODEL_BONE ) return nullptr; return owner->Bones[RawBone.parentIdx]; } array< Bone^ >^ Bone::GetChildren( void ) { List< Bone^ > retList; for( int i = 0; i < owner->Bones->Count; i++ ) if( owner->Bones[i]->Parent == this ) retList.Add( owner->Bones[i] ); return retList.ToArray(); } array< Influence^ >^ Bone::GetInfluences( void ) { List< Influence^ > retList; for( int i = 0; i < owner->Influences->Count; i++ ) if( owner->Influences[i]->Bone == this ) retList.Add( owner->Influences[i] ); return retList.ToArray(); } array< Tag^ >^ Bone::GetTags( void ) { List< Tag^ > retList; for( int i = 0; i < owner->Tags->Count; i++ ) if( owner->Tags[i]->Bone == this ) retList.Add( owner->Tags[i] ); return retList.ToArray(); } BoneCollection::BoneCollection( Model ^owner ) : ModelItemCollection< Bone^ >( owner ) { items = gcnew array< Bone^ >( owner->m->header.numBones ); for( int i = 0; i < items->Length; i++ ) items[i] = gcnew Bone( owner, i ); } BoneCollection::BoneCollection( AnimationGroup ^animGroup ) : ModelItemCollection< Bone^ >( animGroup->Owner ) { items = gcnew array< Bone^ >( animGroup->NumBones ); for( int i = 0; i < items->Length; i++ ) { Bone^ b = animGroup->Owner->Bones[animGroup->FirstBone + i]; b->animGroup = animGroup; items[i] = b; } } array< Bone^ >^ BoneCollection::GetRootBones( void ) { List< Bone^ > retList; for( int i = 0; i < items->Length; i++ ) if( !items[i]->Parent ) retList.Add( items[i] ); return retList.ToArray(); } };