def CreateConfig(self, type):
        # Load the configuration from file
        props = pyluxcore.Properties("resources/scenes/simple/simple.cfg")

        # Change the render engine to PATHCPU
        props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))
        props.Set(pyluxcore.Property("sampler.type", ["RANDOM"]))
        props.Set(GetDefaultEngineProperties("PATHCPU"))

        config = pyluxcore.RenderConfig(props)
        scene = config.GetScene()

        # Delete the red and green boxes
        scene.DeleteObject("box1")
        scene.DeleteObject("box2")

        # Create the base object
        props = pyluxcore.Properties()
        if (type == "Normal"):
            props.SetFromString("""
				scene.objects.box1.ply = resources/scenes/simple/simple-mat-cube1.ply
				scene.objects.box1.material = redmatte
				""")
        elif (type == "Instance"):
            props.SetFromString("""
				scene.objects.box1.ply = resources/scenes/simple/simple-mat-cube1.ply
				scene.objects.box1.material = redmatte
				scene.objects.box1.transformation = 1.0 0.0 0.0 0.0  0.0 1.0 0.0 0.0  0.0 0.0 1.0 0.0  -0.5 0.0 0.0 1.0
				""")
        elif (type == "Motion"):
            props.SetFromString("""
				scene.objects.box1.ply = resources/scenes/simple/simple-mat-cube1.ply
				scene.objects.box1.material = redmatte
				scene.objects.box1.motion.0.time = 0.0
				scene.objects.box1.motion.0.transformation = 1.0 0.0 0.0 0.0  0.0 1.0 0.0 0.0  0.0 0.0 1.0 0.0  -0.25 0.0 0.0 1.0
				scene.objects.box1.motion.1.time = 1.0
				scene.objects.box1.motion.1.transformation = 1.0 0.0 0.0 0.0  0.0 1.0 0.0 0.0  0.0 0.0 1.0 0.0  0.25 0.0 0.0 1.0
				""")
        else:
            self.assertFalse()
        scene.Parse(props)

        return config
Esempio n. 2
0
	def resizeEvent(self, event):
		if (event.size().width() != self.filmWidth) or (event.size().height() != self.filmHeight):
			# Stop the rendering
			self.session.Stop()
			self.session = None

			# Set the new size
			self.filmWidth = int(event.size().width())
			self.filmHeight = int(event.size().height())
			self.config.Parse(pyluxcore.Properties().
				Set(pyluxcore.Property("film.width", [self.filmWidth])).
				Set(pyluxcore.Property("film.height", [self.filmHeight])))
			self.allocateImageBuffers()

			# Re-start the rendering
			self.session = pyluxcore.RenderSession(self.config)
			self.session.Start()
		
		super(RenderView, self).resizeEvent(event)
    def renderEnginePathOCL(self, index):
        # Stop the rendering
        self.session.Stop()
        self.session = None

        # Change the render engine to PATHCPU
        props = self.config.GetProperties()
        selectString = list("0" * len(self.deviceList))
        selectString[index] = "1"
        props.Set(pyluxcore.Property("renderengine.type", ["PATHOCL"])). \
         Set(pyluxcore.Property("opencl.devices.select", ["".join(selectString)]))

        # Create the new RenderConfig
        self.config = pyluxcore.RenderConfig(props, self.scene)

        # Re-start the rendering
        self.session = pyluxcore.RenderSession(self.config)
        self.session.Start()
        print("PathOCL selected: %s" % self.deviceList[index][0])
Esempio n. 4
0
    def test_Properties_GetAllUniqueSubNames(self):
        props = pyluxcore.Properties()
        props.Set(pyluxcore.Property("test1.prop1.aa", "aa"))
        props.Set(pyluxcore.Property("test1.prop1.bb", "bb"))
        props.Set(pyluxcore.Property("test1.prop1.prop2.aa", "aa"))
        props.Set(pyluxcore.Property("test1.prop1.prop2.bb", "bb"))
        props.Set(pyluxcore.Property("test1.prop2.aa", "aa"))
        props.Set(pyluxcore.Property("test2.prop1.aa", "aa"))
        props.Set(pyluxcore.Property("test2.prop1.bb", "bb"))
        props.Set(pyluxcore.Property("test2.prop2", "aa"))
        props.Set(pyluxcore.Property("test3.prop1.aa", "aa"))

        self.assertEqual(props.GetAllUniqueSubNames("test1"),
                         ["test1.prop1", "test1.prop2"])
        self.assertEqual(props.GetAllUniqueSubNames("test1.prop1"),
                         ["test1.prop1.prop2"])
