/****************************************************************************** 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 "VertexData.h" #include "Model.h" #include "Group.h" namespace Libx42 { bool VertexPosition::Equals( VertexPosition v ) { return Position == v.Position && BlendIndex0 == v.BlendIndex0 && BlendIndex1 == v.BlendIndex1 && BlendIndex2 == v.BlendIndex2 && BlendIndex3 == v.BlendIndex3 && BlendWeight0 == v.BlendWeight0 && BlendWeight1 == v.BlendWeight1 && BlendWeight2 == v.BlendWeight2 && BlendWeight3 == v.BlendWeight3; } bool VertexPosition::Equals( Object^ obj ) { if( !obj ) return false; try { VertexPosition v = safe_cast< VertexPosition >( obj ); return Equals( v ); } catch( InvalidCastException^ ) { return false; } } bool VertexNormal::Equals( VertexNormal v ) { return Normal == v.Normal; } bool VertexNormal::Equals( Object^ obj ) { if( !obj ) return false; try { VertexNormal v = safe_cast< VertexNormal >( obj ); return Equals( v ); } catch( InvalidCastException^ ) { return false; } } bool VertexColor::Equals( VertexColor v ) { return R == v.R && G == v.G && B == v.B && A == v.A; } bool VertexColor::Equals( Object^ obj ) { if( !obj ) return false; try { VertexColor v = safe_cast< VertexColor >( obj ); return Equals( v ); } catch( InvalidCastException^ ) { return false; } } bool VertexTangentBasis::Equals( VertexTangentBasis v ) { return Tangent == v.Tangent && NormalFactor == v.NormalFactor && Binormal == v.Binormal; } bool VertexTangentBasis::Equals( Object^ obj ) { if( !obj ) return false; try { VertexTangentBasis v = safe_cast< VertexTangentBasis >( obj ); return Equals( v ); } catch( InvalidCastException^ ) { return false; } } VertexData::VertexData( Model ^model ) : owner( model ) { offset = 0; count = model->m->header.numVerts; InitStreams( offset, count ); } VertexData::VertexData( Group ^group ) : owner( group->Owner ) { offset = group->RawGroup.firstVert; count = group->RawGroup.numVerts; InitStreams( offset, count ); } void VertexData::InitStreams( int startIdx, int count ) { vp = gcnew DataStream< VertexPosition >( owner, owner->m->vertPos + startIdx, sizeof( x42vertAnim_t ), 0, count ); if( owner->m->vertNorm ) vn = gcnew DataStream< VertexNormal >( owner, owner->m->vertNorm + startIdx, sizeof( x42vertNormal_t ), 0, count ); else vn = nullptr; if( owner->m->vertTan ) vt = gcnew DataStream< VertexTangentBasis >( owner, owner->m->vertTan + startIdx, sizeof( x42vertTangent_t ), 0, count ); else vt = nullptr; if( owner->m->vertTc ) vtc = gcnew DataStream< Math::Vector2 >( owner, owner->m->vertTc + startIdx, sizeof( vec2_t ), 0, count ); else vtc = nullptr; if( owner->m->vertCl ) vcl = gcnew DataStream< VertexColor >( owner, owner->m->vertCl + startIdx, sizeof( rgba_t ), 0, count ); } };