OpenMaya 選択中のオブジェクトのComponent IDsやPoly Countを取得する

この記事はMaya Advent Calendar 2021の10日目の記事です

OpenMayaで選択中のオブジェクトのComponent IDsやPoly Countを取得する逆引きのようなものです

import maya.OpenMaya as OpenMaya

#get mSelection List
SelectionList = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList(SelectionList)

#MItSelectionList iteritor for meshes
#filter with mfn class
iterMesh = OpenMaya.MItSelectionList(SelectionList, OpenMaya.MFn.kGeometric)

# selection iterator
while not iterMesh.isDone():
    polyList = []
    dagPath = OpenMaya.MDagPath()
    iterMesh.getDagPath(dagPath)
    fnMesh = OpenMaya.MFnMesh(dagPath)

    # print num information about polycount, vertecescount and etc....
    meshNumPolygons = fnMesh.numPolygons()
    print fnMesh.numPolygons: %s % meshNumPolygons
    meshNumVertices = fnMesh.numVertices()
    print fnMesh.numVertices: %s % meshNumVertices
    meshNumEdges = fnMesh.numEdges()
    print fnMesh.numEdges: %s % meshNumEdges
    meshNumUVs = fnMesh.numUVs()
    print fnMesh.numUVs: %s % meshNumUVs
    meshNumFaceVertices = fnMesh.numFaceVertices()
    print fnMesh.numFaceVertices: %s % meshNumFaceVertices
    meshNumUVSets = fnMesh.numUVSets()
    print fnMesh.meshNumUVSets: %s % meshNumUVSets
    numColors = fnMesh.numColors()
    print fnMesh.numColors: %s % numColors
    meshNumColorSets = fnMesh.numColorSets()
    print fnMesh.meshNumColorSets: %s % meshNumColorSets
    numNormals = fnMesh.numNormals()
    print fnMesh.numNormals: %s % numNormals

    iterMesh.next()

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny