int CreateBrushVersionOfWorldVertexTransitionMaterial( int originalTexInfo ) { // Don't make cubemap tex infos for nodes if ( originalTexInfo == TEXINFO_NODE ) return originalTexInfo; texinfo_t *pTexInfo = &texinfo[originalTexInfo]; dtexdata_t *pTexData = GetTexData( pTexInfo->texdata ); const char *pOriginalMaterialName = TexDataStringTable_GetString( pTexData->nameStringTableID ); // Get out of here if the originalTexInfo is already a patched wvt material if ( Q_stristr( pOriginalMaterialName, "_wvt_patch" ) ) return originalTexInfo; char patchedMaterialName[1024]; GeneratePatchedMaterialName( pOriginalMaterialName, patchedMaterialName, 1024 ); // Warning( "GeneratePatchedMaterialName: %s %s\n", pMaterialName, patchedMaterialName ); // Make sure the texdata doesn't already exist. int nTexDataID = FindTexData( patchedMaterialName ); bool bHasTexData = (nTexDataID != -1); if( !bHasTexData ) { // Create the new vmt material file CreateWorldVertexTransitionPatchedMaterial( pOriginalMaterialName, patchedMaterialName ); // Make a new texdata nTexDataID = AddCloneTexData( pTexData, patchedMaterialName ); } Assert( nTexDataID != -1 ); texinfo_t newTexInfo; newTexInfo = *pTexInfo; newTexInfo.texdata = nTexDataID; int nTexInfoID = -1; // See if we need to make a new texinfo bool bHasTexInfo = false; if( bHasTexData ) { nTexInfoID = FindTexInfo( newTexInfo ); bHasTexInfo = (nTexInfoID != -1); } // Make a new texinfo if we need to. if( !bHasTexInfo ) { nTexInfoID = texinfo.AddToTail( newTexInfo ); } Assert( nTexInfoID != -1 ); return nTexInfoID; }
//----------------------------------------------------------------------------- // Create a VMT to override the specified texinfo which references the cubemap entity at the specified origin. // Returns the index of the new (or preexisting) texinfo referencing that VMT. // // Also adds the new cubemap VTF filename to s_DefaultCubemapNames so it can copy the // default (skybox) cubemap into this file so the cubemap doesn't have the pink checkerboard at // runtime before they run buildcubemaps. //----------------------------------------------------------------------------- static int Cubemap_CreateTexInfo( int originalTexInfo, int origin[3] ) { // Don't make cubemap tex infos for nodes if ( originalTexInfo == TEXINFO_NODE ) return originalTexInfo; texinfo_t *pTexInfo = &texinfo[originalTexInfo]; dtexdata_t *pTexData = GetTexData( pTexInfo->texdata ); const char *pMaterialName = TexDataStringTable_GetString( pTexData->nameStringTableID ); if ( g_IsCubemapTexData[pTexInfo->texdata] ) { Warning("Multiple references for cubemap on texture %s!!!\n", pMaterialName ); return originalTexInfo; } // Get out of here if the originalTexInfo is already a generated material for this position. char pStringToSearchFor[512]; Q_snprintf( pStringToSearchFor, 512, "_%d_%d_%d", origin[0], origin[1], origin[2] ); if ( Q_stristr( pMaterialName, pStringToSearchFor ) ) return originalTexInfo; // Package up information needed to generate patch names PatchInfo_t info; info.m_pMapName = mapbase; info.m_pOrigin[0] = origin[0]; info.m_pOrigin[1] = origin[1]; info.m_pOrigin[2] = origin[2]; // Generate the name of the patched material char pGeneratedTexDataName[1024]; GeneratePatchedName( pMaterialName, info, true, pGeneratedTexDataName, 1024 ); // Make sure the texdata doesn't already exist. int nTexDataID = FindTexData( pGeneratedTexDataName ); bool bHasTexData = (nTexDataID != -1); if( !bHasTexData ) { // Generate the new "$envmap" texture name. char pTextureName[1024]; GeneratePatchedName( "c", info, false, pTextureName, 1024 ); // Hook the texture into the material and all dependent materials // but if no hooking was necessary, exit out if ( !PatchEnvmapForMaterialAndDependents( pMaterialName, info, pTextureName ) ) return originalTexInfo; // Store off the name of the cubemap that we need to create since we successfully patched char pFileName[1024]; int nLen = Q_snprintf( pFileName, 1024, "materials/%s.vtf", pTextureName ); int id = s_DefaultCubemapNames.AddToTail(); s_DefaultCubemapNames[id] = new char[ nLen + 1 ]; strcpy( s_DefaultCubemapNames[id], pFileName ); // Make a new texdata nTexDataID = AddCloneTexData( pTexData, pGeneratedTexDataName ); g_IsCubemapTexData[nTexDataID] = true; } Assert( nTexDataID != -1 ); texinfo_t newTexInfo; newTexInfo = *pTexInfo; newTexInfo.texdata = nTexDataID; int nTexInfoID = -1; // See if we need to make a new texinfo bool bHasTexInfo = false; if( bHasTexData ) { nTexInfoID = FindTexInfo( newTexInfo ); bHasTexInfo = (nTexInfoID != -1); } // Make a new texinfo if we need to. if( !bHasTexInfo ) { nTexInfoID = texinfo.AddToTail( newTexInfo ); } Assert( nTexInfoID != -1 ); return nTexInfoID; }