Esempio n. 5
0
	def test_Properties_SpaceInName(self):
		props = pyluxcore.Properties()
		props.Set(pyluxcore.Property("aa.b b.cc", "123"))
		
		self.assertEqual(props.Get("aa.b b.cc").Get(), ["123"])
		
		props = pyluxcore.Properties()
		props.SetFromString("test1.prop1  = 1 2.0 aa \"quoted\"\ntest2.pr op2   = 1 2.0 'quoted' bb\ntest2.prop3 = 1")
		self.assertEqual(props.Get("test1.prop1").Get(), ["1", "2.0", "aa", "quoted"])
		self.assertEqual(props.Get("test2.pr op2").Get(), ["1", "2.0", "quoted", "bb"])
		self.assertEqual(props.Get("test2.prop3").Get(), ["1"])
Esempio n. 6
0
	def luxBallMove(self, t):
		# Begin scene editing
		self.session.BeginSceneEdit()
		
		self.luxBallPos[0] += t
		# Set the new LuxBall position (note: using the transpose matrix)
		mat = [1.0, 0.0, 0.0, 0.0,
			0.0, 1.0, 0.0, 0.0,
			0.0, 0.0, 1.0, 0.0,
			self.luxBallPos[0], self.luxBallPos[1], self.luxBallPos[2], 1.0]
		self.scene.Parse(self.scene.GetProperties().GetAllProperties("scene.objects.luxtext").
			Set(pyluxcore.Property("scene.objects.luxtext.transformation", mat)))
		self.scene.Parse(self.scene.GetProperties().GetAllProperties("scene.objects.luxinner").
			Set(pyluxcore.Property("scene.objects.luxinner.transformation", mat)))
		self.scene.Parse(self.scene.GetProperties().GetAllProperties("scene.objects.luxshell").
			Set(pyluxcore.Property("scene.objects.luxshell.transformation", mat)))
		
		# End scene editing
		self.session.EndSceneEdit()
		print("LuxBall new position: %f, %f, %f" % (self.luxBallPos[0], self.luxBallPos[1], self.luxBallPos[2]))
Esempio n. 7
0
	def filmSetOutputChannel(self, type):
		# Stop the rendering
		self.session.Stop()
		self.session = None
		
		# Delete old channel outputs
		self.config.Delete("film.outputs")
		
		# Set the new channel outputs
		self.config.Parse(pyluxcore.Properties().
			Set(pyluxcore.Property("film.outputs.1.type", ["RGB_IMAGEPIPELINE"])).
			Set(pyluxcore.Property("film.outputs.1.filename", ["luxball_RGB_IMAGEPIPELINE.png"])).
			Set(pyluxcore.Property("film.outputs.2.type", [str(type)])).
			Set(pyluxcore.Property("film.outputs.2.filename", ["luxball_SELECTED_OUTPUT.exr"])))
		self.selectedFilmChannel = type
		
		# Re-start the rendering
		self.session = pyluxcore.RenderSession(self.config)
		self.session.Start()
		print("Film channel selected: %s" % (str(type)))
Esempio n. 8
0
def PropertiesOps():
    prop = pyluxcore.Property("test1.prop1", "aa")

    prop.Clear().Add([0, 2]).Add([3])
    prop.Set(0, 1)
    prop.Set([3, 2, 1])

    pyvariable = 999
    prop = pyluxcore.Property("test1.prop1", [True, 1, 2.0, "aa", pyvariable])

    props = pyluxcore.Properties()
    props.SetFromString(
        "test1.prop1 = 1 2.0 aa \"quoted\"\ntest2.prop2 = 1 2.0 'quoted' bb\ntest2.prop3 = 1"
    )

    props0 = pyluxcore.Properties()
    props1 = pyluxcore.Properties() \
     .Set(pyluxcore.Property("test1.prop1", [True, 1, 2.0, "aa"])) \
     .Set(pyluxcore.Property("test2.prop1", ["bb"]))

    props0.Set(props1, "prefix.")
Esempio n. 9
0
	def cameraToggleDOF(self):
		# Begin scene editing
		self.session.BeginSceneEdit()

		# Edit the camera
		self.dofEnabled = not self.dofEnabled
		self.scene.Parse(self.scene.ToProperties().GetAllProperties("scene.camera").
			Set(pyluxcore.Property("scene.camera.lensradius", [0.015 if self.dofEnabled else 0.0])))

		# End scene editing
		self.session.EndSceneEdit()
		print("Camera DOF toggled: %s" % (str(self.dofEnabled)))
