/// Called to update the controls of the dialog
    virtual void    Update( TimeValue t, Interval &valid, IParamMap2 *map )
    {
        ICustButton     *bmSelectBtn;
        IParamBlock2    *pblock;
        int             i;
        long            buttons[ 6 ] = { IDC_FRONT_NAME, IDC_BACK_NAME, IDC_LEFT_NAME, IDC_RIGHT_NAME, IDC_TOP_NAME, IDC_BOTTOM_NAME };
        BitmapInfo      bi;


        ParamMap2UserDlgProc::Update( t, valid, map );

        pblock = map->GetParamBlock();
        for( i = plStaticEnvLayer::kBmpFrontBitmap; i <= plStaticEnvLayer::kBmpBottomBitmap; i++ )
        {
            bmSelectBtn = GetICustButton( GetDlgItem( map->GetHWnd(), buttons[ i ] ) );
            PBBitmap *pbbm = pblock->GetBitmap( i, t );
            if( pbbm )
                bmSelectBtn->SetText( (TCHAR *)pbbm->bi.Filename() );
            else
                bmSelectBtn->SetText( _T( "None" ) );
            ReleaseICustButton( bmSelectBtn );
        }

        plStaticEnvLayer *layer = (plStaticEnvLayer *)map->GetParamBlock()->GetOwner();
        bi.SetName( layer->GetBaseFilename( t ) );
        SetDlgItemText( map->GetHWnd(), IDC_BASE_FILENAME, bi.Filename() );
        map->Enable( plStaticEnvLayer::kBmpGenerateFaces, ( bi.Name() == NULL || bi.Name()[ 0 ] == 0 ) ? FALSE : TRUE );

        bmSelectBtn = GetICustButton( GetDlgItem( map->GetHWnd(), IDC_GENERATE_FACES ) );
        bmSelectBtn->SetText( _T( "Generate From Node" ) );
        ReleaseICustButton( bmSelectBtn );

        i = pblock->GetInt( plStaticEnvLayer::kBmpTextureSize, t );
        pblock->SetValue( plStaticEnvLayer::kBmpLastTextureSize, t, i );
    }
