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 | #include "nv/stl/unordered_map.hh"
|
---|
9 | #include "nv/lib/assimp.hh"
|
---|
10 |
|
---|
11 | using namespace nv;
|
---|
12 |
|
---|
13 | const unsigned MAX_BONES = 64;
|
---|
14 |
|
---|
15 | struct assimp_plain_vtx
|
---|
16 | {
|
---|
17 | vec3 position;
|
---|
18 | vec3 normal;
|
---|
19 | vec2 texcoord;
|
---|
20 | vec4 tangent;
|
---|
21 |
|
---|
22 | assimp_plain_vtx() {}
|
---|
23 | assimp_plain_vtx( const vec3& v, const vec2& t, const vec3& n, const vec4& g )
|
---|
24 | {
|
---|
25 | position = v;
|
---|
26 | texcoord = t;
|
---|
27 | normal = n;
|
---|
28 | tangent = g;
|
---|
29 | }
|
---|
30 | };
|
---|
31 |
|
---|
32 | struct assimp_skinned_vtx
|
---|
33 | {
|
---|
34 | vec3 position;
|
---|
35 | vec3 normal;
|
---|
36 | vec2 texcoord;
|
---|
37 | vec4 tangent;
|
---|
38 | ivec4 boneindex;
|
---|
39 | vec4 boneweight;
|
---|
40 |
|
---|
41 | assimp_skinned_vtx() {}
|
---|
42 | assimp_skinned_vtx( const vec3& v, const vec2& t, const vec3& n, const vec4& g )
|
---|
43 | {
|
---|
44 | position = v;
|
---|
45 | texcoord = t;
|
---|
46 | normal = n;
|
---|
47 | tangent = g;
|
---|
48 | }
|
---|
49 | };
|
---|
50 |
|
---|
51 | struct assimp_key_p { float time; vec3 translation; };
|
---|
52 | struct assimp_key_r { float time; quat rotation; };
|
---|
53 | struct assimp_key_s { float time; vec3 scale; };
|
---|
54 | struct assimp_key_tr { transform tform; };
|
---|
55 |
|
---|
56 |
|
---|
57 | nv::assimp_loader::assimp_loader( const std::string& a_ext, uint32 a_assimp_flags /*= 0 */ )
|
---|
58 | : m_scene( nullptr ), m_mesh_count(0)
|
---|
59 | {
|
---|
60 | m_ext = a_ext;
|
---|
61 | m_assimp_flags = a_assimp_flags;
|
---|
62 | if ( m_assimp_flags == 0 )
|
---|
63 | {
|
---|
64 | m_assimp_flags = (
|
---|
65 | aiProcess_CalcTangentSpace |
|
---|
66 | aiProcess_GenSmoothNormals |
|
---|
67 | aiProcess_JoinIdenticalVertices |
|
---|
68 | aiProcess_ImproveCacheLocality |
|
---|
69 | aiProcess_LimitBoneWeights |
|
---|
70 | aiProcess_RemoveRedundantMaterials |
|
---|
71 | aiProcess_SplitLargeMeshes |
|
---|
72 | aiProcess_Triangulate |
|
---|
73 | aiProcess_GenUVCoords |
|
---|
74 | aiProcess_SortByPType |
|
---|
75 | aiProcess_FindDegenerates |
|
---|
76 | aiProcess_FindInvalidData |
|
---|
77 | 0 );
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | bool nv::assimp_loader::load( stream& source )
|
---|
83 | {
|
---|
84 | load_assimp_library();
|
---|
85 | if ( m_scene != nullptr ) aiReleaseImport( reinterpret_cast<const aiScene*>( m_scene ) );
|
---|
86 | m_scene = nullptr;
|
---|
87 | m_mesh_count = 0;
|
---|
88 | NV_LOG_NOTICE( "AssImp loading file..." );
|
---|
89 | size_t size = source.size();
|
---|
90 | char* data = new char[ size ];
|
---|
91 | source.read( data, size, 1 );
|
---|
92 | const aiScene* scene = aiImportFileFromMemory( data, size, m_assimp_flags, m_ext.c_str() );
|
---|
93 |
|
---|
94 | if( !scene)
|
---|
95 | {
|
---|
96 | NV_LOG_ERROR( aiGetErrorString() );
|
---|
97 | return false;
|
---|
98 | }
|
---|
99 | m_scene = scene;
|
---|
100 | m_mesh_count = scene->mNumMeshes;
|
---|
101 | NV_LOG_NOTICE( "Loading successfull" );
|
---|
102 | return true;
|
---|
103 | }
|
---|
104 |
|
---|
105 | mesh_data* nv::assimp_loader::release_mesh_data( size_t index /*= 0 */ )
|
---|
106 | {
|
---|
107 | if ( index >= m_mesh_count ) return nullptr;
|
---|
108 | mesh_data* result = new mesh_data;
|
---|
109 | load_mesh_data( result, index );
|
---|
110 | return result;
|
---|
111 | }
|
---|
112 | void nv::assimp_loader::load_mesh_data( mesh_data* data, size_t index )
|
---|
113 | {
|
---|
114 | const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
|
---|
115 | const aiMesh* mesh = scene->mMeshes[ index ];
|
---|
116 | data->set_name( mesh->mName.data );
|
---|
117 |
|
---|
118 | bool skinned = mesh->mNumBones > 0;
|
---|
119 | raw_data_channel* channel = nullptr;
|
---|
120 | if ( skinned )
|
---|
121 | channel = raw_data_channel::create< assimp_skinned_vtx >( mesh->mNumVertices );
|
---|
122 | else
|
---|
123 | channel = raw_data_channel::create< assimp_plain_vtx >( mesh->mNumVertices );
|
---|
124 | uint8* cdata = const_cast< uint8*>( channel->raw_data() );
|
---|
125 |
|
---|
126 | data->add_channel( channel );
|
---|
127 | if ( mesh->mTangents && mesh->mBitangents )
|
---|
128 | for (unsigned int i=0; i<mesh->mNumVertices; i++)
|
---|
129 | {
|
---|
130 | vec3 v = assimp_vec3_cast( mesh->mVertices[ i ] );
|
---|
131 | vec3 n = glm::normalize( assimp_vec3_cast( mesh->mNormals[ i ] ) );
|
---|
132 | vec3 t = glm::normalize( assimp_vec3_cast( mesh->mTangents[ i ] ) );
|
---|
133 | vec3 b = glm::normalize( assimp_vec3_cast( mesh->mBitangents[ i ] ) );
|
---|
134 | vec2 s = assimp_st_cast( mesh->mTextureCoords[ 0 ][ i ] );
|
---|
135 |
|
---|
136 | glm::vec3 t_i = glm::normalize (t - n * glm::dot (n, t));
|
---|
137 | float det = (glm::dot (glm::cross (n, t), b));
|
---|
138 | det = (det < 0.0f ? -1.0f : 1.0f );
|
---|
139 | nv::vec4 vt ( t_i[0], t_i[1], t_i[2], det );
|
---|
140 | if ( skinned )
|
---|
141 | reinterpret_cast< assimp_skinned_vtx* >( cdata )[i] = assimp_skinned_vtx( v, s, n, vt );
|
---|
142 | else
|
---|
143 | reinterpret_cast< assimp_plain_vtx* >( cdata )[i] = assimp_plain_vtx( v, s, n, vt );
|
---|
144 | }
|
---|
145 |
|
---|
146 | if ( skinned )
|
---|
147 | {
|
---|
148 | assimp_skinned_vtx* vtx = reinterpret_cast< assimp_skinned_vtx* >( cdata );
|
---|
149 | for (unsigned int m=0; m<mesh->mNumBones; m++)
|
---|
150 | {
|
---|
151 | aiBone* bone = mesh->mBones[m];
|
---|
152 | for (unsigned int w=0; w<bone->mNumWeights; w++)
|
---|
153 | {
|
---|
154 | assimp_skinned_vtx& v = vtx[ bone->mWeights[w].mVertexId ];
|
---|
155 | bool found = false;
|
---|
156 | for ( int i = 0 ; i < 4; ++i )
|
---|
157 | {
|
---|
158 | if ( v.boneweight[i] <= 0.0f )
|
---|
159 | {
|
---|
160 | v.boneindex[i] = int( m );
|
---|
161 | v.boneweight[i] = bone->mWeights[w].mWeight;
|
---|
162 | found = true;
|
---|
163 | break;
|
---|
164 | }
|
---|
165 | }
|
---|
166 | NV_ASSERT( found, "Too many weights!" );
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | data_channel_creator< index_u16 > ichannel( mesh->mNumFaces * 3 );
|
---|
172 | uint16* indices = reinterpret_cast<uint16*>( ichannel.raw_data() );
|
---|
173 | for (unsigned int i=0; i<mesh->mNumFaces; i++)
|
---|
174 | {
|
---|
175 | const aiFace* face = &mesh->mFaces[i];
|
---|
176 | for (unsigned int j=0; j<face->mNumIndices; j++)
|
---|
177 | {
|
---|
178 | indices[ i*3 + j ] = uint16( face->mIndices[j] );
|
---|
179 | }
|
---|
180 | }
|
---|
181 | data->add_channel( ichannel.release() );
|
---|
182 | }
|
---|
183 |
|
---|
184 | nv::assimp_loader::~assimp_loader()
|
---|
185 | {
|
---|
186 | if ( m_scene != nullptr ) aiReleaseImport( reinterpret_cast<const aiScene*>( m_scene ) );
|
---|
187 | }
|
---|
188 |
|
---|
189 | bool nv::assimp_loader::load_bones( size_t index, array_ref< mesh_node_data > bones )
|
---|
190 | {
|
---|
191 | if ( m_scene == nullptr ) return false;
|
---|
192 | const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
|
---|
193 | const aiMesh* mesh = scene->mMeshes[ index ];
|
---|
194 |
|
---|
195 | for (unsigned int m=0; m<mesh->mNumBones; m++)
|
---|
196 | {
|
---|
197 | aiBone* bone = mesh->mBones[m];
|
---|
198 | mat4 offset = assimp_mat4_cast( bone->mOffsetMatrix );
|
---|
199 | bones[m].name = bone->mName.data;
|
---|
200 | bones[m].data = nullptr;
|
---|
201 | bones[m].parent_id = -1;
|
---|
202 | bones[m].target_id = -1;
|
---|
203 | bones[m].transform = offset;
|
---|
204 | }
|
---|
205 | return true;
|
---|
206 | }
|
---|
207 |
|
---|
208 | void nv::assimp_loader::scene_report() const
|
---|
209 | {
|
---|
210 | const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
|
---|
211 | if ( scene == nullptr ) return;
|
---|
212 |
|
---|
213 | NV_LOG_NOTICE( "------------------------" );
|
---|
214 | NV_LOG_NOTICE( "Texture count - ", scene->mNumTextures );
|
---|
215 | NV_LOG_NOTICE( "Animation count - ", scene->mNumAnimations );
|
---|
216 | NV_LOG_NOTICE( "Material count - ", scene->mNumMaterials );
|
---|
217 | NV_LOG_NOTICE( "Meshes count - ", scene->mNumMeshes );
|
---|
218 | NV_LOG_NOTICE( "------------------------" );
|
---|
219 |
|
---|
220 | aiNode* root = scene->mRootNode;
|
---|
221 | if (root)
|
---|
222 | {
|
---|
223 | NV_LOG_NOTICE( "Root node - ", root->mName.data );
|
---|
224 | NV_LOG_NOTICE( " meshes - ", root->mNumMeshes );
|
---|
225 | NV_LOG_NOTICE( " children - ", root->mNumChildren );
|
---|
226 | }
|
---|
227 | else
|
---|
228 | {
|
---|
229 | NV_LOG_NOTICE( "No root node!" );
|
---|
230 | }
|
---|
231 | NV_LOG_NOTICE( "------------------------" );
|
---|
232 |
|
---|
233 | if ( scene->mNumMeshes > 0 )
|
---|
234 | {
|
---|
235 | for ( nv::uint32 mc = 0; mc < scene->mNumMeshes; mc++ )
|
---|
236 | {
|
---|
237 | aiMesh* mesh = scene->mMeshes[mc];
|
---|
238 |
|
---|
239 | NV_LOG_NOTICE( "Mesh #", mc, " - ", string_view( static_cast<char*>( mesh->mName.data ) ) );
|
---|
240 | NV_LOG_NOTICE( " bones - ", mesh->mNumBones );
|
---|
241 | NV_LOG_NOTICE( " uvs - ", mesh->mNumUVComponents[0] );
|
---|
242 | NV_LOG_NOTICE( " verts - ", mesh->mNumVertices );
|
---|
243 | NV_LOG_NOTICE( " faces - ", mesh->mNumFaces );
|
---|
244 |
|
---|
245 | // NV_LOG_NOTICE( "Bones:" );
|
---|
246 | // for (unsigned int m=0; m<mesh->mNumBones; m++)
|
---|
247 | // {
|
---|
248 | // aiBone* bone = mesh->mBones[m];
|
---|
249 | // NV_LOG_NOTICE( bone->mName.C_Str() );
|
---|
250 | // }
|
---|
251 | }
|
---|
252 | }
|
---|
253 | else
|
---|
254 | {
|
---|
255 | NV_LOG_NOTICE( "No meshes!" );
|
---|
256 | }
|
---|
257 | NV_LOG_NOTICE( "------------------------" );
|
---|
258 |
|
---|
259 |
|
---|
260 | // if ( scene->mNumMaterials > 0 )
|
---|
261 | // {
|
---|
262 | // for (unsigned int m=0; m < scene->mNumMaterials; m++)
|
---|
263 | // {
|
---|
264 | // int texIndex = 0;
|
---|
265 | // aiReturn texFound = aiReturn_SUCCESS;
|
---|
266 | // aiString path; // filename
|
---|
267 | // while (texFound == aiReturn_SUCCESS)
|
---|
268 | // {
|
---|
269 | // texFound = scene->mMaterials[m]->GetTexture(aiTextureType_DIFFUSE, texIndex, &path);
|
---|
270 | // NV_LOG_NOTICE( " material - ", path.data );
|
---|
271 | // texIndex++;
|
---|
272 | // }
|
---|
273 | // }
|
---|
274 | // }
|
---|
275 | // else
|
---|
276 | // {
|
---|
277 | // NV_LOG_NOTICE( "No materials" );
|
---|
278 | // }
|
---|
279 | // NV_LOG_NOTICE( "------------------------" );
|
---|
280 |
|
---|
281 | }
|
---|
282 |
|
---|
283 | mesh_nodes_data* nv::assimp_loader::release_merged_bones( mesh_data* meshes )
|
---|
284 | {
|
---|
285 | const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
|
---|
286 | vector< mesh_node_data > final_bones;
|
---|
287 | unordered_map< std::string, uint16 > names;
|
---|
288 | for ( unsigned int m = 0; m < m_mesh_count; ++m )
|
---|
289 | {
|
---|
290 | uint16 translate[MAX_BONES];
|
---|
291 | vector< mesh_node_data > bones;
|
---|
292 | const aiMesh* mesh = scene->mMeshes[ m ];
|
---|
293 | if ( mesh->mNumBones != 0 )
|
---|
294 | {
|
---|
295 | bones.resize( mesh->mNumBones );
|
---|
296 | load_bones( m, bones );
|
---|
297 | for ( unsigned int b = 0; b < mesh->mNumBones; ++b )
|
---|
298 | {
|
---|
299 |
|
---|
300 | mesh_node_data& bone = bones[b];
|
---|
301 | auto iname = names.find( bone.name );
|
---|
302 | if ( iname == names.end() )
|
---|
303 | {
|
---|
304 | NV_ASSERT( final_bones.size() < MAX_BONES, "Too many bones to merge!" );
|
---|
305 | uint16 index = uint16( final_bones.size() );
|
---|
306 | final_bones.push_back( bone );
|
---|
307 | names[ bone.name ] = index;
|
---|
308 | translate[b] = index;
|
---|
309 | }
|
---|
310 | else
|
---|
311 | {
|
---|
312 | translate[b] = iname->second;
|
---|
313 | }
|
---|
314 | }
|
---|
315 | if ( m > 0 && bones.size() > 0 )
|
---|
316 | {
|
---|
317 | data_channel_creator< assimp_skinned_vtx > channel( meshes[m].get_raw_channels()[0] );
|
---|
318 | for ( unsigned v = 0; v < channel.size(); ++v )
|
---|
319 | {
|
---|
320 | assimp_skinned_vtx& vertex = channel.data()[v];
|
---|
321 |
|
---|
322 | for ( int i = 0 ; i < 4; ++i)
|
---|
323 | {
|
---|
324 | if ( vertex.boneweight[i] > 0.0f )
|
---|
325 | {
|
---|
326 | vertex.boneindex[i] = int( translate[vertex.boneindex[i]] );
|
---|
327 | }
|
---|
328 | }
|
---|
329 | }
|
---|
330 | }
|
---|
331 | }
|
---|
332 | }
|
---|
333 | mesh_node_data* bones = new mesh_node_data[ final_bones.size() ];
|
---|
334 | raw_copy( final_bones.begin(), final_bones.end(), bones );
|
---|
335 | return new mesh_nodes_data( "bones", final_bones.size(), bones );
|
---|
336 | }
|
---|
337 |
|
---|
338 | mesh_nodes_data* nv::assimp_loader::release_mesh_nodes_data( size_t index /*= 0*/ )
|
---|
339 | {
|
---|
340 | if ( m_scene == nullptr ) return nullptr;
|
---|
341 | const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
|
---|
342 | if ( scene->mRootNode == nullptr || scene->mAnimations == nullptr || scene->mAnimations[index] == nullptr) return nullptr;
|
---|
343 |
|
---|
344 | const aiNode* root = scene->mRootNode;
|
---|
345 | const aiAnimation* anim = scene->mAnimations[index];
|
---|
346 |
|
---|
347 | uint32 count = count_nodes( scene->mRootNode );
|
---|
348 | mesh_node_data* data = new mesh_node_data[count];
|
---|
349 |
|
---|
350 | uint16 frame_rate = static_cast<uint16>( anim->mTicksPerSecond );
|
---|
351 | float duration = static_cast<float>( anim->mDuration );
|
---|
352 | bool flat = false;
|
---|
353 |
|
---|
354 | load_node( index, data, root, 0, -1 );
|
---|
355 |
|
---|
356 | return new mesh_nodes_data( anim->mName.data, count, data, frame_rate, duration, flat );
|
---|
357 | }
|
---|
358 |
|
---|
359 | nv::uint32 nv::assimp_loader::count_nodes( const void* node ) const
|
---|
360 | {
|
---|
361 | const aiNode* ainode = reinterpret_cast< const aiNode* >( node );
|
---|
362 | nv::uint32 count = 1;
|
---|
363 | for ( unsigned i = 0; i < ainode->mNumChildren; ++i )
|
---|
364 | {
|
---|
365 | count += count_nodes( ainode->mChildren[i] );
|
---|
366 | }
|
---|
367 | return count;
|
---|
368 | }
|
---|
369 |
|
---|
370 | nv::sint16 nv::assimp_loader::load_node( uint32 anim_id, mesh_node_data* nodes, const void* vnode, sint16 this_id, sint16 parent_id )
|
---|
371 | {
|
---|
372 | const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
|
---|
373 | const aiNode* node = reinterpret_cast<const aiNode*>( vnode );
|
---|
374 | std::string name( node->mName.data );
|
---|
375 | const aiAnimation* anim = scene->mAnimations[anim_id];
|
---|
376 | const aiNodeAnim* anode = nullptr;
|
---|
377 |
|
---|
378 | for ( unsigned i = 0 ; i < anim->mNumChannels ; i++ )
|
---|
379 | {
|
---|
380 | anode = anim->mChannels[i];
|
---|
381 | if ( std::string( anode->mNodeName.data ) == name ) break;
|
---|
382 | anode = nullptr;
|
---|
383 | }
|
---|
384 |
|
---|
385 | mesh_node_data& a_data = nodes[ this_id ];
|
---|
386 |
|
---|
387 | a_data.name = name;
|
---|
388 | a_data.target_id = -1;
|
---|
389 | a_data.parent_id = parent_id;
|
---|
390 | // This value is ignored by the create_transformed_keys, but needed by create_direct_keys!
|
---|
391 | // TODO: find a common solution!
|
---|
392 | // This is bad because create_transformed_keys never uses node-transformations for
|
---|
393 | // node's without keys
|
---|
394 | a_data.transform = nv::assimp_mat4_cast( node->mTransformation );
|
---|
395 | if (this_id == 0)
|
---|
396 | a_data.transform = mat4();
|
---|
397 | a_data.data = nullptr;
|
---|
398 |
|
---|
399 | if (anode) create_keys( &a_data, anode );
|
---|
400 |
|
---|
401 | nv::sint16 next = this_id + 1;
|
---|
402 | for ( unsigned i = 0; i < node->mNumChildren; ++i )
|
---|
403 | {
|
---|
404 | next = load_node( anim_id, nodes, node->mChildren[i], next, this_id );
|
---|
405 | }
|
---|
406 |
|
---|
407 | return next;
|
---|
408 | }
|
---|
409 |
|
---|
410 | void nv::assimp_loader::create_keys( mesh_node_data* data, const void* vnode )
|
---|
411 | {
|
---|
412 | const aiNodeAnim* node = reinterpret_cast< const aiNodeAnim* >( vnode );
|
---|
413 | if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 )
|
---|
414 | {
|
---|
415 | return;
|
---|
416 | }
|
---|
417 |
|
---|
418 | data->data = new key_data;
|
---|
419 | data_channel_creator< assimp_key_p > pchannel_creator( node->mNumPositionKeys );
|
---|
420 | data_channel_creator< assimp_key_r > rchannel_creator( node->mNumRotationKeys );
|
---|
421 | // data_channel_creator< assimp_key_s > schannel_creator( node->mNumScalingKeys );
|
---|
422 |
|
---|
423 | assimp_key_p* pchannel = pchannel_creator.data();
|
---|
424 | assimp_key_r* rchannel = rchannel_creator.data();
|
---|
425 | //assimp_key_s* schannel = ((assimp_key_s*)(raw_schannel->data));
|
---|
426 |
|
---|
427 | for ( unsigned np = 0; np < node->mNumPositionKeys; ++np )
|
---|
428 | {
|
---|
429 | pchannel[np].time = static_cast<float>( node->mPositionKeys[np].mTime );
|
---|
430 | pchannel[np].translation = assimp_vec3_cast(node->mPositionKeys[np].mValue);
|
---|
431 | }
|
---|
432 | for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
|
---|
433 | {
|
---|
434 | rchannel[np].time = static_cast<float>( node->mRotationKeys[np].mTime );
|
---|
435 | rchannel[np].rotation = assimp_quat_cast(node->mRotationKeys[np].mValue );
|
---|
436 | }
|
---|
437 | // if ( node->mNumScalingKeys > 0 )
|
---|
438 | // {
|
---|
439 | // nv::vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue );
|
---|
440 | // float scale_value = glm::length( glm::abs( scale_vec0 - nv::vec3(1,1,1) ) );
|
---|
441 | // if ( node->mNumScalingKeys > 1 || scale_value > 0.001 )
|
---|
442 | // {
|
---|
443 | // NV_LOG( nv::LOG_WARNING, "scale key significant!" );
|
---|
444 | // for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
|
---|
445 | // {
|
---|
446 | // schannel[np].time = (float)node->mScalingKeys[np].mTime;
|
---|
447 | // schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue);
|
---|
448 | // }
|
---|
449 | // }
|
---|
450 | // else
|
---|
451 | // {
|
---|
452 | // schannel[0].time = (float)node->mScalingKeys[0].mTime;
|
---|
453 | // schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue);
|
---|
454 | // }
|
---|
455 | // }
|
---|
456 | data->data->add_channel( pchannel_creator.release() );
|
---|
457 | data->data->add_channel( rchannel_creator.release() );
|
---|
458 | // data->data->add_channel( schannel_creator.release() );
|
---|
459 | }
|
---|
460 |
|
---|
461 | mesh_data_pack* nv::assimp_loader::release_mesh_data_pack()
|
---|
462 | {
|
---|
463 | if ( m_scene == nullptr || m_mesh_count == 0 ) return nullptr;
|
---|
464 | const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
|
---|
465 | bool has_bones = false;
|
---|
466 | mesh_data* meshes = new mesh_data[ m_mesh_count ];
|
---|
467 | for ( size_t m = 0; m < m_mesh_count; ++m )
|
---|
468 | {
|
---|
469 | const aiMesh* mesh = scene->mMeshes[ m ];
|
---|
470 | meshes[m].set_name( mesh->mName.data );
|
---|
471 | if ( mesh->mNumBones > 0 ) has_bones = true;
|
---|
472 | load_mesh_data(&meshes[m],m);
|
---|
473 | }
|
---|
474 |
|
---|
475 | mesh_nodes_data* nodes = ( has_bones ? release_merged_bones( meshes ) : release_mesh_nodes_data(0) );
|
---|
476 | return new mesh_data_pack( m_mesh_count, meshes, nodes );
|
---|
477 | }
|
---|
478 |
|
---|
479 | nv::size_t nv::assimp_loader::get_nodes_data_count() const
|
---|
480 | {
|
---|
481 | if ( m_scene == nullptr ) return 0;
|
---|
482 | const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
|
---|
483 | return scene->mNumAnimations;
|
---|
484 | }
|
---|
485 |
|
---|
486 |
|
---|