Ejemplo n.º 1
0
 def create(self):
     values = None
     if self.material:
         # Material params have precedence over declarations in shader code
         params = self.material.shaderParameters
         values = params.get(self.uniform.name)
     if values is None:
         values = np.atleast_2d(self.uniform.values)
     else:
         values = np.atleast_2d(values)
     rows, cols = values.shape
     self.widgets = []
     for row in range(rows):
         widgets = []
         for col in range(cols):
             child = self.createWidget(values[row,col], row)
             self.addWidget(child, row, col)
             widgets.append(child)
         self.widgets.append(widgets)
     if self.uniform.pytype == float and rows == 1 and cols in [3, 4]:
         self.colorPicker = gui.ColorPickButton(material.Color().copyFrom(values[0,:3]))
         @self.colorPicker.mhEvent
         def onClicked(color):
             for idx,widget in enumerate(self.widgets[0][:3]):
                 widget.setValue(color.asTuple()[idx])
             self.callEvent('onActivate', color)
         self.addWidget(self.colorPicker, 1, 0)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def __init__(self, human):
        self.human = human
        self.skinCache = { 'caucasian' : image.Image(getSysDataPath('litspheres/skinmat_caucasian.png')),
                           'african'   : image.Image(getSysDataPath('litspheres/skinmat_african.png')),
                           'asian'     : image.Image(getSysDataPath('litspheres/skinmat_asian.png')) }
        self._previousEthnicState = [0, 0, 0]

        self._litsphereTexture = None
        self._diffuseColor = material.Color()

        self.checkUpdate()
Ejemplo n.º 4
0
 def onActivate(self, arg=None):
     values = [[widget.value for widget in widgets]
               for widgets in self.widgets]
     if self.colorPicker:
         self.colorPicker.setColor(material.Color().copyFrom(values[0][:3]))
     if len(self.uniform.dims) == 1:
         values = values[0]
         if self.uniform.dims == (1, ) and self.uniform.pytype == str:
             values = values[0]
             if not os.path.isfile(values):
                 return
     self.material.setShaderParameter(self.uniform.name, values)
Ejemplo n.º 5
0
 def getValue(self):
     return material.Color().copyFrom([widget.value for widget in self.widgets])