Changeset 427
- Timestamp:
- 07/20/15 13:25:20 (10 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/formats/assimp_loader.hh
r425 r427 31 31 private: 32 32 mesh_nodes_data* release_merged_bones( data_channel_set* meshes ); 33 bool load_bones( size_t index, array_ref< mesh_node_data> bones );33 bool load_bones( size_t index, array_ref< data_channel_set* > bones ); 34 34 void load_mesh_data( data_channel_set* data, size_t index ); 35 sint16 load_node( uint32 anim_id, mesh_node_data*nodes, const void* vnode, sint16 this_id, sint16 parent_id );35 sint16 load_node( uint32 anim_id, array_ref< data_channel_set* > nodes, const void* vnode, sint16 this_id, sint16 parent_id ); 36 36 uint32 count_nodes( const void* node ) const; 37 void create_keys( mesh_node_data* data,const void* vnode );37 data_channel_set* create_keys( const void* vnode ); 38 38 39 39 const_string m_ext; -
trunk/nv/formats/md5_loader.hh
r425 r427 83 83 protected: 84 84 void reset(); 85 void build_frame_skeleton( mesh_node _data* nodes, uint32 index, const array_view<md5_joint_info>& joint_info, const array_view<transform>& base_frames, const array_view<float>& frame_data );86 bool prepare_mesh( mesh_node _data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info );85 void build_frame_skeleton( mesh_nodes_data* nodes, uint32 index, const array_view<md5_joint_info>& joint_info, const array_view<transform>& base_frames, const array_view<float>& frame_data ); 86 bool prepare_mesh( mesh_nodes_data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info ); 87 87 protected: 88 88 file_type m_type; -
trunk/nv/formats/nmd_loader.hh
r425 r427 78 78 { 79 79 public: 80 explicit nmd_loader( string_table* strings ) : mesh_loader( strings ), m_node_data( nullptr ) , m_node_array( nullptr ){}80 explicit nmd_loader( string_table* strings ) : mesh_loader( strings ), m_node_data( nullptr ) {} 81 81 virtual bool load( stream& source ); 82 82 virtual data_channel_set* release_mesh_data( size_t index = 0 ); … … 92 92 bool load_strings( stream& source ); 93 93 bool load_animation( stream& source, const nmd_element_header& e ); 94 bool load_node( stream& source, mesh_node_data* data, const nmd_element_header& e );95 94 bool load_channel( stream& source, data_channel_set* channel_set ); 96 95 bool load_channel_set( stream& source, data_channel_set* channel_set, const nmd_element_header& e ); 97 96 98 97 mesh_nodes_data* m_node_data; 99 mesh_node_data* m_node_array;100 // vector< uint16 > m_mesh_names;101 // vector< uint16 > m_node_names;102 98 vector< data_channel_set* > m_meshes; 103 99 }; … … 106 102 void nmd_dump_header( stream& stream_out, uint32 elements, uint64 name ); 107 103 void nmd_dump_strings( stream& stream_out, const string_table& strings ); 108 void nmd_dump_ mesh( stream& stream_out, const data_channel_set& mesh);104 void nmd_dump_element( stream& stream_out, const data_channel_set& data, nmd_type type ); 109 105 void nmd_dump_nodes( stream& stream_out, const mesh_nodes_data& nodes ); 110 106 void nmd_dump( stream& stream_out, const mesh_data_pack* model, const string_table* strings = nullptr, uint64 name = 0 ); -
trunk/nv/interface/data_channel_access.hh
r425 r427 141 141 const_iterator end() const { return m_set->end(); } 142 142 143 void move_to( data_channel_set& other )144 {145 int change_to_move;146 // other.m_name = m_name;147 for ( uint32 c = 0; c < m_set->m_size; ++c )148 {149 // if ( other.m_channels[c] ) delete other.m_channels[c];150 other.m_channels[c] = move( m_set->m_channels[c] );151 }152 other.m_name = m_set->m_name;153 other.m_parent_id = m_set->m_parent_id;154 other.m_transform = m_set->m_transform;155 other.m_size = m_set->m_size;156 m_set->m_size = 0;157 }158 159 143 void set_transform( const mat4& tr ) { m_set->m_transform = tr; } 160 144 const mat4& get_transform() const { return m_set->m_transform; } -
trunk/nv/interface/mesh_data.hh
r424 r427 22 22 using mesh_data = data_channel_set; 23 23 24 #pragma warning TODO_LIST! 25 // TODO : 26 // * get rid of mesh_node_data, optimize further 27 // * properly write and read strings from nmd's 28 // * mesh_loader string_table support 29 // * properly write strings in other loaders 30 // * attribute/property implementation and read/write on every nmd::command 31 struct mesh_node_data 32 { 33 data_channel_set* data; 34 }; 24 // TODO : attribute/property implementation and read/write on every nmd::command 35 25 36 26 class mesh_nodes_data … … 39 29 friend class mesh_nodes_creator; 40 30 public: 41 explicit mesh_nodes_data( uint64 name, uint32 count, mesh_node_data* nodes ) 42 : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(0), m_duration(0.0f), m_flat( false ) 31 typedef vector< data_channel_set* > storage; 32 typedef storage::const_iterator const_iterator; 33 34 explicit mesh_nodes_data( uint64 name ) 35 : m_name( name ), m_frame_rate(0), m_duration(0.0f), m_flat( false ) 43 36 { 44 37 } 45 38 46 explicit mesh_nodes_data( uint64 name, uint32 count, mesh_node_data* nodes, 47 uint16 a_fps, float a_frames, bool a_flat ) 48 : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat ) 39 explicit mesh_nodes_data( uint64 name, uint16 a_fps, float a_frames, bool a_flat ) 40 : m_name( name ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat ) 49 41 { 50 42 } 51 43 52 size_t get_count() const { return m_count; } 44 void push_back( data_channel_set* set ) 45 { 46 m_data.push_back( set ); 47 } 48 49 size_t get_count() const { return m_data.size(); } 53 50 54 51 bool is_animated( size_t i ) const 55 52 { 56 if ( i >= m_ count) return false;57 return ( m_ nodes[i].data && m_nodes[i].data->size() > 0 );53 if ( i >= m_data.size() ) return false; 54 return ( m_data[i]->size() > 0 ); 58 55 } 59 56 60 const mesh_node_data* get_node( size_t i ) const57 const data_channel_set* get_node( size_t i ) const 61 58 { 62 if ( i >= m_ count) return nullptr;63 return &m_nodes[i];59 if ( i >= m_data.size() ) return nullptr; 60 return m_data[i]; 64 61 } 65 62 66 const mesh_node_data* get_node_by_hash( uint64 h ) const63 const data_channel_set* get_node_by_hash( uint64 h ) const 67 64 { 68 for ( uint32 i = 0; i < m_count; ++i)65 for ( auto data : m_data ) 69 66 { 70 NV_ASSERT( m_nodes[i].data, "data!" ); 71 if ( m_nodes[ i ].data->get_name() == h ) 72 return &m_nodes[ i ]; 67 if ( data->get_name() == h ) return data; 73 68 } 74 69 return nullptr; … … 77 72 int get_node_index_by_hash( uint64 h ) const 78 73 { 79 for ( uint32 i = 0; i < m_ count; ++i )74 for ( uint32 i = 0; i < m_data.size(); ++i ) 80 75 { 81 NV_ASSERT( m_nodes[i].data, "data!" ); 82 if ( m_nodes[ i ].data->get_name() == h ) 76 if ( m_data[ i ]->get_name() == h ) 83 77 return int( i ); 84 78 } … … 86 80 } 87 81 88 // data_channel_set* rlease_node_data( size_t i ) 89 // { 90 // data_channel_set* result = m_nodes[i].data; 91 // m_nodes[i].data = nullptr; 92 // return result; 93 // } 82 const data_channel_set* operator[]( size_t i ) const 83 { 84 return m_data[i]; 85 } 86 87 const_iterator begin() const { return m_data.begin(); } 88 const_iterator end() const { return m_data.end(); } 94 89 95 90 bool is_flat() const { return m_flat; } … … 101 96 ~mesh_nodes_data() 102 97 { 103 if ( m_count > 0 ) 104 for ( uint32 i = 0; i < m_count; ++i ) delete m_nodes[i].data; 105 delete[] m_nodes; 98 for ( auto data : m_data ) delete data; 106 99 } 107 100 108 101 private: 102 vector< data_channel_set* > m_data; 109 103 uint64 m_name; 110 uint32 m_count;111 mesh_node_data* m_nodes;112 104 uint16 m_frame_rate; 113 105 float m_duration; -
trunk/nv/stl/memory.hh
r407 r427 137 137 138 138 constexpr size_type size() const { return m_size; } 139 constexpr bool empty() const { return m_size != 0; }139 constexpr bool empty() const { return m_size == 0; } 140 140 constexpr const value_type* data() const { return m_data; } 141 141 constexpr size_type raw_size() const { return sizeof( value_type ) * m_size; } -
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 } -
trunk/src/gfx/keyframed_mesh.cc
r424 r427 42 42 if ( m_tag_map && m_tag_map->get_count() > 0 ) 43 43 { 44 m_interpolation_key = m_tag_map->get_node( 0 )->data->get_interpolation_key();44 m_interpolation_key = (*m_tag_map)[ 0 ]->get_interpolation_key(); 45 45 } 46 46 } … … 55 55 if ( !m_tag_map ) return transform(); 56 56 NV_ASSERT( node_id < m_tag_map->get_count(), "TAGMAP FAIL" ); 57 const data_channel_set* data = m_tag_map->get_node( node_id )->data; 58 NV_ASSERT( data && data->size() > 0, "TAG FAIL" ); 59 raw_channel_interpolator interpolator( data, m_interpolation_key ); 57 NV_ASSERT( (*m_tag_map)[node_id]->size() > 0, "TAG FAIL" ); 58 raw_channel_interpolator interpolator( ( *m_tag_map )[node_id], m_interpolation_key ); 60 59 return interpolator.get< transform >( m_last_frame, m_next_frame, m_interpolation ); 61 60 } -
trunk/src/gfx/mesh_creator.cc
r424 r427 18 18 for ( size_t i = 0; i < m_data->get_count(); ++i ) 19 19 { 20 sint16 parent_id = m_data->m_nodes[i].data->get_parent_id();21 data_channel_set* keys = m_data->m_nodes[i].data;22 data_channel_set* pkeys = ( parent_id != -1 ? m_data->m_ nodes[parent_id].data: nullptr );20 data_channel_set* keys = m_data->m_data[i]; 21 sint16 parent_id = keys->get_parent_id(); 22 data_channel_set* pkeys = ( parent_id != -1 ? m_data->m_data[parent_id] : nullptr ); 23 23 size_t count = ( keys ? keys->get_channel_size(0) : 0 ); 24 24 size_t pcount = ( pkeys ? pkeys->get_channel_size(0) : 0 ); … … 51 51 for ( size_t i = 0; i < m_data->get_count(); ++i ) 52 52 { 53 data_channel_set* old_keys = m_data->m_ nodes[i].data;53 data_channel_set* old_keys = m_data->m_data[i]; 54 54 if ( old_keys && old_keys->size() > 0 ) 55 55 { … … 89 89 90 90 delete old_keys; 91 m_data->m_ nodes[i].data= new_keys;91 m_data->m_data[i] = new_keys; 92 92 } 93 93 } … … 102 102 for ( size_t i = 0; i < m_data->get_count(); ++i ) 103 103 { 104 mesh_node_data& node = m_data->m_nodes[i]; 105 node.data->m_transform = pre_transform * node.data->m_transform * post_transform; 106 if ( node.data ) 107 { 108 data_channel_set* kdata = node.data; 109 for ( size_t c = 0; c < kdata->size(); ++c ) 110 { 111 raw_data_channel_access channel( kdata, c ); 112 size_t key_size = channel.element_size(); 113 for ( size_t n = 0; n < channel.size(); ++n ) 114 { 115 transform_key_raw( kdata->get_channel( c )->descriptor(), channel.raw_data() + n * key_size, scale, r33, ri33 ); 116 } 104 data_channel_set* node = m_data->m_data[i]; 105 node->m_transform = pre_transform * node->m_transform * post_transform; 106 107 for ( size_t c = 0; c < node->size(); ++c ) 108 { 109 raw_data_channel_access channel( node, c ); 110 size_t key_size = channel.element_size(); 111 for ( size_t n = 0; n < channel.size(); ++n ) 112 { 113 transform_key_raw( node->get_channel( c )->descriptor(), channel.raw_data() + n * key_size, scale, r33, ri33 ); 117 114 } 118 115 } … … 458 455 if ( index < m_pack->get_count() ) 459 456 { 460 data_channel_set_creator( &m_pack->m_meshes[m_pack->m_count - 1] ).move_to( m_pack->m_meshes[index] ); 457 458 m_pack->m_meshes[index] = move( m_pack->m_meshes[m_pack->m_count - 1] ); 461 459 m_pack->m_count--; 462 460 } -
trunk/src/gfx/skeletal_mesh.cc
r424 r427 23 23 for ( uint32 i = 0; i < bones->get_count(); ++i ) 24 24 { 25 m_bone_offset[i] = transform( bones->get_node(i)->data->get_transform() );25 m_bone_offset[i] = transform( (*bones)[i]->get_transform() ); 26 26 } 27 27 … … 93 93 void nv::skeletal_animation_entry_cpu::initialize() 94 94 { 95 for ( size_t i = 0; i < m_node_data->get_count(); ++i)96 { 97 if ( m_node_data->is_animated( i ))98 { 99 m_interpolation_key = m_node_data->get_node( i )->data->get_interpolation_key();95 for ( auto bone : *m_node_data ) 96 { 97 if ( bone->size() > 0 ) 98 { 99 m_interpolation_key = bone->get_interpolation_key(); 100 100 break; 101 101 } … … 112 112 for ( size_t i = 0; i < m_node_data->get_count(); ++i ) 113 113 { 114 raw_channel_interpolator interpolator( m_node_data->get_node( i )->data, m_interpolation_key );114 raw_channel_interpolator interpolator( (*m_node_data)[i], m_interpolation_key ); 115 115 skeleton[i] = interpolator.get< transform >( frame_num ); 116 116 } … … 132 132 for ( uint32 n = 0; n < node_count; ++n ) 133 133 { 134 const mesh_node_data* node = m_node_data->get_node(n);135 if ( node-> data->get_parent_id() != -1 )136 { 137 m_children[ node-> data->get_parent_id()].push_back( n );134 const data_channel_set* node = (*m_node_data)[n]; 135 if ( node->get_parent_id() != -1 ) 136 { 137 m_children[ node->get_parent_id()].push_back( n ); 138 138 } 139 139 } … … 156 156 if ( m_bone_ids[n] >= 0 ) 157 157 { 158 const mesh_node_data* node = m_node_data->get_node(n);159 nv::mat4 node_mat( node-> data->get_transform() );160 161 if ( node-> data && node->data->size() > 0 )162 { 163 raw_channel_interpolator interpolator( node ->data, m_interpolation_key );158 const data_channel_set* node = m_node_data->get_node(n); 159 nv::mat4 node_mat( node->get_transform() ); 160 161 if ( node->size() > 0 ) 162 { 163 raw_channel_interpolator interpolator( node, m_interpolation_key ); 164 164 node_mat = interpolator.get< mat4 >( anim_time ); 165 165 } … … 177 177 for ( nv::uint16 bi = 0; bi < bones->get_count(); ++bi ) 178 178 { 179 const mesh_node_data* bone = bones->get_node(bi);180 bone_names[ bone-> data->get_name() ] = bi;181 m_offsets[bi] = bone-> data->get_transform();179 const data_channel_set* bone = bones->get_node( bi ); 180 bone_names[ bone->get_name() ] = bi; 181 m_offsets[bi] = bone->get_transform(); 182 182 } 183 183 184 184 for ( uint32 n = 0; n < m_node_data->get_count(); ++n ) 185 185 { 186 const mesh_node_data* node = m_node_data->get_node(n);186 const data_channel_set* node = m_node_data->get_node( n ); 187 187 sint16 bone_id = -1; 188 188 189 auto bi = bone_names.find( node-> data->get_name() );189 auto bi = bone_names.find( node->get_name() ); 190 190 if ( bi != bone_names.end() ) 191 191 { … … 194 194 m_bone_ids[n] = bone_id; 195 195 196 if ( m_interpolation_key.size() == 0 && node-> data->size() > 0 )197 m_interpolation_key = node-> data->get_interpolation_key();196 if ( m_interpolation_key.size() == 0 && node->size() > 0 ) 197 m_interpolation_key = node->get_interpolation_key(); 198 198 199 199 } … … 205 205 // TODO: fix transforms, which are now embedded, 206 206 // see note in assimp_loader.cc:load_node 207 const mesh_node_data* node = m_node_data->get_node( node_id );208 mat4 node_mat( node-> data->get_transform() );209 210 if ( node-> data && node->data->size() > 0 )211 { 212 raw_channel_interpolator interpolator( node ->data, m_interpolation_key );207 const data_channel_set* node = m_node_data->get_node( node_id ); 208 mat4 node_mat( node->get_transform() ); 209 210 if ( node->size() > 0 ) 211 { 212 raw_channel_interpolator interpolator( node, m_interpolation_key ); 213 213 node_mat = interpolator.get< mat4 >( time ); 214 214 } -
trunk/src/io/string_table.cc
r425 r427 66 66 m_data.resize( dsize + 2 + length + 1 ); 67 67 *reinterpret_cast<uint16*>( m_data.data() + dsize ) = length; 68 raw_copy( str, str + length + 1, m_data.data() + dsize + 2 ); 68 if ( length > 0 ) 69 raw_copy( str, str + length, m_data.data() + dsize + 2 ); 70 m_data[dsize + 2 + length] = 0; 69 71 m_map[h] = dsize; 70 72 return dsize;
Note: See TracChangeset
for help on using the changeset viewer.