122 lines
5.4 KiB
Python
122 lines
5.4 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# @Site : CGNICO Games
|
|
# @Author : Cai Jianbo
|
|
|
|
import xgenm as xg
|
|
import xgenm.xgGlobal as xgg
|
|
import xgenm.XgExternalAPI as xge
|
|
import maya.cmds as cmds
|
|
# Define default values for hair width
|
|
hairwidth = 0.1000
|
|
hairwidthmax = 0.5000
|
|
hairwidthmin = 0.0050
|
|
hairwithstep = 0.0001
|
|
# Define window function
|
|
def create_window():
|
|
global hairwidth
|
|
global hairwidthmax
|
|
global hairwidthmin
|
|
global hairwithstep
|
|
# Create window
|
|
window = cmds.window(title="Hair Width", iconName='Hair Width', widthHeight=(600, 100))
|
|
# Create window layout
|
|
cmds.columnLayout(adjustableColumn=True)
|
|
# Create min and max input fields, editable, set min and max values
|
|
cmds.floatFieldGrp('SetMinMax', label='Set Min and Max', numberOfFields=2, value1=hairwidthmin, value2=hairwidthmax, changeCommand=update)
|
|
# Create Hair Width slider, set min and max values, step, set slider value
|
|
cmds.floatSliderGrp('SetHairWidth', label='Set Hair Width', field=True, minValue=hairwidthmin, maxValue=hairwidthmax, fieldMinValue=hairwidthmin, fieldMaxValue=hairwidthmax, value=hairwidth, step=hairwithstep, changeCommand=update)
|
|
# Set width expression
|
|
set_width_expression(hairwidth)
|
|
# Show window
|
|
cmds.showWindow(window)
|
|
# Define update function
|
|
def update(*args):
|
|
# Get parameters
|
|
hairwidthmin = cmds.floatFieldGrp('SetMinMax', query=True, value1=True)
|
|
hairwidthmax = cmds.floatFieldGrp('SetMinMax', query=True, value2=True)
|
|
hairwidth = cmds.floatSliderGrp('SetHairWidth', query=True, value=True)
|
|
# Define rules for min and max range
|
|
if hairwidthmin > hairwidthmax:
|
|
hairwidthmin = hairwidthmax
|
|
elif hairwidthmax < hairwidthmin:
|
|
hairwidthmax = hairwidthmin
|
|
elif hairwidthmin == hairwidthmax:
|
|
hairwidthmax = hairwidthmin + 0.0001
|
|
# Ensure min and max input fields are between 0 and 1
|
|
if hairwidthmin < 0:
|
|
hairwidthmin = 0
|
|
if hairwidthmax < 0:
|
|
hairwidthmax = 0
|
|
if hairwidthmin > 1:
|
|
hairwidthmin = 1
|
|
if hairwidthmax > 1:
|
|
hairwidthmax = 1
|
|
# Ensure slider value is between min and max
|
|
if hairwidth < hairwidthmin:
|
|
hairwidth = hairwidthmin
|
|
elif hairwidth > hairwidthmax:
|
|
hairwidth = hairwidthmax
|
|
# Ensure slider value is positive
|
|
if hairwidth < 0:
|
|
hairwidth = 0
|
|
# Update UI
|
|
cmds.floatFieldGrp('SetMinMax', edit=True, value1=hairwidthmin, value2=hairwidthmax)
|
|
cmds.floatSliderGrp('SetHairWidth', edit=True, minValue=hairwidthmin, maxValue=hairwidthmax, fieldMinValue=hairwidthmin, fieldMaxValue=hairwidthmax, value=hairwidth)
|
|
# Set width expression
|
|
set_width_expression(hairwidth)
|
|
print("Set the Description Primitive Attributes : ")
|
|
print(" Min : " + str(hairwidthmin) + " Max : " + str(hairwidthmax) + " Width: " + str(hairwidth))
|
|
# Define function to set width expression
|
|
def set_width_expression(hairwidth):
|
|
hairwidthmin = cmds.floatFieldGrp('SetMinMax', query=True, value1=True)
|
|
hairwidthmax = cmds.floatFieldGrp('SetMinMax', query=True, value2=True)
|
|
hairwidth = cmds.floatSliderGrp('SetHairWidth', query=True, value=True)
|
|
# Convert hairwidth to string
|
|
hairwidth_str = str(hairwidth)
|
|
# Convert max and min values to string
|
|
hairwidthmax_str = str(hairwidthmax)
|
|
hairwidthmin_str = str(hairwidthmin)
|
|
# Get selected objects
|
|
selectedobject = cmds.ls(selection=True)
|
|
print(hairwidth)
|
|
if not selectedobject:
|
|
ERROR_MESSAGE = "No object selected"
|
|
cmds.warning(ERROR_MESSAGE)
|
|
cmds.confirmDialog(title='Warning', message=ERROR_MESSAGE, button=['OK'], defaultButton='OK')
|
|
else:
|
|
if xgg.Maya:
|
|
# Palette is collection, first get collections using palettes
|
|
palettes = xg.palettes()
|
|
# Filter selected palettes
|
|
palettes = [palette for palette in palettes if palette in selectedobject]
|
|
# Filter selected Descriptions
|
|
descriptions = xg.descriptions()
|
|
descriptions = [description for description in descriptions if description in selectedobject]
|
|
# Set new width expression
|
|
new_width_expression = "$a=", hairwidth_str + ";#" + hairwidthmax_str + "," + hairwidthmin_str
|
|
# When palettes is empty, filter parent collection of selected Description and add to palettes
|
|
if palettes == []:
|
|
# Filter selected Descriptions
|
|
for description in descriptions:
|
|
# Filter parent collection of selected Description
|
|
if description in selectedobject:
|
|
# Add parent collection of selected Description to palettes
|
|
palettes.append(xg.palette(description))
|
|
# Convert palettes to set to remove duplicates
|
|
palettes = list(set(palettes))
|
|
if palettes != [] and descriptions == []:
|
|
# Collection is selected
|
|
for palette in palettes:
|
|
# Get all Descriptions under the collection
|
|
descriptions = xg.descriptions(palette)
|
|
if palettes == [] and descriptions == []:
|
|
print("No xGen collection or description selected")
|
|
print("Current selected hair collection : " + str(palettes))
|
|
print("Current selected hair description : " + str(descriptions))
|
|
# Set width expression
|
|
|
|
|
|
# if __name__ == "__main__":
|
|
# create_window() |