0
$\begingroup$

I usually only used ".. With automatic weights" when using Armatures. Now I hit a limitation and need help.

I am modeling a book (and want to do Pages later too, which are less stiff than the book cover!)

I'd be fine with 2 lanes of bones, but many vertices bent unwanted so I added more...

But for the Pages I'd like to have 3-5 lanes to make them bend more.

enter image description here

As you can see, the "belt" (brown) isn't affected by the bones at all. enter image description here

Which makes sense, as there is 0 weight linked from the belt to the closest bone. I tried using envelope bones and "... with envelope weights" but that's also a bit strange to work with. enter image description here

I don't want to paint the weight for every bone by hand. That's a really destructive workflow. I'd rather write a python script to assign weight based on x asis (which would be enough in this case)

Is there a builtin function, or how would you approach it? Otherwise, does anyone have a script that does something simliar (to get me started)? looping over bones and setting weights?

Thanks!


edit: Here is a .blend file:

$\endgroup$
2
  • $\begingroup$ can you upload the file? $\endgroup$ Commented Oct 14, 2022 at 13:25
  • $\begingroup$ @mqbakamqbaka - I added the file $\endgroup$
    – KYL3R
    Commented Oct 14, 2022 at 14:40

1 Answer 1

2
$\begingroup$

I wrote a script for the pages and hand-assigned some vertex groups for the book cover. Here is a comparison of problems and my solutions:

The Page Mesh

The Mesh

Compare the Deformation of "With Automatic Weights" vs my Scripted weights. Automatic is a bit crooked and the center bone-row leaves the mesh, because there is not enough weight assigned: enter image description here

The lower side of the page is not static, see gif here: https://i.imgur.com/2fzQFOn.mp4

Lets have a look at the actual weights:

enter image description here

Automatic weights

My Scripted Weights

See my script below. Now, here is how I fixed the book cover and belt:

I used "[Vertex Groups] -> Remove from All" and then assigned the vertices to a single group with 100% weight to make it stiff.

BookCoverAndBeltFix

Here is the before/after comparison:

enter image description here

Here is a video where you can see the book and the pages in action:

https://i.imgur.com/3DrMeiV.mp4

And here is my script, if anyone is interested:

import bpy
from math import sqrt, pow

# HowTo: Select Armature, then Mesh, then go to WeightPaint mode.
# Clear all Vertex Groups / create them by parenting with automatic weights/empty groups
# make sure object is scaled uniformly (1,1,1)
# Replace 'Armature.005' with your Armatures Name
# run script


# ensure we are in edit mode
bpy.ops.object.mode_set(mode="EDIT")

obj = bpy.context.edit_object
mesh = obj.data

# bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.object.mode_set(mode="WEIGHT_PAINT")

print("Working")

for i in mesh.vertices:
    # obj.vertex_groups[dst_group].add([i], 1 - obj.vertex_groups[src_group].weight(i), 'REPLACE')
    for group in obj.vertex_groups:
        boneName = group.name
        armature = bpy.data.armatures['Armature.005']
        bone = armature.bones[boneName]

        vertexPos = i.co # .co = coordinates aka position

        center_local = (bone.head_local + bone.tail_local) / 2

        ydist = abs(center_local.y - vertexPos.y)
        zdist = abs(center_local.z - vertexPos.z)

        zFactor = 4
        yFactor = 1
        weight = min((1 - zdist * zFactor), (1 - ydist * yFactor))

        obj.vertex_groups[group.name].add([i.index], weight, 'REPLACE')

print("Finished")

imgur album: https://i.sstatic.net/l12xy.jpg

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .