Forum: Poser Python Scripting


Subject: Morphs: copying and mirroring

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


unrealblue posted Fri, 06 March 2020 at 8:50 PM

adp001 posted at 12:45PM Sat, 07 March 2020 - #4382717

Have a look in my lib for morphs. Mathematical functions (like reverse the morph_values of an actor) are one-liners (numpy functionality). A "CreateMorph" function is also included ;)

The create function is almost exactly what I came up with. Except I cleared it as a matter of course. Your function is better (being flexible). :)

I'm not seeing the logic for symmetric reverse. I see the vertices being read into the array. And I know it's easy to reverse an array. I think this is what needs to happen. geometry delta 1: 1,1,1 .1,0,0 2: 2,1,1 .2,0,0 3: 4,7,8 .15,0,0 4: 1,4,5 .17,0,0 5: -1,1,1 0,0,0 6: -2,1,1 0,0,0 7: -4,7,8 0,0,0 8: -1,4,5 0,0,0

flipped (x) morph 1: 1,1,1 0,0,0 2: 2,1,1 0,0,0 3: 4,7,8 0,0,0 4: 1,4,5 0,0,0 5: -1,1,1 .1,0,0 6: -2,1,1 .2,0,0 7: -4,7,8 .15,0,0 8: -1,4,5 .17,0,0

Assumptions: geometry vertices are not in any particular order. Also, the order of left and right don't necessarily correspond. In this example, 1 is not necessarily the mirror of 5. I don't know how Poser stores vertices; if there's any consistency to it's ordering.

Anyway, For this "morph flip) to happen, I have to know 1) is_symmetric is true and 2) The vertex index to mirror vertex index.

To do that I make a triple key dict: dict[x][y][z] = i, where i is the geometry vertex index.

For x,y,z I use: int(1e7*x) to make the indexes INTs and allow for some degree of inaccuracy in the mesh. At this point, if the mesh is symmetric, for each x,y,z=i1 I should have a corresponding -x,y,z=i2

NOTE: x=0 is axial and not relevant to test symmetry.

Going through this dict, if there is any failure to find an entry for -x,y,z, given x,y,z then it's not symmetric (by my standards).

And given any point's x,y,z, I have its index, and can find each corresponding mirrored point index by just negating x (looking up using -x,y,z)

I can spawn a morph target, go through one sides vertices (the indexes where x>0 or x<0) pull the morphdelta for each and set the mirrored vertex index morphdelta to that.

Now I have a new morph that is the reverse (flipped x) of the original morph.

This is the only way I can figure to do it, making no assumptions about the ordering of vertices, and allowing for some "play in the values".

Is this a reasonable approach? It works. But it does take 2 passes through the vertices just to build the index then be able to prove symmetry. It happens very quickly so it's not about speed. But I'm wondering is there even faster.

Cheers :)