def update(self):
        caucasianWeight = self.human.getCaucasian()
        africanWeight   = self.human.getAfrican()
        asianWeight     = self.human.getAsian()
        blends = []

        # Set litsphere texture
        if caucasianWeight > 0:
            blends.append( ('caucasian', caucasianWeight) )
        if africanWeight > 0:
            blends.append( ('african', africanWeight) )
        if asianWeight > 0:
            blends.append( ('asian', asianWeight) )

        if len(blends) == 1:
            img = self.skinCache[blends[0][0]]
            img.markModified()
        else:
            img = image_operations.mix(self.skinCache[blends[0][0]], self.skinCache[blends[1][0]], blends[0][1], blends[1][1])
            if len(blends) > 2:
                img = image_operations.mix(img, self.skinCache[blends[2][0]], 1.0, blends[2][1])

        # Set parameter so the image can be referenced when material is written to file (and texture can be cached)
        img.sourcePath = getSysDataPath("litspheres/adaptive_skin_tone.png")
        self._litsphereTexture = img

        # Set diffuse color
        diffuse = asianWeight     * asianColor   + \
                  africanWeight   * africanColor + \
                  caucasianWeight * caucasianColor
        self._diffuseColor = material.Color(diffuse)
示例#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
示例#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
    def getEthnicityBlendMaterial(self):
        caucasianWeight = self.human.getCaucasian()
        africanWeight   = self.human.getAfrican()
        asianWeight     = self.human.getAsian()
        blends = []

        if caucasianWeight > 0:
            blends.append( ('caucasian', caucasianWeight) )
        if africanWeight > 0:
            blends.append( ('african', africanWeight) )
        if asianWeight > 0:
            blends.append( ('asian', asianWeight) )

        if len(blends) == 1:
            return self.skinCache[blends[0][0]]
        else:
            img = image_operations.mix(self.skinCache[blends[0][0]], self.skinCache[blends[1][0]], blends[0][1], blends[1][1])
            if len(blends) > 2:
                img = image_operations.mix(img, self.skinCache[blends[2][0]], 1.0, blends[2][1])
            return img
示例#5
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

    lnum = float(len(scn.lights))
    if (lnum>0):    # Add up all the lightmaps.
        lmap = mapLighting(scn.lights[0].position, lambda p: progress(p/lnum))
        i = 1.0        
        for light in scn.lights[1:]:
            lmap = image_operations.mix(
                lmap, mapLighting(light.position, lambda p: progress((i+p)/lnum)),1,1)       
            i += 1.0
        return image_operations.clipped(lmap)
    else:   # If the scene has no lights, return an empty lightmap.
        return mh.Image(data = np.zeros((1024, 1024, 1), dtype=np.uint8))
示例#6
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

    lnum = float(len(scn.lights))
    if (lnum > 0):  # Add up all the lightmaps.
        lmap = mapLighting(scn.lights[0].position,
                           lambda p: progress(p / lnum))
        i = 1.0
        for light in scn.lights[1:]:
            lmap = image_operations.mix(
                lmap,
                mapLighting(light.position, lambda p: progress(
                    (i + p) / lnum)), 1, 1)
            i += 1.0
        return image_operations.clipped(lmap)
    else:  # If the scene has no lights, return an empty lightmap.
        return mh.Image(data=np.zeros((1024, 1024, 1), dtype=np.uint8))