2

Sorry if some parts of the question or my followup requests may seem silly, but I am not experienced at all in this field and unfortunately I am on a deadline.

The idea is simple to explain, I have (frame-by-frame) exact 3D coordinates of 25 joints of a Human body. What I require is the corresponding animation video of a human character around it. The idea is similar to this - https://www.youtube.com/watch?v=RPrdDlQXjEg

The difference is that I have frame by frame 3d joint values, not mocap data. Also I want to repeat the process for a huge number of videos so I guess I cannot be doing it manually for every video (again my presumption, if I am wrong let me know).

I have no experience whatsoever in this field. It may seem like I did no research prior to asking this question, but I truely did. It's just that I am really confused as to what my options are and whether it is doable or not.

I don't expect a detailed answer (although if I got one that would be awesome). I am just looking for someone to point me to the right tutorials. Thank You.

Edit : Discussion continued - https://blender.stackexchange.com/questions/122369/create-animation-videos-from-3d-joint-positions

Prakhar Ganesh
  • 117
  • 2
  • 8

1 Answers1

2

Mocap data is just a collection of points moving in time, data from a mocap system may be formatted better than the data you have, so it could be easier to say these points are the left elbow and these are the right ankle. If you can't specify that this sequence of points is this joint in the armature, you can expect troubles.

Let's start by saying you have a sequence of locations clearly identified for each tracking marker by name. Start by creating an empty that recreates each marker.

import bpy

scn = bpy.context.scene
objs = bpy.data.objects
rig = objs['myrig']

mocap_data = {
                    # each item in list is (x,y,z) at each frame
        'elbow.l': [(0,-.5,0),(0,-1,0),(0,-.5,0)],
        'elbow.r': [(0,.5,0), (0,1,0), (0,.5,0)],
        }

for m in mocap_data.keys():
    o = objs.new(m, None)
    scn.objects.link(o)

Each bone in your rig should be named to match the naming of the markers. In the same loop you can also create a ChildOf constraint for each bone, this makes the bone follow its marker.

c = rig.pose.bones[m].constraints.new('CHILD_OF')
c.target = o

Now you want to animate each marker to follow its motion.

for f in range(len(mocap_data['elbow.l'])):
    for m in mocap_data.keys():
        objs[m].location = mocap_data[m][f]
        objs[m].keyframe_insert('location', frame=f+1)

If you want to, you can bake the animation into the armature so you can remove the empties.

Blender includes the Motion Capture Tools addon, which provides tools that may help at some stage. You may also want to look at the Carnegie Mellon University Mocap Library Browser addon, this addon downloads mocap data and assigns it to rigs, it includes a way to transfer the mocap data to a MakeHuman rig, so there may be something you can use or adapt.

sambler
  • 6,917
  • 1
  • 16
  • 23
  • Thanks for the directions. I have a few followup questions. 1. You said create an 'empty'. Empty what? I did not understand that term 2. In the mocap_data dictionary, do the name of the keys need to match some predefined nomenclature or I can simply name them as l_elbow, r_elbow etc.? 3. The naming of bones part, I am not clear what am I supposed to do. – Prakhar Ganesh Nov 06 '18 at 12:03
  • 1
    In blender an [empty is an object](https://docs.blender.org/manual/en/dev/modeling/empties.html) that has no geometry attached to it. The keys in the mocap data can be named how you want, it is much easier if they match the corresponding bone names as you can use the key to reference the bone and matching empty. Every bone in an armature has a name, initially they will be Bone, Bone.001... you name the bones to easily identify each bone and in steps like this to reference the corresponding bone. – sambler Nov 07 '18 at 07:26
  • Now I get it. I am having some trouble with bpy module. I am working on windows. I did pip install for the module. I also have blender software seperately installed. But on trying to run the python code, I am getting the following error -> bpy: couldnt find 'scripts/modules', blender probably wont start. Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly. ModuleNotFoundError: No module named 'bpy_types' and so on .... and then the program just crashes. Do i need to do some more installation before I can use bpy module? – Prakhar Ganesh Nov 07 '18 at 10:29
  • 1
    The `bpy` module is part of the blender application. You [tell blender to run the script](https://stackoverflow.com/questions/53167335/how-to-fix-error-when-importing-the-blender-module-in-python#comment93259999_53167335), with blender running you use its [text editor](https://docs.blender.org/manual/en/dev/editors/text_editor.html) to open and run scripts. – sambler Nov 08 '18 at 07:29
  • What is the first loop through the mocap_data keys do? does it just creates the joint markers? Also, you said loop through the bones and name them according to their corresponding marker, and also add child_of constraints. How do I loop through the bones? – Prakhar Ganesh Nov 08 '18 at 16:59
  • 1
    Yes the first loop creates the markers, you can add the next two lines into the same loop to create the constraints at the same time, the second loop then does the animation. The loop creating the markers and constraints will associate each marker with a bone of the same name. If you needed to loop through the bones you can use `for bone in rig.pose.bones:` – sambler Nov 08 '18 at 21:05
  • 1
    If you need more help specific to blender, ask at [blender.stackexchange](https://blender.stackexchange.com/) – sambler Nov 08 '18 at 21:07
  • Discussion continued - https://blender.stackexchange.com/questions/122369/create-animation-videos-from-3d-joint-positions – Prakhar Ganesh Nov 10 '18 at 11:03
  • Can you please answer my question there. Thank you. – Prakhar Ganesh Nov 10 '18 at 11:03