Esempio n. 10
0
	def luxBallMatGlass(self):
		# Begin scene editing
		self.session.BeginSceneEdit()

		# Edit the material
		self.scene.Parse(pyluxcore.Properties().
			Set(pyluxcore.Property("scene.materials.shell.type", ["glass"])).
			Set(pyluxcore.Property("scene.materials.shell.kr", [0.69, 0.78, 1.0])).
			Set(pyluxcore.Property("scene.materials.shell.kt", [0.69, 0.78, 1.0])).
			Set(pyluxcore.Property("scene.materials.shell.ioroutside", [1.0])).
			Set(pyluxcore.Property("scene.materials.shell.iorinside", [1.45]))
			)
		
		# To remove unreferenced constant textures defined implicitely
		self.scene.RemoveUnusedTextures()
		# To remove all unreferenced image maps (note: the order of call does matter)
		self.scene.RemoveUnusedImageMaps()
		
		# End scene editing
		self.session.EndSceneEdit()
		print("LuxBall material set to: Glass")
Esempio n. 11
0
    def RunRemoveUnusedTest(self, name, removeImageMaps, removeUnusedTexs,
                            removeUnusedMats, removeUnusedMeshes, editProps):
        # Load the configuration from file
        props = pyluxcore.Properties(
            "resources/scenes/simple/texture-imagemap.cfg")

        # Change the render engine to PATHCPU
        props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))
        props.Set(pyluxcore.Property("sampler.type", ["RANDOM"]))
        props.Set(GetDefaultEngineProperties("PATHCPU"))
        # Delete halt condition
        props.Delete("batch.haltthreshold")

        config = pyluxcore.RenderConfig(props)
        session = pyluxcore.RenderSession(config)

        session.Start()
        time.sleep(2.0)
        session.BeginSceneEdit()

        scene = config.GetScene()
        scene.Parse(editProps)

        if (removeImageMaps):
            scene.RemoveUnusedImageMaps()
        if (removeUnusedTexs):
            scene.RemoveUnusedTextures()
        if (removeUnusedMats):
            scene.RemoveUnusedMaterials()
        if (removeUnusedMeshes):
            scene.RemoveUnusedMeshes()

        session.EndSceneEdit()
        time.sleep(5.0)
        session.Stop()

        image = GetImagePipelineImage(session.GetFilm())

        CheckResult(self, image, name, False)
Esempio n. 12
0
def TestGeneratedScene(cls, params):
	engineType = params[0]
	samplerType = params[1]

	# Create the rendering configuration
	cfgProps = pyluxcore.Properties(LuxCoreTest.customConfigProps)
	cfgProps.SetFromString("""
		film.width = 512
		film.height = 384
		""")
	# Set the rendering engine
	cfgProps.Set(GetEngineProperties(engineType))
	# Set the sampler (if required)
	if samplerType:
		cfgProps.Set(pyluxcore.Property("sampler.type", samplerType))

	# 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)
Esempio n. 13
0
def SaveFilm():
    print("Film save example (requires scenes directory)...")

    # Load the configuration from file
    props = pyluxcore.Properties("scenes/simple/simple.cfg")
    #props = pyluxcore.Properties("scenes/luxball/luxball-hdr.cfg")
    # To test large films
    #props.Set(pyluxcore.Property("film.width", 2048))
    #props.Set(pyluxcore.Property("film.height", 2048))

    # Change the render engine to PATHCPU
    props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))

    config = pyluxcore.RenderConfig(props)
    session = pyluxcore.RenderSession(config)

    session.Start()

    startTime = time.time()
    while True:
        time.sleep(.5)

        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
    t1 = Clock()
    session.GetFilm().SaveFilm("simple.flm")
    t2 = Clock()
    print("Film save time: %s secs" % (t2 - t1))

    print("Done.")
Esempio n. 14
0
	def luxBallMatGlossyImageMap(self):
		# Begin scene editing
		self.session.BeginSceneEdit()

		# Define check map
		imageMap = array('f', [0.0] * (128 * 128 * 3))
		for y in range(128):
			for x in range(128):
				offset = (x + y * 128) * 3
				if (x % 64 < 32) ^ (y % 64 < 32):
					imageMap[offset] = 1.0
					imageMap[offset] = 1.0
					imageMap[offset] = 1.0
				else:
					imageMap[offset] = 1.0
					imageMap[offset] = 0.0
					imageMap[offset] = 0.0
		########################################################################
		# NOTICE THE DIFFERENT BEHAVIOR REQUIRED BY PYTHON 2.7
		########################################################################
		self.scene.DefineImageMap("check_map", buffer(imageMap) if sys.version_info < (3,0,0) else imageMap, 2.2, 3, 128, 128)

		# Edit the material
		self.scene.Parse(pyluxcore.Properties().
			Set(pyluxcore.Property("scene.textures.tex.type", ["imagemap"])).
			Set(pyluxcore.Property("scene.textures.tex.file", ["check_map"])).
			Set(pyluxcore.Property("scene.textures.tex.gain", [0.6])).
			Set(pyluxcore.Property("scene.textures.tex.mapping.uvscale", [16, -16])).
			Set(pyluxcore.Property("scene.materials.shell.type", ["glossy2"])).
			Set(pyluxcore.Property("scene.materials.shell.kd", ["tex"])).
			Set(pyluxcore.Property("scene.materials.shell.ks", [0.25, 0.0, 0.0])).
			Set(pyluxcore.Property("scene.materials.shell.uroughness", [0.05])).
			Set(pyluxcore.Property("scene.materials.shell.vroughness", [0.05])))

		# To remove unreferenced constant textures defined implicitely
		self.scene.RemoveUnusedTextures()
		# To remove all unreferenced image maps (note: the order of call does matter)
		self.scene.RemoveUnusedImageMaps()
		
		# End scene editing
		self.session.EndSceneEdit()
		print("LuxBall material set to: Glossy with image map")
Esempio n. 15
0
    def test_Film_SaveLoad(self):
        # Load the configuration from file
        props = pyluxcore.Properties("resources/scenes/simple/simple.cfg")

        # Change the render engine to PATHCPU
        props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))
        props.Set(pyluxcore.Property("sampler.type", ["RANDOM"]))
        props.Set(GetDefaultEngineProperties("PATHCPU"))

        config = pyluxcore.RenderConfig(props)
        session = DoRenderSession(config)

        # Get the imagepipeline result
        filmA = session.GetFilm()
        imageA = GetImagePipelineImage(filmA)

        # Save the film
        filmA.SaveFilm("simple.flm")

        # Load the film
        filmB = pyluxcore.Film("simple.flm")
        self.assertEqual(filmB.GetWidth(), filmA.GetWidth())
        self.assertEqual(filmB.GetHeight(), filmA.GetHeight())

        # Get the imagepipeline result
        imageB = GetImagePipelineImage(filmB)

        # To debug
        #imageA.save("imageA.png")
        #imageB.save("imageB.png")

        # Check if there is a difference
        (sameImage, diffCount, diffImage) = CompareImage(imageA, imageB)

        self.assertTrue(sameImage)

        os.unlink("simple.flm")
Esempio n. 16
0
	def renderEnginePathCPU(self):
		# Stop the rendering
		self.session.Stop()
		self.session = None
		
		# Change the render engine to PATHCPU
		props = self.config.GetProperties()
		props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))
		
		# Create the new RenderConfig
		self.config = pyluxcore.RenderConfig(props, self.scene)
		
		# Re-start the rendering
		self.session = pyluxcore.RenderSession(self.config)
		self.session.Start()
		print("PathCPU selected")
Esempio n. 17
0
	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)
Esempio n. 18
0
    def test_Property_GetTypes(self):
        prop = pyluxcore.Property("test1.prop1", "aa")

        prop.Set(0, True)
        self.assertEqual(prop.GetBool(), True)
        prop.Set(0, 123)
        self.assertEqual(prop.GetInt(), 123)
        prop.Set(0, 123.45)
        self.assertEqual(prop.GetFloat(), 123.45)
        prop.Set(0, "abc")
        self.assertEqual(prop.GetString(), "abc")

        prop.Clear().Add([True, False])
        self.assertEqual(prop.GetBools(), [True, False])
        prop.Clear().Add([123, 456])
        self.assertEqual(prop.GetInts(), [123, 456])
        prop.Clear().Add([123.45, 678.9])
        self.assertEqual(prop.GetFloats(), [123.45, 678.9])
        prop.Clear().Add(["abc", "def"])
        self.assertEqual(prop.GetStrings(), ["abc", "def"])
