source: trunk/src/formats/assimp_loader.cc @ 499

Last change on this file since 499 was 491, checked in by epyon, 9 years ago
  • mass update (will try to do atomic from now)
File size: 19.4 KB
Line 
1// Copyright (C) 2014-2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
6
7#include "nv/formats/assimp_loader.hh"
8
9#include "nv/interface/data_channel_access.hh"
10#include "nv/stl/hash_store.hh"
11#include "nv/lib/assimp.hh"
12
13using namespace nv;
14
15namespace nv {
16
17        struct assimp_data
18        {
19                const aiScene* scene;
20                vector< const aiBone* > bones;
21                vector< const aiNode* > nodes;
22                vector< const aiMesh* > meshes;
23                vector< const aiNode* > skeletons;
24
25                hash_store< shash64, const aiBone* > bone_by_name;
26                hash_store< shash64, const aiNode* > node_by_name;
27        };
28
29}
30
31const unsigned MAX_BONES = 64;
32
33struct assimp_plain_vtx
34{
35        vec3 position;
36        vec3 normal;
37        vec2 texcoord;
38        vec4 tangent;
39
40        assimp_plain_vtx() {}
41        assimp_plain_vtx( const vec3& v, const vec2& t, const vec3& n, const vec4& g )
42        {
43                position = v;
44                texcoord = t;
45                normal   = n;
46                tangent  = g;
47        }
48};
49
50struct assimp_skinned_vtx
51{
52        vec3  position;
53        vec3  normal;
54        vec2  texcoord;
55        vec4  tangent;
56        ivec4 boneindex;
57        vec4  boneweight;
58
59        assimp_skinned_vtx() {}
60        assimp_skinned_vtx( const vec3& v, const vec2& t, const vec3& n, const vec4& g )
61        {
62                position = v;
63                texcoord = t;
64                normal   = n;
65                tangent  = g;
66        }
67};
68
69struct assimp_key_p  { float time; vec3 translation; };
70struct assimp_key_r  { float time; quat rotation; };
71struct assimp_key_s  { float time; vec3 scale; };
72struct assimp_key_tr { transform tform; };
73
74
75nv::assimp_loader::assimp_loader( string_table* strings, const string_view& a_ext, uint32 a_assimp_flags /*= 0 */ )
76        : mesh_loader( strings ), m_mesh_count(0)
77{
78        m_ext   = a_ext;
79        m_assimp_flags = a_assimp_flags;
80        if ( m_assimp_flags == 0 )
81        {
82                m_assimp_flags = (
83                        aiProcess_CalcTangentSpace                              | 
84                        aiProcess_GenSmoothNormals                              | 
85                        aiProcess_JoinIdenticalVertices                 |   
86                        aiProcess_ImproveCacheLocality                  | 
87                        aiProcess_LimitBoneWeights                              | 
88                        aiProcess_RemoveRedundantMaterials      | 
89                        aiProcess_SplitLargeMeshes                              | 
90                        aiProcess_Triangulate                                   | 
91                        aiProcess_GenUVCoords                   | 
92                        aiProcess_SortByPType                   | 
93                        aiProcess_FindDegenerates               | 
94                        aiProcess_FindDegenerates |
95                        0 );
96        }
97        m_data = new assimp_data;
98        m_data->scene = nullptr;
99}
100
101
102bool nv::assimp_loader::load( stream& source )
103{
104        load_assimp_library();
105        if ( m_data->scene != nullptr ) aiReleaseImport( m_data->scene );
106        m_data->scene = nullptr;
107        m_mesh_count = 0;
108        NV_LOG_NOTICE( "AssImp loading file..." );
109        size_t size = source.size();
110        char* data  = new char[ size ];
111        source.read( data, size, 1 );
112        const aiScene* scene = aiImportFileFromMemory( data, size, m_assimp_flags, m_ext.data() );
113
114        if( !scene)
115        {
116                NV_LOG_ERROR( aiGetErrorString() );
117                return false;
118        }
119        m_data->scene = scene;
120        m_mesh_count  = scene->mNumMeshes;
121        NV_LOG_NOTICE( "Loading successfull" );
122
123        scan_nodes( scene->mRootNode );
124
125        for ( unsigned i = 0; i < scene->mRootNode->mNumChildren; ++i )
126        {
127                const aiNode* node = scene->mRootNode->mChildren[i];
128                if ( node->mNumMeshes == 0 )
129                        m_data->skeletons.push_back( node );
130        }
131
132        for ( nv::uint32 i = 0; i < m_mesh_count; i++ )
133        {
134                data_node_info info;
135                data_channel_set* mdata = data_channel_set_creator::create_set( 2 );
136                load_mesh_data( mdata, i, info );
137                m_meshes.push_back( mdata );
138                m_mesh_info.push_back( info );
139        }
140
141        scene_report();
142        return true;
143}
144
145data_channel_set* nv::assimp_loader::release_mesh_data( size_t index, data_node_info& info )
146{
147        if ( index >= m_mesh_count ) return nullptr;
148        info = m_mesh_info[index];
149        return m_meshes[index];
150}
151void nv::assimp_loader::load_mesh_data( data_channel_set* data, size_t index, data_node_info& info )
152{
153        const aiMesh*  mesh  = m_data->scene->mMeshes[ index ];
154
155        bool skinned = mesh->mNumBones > 0;
156
157        data_descriptor desc;
158        if ( skinned )
159                desc.initialize< assimp_skinned_vtx >();
160        else
161                desc.initialize< assimp_plain_vtx >();
162        data_channel_set_creator maccess( data );
163        string64 name( mesh->mName.data, mesh->mName.length );
164        if ( mesh->mName.length == 0 )
165        {
166                for ( auto node : m_data->nodes )
167                {
168                        if ( node->mMeshes )
169                                for ( uint32 i = 0; i < node->mNumMeshes; ++i )
170                                        if ( node->mMeshes[i] == index )
171                                        {
172                                                name.assign( node->mName.data, node->mName.length );
173                                                if ( i != 0 )
174                                                {
175                                                        name.append( "#0" );
176                                                        name.append( i );
177                                                }
178                                        }
179
180                }
181        }
182        info.name = make_name( name );
183        info.parent_id = -1;
184        int hack_for_node_anim;
185        if ( is_node_animated() )
186                info.parent_id = sint16( index );
187
188
189        uint8*  cdata   = maccess.add_channel( desc, mesh->mNumVertices ).raw_data();
190        uint32* indices = reinterpret_cast<uint32*>( maccess.add_channel< index_u32 >( mesh->mNumFaces * 3 ).raw_data() );
191
192        if ( mesh->mTangents && mesh->mBitangents )
193                for ( unsigned int i = 0; i < mesh->mNumVertices; i++ )
194                {
195                        vec3 v = assimp_vec3_cast( mesh->mVertices[i] );
196                        vec3 n = math::normalize( assimp_vec3_cast( mesh->mNormals[i] ) );
197                        vec3 t = math::normalize( assimp_vec3_cast( mesh->mTangents[i] ) );
198                        vec3 b = math::normalize( assimp_vec3_cast( mesh->mBitangents[i] ) );
199                        vec2 s = assimp_st_cast( mesh->mTextureCoords[0][i] );
200
201                        vec3 t_i = math::normalize( t - n * math::dot( n, t ) );
202                        float det = ( math::dot( math::cross( n, t ), b ) );
203                        det = ( det < 0.0f ? -1.0f : 1.0f );
204                        nv::vec4 vt( t_i[0], t_i[1], t_i[2], det );
205                        if ( skinned )
206                                reinterpret_cast<assimp_skinned_vtx*>( cdata )[i] = assimp_skinned_vtx( v, s, n, vt );
207                        else
208                                reinterpret_cast<assimp_plain_vtx*>( cdata )[i] = assimp_plain_vtx( v, s, n, vt );
209                }
210
211        if ( skinned )
212        {
213                assimp_skinned_vtx* vtx = reinterpret_cast< assimp_skinned_vtx* >( cdata );
214                for (unsigned int m=0; m<mesh->mNumBones; m++)
215                {
216                        aiBone* bone  = mesh->mBones[m];
217                        for ( size_t w=0; w<bone->mNumWeights; w++)
218                        {
219                                assimp_skinned_vtx& v = vtx[ bone->mWeights[w].mVertexId ];
220                                bool found = false;
221                                for ( size_t i = 0 ; i < 4; ++i )
222                                {
223                                        if ( v.boneweight[i] <= 0.0f )
224                                        {
225                                                v.boneindex[i]  = int( m );
226                                                v.boneweight[i] = bone->mWeights[w].mWeight;
227                                                found = true;
228                                                break;
229                                        }
230                                }
231                                NV_ASSERT( found, "Too many weights!" );
232                        }
233                }
234        }
235
236        for (unsigned int i=0; i<mesh->mNumFaces; i++)
237        {
238                const aiFace* face = &mesh->mFaces[i];
239                for (unsigned int j=0; j<face->mNumIndices; j++)
240                {
241                        indices[ i*3 + j ] = uint32( face->mIndices[j] );
242                }
243        }
244
245}
246
247nv::assimp_loader::~assimp_loader()
248{
249        if ( m_data->scene != nullptr ) aiReleaseImport( m_data->scene );
250        delete m_data;
251}
252
253void nv::assimp_loader::scene_report() const
254{
255        if ( m_data->scene == nullptr ) return;
256
257        NV_LOG_NOTICE( "------------------------" );
258        NV_LOG_NOTICE( "Texture   count - ", m_data->scene->mNumTextures );
259        NV_LOG_NOTICE( "Animation count - ", m_data->scene->mNumAnimations );
260        NV_LOG_NOTICE( "Material  count - ", m_data->scene->mNumMaterials );
261        NV_LOG_NOTICE( "Meshes    count - ", m_data->scene->mNumMeshes );
262        NV_LOG_NOTICE( "------------------------" );
263
264        aiNode* root = m_data->scene->mRootNode;
265        if (root)
266        {
267                NV_LOG_NOTICE( "Root node  - ", root->mName.data );
268                NV_LOG_NOTICE( "  meshes   - ", root->mNumMeshes );
269                NV_LOG_NOTICE( "  children - ", root->mNumChildren );
270        }
271        else
272        {
273                NV_LOG_NOTICE( "No root node!" );
274        }
275        NV_LOG_NOTICE( "------------------------" );
276
277        if ( m_data->scene->mNumMeshes > 0 )
278        {
279                for ( nv::uint32 mc = 0; mc < m_data->scene->mNumMeshes; mc++ )
280                {
281                        aiMesh* mesh = m_data->scene->mMeshes[mc];
282
283                        NV_LOG_NOTICE( "Mesh #", mc, "   - ", string_view( static_cast<char*>( mesh->mName.data ), mesh->mName.length ) );
284                        NV_LOG_NOTICE( "  bones   - ", mesh->mNumBones );
285                        NV_LOG_NOTICE( "  uvs     - ", mesh->mNumUVComponents[0] );
286                        NV_LOG_NOTICE( "  verts   - ", mesh->mNumVertices );
287                        NV_LOG_NOTICE( "  faces   - ", mesh->mNumFaces );
288
289                        //                      NV_LOG_NOTICE(  "Bones:" );
290                        //                      for (unsigned int m=0; m<mesh->mNumBones; m++)
291                        //                      {
292                        //                              aiBone* bone  = mesh->mBones[m];
293                        //                              NV_LOG_NOTICE( bone->mName.C_Str() );
294                        //                      }
295                }
296        }
297        else
298        {
299                NV_LOG_NOTICE( "No meshes!" );
300        }
301        NV_LOG_NOTICE( "------------------------" );
302
303        for ( auto node : m_data->nodes )
304        {
305                NV_LOG_NOTICE( "Node : ", string_view( node->mName.data, node->mName.length ) );
306        }
307
308        for ( auto skeleton : m_data->skeletons )
309        {
310                NV_LOG_NOTICE( "Skeleton : ", string_view( skeleton->mName.data, skeleton->mName.length ) );
311        }
312
313        //      if ( scene->mNumMaterials > 0 )
314        //      {
315        //              for (unsigned int m=0; m < scene->mNumMaterials; m++)
316        //              {
317        //                      int texIndex = 0;
318        //                      aiReturn texFound = aiReturn_SUCCESS;
319        //                      aiString path;  // filename
320        //                      while (texFound == aiReturn_SUCCESS)
321        //                      {
322        //                              texFound = scene->mMaterials[m]->GetTexture(aiTextureType_DIFFUSE, texIndex, &path);
323        //                              NV_LOG_NOTICE( "  material - ", path.data );
324        //                              texIndex++;
325        //                      }
326        //              }
327        //      }
328        //      else
329        //      {
330        //              NV_LOG_NOTICE( "No materials" );
331        //      }
332        //      NV_LOG_NOTICE( "------------------------" );
333
334}
335
336bool nv::assimp_loader::is_node_animated()
337{
338        return is_animated() && m_data->skeletons.empty();
339}
340
341void nv::assimp_loader::build_skeleton( vector< data_node_info >& skeleton, const void* node, sint16 parent_id )
342{
343        const aiNode* ainode = reinterpret_cast<const aiNode*>( node );
344
345        if ( ainode->mNumMeshes > 0 )
346        {
347                int error;
348                int bug_this_works_only_if_before_releasing_meshes;
349
350                nv::uint32 mid = ainode->mMeshes[0];
351                m_mesh_info[mid].parent_id = parent_id;
352                return;
353        }
354
355        string_view name( ainode->mName.data, ainode->mName.length );
356        if ( name.starts_with( '_' ) ) return;
357
358        data_node_info info;
359        info.name      = make_name( name );
360        info.parent_id = parent_id;
361
362        sint16 this_id = sint16( skeleton.size() );
363        skeleton.push_back( info );
364        for ( unsigned i = 0; i < ainode->mNumChildren; ++i )
365        {
366                build_skeleton( skeleton, ainode->mChildren[i], this_id );
367        }
368}
369
370data_node_list* nv::assimp_loader::release_merged_bones()
371{
372        if ( m_data->skeletons.empty() ) return nullptr;
373        vector< data_node_info > bone_data;
374        hash_store< shash64, uint16 > bone_map;
375
376        {
377                const aiNode* skeleton = m_data->skeletons[0];
378                build_skeleton( bone_data, skeleton, -1 );
379
380                for ( uint32 i = 0; i < bone_data.size(); ++i )
381                {
382                        bone_map[bone_data[i].name] = uint16(i);
383                }
384        }
385
386        for ( unsigned int m = 0; m < m_mesh_count; ++m )
387        {
388                uint16 translate[MAX_BONES];
389                vector< data_node_info > bones;
390                const aiMesh*  mesh = m_data->scene->mMeshes[m];
391                if ( mesh->mNumBones != 0 )
392                {
393                        for ( unsigned int b = 0; b < mesh->mNumBones; b++ )
394                        {
395                                aiBone* bone = mesh->mBones[b];
396                                mat4    offset = assimp_mat4_cast( bone->mOffsetMatrix );
397                                shash64 bone_name( bone->mName.data );
398
399                                int remove_this;
400
401                                NV_ASSERT( bone_map.find( shash64( bone->mName.data ) ) != bone_map.end(), "BONE NOT FOUND!" );
402                                uint16 index = bone_map[bone_name];
403                                bone_data[index].transform = offset;
404                                translate[b] = index;
405                        }
406
407                        data_channel_access< assimp_skinned_vtx > channel( const_cast<raw_data_channel*>( m_meshes[m]->get_channel( 0 ) ) );
408                        for ( unsigned v = 0; v < channel.size(); ++v )
409                        {
410                                assimp_skinned_vtx& vertex = channel.data()[v];
411                                for ( size_t i = 0; i < 4; ++i )
412                                {
413                                        if ( vertex.boneweight[i] > 0.0f )
414                                        {
415                                                vertex.boneindex[i] = int( translate[vertex.boneindex[i]] );
416                                        }
417                                }
418                        }
419
420                }
421        }
422
423        for ( uint32 i = 0; i < bone_data.size(); ++i )
424        {
425                int error; // not really, just
426                int check_this_shit;
427                if ( bone_data[i].transform == mat4() )
428                {
429                        mat4 tr = nv::math::inverse( assimp_mat4_cast( m_data->node_by_name[bone_data[i].name]->mTransformation ) );
430                        int pid = bone_data[i].parent_id;
431                        if ( pid >= 0 )
432                                bone_data[i].transform = tr * bone_data[ size_t( pid ) ].transform;
433                        else
434                                bone_data[i].transform = tr;
435                }
436//              list->append( bone_data[i] );
437        }
438
439
440        data_node_list* list = new data_node_list( make_name( "bones" ) );
441        for ( uint32 i = 0; i < bone_data.size(); ++i )
442        {
443                list->append( bone_data[i] );
444        }
445
446        return list;
447}
448
449mesh_nodes_data* nv::assimp_loader::release_mesh_nodes_data( size_t index /*= 0*/ )
450{
451        if ( m_data->scene == nullptr ) return nullptr;
452        const aiScene* scene = reinterpret_cast<const aiScene*>( m_data->scene );
453        if ( scene->mRootNode == nullptr || scene->mAnimations == nullptr || scene->mAnimations[index] == nullptr) return nullptr;
454
455        const aiAnimation* anim = scene->mAnimations[index];
456
457        uint32 count = count_nodes( scene->mRootNode );
458        count = count - 1;
459
460        uint16 frame_rate     = static_cast<uint16>( anim->mTicksPerSecond );
461        uint16 duration       = static_cast<uint16>( anim->mDuration )+1;
462
463        data_channel_set** temp  = new data_channel_set*[ count ];
464        data_node_info*    temp2 = new data_node_info[count ];
465        array_ref< data_channel_set* > temp_ref( temp, count );
466        array_ref< data_node_info >    temp2_ref( temp2, count );
467
468        nv::sint16 next = 0;
469        for ( unsigned i = 0; i < scene->mRootNode->mNumChildren; ++i )
470        {
471                next = load_node( index, temp_ref, temp2_ref, scene->mRootNode->mChildren[i], next, -1 );
472        }
473//      load_node( index, temp_ref, temp2_ref, scene->mRootNode, 0, -1 );
474
475        mesh_nodes_data* result = new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), frame_rate, duration );
476        for ( nv::uint32 i = 0; i < count; ++i )
477        {
478                result->append( temp_ref[i], temp2_ref[i] );
479        }
480        result->initialize();
481        delete temp;
482        delete temp2;
483        return result;
484}
485
486data_node_list* nv::assimp_loader::release_data_node_list( size_t /*= 0 */ )
487{
488        return release_merged_bones();
489}
490
491bool nv::assimp_loader::is_animated( size_t /*= 0 */ )
492{
493        int this_is_incorrect;
494        return m_mesh_count == 0 || ( m_data->scene->mNumAnimations > 0 && m_data->skeletons.size() == 0 );
495}
496
497void nv::assimp_loader::scan_nodes( const void* node ) const
498{
499        const aiNode* ainode = reinterpret_cast<const aiNode*>( node );
500        m_data->nodes.push_back( ainode );
501        m_data->node_by_name[shash64(ainode->mName.data)] = ainode;
502
503        for ( unsigned i = 0; i < ainode->mNumChildren; ++i )
504        {
505                scan_nodes( ainode->mChildren[i] );
506        }
507}
508
509nv::uint32 nv::assimp_loader::count_nodes( const void* node ) const
510{
511        const aiNode* ainode = reinterpret_cast< const aiNode* >( node );
512        nv::uint32 count = 1;
513        for ( unsigned i = 0; i < ainode->mNumChildren; ++i )
514        {
515                count += count_nodes( ainode->mChildren[i] );
516        }
517        return count;
518}
519
520nv::sint16 nv::assimp_loader::load_node( uint32 anim_id, array_ref< data_channel_set* > nodes, array_ref< data_node_info > infos, const void* vnode, sint16 this_id, sint16 parent_id )
521{
522        const aiNode*  node  = reinterpret_cast<const aiNode*>( vnode );
523        string_view name( static_cast< const char* >( node->mName.data ) );
524        const aiAnimation* anim  = m_data->scene->mAnimations[anim_id];
525        const aiNodeAnim*  anode = nullptr;
526
527        for ( unsigned i = 0 ; i < anim->mNumChannels ; i++ )
528        {
529                anode = anim->mChannels[i];
530                if ( string_view( static_cast< const char* >( anode->mNodeName.data ) ) == name ) break;
531                anode = nullptr;
532        }
533
534
535        transform t = nv::transform( nv::assimp_mat4_cast( node->mTransformation ) );
536
537        nodes[ uint32( this_id ) ] = anode ? create_keys( anode, t ) : data_channel_set_creator::create_set( 0 );
538        infos[ uint32( this_id ) ].name      = make_name( name );
539        infos[ uint32( this_id ) ].parent_id = parent_id;
540        // This value is ignored by the create_transformed_keys, but needed by create_direct_keys!
541        // TODO: find a common solution!
542        //       This is bad because create_transformed_keys never uses node-transformations for
543        //       node's without keys
544        // TODO: this can probably be deleted
545//      infos[this_id].transform = nv::assimp_mat4_cast( node->mTransformation );
546//      if ( this_id == 0 ) infos[this_id].transform = mat4();
547
548
549        nv::sint16 next = this_id + 1;
550        for ( unsigned i = 0; i < node->mNumChildren; ++i )
551        {
552                next = load_node( anim_id, nodes, infos, node->mChildren[i], next, this_id );
553        }
554
555        return next;
556}
557
558data_channel_set* nv::assimp_loader::create_keys( const void* vnode, const transform& tr )
559{
560        const aiNodeAnim* node  = reinterpret_cast< const aiNodeAnim* >( vnode );
561        if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 )
562        {
563                return data_channel_set_creator::create_set( 0 );
564        }
565
566/* OLD
567        data_channel_set* set = data_channel_set_creator::create_set( 2 );
568        data_channel_set_creator key_set( set );
569
570        assimp_key_p* pchannel = key_set.add_channel< assimp_key_p >( node->mNumPositionKeys ).data();
571        assimp_key_r* rchannel = key_set.add_channel< assimp_key_r >( node->mNumRotationKeys ).data();
572//      assimp_key_s* schannel = key_set.add_channel< assimp_key_s >( node->mNumScalingKeys ).data();
573
574        for ( unsigned np = 0; np < node->mNumPositionKeys; ++np )
575        {
576                pchannel[np].time        = static_cast<float>( node->mPositionKeys[np].mTime );
577                pchannel[np].translation = assimp_vec3_cast(node->mPositionKeys[np].mValue);
578        }
579        for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
580        {
581                rchannel[np].time     = static_cast<float>( node->mRotationKeys[np].mTime );
582                rchannel[np].rotation = assimp_quat_cast(node->mRotationKeys[np].mValue );
583        }
584        */
585        data_channel_set* set = data_channel_set_creator::create_set( 1 );
586        data_channel_set_creator key_set( set );
587
588        assimp_key_tr* channel = key_set.add_channel< assimp_key_tr >( node->mNumPositionKeys ).data();
589        for ( unsigned np = 0; np < node->mNumPositionKeys; ++np )
590        {
591                channel[np].tform.set_position( assimp_vec3_cast( node->mPositionKeys[np].mValue ) );
592                channel[np].tform.set_orientation( assimp_quat_cast( node->mRotationKeys[np].mValue ) );
593                if ( is_node_animated() )
594                        channel[np].tform = tr.inverse() * channel[np].tform ;
595        }
596
597//      if ( node->mNumScalingKeys > 0 )
598//      {
599//              vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue );
600//              float scale_value   = math::length( math::abs( scale_vec0 - vec3(1,1,1) ) );
601//              if ( node->mNumScalingKeys > 1 || scale_value > 0.001 )
602//              {
603//                      NV_LOG( nv::LOG_WARNING, "scale key significant!" );
604//                      for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
605//                      {
606//                              schannel[np].time  = (float)node->mScalingKeys[np].mTime;
607//                              schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue);
608//                      }
609//              }
610//              else
611//              {
612//                      schannel[0].time  = (float)node->mScalingKeys[0].mTime;
613//                      schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue);
614//              }
615//      }
616        return set;
617}
618
619// mesh_data_pack* nv::assimp_loader::release_mesh_data_pack()
620// {
621//      if ( m_scene == nullptr || m_mesh_count == 0 ) return nullptr;
622//      const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
623//      bool has_bones = false;
624//      data_channel_set* meshes = data_channel_set_creator::create_set_array( m_mesh_count, 2 );
625//      for ( size_t m = 0; m < m_mesh_count; ++m )
626//      {
627//              const aiMesh* mesh = scene->mMeshes[ m ];
628//              data_channel_set_creator( &meshes[m] ).set_name( make_name( static_cast<const char*>( mesh->mName.data ) ) );
629//              if ( mesh->mNumBones > 0 ) has_bones = true;
630//              load_mesh_data(&meshes[m],m);
631//      }
632//
633//      mesh_nodes_data* nodes = ( has_bones ? release_merged_bones( meshes ) : release_mesh_nodes_data(0) );
634//      return new mesh_data_pack( m_mesh_count, meshes, nodes );
635// }
636
637nv::size_t nv::assimp_loader::get_nodes_data_count() const
638{
639        if ( m_data->scene == nullptr ) return 0;
640        return m_data->scene->mNumAnimations;
641}
642
643
Note: See TracBrowser for help on using the repository browser.