Exemplo n.º 1
0
def main(argv):
    """docstring for main"""
    optlist, args = getopt.getopt(argv, "", ['runningmode='])

    runningmode = "global"
    for o, a in optlist:
        if o == "--runningmode":
            runningmode = a

    runmode = getRunMode(runningmode)
    print runmode

    try:
        M_PI = 3.14159265358979323846

        bmh = createNewManagerHandle()
        
        apiCall( ILBSetLogTarget(ILB_LT_ERROR, ILB_LS_STDERR, None) )
        
        apiCall( ILBSetLogTarget(ILB_LT_INFO, ILB_LS_DEBUG_OUTPUT, None) )
        
        config = ConfigParser.ConfigParser()
        config.read('config.ini')
        configItems = {}
        for item in config.items('BeastPythonExamples'):
            configItems[item[0]] = item[1]

        # Setup our beast manager
        beastCacheFolder = os.path.normpath(configItems['beast_cache'])
        beastBinFolder = os.path.normpath(configItems['beast_bin'])
        beastDataFolder = os.path.normpath(configItems['beast_data'])


        dir = beastCacheFolder + r'/temp/cache'

        if runmode == RM_CLEAR:
            print "Clearing cache..."
            apiCall( ILBCreateManager(dir, ILB_CS_GLOBAL, bmh) )
            apiCall( ILBClearCache(bmh) )
            print "Done!"
        elif runmode == RM_GLOBAL:
            print "Creating a global cache!"
            apiCall( ILBCreateManager(dir, ILB_CS_GLOBAL, bmh) )
        elif runmode == RM_LOCAL:
            print "createing a local cache!"
            apiCall( ILBCreateManager(dir, ILB_CS_LOCAL, bmh) )
        else:
            print "Invalid runmode"
        
        apiCall( ILBSetBeastPath(bmh, beastBinFolder) )

        sphereName = "Sphere"
        floorName = "Floor"
        sphereMatName = "SphereMaterial"
        floorMatName = "FloorMaterial"

        sphereMesh = createNewMeshHandle()
        if not findCachedMesh(bmh, sphereName, sphereMesh):
           sphereMesh = primitives.createSphere(bmh, sphereName, sphereMatName, 600, 400, None) 

        floorMesh = createNewMeshHandle()
        if not findCachedMesh(bmh, floorName, floorMesh):
           floorMesh = primitives.createPlaneSimple(bmh, floorName, floorMatName) 

        texName = "Mandelbrot"
        texture = createNewTextureHandle()
        if not findCachedTexture(bmh, texName, texture):
            texture = textures.createMandelbrotTexture(bmh, texName, ColorRGB(1.0, 0.7, 0.7), 1000, 1000)


        scene = createNewSceneHandle()
        sceneName = "SimpleScene"
        apiCall( ILBBeginScene(bmh, sceneName, scene) )

        floorInstance = createNewInstanceHandle()
        floorTrans = vecmath.scaleTranslation(Vec3(10.0, 1.0, 10.0), Vec3(0.0, -5.0, 0.0))
        apiCall( ILBCreateInstance(scene, floorMesh, "FloorInstance", floorTrans, floorInstance))


        SPHERES = 5
        spherePosRadius = 5.0
        sphereRad = 2.0
        sphereInstances = []

        for i in range(SPHERES):
            angle = (M_PI * 2.0 * i) / SPHERES
            x = math.cos(angle) * spherePosRadius
            z = math.sin(angle) * spherePosRadius

            trans = vecmath.scaleTranslation(Vec3(sphereRad, sphereRad, sphereRad), 
                                     Vec3(x, -3.0, z))
            tempInstance = createNewInstanceHandle()
            sphereName = 'SphereInstance_' + str(i)
            apiCall( ILBCreateInstance(scene, sphereMesh, sphereName, trans, tempInstance) )


        # create the floor material
        floorMat = createNewMaterialHandle()
        primitives.apiCall( ILBCreateMaterial(scene, floorMatName, floorMat) )
        primitives.apiCall( ILBSetMaterialTexture(floorMat, ILB_CC_DIFFUSE, texture) )

        # create sphere material
        sphereMat = createNewMaterialHandle()
        apiCall( ILBCreateMaterial(scene, sphereMatName, sphereMat) )
        apiCall( ILBSetMaterialColor(sphereMat, ILB_CC_DIFFUSE, ColorRGBA(0.3, 0.3, 0.3, 1.0)) )
        apiCall( ILBSetMaterialColor(sphereMat, ILB_CC_SPECULAR, ColorRGBA(1.0, 1.0, 1.0, 1.0)) )
        apiCall( ILBSetMaterialScale(sphereMat, ILB_CC_REFLECTION, 0.1) )
        apiCall( ILBSetMaterialScale(sphereMat, ILB_CC_SHININESS, 15.0) )

        light = createNewLightHandle()
        apiCall( ILBCreateDirectionalLight(scene, 
                                           "Sun", 
                                           vecmath.directionalLightOrientation(Vec3(1.0, -1.0, -1.0)),
                                           ColorRGB(1.0, 1.0, 0.8),
                                           light))
        apiCall( ILBSetCastShadows(light, True) )
        apiCall( ILBSetShadowSamples(light, 32) )
        apiCall( ILBSetShadowAngle(light, 0.1) )


        skylight = createNewLightHandle()
        apiCall( ILBCreateSkyLight( scene, 'SkyLight', vecmath.identity(), ColorRGB(0.21, 0.21, 0.3), skylight) )


        camera = createNewCameraHandle()
        apiCall( ILBCreatePerspectiveCamera(scene, 
                 "Camera", 
                 vecmath.setCameraMatrix(Vec3(0.3, 0.5, 15.0), Vec3(0.1, -0.3, -1.0), Vec3(0.0, 1.0, 0.0)),
                 camera) )

        # Finalize the scene
        apiCall(ILBEndScene(scene));

        job = createNewJobHandle()
        apiCall( ILBCreateJob( bmh, 'TestJob', scene, beastDataFolder + r'/data/simpleFG.xml', job ) )

        fullShadingPass = createNewRenderPassHandle()
        apiCall( ILBCreateFullShadingPass(job, 'fullShading', fullShadingPass) )

        cameraTarget = createNewTargetHandle()
        apiCall( ILBCreateCameraTarget( job, 'cameraTarget', camera, 640, 480, cameraTarget ) )

        apiCall( ILBAddPassToTarget( cameraTarget, fullShadingPass ) )

        if not renderJob( job ):
            print "render error occured"

    except BeastPythonException, (instance):
        print "exception: " + str(instance.parameter)
        ex = instance.parameter
        errorString = createNewStringHandle()
        extendedError = createNewStringHandle()
        ILBErrorToString(ex, errorString)
        ILBGetExtendErrorInformation(extendedError)
        print "Beast API error"
        print "Error: " + convertStringHandle(errorString)
        print "Info: " + convertStringHandle(extendedError)
