def mapSceneLighting(scn, object=None, res=(1024, 1024), border=1): """ Create a lightmap for a scene with one or multiple lights. This happens by adding the lightmaps produced by each light, plus the scene ambience. """ if object is None: object = G.app.selectedHuman objrot = G.app.modelCamera.getRotation() def calcLightPos(light): return tuple( matrix.transform3( matrix.rotx(-objrot[0]) * matrix.roty(-objrot[1]) * matrix.rotz(-objrot[2]), light.position)) def getLightmap(light): lmap = mapLighting(calcLightPos(light), object.mesh, res, border) return image_operations.Image(data=lmap.data * light.color.values) progress = Progress(1 + len(scn.lights)) # Ambience lmap = image_operations.colorAsImage( (scn.environment.ambience * object.material.diffuseColor).values, None, *res) if (object.material.shaderConfig['ambientOcclusion'] and not object.material.aoMapTexture is None): aomap = image_operations.Image(data=object.material.aoMapTexture) aomap = image_operations.resized(aomap, *lmap.size) lmap = image_operations.multiply( lmap, image_operations.mix(aomap, image_operations.getWhite(lmap), object.material.aoMapIntensity)) progress.step() # Lights if (scn.lights): amb = lmap lmap = getLightmap(scn.lights[0]).data progress.step() for light in scn.lights[1:]: lmap = image_operations.mixData(lmap, getLightmap(light).data, 1, 1) progress.step() lmap = image_operations.Image(data=lmap) if len(scn.lights) > 1: lmap = image_operations.normalize(lmap) # Ambience calculation function: lmap = lmap + (1 - lmap) * amb lmap = image_operations.mix( lmap, image_operations.multiply(image_operations.invert(lmap), amb), 1, 1) return lmap
def mapSceneLighting(scn, object = None, res = (1024, 1024), border = 1): """ Create a lightmap for a scene with one or multiple lights. This happens by adding the lightmaps produced by each light, plus the scene ambience. """ if object is None: object = G.app.selectedHuman objrot = G.app.modelCamera.getRotation() def calcLightPos(light): return tuple( matrix.transform3( matrix.rotx(-objrot[0]) * matrix.roty(-objrot[1]) * matrix.rotz(-objrot[2]), light.position)) def getLightmap(light): lmap = mapLighting(calcLightPos(light), object.mesh, res, border) return image_operations.Image(data = lmap.data * light.color.values) progress = Progress(1 + len(scn.lights)) # Ambience lmap = image_operations.colorAsImage( (scn.environment.ambience * object.material.diffuseColor).values, None, *res) if (object.material.shaderConfig['ambientOcclusion'] and not object.material.aoMapTexture is None): aomap = image_operations.Image(data = object.material.aoMapTexture) aomap = image_operations.resized(aomap, *lmap.size) lmap = image_operations.multiply(lmap, image_operations.mix( aomap, image_operations.getWhite(lmap), object.material.aoMapIntensity)) progress.step() # Lights if scn.lights: amb = lmap lmap = getLightmap(scn.lights[0]).data progress.step() for light in scn.lights[1:]: lmap = image_operations.mixData(lmap, getLightmap(light).data, 1, 1) progress.step() lmap = image_operations.Image(data = lmap) if len(scn.lights) > 1: lmap = image_operations.normalize(lmap) # Ambience calculation function: lmap = lmap + (1 - lmap) * amb lmap = image_operations.mix( lmap, image_operations.multiply( image_operations.invert(lmap), amb), 1, 1) return lmap