Beispiel #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)
Beispiel #2
0
        boxMat = createNewMaterialHandle()
        apiCall( ILBCreateMaterial(scene, boxMatName, boxMat) )
        apiCall( ILBSetMaterialUseVertexColors(boxMat, ILB_CC_DIFFUSE) )

        # 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)) )

        camera = createNewCameraHandle()
        camPos = Vec3(0.0, 0.0, -20.0)
        camLookAt = Vec3(0.0, -3.0, 0.0)
        primitives.apiCall( ILBCreatePerspectiveCamera(scene, 
                                                       'Camera',
                                                       vecmath.setCameraMatrix(camPos,
                                                       camLookAt - camPos,
                                                       Vec3(0.0,  1.0, 0.0)),
                                                       camera) )

        apiCall( ILBEndScene(scene) )


        # create config
        beastConfig = beastCacheFolder + "/data/rnm.xml"

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

        AASettingsElement = xmlDoc.createElement("AASettings")
        xmlCreateElement(AASettingsElement, "minSampleRate", "0")
Beispiel #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)
Beispiel #4
0
        light = createNewLightHandle()
        pos = Vec3(0.0, 1.0, 0.0)
        lookAt = Vec3(0.0, 0.0, 0.0)

        spotMatrix = vecmath.setSpotlightMatrix(pos, lookAt - pos )

        apiCall( ILBCreateSpotLight(scene, "Light", spotMatrix, ColorRGB(1.0, 1.0, 1.0), light) )
        apiCall( ILBSetSpotlightCone(light, M_PI/3.0, 0.1, 2.0) )


        camera = createNewCameraHandle()
        apiCall( ILBCreatePerspectiveCamera(scene, 
                                            'Camera',
                                            vecmath.setCameraMatrix(Vec3(0.3, 3.0, 20.0),  
                                            Vec3(0.1, -0.3, -1.0), 
                                            Vec3(0.0,  1.0,  0.0)), 
                                            camera) )

        apiCall( ILBSetFov(camera, M_PI/4.0, 1.0) )

        apiCall( ILBEndScene(scene) )

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

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

        AASettingsElement = xmlDoc.createElement("AASettings")
Beispiel #5
0
        apiCall( ILBSetCastShadows(light, True) )
        apiCall( ILBSetShadowSamples(light, 32) )
        apiCall( ILBSetShadowAngle(light, 0.1) )

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

        # set up camera
        camPos = Vec3(10.0, 20.0, 10.0)
        lookAt = Vec3(0.0, -3.0, 0.0)
        camera = createNewCameraHandle()
        primitives.apiCall( ILBCreatePerspectiveCamera(scene, 
                                                       'Camera',
                                                       vecmath.setCameraMatrix(camPos,  
                                                                       vecmath.normalize(lookAt - camPos),
                                                                       Vec3(0.0,  0.0, -1.0)),
                                                       camera) )

        apiCall( ILBSetFov(camera, M_PI/4.0, 1.0) )


        # Create a textured diffuse material for sphere 0
        sm0 = createNewMaterialHandle()
        tex = textures.createXorTexture( bmh, "Tex1", ColorRGB(0.6, 0.6, 0.3) ) 
        apiCall( ILBCreateMaterial(scene, "Textured", sm0) )

        apiCall( ILBSetMaterialTexture(sm0, ILB_CC_DIFFUSE, tex) )
        apiCall( ILBSetMaterialOverrides(sphereInstances[0], sm0, 1) )