from SceneGraphUtilities import CollectLeafNodes
from ScriptRunner import ScriptRunner
import ModelIO
class GenerateAmbientOcclusion( ScriptRunner ):
def __init__( self, scriptName, args ):
ScriptRunner.__init__( self, scriptName, args )
def Main( self ):
"""
This script reads a simple scene and computes ambient occlusion.
"""
exampleFile = 'C:/Example.a3s'
resultFile = 'C:/Result.a3s'
raysPerSample = 128
resolutionFactor = 1.0
shadowSpread = 180.0
useDropOff = False
dropOffDistance = 5.0
dropOffRate = 1.0
chordLengthParameters = False
selfShadowCorrection = 0.01
BlurAmount = 5
minTileSize = 6
useEnvFloor = True
self.sendMessageSync( 'APPLICATION_LOAD_SCENE',
( exampleFile, ),
userTimeout = 3600 )
self.assert_( self.document() is not None )
nodeIds = None
if self.document().has(ModelIO.id) :
nodeIds = tuple(CollectLeafNodes(
self.document().get( ModelIO.id ).root,
[lambda node: node.getIsVisible()], True ))
if nodeIds :
self.sendMessageSync( 'MATERIAL_COMPUTE_OCCLUSION',
( nodeIds,
raysPerSample,
resolutionFactor,
shadowSpread,
useDropOff,
dropOffDistance,
dropOffRate,
chordLengthParameters,
selfShadowCorrection,
BlurAmount,
minTileSize,
useEnvFloor,
),
userTimeout = 36000 )
self.sendMessageSync( 'STATUSBAR_SET_TEXT',
(("Saving scene with occlusion to %s" % (resultFile)),))
self.sendMessageSync( 'APPLICATION_SAVE_SCENE', ( resultFile, ) )
def instantiate( scriptName, args ):
return GenerateAmbientOcclusion( scriptName, args )