Peer-to-Peer Forum

2 of 2
2

Login Register    
Are Extended Materials Used?
Posted: 16 January 2012 04:27 PM   [ # 16 ]  
Moderator
RankRankRankRank
Total Posts:  386
Joined  2008-07-03

Hey BobtheBuilder,

I think I came up with a script that will help you out. It turns our there is a handy function to set up an extended material’s textures. This was the last piece that we needed to convert regular polygon texture’s to extended materials with these textures.

The following script assumes that you have a base texture at layer 0 and a bump texture at layer 1. It will loop over all polygons in the database that are not read only, and make an extended material for it. It will re-use the same extended material for polygons that have the same textures on them. Check it out and see if it helps.

db mgGetCurrentDb()
materialMap {}

def GetMatchingMaterial 
(baseIndexbumpIndex):
    global 
materialMap
    
if ((baseIndex,bumpIndexin materialMap):
        
matIndex materialMap[(baseIndex,bumpIndex)]        
        
return matIndex
    
    
print baseIndexbumpIndex
    mat
matIndex mgNewMaterial (dbNone)
    
mgSetAttList (matfltMatType1)
    
mgSetMatTextureLayer (matfltDiffuseExLayer1baseIndex0)
    
mgSetMatTextureLayer (matfltBumpMapExTexturebumpIndex1)
    
mgSetAttList (matfltBumpMapExTangentLayer7)
    
materialMap[(baseIndex,bumpIndex)matIndex
    
print "Creating Extended Material: "matIndex
    
return matIndex
    
def ProcessAllPolygons 
(dbparentrecdata):
    if (
mgGetCode (rec) == fltPolygon):
        
countcodebaseIndexcode2bumpIndex mgGetAttList (recfltPolyTexturefltLayerTexture1)
        
matIndex GetMatchingMaterial (baseIndexbumpIndex)
        
mgSetAttList (recfltPolyMaterialmatIndex)
    return 
MG_TRUE
    
mgWalk 
(dbNoneProcessAllPolygonsNoneMWALK_NOREADONLY
 
Posted: 16 January 2012 04:40 PM   [ # 17 ]  
Newbie
Rank
Total Posts:  9
Joined  2008-12-08

Cool! Thanks, Chris! I’ll give it a whirl in the morning. I recognise some of this as the route we were trying the other day. Should make life much easier!

 
Posted: 16 January 2012 04:53 PM   [ # 18 ]  
Moderator
RankRankRankRank
Total Posts:  386
Joined  2008-07-03

Try it out on a single database first by running it thorugh the OpenFlight Script editor. If it seems to work well for you, then you can use Batch Run Script to apply it to all of your files at once. (just make sure you tell batch run script to make backup files for you) smile

 



2 of 2
2