Well, I'll try to cut it to just one question.
I tried my best, and I think someway it should be working, but still the
*output
array attribute* is empty (all the values are set to the default value
0,0,0).
So I think there's something wrong in the way I fill up the output array
attribute. I've been striving for days now, but I can't get out of this bog.
Can somebody please help me on how the *MArrayDataBuilder *works?
I shortened the code and bolded the questionable parts to make it more
readable:
thank you guys!
class AttachToMesh(OMMPx.MPxNode):
def compute(self,plug,dataBlock):
if plug == AttachToMesh.a_outPosition:
inMesh = dataBlock.inputValue(AttachToMesh.a_inMesh).asMesh ()
positionOffsetValue = dataBlock.inputValue(AttachToMesh.
a_positionOffset).asFloat()
* 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)*
def nodeInitializer():
AttachToMesh.a_inMesh = mFnTypedAttr.create("inputMesh", "inMesh", OM.
MFnData.kMesh)
AttachToMesh.a_positionOffset = mFnAttr.create("positionOffset",
"posOff", OM.MFnNumericData.kFloat, 0.0)
* AttachToMesh.a_outPosition = mFnAttr.create("outPosition", "outPos",
OM.MFnNumericData.k3Double, 0.0)*
mFnAttr.setKeyable(0)
mFnAttr.setWritable(0)
mFnAttr.setArray(1)
mFnAttr.setUsesArrayDataBuilder(1)
Il giorno mercoledì 30 luglio 2014 01:21:38 UTC+2, Enrico Losavio ha
scritto:
>
> Hi everyone!
>
> I'm trying to write a sort of River node, but I ran into some difficulties
> (obviously :) ) and any help would be greatly appreciated!
>
> Basically i want a DG node that can
>
> - accept geometry as an input
> - retrieve mesh information
> - make up his own calculations based on the mesh information and a few
> custom attributes
> - have an array of MPoints (or k3Double i guess) as output to be piped
> into each locator
> - have the output updated every time an attribute or the mesh itself
> changes
>
> As far as I know, the MPxDeformerNode is the only way to access the
> geometry data. But I don't want to deform the mesh, just query information.
> And yet I don't fully understand how the push-pull mechanism works in this
> case. In a custom DG node i would use the "if plug == attribute" to force
> the evaluation, but in this case...?
> I've already jot down the basic structure for the node, but it doesn't
> work as it should.
> In Maya I loaded the plugin, applied the deformer to a simple cube, and
> fed each value of the array into the Translate attribute of specifically
> created locators (that thus went in the correct position, one on each
> vertex)
> If I tweak the mesh, the locators remain in the same position, don't
> follow the vertices. If I change the value of the positionOffset attribute,
> nothing happens.
> But I noticed that if i tweak the mesh and then change the value of the
> attribute, the position of all the locators suddenly updates as though the
> mesh is read properly, but the positionOffset value remains the previous
> one.
>
> Here's a simplified version of the code I wrote...:
>
> class AttachToMesh(OMMPx.MPxDeformerNode):
>
>
> mObj_positionOffset = OM.MObject()
> mObj_outPosition = OM.MObject()
>
>
> def __init__(self):
> OMMPx.MPxDeformerNode.__init__(self)
>
>
> def deform(self, dataBlock, geoIterator, matrix, geometryIndex):
>
> # RETRIEVE GEOMETRY DATA
> input = OMMPx.cvar.MPxDeformerNode_input
> dataHandleInputArray = dataBlock.outputArrayValue(input)
> dataHandleInputArray.jumpToElement(geometryIndex)
> dataHandleInputElement = dataHandleInputArray.outputValue()
>
> inputGeom = OMMPx.cvar.MPxDeformerNode_inputGeom
> dataHandleInputGeom = dataHandleInputElement.child(inputGeom)
> inMesh = dataHandleInputGeom.asMesh()
>
>
> # POSITION OFFSET
> dataHandlePositionOffset = dataBlock.inputValue(AttachToMesh.
> mObj_positionOffset)
> positionOffsetValue = dataHandlePositionOffset.asFloat()
>
> # OUT POSITION
> dataHandleArrayOutPosition = dataBlock.outputArrayValue(
> AttachToMesh.mObj_outPosition)
> dataBuilderOutPosition = dataHandleArrayOutPosition.builder()
>
> vertexPosition = OM.MPoint()
> mFnMesh = OM.MFnMesh(inMesh)
>
> 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)
>
> #here I'm not sure which setClean function I'm supposed to use...
> in this case I chose dataBlock.setClean
> #dataHandleArrayOutPosition.setAllClean()
>
> dataBlock.setClean(AttachToMesh.mObj_outPosition)
>
>
> def nodeInitializer():
> mFnAttr = OM.MFnNumericAttribute()
>
>
> AttachToMesh.mObj_positionOffset = mFnAttr.create("positionOffset",
> "posOff", OM.MFnNumericData.kFloat, 0.0)
> mFnAttr.setKeyable(1)
>
> AttachToMesh.mObj_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.mObj_outPosition)
>
> AttachToMesh.attributeAffects(AttachToMesh.mObj_positionOffset,
> AttachToMesh.mObj_outPosition)
>
>
>
> Thank you in advance for any reply!!
>
>
>
--
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/d603d985-0654-4060-8a0d-ad686e938887%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.