Exemplo n.º 2
0
        # Setup our beast manager
        beastCacheFolder = os.path.normpath(configItems['beast_cache'])
        beastBinFolder = os.path.normpath(configItems['beast_bin'])
        beastDataFolder = os.path.normpath(configItems['beast_data'])
        apiCall( ILBCreateManager( beastCacheFolder + r'/temp/rnm', ILB_CS_LOCAL, bmh) )
        
        # Set the path to the Beast binaries
        apiCall( ILBSetBeastPath(bmh, beastBinFolder) )

        # Waste the cache from previous runs if present
        apiCall( ILBClearCache(bmh) )

        # Create ball and a plane meshes
        sphereMatName = 'SphereMaterial'
        boxMatName = 'boxMaterial'
        sphereMesh = primitives.createSphere(bmh, 'Sphere', sphereMatName, 32, 32)
        cornellMesh = primitives.createCornellBox(bmh, "Cornell", boxMatName)
        
        # Create a scene
        scene = createNewSceneHandle()
        apiCall( ILBBeginScene(bmh, 'BakingScene', scene) )
        

        # create an instance of the Cornell Box
        cornellInstance = createNewInstanceHandle()
        cornellTrans = vecmath.scaleTranslation(Vec3(10.0, 10.0, 10.0), Vec3(0.0, 0.0, 0.0))

        apiCall( ILBCreateInstance(scene, cornellMesh, "CornellInstance", cornellTrans, cornellInstance))


        # create area light
