Forum: Poser Python Scripting


Subject: Morphs: copying and mirroring

unrealblue opened this issue on Mar 04, 2020 ยท 30 posts


unrealblue posted Sun, 08 March 2020 at 9:59 PM

from collections import defaultdict

PRECISION = 3

def nested_dict(n, type):
    if n == 1:
        return defaultdict(type)
    else:
        return defaultdict(lambda: nested_dict(n-1, type))


def get_mesh (geometry):
    mesh = nested_dict(3, int)  
    i = 1
    for v in geometry.Vertices():
        (x, y, z) = int(v.X()*10**PRECISION), int(v.Y()*10**PRECISION), int(v.Z()*10**PRECISION)
        mesh[x][y][z] = i
        i += 1
    return mesh


def check_symmetry (mesh):
    sym_map = dict()
    try:
        for (x, a) in mesh.items():
                for (y, b) in a.items():
                    for (z, i1) in b.items():
                        if x == 0:
                            i2 = i1
                        else:
                            i2 = mesh[x*-1][y][z]   # index of X mirrored vertex
                        if i2 == 0:
                            raise KeyError()
                        sym_map[i2-1] = i1-1
        return sym_map
    except KeyError:
        print "Non-symmetric vertex:", i1, i2
        return None

SCENE  = poser.Scene()
FIGURE = SCENE.Figure('LaFemme')
ACTOR  = FIGURE.Actor('Right Thigh')
#GEOM   = ACTOR.Geometry()

(GEOM, actor_list, per_actor_vertices)  = FIGURE.UnimeshInfo()


MESH  = get_mesh(GEOM)
SYM_MAP  = check_symmetry(MESH)
print SYM_MAP

LaFemme, it seems is only symmetric to this precision. Using this on a non-torso part barfs on the first vertex test :)

I can use the resulting SYM_MAP with the mappings supplied by unimesh() and reverse (mirror, flip) any FMB, I think.