Changeset 423
- Timestamp:
- 07/16/15 19:24:30 (10 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/formats/nmd_loader.hh
r420 r423 30 30 uint32 id; 31 31 uint32 version; 32 uint64 name; 32 33 uint32 elements; 33 34 uint32 attributes; … … 55 56 uint16 children; 56 57 uint32 size; 57 uint64 name _hash;58 uint64 name; 58 59 mat4 transform; 59 60 sint16 parent_id; … … 77 78 { 78 79 public: 79 nmd_loader() : m_node_data( nullptr ), m_node_array( nullptr ) {} //, m_strings( nullptr ) {}80 nmd_loader() : m_node_data( nullptr ), m_node_array( nullptr ), m_strings( nullptr ) {} 80 81 virtual bool load( stream& source ); 81 82 virtual data_channel_set* release_mesh_data( size_t index = 0 ); … … 97 98 mesh_nodes_data* m_node_data; 98 99 mesh_node_data* m_node_array; 99 //string_table* m_strings;100 string_table* m_strings; 100 101 // vector< uint16 > m_mesh_names; 101 102 // vector< uint16 > m_node_names; … … 104 105 105 106 // HACK : TEMPORARY - will go to it's own file, probably nmd_io 106 void nmd_dump( const nv::mesh_data_pack* model, stream& stream_out ); 107 void nmd_dump_header( stream& stream_out, uint32 elements, uint64 name ); 108 void nmd_dump_strings( stream& stream_out, const string_table& strings ); 109 void nmd_dump_mesh( stream& stream_out, const data_channel_set& mesh ); 110 void nmd_dump_nodes( stream& stream_out, const mesh_nodes_data& nodes ); 111 void nmd_dump( stream& stream_out, const mesh_data_pack* model, const string_table* strings = nullptr, uint64 name = 0 ); 107 112 108 113 } -
trunk/nv/gfx/animation.hh
r419 r423 10 10 #include <nv/common.hh> 11 11 #include <nv/stl/vector.hh> 12 #include <nv/ interface/stream.hh>12 #include <nv/stl/stream.hh> 13 13 #include <nv/stl/math.hh> 14 14 #include <nv/interface/data_channel.hh> -
trunk/nv/gfx/skeletal_mesh.hh
r419 r423 38 38 { 39 39 public: 40 skeletal_animation_entry_cpu( const std::string& name, const mesh_nodes_data* a_animation, bool a_looping )40 skeletal_animation_entry_cpu( uint64 name, const mesh_nodes_data* a_animation, bool a_looping ) 41 41 : animation_entry( name, a_looping, a_animation->get_frame_rate(), 0.0f, a_animation->get_duration() ), m_node_data( a_animation ) 42 42 { 43 43 initialize(); 44 44 } 45 skeletal_animation_entry_cpu( const std::string&name, mesh_nodes_data* a_animation, float time_start, float time_end, bool a_looping )45 skeletal_animation_entry_cpu( uint64 name, mesh_nodes_data* a_animation, float time_start, float time_end, bool a_looping ) 46 46 : animation_entry( name, a_looping, a_animation->get_frame_rate(), time_start, time_end ), m_node_data( a_animation ) 47 47 { … … 75 75 { 76 76 public: 77 skeletal_animation_entry_gpu( const std::string&name, const mesh_nodes_data* anim, bool a_looping )77 skeletal_animation_entry_gpu( uint64 name, const mesh_nodes_data* anim, bool a_looping ) 78 78 : animation_entry( name, a_looping, anim->get_frame_rate(), 0.0f, anim->get_duration() ) 79 79 , m_node_data( anim ) … … 82 82 } 83 83 84 skeletal_animation_entry_gpu( const std::string&name, const mesh_nodes_data* anim, float time_start, float time_end, bool a_looping )84 skeletal_animation_entry_gpu( uint64 name, const mesh_nodes_data* anim, float time_start, float time_end, bool a_looping ) 85 85 : animation_entry( name, a_looping, anim->get_frame_rate(), time_start, time_end ) 86 86 , m_node_data( anim ) -
trunk/nv/interface/animated_mesh.hh
r395 r423 25 25 { 26 26 public: 27 animation_entry( const std::string&name, bool looping, uint32 frame_rate, float a_start, float a_end ) : m_name( name ), m_looping( looping ), m_frame_rate( frame_rate ),27 animation_entry( uint64 name, bool looping, uint32 frame_rate, float a_start, float a_end ) : m_name( name ), m_looping( looping ), m_frame_rate( frame_rate ), 28 28 m_start( a_start ), m_end( a_end ), m_duration( m_end - m_start ), m_material_idx(0) {} 29 const std::string&get_name() const { return m_name; }29 uint64 get_name() const { return m_name; } 30 30 uint32 get_frame_rate() const { return m_frame_rate; } 31 31 float get_duration() const { return m_duration; } … … 47 47 virtual ~animation_entry() {} 48 48 protected: 49 std::stringm_name;49 uint64 m_name; 50 50 bool m_looping; 51 51 uint32 m_frame_rate; -
trunk/nv/interface/mesh_data.hh
r421 r423 24 24 struct mesh_node_data 25 25 { 26 uint64 name _hash;26 uint64 name; 27 27 sint16 parent_id; 28 28 mat4 transform; … … 35 35 friend class mesh_nodes_creator; 36 36 public: 37 explicit mesh_nodes_data( const std::string&name, uint32 count, mesh_node_data* nodes )37 explicit mesh_nodes_data( uint64 name, uint32 count, mesh_node_data* nodes ) 38 38 : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(0), m_duration(0.0f), m_flat( false ) 39 39 { 40 40 } 41 41 42 explicit mesh_nodes_data( const std::string&name, uint32 count, mesh_node_data* nodes,42 explicit mesh_nodes_data( uint64 name, uint32 count, mesh_node_data* nodes, 43 43 uint16 a_fps, float a_frames, bool a_flat ) 44 44 : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat ) … … 58 58 for ( uint32 i = 0; i < m_count; ++i ) 59 59 { 60 if ( m_nodes[ i ].name _hash== h )60 if ( m_nodes[ i ].name == h ) 61 61 return &m_nodes[ i ]; 62 62 } … … 68 68 for ( uint32 i = 0; i < m_count; ++i ) 69 69 { 70 if ( m_nodes[ i ].name _hash== h )70 if ( m_nodes[ i ].name == h ) 71 71 return int( i ); 72 72 } … … 84 84 uint16 get_frame_rate() const { return m_frame_rate; } 85 85 float get_duration() const { return m_duration; } 86 void set_name( const std::string&name ) { m_name = name; }87 const std::string&get_name() const { return m_name; }86 void set_name( uint64 name ) { m_name = name; } 87 uint64 get_name() const { return m_name; } 88 88 89 89 ~mesh_nodes_data() … … 95 95 96 96 private: 97 std::stringm_name;97 uint64 m_name; 98 98 uint32 m_count; 99 99 mesh_node_data* m_nodes; … … 120 120 uint32 get_count() const { return m_count; } 121 121 const mesh_nodes_data* get_nodes() const { return m_nodes; } 122 uint32 get_node_count() const { return m_nodes ? m_nodes->get_count() : 0; } 122 123 ~mesh_data_pack() 123 124 { -
trunk/nv/interface/mesh_loader.hh
r416 r423 19 19 #include <nv/gfx/animation.hh> 20 20 #include <nv/interface/mesh_data.hh> 21 #include <nv/ interface/stream.hh>21 #include <nv/stl/stream.hh> 22 22 23 23 namespace nv -
trunk/src/formats/assimp_loader.cc
r420 r423 200 200 mat4 offset = assimp_mat4_cast( bone->mOffsetMatrix ); 201 201 // bones[m].name = bone->mName.data; 202 bones[m].name _hash= hash_string< uint64 >( bone->mName.data );202 bones[m].name = hash_string< uint64 >( bone->mName.data ); 203 203 bones[m].data = nullptr; 204 204 bones[m].parent_id = -1; … … 302 302 303 303 mesh_node_data& bone = bones[b]; 304 auto iname = names.find( bone.name _hash);304 auto iname = names.find( bone.name ); 305 305 if ( iname == names.end() ) 306 306 { … … 308 308 uint16 index = uint16( final_bones.size() ); 309 309 final_bones.push_back( bone ); 310 names[ bone.name _hash] = index;310 names[ bone.name] = index; 311 311 translate[b] = index; 312 312 } … … 336 336 mesh_node_data* bones = new mesh_node_data[ final_bones.size() ]; 337 337 raw_copy( final_bones.begin(), final_bones.end(), bones ); 338 return new mesh_nodes_data( "bones", final_bones.size(), bones ); 338 int name_; 339 return new mesh_nodes_data( /*"bones"*/0, final_bones.size(), bones ); 339 340 } 340 341 … … 357 358 load_node( index, data, root, 0, -1 ); 358 359 359 return new mesh_nodes_data( anim->mName.data, count, data, frame_rate, duration, flat ); 360 int name; 361 return new mesh_nodes_data( /*anim->mName.data*/0, count, data, frame_rate, duration, flat ); 360 362 } 361 363 … … 389 391 390 392 // a_data.name = name; 391 a_data.name _hash= hash_string< uint64 >( name.c_str() );393 a_data.name = hash_string< uint64 >( name.c_str() ); 392 394 a_data.parent_id = parent_id; 393 395 // This value is ignored by the create_transformed_keys, but needed by create_direct_keys! -
trunk/src/formats/md3_loader.cc
r420 r423 426 426 427 427 nodes[i].transform = mat4(); 428 nodes[i].name _hash= hash_string< uint64 >( name.data() );428 nodes[i].name = hash_string< uint64 >( name.data() ); 429 429 nodes[i].parent_id = -1; 430 430 nodes[i].data = data_channel_set_creator::create( 1 ); 431 431 load_tags( data_channel_set_creator( nodes[i].data ).add_channel<md3_key>( uint32( md3->header.num_frames ) ).channel(), name ); 432 432 } 433 return new mesh_nodes_data( "tags", node_count, nodes ); 433 int name_; 434 return new mesh_nodes_data( 0,/*"tags"*/ node_count, nodes ); 434 435 } 435 436 -
trunk/src/formats/md5_loader.cc
r421 r423 112 112 assert( m_nodes == nullptr ); 113 113 nodes = new mesh_node_data[ num_joints ]; 114 m_nodes = new mesh_nodes_data( "md5_bones", num_joints, nodes ); 114 int name_; //"md5_bones" 115 m_nodes = new mesh_nodes_data( 0, num_joints, nodes ); 115 116 discard( sstream, "{" ); 116 117 for ( size_t i = 0; i < m_nodes->get_count(); ++i ) … … 128 129 remove_quotes( name ); 129 130 // nodes[i].name = name; 130 nodes[i].name _hash= hash_string< uint64 >( name.c_str() );131 nodes[i].name = hash_string< uint64 >( name.c_str() ); 131 132 // nodes[i].target_id = -1; 132 133 nodes[i].parent_id = -1; … … 242 243 assert( nodes == nullptr ); 243 244 nodes = new mesh_node_data[ num_joints ]; 244 m_nodes = new mesh_nodes_data( "md5_animation", num_joints, nodes, static_cast< nv::uint16 >( frame_rate ), static_cast< float >( num_frames ), true ); 245 int name_; 246 m_nodes = new mesh_nodes_data( 0/*"md5_animation"*/, num_joints, nodes, static_cast< nv::uint16 >( frame_rate ), static_cast< float >( num_frames ), true ); 245 247 joint_infos.resize( num_joints ); 246 248 … … 252 254 remove_quotes( name ); 253 255 // nodes[i].name = name; 254 nodes[i].name _hash= hash_string< uint64 >( name.c_str() );256 nodes[i].name = hash_string< uint64 >( name.c_str() ); 255 257 nodes[i].transform = mat4(); 256 258 nodes[i].data = data_channel_set_creator::create( 1 ); -
trunk/src/formats/nmd_loader.cc
r421 r423 28 28 case nmd_type::MESH : load_mesh( source, element_header ); break; 29 29 case nmd_type::ANIMATION : load_animation( source, element_header ); break; 30 // case nmd_type::STRING_TABLE: load_strings( source ); break;30 case nmd_type::STRINGS : load_strings( source ); break; 31 31 default: NV_ASSERT( false, "UNKNOWN NMD ELEMENT!" ); break; 32 32 } … … 68 68 { 69 69 for ( auto mesh : m_meshes ) if ( mesh ) delete mesh; 70 //if ( m_strings ) delete m_strings;70 if ( m_strings ) delete m_strings; 71 71 if ( m_node_data ) delete m_node_data; 72 72 m_meshes.clear(); … … 76 76 m_node_data = nullptr; 77 77 m_node_array = nullptr; 78 //m_strings = nullptr;78 m_strings = nullptr; 79 79 } 80 80 … … 90 90 } 91 91 92 bool nv::nmd_loader::load_strings( stream& /*source*/ ) 93 { 94 // NV_ASSERT( m_strings == nullptr, "MULTIPLE STRING ENTRIES!" ); 95 // m_strings = new string_table( &source ); 92 bool nv::nmd_loader::load_strings( stream& source ) 93 { 94 NV_ASSERT( m_strings == nullptr, "MULTIPLE STRING ENTRIES!" ); 95 // TODO: load strings optionally 96 m_strings = new string_table( source ); 96 97 return true; 97 98 } … … 112 113 load_node( source, &m_node_array[i], element_header ); 113 114 } 114 m_node_data = new mesh_nodes_data( "animation", e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat );115 m_node_data = new mesh_nodes_data( e.name, e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat ); 115 116 return true; 116 117 } … … 118 119 bool nv::nmd_loader::load_node( stream& source, mesh_node_data* data, const nmd_element_header& e ) 119 120 { 120 data->name _hash = e.name_hash;121 data->name = e.name; 121 122 data->parent_id = e.parent_id; 122 123 data->transform = e.transform; … … 190 191 } 191 192 192 static void nmd_dump_mesh( const data_channel_set* mesh, stream& stream_out )193 {194 uint32 size = 0;195 for ( auto& chan : *mesh )196 {197 size += sizeof( nmd_channel_header );198 size += chan.raw_size();199 }200 201 nmd_element_header eheader;202 eheader.type = nmd_type::MESH;203 // eheader.name = 0;204 eheader.children = static_cast< uint16 >( mesh->size() );205 eheader.size = size;206 eheader.name_hash = 0;207 eheader.transform = mat4();208 eheader.parent_id = -1;209 eheader.attributes = 0;210 stream_out.write( &eheader, sizeof( eheader ), 1 );211 nmd_dump_channel_set( mesh, stream_out );212 }213 214 193 static void nmd_dump_node( const mesh_node_data* node, stream& stream_out ) 215 194 { … … 227 206 eheader.children = static_cast<uint16>( chan_count ); 228 207 eheader.size = chan_size; 229 eheader.name _hash = node->name_hash;208 eheader.name = node->name; 230 209 eheader.parent_id = node->parent_id; 231 210 eheader.transform = node->transform; … … 235 214 } 236 215 237 static void nmd_dump_nodes_data( const mesh_nodes_data* nodes, stream& stream_out, string_table_creator* /*strings*/ ) 216 void nv::nmd_dump_header( stream& stream_out, uint32 elements, uint64 name ) 217 { 218 nmd_header header; 219 header.id = four_cc<'n', 'm', 'f', '1'>::value; 220 header.elements = elements; // +1 string array 221 header.name = name; 222 header.version = 1; 223 header.attributes = 0; 224 stream_out.write( &header, sizeof( header ), 1 ); 225 } 226 227 void nv::nmd_dump_mesh( stream& stream_out, const data_channel_set& mesh ) 228 { 229 uint32 size = 0; 230 for ( auto& chan : mesh ) 231 { 232 size += sizeof( nmd_channel_header ); 233 size += chan.raw_size(); 234 } 235 236 nmd_element_header eheader; 237 eheader.type = nmd_type::MESH; 238 eheader.children = static_cast<uint16>( mesh.size() ); 239 eheader.size = size; 240 int uncomment; 241 // eheader.name = mesh.get_name(); 242 // eheader.transform = mesh.get_transform(); 243 // eheader.parent_id = mesh.get_parent_id(); 244 eheader.name = 0; 245 eheader.transform = mat4(); 246 eheader.parent_id = -1; 247 eheader.attributes = 0; 248 stream_out.write( &eheader, sizeof( eheader ), 1 ); 249 nmd_dump_channel_set( &mesh, stream_out ); 250 } 251 252 void nv::nmd_dump_nodes( stream& stream_out, const mesh_nodes_data& nodes ) 238 253 { 239 254 uint32 total = sizeof( nmd_animation_header ); 240 for ( uint32 i = 0; i < nodes ->get_count(); ++i )241 { 242 const mesh_node_data* node = nodes ->get_node(i);255 for ( uint32 i = 0; i < nodes.get_count(); ++i ) 256 { 257 const mesh_node_data* node = nodes.get_node( i ); 243 258 total += sizeof( nmd_element_header ); 244 259 if ( node->data ) … … 246 261 { 247 262 total += sizeof( nmd_channel_header ); 248 total += node->data->get_channel( c)->raw_size();263 total += node->data->get_channel( c )->raw_size(); 249 264 } 250 265 } 251 266 252 267 nmd_element_header header; 253 // header.name = 0; 254 header.type = nmd_type::ANIMATION; 255 header.children = static_cast< uint16 >( nodes->get_count() ); 256 header.size = total; 257 header.name_hash = 0; 258 header.transform = mat4(); 259 header.parent_id = -1; 268 header.type = nmd_type::ANIMATION; 269 header.children = static_cast<uint16>( nodes.get_count() ); 270 header.size = total; 271 header.name = nodes.get_name(); 272 header.transform = mat4(); 273 header.parent_id = -1; 260 274 header.attributes = 0; 261 275 … … 263 277 264 278 nmd_animation_header aheader; 265 aheader.frame_rate = nodes->get_frame_rate();266 aheader.duration = nodes->get_duration();267 aheader.flat = nodes->is_flat();279 aheader.frame_rate = nodes.get_frame_rate(); 280 aheader.duration = nodes.get_duration(); 281 aheader.flat = nodes.is_flat(); 268 282 stream_out.write( &aheader, sizeof( aheader ), 1 ); 269 283 270 for ( uint32 i = 0; i < nodes->get_count(); ++i ) 271 { 272 nmd_dump_node( nodes->get_node( i ), stream_out ); 273 } 274 } 275 276 void nv::nmd_dump( const mesh_data_pack* model, stream& stream_out ) 277 { 278 string_table_creator strings; 279 { 280 nmd_header header; 281 header.id = four_cc<'n','m','f','1'>::value; 282 header.elements = 0; // +1 string array 283 header.elements += model->get_count(); 284 if ( model->get_nodes() && model->get_nodes()->get_count() > 0 ) 285 header.elements += 1;// +1 bone array 286 header.version = 1; 287 header.attributes = 0; 288 stream_out.write( &header, sizeof( header ), 1 ); 289 } 284 for ( uint32 i = 0; i < nodes.get_count(); ++i ) 285 { 286 nmd_dump_node( nodes.get_node( i ), stream_out ); 287 } 288 } 289 290 void nv::nmd_dump_strings( stream& stream_out, const string_table& strings ) 291 { 292 nmd_element_header sheader; 293 sheader.type = nv::nmd_type::STRINGS; 294 sheader.children = 0; 295 sheader.size = strings.dump_size(); 296 sheader.name = 0; 297 sheader.parent_id = -1; 298 sheader.attributes = 0; 299 stream_out.write( &sheader, sizeof( sheader ), 1 ); 300 strings.dump( stream_out ); 301 } 302 303 void nv::nmd_dump( stream& stream_out, const mesh_data_pack* model, const string_table* strings, uint64 name ) 304 { 305 uint32 elements = ( strings ? 1 : 0 ) // +1 string array 306 + model->get_count() // meshes 307 + ( model->get_node_count() > 0 ? 1 : 0 ); // nodes 308 nmd_dump_header( stream_out, elements, name ); 290 309 291 310 for ( uint32 i = 0; i < model->get_count(); ++i ) 292 311 { 293 const data_channel_set* mesh = model->get_mesh(i); 294 nmd_dump_mesh( mesh, stream_out ); 295 } 296 297 if ( model->get_nodes() && model->get_nodes()->get_count() > 0 ) 298 { 299 nmd_dump_nodes_data( model->get_nodes(), stream_out, &strings ); 300 } 301 302 // nmd_element_header sheader; 303 // sheader.type = nv::nmd_type::STRING_TABLE; 304 // sheader.name = 0; 305 // sheader.size = strings.dump_size(); 306 // sheader.children = 0; 307 // sheader.attributes = 0; 308 // stream_out.write( &sheader, sizeof( sheader ), 1 ); 309 // strings.dump( &stream_out ); 310 } 312 nmd_dump_mesh( stream_out, *model->get_mesh( i ) ); 313 } 314 315 if ( model->get_node_count() > 0 ) 316 { 317 nmd_dump_nodes( stream_out, *model->get_nodes() ); 318 } 319 320 if ( strings ) 321 { 322 nmd_dump_strings( stream_out, *strings ); 323 } 324 } -
trunk/src/gfx/skeletal_mesh.cc
r420 r423 178 178 { 179 179 const mesh_node_data* bone = bones->get_node(bi); 180 bone_names[ bone->name _hash] = bi;180 bone_names[ bone->name ] = bi; 181 181 m_offsets[bi] = bone->transform; 182 182 } … … 187 187 sint16 bone_id = -1; 188 188 189 auto bi = bone_names.find( node->name _hash);189 auto bi = bone_names.find( node->name ); 190 190 if ( bi != bone_names.end() ) 191 191 {
Note: See TracChangeset
for help on using the changeset viewer.