/****************************************************************************** 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 "IndexCollection.h" #include "Model.h" #include "Group.h" namespace Libx42 { IndexCollection::IndexCollection( Model ^owner ) : owner( owner ) { baseIndex = 0; count = owner->m->header.numIndices; } IndexCollection::IndexCollection( Model ^owner, Group ^group ) : owner( owner ) { baseIndex = group->RawGroup.firstIndex != X42_NO_INDICES ? group->RawGroup.firstIndex : -1; count = group->RawGroup.numElems; } int IndexCollection::Offset::get( void ) { if( IsImplicit ) throw gcnew InvalidOperationException; return baseIndex; } x42index_t IndexCollection::default::get( int index ) { if( index < 0 || index >= Count ) throw gcnew ArgumentOutOfRangeException( "index" ); if( IsImplicit ) return (x42index_t)index; return owner->m->indices[baseIndex + index]; } array< x42index_t >^ IndexCollection::ToArray( void ) { array< x42index_t > ^ret = gcnew array< x42index_t >( Count ); if( IsImplicit ) { for( int i = 0; i < ret->Length; i++ ) ret[i] = (x42index_t)i; } else { pin_ptr< x42index_t > pinRet = &ret[0]; memcpy( pinRet, owner->m->indices + baseIndex, ret->Length * sizeof( x42index_t ) ); } return ret; } };