Start a new topic

Creator Script: Tip for using mgFind in your script to select nodes for processing

Original Post by: SteveThompson Fri Dec 2 21:41:17 2011

During the OpenFlight User Group Meeting at I/ITSEC on 11/30/2011, tips and tricks were presented for using OpenFlight Script and Creator Script.

Here is a script presented that shows how to use the little known API function mgFind in your Creator Script to select nodes to process (in this case by the Calculate Shading command).

# this walk function for mgFind is used to select

# just polygons that are "flat" shaded

def IsUnshadedFace (db, parent, node, userData):

if (mgGetCode(node) == fltPolygon):

num,code,mode = mgGetAttList (node, fltGcLightMode)

if (mode == 0):

# tell mgFind to include this node in the list it returns

return MG_TRUE

# tell mgFind to NOT include this node in the list it returns

return MG_FALSE

db = mgGetCurrentDb()

# use mgFind to build a node list, according to IsUnshadedFace

# only polygons that are "flat" shaded will be included in the list

faceList = mgFind (db, IsUnshadedFace, None, 0)

# select all the "flat" shaded polygons found

mgSelectList (faceList)

# now invoke Calculate Shading to shade the "flat" shaded polygons

paramBlock = mgGetParamBlock ("Calculate Shading")

mgParamSet (paramBlock, "Angular Tolerance", 89)

mgParamSet (paramBlock, "Sampling Tolerance", 0.01)

mgParamSet (paramBlock, "Shading Model", "Lit")

mgParamSet (paramBlock, "Triangle Area Weighting", MG_FALSE)

mgParamSet (paramBlock, "Update Vertex Colors", MG_TRUE)

mgParamSet (paramBlock, "Update Vertex Normals", MG_TRUE)

mgParamSet (paramBlock, "Use Face Color Intensities", MG_TRUE)

mgExecute ("Calculate Shading", paramBlock)

Login to post a comment