Changeset 457 for trunk


Ignore:
Timestamp:
08/13/15 20:51:12 (10 years ago)
Author:
epyon
Message:
  • mesh_creator - mirror and swap_culling, const on merge and is_same_format
  • mesh_data_pack - get by hash
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gfx/mesh_creator.hh

    r456 r457  
    2525                // assumes that position and normal is vec3, tangent is vec4
    2626                void rotate_quadrant( uint8 rotation );
     27                // assumes that position and normal is vec3, tangent is vec4
     28                void mirror( bool x, bool z );
     29                // assumes mesh is indexed
     30                void swap_culling();
    2731                void translate( vec3 offset );
    2832                void flip_normals();
    2933                void scale_texture( vec2 min, vec2 max );
    30                 bool is_same_format( data_channel_set* other );
    31                 void merge( data_channel_set* other );
     34                bool is_same_format( const data_channel_set* other );
     35                void merge( const data_channel_set* other );
    3236        private:
    3337                void initialize();
  • trunk/nv/interface/mesh_data.hh

    r431 r457  
    116116                        return &m_meshes[ index ];
    117117                }
     118                const data_channel_set* get_mesh_by_hash( shash64 h ) const
     119                {
     120                        for ( uint32 i = 0; i < m_count; ++i )
     121                        {
     122                                if ( m_meshes[i].get_name() == h )
     123                                        return &m_meshes[i];
     124                        }
     125                        return nullptr;
     126                }
    118127                uint32 get_count() const { return m_count; }
    119128                const mesh_nodes_data* get_nodes() const { return m_nodes; }
  • trunk/src/gfx/mesh_creator.cc

    r456 r457  
    345345                        tan.y,
    346346                        tan.x * r21 + tan.z * r22,
    347                         1.0f // make sure this is proper
     347                        tan.w // make sure this is proper
    348348                        );
    349349        }
    350350
    351351
     352}
     353
     354void nv::mesh_data_creator::mirror( bool x, bool z )
     355{
     356        if ( !x && !z ) return;
     357        NV_ASSERT( m_pos_type == FLOAT_VECTOR_3, "Unsupported position vector type!" );
     358        NV_ASSERT( m_nrm_type == FLOAT_VECTOR_3, "Unsupported normal vector type!" );
     359        NV_ASSERT( m_tan_type == FLOAT_VECTOR_4, "Unsupported tangent vector type!" );
     360
     361        float kx = x ? -1.0f : 1.0f;
     362        float kz = z ? -1.0f : 1.0f;
     363
     364        unsigned vtx_count = m_pos_channel->size();
     365        uint8* pos_data = raw_data_channel_access( m_pos_channel ).raw_data();
     366        uint8* nrm_data = raw_data_channel_access( m_nrm_channel ).raw_data();
     367        uint8* tan_data = raw_data_channel_access( m_tan_channel ).raw_data();
     368        for ( unsigned int i = 0; i < vtx_count; ++i )
     369        {
     370                vec3& pos = *reinterpret_cast<vec3*>( pos_data + m_pos_channel->element_size() * i + m_pos_offset );
     371                vec3& nrm = *reinterpret_cast<vec3*>( nrm_data + m_nrm_channel->element_size() * i + m_nrm_offset );
     372                vec4& tan = *reinterpret_cast<vec4*>( tan_data + m_tan_channel->element_size() * i + m_tan_offset );
     373
     374                pos = vec3(
     375                        pos.x * kx,
     376                        pos.y,
     377                        pos.z * kz
     378                        );
     379                nrm = vec3(
     380                        nrm.x * kx,
     381                        nrm.y,
     382                        nrm.z * kz
     383                        );
     384                tan = vec4(
     385                        tan.x * kx,
     386                        tan.y,
     387                        tan.z * kz,
     388                        tan.w * kx * kz// make sure this is proper
     389                        );
     390        }
     391
     392        if ( !( x && z ) )
     393                swap_culling();
     394}
     395
     396template < typename T >
     397static inline void swap_culling_impl( nv::raw_data_channel* index_channel )
     398{
     399        nv::raw_data_channel_access ichannel( index_channel );
     400        T* indices = reinterpret_cast<T*>( ichannel.raw_data() );
     401        nv::uint32 count = index_channel->size() / 3;
     402        for ( nv::uint32 i = 0; i < count; ++i )
     403        {
     404                nv::swap( indices[i * 3], indices[i * 3 + 1] );
     405        }
     406}
     407
     408void nv::mesh_data_creator::swap_culling()
     409{
     410        NV_ASSERT( m_idx_channel, "Swap culling unsupported on non-indexed meshes!" );
     411        NV_ASSERT( m_idx_channel->descriptor().size() == 1, "Malformed index channel!" );
     412        NV_ASSERT( m_idx_channel->size() % 3 == 0, "Malformed index channel - not per GL_TRIANGLE LAYOUT?" );
     413
     414        if ( m_idx_channel->size() == 0 ) return;
     415        switch ( m_idx_type )
     416        {
     417        case USHORT: swap_culling_impl< uint16 >( m_idx_channel ); break;
     418        case UINT: swap_culling_impl< uint16 >( m_idx_channel ); break;
     419        default: NV_ASSERT( false, "Swap culling supports only unsigned and unsigned short indices!" ); break;
     420        }
    352421}
    353422
     
    477546
    478547
    479 bool nv::mesh_data_creator::is_same_format( data_channel_set* other )
     548bool nv::mesh_data_creator::is_same_format( const data_channel_set* other )
    480549{
    481550        if ( m_data->size() != other->size() ) return false;
     
    488557}
    489558
    490 void nv::mesh_data_creator::merge( data_channel_set* other )
     559void nv::mesh_data_creator::merge( const data_channel_set* other )
    491560{
    492561        if ( !is_same_format( other ) ) return;
Note: See TracChangeset for help on using the changeset viewer.