Esempio n. 1
0
def mapSceneLighting(scn, progressCallback = None):
    """
    Create a lightmap for a scene with one or multiple lights.
    """
    def progress(prog):
        if (progressCallback is not None):
            progressCallback(prog)
        else:
            pass

    humanRot = gui3d.app.selectedHuman.getRotation()
    def calcLightPos(light):
        return tuple(
            matrix.transform3(
                matrix.rotx(-humanRot[0]) *
                matrix.roty(-humanRot[1]) *
                matrix.rotz(-humanRot[2]),
                light.position))

    lnum = float(len(scn.lights))
    if (lnum>0):    # Add up all the lightmaps.
        lmap = mapLighting(calcLightPos(scn.lights[0]),
                           lambda p: progress(p/lnum)).data
        i = 1.0        
        for light in scn.lights[1:]:
            lmap = image_operations.mixData(
                lmap, mapLighting(calcLightPos(light),
                                  lambda p: progress((i+p)/lnum)).data,1,1)       
            i += 1.0

        return mh.Image(data = image_operations.normalizeData(lmap))
    else:   # If the scene has no lights, return an empty lightmap.
        return mh.Image(data = np.zeros((1024, 1024, 1), dtype=np.uint8))
Esempio n. 2
0
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
Esempio n. 3
0
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