Standards Forum

 

Login Register    
Creator Script: Tip for using mgFind in your script to select nodes for processing
Posted: 02 December 2011 04:41 PM  
Moderator
RankRankRankRank
Total Posts:  604
Joined  2008-07-02

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 (dbparentnodeuserData):
    if (
mgGetCode(node) == fltPolygon):
        
num,code,mode mgGetAttList (nodefltGcLightMode)
        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 (dbIsUnshadedFaceNone0)

# 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