XGen 으로 헤어를 만들다 보면, 앞머리/뒷머리/옆머리 등 부위별로 Description을 만들게 된다.
한두개 일 때는 XGen Editor에서 Description을 바꿔가며 작업해도 문제가 없지만, Description이 많아 질 수록 번거로워 질 수 밖에 없다.
특히, Batch 랜더를 위해 Description 별로 애니메이션 된 Curve Alembic Cache를 설정하고, 랜더러 및 랜더 설정을 Shot 마다 해 주려면 보통일이 아니다.
XGen API를 이용해서 위와 같은 번거로운 작업들을 처리할 수 있는 툴을 만들어 사용하면 편리하기에, 정리해 놓고자 한다.
setAttr / getAttr
아래와 같은 형식의 명령으로 XGen Editor의 내용을 수정하거나 값을 가져올 수 있다.
import xgenm as xg
xg.setAttr("attributeName", "value", "collectionName", "descriptionName", "ObjectName")
xg.getAttr("attributeName", "collectionName", "descriptionName", "ObjectName")
setAttr에서 값을 설정할 때, string 타입으로 값을 전달해야 하는 것에 주의한다.
값을 수정한 다음에는 아래의 코드를 실행해 주어야 반영된다.
import xgenm.xgGlobal as xgg
de = xgg.DescriptionEditor
de.refresh("Description")
Snippets
Primitives
import xgenm as xg
import xgenm.xgGlobal as xgg
de = xgg.DescriptionEditor
palette = "myCollection"
description = "myDescription"
## Generator Attributes ##
# Density
xg.setAttr("density", "200", palette, description, "RandomGenerator")
## Primitive Attributes ##
# Modifier CV Count
xg.setAttr("fxCVCount", "50", palette, description, "SplinePrimitive")
# Display Width
xg.setAttr("displayWidth", "True", palette, description, "SplinePrimitive")
# Tube Shade
xg.setAttr("tubeShade", "False", palette, description, "SplinePrimitive")
## Guide Animation ##
# Use Animation
xg.setAttr("useCache", "True", palette, description, "SplinePrimitive")
# Cache File Name
xg.setAttr("cacheFileName", "C:/Users/UserName/Documents/xgen/test.abc", palette, description, "SplinePrimitive")
# Live Mode
xg.setAttr("liveMode", "False", palette, description, "SplinePrimitive")
# Refresh description editor
de.refresh("Description")
Preview/Output
import xgenm as xg
import xgenm.xgGlobal as xgg
de = xgg.DescriptionEdito
palette = "myCollection"
description = "myDescription"
## Preview Settings ##
# Spline Segments
xg.setAttr("splineSegments", "2", palette, description, "GLRenderer")
## Output Settings ##
# Renderer
xg.setAttr("renderer", "Arnold Renderer", palette, description, "RendermanRenderer")
## Arnold Settings ##
# Render Mode
xg.setAttr("custom__arnold_rendermode", "1", palette, description, "RendermanRenderer") # 0: Live, 1: Batch Render
# Refresh description editor
de.refresh("Description")
Modifiers
import xgenm as xg
import xgenm.xgGlobal as xgg
de = xgg.DescriptionEditor
palette = "myCollection"
description = "myDescription"
# Get Cut1 modifier amount value
xg.getAttr("amount", palette, description, "Cut1")
# Deactivate Clumping1 modifier
xg.setAttr("active", "False", palette, description, "Clumping1")
# Refresh description editor
de.refresh("Description")
Object Attributes
Description Objects 는 SplinePrimitive, RandomGenerator, GLRenderer, RendermanRenderer 가 있다.
Modifiers Object 는 Modifier 이름과 같다.
Object 의 Attributes 를 알아내기 위해선 아래의 코드를 실행 한다.
import xgenm as xg
palette = "myCollection"
description = "myDescription"
# Get "SplinePrimitive" object attributes
xg.allAttrs(palette, description, "SplinePrimitive")
# Get "RandomGenerator" object attributes
xg.allAttrs(palette, description, "RandomGenerator")
# Get "Cut1" modifier attributes
xg.allAttrs(palette, description, "Cut1")
# Get "Noise1" modifier attributes
xg.allAttrs(palette, description, "Noise1")
Misc Snippets
기타 유용한 Command 및 함수들은 아래와 같다.
import xgenm as xg
import xgenm.xgGlobal as xgg
import xgenm.XgExternalAPI as xge
import xgenm.ui as xgui
import maya.cmds as cmds
import maya.mel as mel
# Get Collections
collections = xg.palettes()
# Get Descriptions
descriptions = xg.descriptions(collection)
# Get Current Description
xgui.currentDescription()
# Set Current Description
xgg.DescriptionEditor.setCurrentDescription(description)
# Get Guides
guides = xg.descriptionGuides(description)
# Create Description Curves
cmds.select(guides, r=True)
mel.eval('xgmCreateCurvesFromGuidesOption(0, 0, "%s")' % (description+"_OutputCurves"))
# Toggle Guide Display
xg.toggleGuideDisplay(description)
# Refresh Primitive Preview
mel.eval('xgmPreview -progress {"%s"};' % description)
# Clean Primitive Preview
mel.eval('xgmPreview -clean {"%s"};' % description)
XGen 관련 명령어들은 Maya Help 에 없어서 알아내는데 애를먹은 기억이 있다.
여기 정리해 놓은 내용들이 도움이 되기를…