// Called at the start of each frame
void VRayCamera::frameBegin(VR::VRayRenderer *vray) {
  const VR::VRayFrameData &fdata = vray->getFrameData();

  TimeValue t = fdata.t;

  stereo_camera=pblock->GetInt(pb_camera, t);

  // angles in paramblock are automatically converted to radians, so no need to convert here
  fov_vert_angle = pblock->GetFloat(pb_fov_vert_angle, t);
  zenith_fov = pblock->GetInt(pb_zenithfov, t);
  fov_horiz_angle = pblock->GetFloat(pb_fov_horiz_angle, t);
  parallax_distance = pblock->GetFloat(pb_parallax_distance, t);
  separation = pblock->GetFloat(pb_separation, t);
  neck_offset = pblock->GetFloat(pb_neck_offset, t);
  zenith_mode = pblock->GetInt(pb_zenith_mode, t);

  separation_map = pblock->GetBitmap(pb_separation_map, t);
  if (separation_map != NULL) {
    separation_map->Load();
    if (separation_map->bm != NULL) {
      separation_map->bm->SetFilter(BMM_FILTER_PYRAMID);
    }
  }
 
  flip_x = pblock->GetInt(pb_flip_x, t);
  flip_y = pblock->GetInt(pb_flip_y, t);

  horiz_neck = pblock->GetInt(pb_horiz_neck, t);;
  poles_corr = pblock->GetInt(pb_poles_corr, t);;
  poles_corr_start = pblock->GetFloat(pb_poles_corr_start, t);
  poles_corr_end = pblock->GetFloat(pb_poles_corr_end, t);
  parallel_cams = pblock->GetInt(pb_parall_cams, t);

  // check poles corr angles
  if (poles_corr_end < poles_corr_start)
    poles_corr_end = poles_corr_start;

  //zenith_fov = (fov_vert_angle < 0.0f) ? TRUE : FALSE;
  //fov_vert_angle = abs(fov_vert_angle);

  //fov=pblock->GetFloat(pb_fov, fdata.t);
  fov = 1.0; // fov_vert_angle / 2.0f;  // [rz] testing only. Need better approximation formula.
  targetDist = GetTDist((TimeValue) fdata.t);
  aperture = 0.0f;

  camera.SetPos(fdata.camToWorld.offs, -fdata.camToWorld.m[2], fdata.camToWorld.m[1], fdata.camToWorld.m[0]);
  camera.Init(fdata.imgWidth, fdata.imgHeight, fov, 1.0f, aperture, targetDist);

  this->vray = vray;
}
Beispiel #3
0
plLayerInterface    *plLayerConverter::IConvertStaticEnvLayer( plPlasmaMAXLayer *layer, 
                                                                plMaxNode *maxNode, uint32_t blendFlags, 
                                                                bool preserveUVOffset, bool upperLayer )
{
    hsGuardBegin( "plLayerConverter::IConvertStaticEnvLayer" );

    IParamBlock2        *bitmapPB;
    plLocation          loc;

    loc = maxNode->GetLocation();
    bitmapPB = layer->GetParamBlockByID( plStaticEnvLayer::kBlkBitmap );
    
    if( !bitmapPB )
    {
        fErrorMsg->Set( !bitmapPB, "Plasma Layer Error", "Bitmap paramblock for Plasma Layer not found" ).Show();
        fErrorMsg->Set();
        return nil;
    }

    // Get a new layer to play with
    plLayer *plasmaLayer = ICreateLayer( plString::FromUtf8( layer->GetName() ), upperLayer, loc );

    // Get the texture info
    PBBitmap *pbbm = bitmapPB->GetBitmap( plStaticEnvLayer::kBmpFrontBitmap + 0 );
    BitmapInfo *bi = nil;
    if( pbbm )
        bi = &pbbm->bi;

    // If the texture had bad info, assert and return the empty layer
    if (!bi || !bi->Name() || !strcmp(bi->Name(), ""))
    {
        // Or don't assert since it can get annoying when you are using someone
        // elses file and don't have all the textures.
        return (plLayerInterface *)plasmaLayer;
    }

    // Setup the texture creation parameters
    plBitmapData bd;
    bd.fileName = bi->Name();

    // Create texture and add it to list if unique
    int32_t texFlags = 0;

    // Texture Alpha/Color
    if( bitmapPB->GetInt( plStaticEnvLayer::kBmpInvertColor ) )
        plasmaLayer->SetBlendFlags( plasmaLayer->GetBlendFlags() | hsGMatState::kBlendInvertColor );
    if( bitmapPB->GetInt( plStaticEnvLayer::kBmpDiscardColor ) )
        plasmaLayer->SetBlendFlags( plasmaLayer->GetBlendFlags() | hsGMatState::kBlendNoTexColor );
    if( bitmapPB->GetInt( kBmpDiscardAlpha ) )
        plasmaLayer->SetBlendFlags( plasmaLayer->GetBlendFlags() | hsGMatState::kBlendNoTexAlpha );
    if( bitmapPB->GetInt( plStaticEnvLayer::kBmpInvertAlpha ) )
        bd.invertAlpha = true;

    // Texture quality
    if( bitmapPB->GetInt( plStaticEnvLayer::kBmpNonCompressed ) )
        texFlags |= plBitmap::kForceNonCompressed;

    switch( bitmapPB->GetInt( plStaticEnvLayer::kBmpScaling ) )
    {
        case plStaticEnvLayer::kScalingHalf: texFlags |= plBitmap::kHalfSize;  break;
        case plStaticEnvLayer::kScalingNone: texFlags |= plBitmap::kNoMaxSize; break;
    }

    bd.texFlags = texFlags;
    bd.isStaticCubicEnvMap = true;
    for( int i = 0; i < 6; i++ )
    {
        PBBitmap *face = bitmapPB->GetBitmap( plStaticEnvLayer::kBmpFrontBitmap + i );
        if( !face )
            return (plLayerInterface *)plasmaLayer;
        bd.faceNames[ i ] = face->bi.Name();
    }

    // Get detail parameters
    if( bitmapPB->GetInt( plStaticEnvLayer::kBmpUseDetail ) )
    {                                           // TODO: be smarter
        if( blendFlags & hsGMatState::kBlendAdd )
            bd.createFlags = plMipmap::kCreateDetailAdd;
        else if( blendFlags & hsGMatState::kBlendMult )
            bd.createFlags = plMipmap::kCreateDetailMult;
        else
            bd.createFlags = plMipmap::kCreateDetailAlpha;

        bd.detailDropoffStart = float( bitmapPB->GetInt( plStaticEnvLayer::kBmpDetailStartSize ) ) / 100.f;
        bd.detailDropoffStop = float( bitmapPB->GetInt( plStaticEnvLayer::kBmpDetailStopSize ) ) / 100.f;
        bd.detailMax = float( bitmapPB->GetInt( plStaticEnvLayer::kBmpDetailStartOpac ) ) / 100.f;
        bd.detailMin = float( bitmapPB->GetInt( plStaticEnvLayer::kBmpDetailStopOpac ) ) / 100.f;
    }

    /// Since we're a cubic environMap, we don't care about the UV transform nor the uvwSrc
    plasmaLayer->SetUVWSrc( 0 );
    plasmaLayer->SetUVWSrc( plasmaLayer->GetUVWSrc() | plLayerInterface::kUVWReflect );

    // Create the texture.  If it works, assign it to the layer
    if( ( plasmaLayer = IAssignTexture( &bd, maxNode, plasmaLayer, upperLayer ) ) == nil )
        return nil;

    // Tag this layer as reflective cubic environmentmapping
    if( bitmapPB->GetInt(plStaticEnvLayer::kBmpRefract) )
        plasmaLayer->SetMiscFlags( plasmaLayer->GetMiscFlags() | hsGMatState::kMiscUseRefractionXform );
    else
        plasmaLayer->SetMiscFlags( plasmaLayer->GetMiscFlags() | hsGMatState::kMiscUseReflectionXform );

    return (plLayerInterface *)plasmaLayer;

    hsGuardEnd;
}
Beispiel #4
0
plLayerInterface    *plLayerConverter::IConvertLayerTex( plPlasmaMAXLayer *layer, 
                                                                plMaxNode *maxNode, uint32_t blendFlags, 
                                                                bool preserveUVOffset, bool upperLayer )
{
    hsGuardBegin( "plLayerConverter::IConvertLayerTex" );

    IParamBlock2        *bitmapPB;
    plLocation          loc;


    loc = maxNode->GetLocation();
    bitmapPB = layer->GetParamBlockByID( plLayerTex::kBlkBitmap );
    
    if( !bitmapPB )
    {
        fErrorMsg->Set( !bitmapPB, "Plasma Layer Error", "Bitmap paramblock for Plasma Layer not found" ).Show();
        fErrorMsg->Set();
        return nil;
    }

    // Get a new layer to play with
    plLayer *plasmaLayer = ICreateLayer( plString::FromUtf8( layer->GetName() ), upperLayer, loc );

    // We're using a texture, try and get its info
    PBBitmap    *pbbm = nil;
    BitmapInfo  *bi = nil;

    if( bitmapPB->GetInt( kBmpUseBitmap ) )
    {
        if( bitmapPB )
            pbbm = bitmapPB->GetBitmap( kBmpBitmap );
        if( pbbm )
            bi = &pbbm->bi;
    }

    // If the texture had bad info, assert and return the empty layer
    if( !bi || !bi->Name() || !strcmp(bi->Name(), "") )
    {
        if( upperLayer )
        {
            if( fErrorMsg->Set( !( fWarned & kWarnedNoUpperTexture ), "Plasma Export Error", sWarnNoUpperTexture, maxNode->GetName() ).CheckAskOrCancel() )
                fWarned |= kWarnedNoUpperTexture; 
            fErrorMsg->Set( false );

            delete plasmaLayer;
            return nil;
        }
        else
        {
            return (plLayerInterface *)plasmaLayer;
        }
    }

    // Setup the texture creation parameters
    plBitmapData bd;
    bd.fileName = bi->Name();

    // Create texture and add it to list if unique
    int32_t texFlags = 0;//hsGTexture::kMipMap;

    // Texture Alpha/Color
    if( bitmapPB->GetInt( kBmpInvertColor ) )
        plasmaLayer->SetBlendFlags( plasmaLayer->GetBlendFlags() | hsGMatState::kBlendInvertColor );
    if( bitmapPB->GetInt( kBmpDiscardColor ) )
        plasmaLayer->SetBlendFlags( plasmaLayer->GetBlendFlags() | hsGMatState::kBlendNoTexColor );
    if( bitmapPB->GetInt( kBmpDiscardAlpha ) )
        plasmaLayer->SetBlendFlags( plasmaLayer->GetBlendFlags() | hsGMatState::kBlendNoTexAlpha );
    if( bitmapPB->GetInt( kBmpInvertAlpha ) )
        bd.invertAlpha = true;

    // Texture quality
    if( bitmapPB->GetInt( kBmpNonCompressed ) )
        texFlags |= plBitmap::kForceNonCompressed;

    if( bitmapPB->GetInt( kBmpNoDiscard ) )
        texFlags |= plBitmap::kDontThrowAwayImage;

    switch( bitmapPB->GetInt( kBmpScaling ) )
    {
        case kScalingHalf: texFlags |= plBitmap::kHalfSize;  break;
        case kScalingNone: texFlags |= plBitmap::kNoMaxSize; break;
    }

    // Mip map filtering.
    if( bitmapPB->GetInt( kBmpNoFilter ) )
        texFlags |= plBitmap::kForceOneMipLevel;
    if( bitmapPB->GetInt( kBmpMipBias ) )
    {
        plasmaLayer->SetZFlags( plasmaLayer->GetZFlags() | hsGMatState::kZLODBias );
        plasmaLayer->SetLODBias( bitmapPB->GetFloat( kBmpMipBiasAmt, fConverterUtils.GetTime( fInterface ) ) );
    }
    float sig = bitmapPB->GetFloat( kBmpMipBlur );

    bd.texFlags = texFlags;
    bd.sig = sig;

    // Get detail parameters
    if( bitmapPB->GetInt( kBmpUseDetail ) )
    {                                           // TODO: be smarter
        if( blendFlags & hsGMatState::kBlendAdd )
            bd.createFlags |= plMipmap::kCreateDetailAdd;
        else if( blendFlags & hsGMatState::kBlendMult )
            bd.createFlags |= plMipmap::kCreateDetailMult;
        else
            bd.createFlags |= plMipmap::kCreateDetailAlpha;
        bd.detailDropoffStart = float(bitmapPB->GetInt(kBmpDetailStartSize)) / 100.f;
        bd.detailDropoffStop = float(bitmapPB->GetInt(kBmpDetailStopSize)) / 100.f;
        bd.detailMax = float(bitmapPB->GetInt(kBmpDetailStartOpac)) / 100.f;
        bd.detailMin = float(bitmapPB->GetInt(kBmpDetailStopOpac)) / 100.f;
    }

    // Get max export dimension (since the function we eventually call
    // expects the max of the two dimensions, we figure that out here and
    // pass it on)
    bd.maxDimension = bitmapPB->GetInt( kBmpExportWidth );
    int expHt = bitmapPB->GetInt( kBmpExportHeight );
    if( bd.maxDimension < expHt )
        bd.maxDimension = expHt;
    int clipID = 0, w;
    for( clipID = 0, w = bi->Width(); w > bd.maxDimension; w >>= 1, clipID++ );

    // Do the UV gen (before we do texture, since it could modify the bitmapData struct)
    IProcessUVGen( layer, plasmaLayer, &bd, preserveUVOffset );

    // Create the texture.  If it works, assign it to the layer
    if( ( plasmaLayer = IAssignTexture( &bd, maxNode, plasmaLayer, upperLayer, clipID ) ) == nil )
        return nil;

    // All done!
    return (plLayerInterface *)plasmaLayer;

    hsGuardEnd;
}
    void HwShaderExporter::exportEffectParameters ( 
        StdMat2* material 
        )
    {
        COLLADASW::StreamWriter* streamWriter = &mDocumentExporter->getStreamWriter();

        IParamBlock2 * pblock = material->GetParamBlock ( 0 );
        int parameterCount = pblock->NumParams();
        
        for ( int i = 0; i < parameterCount; i++ )
        {
            ParamID parameterID = pblock->IndextoID( i );
            ParamType2 parameterType = pblock->GetParameterType( parameterID );
            ParamDef parameterDef = pblock->GetParamDef( parameterID );

            const TCHAR* paramName = parameterDef.int_name;

            switch ( parameterType )
            {
                case TYPE_FLOAT:
                {
                    COLLADASW::NewParam<> newParam ( streamWriter );
                    newParam.setParamType ( COLLADASW::ValueType::FLOAT );

                    int numOfValues = 1;
                    float paramValue = pblock->GetFloat( parameterID );

                    exportParam ( paramName, &newParam, &paramValue, numOfValues );

                    break;
                }

                case TYPE_INT:
                {
                    COLLADASW::NewParam<> newParam ( streamWriter );
                    newParam.setParamType ( COLLADASW::ValueType::INT );

                    int numOfValues = 1;
                    int paramValue = pblock->GetInt( parameterID );

                    exportParam ( paramName, &newParam, &paramValue, numOfValues );

                    break;
                }

                case TYPE_RGBA:
                case TYPE_FRGBA:
                {
                    COLLADASW::NewParam<> newParam ( streamWriter );
                    newParam.setParamType ( COLLADASW::ValueType::FLOAT4 );

                    int numOfValues = 4;
                    AColor paramPoint3Value = pblock->GetAColor( parameterID );
                    float* paramValue = (float*)paramPoint3Value;

                    exportParam ( paramName, &newParam, paramValue, numOfValues );

                    break;
                }

                case TYPE_POINT3:
                {
                    COLLADASW::NewParam<> newParam ( streamWriter );
                    newParam.setParamType ( COLLADASW::ValueType::FLOAT3 );

                    int numOfValues = 3;
                    Point3 paramPoint3Value = pblock->GetPoint3( parameterID );
                    float* paramValue = (float*)paramPoint3Value;

                    exportParam ( paramName, &newParam, paramValue, numOfValues );

                    break;
                }

                case TYPE_BOOL:
                {
                    COLLADASW::NewParam<> newParam ( streamWriter );
                    newParam.setParamType ( COLLADASW::ValueType::BOOL );

                    int numOfValues = 1;
                    /*bool*/ int paramValue = pblock->GetInt( parameterID );

                    exportParam ( paramName, &newParam, &paramValue, numOfValues );

                    break;
                }

                //TYPE_ANGLE   
                //TYPE_PCNT_FRAC   
                //TYPE_WORLD   

                case TYPE_STRING:
                {
                    COLLADASW::NewParam<> newParam ( streamWriter );

                    const MCHAR * paramValue = pblock->GetStr( parameterID );
                    exportParam ( paramName, &newParam, paramValue );

                    break;
                }

                //TYPE_FILENAME   
                //TYPE_HSV   
                //TYPE_COLOR_CHANNEL   
                //TYPE_TIMEVALUE   
                //TYPE_RADIOBTN_INDEX   
                //TYPE_MTL   
                //TYPE_TEXMAP   

                case TYPE_BITMAP:
                {
                    PBBitmap * bitmap = pblock->GetBitmap( parameterID );
                    exportSampler ( paramName, bitmap );

                    break;
                }

                //TYPE_INODE   
                //TYPE_REFTARG   
                //TYPE_INDEX   
                //TYPE_MATRIX3   
                //TYPE_PBLOCK2   

                case TYPE_POINT4:
                {
                    COLLADASW::NewParam<> newParam ( streamWriter );
                    newParam.setParamType ( COLLADASW::ValueType::FLOAT4 );

                    int numOfValues = 4;
                    Point4 paramPoint3Value = pblock->GetPoint4( parameterID );
                    float* paramValue = (float*)paramPoint3Value;

                    exportParam ( paramName, &newParam, paramValue, numOfValues );

                    break;
                }

                default:
                {
                    //:TODO: warning (file and/or popup)
                    GetCOREInterface()->Log()->LogEntry( SYSLOG_WARN, DISPLAY_DIALOG, _M( "Parameter export problem" ),_M( "Unsupported parameter type (%i) for parameter %s\n" ), parameterType, paramName );
                }
            }
        }
    }