The example Toy_Excavator.vpb on how to load lightmaps from a given folder or repath lightmaps to a different location can be found in the lightmaps folder of the example directory.
This code snippet is extracted from Toy_Excavator.vpb example, it shows how to find nodes with lightmaps and how to use the vrBakeService to repath them.
1 # Collect all nodes with a valid base or separate lightmap in subtree
2 def findNodesWithLightmapsRecursive(node, nodesWithLightmaps):
3 if type(node) is vrdGeometryNode:
4 textureBake = node.getTextureBake()
5 if textureBake.isValid():
6 lightmap = textureBake.getLightmap()
7 if lightmap.isValid():
8 nodesWithLightmaps.append(node)
9 for child in node.getChildren():
10 findNodesWithLightmapsRecursive(child, nodesWithLightmaps)
11
12 # These example lines are based on the Toy_Excavator.vpb scene, you will need to adapt the
13 # node names and the folder to your scene.
14 nodesWithLightmaps = []
15 findNodesWithLightmapsRecursive(vrNodeService.findNode("Toy_Excavator"), nodesWithLightmaps)
16
17 # Repathing to a folder with lightmaps for day scenario
18 vrBakeService.repathLightmaps(nodesWithLightmaps, getFileIOBaseDir() + "/BakingTextures_Day/")
19
20 # Repathing to a folder with lightmaps for night scenario
21 vrBakeService.repathLightmaps(nodesWithLightmaps, getFileIOBaseDir() + "/BakingTextures_Night/")
22
This code snippet is extracted from Toy_Excavator.vpb example, it shows how to use the vrBakeService to load lightmaps.
1 import re
2 import os
3
4 # Loading lightmaps from given path using the name of the specific node
5 def loadLightmapsByNodeName(nodesWithLightmaps, path):
6 for node in nodesWithLightmaps:
7 lightmapPaths = []
8 # Create path to lightmap image
9 baseLightmapPath = path + node.getName() + "_Lightmap" + ".exr"
10 if os.path.isfile(baseLightmapPath):
11 lightmapPaths.append(baseLightmapPath)
12 # Check if there is a corresponding separate lightmap, e.g.
13 separateLightmapPath = path + node.getName() + "_SeparateLightmap" + ".exr"
14 # The separate lightmap is optional. Only add the path if the file exists
15 if os.path.isfile(separateLightmapPath):
16 lightmapPaths.append(separateLightmapPath)
17 # For this node load the given files
18 vrBakeService.loadLightmaps([node], lightmapPaths)
19 else:
20 print("Could not find base lightmap file:" + baseLightmapPath)
21
22 # Loading lightmaps from given path using the name of the specific lightmap.
23 # This can also be used if multiple nodes share the same name
24 def loadLightmapsByLightmapName(nodesWithLightmaps, path):
25 for node in nodesWithLightmaps:
26 lightmapPaths = []
27 baseLightmap = node.getTextureBake().getBaseLightmap()
28 # We can only use the lightmap name if we have a valid lightmap
29 if baseLightmap.isValid():
30 # Create path to lightmap image
31 baseLightmapPath = path + baseLightmap.getName() + ".exr"
32 if os.path.isfile(baseLightmapPath):
33 lightmapPaths.append(baseLightmapPath)
34 # Check if there is a corresponding separate lightmap, same filename but with "_SeparateLightmap"
35 separateLightmapPath = re.sub(r"_Lightmap([0-9]*)\.exr",r"_SeparateLightmap\1.exr",baseLightmapPath)
36 # The separate lightmap is optional. Only add the path if the file exists
37 if os.path.isfile(separateLightmapPath):
38 lightmapPaths.append(separateLightmapPath)
39 # For this node load the given files
40 vrBakeService.loadLightmaps([node], lightmapPaths)
41 else:
42 print("Could not find base lightmap file:" + baseLightmapPath)
43
44
45 # These example lines are based on the Toy_Excavator.vpb scene, you will need to adapt the
46 # node names and the folder to your scene.
47
48 # Load by node name. Node names have to be unique.
49 loadLightmapsByLightmapName(vrNodeService.findNodes("Exhaust_Inner"), getFileIOBaseDir() + "/BakingTextures_Night/")
50
51 # Load by lightmap name Node names do not have to be unique, but lightmaps must be present
52 loadLightmapsByLightmapName(vrNodeService.findNodes("Exhaust_Inner"), getFileIOBaseDir() + "/BakingTextures_Day/")
53