Esempio n. 19
0
def TestSceneEditRendering(cls, params):
    engineType = params[0]
    samplerType = params[1]

    # Create the rendering configuration
    props = pyluxcore.Properties(LuxCoreTest.customConfigProps)
    props.SetFromFile("resources/scenes/simple/simple.cfg")

    # Set the rendering engine
    props.Set(GetEngineProperties(engineType))
    # Set the sampler (if required)
    if samplerType:
        props.Set(pyluxcore.Property("sampler.type", samplerType))

    config = pyluxcore.RenderConfig(props)

    # Run the rendering
    StandardAnimTest(
        cls, "SceneEditRendering_" + engineType + ("" if not samplerType else
                                                   ("_" + samplerType)),
        config, 5)
Esempio n. 20
0
def ExtractConfiguration():
	print("Extracting Film configuration example (requires scenes directory)...")

	# Load the configuration from file
	props = pyluxcore.Properties("scenes/luxball/luxball-hdr-comp.cfg")

	# Change the render engine to PATHCPU
	props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))

	config = pyluxcore.RenderConfig(props)
	session = pyluxcore.RenderSession(config)

	# Extract the RenderConfig properties (redundant here)
	props = session.GetRenderConfig().GetProperties()
	
	ids = set()
	for i in props.GetAllUniqueSubNames("film.outputs"):
		if props.Get(i + ".type").GetString() == "MATERIAL_ID_MASK":
			ids.add(props.Get(i + ".id").GetInt())

	for i in ids:
		print("MATERIAL_ID_MASK ID => %d" % i)

	print("Done.")
Esempio n. 21
0
    def save_file(self):
        path = QFileDialog().getSaveFileName(self, u"Save as", (""), "*.cfg")

        fileName = path[0]
        if not fileName == "":
            if not fileName.endswith('cfg'):
                fileName = fileName + '.cfg'
            print(fileName)
            fi = QFileInfo(fileName)
            getName = fi.fileName()
            getDir = os.path.dirname(fileName)
            print(getName)
            print(getDir)

        self.configProps.Set(
            pyluxcore.Property("renderengine.type", ["FILESAVER"]))
        print("scene saved")
        self.configProps.SetFromString("""
        filesaver.format = "TXT"
        filesaver.renderengine.type = "PATHCPU"
        filesaver.directory = {dirt} 
        filesaver.filename ={cfgName}
        """.format(dirt="\"" + getDir + "/\"", cfgName=getName))
        self.render_image()
Esempio n. 22
0
def SaveResumeRenderingS():
	print("Save and Resume example (requires scenes directory)...")

	# Load the configuration from file
	props = pyluxcore.Properties("scenes/luxball/luxball-hdr.cfg")

	# Change the render engine to PATHCPU
	props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))

	config = pyluxcore.RenderConfig(props)
	session = pyluxcore.RenderSession(config)

	session.Start()

	startTime = time.time()
	for i in range(0, 3):
		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/3sec][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)))
	
	session.Pause()
	
	session.GetFilm().SaveOutput("test-save.png", pyluxcore.FilmOutputType.RGB_IMAGEPIPELINE, pyluxcore.Properties())

	# Save the session resume file
	session.SaveResumeFile("test.rsm")

	# Save the rendered image
	session.GetFilm().Save()
	
	# Stop the rendering
	session.Stop()
	
	# Resume rendering
	print("Resume rendering")

	(config, startState, startFilm) = pyluxcore.RenderConfig.LoadResumeFile("test.rsm")
	session = pyluxcore.RenderSession(config, startState, startFilm)
	
	session.Start()

	startTime = time.time()
	for i in range(0, 3):
		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/3sec][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)))
	
	session.GetFilm().SaveOutput("test-resume.png", pyluxcore.FilmOutputType.RGB_IMAGEPIPELINE, pyluxcore.Properties())
	session.Stop()
	
	print("Done.")
