Created
July 24, 2015 11:31
-
-
Save ivogrig/4c3c3dfc21b1f9eeb1ca to your computer and use it in GitHub Desktop.
Example of finding materials connected to a mesh. This should become redundant as there will be convenience functions added to the TD SDK soon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of finding materials connected to a mesh. This should become redundant as | |
# there will be convenience functions added to the TD SDK soon. | |
import modo | |
# This gets the selected mesh if any | |
mesh = modo.Mesh() | |
if mesh: | |
# First collect the materials polygon tags of the mesh in question | |
ptags = set() | |
for tagType in (lx.symbol.i_POLYTAG_MATERIAL, lx.symbol.i_POLYTAG_PART): | |
for index in range(mesh.geometry.PTagCount(tagType)): | |
ptag = mesh.geometry.internalMesh.PTagByIndex(tagType, index) | |
ptags.add(ptag) | |
# Then, iterate all group masks and see if their tags match with the ones from the mesh | |
groupMasks = set() | |
for groupMask in modo.Scene().renderItem.childrenByType('mask'): | |
tagType = groupMask.channel('ptyp').get() | |
if tagType in ('Material', 'Part'): | |
assignedTag = groupMask.channel('ptag').get() | |
if assignedTag in ptags: | |
groupMasks.add(groupMask) | |
# Print their names and children's names | |
for groupMask in groupMasks: | |
print '' | |
print 'groupMask {}:'.format(groupMask.name) | |
for child in groupMask.children(): | |
print '- child {}'.format(child.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment