예제 #1
0
파일: gradient.cpp 프로젝트: 2asoft/xray
Bitmap *Gradient::BuildBitmap(int size) {
	float u,v;
	BitmapInfo bi;
	bi.SetName(GetString(IDS_RB_GRADTEMP));
	bi.SetWidth(size);
	bi.SetHeight(size);
	bi.SetType(BMM_TRUE_32);
	Bitmap *bm = TheManager->Create(&bi);
	if (bm==NULL) return NULL;
	PixelBuf l64(size);
	float d = 1.0f/float(size);
	v = 1.0f - 0.5f*d;
	for (int y=0; y<size; y++) {
		BMM_Color_64 *p64=l64.Ptr();
		u = 0.0f;
		for (int x=0; x<size; x++, p64++) {
			AColor c = DispEvalFunc(u,v);
			p64->r = FlToWord(c.r); 
			p64->g = FlToWord(c.g); 
			p64->b = FlToWord(c.b);
			p64->a = 0xffff; 
			u += d;
			}
		bm->PutPixels(0,y, size, l64.Ptr()); 
		v -= d;
		}
	return bm;
	}
예제 #2
0
Bitmap* UVtex::BuildBitmap(int size) {
	float u,v;
	BitmapInfo bi;
	bi.SetName(_T("uvTexTemp"));
	bi.SetWidth(size);
	bi.SetHeight(size);
	bi.SetType(BMM_TRUE_32);
	Bitmap *bm = TheManager->Create(&bi);
	if (bm==NULL) return NULL;
	PixelBuf l64(size);
	float d = 1.0f/float(size);
	v = 0.0f;
	for (int y=0; y<size; y++) {
		BMM_Color_64 *p64=l64.Ptr();
		u = 0.0f;
		for (int x=0; x<size; x++, p64++) {
			Color c = EvalUVtex( Point3(u,(1.0f-v),0.0f) );
			p64->r = FlToWord(c.r);
			p64->g = FlToWord(c.g);
			p64->b = FlToWord(c.b);
			p64->a = 0xffff;
			u += d;
		}
		bm->PutPixels(0,y, size, l64.Ptr());
		v += d;
	}
	return bm;
}
예제 #3
0
Bitmap *Gradient::BuildBitmap(int size) {
	float u,v;
	BitmapInfo bi;
	static MaxSDK::AssetManagement::AssetUser bitMapAssetUser;
	if (bitMapAssetUser.GetId() == MaxSDK::AssetManagement::kInvalidId)
		bitMapAssetUser = MaxSDK::AssetManagement::IAssetManager::GetInstance()->GetAsset(GetString(IDS_RB_GRADTEMP), MaxSDK::AssetManagement::kBitmapAsset);
	bi.SetAsset(bitMapAssetUser);
	bi.SetWidth(size);
	bi.SetHeight(size);
	bi.SetType(BMM_TRUE_32);
	Bitmap *bm = TheManager->Create(&bi);
	if (bm==NULL) return NULL;
	PixelBuf l64(size);
	float d = 1.0f/float(size);
	v = 1.0f - 0.5f*d;
	for (int y=0; y<size; y++) {
		BMM_Color_64 *p64=l64.Ptr();
		u = 0.0f;
		for (int x=0; x<size; x++, p64++) {
			AColor c = DispEvalFunc(u,v);
			p64->r = FlToWord(c.r); 
			p64->g = FlToWord(c.g); 
			p64->b = FlToWord(c.b);
			p64->a = 0xffff; 
			u += d;
			}
		bm->PutPixels(0,y, size, l64.Ptr()); 
		v -= d;
		}
	return bm;
	}
예제 #4
0
파일: cin.cpp 프로젝트: 2asoft/xray
BMMRES
BitmapIO_CIN::GetImageInfoDlg(HWND hWnd, BitmapInfo* bmi, const TCHAR* fname)
{
    BitmapInfo  bInfo;
    if (!bmi) {
        assert(FALSE);
        return ProcessImageIOError(bmi, GetResIDCaption(IDS_CIN_Internal_Error));
    }

	bInfo.Copy(bmi);

    if (fname)
		bInfo.SetName(fname);

    BMMRES bmmResult = GetImageInfo(&bInfo);
    if (bmmResult != BMMRES_SUCCESS) {
        return bmmResult;
    }

#ifdef BASIC_INFO_DLG
    DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CIN_BASIC_INFO),
                   hWnd, (DLGPROC) CIN_ImageInfoDialogProc, (LPARAM) this);
#else
    DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CIN_INFO),
                   hWnd, (DLGPROC) CIN_ImageInfoDialogProc, (LPARAM) this);
#endif

    return BMMRES_SUCCESS;
}
예제 #5
0
    /// 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 );
    }
예제 #6
0
Bitmap *PainterTextureSample::BuildBitmap(int size) 
	{
	float u,v;
	BitmapInfo bi;
	bi.SetName(_T("checkerTemp"));
	bi.SetWidth(size);
	bi.SetHeight(size);
	bi.SetType(BMM_TRUE_32);
	if (bm == NULL)
		{
		bm = TheManager->Create(&bi);
		if (bm==NULL) return NULL;
		PixelBuf l64(size);
		float d = 1.0f/float(size);
		v = 1.0f - 0.5f*d;
		for (int y=0; y<size; y++) {
			BMM_Color_64 *p64=l64.Ptr();
			u = 0.0f;
			for (int x=0; x<size; x++, p64++) {
				AColor c(0.0f,0.0f,0.0f) ;
				p64->r = FlToWord(c.r); 
				p64->g = FlToWord(c.g); 
				p64->b = FlToWord(c.b);
				p64->a = 0xffff; 
				u += d;
				}
			bm->PutPixels(0,y, size, l64.Ptr()); 
			v -= d;
			}
		}
	width = size;
	return bm;
	}
