Exemple #1
0
    def executeMayabatch(self):
        """The final method used to bake the textures on the deported machine.
        It will only bake the shaders in self.toBake if there is any (if a shader is selected in the UI for example),
        otherwise it will bake all the shaders added.
        """
        tdLib.loadPlugin('Turtle')
        for shader in self.toBake or self.shaders:
            print 'SHADER NAME: ', shader
            print 'SHADER MODE: ', shader.mode
            print 'Render Attr: ', shader.renderAttr
            print 'Shader Attr: ', shader.shaderAttr
        # Assign surfaceshader noir sur tous les meshes ?

        for shader in self.toBake or self.shaders:
            for udim in shader.udims:
                filename = '{}.10{}{}.tga'.format(shader.fileName, udim[1],
                                                  udim[0] + 1)
                cmd = self.constructTurtleCommand(shader, udim, filename)
                tdLib.createDir(shader.texturePath)  # Create directory?
                self.bakeShader(shader, cmd)
                fullpath = tdLib.normpath(
                    os.path.join(shader.texturePath, filename))
                self.result.append(
                    '<a href="file://{0}" {1}>{0}</a> - <a href="rvlink://{0}" {1}>Open in RV</a>'
                    .format(fullpath, 'style="text-decoration: none"'))

        print '<br />'.join(
            self.result
        )  # This is used by the Mayabatch lib to send the result by mail.
Exemple #2
0
 def preview(self, shaders):
     for shader in shaders[::-1]:
         try:
             for udim in shader.udims:
                 filename = '{}.10{}{}.tga'.format(shader.fileName, udim[1], udim[0]+1)
                 cmd = self.constructTurtleCommand(shader, udim, filename, '/tmp', self.dividor)
                 logger.debug(cmd)
                 self.bakeShader(shader, cmd)
             pattern = '-directory \"(.*?)\" -fileName \"(.*?)\"'
             reg = re.search(pattern, cmd)
             path = tdLib.normpath(os.path.join(reg.group(1), reg.group(2)))
             nodeFile, placement = tdLib.createFileNode()
             cmds.setAttr('{}.fileTextureName'.format(nodeFile), path, type="string")
             cmds.setAttr('{}.uvTilingMode'.format(nodeFile), 3)
             cmds.setAttr('{}.uvTileProxyGenerate'.format(nodeFile), 1)
             cmds.connectAttr(nodeFile + '.outColor', shader.name + '.color', force=True)
         except ZeroDivisionError:
             self.render(shader)
         except UnboundLocalError:
             logger.warning('No UDIMs in the shader.')
         except RuntimeError as e:
             if 'cannot be connected to' in repr(e):
                 cmds.connectAttr(nodeFile + '.output3D', shader.name + '.outColor', force=True)
             if 'The destination attribute' in repr(e):
                 cmds.connectAttr(nodeFile + '.outColor', shader.name + '.outColor', force=True)
             elif 'No object matches name: {}.uvTilingMode'.format(nodeFile) in repr(e):
                 # This is used for Maya version < 2015. You could use a plusMinusAverage node instead and several file nodes to have the same effect.
                 # This old method does not displays the textures in the UV editor, but it works great in the viewport 1 unlike the current method.
                 # See revision 3897 to activate this old mode by uncommenting the code
                 pass
             else:
                 raise e
Exemple #3
0
 def setPreset(self, preset):
     # self._preset = preset
     try:
         cmds.select('TurtleRenderOptions')
         path = os.path.join(os.path.split(__file__)[0], 'presets', '{}.mel'.format(preset))
         path = tdLib.normpath(path)
         mel.eval('source "{}"'.format(path))
     except ValueError:
         pass
Exemple #4
0
 def setPreset(self, preset):
     # self._preset = preset
     try:
         cmds.select('TurtleRenderOptions')
         path = os.path.join(
             os.path.split(__file__)[0], 'presets', '{}.mel'.format(preset))
         path = tdLib.normpath(path)
         mel.eval('source "{}"'.format(path))
     except ValueError:
         pass
Exemple #5
0
 def constructTurtleCommand(self, shader, udim, filename, forcePath=None, dividor=1):
     directory = shader.texturePath
     if forcePath:
         directory = tdLib.normpath(forcePath)
     resolution = int(shader.renderAttr['resolution'] / dividor)
     alpha = shader.renderAttr['alpha']
     merge = shader.renderAttr['merge']
     bilinear = shader.renderAttr['tbBilinearFilter']
     edgeDilation = shader.renderAttr['tbEdgeDilation']
     UvRange = shader.renderAttr['tbUvRange']
     Umin, Vmin = udim
     cmd = 'ilrTextureBakeCmd '
     for shape in shader.shapes:
         cmd = cmd + '-target "%s" ' % shape
     cmd = cmd + '-camera "persp" -directory "%s" -fileName "%s" -width %s -height %s -alpha %s -bilinearFilter %s -edgeDilation %s -merge %s -uvRange %s -uMin %s -uMax %s -vMin %s -vMax %s ' % (
                                   directory, filename, resolution, resolution, alpha, bilinear, edgeDilation, merge, UvRange, Umin, Umin + 1, Vmin, Vmin + 1)
     logger.debug(cmd)
     return cmd