Esempio n. 23
0
def ImagePipelineEdit():
	print("Image pipeline editing examples (requires scenes directory)...")

	# Load the configuration from file
	props = pyluxcore.Properties("scenes/luxball/luxball-hdr.cfg")

	# Change the render engine to PATHCPU
	props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))

	config = pyluxcore.RenderConfig(props)
	session = pyluxcore.RenderSession(config)

	session.Start()

	startTime = time.time()
	imageSaved = False
	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/10sec][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 and not imageSaved:
			session.GetFilm().Save()
			os.rename("normal.png", "normal-edit1.png")
			
			# Define the new image pipeline
			props = pyluxcore.Properties()
			props.SetFromString("""
				film.imagepipeline.0.type = TONEMAP_REINHARD02
				film.imagepipeline.1.type = CAMERA_RESPONSE_FUNC
				film.imagepipeline.1.name = Ektachrome_320TCD
				film.imagepipeline.2.type = GAMMA_CORRECTION
				film.imagepipeline.2.value = 2.2
				""")
			session.Parse(props)

			# Change radiance group scale
#			props = pyluxcore.Properties()
#			props.SetFromString("""
#				film.radiancescales.0.rgbscale = 1.0 0.0 0.0
#				""")
#			session.Parse(props)

			imageSaved = True

		if elapsedTime > 10.0:
			# Time to stop the rendering
			break

	session.Stop()

	# Save the rendered image
	session.GetFilm().Save()
	os.rename("normal.png", "normal-edit2.png")

	print("Done.")
Esempio n. 24
0
def PropertiesTests():
	print("Properties examples...")
	prop = pyluxcore.Property("test1.prop1", 0)
	prop.Set(0, 3705339624)

	prop = pyluxcore.Property("test1.prop1", 3705339624)
	print("test1.prop1 => %s\n" % prop.GetInt(0))

	prop = pyluxcore.Property("test1.prop1", "aa")
	print("test1.prop1 => %s\n" % prop.GetString(0))

	prop.Clear().Add([0, 2]).Add([3])
	prop.Set(0, 1)
	print("[%s]\n" % prop.ToString())

	print("[%s]\n" % pyluxcore.Property("test1.prop1").Add([1, 2, 3]).Add([1.0, 2.0, 3.0]))

	prop.Set([3, 2, 1])
	print("[%s]\n" % prop.ToString())

	pyvariable = 999
	prop = pyluxcore.Property("test1.prop1", [True, 1, 2.0, "aa", pyvariable])
	print("[%s]" % prop)
	print("Size: %d" % prop.GetSize())
	print("List: %s" % str(prop.Get()))
	print("[0]: %s" % prop.GetString())
	print("[1]: %d\n" % prop.GetInt(1))

	props = pyluxcore.Properties()
	props.SetFromString("test1.prop1 = 1 2.0 aa \"quoted\"\ntest2.prop2 = 1 2.0 'quoted' bb\ntest2.prop3 = 1")
	print("[\n%s]\n" % props)

	print("%s" % props.GetAllNames())
	print("%s" % props.GetAllNames("test1"))
	print("%s\n" % props.GetAllUniqueSubNames("test2"))

	props0 = pyluxcore.Properties()
	props1 = pyluxcore.Properties() \
		.Set(pyluxcore.Property("test1.prop1", [True, 1, 2.0, "aa"])) \
		.Set(pyluxcore.Property("test2.prop1", ["bb"]));

	props0.Set(props1, "prefix.")
	print("[\n%s]\n" % props0)

	print("Get: %s" % props0.Get("prefix.test1.prop1"))
	print("Get default: %s\n" % props0.Get("doesnt.exist", ["default_value0", "default_value1"]))

	blob = bytearray(100)
	for i in range(0, len(blob)):
		blob[i] = i
	prop = pyluxcore.Property("test.blob", [blob])
	prop.Add([[1, 2, 3]])

	blob2 = prop.GetBlob()
	print("Blob [0]:", end="")
	for i in range(0, len(blob2)):
		print(" %d" % blob2[i], end="")
	print("")

	blob2 = prop.GetBlob(1)
	print("Blob [1]:", end="")
	for i in range(0, len(blob2)):
		print(" %d" % blob2[i], end="")
	print("\n")

	a = array('f', [1.0, 2.0, 3.0])
	prop = pyluxcore.Property("test.array", [])
	prop.AddAllFloat(a)
	print("Array: ", end="")
	for i in range(3):
		print(" %f" % prop.GetFloat(i), end="")
	print("")

	a =[1.0, 2.0, 3.0]
	prop = pyluxcore.Property("test.array", [])
	prop.AddAllFloat(a)
	print("List: ", end="")
	for i in range(3):
		print(" %f" % prop.GetFloat(i), end="")
	print("")

	print("")
	size = 2000000
	a = array('f', [i for i in range(size)])
	prop = pyluxcore.Property("test.array", [])
	
	start = Clock()
	for i in range(size):
		prop.Add([a[i]])
	end = Clock()
	print("Add test: %.2gs" % (end-start))

	prop = pyluxcore.Property("test.array", [])
	
	start = Clock()
	prop.AddAllFloat(a)
	end = Clock()
	print("AddAll test: %.2gs" % (end-start))
	
	prop = pyluxcore.Property("test.array", [])
	
	start = Clock()
	prop.AddAllFloat(a, 3, 1)
	end = Clock()
	print("AddAllStride test: %.2gs" % (end-start))
Esempio n. 25
0
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.")
Esempio n. 26
0
def GetOutputTest():
	print("Film getOutput() example (requires scenes directory)...")

	# Load the configuration from file
	props = pyluxcore.Properties("scenes/luxball/luxball-hdr.cfg")

	# Change the render engine to PATHCPU
	props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))

	config = pyluxcore.RenderConfig(props)
	session = pyluxcore.RenderSession(config)

	# NOTICE THE DIFFERENT BEHAVIOR REQUIRED BY PYTHON 3.3, 2.7 and 2.6
	filmWidth, filmHeight = config.GetFilmSize()[:2]
	if sys.version_info < (2,7,0):
		imageBufferFloat = bytearray(filmWidth * filmHeight * 3 * 4)
		imageBufferUChar = bytearray(filmWidth * filmHeight * 4)
	elif sys.version_info < (3,0,0):
		imageBufferFloat = buffer(array('f', [0.0] * (filmWidth * filmHeight * 3)))
		imageBufferUChar = buffer(array('B', [0] * (filmWidth * filmHeight * 4)))
	else:
		imageBufferFloat = array('f', [0.0] * (filmWidth * filmHeight * 3))
		imageBufferUChar = array('B', [0] * (filmWidth * filmHeight * 4))

	session.Start()

	startTime = time.time()
	imageIndex = 0
	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)))

		# This is mostly for testing the PyLuxCore functionality, save an image every second

		# Update the image
		session.GetFilm().GetOutputFloat(pyluxcore.FilmOutputType.RGB_IMAGEPIPELINE, imageBufferFloat)
		pyluxcore.ConvertFilmChannelOutput_3xFloat_To_4xUChar(filmWidth, filmHeight,
			imageBufferFloat, imageBufferUChar, False)

		# Save the imageBufferUChar buffer to a PPM file
		imageFileName = "image" + str(imageIndex) + ".ppm"
		print("Saving image file: " + imageFileName)
		f = open(imageFileName, "w")
		f.write("P3\n")
		f.write(str(filmWidth) + " " + str(filmHeight) + "\n")
		f.write("255\n")
		for i in range(0, len(imageBufferUChar), 4):
			f.write(str(imageBufferUChar[i + 2]) + " " + str(imageBufferUChar[i + 1]) + " " + str(imageBufferUChar[i]) + "\n")
		f.close()
		imageIndex += 1

		if elapsedTime > 5.0:
			# Time to stop the rendering
			break

	session.Stop()

	print("Done.")
