Skip to content

Instantly share code, notes, and snippets.

@rBrenick
Created March 11, 2022 09:20
Show Gist options
  • Save rBrenick/a53d9a730526a9dee49ed2c5fe0d13d1 to your computer and use it in GitHub Desktop.
Save rBrenick/a53d9a730526a9dee49ed2c5fe0d13d1 to your computer and use it in GitHub Desktop.
Find all textures in the maya scene, and create a low res proxy using Qt
import os
import pymel.core as pm
import json
from PySide2 import QtCore, QtGui
def generate_lowres_textures(output_textures_folder, new_size=1024):
"""
generate lowres textures from those found in the maya scene
"""
generated_texture_paths = []
for file_node in pm.ls(type="file"):
texture_path = file_node.fileTextureName.get()
texture_name = os.path.splitext(os.path.basename(texture_path))[0]
lowres_tex_path = os.path.join(output_textures_folder, "LowRes_{}.png".format(texture_name))
# resave in scaled format
pixmap = QtGui.QPixmap(texture_path)
pixmap = pixmap.scaled(new_size, new_size, QtCore.Qt.KeepAspectRatio)
pixmap.save(lowres_tex_path)
# apply on file node
file_node.fileTextureName.set(lowres_tex_path)
generated_texture_paths.append(lowres_tex_path)
return generated_texture_paths
generated_texture_paths = generate_lowres_textures(r"D:\SomeRandomFolder\LowResTextures")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment