Changeset 420 for trunk/src/formats
- Timestamp:
- 07/15/15 19:59:40 (10 years ago)
- Location:
- trunk/src/formats
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r419 r420 199 199 aiBone* bone = mesh->mBones[m]; 200 200 mat4 offset = assimp_mat4_cast( bone->mOffsetMatrix ); 201 bones[m].name = bone->mName.data; 201 // bones[m].name = bone->mName.data; 202 bones[m].name_hash = hash_string< uint64 >( bone->mName.data ); 202 203 bones[m].data = nullptr; 203 204 bones[m].parent_id = -1; 204 bones[m].target_id = -1;205 // bones[m].target_id = -1; 205 206 bones[m].transform = offset; 206 207 } … … 287 288 const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene ); 288 289 vector< mesh_node_data > final_bones; 289 unordered_map< std::string, uint16 > names;290 unordered_map< uint64, uint16 > names; 290 291 for ( unsigned int m = 0; m < m_mesh_count; ++m ) 291 292 { … … 301 302 302 303 mesh_node_data& bone = bones[b]; 303 auto iname = names.find( bone.name );304 auto iname = names.find( bone.name_hash ); 304 305 if ( iname == names.end() ) 305 306 { … … 307 308 uint16 index = uint16( final_bones.size() ); 308 309 final_bones.push_back( bone ); 309 names[ bone.name 310 names[ bone.name_hash] = index; 310 311 translate[b] = index; 311 312 } … … 387 388 mesh_node_data& a_data = nodes[ this_id ]; 388 389 389 a_data.name = name;390 a_data. target_id = -1;390 // a_data.name = name; 391 a_data.name_hash = hash_string< uint64 >( name.c_str() ); 391 392 a_data.parent_id = parent_id; 392 393 // This value is ignored by the create_transformed_keys, but needed by create_direct_keys! -
trunk/src/formats/md3_loader.cc
r419 r420 426 426 427 427 nodes[i].transform = mat4(); 428 nodes[i].name = name.to_string();428 nodes[i].name_hash = hash_string< uint64 >( name.data() ); 429 429 nodes[i].parent_id = -1; 430 nodes[i].target_id = -1;431 430 nodes[i].data = data_channel_set_creator::create( 1 ); 432 431 load_tags( data_channel_set_creator( nodes[i].data ).add_channel<md3_key>( uint32( md3->header.num_frames ) ).channel(), name ); -
trunk/src/formats/md5_loader.cc
r419 r420 116 116 for ( size_t i = 0; i < m_nodes->get_count(); ++i ) 117 117 { 118 sstream >> nodes[i].name >> nodes[i].parent_id; 118 std::string name; 119 sstream >> name >> nodes[i].parent_id; 119 120 vec3 pos; 120 121 quat orient; … … 125 126 sstream >> orient.x >> orient.y >> orient.z; 126 127 unit_quat_w( orient ); 127 remove_quotes( nodes[i].name ); 128 nodes[i].target_id = -1; 128 remove_quotes( name ); 129 // nodes[i].name = name; 130 nodes[i].name_hash = hash_string< uint64 >( name.c_str() ); 131 // nodes[i].target_id = -1; 129 132 nodes[i].parent_id = -1; 130 133 nodes[i].transform = transform( pos, orient ).inverse().extract(); … … 246 249 { 247 250 std::string name; 248 sstream >> n odes[i].name >> nodes[i].parent_id >> joint_infos[i].flags >> joint_infos[i].start_index;251 sstream >> name >> nodes[i].parent_id >> joint_infos[i].flags >> joint_infos[i].start_index; 249 252 remove_quotes( name ); 253 // nodes[i].name = name; 254 nodes[i].name_hash = hash_string< uint64 >( name.c_str() ); 250 255 nodes[i].transform = mat4(); 251 nodes[i].target_id = -1;252 256 nodes[i].data = data_channel_set_creator::create( 1 ); 253 257 data_channel_set_creator( nodes[i].data ).add_channel< md5_key_t >( num_frames ); -
trunk/src/formats/nmd_loader.cc
r419 r420 18 18 nmd_header root_header; 19 19 source.read( &root_header, sizeof( root_header ), 1 ); 20 skip_attributes( source, root_header.attributes ); 20 21 for ( uint32 i = 0; i < root_header.elements; ++i ) 21 22 { 22 23 nmd_element_header element_header; 23 24 source.read( &element_header, sizeof( element_header ), 1 ); 25 skip_attributes( source, element_header.attributes ); 24 26 switch ( element_header.type ) 25 27 { 26 28 case nmd_type::MESH : load_mesh( source, element_header ); break; 27 29 case nmd_type::ANIMATION : load_animation( source, element_header ); break; 28 case nmd_type::STRING_TABLE : load_strings( source ); break;30 // case nmd_type::STRING_TABLE : load_strings( source ); break; 29 31 default: NV_ASSERT( false, "UNKNOWN NMD ELEMENT!" ); break; 30 32 } … … 36 38 { 37 39 data_channel_set* mesh = data_channel_set_creator::create( e.children ); 38 data_channel_set_creator mcreator( mesh ); 39 for ( uint32 s = 0; s < e.children; ++s ) 40 { 41 nmd_element_header element_header; 42 source.read( &element_header, sizeof( element_header ), 1 ); 43 NV_ASSERT( element_header.type == nmd_type::STREAM, "STREAM expected!" ); 44 45 nmd_stream_header stream_header; 46 source.read( &stream_header, sizeof( stream_header ), 1 ); 47 raw_data_channel_access channel( mcreator.add_channel( stream_header.format, stream_header.count ) ); 48 source.read( channel.raw_data(), channel.element_size(), channel.size() ); 49 } 50 m_mesh_names.push_back( e.name ); 40 load_channel_set( source, mesh, e ); 41 // m_mesh_names.push_back( e.name ); 51 42 m_meshes.push_back( mesh ); 52 43 return true; … … 56 47 { 57 48 data_channel_set* result = m_meshes[ index ]; 58 if ( m_strings ) data_channel_set_creator( result ).set_name( m_strings->get( m_mesh_names[ index ] ) );49 // if ( m_strings ) data_channel_set_creator( result ).set_name( m_strings->get( m_mesh_names[ index ] ) ); 59 50 m_meshes[ index ] = nullptr; 60 51 return result; … … 77 68 { 78 69 for ( auto mesh : m_meshes ) if ( mesh ) delete mesh; 79 if ( m_strings ) delete m_strings;70 // if ( m_strings ) delete m_strings; 80 71 if ( m_node_data ) delete m_node_data; 81 72 m_meshes.clear(); 82 m_mesh_names.clear();83 m_node_names.clear();73 // m_mesh_names.clear(); 74 // m_node_names.clear(); 84 75 85 76 m_node_data = nullptr; 86 77 m_node_array = nullptr; 87 m_strings = nullptr; 78 // m_strings = nullptr; 79 } 80 81 void nv::nmd_loader::skip_attributes( stream& source, uint32 count ) 82 { 83 if ( count == 0 ) return; 84 source.seek( count * sizeof( nmd_attribute ), origin::CUR ); 88 85 } 89 86 … … 93 90 } 94 91 95 bool nv::nmd_loader::load_strings( stream& source)96 { 97 NV_ASSERT( m_strings == nullptr, "MULTIPLE STRING ENTRIES!" );98 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 // m_strings = new string_table( &source ); 99 96 return true; 100 97 } … … 110 107 nmd_element_header element_header; 111 108 source.read( &element_header, sizeof( element_header ), 1 ); 109 skip_attributes( source, element_header.attributes ); 112 110 NV_ASSERT( element_header.type == nmd_type::NODE, "NODE expected!" ); 113 m_node_names.push_back( element_header.name ); 114 uint16 ch_count = element_header.children; 115 116 nmd_node_header node_header; 117 source.read( &node_header, sizeof( node_header ), 1 ); 118 m_node_array[i].parent_id = node_header.parent_id; 119 m_node_array[i].transform = node_header.transform; 120 m_node_array[i].data = nullptr; 121 if ( ch_count > 0 ) 122 { 123 data_channel_set* kdata = data_channel_set_creator::create( ch_count ); 124 data_channel_set_creator kaccess( kdata ); 125 m_node_array[i].data = kdata; 126 for ( uint32 c = 0; c < ch_count; ++c ) 127 { 128 source.read( &element_header, sizeof( element_header ), 1 ); 129 NV_ASSERT( element_header.type == nmd_type::KEY_CHANNEL, "CHANNEL expected!" ); 130 nv::nmd_stream_header cheader; 131 source.read( &cheader, sizeof( cheader ), 1 ); 132 raw_data_channel_access channel( kaccess.add_channel( cheader.format, cheader.count ) ); 133 source.read( channel.raw_data(), channel.element_size(), channel.size() ); 134 } 135 } 111 // m_node_names.push_back( element_header.name ); 112 load_node( source, &m_node_array[i], element_header ); 136 113 } 137 114 m_node_data = new mesh_nodes_data( "animation", e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat ); … … 139 116 } 140 117 118 bool nv::nmd_loader::load_node( stream& source, mesh_node_data* data, const nmd_element_header& e ) 119 { 120 data->name_hash = e.name_hash; 121 data->parent_id = e.parent_id; 122 data->transform = e.transform; 123 data->data = nullptr; 124 if ( e.children > 0 ) 125 { 126 data->data = data_channel_set_creator::create( e.children ); 127 load_channel_set( source, data->data, e ); 128 } 129 return true; 130 } 131 132 bool nv::nmd_loader::load_channel( stream& source, data_channel_set* channel_set ) 133 { 134 data_channel_set_creator kaccess( channel_set ); 135 nmd_channel_header cheader; 136 source.read( &cheader, sizeof( cheader ), 1 ); 137 raw_data_channel_access channel( kaccess.add_channel( cheader.format, cheader.count ) ); 138 source.read( channel.raw_data(), channel.element_size(), channel.size() ); 139 return true; 140 } 141 142 bool nv::nmd_loader::load_channel_set( stream& source, data_channel_set* channel_set, const nmd_element_header& e ) 143 { 144 data_channel_set_creator kaccess( channel_set ); 145 for ( uint32 c = 0; c < e.children; ++c ) 146 { 147 load_channel( source, channel_set ); 148 } 149 return true; 150 } 151 141 152 mesh_nodes_data* nv::nmd_loader::release_mesh_nodes_data( size_t ) 142 153 { 143 154 if ( m_node_data ) 144 155 { 145 if ( m_strings ) 146 { 147 for ( uint32 i = 0; i < m_node_data->get_count(); ++i ) 148 { 149 m_node_array[i].name = m_strings->get( m_node_names[i] ); 150 } 151 } 156 // if ( m_strings ) 157 // { 158 // for ( uint32 i = 0; i < m_node_data->get_count(); ++i ) 159 // { 160 // m_node_array[i].name = m_strings->get( m_node_names[i] ); 161 // m_node_array[i].name_hash = hash_string< uint64 >( m_strings->get( m_node_names[i] ) ); 162 // } 163 // } 152 164 mesh_nodes_data* result = m_node_data; 153 165 m_node_data = nullptr; … … 161 173 // nmd format dump 162 174 // HACK : TEMPORARY - will go to it's own file, probably nmd_io 175 static void nmd_dump_channel( const raw_data_channel* channel , stream& stream_out ) 176 { 177 nmd_channel_header sheader; 178 sheader.format = channel->descriptor(); 179 sheader.count = channel->size(); 180 stream_out.write( &sheader, sizeof( sheader ), 1 ); 181 stream_out.write( channel->raw_data(), channel->element_size(), channel->size() ); 182 } 183 184 static void nmd_dump_channel_set( const data_channel_set* channel_set, stream& stream_out ) 185 { 186 for ( auto& channel : *channel_set ) 187 { 188 nmd_dump_channel( &channel, stream_out ); 189 } 190 } 191 163 192 static void nmd_dump_mesh( const data_channel_set* mesh, stream& stream_out ) 164 193 { 165 uint32 size = sizeof( nmd_element_header );194 uint32 size = 0; 166 195 for ( auto& chan : *mesh ) 167 196 { 168 size += sizeof( nmd_ element_header ) + sizeof( nmd_stream_header );197 size += sizeof( nmd_channel_header ); 169 198 size += chan.raw_size(); 170 199 } 171 200 172 201 nmd_element_header eheader; 173 eheader.type = nmd_type::MESH; 174 eheader.name = 0; 175 eheader.children = static_cast< uint16 >( mesh->size() ); 176 eheader.size = size; 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; 177 210 stream_out.write( &eheader, sizeof( eheader ), 1 ); 178 179 for ( auto& chan : *mesh ) 180 { 181 nmd_element_header cheader; 182 eheader.name = 0; 183 cheader.type = nmd_type::STREAM; 184 cheader.children = 0; 185 cheader.size = chan.raw_size() + sizeof( nmd_stream_header ); 186 stream_out.write( &cheader, sizeof( cheader ), 1 ); 187 188 nmd_stream_header sheader; 189 sheader.format = chan.descriptor(); 190 sheader.count = chan.size(); 191 stream_out.write( &sheader, sizeof( sheader ), 1 ); 192 stream_out.write( chan.raw_data(), chan.element_size(), chan.size() ); 193 } 194 } 195 196 static void nmd_dump_nodes_data( const mesh_nodes_data* nodes, stream& stream_out, string_table_creator* strings ) 211 nmd_dump_channel_set( mesh, stream_out ); 212 } 213 214 static void nmd_dump_node( const mesh_node_data* node, stream& stream_out ) 215 { 216 uint32 chan_size = 0; 217 uint32 chan_count = ( node->data ? node->data->size() : 0 ); 218 for ( uint32 c = 0; c < chan_count; ++c ) 219 { 220 chan_size += sizeof( nmd_channel_header ); 221 chan_size += node->data->get_channel( c )->raw_size(); 222 } 223 224 nmd_element_header eheader; 225 eheader.type = nmd_type::NODE; 226 // eheader.name = strings->insert( node->name ); 227 eheader.children = static_cast<uint16>( chan_count ); 228 eheader.size = chan_size; 229 eheader.name_hash = node->name_hash; 230 eheader.parent_id = node->parent_id; 231 eheader.transform = node->transform; 232 eheader.attributes = 0; 233 stream_out.write( &eheader, sizeof( eheader ), 1 ); 234 if ( node->data ) nmd_dump_channel_set( node->data, stream_out ); 235 } 236 237 static void nmd_dump_nodes_data( const mesh_nodes_data* nodes, stream& stream_out, string_table_creator* /*strings*/ ) 197 238 { 198 239 uint32 total = sizeof( nmd_animation_header ); … … 200 241 { 201 242 const mesh_node_data* node = nodes->get_node(i); 202 total += sizeof( nmd_element_header ) + sizeof( nmd_node_header );243 total += sizeof( nmd_element_header ); 203 244 if ( node->data ) 204 245 for ( uint32 c = 0; c < node->data->size(); ++c ) 205 246 { 206 total += sizeof( nmd_ element_header ) + sizeof( nmd_stream_header );247 total += sizeof( nmd_channel_header ); 207 248 total += node->data->get_channel(c)->raw_size(); 208 249 } … … 210 251 211 252 nmd_element_header header; 212 header.name = 0; 213 header.type = nmd_type::ANIMATION; 214 header.children = static_cast< uint16 >( nodes->get_count() ); 215 header.size = total; 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; 260 header.attributes = 0; 261 216 262 stream_out.write( &header, sizeof( header ), 1 ); 217 263 … … 224 270 for ( uint32 i = 0; i < nodes->get_count(); ++i ) 225 271 { 226 const mesh_node_data* node = nodes->get_node(i); 227 uint32 chan_size = 0; 228 uint32 chan_count = ( node->data ? node->data->size() : 0 ); 229 for ( uint32 c = 0; c < chan_count; ++c ) 230 { 231 chan_size += sizeof( nmd_element_header ) + sizeof( nv::nmd_stream_header ); 232 chan_size += node->data->get_channel(c)->raw_size(); 233 } 234 235 nmd_element_header eheader; 236 eheader.type = nmd_type::NODE; 237 eheader.name = strings->insert( node->name ); 238 eheader.children = static_cast< uint16 >( chan_count ); 239 eheader.size = sizeof( nmd_node_header ) + chan_size; 240 stream_out.write( &eheader, sizeof( eheader ), 1 ); 241 242 nmd_node_header nheader; 243 nheader.parent_id = node->parent_id; 244 nheader.transform = node->transform; 245 stream_out.write( &nheader, sizeof( nheader ), 1 ); 246 247 for ( uint32 c = 0; c < chan_count; ++c ) 248 { 249 const raw_data_channel* channel = node->data->get_channel(c); 250 251 eheader.type = nmd_type::KEY_CHANNEL; 252 eheader.children = 0; 253 eheader.size = sizeof( nmd_stream_header ) + channel->raw_size(); 254 stream_out.write( &eheader, sizeof( eheader ), 1 ); 255 256 nmd_stream_header cheader; 257 cheader.format = channel->descriptor(); 258 cheader.count = channel->size(); 259 stream_out.write( &cheader, sizeof( cheader ), 1 ); 260 stream_out.write( channel->raw_data(), channel->element_size(), channel->size() ); 261 } 272 nmd_dump_node( nodes->get_node( i ), stream_out ); 262 273 } 263 274 } … … 269 280 nmd_header header; 270 281 header.id = four_cc<'n','m','f','1'>::value; 271 header.elements = 1; // +1 string array282 header.elements = 0; // +1 string array 272 283 header.elements += model->get_count(); 273 284 if ( model->get_nodes() && model->get_nodes()->get_count() > 0 ) 274 285 header.elements += 1;// +1 bone array 275 286 header.version = 1; 287 header.attributes = 0; 276 288 stream_out.write( &header, sizeof( header ), 1 ); 277 289 } … … 288 300 } 289 301 290 nmd_element_header sheader; 291 sheader.type = nv::nmd_type::STRING_TABLE; 292 sheader.name = 0; 293 sheader.size = strings.dump_size(); 294 sheader.children = 0; 295 stream_out.write( &sheader, sizeof( sheader ), 1 ); 296 strings.dump( &stream_out ); 297 } 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 }
Note: See TracChangeset
for help on using the changeset viewer.