Esempio n. 27
0
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.")
Esempio n. 28
0
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
Esempio n. 29
0
	def luxBallShapeToggle(self):
		# Begin scene editing
		self.session.BeginSceneEdit()

		# I delete and re-create the LuxBall to reset objects position in
		# case they have been moved

		# Delete the LuxBall
		self.scene.DeleteObject("luxtext")
		self.scene.DeleteObject("luxinner")
		self.scene.DeleteObject("luxshell")
		self.scene.RemoveUnusedMeshes()

		# Re-create the LuxBall inner and text
		sceneProps = pyluxcore.Properties("scenes/luxball/luxball-hdr.scn")
		self.scene.Parse(sceneProps.GetAllProperties("scene.objects.luxtext"))
		self.scene.Parse(sceneProps.GetAllProperties("scene.objects.luxinner"))

		# Re-create the LuxBall shape
		if self.luxBallShapeIsCube:
			self.scene.Parse(sceneProps.GetAllProperties("scene.objects.luxshell").
				Set(pyluxcore.Property("scene.objects.luxshell.ply", ["scenes/luxball/luxball-shell.ply"])))
			self.luxBallShapeIsCube = False
		else:
			self.scene.DefineMesh("LuxCubeMesh", [
				# Bottom face
				(-0.405577, -0.343839, 0.14),
				(-0.405577, 0.506553, 0.14),
				(0.443491, 0.506553, 0.14),
				(0.443491, -0.343839, 0.14),
				# Top face
				(-0.405577, -0.343839, 0.819073),
				(0.443491, -0.343839, 0.819073),
				(0.443491, 0.506553, 0.819073),
				(-0.405577, 0.506553, 0.819073),
				# Side left
				(-0.405577, -0.343839, 0.14),
				(-0.405577, -0.343839, 0.819073),
				(-0.405577, 0.506553, 0.819073),
				(-0.405577, 0.506553, 0.14),
				# Side right
				(0.443491, -0.343839, 0.14),
				(0.443491, 0.506553, 0.14),
				(0.443491, 0.506553, 0.819073),
				(0.443491, -0.343839, 0.819073),
				# Side back
				(-0.405577, -0.343839, 0.14),
				(0.443491, -0.343839, 0.14),
				(0.443491, -0.343839, 0.819073),
				(-0.405577, -0.343839, 0.819073),
				# Side front
				(-0.405577, 0.506553, 0.14),
				(-0.405577, 0.506553, 0.819073),
				(0.443491, 0.506553, 0.819073),
				(0.443491, 0.506553, 0.14)], [
				# Bottom face
				(0, 1, 2), (2, 3, 0),
				# Top face
				(4, 5, 6), (6, 7, 4),
				# Side left
				(8, 9, 10), (10, 11, 8),
				# Side right
				(12, 13, 14), (14, 15, 12),
				# Side back
				(16, 17, 18), (18, 19, 16),
				# Side back
				(20, 21, 22), (22, 23, 20)
				], None, [
				# Bottom face
				(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0),
				# Top face
				(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0),
				# Side left
				(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0),
				# Side right
				(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0),
				# Side back
				(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0),
				# Side front
				(0.0, 0.0),(1.0, 0.0), (1.0, 1.0),	(0.0, 1.0)
				], None, None)
			self.scene.Parse(sceneProps.GetAllProperties("scene.objects.luxshell").
				Set(pyluxcore.Property("scene.objects.luxshell.ply", ["LuxCubeMesh"])))
			self.luxBallShapeIsCube = True

		# End scene editing
		self.session.EndSceneEdit()