Exemplo n.º 3
0
def main(argv):
    """docstring for main"""
    try:
        M_PI = 3.14159265358979323846

        bmh = createNewManagerHandle()
        
        apiCall( ILBSetLogTarget(ILB_LT_ERROR, ILB_LS_STDERR, None) )
        
        apiCall( ILBSetLogTarget(ILB_LT_INFO, ILB_LS_DEBUG_OUTPUT, None) )
        
        config = ConfigParser.ConfigParser()
        config.read('config.ini')
        configItems = {}
        for item in config.items('BeastPythonExamples'):
            configItems[item[0]] = item[1]

        # Setup our beast manager
        beastCacheFolder = os.path.normpath(configItems['beast_cache'])
        beastBinFolder = os.path.normpath(configItems['beast_bin'])
        beastDataFolder = os.path.normpath(configItems['beast_data'])

        dir = beastCacheFolder + r'/temp/baking'
        apiCall( ILBCreateManager(dir, ILB_CS_LOCAL, bmh) )
        
        # Set the path to the Beast binaries
        apiCall( ILBSetBeastPath(bmh, beastBinFolder) )

        # Waste the cache from previous runs if present
        apiCall( ILBClearCache(bmh) )

        sphereName = "Sphere"
        floorName = "Floor"
        sphereMatName = "SphereMaterial"
        floorMatName = "FloorMaterial"

        sphereMesh = createNewMeshHandle()
        floorMesh = createNewMeshHandle()
        floorMesh = primitives.createPlaneSimple(bmh, 'Floor', floorMatName)
        sphereMesh = primitives.createSphere(bmh, 'Sphere', sphereMatName, 30, 15)

        scene = createNewSceneHandle()
        sceneName = "BakingScene"
        apiCall( ILBBeginScene(bmh, sceneName, scene) )

        floorInstance = createNewInstanceHandle()
        floorTrans = vecmath.scaleTranslation(Vec3(10.0, 1.0, 10.0), Vec3(0.0, -5.0, 0.0))
        apiCall( ILBCreateInstance(scene, floorMesh, "FloorInstance", floorTrans, floorInstance))


        SPHERES = 5
        spherePosRadius = 5.0
        sphereRad = 2.0
        sphereInstances = []

        for i in range(SPHERES):
            angle = (M_PI * 2.0 * i) / SPHERES
            x = math.cos(angle) * spherePosRadius
            z = math.sin(angle) * spherePosRadius

            trans = vecmath.scaleTranslation(Vec3(sphereRad, sphereRad, sphereRad), 
                                     Vec3(x, -3.0, z))
            tempInstance = createNewInstanceHandle()
            sphereName = 'SphereInstance_' + str(i)
            apiCall( ILBCreateInstance(scene, sphereMesh, sphereName, trans, tempInstance) )
            apiCall( ILBSetRenderStats(tempInstance, ILB_RS_SHADOW_BIAS, ILB_RSOP_ENABLE) )


        # create the floor material
        floorMat = createNewMaterialHandle()
        primitives.apiCall( ILBCreateMaterial(scene, floorMatName, floorMat) )
        primitives.apiCall( ILBSetMaterialColor(floorMat, ILB_CC_DIFFUSE, ColorRGBA(0.7, 0.7, 0.7, 1.0)) )

        # create sphere material
        sphereMat = createNewMaterialHandle()
        apiCall( ILBCreateMaterial(scene, sphereMatName, sphereMat) )
        apiCall( ILBSetMaterialColor(sphereMat, ILB_CC_DIFFUSE, ColorRGBA(0.9, 0.9, 0.9, 1.0)) )
        #apiCall( ILBSetMaterialColor(sphereMat, ILB_CC_SPECULAR, ColorRGBA(1.0, 1.0, 1.0, 1.0)) )
        #apiCall( ILBSetMaterialScale(sphereMat, ILB_CC_REFLECTION, 0.1) )
        #apiCall( ILBSetMaterialScale(sphereMat, ILB_CC_SHININESS, 15.0) )

        light = createNewLightHandle()
        apiCall( ILBCreateDirectionalLight(scene, 
                                           "Sun", 
                                           vecmath.directionalLightOrientation(Vec3(1.0, -1.0, -1.0)),
                                           ColorRGB(1.0, 1.0, 0.8),
                                           light))
        apiCall( ILBSetCastShadows(light, True) )
        apiCall( ILBSetShadowSamples(light, 32) )
        apiCall( ILBSetShadowAngle(light, 0.1) )


        skylight = createNewLightHandle()
        apiCall( ILBCreateSkyLight( scene, 'SkyLight', vecmath.identity(), ColorRGB(0.21, 0.21, 0.3), skylight) )


        camera = createNewCameraHandle()
        apiCall( ILBCreatePerspectiveCamera(scene, 
                 "Camera", 
                 vecmath.setCameraMatrix(Vec3(0.3, 0.5, 15.0), Vec3(0.1, -0.3, -1.0), Vec3(0.0, 1.0, 0.0)),
                 camera) )

        # Finalize the scene
        apiCall(ILBEndScene(scene));


        beastConfig = beastCacheFolder + "/data/baking.xml"

        dom = minidom.getDOMImplementation()
        xmlDoc = dom.createDocument(None, "ILConfig", None)
        docRoot = xmlDoc.documentElement

        AASettingsElement = xmlDoc.createElement("AASettings")
        xmlCreateElement(xmlDoc, AASettingsElement, "minSampleRate", "0")
        xmlCreateElement(xmlDoc, AASettingsElement, "maxSampleRate", "2")
        docRoot.appendChild(AASettingsElement)


        RenderSettingsElement = xmlDoc.createElement("RenderSettings")
        xmlCreateElement(xmlDoc, RenderSettingsElement, "bias", "0.00001")
        docRoot.appendChild(RenderSettingsElement)

        FrameSettingsElement = xmlDoc.createElement("FrameSettings")
        xmlCreateElement(xmlDoc, FrameSettingsElement, "inputGamma", "0.45")
        outputCorrectionElement = xmlDoc.createElement("outputCorrection")
        xmlCreateElement(xmlDoc, outputCorrectionElement, "colorCorrection", "Gamma")
        xmlCreateElement(xmlDoc, outputCorrectionElement, "gamma", "2.2")
        FrameSettingsElement.appendChild(outputCorrectionElement)



        GISettingsElement = xmlDoc.createElement("GISettings")
        xmlCreateElement(xmlDoc, GISettingsElement, "enableGI", "true")
        xmlCreateElement(xmlDoc, GISettingsElement, "fgRays", "1000")
        xmlCreateElement(xmlDoc, GISettingsElement, "fgContrastThreshold", "0.1")
        xmlCreateElement(xmlDoc, GISettingsElement, "fginterpolationPoints", "15")
        xmlCreateElement(xmlDoc, GISettingsElement, "primaryIntegrator", "FinalGather")
        xmlCreateElement(xmlDoc, GISettingsElement, "secondaryIntegrator", "None")

        docRoot.appendChild(FrameSettingsElement)

        #write file contents
        xmlFile = open(beastConfig, "w")
        xmlFile.write(xmlDoc.toprettyxml())
        xmlFile.close()


        job = createNewJobHandle()
        apiCall( ILBCreateJob( bmh, 'TestJob', scene, beastConfig, job ) )

        fullShadingPass = createNewRenderPassHandle()
        apiCall( ILBCreateFullShadingPass(job, 'fullShading', fullShadingPass) )


        textureTarget = createNewTargetHandle()
        apiCall( ILBCreateTextureTarget(job, "textureTarget", 512, 512, textureTarget))
        entity = createNewTargetEntityHandle()

        # Add the floor instance twice in different parts of the UV space
        apiCall( ILBAddBakeInstance(textureTarget, floorInstance, entity) )
        apiCall( ILBSetUVTransform(entity, Vec2(0.0, 0.0), Vec2(0.5, 1.0)) )

        apiCall( ILBAddBakeInstance(textureTarget, floorInstance, entity) )

        apiCall( ILBSetUVTransform(entity, Vec2(0.5, 0.0), Vec2(0.5, 1.0)) )

        cameraTarget = createNewTargetHandle()
        apiCall( ILBCreateCameraTarget( job, 'cameraTarget', camera, 640, 480, cameraTarget ) )


        apiCall( ILBAddPassToTarget( textureTarget, fullShadingPass ) )
        apiCall( ILBAddPassToTarget( cameraTarget, fullShadingPass ) )

        if not renderJob( job ):
            print "render error occured"

    except BeastPythonException, (instance):
        print "exception: " + str(instance.parameter)
        ex = instance.parameter
        errorString = createNewStringHandle()
        extendedError = createNewStringHandle()
        ILBErrorToString(ex, errorString)
        ILBGetExtendErrorInformation(extendedError)
        print "Beast API error"
        print "Error: " + convertStringHandle(errorString)
        print "Info: " + convertStringHandle(extendedError)
