Changeset 287 for trunk


Ignore:
Timestamp:
07/23/14 15:24:03 (11 years ago)
Author:
epyon
Message:
  • mesh_data_pack's in every format
  • md5_mesh_data removed, uses standard mesh_data
  • BONE_ARRAY in NMD is now a simple set of animation nodes
  • bone and animation node concepts merged
  • several minor changes
Location:
trunk
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/formats/assimp_loader.hh

    r285 r287  
    5656        struct assimp_animation
    5757        {
    58                 float fps;
    59                 float duration;
    60                 bool  pretransformed;
     58                uint16 frame_rate;
     59                float  duration;
     60                bool   flat;
     61                uint32 max_frames;
    6162                dynamic_array< assimp_animated_node_data > nodes;
    6263        };
     
    7172                virtual size_t get_mesh_count() const { return m_mesh_count; }
    7273                virtual ~assimp_loader();
     74                // TODO: remove
    7375                assimp_model* release_merged_model();
     76                // TODO: implement release_mesh_nodes_data
     77                virtual mesh_data_pack* release_mesh_data_pack();
    7478                assimp_animation* release_animation( size_t index, bool pre_transform );
     79                // TODO: implement
     80                virtual mesh_nodes_data* release_mesh_nodes_data();
    7581                bool load_bones( size_t index, std::vector< assimp_bone >& bones );
    7682                void scene_report() const;
    7783        private:
     84                void load_mesh_data( mesh_data* data, size_t index );
    7885                void initialize( const string& a_ext, const mat3& a_rotate_transform, float a_scale, uint32 a_assimp_flags );
    7986                uint32 load_node( assimp_animation* data, const void* vnode, sint32 this_id, sint32 parent_id );
  • trunk/nv/formats/md2_loader.hh

    r285 r287  
    2929                virtual bool load( stream& source );
    3030                virtual mesh_data* release_mesh_data( size_t index = 0 );
     31                virtual mesh_data_pack* release_mesh_data_pack();
    3132                virtual size_t get_mesh_count() const { return 1; }
    3233        private:
    33                 virtual mesh_data* release_mesh_frame( sint32 frame );
     34                void release_mesh_frame( mesh_data* data, sint32 frame );
    3435                size_t get_max_frames() const;
    3536                void reindex();
  • trunk/nv/formats/md3_loader.hh

    r285 r287  
    3636                virtual bool load( stream& source );
    3737                virtual mesh_data* release_mesh_data( size_t index = 0 );
    38                 virtual mesh_data* release_mesh_frame( sint32 frame );
     38                virtual mesh_data_pack* release_mesh_data_pack();
    3939                virtual size_t get_mesh_count() const { return 1; }
    4040                size_t get_max_frames() const;
    41                 virtual tag_map* create_tag_map();
    42                 virtual mesh_node_data* release_mesh_node_data( size_t index );
    43                 virtual size_t get_node_count() const;
     41                virtual mesh_nodes_data* release_mesh_nodes_data();
    4442        private:
     43                void release_mesh_frame( mesh_data* data, sint32 frame );
    4544                key_raw_channel* load_tags( const std::string& tag );
    4645                void* m_md3;
  • trunk/nv/formats/md5_loader.hh

    r282 r287  
    3333        };
    3434
    35         struct md5_vtx_data
     35        struct md5_vtx_pntiw
    3636        {
    3737                vec3  position;
     
    8888        };
    8989
    90         class md5_mesh_instance
    91         {
    92                 friend class md5_mesh_data;
    93         public:
    94                 const void* data() const { return m_pntdata.data(); }
    95                 uint32 get_index_count() const { return m_indices; }
    96                 size_t size() const { return m_pntdata.raw_size(); }
    97                 void apply( const transform* skeleton );
    98                 const md5_mesh_data* get_mesh_data() const { return m_data; }
    99         private:
    100                 md5_mesh_instance( const md5_mesh_data* a_data );
    101 
    102                 uint32                       m_indices;
    103                 dynamic_array< md5_vtx_pnt > m_pntdata;
    104                 dynamic_array< transform >   m_pos_offset;
    105                 const md5_mesh_data*         m_data;
    106         };
    107 
    108         class md5_mesh_data : public mesh_data
    109         {
    110         public:
    111                 friend class md5_loader;
    112                 friend class md5_mesh_instance;
    113                 md5_mesh_instance* spawn() const;
    114         private:
    115                 uint32*                       m_idata;
    116                 md5_vtx_t*                    m_tdata;
    117                 md5_vtx_pnt*                  m_pntdata;
    118                 std::string                   m_shader;
    119                 dynamic_array< transform >    m_bone_offset;
    120                 dynamic_array< md5_vtx_data > m_vtx_data;
    121         };
    122 
    123 
    12490        class md5_loader : public mesh_loader
    12591        {
     
    12995                virtual bool load( stream& source );
    13096                virtual mesh_data* release_mesh_data( size_t index = 0 );
     97                virtual mesh_nodes_data* release_mesh_nodes_data();
     98                // TODO: broken due to larger mesh_data structure!
     99                virtual mesh_data_pack* release_mesh_data_pack();
    131100                virtual size_t get_mesh_count() const { return m_meshes.size(); }
    132101        protected:
     
    151120                };
    152121        protected:
    153                 bool prepare_mesh( md5_mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info );
     122                bool prepare_mesh( uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info );
    154123        protected:
    155124                uint32 m_md5_version;
     
    157126                uint32 m_num_meshes;
    158127
    159                 dynamic_array<md5_joint>      m_joints;
    160                 dynamic_array<md5_mesh_data*> m_meshes;
     128                dynamic_array<md5_joint>  m_joints;
     129                dynamic_array<mesh_data*> m_meshes;
    161130        };
    162131
  • trunk/nv/formats/nmd_loader.hh

    r285 r287  
    2020                MESH,
    2121                STREAM,
    22                 BONE_ARRAY,
     22                NODE,
    2323                STRING_TABLE,
    2424                ANIMATION,
    25                 ANIMATION_NODE,
    26                 ANIMATION_CHANNEL,
     25                KEY_CHANNEL,
    2726        };
    2827
     
    4443        struct nmd_animation_header
    4544        {
    46                 float fps;
    47                 float duration;
    48                 bool  flat;
     45                uint16 frame_rate;
     46                float  duration;
     47                bool   flat;
    4948        };
    5049
    51         struct nmd_animation_node_header
     50        struct nmd_node_header
    5251        {
    5352                sint16 parent_id;
     
    5554        };
    5655
    57         struct nmd_animation_channel_header
     56        struct nmd_key_channel_header
    5857        {
    5958                key_descriptor format;
     
    6766        };
    6867
    69         struct nmd_bone
    70         {
    71                 uint16 name;
    72                 mat4   offset;
    73         };
    74 
    75         struct nmd_node
    76         {
    77                 uint16 name;
    78                 sint16 parent_id;
    79                 mat4   transform;
    80                 key_data* data;
    81         };
    82 
    83         struct nmd_animation
    84         {
    85                 float     fps;
    86                 float     duration;
    87                 bool      flat;
    88                 uint16    node_count;
    89                 nmd_node* nodes;
    90 
    91                 nmd_animation() : node_count(0), nodes( nullptr ) {}
    92                 ~nmd_animation()
    93                 {
    94                         for ( uint16 n = 0; n < node_count; ++n )
    95                         {
    96                                 if ( nodes[n].data ) delete nodes[n].data;
    97                         }
    98                         delete[] nodes;
    99                 }
    100         };
    101 
    102         struct nmd_bone_data
    103         {
    104                 nmd_bone* bones;
    105                 uint16    count;
    106 
    107                 nmd_bone_data() : count(0), bones( nullptr ) {}
    108                 ~nmd_bone_data()
    109                 {
    110                         if ( bones ) delete[] bones;
    111                 }
    112         };
    113 
    114 
    115 
    11668        class nmd_loader : public mesh_loader
    11769        {
    11870        public:
    119                 nmd_loader() : m_animation( nullptr ), m_bone_data( nullptr ), m_strings( nullptr ) {}
     71                nmd_loader() : m_node_data( nullptr ), m_node_array( nullptr ), m_strings( nullptr ) {}
    12072                virtual bool load( stream& source );
    12173                virtual mesh_data* release_mesh_data( size_t index = 0 );
    122                 virtual nmd_animation* release_animation();
    123                 virtual nmd_bone_data* release_bone_data();
    124                 virtual string_table* release_string_table();
     74                virtual mesh_nodes_data* release_mesh_nodes_data();
     75                virtual mesh_data_pack* release_mesh_data_pack();
    12576                virtual size_t get_mesh_count() const { return m_meshes.size(); }
    12677                virtual ~nmd_loader();
     
    12879                void reset();
    12980                bool load_mesh( stream& source, const nmd_element_header& e );
    130                 bool load_bones( stream& source, const nmd_element_header& e );
    13181                bool load_strings( stream& source );
    13282                bool load_animation( stream& source, const nmd_element_header& e );
    13383
    134                 nmd_animation*            m_animation;
    135                 nmd_bone_data*            m_bone_data;
     84                mesh_nodes_data*          m_node_data;
     85                mesh_node_data*           m_node_array;
    13686                string_table*             m_strings;
     87                std::vector< uint16 >     m_mesh_names;
     88                std::vector< uint16 >     m_node_names;
    13789                std::vector< mesh_data* > m_meshes;
    13890        };
    13991
    14092        // TODO: Temporary, find a better way and remove!
    141 
    142         class nmd_temp_model;
    143 
    144         class nmd_temp_animation
     93        class nmd_temp_model_data
    14594        {
     95                friend class nmd_temp_animation_data;
    14696        public:
    147                 nmd_temp_animation( nmd_loader* loader );
    148                 void prepare( const nmd_temp_model* model );
    149                 void animate( mat4* data, uint32 time );
    150                 virtual uint32 get_frame_rate() const { return uint32(m_animation->fps); }
    151                 virtual uint32 get_frame_count() const { return uint32(m_animation->duration) / uint32(m_animation->fps); }
    152                 ~nmd_temp_animation();
     97                nmd_temp_model_data( nmd_loader* loader );
     98                const mesh_data* get_data( uint32 index ) const { return m_mesh_data[index]; }
     99                uint32 get_count() const { return m_mesh_data.size(); }
     100                const mesh_nodes_data* get_node_data() const { return m_node_data; }
     101                ~nmd_temp_model_data();
    153102        private:
    154                 void animate_rec( mat4* data, float time, uint32 node_id, const mat4& parent_mat );
    155 
    156                 std::vector< key_data* > m_data;
    157                 std::vector< sint16 > m_bone_ids;
    158                 std::vector< std::vector< uint32 > > m_children;
    159                 const mat4*    m_offsets;
    160                 string_table*  m_strings;
    161                 nmd_animation* m_animation;
    162         };
    163 
    164         // TODO: Temporary, find a better way and remove!
    165         class nmd_temp_model
    166         {
    167                 friend class nmd_temp_animation;
    168         public:
    169                 nmd_temp_model( nmd_loader* loader );
    170                 const mesh_data* get_data( uint32 index ) const { return m_mesh_data[index]; }
    171                 uint32 get_bone_count() const { return m_bone_offsets.size(); }
    172                 uint32 get_count() const { return m_mesh_data.size(); }
    173                 ~nmd_temp_model();
    174         private:
    175                 std::unordered_map< std::string, nv::uint16 > m_bone_names;
    176                 std::vector< mat4 >      m_bone_offsets;
    177103                std::vector< mesh_data*> m_mesh_data;
     104                mesh_nodes_data*         m_node_data;
    178105        };
    179106
  • trunk/nv/formats/obj_loader.hh

    r240 r287  
    2626                obj_loader( bool normals = true, bool tangents = false );
    2727                virtual bool load( stream& source );
    28                 mesh_data* release_mesh_data( size_t index = 0 );
     28                virtual mesh_data* release_mesh_data( size_t index = 0 );
     29                virtual mesh_data_pack* release_mesh_data_pack();
    2930                virtual size_t get_mesh_count() const { return m_meshes.size(); }
    3031                ~obj_loader();
  • trunk/nv/gfx/animation.hh

    r286 r287  
    7373
    7474                        uint32 slot = 0;
    75                         int index    = -1;
     75                        int index0  = -1;
     76                        int index1  = -1;
    7677                        float factor = 1.0f;
    7778                        if ( desc.slots[0].vslot == animation_slot::TIME )
    7879                        {
     80                                NV_ASSERT( desc.slots[0].offset == 0, "time offset not zero!" );
    7981                                slot++;
    8082                                keyfresult--;
     
    8486                                        return keyfresult;
    8587                                }
    86                                 uint32 toffset = desc.slots[0].offset / 4;
    87                                 for ( int i = 0 ; i < (int)count - 1 ; i++ )
     88                                for ( int i = 1 ; i < (int)count ; i++ )
    8889                                {
    89                                         if ( time < fdata[ i * keyfsize + keyfsize + toffset ] ) { index = i; break; }
     90                                        if ( time < fdata[ i * keyfsize ] ) { index0 = i - 1; break; }
    9091                                }
    91                                 NV_ASSERT( index >= 0, "animation time fail!");
    92                                 float time0  = fdata[ index * keyfsize + toffset ];
    93                                 float time1  = fdata[ index * keyfsize + keyfsize + toffset ];
     92                                NV_ASSERT( index0 >= 0, "animation time fail!");
     93                                index1 = index0 + 1;
     94                                float time0  = fdata[ index0 * keyfsize ];
     95                                float time1  = fdata[ index1 * keyfsize ];
    9496                                float delta  = time1 - time0;
    9597                                factor = glm::clamp( (time - time0) / delta, 0.0f, 1.0f );
     
    102104                                        return keyfresult;
    103105                                }
    104                                 index  = glm::clamp<int>( int( time ), 0, count - 2 );
    105                                 factor = glm::clamp<float> ( time - index, 0.0f, 1.0f );
     106                                index0 = glm::clamp<int>( int( time ), 0, count - 2 );
     107                                index1 = index0 + 1;
     108                                factor = glm::clamp<float> ( time - index0, 0.0f, 1.0f );
    106109                        }
    107110                        uint32 ret = 0;
     
    110113                                ret += nv::interpolate_raw(
    111114                                        desc.slots[slot], factor,
    112                                         fdata + index * keyfsize + desc.slots[slot].offset / 4,
    113                                         fdata + index * keyfsize + keyfsize + desc.slots[slot].offset / 4,
     115                                        fdata + index0 * keyfsize + desc.slots[slot].offset / 4,
     116                                        fdata + index1 * keyfsize + desc.slots[slot].offset / 4,
    114117                                        result + ret );
    115118                        }
  • trunk/nv/gfx/keyframed_mesh.hh

    r285 r287  
    2424                        : animation_entry( name ), m_start( a_start ), m_frames( a_frames ), m_fps( a_fps ), m_looping( a_loop ) {}
    2525                virtual uint32 get_frame_rate() const { return m_fps; }
    26                 virtual uint32 get_frame_count() const { return m_frames; }
     26                virtual float get_duration() const { return (float)m_frames; }
    2727                virtual bool is_looping() const { return m_looping; }
    2828        protected:
     
    3737        {
    3838        public:
    39                 keyframed_mesh( device* a_device, mesh_data* a_data, tag_map* a_tag_map );
     39                keyframed_mesh( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map );
    4040                virtual size_t get_index_count() const { return m_index_count; }
    4141                virtual void run_animation( animation_entry* a_anim );
    4242                size_t get_max_frames() const;
    43                 transform get_tag( uint32 tag_id ) const;
     43                virtual transform get_node_transform( uint32 node_id ) const;
     44                virtual mat4 get_node_matrix( uint32 node_id ) const;
    4445                virtual void setup_animation( uint32 start, uint32 count, uint32 fps, bool loop );
    4546                virtual void set_frame( uint32 frame );
     
    5859                };
    5960
    60                 mesh_data* m_mesh_data;
    61                 tag_map*  m_tag_map;
     61                const mesh_data*      m_mesh_data;
     62                const mesh_nodes_data* m_tag_map;
    6263
    6364                uint32 m_start_frame;
     
    7980        {
    8081        public:
    81                 keyframed_mesh_gpu( device* a_device, mesh_data* a_data, tag_map* a_tag_map, program* a_program );
     82                keyframed_mesh_gpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map, program* a_program );
    8283                void update( uint32 ms );
    8384        private:
     
    9293        {
    9394        public:
    94                 keyframed_mesh_cpu( device* a_device, mesh_data* a_data, tag_map* a_tag_map );
     95                keyframed_mesh_cpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map );
    9596                void update( uint32 ms );
    9697        private:
  • trunk/nv/gfx/skeletal_mesh.hh

    r283 r287  
    3737        {
    3838        public:
    39                 skeletal_mesh( device* a_device, md5_mesh_data* a_mesh_data );
    40                 virtual size_t get_index_count() const { return m_mesh_data->get_index_count(); }
     39                skeletal_mesh( device* a_device, const mesh_data* a_mesh_data, const mesh_nodes_data* bones );
     40                virtual size_t get_index_count() const { return m_indices; }
    4141                virtual void run_animation( animation_entry* a_anim );
    4242                virtual void update_animation( animation_entry* a_anim, uint32 a_anim_time );
    4343                virtual ~skeletal_mesh();
    4444        protected:
    45                 md5_mesh_instance* m_mesh_data;
    46                 std::vector< transform > m_transform;
     45                uint32                       m_indices;
     46                dynamic_array< md5_vtx_pnt > m_pntdata;
     47                dynamic_array< transform >   m_pos_offset;
     48                dynamic_array< transform >   m_bone_offset;
     49;
     50                const mesh_data*             m_data;
     51                const md5_vtx_pntiw*         m_vtx_data;
     52                dynamic_array< transform >   m_transform;
    4753        };
    4854
     
    5056        {
    5157        public:
    52                 skeletal_animation_entry_gpu( const std::string& name, nmd_temp_animation* anim, bool a_looping )
    53                         : animation_entry( name ), m_animation( anim ), m_looping( a_looping ), m_prepared( false ) {}
    54                 virtual uint32 get_frame_rate() const { return 0; }
    55                 virtual uint32 get_frame_count() const { return 0; }
     58                skeletal_animation_entry_gpu( const std::string& name, const mesh_nodes_data* anim, bool a_looping );
     59                virtual uint32 get_frame_rate() const { return m_node_data->get_frame_rate(); }
     60                virtual float get_duration() const { return m_node_data->get_duration(); }
    5661                virtual bool is_looping() const { return m_looping; }
    57                 void prepare( const nmd_temp_model* m_model );
    58                 void update_skeleton( mat4* tr, uint32 time );
     62                void prepare( const mesh_nodes_data* bones );
     63                void update_skeleton( mat4* tr, uint32 time ) const;
     64                ~skeletal_animation_entry_gpu();
    5965        protected:
    60                 nmd_temp_animation* m_animation;
    61                 bool           m_prepared;
    62                 bool           m_looping;
     66                void animate_rec( mat4* data, float time, uint32 node_id, const mat4& parent_mat ) const;
     67                const mesh_nodes_data* m_node_data;
     68                std::vector< uint32 >* m_children;
     69                sint16* m_bone_ids;
     70                mat4* m_offsets;
     71                bool m_prepared;
     72                bool m_looping;
    6373        };
    6474
     
    6676        {
    6777        public:
    68                 skeletal_mesh_gpu( device* a_device, const nmd_temp_model* a_model, uint32 index, bool primary );
     78                skeletal_mesh_gpu( device* a_device, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data );
    6979                virtual size_t get_index_count() const { return m_index_count; }
    7080                virtual void run_animation( animation_entry* a_anim );
     
    7282                virtual void update_animation( animation_entry* a_anim, uint32
    7383                        a_anim_time );
     84                virtual transform get_node_transform( uint32 node_id ) const;
     85                virtual mat4 get_node_matrix( uint32 node_id ) const;
     86                ~skeletal_mesh_gpu() { delete m_transform; }
    7487        protected:
    75                 const nmd_temp_model* m_model;
    76                 bool m_primary;
     88                const mesh_nodes_data* m_bone_data;
    7789                uint32 m_index_count;
    78                 std::vector< mat4 > m_transform;
     90                mat4* m_transform;
    7991        };
    8092
  • trunk/nv/handle.hh

    r274 r287  
    244244                }
    245245
     246                const value_type* get( handle h ) const
     247                {
     248                        if ( h.is_nil() ) return nullptr;
     249                        sint32 eindex = m_indexes.get_index( h );
     250                        return eindex >= 0 ? &(m_data[ eindex ]) : nullptr;
     251                }
     252
    246253                value_type* get( handle h )
    247254                {
  • trunk/nv/interface/animated_mesh.hh

    r285 r287  
    2828                virtual const std::string& get_name() const { return m_name; }
    2929                virtual uint32 get_frame_rate() const = 0;
    30                 virtual uint32 get_frame_count() const = 0;
     30                virtual float get_duration() const = 0;
    3131                virtual bool is_looping() const = 0;
    3232                virtual ~animation_entry() {}
     
    4141                virtual void update_animation( animation_entry*, uint32 ) {}
    4242                virtual void run_animation( animation_entry* ) {}
    43                 virtual transform get_tag( uint32 ) const { return transform(); }
    44 
     43                virtual transform get_node_transform( uint32 ) const { return transform(); }
     44                virtual mat4 get_node_matrix( uint32 ) const { return mat4(); }
    4545        };
    4646
  • trunk/nv/interface/device.hh

    r280 r287  
    104104                        {
    105105                                const mesh_raw_channel* channel = channels[ch];
    106                                 if ( channel->is_index() )
     106                                if ( channel->count > 0 )
    107107                                {
    108                                         index_buffer* ib = create_index_buffer( hint, channel->size(), channel->data );
    109                                         va->set_index_buffer( ib, channel->desc.slots[0].etype, true );
    110                                 }
    111                                 else
    112                                 {
    113                                         vertex_buffer* vb = create_vertex_buffer( hint, channel->size(), channel->data );
    114                                         va->add_vertex_buffers( vb, channel );
     108                                        if ( channel->is_index() )
     109                                        {
     110                                                index_buffer* ib = create_index_buffer( hint, channel->size(), channel->data );
     111                                                va->set_index_buffer( ib, channel->desc.slots[0].etype, true );
     112                                        }
     113                                        else
     114                                        {
     115                                                vertex_buffer* vb = create_vertex_buffer( hint, channel->size(), channel->data );
     116                                                va->add_vertex_buffers( vb, channel );
     117                                        }
    115118                                }
    116119                        }
  • trunk/nv/interface/mesh_data.hh

    r281 r287  
    7979        {
    8080        public:
    81                 mesh_data() : m_index_channel( nullptr ) {}
     81                explicit mesh_data() : m_index_channel( nullptr ) {}
     82                explicit mesh_data( const std::string& name ) : m_name(name), m_index_channel( nullptr ) {}
     83
    8284                void add_channel( mesh_raw_channel* channel )
    8385                {
     
    137139                }
    138140
     141                void set_name( const std::string& name ) { m_name = name; }
     142                const std::string& get_name() const { return m_name; }
     143
     144                void move_to( mesh_data& other )
     145                {
     146                        other.m_name          = m_name;
     147                        other.m_index_channel = m_index_channel;
     148                        for ( auto c : m_channels )
     149                        {
     150                                other.m_channels.push_back( c );
     151                        }
     152                        m_channels.clear();
     153                        m_index_channel = nullptr;
     154                }
     155
    139156                virtual ~mesh_data()
    140157                {
     
    142159                }
    143160        private:
     161                std::string                      m_name;
    144162                std::vector< mesh_raw_channel* > m_channels;
    145163                mesh_raw_channel*                m_index_channel;
    146164        };
    147165
    148 
    149166}
    150167
  • trunk/nv/interface/mesh_loader.hh

    r285 r287  
    2626{
    2727
    28         // TODO: change to generic nodes!
    29         class tag_map
    30         {
    31         public:
    32                 typedef std::unordered_map< std::string, uint32 > map;
    33 
    34                 tag_map() {}
    35 
    36                 const key_data* get_tag( uint32 id ) const
    37                 {
    38                         return m_data[id];
    39                 }
    40                 uint32 get_tag_id( const std::string& key ) const
    41                 {
    42                         return m_map.at( key );
    43                 }
    44                 void insert( const std::string& key, key_data* chan )
    45                 {
    46                         m_map[ key ] = m_data.size();
    47                         m_data.push_back( chan );
    48                 }
    49                 ~tag_map()
    50                 {
    51                         for ( auto t : m_data )
    52                                 delete t;
    53                 }
    54         private:
    55                 std::vector< key_data* > m_data;
    56                 map m_map;
    57         };
    58 
    5928        struct mesh_node_data
    6029        {
     
    6635        };
    6736
     37        class mesh_nodes_data
     38        {
     39        public:
     40                explicit mesh_nodes_data( const string& name, uint32 count, mesh_node_data* nodes )
     41                        : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(0), m_duration(0.0f), m_flat( false )
     42                {
     43                }
     44
     45                explicit mesh_nodes_data( const string& name, uint32 count, mesh_node_data* nodes,
     46                        uint16 a_fps, float a_frames, bool a_flat )
     47                        : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat )
     48                {
     49                }
     50
     51                size_t get_count() const { return m_count; }
     52
     53                const mesh_node_data* get_node( size_t i ) const
     54                {
     55                        if ( i >= m_count ) return nullptr;
     56                        return &m_nodes[i];
     57                }
     58
     59                key_data* release_node_data( size_t i )
     60                {
     61                        key_data* result = m_nodes[i].data;
     62                        m_nodes[i].data = nullptr;
     63                        return result;
     64                }
     65
     66                bool is_flat() const { return m_flat; }
     67                uint16 get_frame_rate() const { return m_frame_rate; }
     68                float get_duration() const { return m_duration; }
     69                void set_name( const std::string& name ) { m_name = name; }
     70                const string& get_name() const { return m_name; }
     71
     72                ~mesh_nodes_data()
     73                {
     74                        if ( m_count > 0 )
     75                                for ( uint32 i = 0; i < m_count; ++i ) delete m_nodes[i].data;
     76                        delete[] m_nodes;
     77                }
     78
     79        private:
     80                string m_name;
     81                uint32 m_count;
     82                mesh_node_data* m_nodes;
     83                uint16  m_frame_rate;
     84                float   m_duration;
     85                bool    m_flat;
     86        };
     87
     88        class mesh_data_pack
     89        {
     90        public:
     91                explicit mesh_data_pack( uint32 a_count, mesh_data* a_meshes, mesh_nodes_data* a_nodes = nullptr )
     92                {
     93                        m_count  = a_count;
     94                        m_meshes = a_meshes;
     95                        m_nodes  = a_nodes;
     96                }
     97                const mesh_data* get_mesh( uint32 index ) const
     98                {
     99                        if ( index >= m_count ) return nullptr;
     100                        return &m_meshes[ index ];
     101                }
     102                uint32 get_count() const { return m_count; }
     103                const mesh_nodes_data* get_nodes() const { return m_nodes; }
     104                ~mesh_data_pack()
     105                {
     106                        delete[] m_meshes;
     107                        delete   m_nodes;
     108                }
     109        private:
     110                uint32           m_count;
     111                mesh_data*       m_meshes;
     112                mesh_nodes_data* m_nodes;
     113        };
     114
     115
    68116        class mesh_loader
    69117        {
     
    71119                mesh_loader() {}
    72120                virtual ~mesh_loader() {}
    73                 virtual tag_map* create_tag_map() { return nullptr; }
    74121                virtual bool load( stream& source ) = 0;
    75122                virtual mesh_data* release_mesh_data( size_t index = 0 ) = 0;
     123                virtual mesh_data_pack* release_mesh_data_pack() = 0;
    76124                virtual size_t get_mesh_count() const = 0;
    77                 virtual mesh_node_data* release_mesh_node_data( size_t ) { return nullptr; }
    78                 virtual size_t get_node_count() const { return 0; }
     125                virtual mesh_nodes_data* release_mesh_nodes_data() { return nullptr; }
    79126        };
    80127
  • trunk/nv/interface/program.hh

    r277 r287  
    140140                        // }
    141141                        // TODO: nicer check
    142                         NV_ASSERT( count <= base->get_length(), "LENGTH CHECK FAIL" );
     142                        NV_ASSERT( (int)count <= base->get_length(), "LENGTH CHECK FAIL" );
    143143                        ((uniform<T>*)( base ))->set_value( value, count );
    144144                }
  • trunk/src/formats/assimp_loader.cc

    r285 r287  
    7979{
    8080        if ( index >= m_mesh_count ) return nullptr;
    81         mesh_data* result = new mesh_data();
     81        mesh_data* result = new mesh_data;
     82        load_mesh_data( result, index );
     83        return result;
     84}
     85void nv::assimp_loader::load_mesh_data( mesh_data* data, size_t index )
     86{
    8287        const aiScene* scene = (const aiScene*)m_scene;
    8388        const aiMesh*  mesh  = scene->mMeshes[ index ];
     89        data->set_name( mesh->mName.data );
    8490
    8591        vec3 vertex_offset     = glm::vec3();
     
    94100                channel = mesh_raw_channel::create< assimp_plain_vtx >( mesh->mNumVertices );
    95101
    96         result->add_channel( channel );
     102        data->add_channel( channel );
    97103        for (unsigned int i=0; i<mesh->mNumVertices; i++)
    98104        {
     
    139145
    140146        mesh_raw_channel* ichannel = mesh_raw_channel::create_index( USHORT, mesh->mNumFaces * 3 );
    141         result->add_channel( ichannel );
     147        data->add_channel( ichannel );
    142148        uint16* indices = (uint16*)ichannel->data;
    143149        for (unsigned int i=0; i<mesh->mNumFaces; i++)
     
    149155                }
    150156        }
    151 
    152         return result;
    153157}
    154158
     
    322326        const aiAnimation* anim = scene->mAnimations[0]; // if implemented, change in load_node also
    323327
    324         result->fps            = (float)anim->mTicksPerSecond;
     328        result->frame_rate     = (uint16)anim->mTicksPerSecond;
    325329        result->duration       = (float)anim->mDuration;
    326         result->pretransformed = pre_transform;
     330        result->flat           = pre_transform;
     331        result->max_frames     = 0;
    327332
    328333        load_node( result, root, 0, -1 );
     334
     335        // DAE pre_transform hack
     336        if ( result->flat && result->frame_rate == 1 )
     337        {
     338                result->frame_rate = 32;
     339                result->duration   = (float)result->max_frames;
     340        }
     341
    329342        return result;
    330343}
     
    371384        if (anode)
    372385        {
    373                 if ( data->pretransformed )
     386                if ( data->flat )
    374387                {
    375388                        create_transformed_keys( &a_data, anode, parent_id >= 0 ? &(data->nodes[ parent_id ]) : nullptr );
     
    379392                        create_direct_keys( &a_data, anode );
    380393                }
     394                data->max_frames = glm::max<uint32>( a_data.data->get_channel(0)->count, data->max_frames );
    381395        }
    382396
     
    386400                next = load_node( data, node->mChildren[i], next, this_id );
    387401        }
     402
    388403        return next;
    389404}
     
    432447        key_raw_channel* raw_pchannel = key_raw_channel::create<assimp_key_p>( node->mNumPositionKeys );
    433448        key_raw_channel* raw_rchannel = key_raw_channel::create<assimp_key_r>( node->mNumRotationKeys );
    434         key_raw_channel* raw_schannel = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys );
     449        //key_raw_channel* raw_schannel = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys );
    435450        data->data->add_channel( raw_pchannel );
    436451        data->data->add_channel( raw_rchannel );
    437         data->data->add_channel( raw_schannel );
     452        //data->data->add_channel( raw_schannel );
    438453        assimp_key_p* pchannel = ((assimp_key_p*)(raw_pchannel->data));
    439454        assimp_key_r* rchannel = ((assimp_key_r*)(raw_rchannel->data));
    440         assimp_key_s* schannel = ((assimp_key_s*)(raw_schannel->data));
     455        //assimp_key_s* schannel = ((assimp_key_s*)(raw_schannel->data));
    441456
    442457        for ( unsigned np = 0; np < node->mNumPositionKeys; ++np )
     
    450465                rchannel[np].rotation = glm::quat_cast( m_r33 * glm::mat3_cast( assimp_quat_cast(node->mRotationKeys[np].mValue ) ) * m_ri33 );
    451466        }
    452         if ( node->mNumScalingKeys > 0 )
    453         {
    454                 nv::vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue );
    455                 float scale_value   = glm::length( glm::abs( scale_vec0 - nv::vec3(1,1,1) ) );
    456                 if ( node->mNumScalingKeys > 1 || scale_value > 0.001 )
    457                 {
    458                         NV_LOG( nv::LOG_WARNING, "scale key significant!" );
    459                         for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
    460                         {
    461                                 schannel[np].time  = (float)node->mScalingKeys[np].mTime;
    462                                 schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue);
    463                         }
    464                 }
    465                 else
    466                 {
    467                         schannel[0].time  = (float)node->mScalingKeys[0].mTime;
    468                         schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue);
    469                 }
    470         }
    471 
    472 }
    473 
     467//      if ( node->mNumScalingKeys > 0 )
     468//      {
     469//              nv::vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue );
     470//              float scale_value   = glm::length( glm::abs( scale_vec0 - nv::vec3(1,1,1) ) );
     471//              if ( node->mNumScalingKeys > 1 || scale_value > 0.001 )
     472//              {
     473//                      NV_LOG( nv::LOG_WARNING, "scale key significant!" );
     474//                      for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
     475//                      {
     476//                              schannel[np].time  = (float)node->mScalingKeys[np].mTime;
     477//                              schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue);
     478//                      }
     479//              }
     480//              else
     481//              {
     482//                      schannel[0].time  = (float)node->mScalingKeys[0].mTime;
     483//                      schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue);
     484//              }
     485//      }
     486
     487}
     488
     489mesh_data_pack* nv::assimp_loader::release_mesh_data_pack()
     490{
     491        mesh_data* meshes = new mesh_data[ m_mesh_count ];
     492        for ( uint32 i = 0; i < m_mesh_count; ++i )
     493        {
     494                load_mesh_data(&meshes[i],i);
     495        }
     496        return new mesh_data_pack( m_mesh_count, meshes, release_mesh_nodes_data() );
     497}
     498
     499mesh_nodes_data* nv::assimp_loader::release_mesh_nodes_data()
     500{
     501        // TODO: implement
     502        return nullptr;
     503}
     504
  • trunk/src/formats/md2_loader.cc

    r280 r287  
    315315mesh_data* nv::md2_loader::release_mesh_data( size_t )
    316316{
    317         return release_mesh_frame( -1 );
    318 }
    319 
    320 mesh_data* nv::md2_loader::release_mesh_frame( sint32 frame )
     317        mesh_data* data = new mesh_data( "md2_mesh" );
     318        release_mesh_frame( data, -1 );
     319        return data;
     320}
     321
     322void nv::md2_loader::release_mesh_frame( mesh_data* data, sint32 frame )
    321323{
    322324        md2_t* md2 = (md2_t*)m_md2;
     
    366368        }
    367369
    368         mesh_data* result = new mesh_data();
    369         result->add_channel( mc_pn );
    370         result->add_channel( mc_t );
    371         result->add_channel( ic );
    372         return result;
    373 }
     370        data->add_channel( mc_pn );
     371        data->add_channel( mc_t );
     372        data->add_channel( ic );
     373}
     374
     375mesh_data_pack* nv::md2_loader::release_mesh_data_pack()
     376{
     377        mesh_data* data = new mesh_data[1];
     378        release_mesh_frame( &data[0], -1 );
     379        return new mesh_data_pack( 1, data );
     380}
  • trunk/src/formats/md3_loader.cc

    r285 r287  
    321321mesh_data* nv::md3_loader::release_mesh_data( size_t )
    322322{
    323         return release_mesh_frame( -1 );
    324 }
    325 
    326 mesh_data* nv::md3_loader::release_mesh_frame( sint32 frame )
     323        mesh_data* data = new mesh_data;
     324        release_mesh_frame( data, -1 );
     325        return data;
     326}
     327
     328void nv::md3_loader::release_mesh_frame( mesh_data* data, sint32 frame )
    327329{
    328330        md3_t* md3 = (md3_t*)m_md3;
     
    394396        }
    395397
    396         mesh_data* result = new mesh_data();
    397         result->add_channel( mc_pn );
    398         result->add_channel( mc_t );
    399         result->add_channel( ic );
    400         return result;
    401 }
    402 
    403 tag_map* nv::md3_loader::create_tag_map()
     398        data->set_name( (char*)md3->header.name );
     399        data->add_channel( mc_pn );
     400        data->add_channel( mc_t );
     401        data->add_channel( ic );
     402}
     403
     404mesh_nodes_data* nv::md3_loader::release_mesh_nodes_data()
    404405{
    405406        md3_t* md3 = (md3_t*)m_md3;
    406         tag_map* result = new tag_map();
    407         for ( sint32 i = 0; i < md3->header.num_tags; ++i )
     407        uint32 node_count = md3->header.num_tags;
     408        if ( node_count == 0 ) return nullptr;;
     409        mesh_node_data* nodes = new mesh_node_data[ node_count ];
     410        for ( uint32 i = 0; i < node_count; ++i )
    408411        {
    409412                const md3_tag_t& rtag = md3->tags[i];
    410413                std::string name( (char*)(rtag.name) );
    411414
    412                 key_data* data = new key_data;
    413                 data->add_channel( load_tags( name ) );
    414                 result->insert( name, data );
    415         }
    416         return result;
    417 }
    418 
    419 mesh_node_data* nv::md3_loader::release_mesh_node_data( size_t index )
    420 {
    421         md3_t* md3 = (md3_t*)m_md3;
    422         const md3_tag_t& rtag = md3->tags[index];
    423         std::string name( (char*)(rtag.name) );
    424 
    425         mesh_node_data* result = new mesh_node_data;
    426         result->transform = mat4();
    427         result->name      = name;
    428         result->parent_id = -1;
    429         result->target_id = -1;
    430         result->data = new key_data;
     415                nodes[i].transform = mat4();
     416                nodes[i].name      = name;
     417                nodes[i].parent_id = -1;
     418                nodes[i].target_id = -1;
     419                nodes[i].data = new key_data;
    431420       
    432         key_raw_channel* keys = load_tags( name );
    433         result->data->add_channel( keys );
    434         return result;
    435 }
    436 
    437 size_t nv::md3_loader::get_node_count() const
    438 {
    439         return ((md3_t*)m_md3)->header.num_tags;
     421                key_raw_channel* keys = load_tags( name );
     422                nodes[i].data->add_channel( keys );
     423        }
     424        return new mesh_nodes_data( "tags", node_count, nodes );
     425}
     426
     427mesh_data_pack* nv::md3_loader::release_mesh_data_pack()
     428{
     429        mesh_data* data = new mesh_data[1];
     430        release_mesh_frame( &data[0], -1 );
     431        return new mesh_data_pack( 1, data, release_mesh_nodes_data() );
    440432}
    441433
  • trunk/src/formats/md5_loader.cc

    r282 r287  
    1010#include "nv/logging.hh"
    1111#include "nv/io/std_stream.hh"
    12 #include "nv/profiler.hh"
    1312#include <cstring>
    1413
     
    4544bool md5_loader::load( stream& source )
    4645{
    47         NV_PROFILE( "Load MD5" ); // 16XXms original
    4846        std_stream sstream( &source );
    4947        std::string command;
     
    9694                else if ( command == "mesh" )
    9795                {
    98                         md5_mesh_data* mesh = new md5_mesh_data();
    99 
    100                         int num_verts, num_tris, num_weights;
     96                        mesh_data* mesh = new mesh_data("md5_mesh");
     97
     98                        int num_verts   = 0;
     99                        int num_tris    = 0;
     100                        int num_weights = 0;
    101101
    102102                        discard( sstream, "{" );
     
    106106                                if ( command == "shader" )
    107107                                {
    108                                         sstream >> mesh->m_shader;
    109                                         remove_quotes( mesh->m_shader );
    110                                         // texturePath.replace_extension( ".tga" );
     108                                        std::string shader;
     109                                        sstream >> shader;
     110                                        remove_quotes( shader );
    111111                                        next_line( sstream );
    112112                                }
     
    115115                                        sstream >> num_verts;
    116116
     117                                        md5_vtx_t* tdata = nullptr;
    117118                                        {
    118119                                                mesh_raw_channel* ch_pnt = mesh_raw_channel::create<md5_vtx_pnt>( num_verts );
    119120                                                mesh_raw_channel* ch_t   = mesh_raw_channel::create<md5_vtx_t>( num_verts );
    120                                                 mesh->m_pntdata          = (md5_vtx_pnt*)ch_pnt->data;
    121                                                 mesh->m_tdata            = (md5_vtx_t*)ch_t->data;
     121                                                mesh_raw_channel* ch_pntiw = mesh_raw_channel::create<md5_vtx_pntiw>( num_verts );
     122                                                tdata = (md5_vtx_t*)ch_t->data;
    122123                                                mesh->add_channel( ch_pnt );
    123124                                                mesh->add_channel( ch_t );
     125                                                // TODO: hack to prevent rendering
     126                                                ch_pntiw->count = 0;
     127                                                mesh->add_channel( ch_pntiw );
    124128                                        }
    125                                         mesh->m_vtx_data.resize( num_verts );
    126129                                        weight_info.resize( num_verts );
    127130
     
    138141                                                weight_info[i].start_weight = start_weight;
    139142                                                weight_info[i].weight_count = weight_count;
    140                                                 mesh->m_tdata[i].texcoord = texcoord;
     143                                                tdata[i].texcoord = texcoord;
    141144                                        } 
    142145                                }
     
    147150                                        mesh_raw_channel* ch_i = mesh_raw_channel::create_index<uint32>( num_tris * 3 );
    148151                                        uint32* vtx_i                = (uint32*)ch_i->data;
    149                                         mesh->m_idata                = vtx_i;
    150152                                        uint32 idx = 0;
    151153                                        mesh->add_channel( ch_i );
     
    190192                        }
    191193
    192                         prepare_mesh( mesh, weights.data(), weight_info.data() );
     194                        prepare_mesh( weight_info.size(), mesh, weights.data(), weight_info.data() );
    193195
    194196                        m_meshes[ m_num_meshes ] = mesh;
     
    201203}
    202204
    203 bool md5_loader::prepare_mesh( md5_mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info )
    204 {
    205         uint32 vtx_count = mdata->m_vtx_data.size();
    206         md5_vtx_pnt* vtcs = mdata->m_pntdata;
    207 
    208         mdata->m_bone_offset.resize( m_joints.size() );
    209         for ( uint32 i = 0; i < m_joints.size(); ++i )
    210         {
    211                 transform j( m_joints[i].pos, m_joints[i].orient );
    212                 mdata->m_bone_offset[i] = j.inverse();
    213         }
     205bool md5_loader::prepare_mesh( uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info )
     206{
     207        md5_vtx_pnt* vtcs = (md5_vtx_pnt*)mdata->get_channel< md5_vtx_pnt >()->data;
     208        md5_vtx_pntiw* vtx_data = (md5_vtx_pntiw*)mdata->get_channel< md5_vtx_pntiw >()->data;
    214209
    215210        for ( uint32 i = 0; i < vtx_count; ++i )
     
    217212                size_t start_weight = weight_info[i].start_weight;
    218213                size_t weight_count = weight_info[i].weight_count;
    219                 md5_vtx_data& vdata = mdata->m_vtx_data[i];
     214                md5_vtx_pntiw& vdata = vtx_data[i];
    220215                md5_vtx_pnt& vtc = vtcs[i];
    221216
     
    268263        }
    269264
     265        const uint32*    idata = (uint32*)mdata->get_index_channel()->data;
     266        const md5_vtx_t* tdata = mdata->get_channel_data<md5_vtx_t>();
     267
    270268        // Prepare normals
    271269        uint32 tri_count = mdata->get_count() / 3;
    272270        for ( unsigned int i = 0; i < tri_count; ++i )
    273271        {
    274                 uint32 ti0 = mdata->m_idata[ i * 3 ];
    275                 uint32 ti1 = mdata->m_idata[ i * 3 + 1 ];
    276                 uint32 ti2 = mdata->m_idata[ i * 3 + 2 ];
     272                uint32 ti0 = idata[ i * 3 ];
     273                uint32 ti1 = idata[ i * 3 + 1 ];
     274                uint32 ti2 = idata[ i * 3 + 2 ];
    277275 
    278276                glm::vec3 v1 = vtcs[ ti0 ].position;
     
    288286                vtcs[ ti2 ].normal += normal;
    289287
    290                 const vec2& w1 = mdata->m_tdata[ ti0 ].texcoord;
    291                 const vec2& w2 = mdata->m_tdata[ ti1 ].texcoord;
    292                 const vec2& w3 = mdata->m_tdata[ ti2 ].texcoord;
     288                const vec2& w1 = tdata[ ti0 ].texcoord;
     289                const vec2& w2 = tdata[ ti1 ].texcoord;
     290                const vec2& w3 = tdata[ ti2 ].texcoord;
    293291
    294292                vec2 st1 = w3 - w1;
     
    306304        for ( size_t i = 0; i < vtx_count; ++i )
    307305        {
    308                 md5_vtx_data& vdata = mdata->m_vtx_data[i];
     306                md5_vtx_pntiw& vdata = vtx_data[i];
    309307
    310308                glm::vec3 normal  = glm::normalize( vtcs[i].normal );
     
    541539}
    542540
    543 md5_mesh_instance* nv::md5_mesh_data::spawn() const
    544 {
    545         return new md5_mesh_instance( this );
    546 }
     541mesh_nodes_data* nv::md5_loader::release_mesh_nodes_data()
     542{
     543        mesh_node_data* nodes = new mesh_node_data[ m_num_joints ];
     544        for ( uint32 i = 0; i < m_num_joints; ++i )
     545        {
     546                mesh_node_data& node = nodes[i];
     547                node.name      = m_joints[i].name;
     548                node.target_id = -1;
     549                node.parent_id = -1;
     550                node.transform = transform( m_joints[i].pos, m_joints[i].orient ).inverse().extract();
     551                node.data      = nullptr;
     552        }
     553        return new mesh_nodes_data( "nodes", m_num_joints, nodes );
     554}
     555
     556mesh_data_pack* nv::md5_loader::release_mesh_data_pack()
     557{
     558        uint32 size = m_meshes.size();
     559        mesh_data* meshes = new mesh_data[ size ];
     560        for ( uint32 i = 0; i < size; ++i )
     561        {
     562                m_meshes[i]->move_to( meshes[i] );
     563                delete m_meshes[i];
     564                m_meshes[i] = nullptr;
     565        }
     566        return new mesh_data_pack( size, meshes, release_mesh_nodes_data() );
     567}
     568
    547569
    548570nv::md5_loader::~md5_loader()
     
    551573}
    552574
    553 nv::md5_mesh_instance::md5_mesh_instance( const md5_mesh_data* a_data )
    554         : m_data( a_data ), m_indices( 0 )
    555 {
    556         m_indices = m_data->get_count();
    557         m_pntdata.assign( m_data->m_pntdata, m_data->m_vtx_data.size() );
    558 }
    559 
    560 void nv::md5_mesh_instance::apply( const transform* skeleton )
    561 {
    562         NV_PROFILE("md5::apply");
    563         size_t skeleton_size = m_data->m_bone_offset.size();
    564         size_t vertex_count  = m_pntdata.size();
    565         m_pos_offset.resize( skeleton_size );
    566         for ( unsigned int i = 0; i < skeleton_size; ++i )
    567         {
    568                 m_pos_offset[i] = skeleton[i] * m_data->m_bone_offset[i];
    569         }
    570 
    571         std::fill( m_pntdata.raw_data(), m_pntdata.raw_data() + m_pntdata.raw_size(), 0 );
    572         for ( unsigned int i = 0; i < vertex_count; ++i )
    573         {
    574                 const md5_vtx_data& vert = m_data->m_vtx_data[i];
    575                 md5_vtx_pnt& result = m_pntdata[i];
    576 
    577                 for ( size_t j = 0; j < 4; ++j )
    578                 {
    579                         int   index  = vert.boneindex[j];
    580                         float weight = vert.boneweight[j];
    581                         const quat& orient      = skeleton[index].get_orientation();
    582                         const transform& offset = m_pos_offset[index];
    583                         result.position += offset.transformed( vert.position )        * weight;
    584                         result.normal   += ( orient * vert.normal  ) * weight;
    585                         result.tangent  += ( orient * vert.tangent ) * weight;
    586                 }
    587         }
    588 }
  • trunk/src/formats/nmd_loader.cc

    r285 r287  
    77#include "nv/formats/nmd_loader.hh"
    88#include "nv/io/std_stream.hh"
     9#include "nv/string.hh"
    910
    1011using namespace nv;
     
    2425                case nmd_type::MESH           : load_mesh( source, element_header ); break;
    2526                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;
     
    4747                mesh->add_channel( channel );
    4848        }
     49        m_mesh_names.push_back( e.name );
    4950        m_meshes.push_back( mesh );
    5051        return true;
     
    5455{
    5556        mesh_data* result = m_meshes[ index ];
     57        if ( m_strings ) result->set_name( m_strings->get( m_mesh_names[ index ] ) );
    5658        m_meshes[ index ] = nullptr;
    5759        return result;
     60}
     61
     62mesh_data_pack* nv::nmd_loader::release_mesh_data_pack()
     63{
     64        uint32 size = m_meshes.size();
     65        mesh_data* meshes = new mesh_data[ size ];
     66        for ( uint32 i = 0; i < size; ++i )
     67        {
     68                m_meshes[i]->move_to( meshes[i] );
     69                delete m_meshes[i];
     70        }
     71        m_meshes.clear();
     72        return new mesh_data_pack( size, meshes, release_mesh_nodes_data() );
    5873}
    5974
     
    6176{
    6277        for ( auto mesh : m_meshes ) if ( mesh ) delete mesh;
    63         if ( m_animation ) delete m_animation;
    6478        if ( m_strings )   delete m_strings;
    65         if ( m_bone_data ) delete m_bone_data;
     79        if ( m_node_data ) delete m_node_data;
    6680        m_meshes.clear();
    67         m_animation = nullptr;
    68         m_bone_data = nullptr;
    69         m_strings   = nullptr;
     81        m_mesh_names.clear();
     82        m_node_names.clear();
     83
     84        m_node_data  = nullptr;
     85        m_node_array = nullptr;
     86        m_strings    = nullptr;
    7087}
    7188
     
    8299}
    83100
    84 bool nv::nmd_loader::load_bones( stream& source, const nmd_element_header& e )
    85 {
    86         NV_ASSERT( m_bone_data == nullptr, "MULTIPLE BONE ENTRIES!" );
    87         m_bone_data = new nmd_bone_data;
    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 );
    91         return true;
    92 }
    93 
    94 nmd_animation* nv::nmd_loader::release_animation()
    95 {
    96         nmd_animation* result = m_animation;
    97         m_animation = nullptr;
    98         return result;
    99 }
    100 
    101 nmd_bone_data* nv::nmd_loader::release_bone_data()
    102 {
    103         nmd_bone_data* result = m_bone_data;
    104         m_bone_data = nullptr;
    105         return result;
    106 }
    107 
    108 string_table* nv::nmd_loader::release_string_table()
    109 {
    110         string_table* result = m_strings;
    111         m_strings = nullptr;
    112         return result;
    113 }
    114 
    115 
    116101bool nv::nmd_loader::load_animation( stream& source, const nmd_element_header& e )
    117102{
    118         NV_ASSERT( m_animation == nullptr, "MULTIPLE ANIMATION ENTRIES!" );
    119         nmd_animation_header header;
    120         source.read( &header, sizeof( header ), 1 );
    121         m_animation = new nmd_animation;
    122         m_animation->fps        = header.fps;
    123         m_animation->duration   = header.duration;
    124         m_animation->flat       = header.flat;
    125         m_animation->node_count = (uint16)e.children;
    126         m_animation->nodes      = new nmd_node[ e.children ];
     103        NV_ASSERT( m_node_data == nullptr, "MULTIPLE NODE ENTRIES!" );
     104        nmd_animation_header animation_header;
     105        source.read( &animation_header, sizeof( animation_header ), 1 );
     106        m_node_array = new mesh_node_data[ e.children ];
    127107        for ( uint32 i = 0; i < e.children; ++i )
    128108        {
    129109                nmd_element_header element_header;
    130110                source.read( &element_header, sizeof( element_header ), 1 );
    131                 NV_ASSERT( element_header.type == nmd_type::ANIMATION_NODE, "ANIMATION_NODE expected!" );
    132                 m_animation->nodes[i].name          = element_header.name;
    133 
     111                NV_ASSERT( element_header.type == nmd_type::NODE, "NODE expected!" );
     112                m_node_names.push_back( element_header.name );
    134113                uint16 ch_count = element_header.children;
    135114
    136                 nmd_animation_node_header node_header;
     115                nmd_node_header node_header;
    137116                source.read( &node_header, sizeof( node_header ), 1 );
    138                 m_animation->nodes[i].parent_id     = node_header.parent_id;
    139                 m_animation->nodes[i].transform     = node_header.transform;
    140                 m_animation->nodes[i].data          = nullptr;
     117                m_node_array[i].parent_id     = node_header.parent_id;
     118                m_node_array[i].transform     = node_header.transform;
     119                m_node_array[i].data          = nullptr;
    141120                if ( ch_count > 0 )
    142121                {
    143122                        key_data* kdata = new key_data;
    144                         m_animation->nodes[i].data = kdata;
     123                        m_node_array[i].data = kdata;
    145124                        for ( uint32 c = 0; c < ch_count; ++c )
    146125                        {
    147126                                source.read( &element_header, sizeof( element_header ), 1 );
    148                                 NV_ASSERT( element_header.type == nmd_type::ANIMATION_CHANNEL, "ANIMATION_CHANNEL expected!" );
    149                                 nv::nmd_animation_channel_header cheader;
     127                                NV_ASSERT( element_header.type == nmd_type::KEY_CHANNEL, "CHANNEL expected!" );
     128                                nv::nmd_key_channel_header cheader;
    150129                                source.read( &cheader, sizeof( cheader ), 1 );
    151130                                key_raw_channel* channel = key_raw_channel::create( cheader.format, cheader.count );
     
    155134                }
    156135        }
     136        m_node_data = new mesh_nodes_data( "animation", e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat );
    157137        return true;
    158138}
    159139
     140mesh_nodes_data* nv::nmd_loader::release_mesh_nodes_data()
     141{
     142        if ( m_node_data )
     143        {
     144                if ( m_strings )
     145                {
     146                        for ( uint32 i = 0; i < m_node_data->get_count(); ++i )
     147                        {
     148                                m_node_array[i].name = m_strings->get( m_node_names[i] );
     149                        }
     150                }
     151                mesh_nodes_data* result = m_node_data;
     152                m_node_data = nullptr;
     153                m_node_array = nullptr;
     154                return result;
     155        }
     156        return nullptr;
     157}
    160158
    161159// TEMPORARY
    162 nv::nmd_temp_animation::nmd_temp_animation( nmd_loader* loader )
    163 {
    164         m_animation = loader->release_animation();
    165         m_strings   = loader->release_string_table();
    166160
    167         for ( uint32 n = 0; n < m_animation->node_count; ++n )
    168         {
    169                 nmd_node& node = m_animation->nodes[n];
    170                 m_data.push_back( node.data );
    171                 node.data = nullptr;
    172         }
    173 
    174         if ( !m_animation->flat )
    175         {
    176                 m_children.resize( m_animation->node_count );
    177                 for ( nv::uint32 n = 0; n < m_animation->node_count; ++n )
    178                 {
    179                         const nmd_node& node = m_animation->nodes[n];
    180                         if ( node.parent_id != -1 )
    181                         {
    182                                 m_children[ node.parent_id ].push_back( n );
    183                         }
    184                 }
    185         }
    186 
    187         m_bone_ids.resize( m_animation->node_count );
    188 }
    189 
    190 nv::nmd_temp_animation::~nmd_temp_animation()
    191 {
    192         for ( auto node : m_data ) delete node;
    193         delete m_animation;
    194         delete m_strings;
    195 }
    196 
    197 void nv::nmd_temp_animation::prepare( const nmd_temp_model* model )
    198 {
    199         m_offsets = model->m_bone_offsets.data();
    200         for ( uint32 n = 0; n < m_animation->node_count; ++n )
    201         {
    202                 const nmd_node& node = m_animation->nodes[n];
    203                 sint16 bone_id = -1;
    204 
    205                 auto bi = model->m_bone_names.find( m_strings->get( node.name ) );
    206                 if ( bi != model->m_bone_names.end() )
    207                 {
    208                         bone_id = bi->second;
    209                 }
    210                 m_bone_ids[n] = bone_id;
    211         }
    212 }
    213 
    214 void nv::nmd_temp_animation::animate( mat4* data, uint32 time )
    215 {
    216         float tick_time = ( time / 1000.0f ) * m_animation->fps;
    217         float anim_time = fmodf( tick_time, m_animation->duration );
    218 
    219         if ( !m_animation->flat )
    220         {
    221                 animate_rec( data, anim_time, 0, mat4() );
    222                 return;
    223         }
    224 
    225         for ( uint32 n = 0; n < m_animation->node_count; ++n )
    226                 if ( m_bone_ids[n] >= 0 )
    227                 {
    228                         const nmd_node* node = &m_animation->nodes[ n ];
    229                         nv::mat4 node_mat( node->transform );
    230 
    231                         if ( m_data[n] )
    232                         {
    233                                 node_mat = m_data[n]->get_matrix( anim_time );
    234                         }
    235 
    236                         sint16 bone_id = m_bone_ids[n];
    237                         data[ bone_id ] = node_mat * m_offsets[ bone_id ];
    238                 }
    239 
    240 }
    241 
    242 void nv::nmd_temp_animation::animate_rec( mat4* data, float time, uint32 node_id, const mat4& parent_mat )
    243 {
    244         // TODO: fix transforms, which are now embedded,
    245         //       see note in assimp_loader.cc:load_node
    246         const nmd_node* node = &m_animation->nodes[ node_id ];
    247         mat4 node_mat( node->transform );
    248 
    249         if ( m_data[ node_id ] )
    250         {
    251                 node_mat = m_data[ node_id ]->get_matrix( time );
    252         }
    253 
    254         mat4 global_mat = parent_mat * node_mat;
    255 
    256         sint16 bone_id = m_bone_ids[ node_id ];
    257         if ( bone_id >= 0 )
    258         {
    259                 data[ bone_id ] = global_mat * m_offsets[ bone_id ];
    260         }
    261 
    262         for ( auto child : m_children[ node_id ] )
    263         {
    264                 animate_rec( data, time, child, global_mat );
    265         }
    266 }
    267 
    268 nv::nmd_temp_model::nmd_temp_model( nmd_loader* loader )
     161nv::nmd_temp_model_data::nmd_temp_model_data( nmd_loader* loader )
    269162{
    270163        for ( unsigned m = 0; m < loader->get_mesh_count(); ++m )
     
    272165                m_mesh_data.push_back(loader->release_mesh_data(m));
    273166        }
    274         nmd_bone_data* bone_data = loader->release_bone_data();
    275         string_table*  strings   = loader->release_string_table();
    276 
    277         for ( nv::uint16 bi = 0; bi < bone_data->count; ++bi )
    278         {
    279                 m_bone_names[ strings->get( bone_data->bones[bi].name ) ] = bi;
    280                 m_bone_offsets.push_back( bone_data->bones[bi].offset );
    281         }
    282 
    283         delete bone_data;
    284         delete strings;
     167        m_node_data = loader->release_mesh_nodes_data();
    285168}
    286169
    287 nv::nmd_temp_model::~nmd_temp_model()
     170nv::nmd_temp_model_data::~nmd_temp_model_data()
    288171{
    289172        for ( unsigned m = 0; m < m_mesh_data.size(); ++m )
     
    291174                delete m_mesh_data[m];
    292175        }
     176        delete m_node_data;
    293177}
  • trunk/src/formats/obj_loader.cc

    r280 r287  
    5050        std::string line;
    5151        std::string cmd;
     52        std::string name;
     53        std::string next_name;
    5254
    5355        std::size_t size;
     
    7779bool obj_reader::read_stream( std::istream& stream )
    7880{
     81        name = next_name;
    7982        bool added_faces = false;
    8083        f32 x, y, z;
     
    146149                if ( cmd == "g" )
    147150                {
    148                         if (added_faces) return true;
     151                        ss >> next_name;
     152                        if (added_faces)
     153                                return true;
     154                        name = next_name;
    149155                        continue;
    150156                }
     
    335341                channel->count = reader->size * 3;
    336342
    337                 mesh_data* mesh = new mesh_data();
     343                mesh_data* mesh = new mesh_data(reader->name);
    338344                mesh->add_channel( channel );
    339345                m_meshes.push_back( mesh );
     
    357363        for ( auto mesh : m_meshes ) if ( mesh ) delete mesh;
    358364}
     365
     366mesh_data_pack* nv::obj_loader::release_mesh_data_pack()
     367{
     368        uint32 size = m_meshes.size();
     369        mesh_data* meshes = new mesh_data[ size ];
     370        for ( uint32 i = 0; i < size; ++i )
     371        {
     372                m_meshes[i]->move_to( meshes[i] );
     373                delete m_meshes[i];
     374        }
     375        m_meshes.clear();
     376        return new mesh_data_pack( size, meshes );
     377}
  • trunk/src/gfx/keyframed_mesh.cc

    r285 r287  
    1515using namespace nv;
    1616
    17 nv::keyframed_mesh::keyframed_mesh( device* a_device, mesh_data* a_data, tag_map* a_tag_map )
     17nv::keyframed_mesh::keyframed_mesh( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
    1818        : animated_mesh()
    1919        , m_mesh_data( a_data )
     
    4040}
    4141
    42 transform keyframed_mesh::get_tag( uint32 tag ) const
     42transform keyframed_mesh::get_node_transform( uint32 node_id ) const
    4343{
    4444        NV_ASSERT( m_tag_map, "TAGMAP FAIL" );
    45         const key_data* data = m_tag_map->get_tag( tag );
     45        NV_ASSERT( node_id < m_tag_map->get_count(), "TAGMAP FAIL" );
     46        const key_data* data = m_tag_map->get_node( node_id )->data;
    4647        NV_ASSERT( data, "TAG FAIL" );
    4748        transform last = data->get_raw_transform( m_last_frame );
    4849        transform next = data->get_raw_transform( m_next_frame );
    4950        return interpolate( last, next, m_interpolation  );
     51}
     52
     53mat4 keyframed_mesh::get_node_matrix( uint32 node_id ) const
     54{
     55        return get_node_transform( node_id ).extract();
    5056}
    5157
     
    125131}
    126132
    127 nv::keyframed_mesh_gpu::keyframed_mesh_gpu( device* a_device, mesh_data* a_data, tag_map* a_tag_map, program* a_program )
     133nv::keyframed_mesh_gpu::keyframed_mesh_gpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map, program* a_program )
    128134        : keyframed_mesh( a_device, a_data, a_tag_map )
    129135        , m_loc_next_position( 0 )
     
    159165}
    160166
    161 nv::keyframed_mesh_cpu::keyframed_mesh_cpu( device* a_device, mesh_data* a_data, tag_map* a_tag_map )
     167nv::keyframed_mesh_cpu::keyframed_mesh_cpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
    162168        : keyframed_mesh( a_device, a_data, a_tag_map )
    163169{
  • trunk/src/gfx/skeletal_mesh.cc

    r283 r287  
    1111
    1212
    13 nv::skeletal_mesh::skeletal_mesh( device* a_device, md5_mesh_data* a_mesh_data )
     13nv::skeletal_mesh::skeletal_mesh( device* a_device, const mesh_data* a_mesh_data, const mesh_nodes_data* bones )
    1414        : animated_mesh()
    15         , m_mesh_data( nullptr )
    16 {
    17         m_mesh_data = a_mesh_data->spawn();
     15        , m_data( a_mesh_data )
     16{
     17        const mesh_raw_channel* pnt_chan = a_mesh_data->get_channel<md5_vtx_pnt>();
     18        m_pntdata.assign( (const md5_vtx_pnt*)pnt_chan->data, pnt_chan->count );
     19        m_bone_offset.resize( bones->get_count() );
     20        for ( uint32 i = 0; i < bones->get_count(); ++i )
     21        {
     22                m_bone_offset[i] = transform( bones->get_node(i)->transform );
     23        }
     24        m_vtx_data  = a_mesh_data->get_channel_data<md5_vtx_pntiw>();
     25        m_indices   = a_mesh_data->get_count();
    1826        m_va        = a_device->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
    1927}
     
    2836                uint32 new_time = a_anim_time % anim_duration;
    2937                anim->update_skeleton( m_transform.data(), (float)new_time * 0.001f );
    30                 m_mesh_data->apply( m_transform.data() );
     38
     39                //m_mesh_data->apply( m_transform.data() );
     40                {
     41                        size_t skeleton_size = m_bone_offset.size();
     42                        size_t vertex_count  = m_pntdata.size();
     43                        m_pos_offset.resize( skeleton_size );
     44                        for ( unsigned int i = 0; i < skeleton_size; ++i )
     45                        {
     46                                m_pos_offset[i] = m_transform[i] * m_bone_offset[i];
     47                        }
     48
     49                        std::fill( m_pntdata.raw_data(), m_pntdata.raw_data() + m_pntdata.raw_size(), 0 );
     50                        for ( unsigned int i = 0; i < vertex_count; ++i )
     51                        {
     52                                const md5_vtx_pntiw& vert = m_vtx_data[i];
     53
     54                                for ( size_t j = 0; j < 4; ++j )
     55                                {
     56                                        int   index  = vert.boneindex[j];
     57                                        float weight = vert.boneweight[j];
     58                                        const quat& orient      = m_transform[index].get_orientation();
     59                                        const transform& offset = m_pos_offset[index];
     60                                        m_pntdata[i].position += offset.transformed( vert.position )        * weight;
     61                                        m_pntdata[i].normal   += ( orient * vert.normal  ) * weight;
     62                                        m_pntdata[i].tangent  += ( orient * vert.tangent ) * weight;
     63                                }
     64                        }
     65                }
     66
    3167                vertex_buffer* vb = m_va->find_buffer( nv::slot::POSITION );
    3268                vb->bind();
    33                 vb->update( m_mesh_data->data(), 0, m_mesh_data->size() );
     69                vb->update( m_pntdata.data(), 0, m_pntdata.raw_size() );
    3470                vb->unbind();
    3571        }
     
    3975{
    4076        delete m_va;
    41         delete m_mesh_data;
    4277}
    4378
     
    5287}
    5388
    54 void nv::skeletal_animation_entry_gpu::update_skeleton( mat4* data, uint32 time )
    55 {
    56         m_animation->animate( data, time );
    57 }
    58 
    59 void nv::skeletal_animation_entry_gpu::prepare( const nmd_temp_model* m_model )
    60 {
    61         m_animation->prepare( m_model );
    62 }
    63 
    64 nv::skeletal_mesh_gpu::skeletal_mesh_gpu( device* a_device, const nmd_temp_model* a_model, uint32 index, bool primary )
    65         : animated_mesh(), m_primary( primary ), m_model( a_model )
    66 {
    67         const mesh_data* data = a_model->get_data( index );
    68         m_va          = a_device->create_vertex_array( data, nv::STATIC_DRAW );
    69         m_index_count = data->get_count();
     89
     90nv::skeletal_animation_entry_gpu::skeletal_animation_entry_gpu( const std::string& name, const mesh_nodes_data* anim, bool a_looping )
     91        : animation_entry( name )
     92        , m_node_data( anim )
     93{
     94        uint32 node_count = m_node_data->get_count();
     95
     96        m_prepared  = false;
     97        m_looping   = a_looping;
     98        m_children  = nullptr;
     99        m_offsets   = nullptr;
     100        m_bone_ids  = new sint16[ node_count ];
     101
     102        if ( !m_node_data->is_flat() )
     103        {
     104                m_children = new std::vector< uint32 >[ node_count ];
     105                for ( uint32 n = 0; n < node_count; ++n )
     106                {
     107                        const mesh_node_data* node = m_node_data->get_node(n);
     108                        if ( node->parent_id != -1 )
     109                        {
     110                                m_children[ node->parent_id ].push_back( n );
     111                        }
     112                }
     113        }
     114}
     115
     116void nv::skeletal_animation_entry_gpu::update_skeleton( mat4* data, uint32 time ) const
     117{
     118        float tick_time = ( time * 0.001f ) * m_node_data->get_frame_rate();
     119        float anim_time = fmodf( tick_time, m_node_data->get_duration() );
     120
     121        if ( !m_node_data->is_flat() )
     122        {
     123                animate_rec( data, anim_time, 0, mat4() );
     124                return;
     125        }
     126
     127        for ( uint32 n = 0; n < m_node_data->get_count(); ++n )
     128                if ( m_bone_ids[n] >= 0 )
     129                {
     130                        const mesh_node_data* node = m_node_data->get_node(n);
     131                        nv::mat4 node_mat( node->transform );
     132
     133                        if ( node->data )
     134                        {
     135                                node_mat = node->data->get_matrix( anim_time );
     136                        }
     137
     138                        sint16 bone_id = m_bone_ids[n];
     139                        data[ bone_id ] = node_mat * m_offsets[ bone_id ];
     140                }
     141}
     142
     143void nv::skeletal_animation_entry_gpu::prepare( const mesh_nodes_data* bones )
     144{
     145        if ( m_prepared ) return;
     146        std::unordered_map< std::string, nv::uint16 > bone_names;
     147        m_offsets = new mat4[ bones->get_count() ];
     148        for ( nv::uint16 bi = 0; bi < bones->get_count(); ++bi )
     149        {
     150                const mesh_node_data* bone = bones->get_node(bi);
     151                bone_names[ bone->name ] = bi;
     152                m_offsets[bi] = bone->transform;
     153        }
     154
     155        for ( uint32 n = 0; n < m_node_data->get_count(); ++n )
     156        {
     157                const mesh_node_data* node = m_node_data->get_node(n);
     158                sint16 bone_id = -1;
     159
     160                auto bi = bone_names.find( node->name );
     161                if ( bi != bone_names.end() )
     162                {
     163                        bone_id = bi->second;
     164                }
     165                m_bone_ids[n] = bone_id;
     166        }
     167        m_prepared = true;
     168}
     169
     170void nv::skeletal_animation_entry_gpu::animate_rec( mat4* data, float time, uint32 node_id, const mat4& parent_mat ) const
     171{
     172        // TODO: fix transforms, which are now embedded,
     173        //       see note in assimp_loader.cc:load_node
     174        const mesh_node_data* node = m_node_data->get_node( node_id );
     175        mat4 node_mat( node->transform );
     176
     177        if ( node->data )
     178        {
     179                node_mat = node->data->get_matrix( time );
     180        }
     181
     182        mat4 global_mat = parent_mat * node_mat;
     183
     184        sint16 bone_id = m_bone_ids[ node_id ];
     185        if ( bone_id >= 0 )
     186        {
     187                data[ bone_id ] = global_mat * m_offsets[ bone_id ];
     188        }
     189
     190        for ( auto child : m_children[ node_id ] )
     191        {
     192                animate_rec( data, time, child, global_mat );
     193        }
     194}
     195
     196nv::skeletal_animation_entry_gpu::~skeletal_animation_entry_gpu()
     197{
     198        delete[] m_offsets;
     199        delete[] m_children;
     200        delete[] m_bone_ids;
     201}
     202
     203nv::skeletal_mesh_gpu::skeletal_mesh_gpu( device* a_device, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data )
     204        : animated_mesh(), m_bone_data( a_bone_data ), m_transform( nullptr )
     205{
     206        m_va          = a_device->create_vertex_array( a_mesh, nv::STATIC_DRAW );
     207        m_index_count = a_mesh->get_count();
     208        if ( m_bone_data )
     209        {
     210                m_transform = new mat4[ m_bone_data->get_count() ];
     211        }
    70212}
    71213
    72214void nv::skeletal_mesh_gpu::run_animation( animation_entry* a_anim )
    73215{
    74         if ( m_primary && a_anim != nullptr )
     216        if ( m_bone_data && a_anim != nullptr )
    75217        {
    76218                skeletal_animation_entry_gpu * anim = (skeletal_animation_entry_gpu*)(a_anim);
    77                 m_transform.resize( m_model->get_bone_count() );
    78                 anim->prepare( m_model );
     219                anim->prepare( m_bone_data );
    79220                update_animation( a_anim, 0 );
    80221        }
     
    83224void nv::skeletal_mesh_gpu::update_animation( animation_entry* a_anim, uint32 a_anim_time )
    84225{
    85         if ( m_primary && a_anim )
     226        if ( m_bone_data && a_anim )
    86227        {
    87228                skeletal_animation_entry_gpu * anim = (skeletal_animation_entry_gpu*)a_anim;
    88                 anim->update_skeleton( m_transform.data(), a_anim_time );
     229                anim->update_skeleton( m_transform, a_anim_time );
    89230        }
    90231}
     
    92233void nv::skeletal_mesh_gpu::update( program* a_program ) const
    93234{
    94         if (m_primary)
    95                 a_program->set_uniform_array( "nv_m_bones", m_transform );
    96 }
     235        if ( m_bone_data )
     236                a_program->set_uniform_array( "nv_m_bones", m_transform, m_bone_data->get_count() );
     237}
     238
     239nv::transform nv::skeletal_mesh_gpu::get_node_transform( uint32 node_id ) const
     240{
     241        return transform( m_transform[ node_id ] );
     242}
     243
     244nv::mat4 nv::skeletal_mesh_gpu::get_node_matrix( uint32 node_id ) const
     245{
     246        return m_transform[ node_id ];
     247}
Note: See TracChangeset for help on using the changeset viewer.