mirror bone weights

Animation tools, character animation, non linear animation

Moderators: jesterKing, stiv

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

mirror bone weights

Post by kakapo »

a mirror bone weights function would be a nice time saver!

(i hope i didn't miss an already existing feature? :))

z3r0_d
Posts: 289
Joined: Wed Oct 16, 2002 2:38 am
Contact:

Post by z3r0_d »

it would work the same way as a copy vertex colors feature

... which doesn't exist


what you can do is duplicate the half of your mesh [a regular duplicate, not a linked one], mirror it [in edit mode if you like] and then rename the groups as necescary. Then join with the original half and use remove doubles to get rid of the seam. This will get your weights to the other side

however, once the other side exists, there is no way to get the weights copied there...

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

hm... sounds like a pain...

wouldn't such a feature be worth to be included in the 2.4 update? or am i the only one who would find it helpful? :)

...could this be done with a python script? if the mesh is symetric it shouldn't be a big problem?

nemyax
Posts: 0
Joined: Mon May 31, 2004 12:34 pm

Post by nemyax »

kakapo,
Surely you're not the only one. I've brought up the feature before:
http://blender.org/forum/viewtopic.php?t=6573
But the thread sort of went unnoticed. Hopefully, this thread will get developers' attention. I'd say this feature makes a lot of sense.

UncleZeiv
Posts: 0
Joined: Mon Aug 29, 2005 1:11 pm

Post by UncleZeiv »

Hi, I had the same problem and wrote a custom script for it. I would love to post it but unfortunately is custom-taylored for my convenience and would serve only as a guideline for an actual, more general script. But maybe again someone has already written it.

_dave_

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

it would be nice if you could post your script!

UncleZeiv
Posts: 0
Joined: Mon Aug 29, 2005 1:11 pm

Post by UncleZeiv »

Okay so, here you are. This is far from perfect and maybe it's not even exactly what you need, but with some quick changes it could suit your needs.

Please note that I have removed some unnecessary parts and changed the code here and there, so I'm not entirely sure that it runs as is ;)

z3r0_d's solution is actually simpler, but you can still use Python to automate vertex group renaming.

Code: Select all

#!BPY

# """
# Name: 'Mirror Vertex Groups'
# Blender: 237
# Group: 'Misc'
# Tooltip: 'Mirror Vertex Groups With Weights'
# """

# first of all, select your mesh
# your mesh will have all the left (.L) vertex groups with correct weights
# now duplicate and mirror the left part so that each left group includes also right vertices
# we don't care about .R groups, if they already exist or not

import Blender
from Blender import NMesh, Object

import re

# get selected mesh
av_mesh_obj = Object.GetSelected()[0]
av_mesh = av_mesh_obj.getData()

grouplist = av_mesh.getVertGroupNames()

# for each vertex group that ends in ".L" ...
for i in grouplist:
    if re.search('\.L$', i) == None:
        continue
    
# find out the name of the corresponding .R group...
    mirrorgroup = re.sub('\.L$', '.R', i)

# ... and clear any vertex that it could already have
    av_mesh.removeVertsFromGroup(mirrorgroup)
    
# for each of its vertices whose X coordinate is < 0...
    vertlist = av_mesh.getVertsFromGroup(i, True)
    ourverts = [v for v in vertlist if av_mesh.verts[v[0]].co.x < 0.0]

# erase them from left group
    av_mesh.removeVertsFromGroup(i, [v[0] for v in ourverts])

# add them with correct weigths in the Right group
    for i in ourverts:
        av_mesh.assignVertsToGroup(mirrorgroup, [i[0]], i[1], 'replace')

That's it. As you can see, it's quite simple.

_dave_

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

thanks! i think this will get me started. i will try to work on a solution which doesn't require to mirror the mesh manually...

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

getVertexInfluences(index)
Get influences of bones in a specific vertex.

Parameters:
index - The index of a vertex.
(type=int)

Returns:
List of pairs (name, weight), where name is the bone name (string) and its weight is a float value.
(type=list of lists)
is this function broken? have you ever tried to use it? it doesn't return anything for me. it would be very convenient for my solution. probably i will have to do some workaround with the other functions...

UncleZeiv
Posts: 0
Joined: Mon Aug 29, 2005 1:11 pm

Post by UncleZeiv »

kakapo wrote:
getVertexInfluences(index) [...]
is this function broken? have you ever tried to use it?
Yes I used it for an exporter and it worked. I don't know why it is broken for you: maybe you edited the mesh and run the script without exiting from edit mode? Changes to the mesh, vertex groups etc. are not committed until you exit from edit mode.

_dave_

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

i use the latest windows build from the test builds forum. does it work for you with that one? i wasn't in edit mode.

Code: Select all

from Blender import NMesh, Object

o = Object.GetSelected()[0]
m = o.getData()

for i in range(1000):
	print m.getVertexInfluences(i),
this always just returns lots of [] [] [] [] []...!
Last edited by kakapo on Fri Oct 07, 2005 2:33 pm, edited 1 time in total.

UncleZeiv
Posts: 0
Joined: Mon Aug 29, 2005 1:11 pm

Post by UncleZeiv »

I'm sorry, I'm using blender 2.37a on linux ;) The problem you are experiencing doesn't seem to be you fault, anyway.

_dave_

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

hm... maybe the problem of the function has something to do with the new bone envelopes.

i will try to fill a dictionary to get the same functionality.

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

today i had time to work on my version. it does exactly what i want. :)

it copies the weights from right to left on the x-axis. the mesh has to be symmetrical (you can set a threshold) and the groups of each side already have to exist.

here it is. maybe it's helpful for some of you:

Code: Select all

new version below
maybe something like that with more options and error checks could be bundled with blender?
Last edited by kakapo on Fri Oct 14, 2005 3:29 pm, edited 1 time in total.

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

Image

i have added a gui and did some other improvements.

copy it to your scripts folder:

Code: Select all

new version below
please tell me what you think and report bugs!
Last edited by kakapo on Fri Oct 14, 2005 3:52 pm, edited 3 times in total.

Post Reply