Deformer displace mesh along normal problem

77 views
Skip to first unread message

marcin

unread,
Feb 16, 2009, 12:49:24 PM2/16/09
to python_inside_maya
Hi!

I want to displace my mesh along normals using deformer. So I wrote
following code in compute method

thisNode = self.thisMObject()

index = plug.logicalIndex()
inPlug = OpenMaya.MPlug( thisNode,
OpenMayaMPx.cvar.MPxDeformerNode_input )
inPlug.selectAncestorLogicalIndex( index,
OpenMayaMPx.cvar.MPxDeformerNode_input )

hInput = dataBlock.inputValue( inPlug )

hGeom = hInput.child
( OpenMayaMPx.cvar.MPxDeformerNode_inputGeom )
hGroup = hInput.child
( OpenMayaMPx.cvar.MPxDeformerNode_groupId )
groupId = hGroup.asLong()
hOutput = dataBlock.outputValue( plug )
hOutput.copy( hGeom )

pt = OpenMaya.MPoint()
normalvec = OpenMaya.MVector()

mesh = hOutput.data()
iter = OpenMaya.MItMeshVertex(mesh)

while iter.isDone() == False:
pt = iter.position()
iter.getNormal(normalvec)
iter.setPosition(pt+normalvec*2)
iter.next()

and I've got mesh distorted in random directions instead of normals.
When I replace normalvec with
some arbitrary vector everything is working fine. What I'm doing
wrong ?

Adam Mechtley

unread,
Feb 16, 2009, 1:00:41 PM2/16/09
to python_in...@googlegroups.com
Hi Marcin,

Looks like you need to first iterate your mesh to store the normals in an array, then iterate again to translate each point along these normals.

Right now, each time you move a point, you are affecting the normals of all other points that share an edge with it, so its normal has been changed by the time the iterator gets to it to read the normal.

-Adam

marcin

unread,
Feb 16, 2009, 2:38:32 PM2/16/09
to python_inside_maya
On 16 Lut, 19:00, Adam Mechtley <adam.mecht...@gmail.com> wrote:
> Hi Marcin,
>
> Looks like you need to first iterate your mesh to store the normals in an
> array, then iterate again to translate each point along these normals.

It works perfect. Thanks :)
I've one question about deform and compute methods in deformer class.
I can access normals in compute and deform methods, so which one
is better in this case ?

Marcin

jasonosipa

unread,
Feb 17, 2009, 1:29:00 PM2/17/09
to python_inside_maya
Hi All!

I actually took this code by Marcin, rejiggered it slightly to take in
a collider mesh, as well as a "maximum distance", just like the oeRay
plugin I put together, only this time, it's all a lot cleaner. There
is one kind of annoying problem, however, I'd love some help with,
which came up in both plug-ins: an empty collision plug making a lot
of noise.

I connect *anything* before the collision mesh, I get an error:

deformer -type myDeformer;
// Error: line 1: (kInvalidParameter): Argument is a NULL pointer
# Traceback (most recent call last):
# File "C:/myDeformer.py", line 28, in compute
# targetFnMesh = om.MFnMesh( targetMesh )
# File "C:\engserv\rbuild\194\build\wrk\optim\runTime\Python\Lib
\site-packages\maya\OpenMaya.py", line 4281, in __init__
# RuntimeError: (kInvalidParameter): Argument is a NULL pointer //
// Error: line 1: Connection not made: 'pSphereShape1.instObjGroups
[0]' -> 'set2.dagSetMembers[-1]'. Destination node will not allow the
connection. //
// Error: line 1: Connection not made: 'pSphereShape1.instObjGroups
[0]' -> 'set2.dagSetMembers[-1]'. Destination node will not allow the
connection. //
// Result: myDeformer1 //


As soon as I hook up a collision mesh, everything works perfectly,
errors all go away, the deformed mesh does what's expected. So, is
there a way inside of the compute to simply check if the collision
plug is occupied? Would that be the same for a single connection v an
array, or different?

From that check it would just be a simple "if" and I could just skip
the collision stuff...

marcin

unread,
Feb 17, 2009, 3:28:30 PM2/17/09
to python_inside_maya


>
> From that check it would just be a simple "if" and I could just skip
> the collision stuff...
>

Hi!

MPlug class has connectedTo method which allows you to check if there
are connections.

marcin

unread,
Feb 17, 2009, 3:40:36 PM2/17/09
to python_inside_maya
>
> MPlug class has connectedTo method which allows you to check if there
> are connections.

Something like this will work:

plugArray = OpenMaya.MPlugArray()
plug = OpenMaya.MPlug(self.thisMObject(),
myDeformer.aColliderMesh)
isConnected = plug.connectedTo(plugArray,1,0)
if not isConnected:




Matthew Chapman

unread,
Feb 17, 2009, 3:41:10 PM2/17/09
to python_in...@googlegroups.com
If the MObject passed from the data block is null when there is no
connection/data present. MObject::isNull() might work for that.

Matt
Reply all
Reply to author
Forward
0 new messages