Exemplo n.º 4
0
def main(argv):
    """docstring for main"""
    try:
        bmh = createNewManagerHandle()
        
        apiCall( ILBSetLogTarget(ILB_LT_ERROR, ILB_LS_STDERR, None) )
        
        apiCall( ILBSetLogTarget(ILB_LT_INFO, ILB_LS_DEBUG_OUTPUT, None) )
        
        config = ConfigParser.ConfigParser()
        config.read('config.ini')
        configItems = {}
        for item in config.items('BeastPythonExamples'):
            configItems[item[0]] = item[1]

        # Setup our beast manager
        beastCacheFolder = os.path.normpath(configItems['beast_cache'])
        beastBinFolder = os.path.normpath(configItems['beast_bin'])
        beastDataFolder = os.path.normpath(configItems['beast_data'])
        dir = beastCacheFolder + r'/temp/readback'

        apiCall( ILBCreateManager(dir, ILB_CS_LOCAL, bmh) )
        
        # Set the path to the Beast binaries
        apiCall( ILBSetBeastPath(bmh, beastBinFolder) )

        # Waste the cache from previous runs if present
        apiCall( ILBClearCache(bmh) )

        sphereName = "Sphere"
        floorName = "Floor"
        sphereMatName = "SphereMaterial"
        floorMatName = "FloorMaterial"

        sphereMesh = createNewMeshHandle()
        floorMesh = createNewMeshHandle()
        floorMesh = primitives.createPlane(bmh, 'Floor', floorMatName, planeRes, planeRes)
        sphereMesh = primitives.createSphere(bmh, 'Sphere', sphereMatName, sphereRes, sphereRes)

        bakingScene = SampleScene(bmh, "BakingScene")
        bakingScene.createInstances(floorMesh, sphereMesh)
        bakingScene.createLight()
        bakingScene.createCamera()

        bakingScene.createDiffuseMaterial(floorMatName, ColorRGBA(0.7, 0.7, 0.7, 1.0))
        bakingScene.createDiffuseMaterial(sphereMatName, ColorRGBA(0.9, 0.9, 0.9, 1.0))
        bakingScene.finalize()

        beastConfig = beastCacheFolder + "/data/baking.xml"
        createXML(beastConfig, True)

        bakeJob = SampleJob(bmh, "BakeJob", bakingScene, beastConfig)
        bakeJob.createTextureTarget("floorTextureTarget", lightmapRes, lightmapRes, bakingScene.getFloorInstance())
        bakeJob.createTextureTarget("sphereTextureTarget", lightmapRes, lightmapRes, bakingScene.getSphereInstance())
        bakeJob.createVertexTarget("floorVertexTarget", bakingScene.getFloorInstance())
        bakeJob.createVertexTarget("sphereVertexTarget", bakingScene.getSphereInstance())

        if bakeJob.run(True, False):
            return True

        # read back the lightmaps as textures
        lightmapFloor = bakeJob.createTextureFromTarget("floorTextureTarget")
        lightmapSphere = bakeJob.createTextureFromTarget("sphereTextureTarget")

        floorVertexColors = FloatArray()
        bakeJob.readVertexColors("floorVertexTarget", floorVertexColors)

        sphereVertexColors = FloatArray()
        bakeJob.readVertexColors("sphereVertexTarget", sphereVertexColors)

        floorMeshColors = primitives.createPlane(bmh, "FloorColor", floorMatName, planeRes, planeRes, floorVertexColors)
        sphereMeshColors = primitives.createSphere(bmh, "SphereColor", sphereMatName, sphereRes, sphereRes, sphereVertexColors)

        noGIConfig = beastCacheFolder + "/data/bakingNoGI.xml"
        createXML(noGIConfig, False)

        displayResults(bmh, floorMeshColors, floorMatName, lightmapFloor, sphereMeshColors, sphereMatName, lightmapSphere, noGIConfig, True)

        displayResults(bmh, floorMeshColors, floorMatName, lightmapFloor, sphereMeshColors, sphereMatName, lightmapSphere, noGIConfig, False)

    except BeastPythonException, (instance):
        print "exception: " + str(instance.parameter)
        ex = instance.parameter
        errorString = createNewStringHandle()
        extendedError = createNewStringHandle()
        ILBErrorToString(ex, errorString)
        ILBGetExtendErrorInformation(extendedError)
        print "Beast API error"
        print "Error: " + convertStringHandle(errorString)
        print "Info: " + convertStringHandle(extendedError)
