Like the title says, I was wondering how to check if an object is currently in smooth preview mode and if so, getting the triangles of that object. I'm working on a simple script that renames high and low poly meshes for me but I didn't consider the possibility of using smooth preview meshes, it currently gets the triangles of the mesh pre-smooth preview mode.
Like the title says, I was wondering how to check if an object is currently in smooth preview mode and if so, getting the triangles of that object. I'm working on a simple script that renames high and low poly meshes for me but I didn't consider the possibility of using smooth preview meshes, it currently gets the triangles of the mesh pre-smooth preview mode.
Hi,
The mesh's displaySmoothMesh attribute controls whether the object is displaying the smooth mesh or base mesh.
getAttr pCubeShape1.displaySmoothMesh;
The mesh also has an outSmoothMesh attribute that can be used to access the smoothed mesh.
connectAttr pCubeShape1.outSmoothMesh pConeShape1.inMesh;
Hi,
The mesh's displaySmoothMesh attribute controls whether the object is displaying the smooth mesh or base mesh.
getAttr pCubeShape1.displaySmoothMesh;
The mesh also has an outSmoothMesh attribute that can be used to access the smoothed mesh.
connectAttr pCubeShape1.outSmoothMesh pConeShape1.inMesh;
What does connectAttr do in this case? I tried using .outSmoothMesh on a selected object but my console says that there is no 'outSmoothMesh' attribute.
import maya.cmds as cmds
selected = cmds.ls(selection=True)[0]
print('selected: ' + selected)
smooth = cmds.getAttr(selected + '.displaySmoothMesh')
print (smooth)
if (smooth == 2):
print(str(selected.outSmoothMesh))
else:
print("not smooth")
What does connectAttr do in this case? I tried using .outSmoothMesh on a selected object but my console says that there is no 'outSmoothMesh' attribute.
import maya.cmds as cmds
selected = cmds.ls(selection=True)[0]
print('selected: ' + selected)
smooth = cmds.getAttr(selected + '.displaySmoothMesh')
print (smooth)
if (smooth == 2):
print(str(selected.outSmoothMesh))
else:
print("not smooth")
It allows you to query the triangles of the smoothed mesh. The smoothed mesh will give you the unsmoothed triangle count if you use the polyEvaluate() command on it. When connecting the outSmoothMesh attribute (which is located on the shapenode, maybe thats why you couldn't find it.) to the inMesh of an other object, that object basically becomes the shape of the connected object so you can use polyEvaluate on it an get the correct number of triangles
It allows you to query the triangles of the smoothed mesh. The smoothed mesh will give you the unsmoothed triangle count if you use the polyEvaluate() command on it. When connecting the outSmoothMesh attribute (which is located on the shapenode, maybe thats why you couldn't find it.) to the inMesh of an other object, that object basically becomes the shape of the connected object so you can use polyEvaluate on it an get the correct number of triangles
Thank you for your reply, sorry for the delay.
Are there any other methods to achieve what I want without actually smoothing a mesh to get the tris amount? I've explored other possibilities like the heads up display's tris count but is there any way of accessing that number myself somehow? How is that calculated?
Also, when I tried to do cmds.connectAttr, it resulted in a really odd result - my mesh turned into a strange comet?
Thank you for your reply, sorry for the delay.
Are there any other methods to achieve what I want without actually smoothing a mesh to get the tris amount? I've explored other possibilities like the heads up display's tris count but is there any way of accessing that number myself somehow? How is that calculated?
Also, when I tried to do cmds.connectAttr, it resulted in a really odd result - my mesh turned into a strange comet?
Thank you for your reply, sorry for the delay. (Might be dubble post, whoops)
Are there any other methods to achieve what I want without actually smoothing a mesh to get the tris amount? I've explored other possibilities like the heads up display's tris count but is there any way of accessing that number myself somehow? How is that calculated?
Also, when I tried to do cmds.connectAttr, it resulted in a really odd result - my mesh turned into a strange comet?
Thank you for your reply, sorry for the delay. (Might be dubble post, whoops)
Are there any other methods to achieve what I want without actually smoothing a mesh to get the tris amount? I've explored other possibilities like the heads up display's tris count but is there any way of accessing that number myself somehow? How is that calculated?
Also, when I tried to do cmds.connectAttr, it resulted in a really odd result - my mesh turned into a strange comet?
Hi,
I believe you could access this data using the Maya API MGeometryExtractor class. This is primarily meant for renderers but the primitiveCount method should give you the info you need.
https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=MAYA_API_REF_cpp_ref_class_m_h_w_render_1_1_m_g...
Note: I haven't tried this myself but that is essentially how the HUD gets this information.
Hi,
I believe you could access this data using the Maya API MGeometryExtractor class. This is primarily meant for renderers but the primitiveCount method should give you the info you need.
https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=MAYA_API_REF_cpp_ref_class_m_h_w_render_1_1_m_g...
Note: I haven't tried this myself but that is essentially how the HUD gets this information.
How do I go about accessing the class? Using Python to write my script and I've tried OpenMaya but I don't think I can use it to instantiate MGeometryExtractor.
How do I go about accessing the class? Using Python to write my script and I've tried OpenMaya but I don't think I can use it to instantiate MGeometryExtractor.
Hi,
Here is a quick and dirty sample script that should get you started.
Note: you need to use OpenMaya API v2.0 to access this class. ("import maya.api...")
import maya.cmds as cmds
import maya.api.OpenMaya as om
import maya.api.OpenMayaRender as omr
def printNumberOfTriangles(path, base):
indexDesc = omr.MIndexBufferDescriptor(omr.MIndexBufferDescriptor.kTriangle, "indices", omr.MGeometry.kTriangles)
positionDesc = omr.MVertexBufferDescriptor("POSITION", omr.MGeometry.kPosition, omr.MGeometry.kFloat, 3)
requirements = omr.MGeometryRequirements()
requirements.addVertexRequirement(positionDesc)
requirements.addIndexingRequirement(indexDesc)
meshType = 'Display'
options = omr.MGeometryExtractor.kPolyGeom_Normal # Display mesh
if base:
meshType = 'Base'
options = omr.MGeometryExtractor.kPolyGeom_BaseMesh # Base mesh
extractor = omr.MGeometryExtractor(requirements, path, options)
print('%s mesh has %d triangles' % (meshType, extractor.primitiveCount(indexDesc)))
cmds.file(new=True, force=True)
cmds.polyCube()
cmds.select('pCubeShape1')
cmds.setAttr('pCubeShape1.displaySmoothMesh', 2)
sList = om.MGlobal.getActiveSelectionList()
path = sList.getDagPath(0)
printNumberOfTriangles(path, True) # Base mesh
printNumberOfTriangles(path, False) # Display mesh
# Prints:
# Base mesh has 12 triangles
# Display mesh has 192 triangles
Hi,
Here is a quick and dirty sample script that should get you started.
Note: you need to use OpenMaya API v2.0 to access this class. ("import maya.api...")
import maya.cmds as cmds
import maya.api.OpenMaya as om
import maya.api.OpenMayaRender as omr
def printNumberOfTriangles(path, base):
indexDesc = omr.MIndexBufferDescriptor(omr.MIndexBufferDescriptor.kTriangle, "indices", omr.MGeometry.kTriangles)
positionDesc = omr.MVertexBufferDescriptor("POSITION", omr.MGeometry.kPosition, omr.MGeometry.kFloat, 3)
requirements = omr.MGeometryRequirements()
requirements.addVertexRequirement(positionDesc)
requirements.addIndexingRequirement(indexDesc)
meshType = 'Display'
options = omr.MGeometryExtractor.kPolyGeom_Normal # Display mesh
if base:
meshType = 'Base'
options = omr.MGeometryExtractor.kPolyGeom_BaseMesh # Base mesh
extractor = omr.MGeometryExtractor(requirements, path, options)
print('%s mesh has %d triangles' % (meshType, extractor.primitiveCount(indexDesc)))
cmds.file(new=True, force=True)
cmds.polyCube()
cmds.select('pCubeShape1')
cmds.setAttr('pCubeShape1.displaySmoothMesh', 2)
sList = om.MGlobal.getActiveSelectionList()
path = sList.getDagPath(0)
printNumberOfTriangles(path, True) # Base mesh
printNumberOfTriangles(path, False) # Display mesh
# Prints:
# Base mesh has 12 triangles
# Display mesh has 192 triangles
Can't find what you're looking for? Ask the community or share your knowledge.