(two and a half years later)
I was wondering the same! 😅
I haven't touched this code in a long time. When I finally got it to work I
decided not to change, as there are a couple of things that I still don't
fully understand and I don't wanna break it.
This is the typical case of "It works!... But why?!"
Today I was just looking back into it, cause I was investigating a small
issue (which is actually specific to one file only, so maybe just a quirk
of maya) where inputComponentsTarget and inputPointsTarget have different
lengths, but the blendShape node still works fine... For most of the poses,
the index list
I was very surprised, cause a delta can't really be applied without knowing
which vertex to affect. Maybe the indices are stored somewhere else? Maybe
they're cached?
Now... I have also written some code to actually *write* my custom deltas
in the blendShape node. Here is an excerpt.
index_list = OM.MIntArray() # indices to be written
deltas_list = OM.MPointArray() # deltas to be written (maya wants points
instead of vectors) ¯\_(ツ)_/¯
####################################################################################
### values for index_list and deltas_list are assigned outside this code
snippet ###
####################################################################################
# initializes function sets, needed to create the MObjects and set their
data
dg_component_fn = OM.MFnComponentListData()
dg_component_data = dg_component_fn.create()
singleComponent_fn = OM.MFnSingleIndexedComponent()
singleComponent_data = singleComponent_fn.create(OM.MFn.kMeshVertComponent)
singleComponent_fn.addElements(index_list)
# write the index data in the inputComponentsTarget plug
if not singleComponent_data.isNull():
dg_component_fn.add(singleComponent_data)
inputComponentsTarget_plug.setMObject(dg_component_data)
print dg_component_fn.length() # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
this line prints 1 (in my test index_list and deltas_list had 11476
elements each)
# writes the delta data in the inputPointsTarget plug
dg_pointArray_fn = OM.MFnPointArrayData()
dg_pointArray_data = dg_pointArray_fn.create(deltas_list)
if not dg_pointArray_data.isNull():
inputPointsTarget_plug.setMObject(dg_pointArray_data)
print dg_pointArray_fn.length() # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
this line prints 11476 (correct!)
It has always worked fine in the last few years, and it still works
correctly also with this file.
However, even after re-writing the blendShape targets in the node, the
indices still don't have the right length.
*With very few exceptions*,the length of the indices in
inputComponentsTarget is a very small value, between 1 and 5.
Here is an excerpt of the code to read the deltas from the blendShape node.
inputPointsTarget_data = inputPointsTarget_plug.asMDataHandle().data()
inputComponentsTarget_data =
inputComponentsTarget_plug.asMDataHandle().data()
# to read the deltas, use a MFnPointArrayData
targetPoints = OM.MPointArray()
fnPoints = OM.MFnPointArrayData(inputPointsTarget_data)
fnPoints.copyTo(targetPoints)
# use MFnSingleIndexedComponent to extract an MIntArray with the indices
dg_component_fn = OM.MFnComponentListData(inputComponentsTarget_data)[0]
# <<<<<<<<<<<< why does this need to be only the first element?
if dg_component_fn.isNull():
continue
singleComponent_fn = OM.MFnSingleIndexedComponent(dg_component_fn)
targetIndices = OM.MIntArray()
singleComponent_fn.getElements(targetIndices)
print "indices: ", targetIndices.length(), "points: ",
targetPoints.length() # <<<<<<<<<<<< prints "indices: 1 points: 11476"
To be honest I am still a bit confused by some bits of this code. I *think *I
understand the combined use of MFnComponentListData and
MFnSingleIndexedComponent, but I'm not so familiar with these classes and
the documentation is pretty scarce. Also google wasn't very helpful, as
brought me back to this very thread that I started long time ago...
Since I noticed this issue on one file only, I don't know if you'll be able
to replicate the same scenario.
However, maybe you can notice any anomaly in the way I'm handling this data
to put it in / take it out the plug.
Can anyone shed some light on what's going on here?
Any help would be greatly appreciated!
Thanks,
Enrico
--
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/3ed84bae-bd1b-470e-b701-3c145c50f235%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.