Esempio n. 30
0
def PropertiesTests():
    print("Properties examples...")
    prop = pyluxcore.Property("test1.prop1", "aa")
    print("test1.prop1 => %s\n" % prop.GetString(0))

    prop.Clear().Add([0, 2]).Add([3])
    prop.Set(0, 1)
    print("[%s]\n" % prop.ToString())

    print(
        "[%s]\n" %
        pyluxcore.Property("test1.prop1").Add([1, 2, 3]).Add([1.0, 2.0, 3.0]))

    prop.Set([3, 2, 1])
    print("[%s]\n" % prop.ToString())

    pyvariable = 999
    prop = pyluxcore.Property("test1.prop1", [True, 1, 2.0, "aa", pyvariable])
    print("[%s]" % prop)
    print("Size: %d" % prop.GetSize())
    print("List: %s" % str(prop.Get()))
    print("[0]: %s" % prop.GetString())
    print("[1]: %d\n" % prop.GetInt(1))

    props = pyluxcore.Properties()
    props.SetFromString(
        "test1.prop1 = 1 2.0 aa \"quoted\"\ntest2.prop2 = 1 2.0 'quoted' bb\ntest2.prop3 = 1"
    )
    print("[\n%s]\n" % props)

    print("%s" % props.GetAllNames())
    print("%s" % props.GetAllNames("test1"))
    print("%s\n" % props.GetAllUniqueSubNames("test2"))

    props0 = pyluxcore.Properties()
    props1 = pyluxcore.Properties() \
     .Set(pyluxcore.Property("test1.prop1", [True, 1, 2.0, "aa"])) \
     .Set(pyluxcore.Property("test2.prop1", ["bb"]))

    props0.Set(props1, "prefix.")
    print("[\n%s]\n" % props0)

    print("Get: %s" % props0.Get("prefix.test1.prop1"))
    print("Get default: %s\n" %
          props0.Get("doesnt.exist", ["default_value0", "default_value1"]))

    blob = bytearray(100)
    for i in range(0, len(blob)):
        blob[i] = i
    prop = pyluxcore.Property("test.blob", [blob])
    prop.Add([[1, 2, 3]])

    blob2 = prop.GetBlob()
    print("Blob [0]:", end="")
    for i in range(0, len(blob2)):
        print(" %d" % blob2[i], end="")
    print("")

    blob2 = prop.GetBlob(1)
    print("Blob [1]:", end="")
    for i in range(0, len(blob2)):
        print(" %d" % blob2[i], end="")
    print("\n")