On Thu, Feb 5, 2009 at 00:39, Chadrik <[email protected]> wrote:
>
> i'm having problems getting reliable component MObjects.   i can get a
> good MObject if i use an MSelectionList and put in the string for a
> component like a face.  in the example below, i'm going to get two
> MObjects representing the same face to make sure that they evaluate as
> the same:
>
> import maya.cmds as cmds
> import maya.OpenMaya as api
> s,h = cmds.polySphere()
> sel1 = api.MSelectionList()
> dag1 = api.MDagPath()
> obj1 = api.MObject()
> sel1.add( s + '.f[0]' )
> sel1.getDagPath( 0, dag1, obj1)
>
> sel2 = api.MSelectionList()
> dag2 = api.MDagPath()
> obj2 = api.MObject()
> sel2.add( s + '.f[0]' )
> sel1.getDagPath( 0, dag2, obj2)
>
> dag1 == dag2
> # True
> obj1 == obj2
> # True

That only returned True because your second call to getDagPath() is
still using 'sel1'. If you had used 'sel2' the comparison of the two
MObjects would have returned false.

> mit1 = api.MItMeshPolygon( dag1, obj1 )
> mit2 = api.MItMeshPolygon( dag1, obj1 )
> mit1.currentItem() == mit2.currentItem()
> # False
>
> what's going on here?

An MObject is a container. When you compare two MObject's you are not
comparing the MObject's themselves but what they contain. So if you
have two different MObjects but they both contain the same node, the
comparison will be true.

A face component is also a container object, one which holds one or
more integer indices representing faces of a mesh. The mesh itself
does not need these component objects to keep track of its faces
because they are inherent in its geometry. The component objects are
created on the fly, whenever they are needed. This means that two
different requests for the same face of a mesh may return two
completely different component objects which contain indices to the
same face of the mesh.

In your calls above you have two different MObjects, each of which
contains a *different* component object. Those two component objects
contain the same face indices, but they are different objects. When
you compare the two MObjects it looks to see if the objects they
contain are the same. Since they are different, you get a result of
False. This is because MObject does not know anything about the
contents of the objects it contains so it cannot pry any deeper to
discover that these are two component objects which happen to refer to
the same component.

If you want to make inquiries involving the contents of a component
object, then you need to use one of the component function sets. Since
all you care about is whether they refer to the same components,
MFnComponent will suffice:

  api.MFnComponent(obj1).isEqual(obj2)
  # True

-- 
-deane

--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to