Hiya,

I'm currently working on (actually, finished) a small tool that transfers
deformer weights from one deformer node to another (between objects of
non-identical topologies, similar to the Transfer Attributes tool).

I have a pointCloud class (i omit its code, but its very simple) which I use
for storing the deformer weights for each point. Then I have the following:

---------------------------------------------------------------------------------------------------------------------------------

import pointCloud as PC    # my own point cloud class


> from maya.OpenMaya import *

from maya.OpenMayaAnim import *


>
> def getDeformerWeightsToPC(pc, deformer_name):

"""Get all per-vertex deformer weights to a point cloud."""

#assert type(pc) is pointCloud

assert type(pc) is PC.pointCloud

assert type(deformer_name) is str


> print "getDeformerWeightsToPC() ..."


> try:

sel = MSelectionList()

sel.add(deformer_name)


> obj = MObject()

sel.getDependNode(0, obj)


> f = MFnWeightGeometryFilter(obj)

num_connections = f.numOutputConnections()


> for c in range(num_connections):


> i = f.indexForOutputConnection(c)


> shape_path = MDagPath()

f.getPathAtIndex(i, shape_path)

it = MItGeometry(shape_path)


> print i, shape_path.fullPathName(), it.count()


> w = MFloatArray()


> while not it.isDone():

comp = it.currentItem()


> p = it.position(MSpace.kWorld)

p = (p[0], p[1], p[2])

f.getWeights(i, comp, w)


> pc.addPoint(p, float(w[0]))


> it.next()


> pc.setName(deformer_name)


>
> except Exception, e:

print "failed to get weights from deformer:", type(e), e

pass


>
>
>
>
> def setDeformerWeightsFromPC(pc, deformer_name):

assert type(pc) is PC.pointCloud

assert type(deformer_name) is str


> print "setDeformerWeightsToPC() ..."


> try:

sel = MSelectionList()

sel.add(deformer_name)


> obj = MObject()

sel.getDependNode(0, obj)


> f = MFnWeightGeometryFilter(obj)

num_connections = f.numOutputConnections()


> W = MFloatArray(1, 0.0)


> for c in range(num_connections):


> i = f.indexForOutputConnection(c)


> shape_path = MDagPath()

f.getPathAtIndex(i, shape_path)

it = MItGeometry(shape_path)


> print i, shape_path.fullPathName(), it.count()


> while not it.isDone():

comp = it.currentItem()


> print comp, comp.apiTypeStr()


> p = it.position(MSpace.kWorld)

p = (p[0], p[1], p[2])


> W[0] = pc.getValue(p)

f.setWeight(shape_path, i, comp, W)


> it.next()


>
>
> except Exception, e:

print "failed to set weights from deformer:", type(e), e

pass


>
>
>
>
>
>
> def transferDeformerWeights():

"""A test function."""


> print "transferDeformerWeights() !!!"


> pc = PC.pointCloud()

getDeformerWeightsToPC(pc, "cluster1")

setDeformerWeightsFromPC(pc, "cluster2")


---------------------------------------------------------------------------------------------------------------------------------


The above code works properly between polygon meshes. However once I try to
run it where I try to transfer TO (ie. do ::setWeights() on) nurbs surfaces
or curves _sharing the same deformer_, the code crashes Maya (it does an
emergency save, which usually shows that the code ran successfully for the
first few CVs).

So it crashes when I try it on:
- a deformer, applied to multiple nurbs objects (be it curves or surfaces);
- if I run the function _more than once_ for a single nurbs object with a
single deformer on it.

Any help or idea would be appreciated


imre



-- 
[ Imre Tuske | http://blueriviera.wordpress.com/ | mailto:
[email protected] ]

" On a horse made of crystal he patrolled the land
  With a mason ring and schnauzer in his perfect hands "

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to