예제 #7
0
//
// Create Bitmap
//
plMipmap *plBitmapCreator::ICreateBitmap(plBitmapData *bd)
{
    hsGuardBegin("hsConverterUtils::CreateBitmap");

    // Load the bitmap
    BitmapInfo bi;
    bi.SetName(bd->fileName.AsString().c_str());

#if 0 // This isn't really an issue since the textures are packed -Colin
    const int kMaxFileNameLength = 30;
    if (strlen(bi.Filename()) > kMaxFileNameLength)
    {
        // Allow to continue, But make it painful
        char errStr[256];
        sprintf(errStr, "File name longer than %d, won't burn to CD (%s)", kMaxFileNameLength, bi.Filename());//bitmapTex->GetName());
        MessageBox(GetActiveWindow(), errStr, bd->fileName, MB_OK|MB_ICONEXCLAMATION);  
    }
#endif

    bool notMipped = (bd->texFlags & plMipmap::kForceOneMipLevel) != 0;
    float sigma = bd->sig;
    
    // Load the bitmap
    Bitmap *bm = TheManager->Load(&bi);
    if (!bm)
    {
        // FIXME
        /*
        if (fErrorMsg->Set(!(fWarned & kWarnedNoMoreBitmapLoadErr), 
            "Error loading bitmap", pathName).CheckAskOrCancel())
        {
            fWarned |= kWarnedNoMoreBitmapLoadErr;
        }
        */
        return nil;
    }
    BitmapStorage *storage = bm->Storage();
    BitmapInfo *bInfo = &storage->bi;

    ICheckOutBitmap(bInfo, bm, bd->fileName);

    //
    // Create a plMipmap 
    //
    plMipmap *hBitmap = new plMipmap;
    if( (bm->Width() ^ (bm->Width() & -bm->Width()))
        ||(bm->Height() ^ (bm->Height() & -bm->Height())) )
    {
        IResampBitmap(bm, *hBitmap);
    }
    else if( ((bm->Width() >> 3) > bm->Height())||((bm->Height() >> 3) > bm->Width()) )
    {
        IResampBitmap(bm, *hBitmap);
    }
    else
    {
예제 #8
0
void	ViewFile::View( HWND	hWnd ) {
	
	int idx;
	DWORD caps;
	BitmapInfo bi;
	Bitmap *map = NULL;
	TCHAR buf[256];

	LoadString(hInst, IDS_DB_VIEW_FILE, buf, _countof(buf));
	
	if (!TheManager->SelectFileInputEx(&bi, hWnd, buf, TRUE))
	   return;

	if	(bi.Name()[0])
		idx = TheManager->ioList.ResolveDevice(&bi);
	else
		idx = TheManager->ioList.FindDevice(bi.Device());

	if (idx == -1)
		goto error;

	caps = TheManager->ioList.GetDeviceCapabilities(bi.Device());
	TCHAR title[MAX_PATH];

	if	(caps & BMMIO_EXTENSION)
		_tcscpy(title,bi.Filename());
	else
		_tcscpy(title,bi.Device());

	if	(caps & BMMIO_OWN_VIEWER) {
		BitmapIO	*IO =	TheManager->ioList.CreateDevInstance(bi.Device());
		if(IO) {
			BOOL succeeded = IO->ShowImage(hWnd,&bi);
			delete IO;
			if(!succeeded)
				goto normal_view;
		}
	} else {
		normal_view:
		SetCursor(LoadCursor(NULL,IDC_WAIT));
		map = TheManager->Load(&bi);
		if	(map)	{
			map->Display(title, BMM_CN, TRUE, FALSE);
		} else {
			error:
			TCHAR text[128];
			TCHAR tmp[128];
			LoadString(hInst, IDS_DB_NO_VIEW, tmp, _countof(tmp));
			wsprintf(text,tmp,bi.Name());
			LoadString(hInst, IDS_DB_VIEW_ERROR, tmp, _countof(tmp));
			MessageBox(hWnd,text,tmp,MB_OK);
		}
		SetCursor(LoadCursor(NULL,IDC_ARROW));
	}
	
}
예제 #9
0
bool SharedBitmap::to16bit()
{
    if (m_locked)
        return false;
    if (is16bit())
        return true;

    BitmapInfo newBmpInfo = BitmapInfo::create(m_bmpInfo.size(), BitmapInfo::BitCount16);

    int width = newBmpInfo.width();
    int paddedWidth = newBmpInfo.paddedWidth();
    int bufferSize = paddedWidth * newBmpInfo.height();
    OwnArrayPtr<unsigned> newPixelData = adoptArrayPtr(new unsigned[bufferSize / 2]);
    void* newPixels = newPixelData.get();

    if (!newPixels)
        return false;

    unsigned short* p16 = static_cast<unsigned short*>(newPixels);
    const unsigned* p32 = static_cast<const unsigned*>(m_pixels);

    bool skips = paddedWidth != width;

    const unsigned short* p16end = p16 + bufferSize;
    while (p16 < p16end) {
        for (unsigned short* p16lineEnd = p16 + width; p16 < p16lineEnd; )
            *p16++ = convert32To16(*p32++);

        if (skips)
            *p16++ = 0;
    }

    if (m_hbitmap)
        m_hbitmap = nullptr;
    else
        m_pixelData = newPixelData.release();

    m_pixels = newPixels;
    m_bmpInfo = newBmpInfo;

    setHasAlpha(false);
    return true;
}
예제 #10
0
void UtilTest::RenderFrame()
{
    int res;

    // Create a blank bitmap
    static Bitmap *bm = NULL;
    if (!bm) {
        BitmapInfo bi;
        bi.SetWidth(320);
        bi.SetHeight(200);
        bi.SetType(BMM_TRUE_64);
        bi.SetFlags(MAP_HAS_ALPHA);
        bi.SetAspect(1.0f);
        bm = TheManager->Create(&bi);
    }

    // Get the active viewport to render

    // Display the bitmap
    bm->Display(_T("Test"));

    // Open up the renderer, render a frame and close it.
    res = ip->OpenCurRenderer(NULL,ip->GetActiveViewExp().ToPointer());
    res = ip->CurRendererRenderFrame(
              ip->GetTime(),bm);
    ip->CloseCurRenderer();

    // We're done with the viewport.

}
예제 #11
0
int plLayerTex::ICalcFrame(TimeValue t)
{
    PBBitmap *pbbm = fBitmapPB->GetBitmap(kBmpBitmap);
    if (!pbbm || !pbbm->bi)
        return 0;
    BitmapInfo *bi = pbbm->bi;

    TimeValue tm, dur, td;
    int frameStart = bi->FirstFrame();
    int frameEnd = bi->LastFrame();
    int tpf = GetTicksPerFrame();
    tm = TimeValue(float(t - startTime) * pbRate);
    dur = (fend-fstart+1)*GetTicksPerFrame();

    switch (endCond)
    {
    case END_HOLD:
        if (tm <= 0)
            return frameStart;
        if (tm >= dur)
            return frameEnd;
        return tm/tpf;

    case END_PINGPONG:
        if (((tm >= 0) && ((tm / dur) & 1)) || ((tm < 0) && !(tm / dur)))
        {
            td = modt(tm, dur);
            return frameStart + frameEnd - td / tpf;
        }
    // else fall through
    case END_LOOP:
        td = modt(tm, dur);
        return td / tpf;
    }

    return 0;
}
예제 #12
0
파일: plate.cpp 프로젝트: artemeliy/inf4715
int PlateMap::AllocMap(int w, int h) {
	if ( bm && w==bm->Width() && h==bm->Height())
		return 1;
	BitmapInfo bi;
	if (bm) bm->DeleteThis();
	bi.SetName(_T(""));
	bi.SetWidth(w);
	bi.SetHeight(h);
	bi.SetType(BMM_TRUE_32);
	bi.SetCustomFlag(BMM_CUSTOM_GAMMA);
	bi.SetCustomGamma(1.0f);

	bm = TheManager->Create(&bi);

//	bm->CreateChannels(BMM_CHAN_Z); 
	return 1;
	}
예제 #13
0
void    plStaticEnvLayer::RenderCubicMap( INode *node )
{
    int         res, size;
    BOOL        success = 0;
    TSTR        fname, fullname;
    Bitmap      *bm = NULL;
    TSTR        path, filename, ext, thisFilename;
    BitmapInfo  biOutFile;

    static TCHAR    suffixes[ 6 ][ 4 ] = { "_FR", "_BK", "_LF", "_RT", "_UP", "_DN" };


    Interface *ip = GetCOREInterface();
    size = fBitmapPB->GetInt( kBmpTextureSize, ip->GetTime() );
    if( size <= 0 ) 
    {
        return;
    }

    thisFilename = fBitmapPB->GetStr( kBmpBaseFilename, ip->GetTime() );
    if( thisFilename.isNull() )
    {
        return;
    }

    SplitFilename( thisFilename, &path, &filename, &ext );

    BOOL    wasHid = node->IsNodeHidden();
    node->Hide( TRUE );

    // Create a blank bitmap
    biOutFile.SetWidth( size );
    biOutFile.SetHeight( size );
    biOutFile.SetType( BMM_TRUE_64 );
    biOutFile.SetAspect( 1.0f );
    biOutFile.SetCurrentFrame( 0 );
    bm = TheManager->Create( &biOutFile );

    Matrix3 nodeTM = node->GetNodeTM( ip->GetTime() );
    Matrix3 tm; 
    INode *root = ip->GetRootNode();        
    bm->Display( GetString( IDS_CUBIC_RENDER_TITLE ) );

    /// Set up rendering contexts
    ViewParams vp;
    vp.projType = PROJ_PERSPECTIVE;
    vp.hither = .001f;
    vp.yon = 1.0e30f;
    vp.fov = M_PI/2.0f;
    if( fBitmapPB->GetInt( kBmpUseMAXAtmosphere ) )
    {
        vp.nearRange = 0;
        vp.farRange = fBitmapPB->GetFloat( kBmpFarDistance );
    }
    else
    {
        vp.nearRange = vp.farRange = 1.0e30f;
    }
    BOOL    saveUseEnvMap = ip->GetUseEnvironmentMap();
    ip->SetUseEnvironmentMap( false );

    res = ip->OpenCurRenderer( &vp ); 
    for( int i = 0; i < 6; i++ )
    {
        tm = IGetViewTM( i );
        tm.PreTranslate( -nodeTM.GetTrans() ); 
        vp.affineTM = tm;

        // Construct filename
        thisFilename.printf( _T( "%s\\%s%s%s" ), path, filename, suffixes[ i ], ext );

        res = ip->CurRendererRenderFrame( ip->GetTime(), bm, NULL, 1.0f, &vp );
        if( !res ) 
            goto fail;

        if( !IWriteBM( &biOutFile, bm, thisFilename ) ) 
            goto fail;
    }

    success = 1;
fail:
    ip->CloseCurRenderer(); 
    ip->SetUseEnvironmentMap( saveUseEnvMap );

    bm->DeleteThis();
    node->Hide( wasHid );
    if( success )
    {
        for(int i = 0; i < 6; i++ )
        {
            BitmapInfo  bi;
            thisFilename.printf( _T( "%s\\%s%s%s" ), path, filename, suffixes[ i ], ext );
            bi.SetName( thisFilename );

            PBBitmap    pbBitmap( bi );
            fBitmapPB->SetValue( kBmpFrontBitmap + i, ip->GetTime(), &pbBitmap );
        }
        fBitmapPB->GetMap()->UpdateUI( ip->GetTime() );
    }
}
예제 #14
0
BOOL plPlasmaMAXLayer::HandleBitmapSelection(int index /* = 0 */)
{
    static ICustButton* bmSelectBtn;

    PBBitmap *pbbm = GetPBBitmap( index );

#ifdef MAXASS_AVAILABLE
    MaxAssInterface* maxAssInterface = GetMaxAssInterface();
#endif
    
    // If the control key is held, we want to get rid of this texture
    if ((GetKeyState(VK_CONTROL) & 0x8000) && pbbm != nil)
    {
        char msg[512];
        sprintf(msg, "Are you sure you want to change this bitmap from %s to (none)?", pbbm->bi.Name());
        if (hsMessageBox(msg, "Remove texture?", hsMessageBoxYesNo) == hsMBoxYes)
        {
            SetBitmap(nil, index);
            return TRUE;
        }
        return FALSE;
    }
    // if we have the assetman plug-in, then try to use it, unless shift is held down
#ifdef MAXASS_AVAILABLE
    else if(maxAssInterface && !(GetKeyState(VK_SHIFT) & 0x8000))
    {
        jvUniqueId assetId;
        GetBitmapAssetId(assetId, index);

        char filename[MAX_PATH];
        if (maxAssInterface->OpenBitmapDlg(assetId, filename, sizeof(filename)))
        {
            SetBitmapAssetId(assetId, index);

            BitmapInfo bi;
            bi.SetName(filename);
            SetBitmap(&bi, index);
            return TRUE;
        }
    }
#endif
    else
    {
        BitmapInfo bi;
        if( pbbm != NULL )
            bi.SetName( pbbm->bi.Name() );

        BOOL selectedNewBitmap = TheManager->SelectFileInput(&bi,
                                                            GetCOREInterface()->GetMAXHWnd(),
                                                            _T("Select Bitmap Image File"));
        if (selectedNewBitmap)
        {
#ifdef MAXASS_AVAILABLE
            // Set the assetId to empty so our new, unmanaged texture will take
            jvUniqueId emptyId;
            SetBitmapAssetId(emptyId, index);
#endif

            SetBitmap(&bi, index);
            return TRUE;
        }
    }

    return FALSE;
}
예제 #15
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;
}
예제 #16
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;
}
예제 #17
0
//----------------------------------------------------------------------------
void SceneBuilder::ConvertMaterial (Mtl &mtl, MtlTree &mtlTree)
{
	// 光照属性
	PX2::Shine *shine = new0 PX2::Shine;
	Color color = mtl.GetAmbient();
	float alpha = 1.0f - mtl.GetXParency();
	shine->Ambient = PX2::Float4(color.r, color.g, color.b, 1.0f);
	color = mtl.GetDiffuse();
	shine->Diffuse = PX2::Float4(color.r, color.g, color.b, alpha);
	color = mtl.GetSpecular();
	float shininess = mtl.GetShininess()*2.0f;
	shine->Specular = PX2::Float4(color.r, color.g, color.b, shininess);

	const char *name = (const char*)mtl.GetName();
	shine->SetName(name);

	mtlTree.SetShine(shine);

	bool IsDirect9Shader = false;

	if (mtl.ClassID() == Class_ID(CMTL_CLASS_ID, 0)
		|| mtl.ClassID() == Class_ID(DMTL_CLASS_ID, 0))
	{
		StdMat2 *stdMat2 = (StdMat2*)(&mtl);
		Interval valid = FOREVER;
		stdMat2->Update(mTimeStart, valid);

		std::string strName(stdMat2->GetName());
		bool doubleSide = (stdMat2->GetTwoSided()==1);

		char strBitMapName[256];
		memset(strBitMapName, 0, 256*sizeof(char));
		std::string resourcePath;

		PX2::Shader::SamplerFilter filter = PX2::Shader::SF_LINEAR_LINEAR;
		PX2::Shader::SamplerCoordinate uvCoord = PX2::Shader::SC_REPEAT;
		PX2_UNUSED(uvCoord);

		if (stdMat2->MapEnabled(ID_DI))
		{
			BitmapTex *tex = (BitmapTex*)stdMat2->GetSubTexmap(ID_DI);

			BitmapInfo bI;
			const char *mapName = tex->GetMapName();
			TheManager->GetImageInfo(&bI, mapName);
			strcpy(strBitMapName, bI.Name());

			std::string fullName = std::string(strBitMapName);
			std::string::size_type sizeT = fullName.find_first_not_of(mSettings->SrcRootDir);
			resourcePath = std::string(strBitMapName).substr(sizeT);

			StdUVGen* uvGen = tex->GetUVGen();
			PX2_UNUSED(uvGen);
			int filType = tex->GetFilterType();
			switch (filType)
			{
				case FILTER_PYR:
					filter = PX2::Shader::SF_LINEAR_LINEAR;
					break;
				case FILTER_SAT:
					filter = PX2::Shader::SF_NEAREST;
					break;
				default:
					break;
			}
		}
		else
		{
			sprintf(strBitMapName, "%s/%s", mSettings->SrcRootDir, PX2_DEFAULT_TEXTURE);
			resourcePath = PX2_DEFAULT_TEXTURE;
		}

		PX2::Texture2D *tex2d = PX2::DynamicCast<PX2::Texture2D>(
			PX2::ResourceManager::GetSingleton().BlockLoad(strBitMapName));
		tex2d->SetResourcePath(resourcePath);

		if (tex2d)
		{
			PX2::Texture2DMaterial *tex2dMtl = new0 PX2::Texture2DMaterial(filter, 
				uvCoord, uvCoord);
			if (doubleSide)
			{
				tex2dMtl->GetCullProperty(0, 0)->Enabled = false;
			}

			PX2::MaterialInstance *instance = tex2dMtl->CreateInstance(tex2d);

			mtlTree.SetMaterialInstance(instance);
		}
		else
		{
			PX2::VertexColor4Material *vcMtl = new0 PX2::VertexColor4Material();
			PX2::MaterialInstance *instance = vcMtl->CreateInstance();
			mtlTree.SetMaterialInstance(instance);
		}
	}
	else if (mtl.ClassID() == Class_ID(MULTI_CLASS_ID, 0))
	{
	}
	else if (mtl.ClassID() == DIRECTX_9_SHADER_CLASS_ID)
	{
		IsDirect9Shader = true;

		IDxMaterial* dxMtl = (IDxMaterial*)mtl.GetInterface(IDXMATERIAL_INTERFACE);
		char *effectName = dxMtl->GetEffectFilename();
		IParamBlock2 *paramBlock = mtl.GetParamBlock(0);

		std::string outPath;
		std::string outBaseName;
		std::string outExtention;
		PX2::StringHelp::SplitFullFilename(effectName, outPath, outBaseName,
			outExtention);

		PX2::ShinePtr shineStandard = new0 PX2::Shine();
		bool alphaVertex = false;
		PX2::Texture2DPtr diffTex;
		bool normalEnable = false;
		PX2::Texture2DPtr normalTex;
		float normalScale = 0.0f;
		bool specEnable = false;
		PX2::Texture2DPtr specTex;
		float specPower = 0.0f;
		bool reflectEnable = false;
		PX2::TextureCubePtr reflectTex;
		float reflectPower = 0.0f;
		bool doubleSide = false;
		int blendMode = 2;

		ParamBlockDesc2 *paramDesc = 0;
		int numParam = 0;
		if (paramBlock)
		{
			paramDesc = paramBlock->GetDesc();
			numParam = paramBlock->NumParams();

			ParamType2 paramType;
			for (int i=0; i<numParam; i++)
			{
				std::string parmName;
				PX2::Float4 color4 = PX2::Float4(0.0f, 0.0f, 0.0f, 0.0f);
				PX2::Float3 color3 = PX2::Float3(0.0f, 0.0f, 0.0f);
				float floatValue = 0.0f;
				bool boolValue = false;
				float *floatTable = 0;
				int intValue = 0;
				std::string str;
				PX2::Texture2D *tex2d = 0;

				paramType = paramBlock->GetParameterType((ParamID)i);

				if (TYPE_STRING == paramType)
					ConvertStringAttrib(paramBlock, i, parmName, str);
				else if (TYPE_FLOAT == paramType)
					ConvertFloatAttrib(paramBlock, i, parmName, floatValue);
				else if (TYPE_INT == paramType)
					ConvertIntAttrib(paramBlock, i, parmName, intValue);
				else if (TYPE_RGBA == paramType)
					ConvertColorAttrib(paramBlock, i, parmName, color4, i);
				else if (TYPE_POINT3 == paramType)
					ConvertPoint3Attrib(paramBlock, i, parmName, color3);
				else if (TYPE_POINT4 == paramType)
					ConvertPoint4Attrib(paramBlock, i, parmName, color4);
				else if (TYPE_BOOL == paramType)
					ConvertBoolAttrib(paramBlock, i, parmName, boolValue);
				else if (TYPE_FLOAT_TAB == paramType)
					ConvertFloatTabAttrib(paramBlock, i, parmName, floatTable);
				else if (TYPE_BITMAP == paramType)
					ConvertBitMapAttrib(paramBlock, i, parmName, tex2d);
				else if (TYPE_FRGBA ==paramType)
					ConvertFRGBAAttrib(paramBlock, i, parmName, color4);

				// shine
				if (parmName == "gBlendMode")
				{
					blendMode = intValue;
				}
				else if (parmName == "gShineEmissive")
				{
					shineStandard->Emissive = color4;
				}
				else if (parmName == "gShineAmbient")
				{
					shineStandard->Ambient = color4;
				}
				else if (parmName == "gShineDiffuse")
				{
					shineStandard->Diffuse = color4;
				}
				// alpha vertex
				else if (parmName == "gAlphaVertex")
				{
					alphaVertex = boolValue;
				}
				// diffuse
				else if (parmName == "gDiffuseTexture")
				{
					diffTex = tex2d;
				}
				// normal
				else if (parmName == "gNormalEnable")
				{
					normalEnable = boolValue;
				}
				else if (parmName == "gNormalTexture")
				{
					normalTex = tex2d;
				}
				else if (parmName == "gNormalScale")
				{
					normalScale = floatValue;
				}
				// specular
				else if (parmName == "gSpecularEnable")
				{
					specEnable = boolValue;
				}
				else if (parmName == "gSpecularTexture")
				{
					specTex = tex2d;
				}
				else if (parmName == "gSpecularPower")
				{
					specPower = floatValue;
				}
				// reflect
				else if (parmName == "gReflectionEnable")
				{
					reflectEnable = boolValue;
				}
				else if (parmName == "gReflectTexture")
				{
					//reflectTex = tex2d;
				}
				else if (parmName == "gReflectPower")
				{
					reflectPower = floatValue;
				}
				// other
				else if (parmName == "gDoubleSide")
				{
					doubleSide = boolValue;
				}
			}
		}

		PX2::MaterialInstance *inst = 0;
		PX2::StandardMaterial *standardMtl = 0;
		PX2::StandardESMaterial_Default *standardESMtl_D = 0;
		PX2::StandardESMaterial_Specular *standardESMtl_S = 0;
		if (outBaseName == "Standard")
		{
			char mtlName[256];
			memset(mtlName, 0, 256*sizeof(char));
			sprintf(mtlName, "%s/%s", mSettings->DstRootDir, 
				"Data/mtls/Standard.pxfx");
			standardMtl = new0 PX2::StandardMaterial(mtlName);
		}
		else if (outBaseName == "StandardES")
		{
			if (false == specEnable)
			{
				standardESMtl_D = new0 PX2::StandardESMaterial_Default();

				if (0 == blendMode)
				{
					standardESMtl_D->GetAlphaProperty(0, 0)->BlendEnabled = false;
					standardESMtl_D->GetAlphaProperty(0, 0)->CompareEnabled = false;
				}
				else if (1 == blendMode)
				{
					standardESMtl_D->GetAlphaProperty(0, 0)->BlendEnabled = true;
				}
				else if (2 == blendMode)
				{
					standardESMtl_D->GetAlphaProperty(0, 0)->BlendEnabled = false;
					standardESMtl_D->GetAlphaProperty(0, 0)->CompareEnabled = true;
					standardESMtl_D->GetAlphaProperty(0, 0)->Compare = PX2::AlphaProperty::CM_GEQUAL;
					standardESMtl_D->GetAlphaProperty(0, 0)->Reference = 0.2f;
				}
			}
			else
			{
				char mtlName[256];
				memset(mtlName, 0, 256*sizeof(char));
				sprintf(mtlName, "%s/%s", mSettings->DstRootDir, 
					"Data/mtls/StandardES_Specular.pxfx");
				standardESMtl_S = new0 PX2::StandardESMaterial_Specular(mtlName);
			}
		}

		if (standardMtl && diffTex)
		{
			if (doubleSide)
			{
				standardMtl->GetCullProperty(0, 0)->Enabled = false;
			}

			inst = standardMtl->CreateInstance(diffTex, alphaVertex, 
				normalEnable, normalTex, normalScale, specEnable, specTex,
				specPower, 0, shineStandard);
		}
		else if (standardESMtl_D && diffTex)
		{
			if (doubleSide)
			{
				standardESMtl_D->GetCullProperty(0, 0)->Enabled = false;
			}

			inst = standardESMtl_D->CreateInstance(diffTex, 0, shineStandard);
		}
		else if (standardESMtl_S && diffTex && specTex)
		{
			if (doubleSide)
			{
				standardESMtl_S->GetCullProperty(0, 0)->Enabled = false;
			}

			inst = standardESMtl_S->CreateInstance(diffTex, specTex, specPower,
				0, shineStandard);
		}

		if (inst)
		{
			mtlTree.SetMaterialInstance(inst);
		}
		else
		{
			PX2::MaterialInstance *instance = 
				PX2::VertexColor4Material::CreateUniqueInstance();
			mtlTree.SetMaterialInstance(instance);
		}
	}
	else
	{
		PX2::VertexColor4Material *vcMtl = new0 PX2::VertexColor4Material();
		PX2::MaterialInstance *instance = vcMtl->CreateInstance();
		mtlTree.SetMaterialInstance(instance);
	}

	// 对子材质进行处理
	if (IsDirect9Shader)
		return;

	int mQuantity = mtl.NumSubMtls(); // Class_ID(MULTI_CLASS_ID, 0)
	if (mQuantity > 0)
	{
		mtlTree.SetMChildQuantity(mQuantity);
		for (int i=0; i<mQuantity; i++)
		{
			Mtl *subMtl = 0;
			subMtl = mtl.GetSubMtl(i);
			if (subMtl)
			{
				ConvertMaterial(*subMtl, mtlTree.GetMChild(i));
			}
		}
	}
}
예제 #18
0
AWDTexture *
AWDExporter::ExportTexture(AWD *awd, awd_ncache *ncache,Texmap* tex, Class_ID cid, int subNo, AWDMaterial * mat ) {

    AWDTexture *awd_tex;

    const char* name;
    int name_len;
    bool hasAlpha = false;

    MSTR path;

    awd_uint8 * buf;
    int buf_len;



    if (!tex) return NULL;
    if (tex->ClassID() != Class_ID(BMTEX_CLASS_ID, 0x00) ) return NULL;


    // texture already exist in cache
    awd_tex = (AWDTexture *)awd_ncache_get( ncache, tex );
    if( awd_tex ) return awd_tex;

    BitmapTex *bmptex = (BitmapTex*)tex;

    MaxSDK::AssetManagement::AssetUser asset = bmptex->GetMap();

    hasAlpha = bmptex->GetBitmap( GetStaticFrame() )->HasAlpha();

    if( !asset.GetFullFilePath(path) ) {
        fprintf( logfile, " export !asset.GetFullFilePath(path) : %i \n", asset.GetType() );
        fflush( logfile );

        //return NULL;
    }

    fprintf( logfile, " export  : %s \n", path );
    fflush( logfile );

    AWD_tex_type textype = EXTERNAL;

    if( GetIncludeMaps() &&
            asset.GetType() == MaxSDK::AssetManagement::kBitmapAsset
      ) {


        const char * dot;
        dot = strrchr(path,'.');




        if( !strcmp(dot, ".jpg")||
                !strcmp(dot, ".JPG")||
                !strcmp(dot, ".jpeg")||
                !strcmp(dot, ".JPEG")
          ) {
            textype = EMBEDDED_JPEG;
        } else if (
            !strcmp(dot, ".png")||
            !strcmp(dot, ".PNG")
        ) {
            textype = EMBEDDED_PNG;
        }



        if( textype == 0 ) {

            fprintf( logfile, " export texture : %s \n", path );
            fflush( logfile );
            // try to extract data
            Bitmap *bmp = bmptex->GetBitmap( GetStaticFrame() );

            BitmapInfo bi;

            MaxSDK::Util::Path *temppath;

            bi.SetWidth( bmp->Width() );
            bi.SetHeight( bmp->Height() );
            if( hasAlpha ) {
                bi.SetType( BMM_TRUE_32 );
                bi.SetFlags( MAP_HAS_ALPHA );
                path = "C:\\Users\\lepersp\\Desktop\\temp\\awdexporttempjpg.png";
                textype = EMBEDDED_PNG;
            } else {
                bi.SetType( BMM_TRUE_24 );
                path = "C:\\Users\\lepersp\\Desktop\\temp\\awdexporttempjpg.jpg";
                textype = EMBEDDED_JPEG;
            }

            temppath = new MaxSDK::Util::Path( path );
            bi.SetPath( *temppath );

            bmp->OpenOutput( & bi );
            bmp->Write( & bi );
            bmp->Close(& bi);

        }

        if( path != NULL ) {

            size_t result;

            int fd;
            errno_t err = _sopen_s( &fd, path, _O_RDONLY|_O_BINARY, _SH_DENYNO, _S_IREAD );

            if( err == 0 ) {

                struct stat *s;
                s = (struct stat *)malloc(sizeof(struct stat));
                fstat(fd, s);

                buf_len = s->st_size;
                buf = (awd_uint8 *) malloc (buf_len * sizeof( awd_uint8 ) );

                lseek(fd, 0, SEEK_SET);
                result = read(fd, buf, buf_len);


                if (result != buf_len) {
                    textype = EXTERNAL;
                }

                _close( fd );
            } else {
                textype = EXTERNAL;
            }
        }
    }

    name = tex->GetName();
    name_len = strlen( name );
    char* namecpy = (char*) malloc( name_len*sizeof( char ) ) ;
    strcpy( namecpy, name );

    awd_tex = new AWDTexture( textype, namecpy, name_len );

    if( textype != 0 ) {
        awd_tex->set_embed_data(buf, buf_len);
    }



    char * pathcpy = (char *) malloc( (path.length()+1) * sizeof( char ) );
    strcpy( pathcpy, path.data() );


    awd_tex->set_url( pathcpy, strlen( pathcpy ) );

    awd->add_texture( awd_tex );

    awd_ncache_add( ncache, tex, awd_tex );

    if( subNo == ID_DI ) {
        mat->set_texture( awd_tex );
        mat->alpha_blending = hasAlpha;
    }

    return awd_tex;
}
예제 #19
0
void DxStdMtl2::LoadTextureData(IHLSLCodeGenerator * codeGen)
{
	Bitmap * bmap;
	BitmapInfo stBI;

	TimeValue t = GetCOREInterface()->GetTime();
	int nWidth,nHeight;

	int numberOfTextures = elementContainer.NumberofElementsByType(EffectElements::kEleTex);
	for(int i=0; i<numberOfTextures;i++)
	{
		bool bBump;
		TextureElement * texEle = static_cast<TextureElement*>(elementContainer.GetElementByType(i,EffectElements::kEleTex));

		TSTR mapType = texEle->GetMapName();
		Texmap *texmap = codeGen->GetShaderDefinedTexmap(map,mapType.data(),bBump);

		if(texmap)
		{
			BMM_Color_64 *p;
			nWidth = nHeight = DIMDEFAULT;
			BitmapDimensions(nWidth,nHeight,texmap);
			// load and create the D3D texture;
/*			if(texmap->ClassID() == Class_ID(BMTEX_CLASS_ID, 0))
			{
				BitmapTex *pBT;
				Bitmap *pTex;
				pBT = (BitmapTex *)texmap;
				pTex = pBT->GetBitmap(t);
				if (pTex)
				{
					nWidth = getClosestPowerOf2(pTex->Width());
					nHeight = getClosestPowerOf2(pTex->Height());
				}

			}
*/				
			stBI.SetType(BMM_TRUE_32);
			stBI.SetWidth(nWidth);
			stBI.SetHeight(nHeight);        
			bmap = TheManager->Create(&stBI);

			if (bmap)
			{
//				LPDIRECT3DTEXTURE9 pRenderTex = texEle->GetD3DTexture();

				texmap->RenderBitmap(t, bmap, MAPSCALE3D * 2.0f);
				p = new BMM_Color_64[nWidth*nHeight];

				for (int y = 0; y < nHeight; y++)
					bmap->GetLinearPixels(0, y, nWidth, p + y * nWidth);
			
				if(texEle->pTex)
				{
					D3DSURFACE_DESC stLD;
					texEle->pTex->GetLevelDesc(0, &stLD);
					if (stLD.Width != nWidth || stLD.Height != nHeight)
					{
						SAFE_RELEASE(texEle->pTex);
					}

				}
				if(!texEle->pTex)
					pd3dDevice->CreateTexture(nWidth,nHeight, 0,D3DUSAGE_AUTOGENMIPMAP,	D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&texEle->pTex, NULL);

				if(texEle->pTex)
				{
					PIXELFMT *pT;
					D3DLOCKED_RECT stLR;
					texEle->pTex->LockRect(0, &stLR, 0, 0);
					pT = (PIXELFMT *)stLR.pBits;

					for (int i = 0; i < nWidth * nHeight; i++)
					{
						pT[i].r = p[i].r >> 8;
						pT[i].g = p[i].g >> 8;
						pT[i].b = p[i].b >> 8;
						pT[i].a = p[i].a >> 8;
					}
					texEle->pTex->UnlockRect(0);
				
					if(bBump && texmap->ClassID() != GNORMAL_CLASS_ID)
					{
//						LPDIRECT3DTEXTURE9 normalTex = texEle->GetD3DBumpTexture();
						
						if(texEle->pBumpTex)
						{
							D3DSURFACE_DESC stLD;
							texEle->pBumpTex->GetLevelDesc(0, &stLD);
							if (stLD.Width != nWidth || stLD.Height != nHeight)
							{
								SAFE_RELEASE(texEle->pBumpTex);
							}
						}
						if(!texEle->pBumpTex)
							pd3dDevice->CreateTexture(nWidth,nHeight, 0,D3DUSAGE_AUTOGENMIPMAP,	D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&texEle->pBumpTex, NULL);

						D3DXComputeNormalMap(texEle->pBumpTex,texEle->pTex,NULL, NULL, D3DX_CHANNEL_RED,30.0f);

						if(texEle->GetParamHandle())
						{
							pEffectParser->LoadTexture(texEle->pBumpTex, texEle->GetParameterName());
//							pEffect->SetTexture(texEle->GetParamHandle(),texEle->pBumpTex);
//							D3DXSaveTextureToFile("c:\\temp\\normal_notgnormal.dds", D3DXIFF_DDS, texEle->pBumpTex, NULL);
							SAFE_RELEASE(texEle->pBumpTex);
						}
					}
					else
					{
						if(texEle->GetParamHandle())
						{
							pEffectParser->LoadTexture(texEle->pTex, texEle->GetParameterName());
//							pEffect->SetTexture(texEle->GetParamHandle(),texEle->pTex);
//							D3DXSaveTextureToFile("c:\\temp\\normal_gnormal.dds", D3DXIFF_DDS, texEle->pTex, NULL);
							SAFE_RELEASE(texEle->pTex);
						}

					}
				}
				bmap->DeleteThis();

			}
			delete p;
		}
		else
		{
예제 #20
0
void plTextureSearch::IUpdateTextures(plTextureSearch::Update update)
{
    MtlSet mtls;
    plMtlCollector::GetMtls(&mtls, nil, plMtlCollector::kPlasmaOnly | plMtlCollector::kNoMultiMtl);

    char searchStr[256];
    GetDlgItemText(fDlg, IDC_FIND_EDIT, searchStr, sizeof(searchStr));
    strlwr(searchStr);

    HWND hList = GetDlgItem(fDlg, IDC_TEXTURE_LIST);
    ListView_DeleteAllItems(hList);

    int sizeX = -1, sizeY = -1;

    HWND hCombo = GetDlgItem(fDlg, IDC_SIZE_COMBO);

    // If we're updating the size, get whatever the user selected
    if (update == kUpdateSetSize)
    {
        int sel = ComboBox_GetCurSel(hCombo);
        uint32_t data = ComboBox_GetItemData(hCombo, sel);
        sizeX = LOWORD(data);
        sizeY = HIWORD(data);
    }

    MtlSet::iterator it = mtls.begin();
    for (; it != mtls.end(); it++)
    {
        Mtl *mtl = (*it);

        LayerSet layers;
        plMtlCollector::GetMtlLayers(mtl, layers);

        LayerSet::iterator layerIt = layers.begin();
        for (; layerIt != layers.end(); layerIt++)
        {
            plPlasmaMAXLayer *layer = (*layerIt);

            int numBitmaps = layer->GetNumBitmaps();

            for (int i = 0; i < numBitmaps; i++)
            {
                PBBitmap *pbbm = layer->GetPBBitmap(i);
                if (pbbm)
                {
                    const char *name = pbbm->bi.Filename();
                    if (name && *name != '\0')
                    {
                        char buf[256];
                        strncpy(buf, name, sizeof(buf));
                        strlwr(buf);

                        // If we don't have a search string, or we do and it was
                        // found in the texture name, add the texture to the list.
                        if (searchStr[0] == '\0' || strstr(buf, searchStr))
                        {
                            if (update == kUpdateLoadList)
                            {
                                LVITEM item = {0};
                                item.mask = LVIF_TEXT | LVIF_PARAM;
                                item.pszText = mtl->GetName();
                                item.lParam = (LPARAM)mtl;  // A little dangerous, since the user could delete this
                                int idx = ListView_InsertItem(hList, &item);

                                ListView_SetItemText(hList, idx, 1, layer->GetName());
                                ListView_SetItemText(hList, idx, 2, (char*)name);

                                // If size is uninitialized or the same as the last, keep size
                                if ((sizeX == -1 && sizeY == -1) || (sizeX == pbbm->bi.Width() && sizeY == pbbm->bi.Height()))
                                {
                                    sizeX = pbbm->bi.Width();
                                    sizeY = pbbm->bi.Height();
                                }
                                // Otherwise clear it
                                else
                                {
                                    sizeX = sizeY = 0;
                                }
                            }
                            else if (update == kUpdateReplace)
                            {
#ifdef MAXASS_AVAILABLE
                                layer->SetBitmapAssetId(gAssetID, i);
#endif

                                BitmapInfo info;
                                info.SetName(fFileName);
                                layer->SetBitmap(&info, i);
                            }
                            else if (update == kUpdateSetSize)
                            {
                                layer->SetExportSize(sizeX, sizeY);
                            }
                        }
                    }
                }
            }
        }
    }

    if (update == kUpdateLoadList)
    {
        HWND hButton = GetDlgItem(fDlg, IDC_SET_ALL_BUTTON);
        ComboBox_ResetContent(hCombo);

        // If all bitmaps are the same size, enable resizing
        if (sizeX != -1 && sizeX != 0)
        {
            sizeX = FloorPow2(sizeX);
            sizeY = FloorPow2(sizeY);

            char buf[256];

            while (sizeX >= 4 && sizeY >= 4)
            {
                sprintf(buf, "%d x %d", sizeX, sizeY);
                int idx = ComboBox_AddString(hCombo, buf);
                ComboBox_SetItemData(hCombo, idx, MAKELPARAM(sizeX, sizeY));

                sizeX >>= 1;
                sizeY >>= 1;
            }

            ComboBox_SetCurSel(hCombo, 0);

            EnableWindow(hCombo, TRUE);
            EnableWindow(hButton, TRUE);
        }
예제 #21
0
BITMAPINFO *plLayerTex::GetVPDisplayDIB(TimeValue t, TexHandleMaker& thmaker, Interval &valid, BOOL mono, BOOL forceW, BOOL forceH)
{
    // FIXME
    fTexTime = 0;//CalcFrame(t);
//  texValid = clipValid;
    BITMAPINFO *bmi = NULL;
    int xflags = 0;

    if (fBitmapPB->GetInt(kBmpApply))
    {
        float clipu = fBitmapPB->GetFloat(kBmpClipU);
        float clipv = fBitmapPB->GetFloat(kBmpClipV);
        float clipw = fBitmapPB->GetFloat(kBmpClipW);
        float cliph = fBitmapPB->GetFloat(kBmpClipH);
        int discardAlpha = fBitmapPB->GetInt(kBmpDiscardAlpha);
        int alphaAsRGB = (fBitmapPB->GetInt(kBmpRGBOutput) == 1);

        int w = fBM->Width();
        int h = fBM->Height();

        Bitmap *newBM;
        BitmapInfo bi;
        bi.SetName(_T("y8798734"));
        bi.SetType(BMM_TRUE_32);
        bi.SetFlags(MAP_HAS_ALPHA);

        if (fBitmapPB->GetInt(kBmpCropPlace) == 1)
        {
            int x0, y0, nw, nh;
            int bmw = thmaker.Size();
            int bmh = int(float(bmw)*float(h)/float(w));
            bi.SetWidth(bmw);
            bi.SetHeight(bmh);
            newBM = TheManager->Create(&bi);
            newBM->Fill(0,0,0,0);
            nw = int(float(bmw)*clipw);
            nh = int(float(bmh)*cliph);
            x0 = int(float(bmw-1)*clipu);
            y0 = int(float(bmh-1)*clipv);

            if (nw<1) nw = 1;
            if (nh<1) nh = 1;
            PixelBuf row(nw);

            Bitmap *tmpBM;
            BitmapInfo bif2;
            bif2.SetName(_T("xxxx67878"));
            bif2.SetType(BMM_TRUE_32);
            bif2.SetFlags(MAP_HAS_ALPHA);
            bif2.SetWidth(nw);
            bif2.SetHeight(nh);
            tmpBM = TheManager->Create(&bif2);
            tmpBM->CopyImage(fBM, COPY_IMAGE_RESIZE_LO_QUALITY, 0);
            BMM_Color_64*  p1 = row.Ptr();
            for (int y = 0; y<nh; y++)
            {
                tmpBM->GetLinearPixels(0,y, nw, p1);
                if (alphaAsRGB)
                {
                    for (int ix =0; ix<nw; ix++)
                        p1[ix].r = p1[ix].g = p1[ix].b = p1[ix].a;
                }
                if (discardAlpha)
                {
                    for (int ix = 0; ix < nw; ix++)
                        p1[ix].a = 0xffff;
                }
                newBM->PutPixels(x0, y+y0, nw, p1);
            }
            tmpBM->DeleteThis();
            bmi = thmaker.BitmapToDIB(newBM, fUVGen->SymFlags(), xflags, forceW, forceH);
            newBM->DeleteThis();
        }
        else
        {
            int x0,y0,nw,nh;
            x0 = int(float(w-1)*clipu);
            y0 = int(float(h-1)*clipv);
            nw = int(float(w)*clipw);
            nh = int(float(h)*cliph);
            if (nw<1) nw = 1;
            if (nh<1) nh = 1;
            bi.SetWidth(nw);
            bi.SetHeight(nh);
            PixelBuf row(nw);
            newBM = TheManager->Create(&bi);
            BMM_Color_64*  p1 = row.Ptr();
            for (int y = 0; y<nh; y++)
            {
                fBM->GetLinearPixels(x0,y+y0, nw, p1);
                if (alphaAsRGB)
                {
                    for (int ix = 0; ix < nw; ix++)
                        p1[ix].r = p1[ix].g = p1[ix].b = p1[ix].a;
                }
                if (discardAlpha)
                {
                    for (int ix = 0; ix < nw; ix++)
                        p1[ix].a = 0xffff;
                }
                newBM->PutPixels(0, y, nw, p1);
            }
            bmi = thmaker.BitmapToDIB(newBM, fUVGen->SymFlags(), xflags, forceW, forceH);
            newBM->DeleteThis();
        }
    }
    else
    {
        if (fBitmapPB->GetInt(kBmpRGBOutput) == 1)
            xflags |= EX_RGB_FROM_ALPHA;
        bmi = thmaker.BitmapToDIB(fBM, fUVGen->SymFlags(), xflags, forceW, forceH);
    }

    return bmi;
}
예제 #22
0
//DIB Methods
Value*
getViewportDib_cf(Value** arg_list, int count)
{
	check_arg_count(getViewportDib, 0, count);
	GraphicsWindow *gw = MAXScript_interface->GetActiveViewExp().getGW();
	BITMAPINFO *bmi = NULL;
	BITMAPINFOHEADER *bmih;
	BitmapInfo bi;
	Bitmap *bmp;
	int size;
	gw->getDIB(NULL, &size);
	bmi  = (BITMAPINFO *)malloc(size);
	bmih = (BITMAPINFOHEADER *)bmi;
	gw->getDIB(bmi, &size);
	bi.SetWidth((WORD)bmih->biWidth);
	bi.SetHeight((WORD)bmih->biHeight);
	bi.SetType(BMM_TRUE_32);

	UWORD  *gammatab = NULL;

	IColorCorrectionMgr* idispGamMgr = (IColorCorrectionMgr*) GetCOREInterface(COLORCORRECTIONMGR_INTERFACE);
	float gamma = 1.0f; // default if off
	if(gammaMgr.IsEnabled() && idispGamMgr)
	{
		gamma = idispGamMgr->GetGamma();
		gammatab = new UWORD[RCOLN];

		// Build gamma correction table
		if (gammatab)
			BuildGammaTab(gammatab, 1.0f/gamma, true);

		// To gamma-correct we need 64 bits resolution
		bi.SetType(BMM_TRUE_64);
	}

	bi.SetGamma(1.0f); // New bitmap will be linear

	bmp = CreateBitmapFromBitmapInfo(bi); // Make new, linear bitmap
	bmp->FromDib(bmi);

	free(bmi);    // JBW 10.7.99: missing free(), elided above I/O, not desired

	// If gamma is on:
	/* EXPLANATION:
		The code that saves a bitmap always assumes the bitmap to be saved comes from the renderer,
		and hence, is linear. Since we are grabbing off the viewport (with an embedded gamma) we
		need to linearize the bitmap first */
	if (gammatab)
	{
		// We still want this to be SAVED with a gamma. What gamma MaxScript will save
		// this with (by default) is defined by the gamma of the BitmapInfo bi's gamma
		// And we intentionally want it to look like it was displayed - hence we use the
		// display gamma!!
		bi.SetGamma(gamma);

		int h = bmp->Height();
		int w = bmp->Width();

		BMM_Color_64 *pixelrow = (BMM_Color_64 *)LocalAlloc(LPTR,w*sizeof(BMM_Color_64));

		if (pixelrow) 
		{
			for (int iy = 0; iy < h; iy++) {
				bmp->GetPixels(0, iy, w, pixelrow);
				for (int ix = 0; ix < w; ix++) {
					
					pixelrow[ix].r = gammatab[UWORD(pixelrow[ix].r) >> RCSH16];
					pixelrow[ix].g = gammatab[UWORD(pixelrow[ix].g) >> RCSH16];
					pixelrow[ix].b = gammatab[UWORD(pixelrow[ix].b) >> RCSH16];
				}
				bmp->PutPixels(0, iy, w, pixelrow);
			}
			LocalFree(pixelrow);
		}

		delete [] gammatab;
	}

	return new MAXBitMap(bi, bmp);
}
예제 #23
0
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CStravaganzaMaxTools
//
//  - prototype : bool BuildShaders()
//
//  - Purpose   : Builds the shader list from MAX's materials.
//                Preview mode requires texture files to be stored with full
//                path in order to load them. When we export, we only store the
//                filename. Another thing is that in the export mode, we copy
//                all textures into the path specified by the user if that
//                option is checked.
//
// -----------------------------------------------------------------------------
bool CStravaganzaMaxTools::BuildShaders()
{
	std::vector<Mtl*>::iterator it;

	assert(m_vecShaders.empty());

	if(!m_bPreview && m_bCopyTextures && m_strTexturePath == "")
	{
		CLogger::NotifyWindow("Textures won't be copied\nSpecify a valid output texture path first");
	}

	LOG.Write("\n\n-Building shaders: ");

	for(it = m_vecMaterials.begin(); it != m_vecMaterials.end(); ++it)
	{
		Mtl* pMaxMaterial = *it;
		assert(pMaxMaterial);

		LOG.Write("\n    %s", pMaxMaterial->GetName().data());
		CShaderStandard* pShaderStd = new CShaderStandard;
		pShaderStd->SetName(pMaxMaterial->GetName().data());

		// Properties

		StdMat2 *pMaxStandardMtl = NULL;
		StdMat2 *pMaxBakedMtl    = NULL;

		float fAlpha;

		if(pMaxMaterial->ClassID() == Class_ID(DMTL_CLASS_ID, 0))
		{
			pMaxStandardMtl = (StdMat2 *)pMaxMaterial;
		}
		else if(pMaxMaterial->ClassID() == Class_ID(BAKE_SHELL_CLASS_ID, 0))
		{
			pMaxStandardMtl = (StdMat2 *)pMaxMaterial->GetSubMtl(0);
			pMaxBakedMtl    = (StdMat2 *)pMaxMaterial->GetSubMtl(1);
		}

		if(pMaxStandardMtl)
		{
			// Standard material

			fAlpha = pMaxStandardMtl->GetOpacity(0);

			Shader* pMaxShader = pMaxStandardMtl->GetShader();

			CVector4 v4Specular = ColorToVector4(pMaxStandardMtl->GetSpecular(0), 0.0f) * pMaxShader->GetSpecularLevel(0, 0);

			pShaderStd->SetAmbient  (ColorToVector4(pMaxStandardMtl->GetAmbient(0),  0.0f));
			pShaderStd->SetDiffuse  (ColorToVector4(pMaxStandardMtl->GetDiffuse(0),  fAlpha));
			pShaderStd->SetSpecular (v4Specular);
			pShaderStd->SetShininess(pMaxShader->GetGlossiness(0, 0) * 128.0f);

			if(pMaxStandardMtl->GetTwoSided() == TRUE)
			{
				pShaderStd->SetTwoSided(true);
			}

			// Need to cast to StdMat2 in order to get access to IsFaceted().
			// ¿Is StdMat2 always the interface for standard materials?
			if(((StdMat2*)pMaxStandardMtl)->IsFaceted())
			{
				pShaderStd->SetFaceted(true);
			}

			if(pMaxStandardMtl->GetWire() == TRUE)
			{
				pShaderStd->SetPostWire(true);
				pShaderStd->SetWireLineThickness(pMaxStandardMtl->GetWireSize(0));
			}
		}
		else
		{
			// Material != Standard

			fAlpha = 1.0f; // pMaxMaterial->GetXParency();

			pShaderStd->SetAmbient  (ColorToVector4(pMaxMaterial->GetAmbient(),  0.0f));
			pShaderStd->SetDiffuse  (ColorToVector4(pMaxMaterial->GetDiffuse(),  fAlpha));
			pShaderStd->SetSpecular (CVector4(0.0f, 0.0f, 0.0f, 0.0f));
			pShaderStd->SetShininess(0.0f);
		}

		// Layers

		if(!pMaxStandardMtl)
		{
			m_vecShaders.push_back(pShaderStd);
			continue;
		}

		bool bDiffuseMap32Bits = false;
		StdMat2 *pStandardMtl;

		for(int i = 0; i < 3; i++)
		{
			int nMap;

			pStandardMtl = pMaxStandardMtl;

			// 0 = diffuse, 1 == bump, 2 = lightmap (self illumination slot) or envmap (reflection slot)

			if(i == 0)
			{
				nMap = ID_DI;
			}
			else if(i == 1)
			{
				nMap = ID_BU;

				// If its a baked material, get the bump map from there

				if(pMaxBakedMtl)
				{
					pStandardMtl = pMaxBakedMtl;
				}
			}
			else if(i == 2)
			{
				bool bBaked = false;

				// If its a baked material, get the map2 (lightmap) from there

				if(pMaxBakedMtl)
				{
					if(pMaxBakedMtl->GetMapState(ID_SI) == MAXMAPSTATE_ENABLED)
					{
						bBaked       = true;
						nMap         = ID_SI;
						pStandardMtl = pMaxBakedMtl;
					}
				}

				if(!bBaked)
				{
					if(pStandardMtl->GetMapState(ID_SI) == MAXMAPSTATE_ENABLED)
					{
						nMap = ID_SI;
					}
					else
					{
						nMap = ID_RL;
					}
				}
			}

			// Check validity

			if(pStandardMtl->GetMapState(nMap) != MAXMAPSTATE_ENABLED)
			{
				if(i == 0)
				{
					LOG.Write("\n        No diffuse. Skipping.");
					break;
				}

				continue;
			}

			Texmap* pMaxTexmap = pStandardMtl->GetSubTexmap(nMap);

			if(!pMaxTexmap)
			{
				if(i == 0)
				{
					LOG.Write("\n        No diffuse. Skipping.");
					break;
				}

				continue;
			}

			// Get texmaps

			std::vector<std::string> vecTextures, vecPaths;

			CShaderStandard::SLayerInfo  layerInfo;
			CShaderStandard::SBitmapInfo bitmapInfo;

			if(pMaxTexmap->ClassID() == Class_ID(BMTEX_CLASS_ID, 0))
			{
				BitmapTex* pMaxBitmapTex = (BitmapTex*)pMaxTexmap;
				Bitmap*    pMaxBitmap    = pMaxBitmapTex->GetBitmap(SECONDS_TO_TICKS(m_fStartTime));
				StdUVGen*  pMaxUVGen     = pMaxBitmapTex->GetUVGen();

				if(!pMaxBitmap)
				{
					if(i == 0)
					{
						LOG.Write("\n        Invalid diffuse. Skipping.");
						break;
					}
					continue;
				}

				assert(pMaxUVGen);

				BitmapInfo bi = pMaxBitmap->Storage()->bi;

				// bi.Name() returns the full path
				// bi.Filename() returns just the filename

				vecTextures.push_back(bi.Filename());
				vecPaths.   push_back(bi.Name());

				LOG.Write("\n        Bitmap %s", vecTextures[0].data());

				// Check if diffuse texture has alpha channel

				if(i == 0)
				{
					CBitmap    bitmap;
					CInputFile bitmapFile;

					if(!bitmapFile.Open(bi.Name(), false))
					{
						CLogger::NotifyWindow("WARNING - CStravaganzaMaxTools::BuildShaders():\nUnable to load file %s", bi.Name());
					}
					else
					{
						if(!bitmap.Load(&bitmapFile, GetFileExt(bi.Name())))
						{
							CLogger::NotifyWindow("WARNING - CStravaganzaMaxTools::BuildShaders():\nUnable to load bitmap %s", bi.Name());
						}
						else
						{
							if(bitmap.GetBpp() == 32)
							{
								bDiffuseMap32Bits = true;
								LOG.Write(" (with alpha channel)");
							}
							bitmap.Free();
						}
						bitmapFile.Close();
					}
				}

				// Ok, copy properties

				layerInfo.texInfo.bLoop        = false;
				layerInfo.texInfo.eTextureType = UtilGL::Texturing::CTexture::TEXTURE2D;

				bitmapInfo.strFile         = m_bPreview ? bi.Name() : bi.Filename();
				bitmapInfo.bTile           = ((pMaxUVGen->GetTextureTiling() & (U_WRAP | V_WRAP)) == (U_WRAP | V_WRAP)) ? true : false;
				bitmapInfo.fSeconds        = 0.0f;
				bitmapInfo.bForceFiltering = false;
				bitmapInfo.eFilter         = UtilGL::Texturing::FILTER_TRILINEAR; // won't be used (forcefiltering = false)
				
				layerInfo.texInfo.m_vecBitmaps.push_back(bitmapInfo);

				layerInfo.eTexEnv          = nMap == ID_RL ? CShaderStandard::TEXENV_ADD : CShaderStandard::TEXENV_MODULATE;
				layerInfo.eUVGen           = pMaxUVGen->GetCoordMapping(0) == UVMAP_SPHERE_ENV ? CShaderStandard::UVGEN_ENVMAPPING : CShaderStandard::UVGEN_EXPLICITMAPPING;
				layerInfo.uMapChannel      = pMaxUVGen->GetMapChannel();
				layerInfo.v3ScrollSpeed    = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3RotationSpeed  = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3ScrollOffset   = CVector3(pMaxUVGen->GetUOffs(0), pMaxUVGen->GetVOffs(0), 0.0f);
				layerInfo.v3RotationOffset = CVector3(pMaxUVGen->GetUAng(0),  pMaxUVGen->GetVAng(0),  pMaxUVGen->GetWAng(0));
			}
			else if(pMaxTexmap->ClassID() == Class_ID(ACUBIC_CLASS_ID, 0))
			{
				ACubic*       pMaxCubic  = (ACubic*)pMaxTexmap;
				IParamBlock2* pBlock     = pMaxCubic->pblock;
				Interval      validRange = m_pMaxInterface->GetAnimRange();

				for(int nFace = 0; nFace < 6; nFace++)
				{
					int nMaxFace;

					switch(nFace)
					{
					case 0: nMaxFace = 3; break;
					case 1: nMaxFace = 2; break;
					case 2: nMaxFace = 1; break;
					case 3: nMaxFace = 0; break;
					case 4: nMaxFace = 5; break;
					case 5: nMaxFace = 4; break;
					}

					TCHAR *name;
					pBlock->GetValue(acubic_bitmap_names, TICKS_TO_SECONDS(m_fStartTime), name, validRange, nMaxFace);

					vecPaths.push_back(name);

					CStr path, file, ext;
					SplitFilename(CStr(name), &path, &file, &ext);

					std::string strFile = std::string(file.data()) + ext.data();

					vecTextures.push_back(strFile);

					bitmapInfo.strFile         = m_bPreview ? name : strFile;
					bitmapInfo.bTile           = false;
					bitmapInfo.fSeconds        = 0.0f;
					bitmapInfo.bForceFiltering = false;
					bitmapInfo.eFilter         = UtilGL::Texturing::FILTER_TRILINEAR;
					
					layerInfo.texInfo.m_vecBitmaps.push_back(bitmapInfo);
				}

				layerInfo.texInfo.bLoop        = false;
				layerInfo.texInfo.eTextureType = UtilGL::Texturing::CTexture::TEXTURECUBEMAP;

				layerInfo.eTexEnv          = nMap == ID_RL ? CShaderStandard::TEXENV_ADD : CShaderStandard::TEXENV_MODULATE;
				layerInfo.eUVGen           = CShaderStandard::UVGEN_ENVMAPPING;
				layerInfo.uMapChannel      = 0;
				layerInfo.v3ScrollSpeed    = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3RotationSpeed  = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3ScrollOffset   = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3RotationOffset = CVector3(0.0f, 0.0f, 0.0f);
			}
			else
			{
				if(i == 0)
				{
					LOG.Write("\n        No diffuse. Skipping.");
					break;
				}
				continue;
			}

			if(!m_bPreview && m_bCopyTextures && m_strTexturePath != "")
			{
				for(int nTex = 0; nTex != vecTextures.size(); nTex++)
				{
					// Copy textures into the specified folder

					std::string strDestPath = m_strTexturePath;

					if(strDestPath[strDestPath.length() - 1] != '\\')
					{
						strDestPath.append("\\", 1);
					}

					strDestPath.append(vecTextures[nTex]);

					if(!CopyFile(vecPaths[nTex].data(), strDestPath.data(), FALSE))
					{
						CLogger::NotifyWindow("Unable to copy %s to\n%s", vecPaths[i], strDestPath.data());
					}
				}
			}

			if(layerInfo.eUVGen == CShaderStandard::UVGEN_ENVMAPPING && i == 1)
			{
				CLogger::NotifyWindow("%s : Bump with spheremapping not supported", pShaderStd->GetName().data());
			}
			else
			{
				// Add layer

				switch(i)
				{
				case 0: pShaderStd->SetLayer(CShaderStandard::LAYER_DIFF, layerInfo); break;
				case 1: pShaderStd->SetLayer(CShaderStandard::LAYER_BUMP, layerInfo); break;
				case 2: pShaderStd->SetLayer(CShaderStandard::LAYER_MAP2, layerInfo); break;
				}
			}
		}

		// ¿Do we need blending?

		if(ARE_EQUAL(fAlpha, 1.0f) && !bDiffuseMap32Bits)
		{
			pShaderStd->SetBlendSrcFactor(UtilGL::States::BLEND_ONE);
			pShaderStd->SetBlendDstFactor(UtilGL::States::BLEND_ZERO);
		}
		else
		{
			pShaderStd->SetBlendSrcFactor(UtilGL::States::BLEND_SRCALPHA);
			pShaderStd->SetBlendDstFactor(UtilGL::States::BLEND_INVSRCALPHA);
		}

		// Add shader

		m_vecShaders.push_back(pShaderStd);
	}

	return true;
}