/****************************************************************************** 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 "Quaternion.h" #include "DataStream.h" #include "ModelItemCollection.h" namespace Libx42 { public enum class KeyType : System::UInt16 { Position = X42_KT_POSITION, Scale = X42_KT_SCALE, Rotation = X42_KT_ROTATION, }; [::System::Runtime::InteropServices::StructLayout( ::System::Runtime::InteropServices::LayoutKind::Explicit, Size = 8 )] public value struct KeyStreamEntry { public: [::System::Runtime::InteropServices::FieldOffset( 0 )] KeyType Type; [::System::Runtime::InteropServices::FieldOffset( 2 )] System::UInt16 Bone; [::System::Runtime::InteropServices::FieldOffset( 4 )] System::UInt16 Frame; [::System::Runtime::InteropServices::FieldOffset( 6 )] System::UInt16 Value; bool Equals( KeyStreamEntry ke ) new; virtual bool Equals( Object ^obj ) override; static bool operator == ( KeyStreamEntry a, KeyStreamEntry b ) { return a.Equals( b ); } static bool operator != ( KeyStreamEntry a, KeyStreamEntry b ) { return !a.Equals( b ); } }; public ref class KeyStream : public DataStream< KeyStreamEntry > { public: property Model^ Owner { Model^ get( void ) { return owner; } } internal: KeyStream( Model ^owner ); private: Model ^owner; }; public ref class AnimationClip { public: property Model^ Owner { Model^ get( void ) { return owner; } } property int Index { int get( void ) { return index; } } [ComponentModel::EditorBrowsable( ComponentModel::EditorBrowsableState::Advanced )] property const x42animation_t& RawAnimationClip { const x42animation_t& get( void ); } property String^ Name { String^ get( void ); } property int FirstFrame { int get( void ) { return RawAnimationClip.firstFrame; } } property int LastFrame { int get( void ) { return RawAnimationClip.lastFrame; } } property bool IsLoopingAnimation { bool get( void ) { return RawAnimationClip.loopStart != X42_NO_LOOP; } } property int LoopStart { int get( void ) { if( !IsLoopingAnimation ) throw gcnew System::InvalidOperationException( "Can't read LoopStart on a non-looping animation." ); return RawAnimationClip.loopStart; } } property int LoopEnd { int get( void ) { if( !IsLoopingAnimation ) throw gcnew System::InvalidOperationException( "Can't read LoopEnd on a non-looping animation." ); return RawAnimationClip.loopEnd; } } /// /// Gets the animation's frame rate in frames per second. /// property float FrameRate { float get( void ) { return RawAnimationClip.frameRate / 1000.0F; } } internal: AnimationClip( Model ^owner, int index ); private: int index; Model ^owner; }; public ref class AnimationClipCollection : public ModelItemCollection< AnimationClip^ > { internal: AnimationClipCollection( Model ^owner ); }; public ref class AnimationData { public: property Model^ Owner { Model^ get( void ) { return owner; } } property Libx42::KeyStream^ KeyStream { Libx42::KeyStream^ get( void ) { return keyStream; } } property DataStream< Libx42::Math::Vector3 >^ PositionValues { DataStream< Libx42::Math::Vector3 >^ get( void ) { return posValues; } } property DataStream< Libx42::Math::Quaternion >^ RotationValues { DataStream< Libx42::Math::Quaternion >^ get( void ) { return rotValues; } } property DataStream< Libx42::Math::Vector3 >^ ScaleValues { DataStream< Libx42::Math::Vector3 >^ get( void ) { return scaleValues; } } property AnimationClipCollection^ Animations { AnimationClipCollection^ get( void ) { return animations; } } internal: AnimationData( Model ^owner ); private: Model ^owner; Libx42::KeyStream ^keyStream; DataStream< Libx42::Math::Vector3 > ^posValues; DataStream< Libx42::Math::Quaternion > ^rotValues; DataStream< Libx42::Math::Vector3 > ^scaleValues; AnimationClipCollection ^animations; }; };