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 (baseIndex, bumpIndex):
global materialMap
if ((baseIndex,bumpIndex) in materialMap):
matIndex = materialMap[(baseIndex,bumpIndex)]
return matIndex
print baseIndex, bumpIndex
mat, matIndex = mgNewMaterial (db, None)
mgSetAttList (mat, fltMatType, 1)
mgSetMatTextureLayer (mat, fltDiffuseExLayer1, baseIndex, 0)
mgSetMatTextureLayer (mat, fltBumpMapExTexture, bumpIndex, 1)
mgSetAttList (mat, fltBumpMapExTangentLayer, 7)
materialMap[(baseIndex,bumpIndex)] = matIndex
print "Creating Extended Material: ", matIndex
return matIndex
def ProcessAllPolygons (db, parent, rec, data):
if (mgGetCode (rec) == fltPolygon):
count, code, baseIndex, code2, bumpIndex = mgGetAttList (rec, fltPolyTexture, fltLayerTexture1)
matIndex = GetMatchingMaterial (baseIndex, bumpIndex)
mgSetAttList (rec, fltPolyMaterial, matIndex)
return MG_TRUE
mgWalk (db, None, ProcessAllPolygons, None, MWALK_NOREADONLY)