Hey Leonardo.
Thanks a lot for the answer, it's been very useful.
So revised my code, but it's still not working. I mean... Maya handles the
node smoothly, I can connect a mesh into the inMesh attribute, tweak the
value of the positionOffset attribute, and even connect the values of the
outPosition array to the translate channel of the locators. But still the
locators all stay in the center of the scene (0,0,0) and if I modify the
positionOffset or tweak the mesh, nothing happens: they stay there.
I also have an error (one for each connected locator, it doesn't show up if
the locators are not connected..) :
> " Error: RuntimeError: file
> S:\Maya_2015_DI\build\Release\runTime\Python\Lib\site-packages\maya\OpenMaya.py
>
> line 8174: (kInvalidParameter): Object is incompatible with this method "
Most likely my error is how I write the data into the array, but I don't
know which is the right way to do it!
Here's a snippet of my code:
class AttachToMesh(OMMPx.MPxNode):
a_inMesh = OM.MObject()
a_positionOffset = OM.MObject()
a_outPosition = OM.MObject()
def __init__(self):
OMMPx.MPxNode.__init__(self)
def compute(self,plug,dataBlock):
thisNode = AttachToMesh.thisMObject(self)
inputMeshPlug = OM.MPlug(thisNode, AttachToMesh.a_inMesh)
if not inputMeshPlug.isConnected():
return OM.kNotImplemented
if plug == AttachToMesh.a_outPosition:
# GET MESH DATA
inMesh = dataBlock.inputValue(AttachToMesh.a_inMesh).asMesh()
# GET POSITION OFFSET VALUE
dataHandlePositionOffset = dataBlock.inputValue(AttachToMesh.
a_positionOffset)
positionOffsetValue = dataHandlePositionOffset.asFloat()
# OUT POSITION
dataHandleArrayOutPosition = dataBlock.outputArrayValue(
AttachToMesh.a_outPosition)
dataBuilderOutPosition = dataHandleArrayOutPosition.builder()
geoIterator = OM.MItGeometry(inMesh)
mFnMesh = OM.MFnMesh(inMesh)
vertexPosition = OM.MPoint()
normals = OM.MFloatVectorArray()
mFnMesh.getVertexNormals(False, normals)
while not geoIterator.isDone():
vertexPosition.x = geoIterator.position().x + ( normals[
geoIterator.index()].x * positionOffsetValue )
vertexPosition.y = geoIterator.position().y + ( normals[
geoIterator.index()].y * positionOffsetValue )
vertexPosition.z = geoIterator.position().z + ( normals[
geoIterator.index()].z * positionOffsetValue )
dataHandleOutPosition = dataBuilderOutPosition.addElement(
geoIterator.index())
dataHandleOutPosition.set3Double(vertexPosition.x,
vertexPosition.y, vertexPosition.z)
geoIterator.next()
dataHandleArrayOutPosition.set(dataBuilderOutPosition)
dataBlock.setClean(plug)
else:
return OM.kUnknownParameter
def nodeInitializer():
mFnTypedAttr = OM.MFnTypedAttribute()
mFnAttr = OM.MFnNumericAttribute()
AttachToMesh.a_inMesh = mFnTypedAttr.create("inputMesh", "inMesh", OM.
MFnData.kMesh)
AttachToMesh.a_positionOffset = mFnAttr.create("positionOffset",
"posOff", OM.MFnNumericData.kFloat, 0.0)
mFnAttr.setKeyable(1)
AttachToMesh.a_outPosition = mFnAttr.create("outPosition", "outPos", OM.
MFnNumericData.k3Double, 0.0)
mFnAttr.setKeyable(0)
mFnAttr.setWritable(0)
mFnAttr.setArray(1)
mFnAttr.setUsesArrayDataBuilder(1)
AttachToMesh.addAttribute(AttachToMesh.a_inMesh)
AttachToMesh.addAttribute(AttachToMesh.a_positionOffset)
AttachToMesh.addAttribute(AttachToMesh.a_outPosition)
AttachToMesh.attributeAffects(AttachToMesh.a_inMesh, AttachToMesh.
a_outPosition)
AttachToMesh.attributeAffects(AttachToMesh.a_positionOffset,
AttachToMesh.a_outPosition)
Thanks, folks!
PS... In Maya I piped a cubeShape's outMesh into my node's inMesh
attribute. (Is it right? I guess so). And in the Hypergraph (Heat Map
Display On) I see that my node is red, meaning that is making heavy
calculations (0.05 s).
So far I kept the code as simple as possible! Does that mean that it will
be super slow when I'll add more functionalities or use it with hi-poly
meshes?
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/97121531-a692-446b-a656-d2a852f17bfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.