/****************************************************************************** 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. ******************************************************************************/ #pragma once #include "Vector.h" #include "DataStream.h" namespace Libx42 { [::System::Runtime::InteropServices::StructLayout( ::System::Runtime::InteropServices::LayoutKind::Explicit, Size = 32 )] public value struct VertexPosition { public: [::System::Runtime::InteropServices::FieldOffset( 0 )] Math::Vector3 Position; [::System::Runtime::InteropServices::FieldOffset( 12 )] Byte BlendIndex0; [::System::Runtime::InteropServices::FieldOffset( 13 )] Byte BlendIndex1; [::System::Runtime::InteropServices::FieldOffset( 14 )] Byte BlendIndex2; [::System::Runtime::InteropServices::FieldOffset( 15 )] Byte BlendIndex3; [::System::Runtime::InteropServices::FieldOffset( 16 )] float BlendWeight0; [::System::Runtime::InteropServices::FieldOffset( 20 )] float BlendWeight1; [::System::Runtime::InteropServices::FieldOffset( 24 )] float BlendWeight2; [::System::Runtime::InteropServices::FieldOffset( 28 )] float BlendWeight3; [::System::Runtime::InteropServices::FieldOffset( 0 )] literal int NumBlendWeignts = 4; bool GetBlend( int index, [::System::Runtime::InteropServices::Out] int %influenceIndex, [::System::Runtime::InteropServices::Out] float %weightValue ) { switch( index ) { case 0: influenceIndex = BlendIndex0; weightValue = BlendWeight0; break; case 1: influenceIndex = BlendIndex1; weightValue = BlendWeight1; break; case 2: influenceIndex = BlendIndex2; weightValue = BlendWeight2; break; case 3: influenceIndex = BlendIndex3; weightValue = BlendWeight3; break; default: throw gcnew ArgumentOutOfRangeException( "index" ); } return weightValue != 0; } bool Equals( VertexPosition vp ) new; virtual bool Equals( Object ^obj ) override; static bool operator == ( VertexPosition a, VertexPosition b ) { return a.Equals( b ); } static bool operator != ( VertexPosition a, VertexPosition b ) { return !a.Equals( b ); } }; [::System::Runtime::InteropServices::StructLayout( ::System::Runtime::InteropServices::LayoutKind::Explicit, Size = 16 )] public value struct VertexNormal { public: [::System::Runtime::InteropServices::FieldOffset( 0 )] Math::Vector3 Normal; bool Equals( VertexNormal vp ) new; virtual bool Equals( Object ^obj ) override; static bool operator == ( VertexNormal a, VertexNormal b ) { return a.Equals( b ); } static bool operator != ( VertexNormal a, VertexNormal b ) { return !a.Equals( b ); } }; [::System::Runtime::InteropServices::StructLayout( ::System::Runtime::InteropServices::LayoutKind::Explicit, Size = 32 )] public value struct VertexTangentBasis { public: [::System::Runtime::InteropServices::FieldOffset( 0 )] Math::Vector3 Tangent; [::System::Runtime::InteropServices::FieldOffset( 12 )] float NormalFactor; [::System::Runtime::InteropServices::FieldOffset( 16 )] Math::Vector3 Binormal; bool Equals( VertexTangentBasis vp ) new; virtual bool Equals( Object ^obj ) override; static bool operator == ( VertexTangentBasis a, VertexTangentBasis b ) { return a.Equals( b ); } static bool operator != ( VertexTangentBasis a, VertexTangentBasis b ) { return !a.Equals( b ); } }; [::System::Runtime::InteropServices::StructLayout( ::System::Runtime::InteropServices::LayoutKind::Explicit, Size = 4 )] public value struct VertexColor { public: [::System::Runtime::InteropServices::FieldOffset( 0 )] Byte R; [::System::Runtime::InteropServices::FieldOffset( 1 )] Byte G; [::System::Runtime::InteropServices::FieldOffset( 2 )] Byte B; [::System::Runtime::InteropServices::FieldOffset( 3 )] Byte A; bool Equals( VertexColor cl ) new; virtual bool Equals( Object ^obj ) override; static bool operator == ( VertexColor a, VertexColor b ) { return a.Equals( b ); } static bool operator != ( VertexColor a, VertexColor b ) { return !a.Equals( b ); } }; ref class Model; ref class Group; public ref class VertexData { public: property Model^ Owner { Model^ get( void ) { return owner; } } /// /// Gets this vertex data chunk's starting index in the model's vertices array. /// property int Offset { int get( void ) { return offset; } } /// /// Gets the number of vertices in this data chunk. /// property int Count { int get( void ) { return count; } } property DataStream< VertexPosition >^ PositionStream { DataStream< VertexPosition >^ get( void ) { return vp; } } property DataStream< VertexNormal >^ NormalStream { DataStream< VertexNormal >^ get( void ) { return vn; } } property DataStream< VertexTangentBasis >^ TangentBasisStream { DataStream< VertexTangentBasis >^ get( void ) { return vt; } } property DataStream< Math::Vector2 >^ TextureCoordinateStream { DataStream< Math::Vector2 >^ get( void ) { return vtc; } } property DataStream< VertexColor >^ ColorStream { DataStream< VertexColor >^ get( void ) { return vcl; } } internal: VertexData( Model ^model ); VertexData( Group ^group ); private: Model ^owner; int offset, count; DataStream< VertexPosition > ^vp; DataStream< VertexNormal > ^vn; DataStream< VertexTangentBasis > ^vt; DataStream< Math::Vector2 > ^vtc; DataStream< VertexColor > ^vcl; void InitStreams( int startIdx, int count ); }; };