Ignore:
Timestamp:
07/20/14 23:45:56 (11 years ago)
Author:
epyon
Message:
  • nmd format made more robust
  • full implementation of runtime animation format decoding
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/formats/nmd_loader.cc

    r283 r284  
    2222                switch ( element_header.type )
    2323                {
    24                 case nmd_type::MESH           : load_mesh( source, element_header.children ); break;
    25                 case nmd_type::ANIMATION      : load_animation( source, element_header.children ); break;
    26                 case nmd_type::BONE_ARRAY     : load_bones( source, element_header.children ); break;
     24                case nmd_type::MESH           : load_mesh( source, element_header ); break;
     25                case nmd_type::ANIMATION      : load_animation( source, element_header ); break;
     26                case nmd_type::BONE_ARRAY     : load_bones( source, element_header ); break;
    2727                case nmd_type::STRING_TABLE   : load_strings( source ); break;
    2828                default: NV_ASSERT( false, "UNKNOWN NMD ELEMENT!" ); break;
     
    3232}
    3333
    34 bool nv::nmd_loader::load_mesh( stream& source, uint32 children )
     34bool nv::nmd_loader::load_mesh( stream& source, const nmd_element_header& e )
    3535{
    3636        mesh_data* mesh = new mesh_data();
    37         for ( uint32 s = 0; s < children; ++s )
     37        for ( uint32 s = 0; s < e.children; ++s )
    3838        {
    3939                nmd_element_header element_header;
     
    8282}
    8383
    84 bool nv::nmd_loader::load_bones( stream& source, uint32 children )
     84bool nv::nmd_loader::load_bones( stream& source, const nmd_element_header& e )
    8585{
    8686        NV_ASSERT( m_bone_data == nullptr, "MULTIPLE BONE ENTRIES!" );
    8787        m_bone_data = new nmd_bone_data;
    88         m_bone_data->bones = new nmd_bone[ children ];
    89         m_bone_data->count = (uint16)children;
    90         source.read( m_bone_data->bones, sizeof( nmd_bone ), children );
     88        m_bone_data->bones = new nmd_bone[ e.children ];
     89        m_bone_data->count = (uint16)e.children;
     90        source.read( m_bone_data->bones, sizeof( nmd_bone ), e.children );
    9191        return true;
    9292}
     
    114114
    115115
    116 bool nv::nmd_loader::load_animation( stream& source, uint32 children )
     116bool nv::nmd_loader::load_animation( stream& source, const nmd_element_header& e )
    117117{
    118118        NV_ASSERT( m_animation == nullptr, "MULTIPLE ANIMATION ENTRIES!" );
     
    123123        m_animation->duration   = header.duration;
    124124        m_animation->flat       = header.flat;
    125         m_animation->node_count = (uint16)children;
    126         m_animation->nodes      = new nmd_node[ children ];
    127         for ( uint32 i = 0; i < children; ++i )
     125        m_animation->node_count = (uint16)e.children;
     126        m_animation->nodes      = new nmd_node[ e.children ];
     127        for ( uint32 i = 0; i < e.children; ++i )
    128128        {
    129129                nmd_element_header element_header;
    130130                source.read( &element_header, sizeof( element_header ), 1 );
    131131                NV_ASSERT( element_header.type == nmd_type::ANIMATION_NODE, "ANIMATION_NODE expected!" );
     132                m_animation->nodes[i].name          = element_header.name;
    132133
    133134                uint16 ch_count = element_header.children;
     
    135136                nmd_animation_node_header node_header;
    136137                source.read( &node_header, sizeof( node_header ), 1 );
    137                 m_animation->nodes[i].name          = node_header.name;
    138138                m_animation->nodes[i].parent_id     = node_header.parent_id;
    139139                m_animation->nodes[i].transform     = node_header.transform;
Note: See TracChangeset for help on using the changeset viewer.