def TestGeneratedScene(cls, params): engineType = params[0] samplerType = params[1] renderConfigAdditionalProps = params[2] isDeterministic = params[3] # Create the rendering configuration cfgProps = pyluxcore.Properties() cfgProps.SetFromString(""" film.width = 512 film.height = 384 """) # Set the rendering engine cfgProps.Set(pyluxcore.Property("renderengine.type", engineType)) # Set the sampler cfgProps.Set(pyluxcore.Property("sampler.type", samplerType)) cfgProps.Set(renderConfigAdditionalProps) cfgProps.Set(LuxCoreTest.customConfigProps) # Create the scene properties scnProps = pyluxcore.Properties() # Set the camera position scnProps.SetFromString(""" scene.camera.lookat.orig = 0.0 5.0 2.0 scene.camera.lookat.target = 0.0 0.0 0.0 """) # Define a white matte material scnProps.SetFromString(""" scene.materials.whitematte.type = matte scene.materials.whitematte.kd = 0.75 0.75 0.75 """) # Add a plane scnProps.Set(BuildPlane("plane1", "whitematte")) # Add a distant light source scnProps.SetFromString(""" scene.lights.distl.type = sharpdistant scene.lights.distl.color = 1.0 1.0 1.0 scene.lights.distl.gain = 2.0 2.0 2.0 scene.lights.distl.direction = 1.0 1.0 -1.0 """) # Create the scene scene = pyluxcore.Scene() scene.Parse(scnProps) # Create the render config config = pyluxcore.RenderConfig(cfgProps, scene) # Run the rendering StandardImageTest( cls, "GeneratedScene_" + engineType + ("" if not samplerType else ("_" + samplerType)), config, isDeterministic)
def load_stuff(self): self.session = None self.config = None self.scene = None self.ui.renBtn.setEnabled(True) self.ui.stopBtn.setEnabled(False) self.ui.pauBtn.setEnabled(False) self.ui.renderView.clear() cmdLineProp = pyluxcore.Properties() self.configProps = pyluxcore.Properties() self.sceneProps = pyluxcore.Properties() print(self.ext) print(self.cfgFileName) if (self.ext == "lxs"): os.chdir(self.lastpath) pyluxcore.ParseLXS(self.cfgFileName, self.configProps, self.sceneProps) self.configProps.Set(cmdLineProp) self.scene = pyluxcore.Scene( self.configProps.Get("images.scale", [1.0]).GetFloat()) self.scene.Parse(self.sceneProps) self.config = pyluxcore.RenderConfig(self.configProps, self.scene) self.setup() return elif (self.ext == "cfg"): os.chdir(self.lastpath) print(self.cfgFileName) self.configProps = pyluxcore.Properties(self.cfgFileName) self.scene = pyluxcore.Scene( self.configProps.Get("scene.file").GetString()) self.sceneProps = self.scene.ToProperties() self.cameraPos = self.sceneProps.Get( "scene.camera.lookat.orig").GetFloats() self.config = pyluxcore.RenderConfig(self.configProps, self.scene) self.setup() elif (self.ext == "bcf"): os.chdir(self.lastpath) self.config = pyluxcore.RenderConfig(self.cfgFileName) self.configProps.Parse(cmdLineProp) self.setup()
def __init__(self, cfgFileName): super(RenderView, self).__init__() self.dofEnabled = True self.luxBallShapeIsCube = False self.selectedFilmChannel = pyluxcore.FilmOutputType.RGB_TONEMAPPED self.createActions() self.createMenus() # Load the configuration from file props = pyluxcore.Properties(cfgFileName) # Change the render engine to PATHCPU props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"])) # Read the configuration and start the rendering self.scene = pyluxcore.Scene(props.Get("scene.file").GetString(), props.Get("images.scale", [1.0]).GetFloat()) sceneProps = self.scene.GetProperties() # Save Camera position self.cameraPos = sceneProps.Get("scene.camera.lookat.orig").GetFloats() self.luxBallPos = [0.0, 0.0, 0.0] # Create the rendering configuration self.config = pyluxcore.RenderConfig(props, self.scene) self.filmWidth, self.filmHeight = self.config.GetFilmSize()[:2] # Allocate the image for the rendering self.allocateImageBuffers() self.setGeometry(0, 0, self.filmWidth, self.filmHeight) self.setWindowTitle('LuxCore RenderView') self.center() # Create the rendering session self.session = pyluxcore.RenderSession(self.config) # Start the rendering self.session.Start() self.timer = QBasicTimer() self.timer.start(500, self)
def StrandsRender(): print("Strands example...") # Create the rendering configuration cfgProps = pyluxcore.Properties() cfgProps.SetFromString(""" film.width = 640 film.height = 480 """) # Set the rendering engine cfgProps.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"])) # Create the scene properties scnProps = pyluxcore.Properties() # Set the camera position scnProps.SetFromString(""" scene.camera.lookat.orig = 0.0 5.0 2.0 scene.camera.lookat.target = 0.0 0.0 0.0 """) # Define a white matte material scnProps.SetFromString(""" scene.materials.whitematte.type = matte scene.materials.whitematte.kd = 0.75 0.75 0.75 """) # Add a plane scnProps.Set(BuildPlane("plane1", "whitematte")) # Add a distant light source scnProps.SetFromString(""" scene.lights.distl.type = sharpdistant scene.lights.distl.color = 1.0 1.0 1.0 scene.lights.distl.gain = 2.0 2.0 2.0 scene.lights.distl.direction = 1.0 1.0 -1.0 """) # Create the scene #resizePolicyProps = pyluxcore.Properties() #resizePolicyProps.SetFromString(""" # scene.images.resizepolicy.type = "MIPMAPMEM" # scene.images.resizepolicy.scale = 1.0 # scene.images.resizepolicy.minsize = 64 # """) #scene = pyluxcore.Scene(scnProps, resizePolicyProps) scene = pyluxcore.Scene() scene.Parse(scnProps) # Add strands points = [] segments = [] strandsCount = 30 for i in range(strandsCount): x = random.random() * 2.0 - 1.0 y = random.random() * 2.0 - 1.0 points.append((x , y, 0.0)) points.append((x , y, 1.0)) segments.append(1) scene.DefineStrands("strands_shape", strandsCount, 2 * strandsCount, points, segments, 0.025, 0.0, (1.0, 1.0, 1.0), None, "ribbon", 0, 0, 0, False, False, True) strandsProps = pyluxcore.Properties() strandsProps.SetFromString(""" scene.objects.strands_obj.material = whitematte scene.objects.strands_obj.shape = strands_shape """) scene.Parse(strandsProps) # Save the strand mesh (just for testing) scene.SaveMesh("strands_shape", "strands_shape.ply") # Create the render config config = pyluxcore.RenderConfig(cfgProps, scene) session = pyluxcore.RenderSession(config) session.Start() startTime = time.time() while True: time.sleep(1) elapsedTime = time.time() - startTime # Print some information about the rendering progress # Update statistics session.UpdateStats() stats = session.GetStats(); print("[Elapsed time: %3d/5sec][Samples %4d][Avg. samples/sec % 3.2fM on %.1fK tris]" % ( stats.Get("stats.renderengine.time").GetFloat(), stats.Get("stats.renderengine.pass").GetInt(), (stats.Get("stats.renderengine.total.samplesec").GetFloat() / 1000000.0), (stats.Get("stats.dataset.trianglecount").GetFloat() / 1000.0))) if elapsedTime > 5.0: # Time to stop the rendering break session.Stop() # Save the rendered image session.GetFilm().Save() print("Done.")
def LuxCoreConsole(argv): parser = argparse.ArgumentParser(description="PyLuxCoreConsole") parser.add_argument("fileToRender", help=".cfg, .lxs, .bcf or .rsm file to render") parser.add_argument("-f", "--scene", metavar="FILE_NAME", nargs=1, help="scene file name") parser.add_argument("-w", "--film-width", metavar="WIDTH", nargs=1, type=int, help="film width") parser.add_argument("-e", "--film-height", metavar="HEIGHT", nargs=1, type=int, help="film height") parser.add_argument("-D", "--define", metavar=("PROP_NAME", "VALUE"), nargs=2, action="append", help="assign a value to a property") parser.add_argument("-d", "--current-dir", metavar="DIR_NAME", nargs=1, help="current directory path") parser.add_argument( "-c", "--remove-unused", action="store_true", help="remove all unused meshes, materials, textures and image maps") parser.add_argument("-t", "--camera-shutter", metavar="CAMERA_SHUTTER", nargs=2, type=float, help="camera shutter open/close") # Parse command line arguments args = parser.parse_args(argv) cmdLineProp = pyluxcore.Properties() if (args.scene): cmdLineProp.Set(pyluxcore.Property("scene.file", args.scene)) if (args.film_width): cmdLineProp.Set(pyluxcore.Property("film.width", args.film_width)) if (args.film_height): cmdLineProp.Set(pyluxcore.Property("film.height", args.film_height)) if (args.define): for (name, value) in args.define: cmdLineProp.Set(pyluxcore.Property(name, value)) if (args.current_dir): os.chdir(args.current_dir[0]) removeUnused = args.remove_unused if (not args.fileToRender): raise TypeError("File to render must be specified") # Load the file to render config = None startState = None startFilm = None configFileNameExt = os.path.splitext(args.fileToRender)[1] if (configFileNameExt == ".lxs"): # It is a LuxRender SDL file logger.info("Parsing LuxRender SDL file...") # Parse the LXS file configProps = pyluxcore.Properties() sceneProps = pyluxcore.Properties() pyluxcore.ParseLXS(args.fileToRender, configProps, sceneProps) configProps.Set(cmdLineProp) scene = pyluxcore.Scene( configProps.Get("images.scale", [1.0]).GetFloat()) scene.Parse(sceneProps) config = pyluxcore.RenderConfig(configProps, scene) elif (configFileNameExt == ".cfg"): # It is a LuxCore SDL file configProps = pyluxcore.Properties(args.fileToRender) configProps.Set(cmdLineProp) config = pyluxcore.RenderConfig(configProps) elif (configFileNameExt == ".bcf"): # It is a LuxCore RenderConfig binary archive config = pyluxcore.RenderConfig(args.fileToRender) config.Parse(cmdLineProp) elif (configFileNameExt == ".rsm"): # It is a rendering resume file (config, startState, startFilm) = pyluxcore.RenderConfig.LoadResumeFile(args.fileToRender) config.Parse(cmdLineProp) else: raise TypeError("Unknown file extension: " + args.fileToRender) if (removeUnused): config.GetScene().RemoveUnusedMeshes() config.GetScene().RemoveUnusedImageMaps() config.GetScene().RemoveUnusedMaterials() config.GetScene().RemoveUnusedTextures() # Overwrite camera shutter open/close if (args.camera_shutter): cameraProps = config.GetScene().ToProperties().GetAllProperties( "scene.camera") cameraProps.Set( pyluxcore.Property("scene.camera.shutteropen", [args.camera_shutter[0]])) cameraProps.Set( pyluxcore.Property("scene.camera.shutterclose", [args.camera_shutter[1]])) config.GetScene().Parse(cameraProps) # Force the film update at 2.5secs (mostly used by PathOCL) # Skip in case of a FILESAVER isFileSaver = ( config.GetProperty("renderengine.type").GetString() == "FILESAVER") if (not isFileSaver): config.Parse(pyluxcore.Properties().Set( pyluxcore.Property("screen.refresh.interval", 2500))) session = BatchRendering(config, startState, startFilm) if (not isFileSaver): # Save the rendered image session.GetFilm().Save() logger.info("Done.")
def build_scene(fluid_mesh): scene = pyluxcore.Scene() props = pyluxcore.Properties() props.SetFromString(""" scene.camera.type = "perspective" scene.camera.lookat.orig = 0.5 -2.0 1.0 scene.camera.lookat.target = 0.5 0.5 0.4 scene.camera.fieldofview = 35 ################################################################################ scene.materials.fluid.type = glass #scene.materials.fluid.kd = 1. 0.824176 0.549451 scene.materials.fluid.kr = 1.0 1.0 1.0 scene.materials.fluid.kt = 1.0 1.0 1.0 scene.materials.fluid.interiorior = 1.333 scene.materials.fluid.exteriorior = 1.0 scene.materials.fluid.photongi.enable = 1 ################################################################################ scene.textures.table.type = blender_noise scene.materials.slab.type = matte #scene.materials.slab.kd = table scene.materials.slab.kd = 0.8 0.64 0.45 ################################################################################ #scene.materials.container.type = roughglass #scene.materials.container.kr = 0.9 0.9 0.9 #scene.materials.container.kt = 0.9 0.9 0.9 #scene.materials.container.interiorior = 1.5 #scene.materials.container.exteriorior = 1.0 #scene.materials.container.uroughness = 0.5 #scene.materials.container.vroughness = 0.5 scene.materials.container.type = matte scene.materials.container.kd = 1.0 1.0 1.0 ################################################################################ #scene.lights.l1.type = sky2 #scene.lights.l1.gain = 0.0003 0.0003 0.0003 #scene.lights.l1.dir = 0.0 0.0 1.0 #scene.lights.l1.relsize = 1.0 #scene.lights.l1.turbidity = 2.0 #scene.lights.l1.ground.enable = 0 scene.lights.l2.type = point scene.lights.l2.position = 0.5 0.5 1.0 scene.lights.l2.gain = 0.7 0.7 0.7 scene.lights.l3.type = point scene.lights.l3.position = 0.0 0.5 2.0 scene.lights.l3.gain = 0.99 0.99 0.99 ################################################################################ scene.objects.slab.material = slab scene.objects.slab.ply = slab.ply #scene.objects.container.material = container #scene.objects.container.ply = container_tri.ply #scene.objects.stairs.material = container #scene.objects.stairs.ply = stairs.ply scene.objects.solid.material = container scene.objects.solid.ply = solid.ply ################################################################################ """) scene.Parse(props) props = pyluxcore.Properties() props.Set(pyluxcore.Property("scene.objects.fluid.material", "fluid")) props.Set(pyluxcore.Property("scene.objects.fluid.ply", fluid_mesh)) scene.Parse(props) return scene
def SceneOps(): scene = pyluxcore.Scene("scenes/luxball/luxball-hdr.scn", 1.0)
def RenderConfigOps(): renderConfig = pyluxcore.Scene("scenes/luxball/luxball-hdr.cfg", 1.0)
def ConvertBlenderScene(self, blScene): ######################################################################## # Create the scene ######################################################################## scene = pyluxcore.Scene() sceneProps = pyluxcore.Properties() ######################################################################## # Get camera and lookat direction ######################################################################## camera = blScene.camera cameraDir = camera.matrix_world * Vector((0, 0, -1)) sceneProps.Set( pyluxcore.Property("scene.camera.lookat.target", [cameraDir.x, cameraDir.y, cameraDir.z])) # Camera.location not always updated, but matrix is cameraLoc = camera.matrix_world.to_translation() sceneProps.Set( pyluxcore.Property("scene.camera.lookat.orig", [cameraLoc.x, cameraLoc.y, cameraLoc.z])) cameraUp = camera.matrix_world.to_3x3() * Vector((0, 1, 0)) sceneProps.Set( pyluxcore.Property("scene.camera.up", [cameraUp.x, cameraUp.y, cameraUp.z])) cameraFOV = camera.data.angle * 180.0 / 3.1415926536 sceneProps.Set( pyluxcore.Property("scene.camera.fieldofview", [cameraFOV])) ######################################################################## # Add Sun and Sky ######################################################################## sceneProps.Set( pyluxcore.Property("scene.skylight.dir", [-0.5, -0.5, 0.5])) sceneProps.Set(pyluxcore.Property("scene.skylight.turbidity", [2.2])) sceneProps.Set( pyluxcore.Property("scene.skylight.gain", [1.0, 1.0, 1.0])) sceneProps.Set( pyluxcore.Property("scene.sunlight.dir", [-0.5, -0.5, 0.5])) sceneProps.Set(pyluxcore.Property("scene.sunlight.turbidity", [2.2])) sceneProps.Set( pyluxcore.Property("scene.sunlight.gain", [1.0, 1.0, 1.0])) ######################################################################## # Add dummy material ######################################################################## sceneProps.Set( pyluxcore.Property("scene.materials.dummymat.type", ["matte"])) sceneProps.Set( pyluxcore.Property("scene.materials.dummymat.kd", [0.7, 0.7, 0.7])) ######################################################################## # Add all objects ######################################################################## rendertypes = ["MESH", "SURFACE", "META", "TEXT", "CURVE"] for obj in blScene.objects: objName = obj.name.replace('.', '___') if not obj.hide_render and obj.type in rendertypes: try: if type(obj) == bpy.types.Object: print("Object: {}".format(objName)) mesh = obj.to_mesh(blScene, True, "RENDER") else: print("Mesh: {}".format(objName)) mesh = obj mesh.update(calc_tessface=True) except: print("Pass") pass mesh.transform(obj.matrix_world) mesh.update(calc_tessface=True) verts = [v.co[:] for v in mesh.vertices] # Split all polygons in triangles tris = [] for poly in mesh.polygons: for loopIndex in range( poly.loop_start + 1, poly.loop_start + poly.loop_total - 1): tris.append((mesh.loops[poly.loop_start].vertex_index, mesh.loops[loopIndex].vertex_index, mesh.loops[loopIndex + 1].vertex_index)) # Define a new object scene.DefineMesh("Mesh-" + objName, verts, tris, None, None, None, None) sceneProps.Set( pyluxcore.Property("scene.objects." + objName + ".material", ["dummymat"])) sceneProps.Set( pyluxcore.Property("scene.objects." + objName + ".ply", ["Mesh-" + objName])) scene.Parse(sceneProps) return scene