Exemplo n.º 5
0
        # Setup our beast manager
        beastCacheFolder = os.path.normpath(configItems['beast_cache'])
        beastBinFolder = os.path.normpath(configItems['beast_bin'])
        beastDataFolder = os.path.normpath(configItems['beast_data'])
        apiCall( ILBCreateManager( os.path.join(beastCacheFolder, r'temp/simpleCache'), ILB_CS_LOCAL, bmh) )
        
        # Set the path to the Beast binaries
        apiCall( ILBSetBeastPath(bmh, beastBinFolder) )

        # Waste the cache from previous runs if present
        apiCall( ILBClearCache(bmh) )

        # Create ball and a plane meshes
        sphereMatName = 'SphereMaterial'
        floorMatName = 'FloorMaterial'
        sphereMesh = primitives.createSphere(bmh, 'Sphere', sphereMatName, 30, 15, None)
        floorMesh = primitives.createPlaneSimple(bmh, 'Floor', floorMatName)

        
        # Create a scene
        scene = createNewSceneHandle()
        apiCall( ILBBeginScene(bmh, 'SimpleScene', scene) )
        
        # Create an instance of the plane that will be a floor
        floorInstance = createNewInstanceHandle()
        floorTrans = vecmath.scaleTranslation(Vec3(10.0, 1.0, 10.0), 
                                              Vec3(0.0, -5.0, 0.0))
        apiCall( ILBCreateInstance(scene, floorMesh, 'FloorInstance', floorTrans, floorInstance) )

        # Create 5 instances of the sphere on the plane
        spheres = 5