4
$\begingroup$

Anyways, I am trying to create a folding package with a simple dieline structure. Each flap has a bone in order for it to fold (rotate). (See dieline figure) enter image description here

I have watched a tutorial on how to create bones and pair them to the flaps from its vertices in edit mode. Keep in mind this tutorial is outdated but the features are still there not sure if Blender evolved a feature where I am making an honest mistake: https://www.youtube.com/watch?v=qh2fhnQlJqU&list=PL1ufR-_dSlrGa-rN23kR_C0ACjpi-38JE&index=13&ab_channel=BlenderForDesigners

The video where I am struggling starts at 11:10

Rigging process starts at 12:30

What he does is selects the box and selects the armature > crtl + P (to parent) > with empty groups > tab into edit mode with that panel > go to vertex groups > "select top points" then click assign > tab out of edit mode > select armature > pose mode (blue highlight) > rotate armature.

I've done these steps to the teeth and no good results. I can't move the armature in pose mode, I can only move it in object mode and when I do it only moves the single flap and not the rest along with the larger flap (see figure below). enter image description here Object mode it can but not with the rest: enter image description here

So, at that point I thought its a parenting problem, checked out another video on YouTube to see how to do it: https://www.youtube.com/watch?v=i_I4XWATOYk&list=PL1ufR-_dSlrGa-rN23kR_C0ACjpi-38JE&index=115

and still no success..

Not sure what to do at this point. If I could figure out how to do this, it will change my career. Here is the Blender file I am working on, maybe it can point out something I am missing. Thanks 🙏

$\endgroup$
2
  • $\begingroup$ Heya, you don't need to explain yourself with the intro, you can jump right into the question to skip formalities and save time reading. We can see you've put time into explaining, there are pictures, videos, your process, blend file and you even put tags. You did great job don't worry:) If only more people would ask questions like you.. $\endgroup$ Jan 31 at 7:20
  • $\begingroup$ Ha I see it's not your first try to write this, but you improved, this one is much better quality than the rest. $\endgroup$ Jan 31 at 7:24
5
$\begingroup$

You can't move the panel in Pose mode because you haven't assigned any vertex of the panel to any vertex group in Edit mode, parenting With Empty Groups won't assign any vertex, it will just create vertex groups but by default no vertex is assigned to these groups for the moment, the object is waiting for you to assign its vertices to the right group, i.e. the group that has the name of the bone that is supposed to control it. Also, I'm not sure why you have made one object per panel, it will be much more convenient if you join them all into one object imho.

$\endgroup$
5
$\begingroup$

Ditch the bones and make an object hierarchy.

enter image description here

Since each flap of your test file is a separate object would suggest can be done without the extra hassle of creating an armature.

For simplicity the face with the most folds is selected as the parent. Its origin is arbitrary and has been kept as the center of geometry.

Now for each flap connected to this, move its origin to the middle of the fold edge and parent to it.

And so on. In example the top flap is parented to the left flap which is parented to the bottom flap.

Make sure the rotation is applied on all the flaps.

Angle axis Rotation.

One of the rotation types available in blender is axis angle. ie how much to rotate about a particular axis, which is ideal in this case, since the fold determines the axis.

enter image description here

For example the front and bottom faces fold on the X axis. To keep the angle of fold direction desired positive, the -X axis is chosen for front flap.

Custom Rotation for a tilted aircraft flap

Driving the result.

Since for simple example, flat is angle 0 and folded is angle 90. Added a simple custom property "prop" to the bottom which goes from 0 (flat) to 90 degrees (pi / 2) folded and driven each child flap with it.

enter image description here

and here is the end result.

enter image description here

Same for armatures.

enter image description here

Slapped this together, thought I'd add it here. Can make a single mesh where each edge between two flaps is exactly aligned down the axis of the hinge.

Makes an armature and puts in hinge bones with head in closest point on of edge to face center, and tail pointing towards the face center. This will ensure that the bone always hinges on the X axis (1, 0, 0). With the mesh in XY plane the bone z axis matches the global z axis (or face normals)

All the hinge bones rotation modes are set to axis angle.

Each hinge bone is given a name with the edge index appended.

If a temp mesh is made as such, the location of the face center will become the bone tip. The actual objects can be parented to tip, or constraints used.

Added vertex groups to each face of the object.

Select the base face of the folding structure and run script.

import bpy
from mathutils import Matrix, Vector
from mathutils.geometry import intersect_point_line
import bmesh
context = bpy.context

def hinge(armob, ob, pb, face):
    arm = armob.data
    # add a bone from edge center to face center
    face.select_set(True)
    edges = [(l, f) for l in face.loops for f in l.edge.link_faces if not f.select]

    for l, f in edges:
        e = l.edge
        b = arm.edit_bones.new(f"Hinge_{f.index}")
        b.parent = pb
        pt, dist = intersect_point_line(
                f.calc_center_median(),
                e.verts[1].co,
                e.verts[0].co,
                ) 
        b.head = pt
        b.tail = f.calc_center_median()
        vg = (
                ob.vertex_groups.get(b.name) or
                ob.vertex_groups.new(name=b.name)
                )
        vg.add([v.index for v in f.verts], 1, 'ADD')
        hinge(armob, ob, b, f)

def make_armature(ob, face_index):
    me = ob.data
    bm = bmesh.from_edit_mesh(me).copy()
    
    face = bm.faces.active
    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.ops.object.armature_add()
    arm = context.object

    mw = (
            ob.parent.matrix_world.copy() if ob.parent
            else ob.matrix_world.copy()
        )

    ob.matrix_parent_inverse.identity()
    #ob.matrix_world.identity()
    ob.parent = arm
    ob.matrix_parent_inverse = ob.matrix_world.inverted()
    ob.vertex_groups.clear()
    
    arm.matrix_world = ob.matrix_world
    bpy.ops.object.mode_set(mode='EDIT')
    b = arm.data.edit_bones[0]
    b.tail += face.calc_center_median()
    b.head += face.calc_center_median()
    hinge(arm, ob, b, face) 

    bpy.ops.object.mode_set(mode='OBJECT')  
    for pb in arm.pose.bones[1:]:

        pb.rotation_mode = 'AXIS_ANGLE'
        pb.rotation_axis_angle = (0, 1, 0, 0)
    ob.modifiers.clear() 
    mod = ob.modifiers.new(
            "Hinger",
            type='ARMATURE',
            )
    mod.object = arm 
    bpy.ops.object.mode_set(mode='POSE') 
make_armature(context.object, 0) 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.