Exemple #6
0
 def preview(self, shaders):
     for shader in shaders[::-1]:
         try:
             for udim in shader.udims:
                 filename = '{}.10{}{}.tga'.format(shader.fileName, udim[1],
                                                   udim[0] + 1)
                 cmd = self.constructTurtleCommand(shader, udim, filename,
                                                   '/tmp', self.dividor)
                 logger.debug(cmd)
                 self.bakeShader(shader, cmd)
             pattern = '-directory \"(.*?)\" -fileName \"(.*?)\"'
             reg = re.search(pattern, cmd)
             path = tdLib.normpath(os.path.join(reg.group(1), reg.group(2)))
             nodeFile, placement = tdLib.createFileNode()
             cmds.setAttr('{}.fileTextureName'.format(nodeFile),
                          path,
                          type="string")
             cmds.setAttr('{}.uvTilingMode'.format(nodeFile), 3)
             cmds.setAttr('{}.uvTileProxyGenerate'.format(nodeFile), 1)
             cmds.connectAttr(nodeFile + '.outColor',
                              shader.name + '.color',
                              force=True)
         except ZeroDivisionError:
             self.render(shader)
         except UnboundLocalError:
             logger.warning('No UDIMs in the shader.')
         except RuntimeError as e:
             if 'cannot be connected to' in repr(e):
                 cmds.connectAttr(nodeFile + '.output3D',
                                  shader.name + '.outColor',
                                  force=True)
             if 'The destination attribute' in repr(e):
                 cmds.connectAttr(nodeFile + '.outColor',
                                  shader.name + '.outColor',
                                  force=True)
             elif 'No object matches name: {}.uvTilingMode'.format(
                     nodeFile) in repr(e):
                 # This is used for Maya version < 2015. You could use a plusMinusAverage node instead and several file nodes to have the same effect.
                 # This old method does not displays the textures in the UV editor, but it works great in the viewport 1 unlike the current method.
                 # See revision 3897 to activate this old mode by uncommenting the code
                 pass
             else:
                 raise e
Exemple #7
0
    def executeMayabatch(self):
        """The final method used to bake the textures on the deported machine.
        It will only bake the shaders in self.toBake if there is any (if a shader is selected in the UI for example),
        otherwise it will bake all the shaders added.
        """
        tdLib.loadPlugin('Turtle')
        for shader in self.toBake or self.shaders:
            print 'SHADER NAME: ', shader
            print 'SHADER MODE: ', shader.mode
            print 'Render Attr: ', shader.renderAttr
            print 'Shader Attr: ', shader.shaderAttr
        # Assign surfaceshader noir sur tous les meshes ?

        for shader in self.toBake or self.shaders:
            for udim in shader.udims:
                filename = '{}.10{}{}.tga'.format(shader.fileName, udim[1], udim[0]+1)
                cmd = self.constructTurtleCommand(shader, udim, filename)
                tdLib.createDir(shader.texturePath) # Create directory?
                self.bakeShader(shader, cmd)
                fullpath = tdLib.normpath(os.path.join(shader.texturePath, filename))
                self.result.append('<a href="file://{0}" {1}>{0}</a> - <a href="rvlink://{0}" {1}>Open in RV</a>'.format(fullpath, 'style="text-decoration: none"'))

        print '<br />'.join(self.result) # This is used by the Mayabatch lib to send the result by mail.
Exemple #8
0
 def constructTurtleCommand(self,
                            shader,
                            udim,
                            filename,
                            forcePath=None,
                            dividor=1):
     directory = shader.texturePath
     if forcePath:
         directory = tdLib.normpath(forcePath)
     resolution = int(shader.renderAttr['resolution'] / dividor)
     alpha = shader.renderAttr['alpha']
     merge = shader.renderAttr['merge']
     bilinear = shader.renderAttr['tbBilinearFilter']
     edgeDilation = shader.renderAttr['tbEdgeDilation']
     UvRange = shader.renderAttr['tbUvRange']
     Umin, Vmin = udim
     cmd = 'ilrTextureBakeCmd '
     for shape in shader.shapes:
         cmd = cmd + '-target "%s" ' % shape
     cmd = cmd + '-camera "persp" -directory "%s" -fileName "%s" -width %s -height %s -alpha %s -bilinearFilter %s -edgeDilation %s -merge %s -uvRange %s -uMin %s -uMax %s -vMin %s -vMax %s ' % (
         directory, filename, resolution, resolution, alpha, bilinear,
         edgeDilation, merge, UvRange, Umin, Umin + 1, Vmin, Vmin + 1)
     logger.debug(cmd)
     return cmd