Changeset 391 for cafu/trunk

Show
Ignore:
Timestamp:
09/22/11 14:13:56 (8 months ago)
Author:
Carsten
Message:

Model support:
Added data structures and load/save code for "animation channels".

Location:
cafu/trunk/Libs/Models
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/Libs/Models/Loader.hpp

    r382 r391  
    6565    virtual void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs)=0; 
    6666 
     67    /// Loads the animation channels (groups of joints) of the Cafu model. 
     68    virtual void Load(ArrayT<CafuModelT::ChannelT>& Channels)=0; 
     69 
    6770    /// Postprocesses the file data according to flags given to the constructor. 
    6871    virtual void Postprocess(ArrayT<CafuModelT::MeshT>& Meshes); 
  • cafu/trunk/Libs/Models/Loader_ase.hpp

    r382 r391  
    4343    void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) { } 
    4444    void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs); 
     45    void Load(ArrayT<CafuModelT::ChannelT>& Channels) { } 
    4546 
    4647 
  • cafu/trunk/Libs/Models/Loader_assimp.hpp

    r382 r391  
    4747    void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) { } 
    4848    void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) { } 
     49    void Load(ArrayT<CafuModelT::ChannelT>& Channels) { } 
    4950 
    5051 
  • cafu/trunk/Libs/Models/Loader_cmdl.cpp

    r384 r391  
    528528 
    529529 
     530void LoaderCafuT::Load(ArrayT<CafuModelT::ChannelT>& Channels) 
     531{ 
     532    // Read the channels. 
     533    lua_getglobal(m_LuaState, "Channels"); 
     534    { 
     535        Channels.Overwrite(); 
     536        Channels.PushBackEmptyExact(lua_objlen_ul(m_LuaState, -1)); 
     537 
     538        for (unsigned long ChannelNr=0; ChannelNr<Channels.Size(); ChannelNr++) 
     539        { 
     540            CafuModelT::ChannelT& Channel=Channels[ChannelNr]; 
     541 
     542            lua_rawgeti(m_LuaState, -1, ChannelNr+1); 
     543            { 
     544                lua_getfield(m_LuaState, -1, "name"); 
     545                { 
     546                    const char* Name=lua_tostring(m_LuaState, -1); 
     547                    Channel.Name=Name ? Name : "Channel"; 
     548                } 
     549                lua_pop(m_LuaState, 1); 
     550 
     551                lua_getfield(m_LuaState, -1, "joints"); 
     552                { 
     553                    const unsigned long NumJoints=lua_objlen_ul(m_LuaState, -1); 
     554 
     555                    for (unsigned int c=0; c<NumJoints; c++) 
     556                    { 
     557                        lua_rawgeti(m_LuaState, -1, c+1); 
     558                        Channel.SetMember(lua_tointeger(m_LuaState, -1)); 
     559                        lua_pop(m_LuaState, 1); 
     560                    } 
     561                } 
     562                lua_pop(m_LuaState, 1); 
     563            } 
     564            lua_pop(m_LuaState, 1); 
     565        } 
     566    } 
     567    lua_pop(m_LuaState, 1); 
     568} 
     569 
     570 
    530571/*static*/ int LoaderCafuT::SetVersion(lua_State* LuaState) 
    531572{ 
  • cafu/trunk/Libs/Models/Loader_cmdl.hpp

    r382 r391  
    4646    void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan); 
    4747    void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs); 
     48    void Load(ArrayT<CafuModelT::ChannelT>& Channels); 
    4849 
    4950 
  • cafu/trunk/Libs/Models/Loader_fbx.hpp

    r382 r391  
    4444    void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan); 
    4545    void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs); 
     46    void Load(ArrayT<CafuModelT::ChannelT>& Channels) { } 
    4647 
    4748 
  • cafu/trunk/Libs/Models/Loader_lwo.hpp

    r382 r391  
    4040    void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) { } 
    4141    void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) { } 
     42    void Load(ArrayT<CafuModelT::ChannelT>& Channels) { } 
    4243 
    4344 
  • cafu/trunk/Libs/Models/Loader_md5.hpp

    r382 r391  
    4242    void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) { } 
    4343    void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) { } 
     44    void Load(ArrayT<CafuModelT::ChannelT>& Channels) { } 
    4445}; 
    4546 
  • cafu/trunk/Libs/Models/Loader_mdl.hpp

    r382 r391  
    4848    void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan); 
    4949    void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) { } 
     50    void Load(ArrayT<CafuModelT::ChannelT>& Channels) { } 
    5051 
    5152 
  • cafu/trunk/Libs/Models/Model_cmdl.cpp

    r390 r391  
    209209 
    210210 
     211bool CafuModelT::ChannelT::IsMember(unsigned int JointNr) const 
     212{ 
     213    const unsigned int BlockNr=JointNr >> 5; 
     214    const unsigned int BitNr  =JointNr & 31; 
     215    const unsigned int BitMask=1 << BitNr; 
     216 
     217    if (BlockNr >= m_BitBlocks.Size()) return false; 
     218 
     219    return (m_BitBlocks[BlockNr] & BitMask) != 0; 
     220} 
     221 
     222 
     223void CafuModelT::ChannelT::SetMember(unsigned int JointNr, bool Member) 
     224{ 
     225    const unsigned int BlockNr=JointNr >> 5; 
     226    const unsigned int BitNr  =JointNr & 31; 
     227    const unsigned int BitMask=1 << BitNr; 
     228 
     229    // Grow as needed. 
     230    while (BlockNr >= m_BitBlocks.Size()) 
     231        m_BitBlocks.PushBack(0); 
     232 
     233    if (Member) m_BitBlocks[BlockNr] |=  BitMask; 
     234           else m_BitBlocks[BlockNr] &= ~BitMask; 
     235} 
     236 
     237 
    211238CafuModelT::CafuModelT(ModelLoaderT& Loader) 
    212239    : m_FileName(Loader.GetFileName()), 
     
    234261    Loader.Load(m_Skins, m_MaterialMan); 
    235262    Loader.Load(m_GuiFixtures, m_GuiLocs); 
     263    Loader.Load(m_Channels); 
    236264    Loader.Postprocess(m_Meshes); 
    237265 
     
    851879                  << "AxisY={ " << serialize(GuiLoc.AxisY) << " }; " 
    852880                  << "},\n"; 
     881    } 
     882 
     883    OutStream << "}\n"; 
     884 
     885 
     886    // *** Write the channels. *** 
     887    OutStream << "\nChannels=\n{\n"; 
     888 
     889    for (unsigned long ChanNr=0; ChanNr<m_Channels.Size(); ChanNr++) 
     890    { 
     891        const ChannelT& Channel=m_Channels[ChanNr]; 
     892        bool            IsFirst=true; 
     893 
     894        OutStream << "\t{\n" 
     895                  << "\t\tname=\"" << Channel.Name << "\";\n" 
     896                  << "\t\tjoints={ "; 
     897 
     898        for (unsigned long JointNr=0; JointNr<m_Joints.Size(); JointNr++) 
     899        { 
     900            if (Channel.IsMember(JointNr)) 
     901            { 
     902                if (!IsFirst) OutStream << ", "; 
     903                OutStream << JointNr; 
     904                IsFirst=false; 
     905            } 
     906        } 
     907 
     908        OutStream << " };\n" 
     909                  << "\t},\n"; 
    853910    } 
    854911 
  • cafu/trunk/Libs/Models/Model_cmdl.hpp

    r390 r391  
    2929#include "Math3D/Matrix.hpp" 
    3030#include "Model.hpp" 
     31 
     32#if defined(_WIN32) && _MSC_VER<1600 
     33#include "pstdint.h"            // Paul Hsieh's portable implementation of the stdint.h header. 
     34#else 
     35#include <stdint.h> 
     36#endif 
    3137 
    3238 
     
    166172 
    167173 
    168     /// This struct describes additional/alternative skins for this model. 
     174    /// This struct describes additional/alternative skins for the meshes of this model. 
    169175    struct SkinT 
    170176    { 
     
    206212        Vector3fT AxisX; 
    207213        Vector3fT AxisY; 
     214    }; 
     215 
     216 
     217    /// Channels allow animations to play only on a subset of the joints, 
     218    /// so that multiple animations can play on different parts of the model at the same time. 
     219    /// For example, you can play a walking animation on the legs, an animation for swinging 
     220    /// the arms on the upper body, and an animation for moving the eyes on the head.  
     221    /// 
     222    /// Technically, a channel defines a group of joints. It is used to limit or "filter" 
     223    /// animations such that they affect only the joints that are members of the channel. 
     224    struct ChannelT 
     225    { 
     226        std::string Name;   ///< The name of this channel. 
     227 
     228        bool IsMember(unsigned int JointNr) const; 
     229        void SetMember(unsigned int JointNr, bool Member=true); 
     230 
     231 
     232        private: 
     233 
     234        ArrayT<uint32_t> m_BitBlocks; 
    208235    }; 
    209236 
     
    250277    const ArrayT<SkinT>&        GetSkins() const { return m_Skins; } 
    251278    const ArrayT<GuiFixtureT>&  GetGuiFixtures() const { return m_GuiFixtures; } 
     279    const ArrayT<ChannelT>&     GetChannels() const { return m_Channels; } 
    252280 
    253281    /// This method returns the set of drawing matrices (one per joint) at the given sequence and frame number. 
     
    315343    ArrayT<GuiFixtureT>   m_GuiFixtures;            ///< Array of GUI fixtures in the model. 
    316344    ArrayT<GuiLocT>       m_GuiLocs;                ///< Array of locations where GUIs can be attached to this model. 
     345    ArrayT<ChannelT>      m_Channels;               ///< Array of channels in this model. 
    317346 
    318347