Changeset 482 for trunk/src/formats/assimp_loader.cc
- Timestamp:
- 11/12/15 19:02:08 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r480 r482 105 105 } 106 106 107 data_channel_set* nv::assimp_loader::release_mesh_data( size_t index /*= 0 */)107 data_channel_set* nv::assimp_loader::release_mesh_data( size_t index, data_node_info& info ) 108 108 { 109 109 if ( index >= m_mesh_count ) return nullptr; 110 110 data_channel_set* result = data_channel_set_creator::create_set( 2 ); 111 load_mesh_data( result, index );111 load_mesh_data( result, index, info ); 112 112 return result; 113 113 } 114 void nv::assimp_loader::load_mesh_data( data_channel_set* data, size_t index )114 void nv::assimp_loader::load_mesh_data( data_channel_set* data, size_t index, data_node_info& info ) 115 115 { 116 116 const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene ); … … 126 126 data_channel_set_creator maccess( data ); 127 127 const char* name = mesh->mName.data; 128 maccess.set_name( make_name( name ) ); 128 info.name = make_name( name ); 129 info.parent_id = -1; 129 130 uint8* cdata = maccess.add_channel( desc, mesh->mNumVertices ).raw_data(); 130 131 uint16* indices = reinterpret_cast<uint16*>( maccess.add_channel< index_u16 >( mesh->mNumFaces * 3 ).raw_data() ); … … 190 191 } 191 192 192 bool nv::assimp_loader::load_bones( size_t index, array_ref< data_ channel_set*> bones )193 bool nv::assimp_loader::load_bones( size_t index, array_ref< data_node_info > bones ) 193 194 { 194 195 if ( m_scene == nullptr ) return false; … … 200 201 aiBone* bone = mesh->mBones[m]; 201 202 mat4 offset = assimp_mat4_cast( bone->mOffsetMatrix ); 202 bones[m] = data_channel_set_creator::create_set( 0 );203 data_channel_set_creator access( bones[m] );204 203 const char* name = bone->mName.data; 205 access.set_name( make_name( name ));206 access.set_transform( offset );204 bones[m].name = make_name( name ); 205 bones[m].transform = offset; 207 206 } 208 207 return true; … … 284 283 } 285 284 286 mesh_nodes_data* nv::assimp_loader::release_merged_bones( data_channel_set* meshes )287 { 288 const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene ); 289 mesh_nodes_data* result = new mesh_nodes_data( make_name( "bones" ) );285 data_node_list* nv::assimp_loader::release_merged_bones( data_channel_set* meshes ) 286 { 287 const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene ); 288 data_node_list* result = new data_node_list( make_name( "bones" ) ); 290 289 hash_store< shash64, uint16 > names; 291 290 for ( unsigned int m = 0; m < m_mesh_count; ++m ) 292 291 { 293 292 uint16 translate[MAX_BONES]; 294 vector< data_ channel_set*> bones;293 vector< data_node_info > bones; 295 294 const aiMesh* mesh = scene->mMeshes[ m ]; 296 295 if ( mesh->mNumBones != 0 ) 297 296 { 298 297 bones.resize( mesh->mNumBones ); 298 NV_ASSERT( false, "parent ids for bones are not loaded!" ); 299 299 load_bones( m, bones ); 300 300 for ( unsigned int b = 0; b < mesh->mNumBones; ++b ) 301 301 { 302 302 303 data_ channel_set*bone = bones[b];304 auto iname = names.find( bone ->get_name());303 data_node_info bone = bones[b]; 304 auto iname = names.find( bone.name ); 305 305 if ( iname == names.end() ) 306 306 { … … 308 308 uint16 index = uint16( result->size() ); 309 309 result->append( bone ); 310 names[ bone ->get_name()] = index;310 names[ bone.name ] = index; 311 311 translate[b] = index; 312 312 } … … 334 334 } 335 335 } 336 result->initialize();336 //result->initialize(); 337 337 338 338 return result; … … 352 352 uint16 frame_rate = static_cast<uint16>( anim->mTicksPerSecond ); 353 353 uint16 duration = static_cast<uint16>( anim->mDuration ); 354 bool flat = false; 355 356 data_ channel_set** temp = new data_channel_set*[ count];354 355 data_channel_set** temp = new data_channel_set*[ count ]; 356 data_node_info* temp2 = new data_node_info[count]; 357 357 array_ref< data_channel_set* > temp_ref( temp, count ); 358 load_node( index, temp_ref, root, 0, -1 ); 359 360 mesh_nodes_data* result = new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), frame_rate, duration, flat ); 361 for ( auto set : temp_ref ) 362 { 363 result->append( set ); 358 array_ref< data_node_info > temp2_ref( temp2, count ); 359 load_node( index, temp_ref, temp2_ref, root, 0, -1 ); 360 361 mesh_nodes_data* result = new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), frame_rate, duration ); 362 for ( nv::uint32 i = 0; i < count; ++i ) 363 { 364 result->append( temp_ref[i], temp2_ref[i] ); 364 365 } 365 366 result->initialize(); 366 367 delete temp; 368 delete temp2; 367 369 return result; 370 } 371 372 data_node_list* nv::assimp_loader::release_data_node_list( size_t index /*= 0 */ ) 373 { 374 int this_is_incorrect; 375 NV_ASSERT( false, "unimplemented!" ); 376 // mesh_nodes_data* half_result = release_mesh_nodes_data( index ); 377 // data_node_list* result = new data_node_list( half_result->get_name() ); 378 // for ( auto node : *half_result ) 379 // result->append( node->get_info() ); 380 // delete half_result; 381 // return result; 382 return nullptr; 383 } 384 385 bool nv::assimp_loader::is_animated( size_t /*= 0 */ ) 386 { 387 int this_is_incorrect; 388 return false; 368 389 } 369 390 … … 379 400 } 380 401 381 nv::sint16 nv::assimp_loader::load_node( uint32 anim_id, array_ref< data_channel_set* > nodes, const void* vnode, sint16 this_id, sint16 parent_id )402 nv::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 ) 382 403 { 383 404 const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene ); … … 396 417 nodes[ this_id ] = anode ? create_keys( anode ) : data_channel_set_creator::create_set( 0 ); 397 418 398 data_channel_set_creator access( nodes[this_id] ); 399 access.set_name( make_name( name ) ); 400 access.set_parent_id( parent_id ); 419 infos[this_id].name = make_name( name ); 420 infos[this_id].parent_id = parent_id; 401 421 // This value is ignored by the create_transformed_keys, but needed by create_direct_keys! 402 422 // TODO: find a common solution! 403 423 // This is bad because create_transformed_keys never uses node-transformations for 404 424 // node's without keys 405 access.set_transform( nv::assimp_mat4_cast( node->mTransformation ) ); 406 if ( this_id == 0 ) access.set_transform( mat4() ); 425 // TODO: this can probably be deleted 426 infos[this_id].transform = nv::assimp_mat4_cast( node->mTransformation ); 427 if ( this_id == 0 ) infos[this_id].transform = mat4(); 407 428 408 429 nv::sint16 next = this_id + 1; 409 430 for ( unsigned i = 0; i < node->mNumChildren; ++i ) 410 431 { 411 next = load_node( anim_id, nodes, node->mChildren[i], next, this_id );432 next = load_node( anim_id, nodes, infos, node->mChildren[i], next, this_id ); 412 433 } 413 434
Note: See TracChangeset
for help on using the changeset viewer.