Ignore:
Timestamp:
07/23/14 15:24:03 (11 years ago)
Author:
epyon
Message:
  • mesh_data_pack's in every format
  • md5_mesh_data removed, uses standard mesh_data
  • BONE_ARRAY in NMD is now a simple set of animation nodes
  • bone and animation node concepts merged
  • several minor changes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/formats/assimp_loader.cc

    r285 r287  
    7979{
    8080        if ( index >= m_mesh_count ) return nullptr;
    81         mesh_data* result = new mesh_data();
     81        mesh_data* result = new mesh_data;
     82        load_mesh_data( result, index );
     83        return result;
     84}
     85void nv::assimp_loader::load_mesh_data( mesh_data* data, size_t index )
     86{
    8287        const aiScene* scene = (const aiScene*)m_scene;
    8388        const aiMesh*  mesh  = scene->mMeshes[ index ];
     89        data->set_name( mesh->mName.data );
    8490
    8591        vec3 vertex_offset     = glm::vec3();
     
    94100                channel = mesh_raw_channel::create< assimp_plain_vtx >( mesh->mNumVertices );
    95101
    96         result->add_channel( channel );
     102        data->add_channel( channel );
    97103        for (unsigned int i=0; i<mesh->mNumVertices; i++)
    98104        {
     
    139145
    140146        mesh_raw_channel* ichannel = mesh_raw_channel::create_index( USHORT, mesh->mNumFaces * 3 );
    141         result->add_channel( ichannel );
     147        data->add_channel( ichannel );
    142148        uint16* indices = (uint16*)ichannel->data;
    143149        for (unsigned int i=0; i<mesh->mNumFaces; i++)
     
    149155                }
    150156        }
    151 
    152         return result;
    153157}
    154158
     
    322326        const aiAnimation* anim = scene->mAnimations[0]; // if implemented, change in load_node also
    323327
    324         result->fps            = (float)anim->mTicksPerSecond;
     328        result->frame_rate     = (uint16)anim->mTicksPerSecond;
    325329        result->duration       = (float)anim->mDuration;
    326         result->pretransformed = pre_transform;
     330        result->flat           = pre_transform;
     331        result->max_frames     = 0;
    327332
    328333        load_node( result, root, 0, -1 );
     334
     335        // DAE pre_transform hack
     336        if ( result->flat && result->frame_rate == 1 )
     337        {
     338                result->frame_rate = 32;
     339                result->duration   = (float)result->max_frames;
     340        }
     341
    329342        return result;
    330343}
     
    371384        if (anode)
    372385        {
    373                 if ( data->pretransformed )
     386                if ( data->flat )
    374387                {
    375388                        create_transformed_keys( &a_data, anode, parent_id >= 0 ? &(data->nodes[ parent_id ]) : nullptr );
     
    379392                        create_direct_keys( &a_data, anode );
    380393                }
     394                data->max_frames = glm::max<uint32>( a_data.data->get_channel(0)->count, data->max_frames );
    381395        }
    382396
     
    386400                next = load_node( data, node->mChildren[i], next, this_id );
    387401        }
     402
    388403        return next;
    389404}
     
    432447        key_raw_channel* raw_pchannel = key_raw_channel::create<assimp_key_p>( node->mNumPositionKeys );
    433448        key_raw_channel* raw_rchannel = key_raw_channel::create<assimp_key_r>( node->mNumRotationKeys );
    434         key_raw_channel* raw_schannel = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys );
     449        //key_raw_channel* raw_schannel = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys );
    435450        data->data->add_channel( raw_pchannel );
    436451        data->data->add_channel( raw_rchannel );
    437         data->data->add_channel( raw_schannel );
     452        //data->data->add_channel( raw_schannel );
    438453        assimp_key_p* pchannel = ((assimp_key_p*)(raw_pchannel->data));
    439454        assimp_key_r* rchannel = ((assimp_key_r*)(raw_rchannel->data));
    440         assimp_key_s* schannel = ((assimp_key_s*)(raw_schannel->data));
     455        //assimp_key_s* schannel = ((assimp_key_s*)(raw_schannel->data));
    441456
    442457        for ( unsigned np = 0; np < node->mNumPositionKeys; ++np )
     
    450465                rchannel[np].rotation = glm::quat_cast( m_r33 * glm::mat3_cast( assimp_quat_cast(node->mRotationKeys[np].mValue ) ) * m_ri33 );
    451466        }
    452         if ( node->mNumScalingKeys > 0 )
    453         {
    454                 nv::vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue );
    455                 float scale_value   = glm::length( glm::abs( scale_vec0 - nv::vec3(1,1,1) ) );
    456                 if ( node->mNumScalingKeys > 1 || scale_value > 0.001 )
    457                 {
    458                         NV_LOG( nv::LOG_WARNING, "scale key significant!" );
    459                         for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
    460                         {
    461                                 schannel[np].time  = (float)node->mScalingKeys[np].mTime;
    462                                 schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue);
    463                         }
    464                 }
    465                 else
    466                 {
    467                         schannel[0].time  = (float)node->mScalingKeys[0].mTime;
    468                         schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue);
    469                 }
    470         }
    471 
    472 }
    473 
     467//      if ( node->mNumScalingKeys > 0 )
     468//      {
     469//              nv::vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue );
     470//              float scale_value   = glm::length( glm::abs( scale_vec0 - nv::vec3(1,1,1) ) );
     471//              if ( node->mNumScalingKeys > 1 || scale_value > 0.001 )
     472//              {
     473//                      NV_LOG( nv::LOG_WARNING, "scale key significant!" );
     474//                      for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
     475//                      {
     476//                              schannel[np].time  = (float)node->mScalingKeys[np].mTime;
     477//                              schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue);
     478//                      }
     479//              }
     480//              else
     481//              {
     482//                      schannel[0].time  = (float)node->mScalingKeys[0].mTime;
     483//                      schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue);
     484//              }
     485//      }
     486
     487}
     488
     489mesh_data_pack* nv::assimp_loader::release_mesh_data_pack()
     490{
     491        mesh_data* meshes = new mesh_data[ m_mesh_count ];
     492        for ( uint32 i = 0; i < m_mesh_count; ++i )
     493        {
     494                load_mesh_data(&meshes[i],i);
     495        }
     496        return new mesh_data_pack( m_mesh_count, meshes, release_mesh_nodes_data() );
     497}
     498
     499mesh_nodes_data* nv::assimp_loader::release_mesh_nodes_data()
     500{
     501        // TODO: implement
     502        return nullptr;
     503}
     504
Note: See TracChangeset for help on using the changeset viewer.