Vertex points changing slightly after combine

Hello fellow TA’s,

I am having a bit of an issue with Maya at the moment and was wondering if anyone had come across this before. What I am doing is writing a script in PyMel that gathers the vertex point positions of 3 separate objects and storing them in a multi list.
The next step is to combine the objects, once this is done I iterate through the new object’s vertex point positions to check which are the same as the values in my list:

for point in myNode.getPoints("world"):
    vertCount += 1
    vertPositions[count].append(point)

for point in myNode.getPoints("world"):
    vertCount += 1
    if (pm.dt.Vector(point) == pm.dt.Vector(verts[1][2])):
        print "found"

Now onto my issue. When I print out the values of the first list of point positions compared to the 2nd set of point positions the values are slightly different, it’s as if the verts have shifted slightly. Here is an example:

The first set of point positions (separate objects):
[-141.332735864, -34.1640412074, 0.0]
[200.334744605, -34.1640412074, 0.0]

The second set of point positions (now combined using polyunite):
[-141.332733154, -34.1640396118, 0.0]
[200.334747314, -34.1640396118, 0.0]

As you can see, the values are very similar except for the last 6 decimal places. Is this just an unavoidable computing error or something wrong with Maya?

Cheers!

Hopefully I’m not crazy, but it looks like all those numbers are the same?

Also floating point is weird and will rarely work with ==

Instead try the isEquivalent method on vectors, it has a tolerance parameter and will return true if the two vectors are within that tolerance.

Woops, I have edited the post. I copied the same values by accident. I have been playing around with it some more and capped it to 4 decimal places. Seems to work except it will skip some verts and leave me with a half skinned model

you need to make sure that each object has the same local object space origin.

try this:

  1. For each object, move the pivot to the same location. For example, move all the pivots to the world origin.
  2. Freeze the transform. This will force all vertex position to be baked down. Since the object pivot is in alignment with the world pivot, this will store all vertex positions in “world” position.
  3. Now check your vertex positions, they should all be exactly the same.

Also, this is the way floating point numbers work. They are very squirrely. But compounding this is that Maya stores all vertex positions relative to the object’s transform, so querying the position in world space requires a space transformation, and this can cause very small differences across multiple objects with unique local transforms.

Hello,

I tried setting the pivot to origin and freezing the transforms to no avail. My positions are still off. In one case I printed out the errored line and it was off by a single decimal place:

dodgy one is: [-42.1087, -93.8207, 50.1749] [-42.1088, -93.8207, 50.1749] 29

The odd thing is the more verts there are in the scene the less precise it gets:

def skinObject(verts, joints, name):

    pm.skinCluster(joints, "car", tsb = True) # Skin the newly combined object to the joints in the list


    myNode = pm.PyNode(str(name))
    count = 0
    vertCount = -1
    pointList = []

    
    for point in myNode.getPoints("world"): # Run through each point in the newly combined mesh

        point[0] = float("%.3f" % point[0])
        point[1] = float("%.3f" % point[1])
        point[2] = float("%.3f" % point[2])
        pointList.append(point)
        
    print "Got points"
                    
    count = -1
    printed = False
    for i in range(len(verts)):
        for j in range(len(verts[i])):
            count += 1
            printed = True
            for point in pointList:
                if point == verts[i][j]:
                    print "skinned: " + str(count), point, verts[i][j]
                    pm.select(myNode.vtx[count])
                    pm.skinPercent("skinCluster1", transformValue = [(joints[i]), 1])
                    pm.select(cl = True)
                    

I am truly stumped by this??

So…after much deliberation and stressful thinking I narrowed my float values down to 1 decimal place and voila. It works like a charm. Albeit a hacky cheating charm but for the time being i’ll take it!

Thanks for the help :slight_smile:

as noted above, floating point numbers can’t really be tested for equality.

check out the section on Rounding.

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html