Changeset 427 for trunk/src/formats
- Timestamp:
- 07/20/15 13:25:20 (10 years ago)
- Location:
- trunk/src/formats
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r425 r427 190 190 } 191 191 192 bool nv::assimp_loader::load_bones( size_t index, array_ref< mesh_node_data> bones )192 bool nv::assimp_loader::load_bones( size_t index, array_ref< data_channel_set* > bones ) 193 193 { 194 194 if ( m_scene == nullptr ) return false; … … 200 200 aiBone* bone = mesh->mBones[m]; 201 201 mat4 offset = assimp_mat4_cast( bone->mOffsetMatrix ); 202 bones[m] .data= data_channel_set_creator::create_set( 0 );203 data_channel_set_creator access( bones[m] .data);202 bones[m] = data_channel_set_creator::create_set( 0 ); 203 data_channel_set_creator access( bones[m] ); 204 204 const char* name = bone->mName.data; 205 205 access.set_name( make_name( name ) ); … … 287 287 { 288 288 const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene ); 289 vector< mesh_node_data > final_bones;289 mesh_nodes_data* result = new mesh_nodes_data( make_name( "bones" ) ); 290 290 unordered_map< uint64, uint16 > names; 291 291 for ( unsigned int m = 0; m < m_mesh_count; ++m ) 292 292 { 293 293 uint16 translate[MAX_BONES]; 294 vector< mesh_node_data> bones;294 vector< data_channel_set* > bones; 295 295 const aiMesh* mesh = scene->mMeshes[ m ]; 296 296 if ( mesh->mNumBones != 0 ) … … 301 301 { 302 302 303 mesh_node_data&bone = bones[b];304 auto iname = names.find( bone .data->get_name() );303 data_channel_set* bone = bones[b]; 304 auto iname = names.find( bone->get_name() ); 305 305 if ( iname == names.end() ) 306 306 { 307 NV_ASSERT( final_bones.size() < MAX_BONES, "Too many bones to merge!" );308 uint16 index = uint16( final_bones.size() );309 final_bones.push_back( bone );310 names[ bone .data->get_name() ] = index;307 NV_ASSERT( result->get_count() < MAX_BONES, "Too many bones to merge!" ); 308 uint16 index = uint16( result->get_count() ); 309 result->push_back( bone ); 310 names[ bone->get_name() ] = index; 311 311 translate[b] = index; 312 312 } … … 334 334 } 335 335 } 336 mesh_node_data* bones = new mesh_node_data[ final_bones.size() ]; 337 raw_copy( final_bones.begin(), final_bones.end(), bones ); 338 return new mesh_nodes_data( make_name( "bones" ), final_bones.size(), bones ); 336 337 return result; 339 338 } 340 339 … … 349 348 350 349 uint32 count = count_nodes( scene->mRootNode ); 351 mesh_node_data* data = new mesh_node_data[count];352 350 353 351 uint16 frame_rate = static_cast<uint16>( anim->mTicksPerSecond ); … … 355 353 bool flat = false; 356 354 357 load_node( index, data, root, 0, -1 ); 358 359 return new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), count, data, frame_rate, duration, flat ); 355 data_channel_set** temp = new data_channel_set*[ count ]; 356 array_ref< data_channel_set* > temp_ref( temp, count ); 357 load_node( index, temp_ref, root, 0, -1 ); 358 359 mesh_nodes_data* result = new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), frame_rate, duration, flat ); 360 for ( auto set : temp_ref ) 361 { 362 result->push_back( set ); 363 } 364 delete temp; 365 return result; 360 366 } 361 367 … … 371 377 } 372 378 373 nv::sint16 nv::assimp_loader::load_node( uint32 anim_id, mesh_node_data*nodes, const void* vnode, sint16 this_id, sint16 parent_id )379 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 ) 374 380 { 375 381 const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene ); … … 386 392 } 387 393 388 mesh_node_data& a_data = nodes[ this_id ]; 389 390 if (anode) 391 create_keys( &a_data, anode ); 392 else 393 a_data.data = data_channel_set_creator::create_set( 0 ); 394 395 data_channel_set_creator access( a_data.data ); 394 nodes[ this_id ] = anode ? create_keys( anode ) : data_channel_set_creator::create_set( 0 ); 395 396 data_channel_set_creator access( nodes[this_id] ); 396 397 access.set_name( make_name( name ) ); 397 398 access.set_parent_id( parent_id ); … … 412 413 } 413 414 414 void nv::assimp_loader::create_keys( mesh_node_data* data,const void* vnode )415 data_channel_set* nv::assimp_loader::create_keys( const void* vnode ) 415 416 { 416 417 const aiNodeAnim* node = reinterpret_cast< const aiNodeAnim* >( vnode ); 417 418 if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 ) 418 419 { 419 return ;420 } 421 422 data ->data= data_channel_set_creator::create_set( 2 );423 data_channel_set_creator key_set( data->data);420 return data_channel_set_creator::create_set( 0 ); 421 } 422 423 data_channel_set* set = data_channel_set_creator::create_set( 2 ); 424 data_channel_set_creator key_set( set ); 424 425 425 426 assimp_key_p* pchannel = key_set.add_channel< assimp_key_p >( node->mNumPositionKeys ).data(); … … 456 457 // } 457 458 // } 458 459 return set; 459 460 } 460 461 -
trunk/src/formats/md3_loader.cc
r425 r427 420 420 uint32 node_count = uint32( md3->header.num_tags ); 421 421 if ( node_count == 0 ) return nullptr; 422 mesh_node _data* nodes = new mesh_node_data[ node_count ];422 mesh_nodes_data* result = new mesh_nodes_data( m_strings ? m_strings->insert( "tags" ) : 0 ); 423 423 for ( uint32 i = 0; i < node_count; ++i ) 424 424 { 425 425 const md3_tag_t& rtag = md3->tags[i]; 426 426 string_view name( reinterpret_cast< const char* >(rtag.name) ); 427 nodes[i].data= data_channel_set_creator::create_set( 1 );428 data_channel_set_creator access( nodes[i].data);427 data_channel_set* set = data_channel_set_creator::create_set( 1 ); 428 data_channel_set_creator access( set ); 429 429 access.set_name( make_name( name ) ); 430 430 load_tags( access.add_channel<md3_key>( uint32( md3->header.num_frames ) ).channel(), name ); 431 } 432 return new mesh_nodes_data( m_strings ? m_strings->insert( "tags" ) : 0, node_count, nodes ); 431 result->push_back( set ); 432 } 433 return result; 433 434 } 434 435 -
trunk/src/formats/md5_loader.cc
r425 r427 46 46 std_stream sstream( &source ); 47 47 std::string command; 48 mesh_node_data* nodes = nullptr;49 48 size_t num_joints = 0; 50 49 … … 111 110 assert( m_type == MESH ); 112 111 assert( m_nodes == nullptr ); 113 nodes = new mesh_node_data[ num_joints ]; 114 m_nodes = new mesh_nodes_data( make_name( "md5_bones"), num_joints, nodes ); 112 m_nodes = new mesh_nodes_data( make_name( "md5_bones") ); 115 113 discard( sstream, "{" ); 116 114 for ( size_t i = 0; i < m_nodes->get_count(); ++i ) … … 128 126 unit_quat_w( orient ); 129 127 remove_quotes( name ); 130 nodes[i].data= data_channel_set_creator::create_set( 0 );131 data_channel_set_creator access( nodes[i].data);128 data_channel_set* set = data_channel_set_creator::create_set( 0 ); 129 data_channel_set_creator access( set ); 132 130 access.set_parent_id( parent_id ); 133 131 access.set_transform( transform( pos, orient ).inverse().extract() ); 134 132 access.set_name( make_name( name.c_str() ) ); 135 133 next_line( sstream ); 134 m_nodes->push_back( set ); 136 135 } 137 136 discard( sstream, "}" ); … … 233 232 } 234 233 235 prepare_mesh( nodes, weight_info.size(), mesh, weights.data(), weight_info.data() );234 prepare_mesh( m_nodes, weight_info.size(), mesh, weights.data(), weight_info.data() ); 236 235 237 236 m_meshes[ num_meshes ] = mesh; … … 241 240 { 242 241 assert( m_type == ANIMATION ); 243 assert( nodes == nullptr ); 244 nodes = new mesh_node_data[ num_joints ]; 245 m_nodes = new mesh_nodes_data( make_name( "md5_animation" ), num_joints, nodes, static_cast< nv::uint16 >( frame_rate ), static_cast< float >( num_frames ), true ); 242 assert( m_nodes == nullptr ); 243 m_nodes = new mesh_nodes_data( make_name( "md5_animation" ), static_cast< nv::uint16 >( frame_rate ), static_cast< float >( num_frames ), true ); 246 244 joint_infos.resize( num_joints ); 247 245 … … 253 251 sstream >> name >> parent_id >> joint_infos[i].flags >> joint_infos[i].start_index; 254 252 remove_quotes( name ); 255 nodes[i].data= data_channel_set_creator::create_set( 1 );256 data_channel_set_creator access( nodes[i].data);253 data_channel_set* set = data_channel_set_creator::create_set( 1 ); 254 data_channel_set_creator access( set ); 257 255 access.add_channel< md5_key_t >( num_frames ); 258 256 access.set_name( make_name( name.c_str() ) ); 259 257 access.set_parent_id( parent_id ); 258 m_nodes->push_back( set ); 260 259 next_line( sstream ); 261 260 } … … 322 321 } 323 322 324 build_frame_skeleton( nodes, frame_id, joint_infos, base_frames, frame );323 build_frame_skeleton( m_nodes, frame_id, joint_infos, base_frames, frame ); 325 324 326 325 discard( sstream, "}" ); … … 334 333 } 335 334 336 bool md5_loader::prepare_mesh( mesh_node _data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info )335 bool md5_loader::prepare_mesh( mesh_nodes_data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info ) 337 336 { 338 337 assert( m_type == MESH ); … … 389 388 if ( j < weight_count ) 390 389 { 391 md5_weight& weight = weights[start_weight + j];392 const mesh_node_data& joint = nodes[weight.joint_id];393 const transform tr = transform( joint .data->get_transform() ).inverse();390 md5_weight& weight = weights[start_weight + j]; 391 const data_channel_set* joint = (*nodes)[weight.joint_id]; 392 const transform tr = transform( joint->get_transform() ).inverse(); 394 393 vec3 rot_pos = tr.get_orientation() * weight.pos; 395 394 … … 453 452 for ( int j = 0; j < 4; ++j ) 454 453 { 455 const mesh_node_data& joint = nodes[vdata.boneindex[j]];456 const transform tr = transform( joint .data->get_transform() ).inverse();454 const data_channel_set* joint = ( *nodes )[vdata.boneindex[j]]; 455 const transform tr = transform( joint->get_transform() ).inverse(); 457 456 vdata.normal += ( normal * tr.get_orientation() ) * vdata.boneweight[j]; 458 457 vdata.tangent += ( tangent * tr.get_orientation() ) * vdata.boneweight[j]; … … 463 462 } 464 463 465 void md5_loader::build_frame_skeleton( mesh_node _data* nodes, uint32 index, const array_view<md5_joint_info>& joint_infos, const array_view<transform>& base_frames, const array_view<float>& frame_data )464 void md5_loader::build_frame_skeleton( mesh_nodes_data* nodes, uint32 index, const array_view<md5_joint_info>& joint_infos, const array_view<transform>& base_frames, const array_view<float>& frame_data ) 466 465 { 467 466 assert( m_type == ANIMATION ); … … 471 470 472 471 const md5_joint_info& jinfo = joint_infos[i]; 473 mesh_node_data& joint = nodes[i];474 int parent_id = joint .data->get_parent_id();472 const data_channel_set* joint = (*nodes)[i]; 473 int parent_id = joint->get_parent_id(); 475 474 476 475 vec3 pos = base_frames[i].get_position(); … … 486 485 if ( parent_id >= 0 ) // Has a parent joint 487 486 { 488 const mesh_node_data& pjoint = nodes[parent_id];489 const transform* ptv = reinterpret_cast< const transform* >( pjoint .data->get_channel(0)->raw_data() );487 const data_channel_set* pjoint = ( *nodes )[i]; 488 const transform* ptv = reinterpret_cast< const transform* >( pjoint->get_channel(0)->raw_data() ); 490 489 transform ptr; 491 if ( pjoint .data->get_channel(0)->size() > index ) ptr = ptv[ index ];490 if ( pjoint->get_channel(0)->size() > index ) ptr = ptv[ index ]; 492 491 vec3 rot_pos = ptr.get_orientation() * pos; 493 492 … … 498 497 } 499 498 500 reinterpret_cast< transform* >( const_cast< uint8* >( joint .data->get_channel(0)->raw_data() ) )[index] = transform( pos, orient );499 reinterpret_cast< transform* >( const_cast< uint8* >( joint->get_channel(0)->raw_data() ) )[index] = transform( pos, orient ); 501 500 } 502 501 } -
trunk/src/formats/nmd_loader.cc
r425 r427 71 71 72 72 m_node_data = nullptr; 73 m_node_array = nullptr;74 73 } 75 74 … … 100 99 nmd_animation_header animation_header; 101 100 source.read( &animation_header, sizeof( animation_header ), 1 ); 102 m_node_ array = new mesh_node_data[ e.children ];101 m_node_data = new mesh_nodes_data( e.name, animation_header.frame_rate, animation_header.duration, animation_header.flat ); 103 102 for ( uint32 i = 0; i < e.children; ++i ) 104 103 { … … 107 106 skip_attributes( source, element_header.attributes ); 108 107 NV_ASSERT( element_header.type == nmd_type::NODE, "NODE expected!" ); 109 m_node_array[i].data= data_channel_set_creator::create_set( element_header.children );110 load_channel_set( source, m_node_array[i].data, element_header );111 }112 m_node_data = new mesh_nodes_data( e.name, e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat );108 data_channel_set* set = data_channel_set_creator::create_set( element_header.children ); 109 load_channel_set( source, set, element_header ); 110 m_node_data->push_back( set ); 111 } 113 112 return true; 114 113 } … … 144 143 mesh_nodes_data* result = m_node_data; 145 144 m_node_data = nullptr; 146 m_node_array = nullptr;147 145 return result; 148 146 } … … 153 151 // nmd format dump 154 152 // HACK : TEMPORARY - will go to it's own file, probably nmd_io 155 static void nmd_dump_channel( const raw_data_channel* channel , stream& stream_out )156 {157 nmd_channel_header sheader;158 sheader.format = channel->descriptor();159 sheader.count = channel->size();160 stream_out.write( &sheader, sizeof( sheader ), 1 );161 stream_out.write( channel->raw_data(), channel->element_size(), channel->size() );162 }163 164 static void nmd_dump_channel_set( const data_channel_set* channel_set, stream& stream_out )165 {166 for ( auto& channel : *channel_set )167 {168 nmd_dump_channel( &channel, stream_out );169 }170 }171 172 static void nmd_dump_node( const mesh_node_data* node, stream& stream_out )173 {174 uint32 chan_size = 0;175 uint32 chan_count = ( node->data ? node->data->size() : 0 );176 for ( uint32 c = 0; c < chan_count; ++c )177 {178 chan_size += sizeof( nmd_channel_header );179 chan_size += node->data->get_channel( c )->raw_size();180 }181 182 nmd_element_header eheader;183 eheader.type = nmd_type::NODE;184 eheader.children = static_cast<uint16>( chan_count );185 eheader.size = chan_size;186 eheader.name = node->data->get_name();187 eheader.parent_id = node->data->get_parent_id();188 eheader.transform = node->data->get_transform();189 eheader.attributes = 0;190 stream_out.write( &eheader, sizeof( eheader ), 1 );191 if ( chan_count > 0 ) nmd_dump_channel_set( node->data, stream_out );192 }193 153 194 154 void nv::nmd_dump_header( stream& stream_out, uint32 elements, uint64 name ) … … 203 163 } 204 164 205 void nv::nmd_dump_ mesh( stream& stream_out, const data_channel_set& mesh)165 void nv::nmd_dump_element( stream& stream_out, const data_channel_set& data, nmd_type type ) 206 166 { 207 167 uint32 size = 0; 208 for ( auto& chan : mesh)168 for ( auto& chan : data ) 209 169 { 210 170 size += sizeof( nmd_channel_header ); … … 213 173 214 174 nmd_element_header eheader; 215 eheader.type = nmd_type::MESH;216 eheader.children = static_cast<uint16>( mesh.size() );175 eheader.type = type; 176 eheader.children = static_cast<uint16>( data.size() ); 217 177 eheader.size = size; 218 eheader.name = mesh.get_name();219 eheader.transform = mesh.get_transform();220 eheader.parent_id = mesh.get_parent_id();178 eheader.name = data.get_name(); 179 eheader.transform = data.get_transform(); 180 eheader.parent_id = data.get_parent_id(); 221 181 eheader.attributes = 0; 222 182 stream_out.write( &eheader, sizeof( eheader ), 1 ); 223 nmd_dump_channel_set( &mesh, stream_out ); 183 for ( auto& channel : data ) 184 { 185 nmd_channel_header cheader; 186 cheader.format = channel.descriptor(); 187 cheader.count = channel.size(); 188 stream_out.write( &cheader, sizeof( cheader ), 1 ); 189 stream_out.write( channel.raw_data(), channel.element_size(), channel.size() ); 190 } 224 191 } 225 192 … … 227 194 { 228 195 uint32 total = sizeof( nmd_animation_header ); 229 for ( uint32 i = 0; i < nodes.get_count(); ++i ) 230 { 231 const mesh_node_data* node = nodes.get_node( i ); 196 for ( auto node : nodes ) 197 { 232 198 total += sizeof( nmd_element_header ); 233 if ( node->data ) 234 for ( uint32 c = 0; c < node->data->size(); ++c ) 235 { 236 total += sizeof( nmd_channel_header ); 237 total += node->data->get_channel( c )->raw_size(); 238 } 199 for ( uint32 c = 0; c < node->size(); ++c ) 200 { 201 total += sizeof( nmd_channel_header ); 202 total += node->get_channel( c )->raw_size(); 203 } 239 204 } 240 205 … … 256 221 stream_out.write( &aheader, sizeof( aheader ), 1 ); 257 222 258 for ( uint32 i = 0; i < nodes.get_count(); ++i)259 { 260 nmd_dump_ node( nodes.get_node( i ), stream_out);223 for ( auto node : nodes ) 224 { 225 nmd_dump_element( stream_out, *node, nv::nmd_type::NODE ); 261 226 } 262 227 } … … 284 249 for ( uint32 i = 0; i < model->get_count(); ++i ) 285 250 { 286 nmd_dump_ mesh( stream_out, *model->get_mesh( i ));251 nmd_dump_element( stream_out, *model->get_mesh( i ), nv::nmd_type::MESH ); 287 252 } 288 253 -
trunk/src/formats/obj_loader.cc
r425 r427 363 363 for ( uint32 i = 0; i < size; ++i ) 364 364 { 365 data_channel_set_creator( m_meshes[i] ).move_to(meshes[i] );365 meshes[i] = move( *m_meshes[i] ); 366 366 delete m_meshes[i]; 367 367 }
Note: See TracChangeset
for help on using the changeset viewer.