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
def generate(self): for shader in self.shaders.keys(): assignation = tdLib.getShaderAssignation(shader) filename = self.assetName.upper() + '_' + shader + '_Small.tga' fullpath = os.path.join(self.exportPath, filename) text = create_text_image(fullpath, self.assetName, shader, 1024, self.fillColor) texture, placed2dtexture = tdLib.createFileNode() cmds.connectAttr(texture + '.outColor', shader + '.color', force=True) cmds.setAttr(texture + '.fileTextureName', fullpath, type='string') self.shaders[shader] = [assignation, fullpath, texture, placed2dtexture]
def generate(self): for shader in self.shaders.keys(): assignation = tdLib.getShaderAssignation(shader) filename = self.assetName.upper() + '_' + shader + '_Small.tga' fullpath = os.path.join(self.exportPath, filename) text = create_text_image(fullpath, self.assetName, shader, 1024, self.fillColor) texture, placed2dtexture = tdLib.createFileNode() cmds.connectAttr(texture + '.outColor', shader + '.color', force=True) cmds.setAttr(texture + '.fileTextureName', fullpath, type='string') self.shaders[shader] = [ assignation, fullpath, texture, placed2dtexture ]
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