I will answer each one of the questions: 1. Why not use the 'weight' attribute if it's faster? -> Because I need to replicate that efficient behaviour in custom attributes, to avoid being limited using only that one. 2. What does your custom attribute do, how was it created and is there any compute handler for it? -> My custom attribute affects the outputGeom attribute. Do I need a custom compute handler for it? 3. Can you reproduce the slowness in another superclass, like the MPxSurfaceNode? -> Yes, initially I tested using an MPxDeformerNode, but I got the same behaviour on my custom attributes when are keyframed. 4. Can you share a reproducible source file? I can share the Python script. For the Maya scene I'm using an sphere with a high resolution (around 1.1 Million verts), with low resolution it doesn't affect too much, but with higher it's noticeable. For the input attribute, I'm using a floatConstant with 2 keyframes (at 0 and 120).
Thanks for the help! On Thursday, 5 December 2024 at 11:11:09 UTC+1 Marcus Ottosson wrote: > Some clarifying questions: > > 1. Why not use the 'weight' attribute if it's faster? > 2. What does your custom attribute do, how was it created and is there any > compute handler for it? > 3. Can you reproduce the slowness in another superclass, like the > MPxSurfaceNode? > 4. Can you share a reproducible source file? > > On Thursday, 5 December 2024 at 07:55:37 UTC hector....@inbibo.co.uk > wrote: > >> Hello! Nice to meet you! I'm new on this forum and it's a pleasure being >> here! >> >> I am trying to create a new MPxBlendShape node, but using a new custom >> attribute slow down the computation when using keyframes, if I use the >> 'weight' attribute instead of the new one, doesn't have that slowness: >> [image: BlendShapeTemplate0.gif] >> >> Is there any way of aligning my new attribute to the 'weight' attribute >> without loosing performance when using keyframes? >> >> Thank you so much for your attention. >> >> Best regards, >> Héctor >> > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/python_inside_maya/02f693b3-d6bd-455f-8a1f-fa648a42db32n%40googlegroups.com.
import maya.OpenMaya as OpenMaya import maya.OpenMayaMPx as OpenMayaMPx # Set globals to the proper cpp cvars. (compatible from maya 2016) kInput = OpenMayaMPx.cvar.MPxGeometryFilter_input kInputGeom = OpenMayaMPx.cvar.MPxGeometryFilter_inputGeom kOutputGeom = OpenMayaMPx.cvar.MPxGeometryFilter_outputGeom kWeight = OpenMayaMPx.cvar.MPxBlendShape_weight class templateBlendShape(OpenMayaMPx.MPxBlendShape): """BlendShape node template.""" # Node info type_id = OpenMaya.MTypeId(0x00002) type_name = "templateBlendShape" # Attribute variables sampleInAttribute = OpenMaya.MObject() @classmethod def initialize(cls): """Initialize attributes and dependencies.""" # Numeric attribute numAttrFn = OpenMaya.MFnNumericAttribute() # Custom input attr cls.sampleInAttribute = numAttrFn.create('myInputAttribute', 'i', OpenMaya.MFnNumericData.kFloat, 0.0) numAttrFn.setArray(True) numAttrFn.setKeyable(True) numAttrFn.setMin(-10.0) numAttrFn.setMax(10.0) numAttrFn.setSoftMin(0.0) numAttrFn.setSoftMax(1.0) numAttrFn.setCached(True) cls.addAttribute( cls.sampleInAttribute ) cls.attributeAffects( cls.sampleInAttribute, kOutputGeom ) @classmethod def creator(cls): """Create instance of this class. Returns: templateDeformer: New class instance. """ return cls() def __init__(self): """Construction.""" OpenMayaMPx.MPxBlendShape.__init__(self) def deformData(self, data_block, geomData, groupId, local_to_world_matrix, geometry_index): """Perfoms a deformation. Args: data_block (MDataBlock): the node's datablock. geomData (MDataHandle): a handle to the current geometry being deformed. groupId (unsigned int): the group ID within the geometry to deform. local_to_world_matrix (MMatrix): the geometry's world space transformation matrix. geometry_index (int): the index corresponding to the requested output geometry. """ #weights_array_handle = data_block.inputArrayValue(kWeight) weights_array_handle = data_block.inputArrayValue(self.sampleInAttribute) num_weights = weights_array_handle.elementCount() for i in range(0, num_weights): # Add weight value weights_array_handle.jumpToElement(i) print("Weight[{0}]: {1}".format(i, weights_array_handle.inputValue().asFloat())) def getDeformerInputGeometry(self, data_block, geometry_index): """Obtain a reference to the input mesh. Args: data_block (MDataBlock): the node's datablock. geometry_index (int): the index corresponding to the requested output geometry. Returns: MObject mesh. """ inputAttribute = OpenMayaMPx.cvar.MPxGeometryFilter_input inputGeometryAttribute = OpenMayaMPx.cvar.MPxGeometryFilter_inputGeom inputHandle = data_block.outputArrayValue( inputAttribute ) inputHandle.jumpToElement( geometry_index ) inputGeometryObject = inputHandle.outputValue().child(inputGeometryAttribute).asMesh() return inputGeometryObject def initializePlugin(plugin): """Called when plugin is loaded. Args: plugin (MObject): The plugin. """ plugin_fn = OpenMayaMPx.MFnPlugin(plugin, "Test", "0.1", "Any") try: plugin_fn.registerNode( templateBlendShape.type_name, templateBlendShape.type_id, templateBlendShape.creator, templateBlendShape.initialize, OpenMayaMPx.MPxNode.kBlendShape ) except: print("failed to register node {0}".format(templateBlendShape.type_name)) raise def uninitializePlugin(plugin): """Called when plugin is unloaded. Args: plugin (MObject): The plugin. """ plugin_fn = OpenMayaMPx.MFnPlugin(plugin) try: plugin_fn.deregisterNode(templateBlendShape.type_id) except: print("failed to deregister node {0}".format( templateBlendShape.type_name )) raise