1
$\begingroup$

I am writing a script which takes makehuman model and bvh files aS input and create animation. i also want to get coordinates of each vertex in image space after rendering, i write this script

for f in range(0,tracking_frames):
                #updating frame number for tracking coordinates of vertices in image space
                bpy.context.scene.frame_set(f)
                pointTracking(curr_scn,person_name+":Body",bpy.data.cameras[0].name,f)

def pointTracking(scene,person_body,scene_camera_name,frame_number):
    # needed to rescale 2d coordinates
    render = scene.render
    res_x = render.resolution_x
    res_y = render.resolution_y

    obj = bpy.data.objects[person_body]
    cam = bpy.data.objects[scene_camera_name]

    # use generator expressions () or list comprehensions []
    total_vg = len(obj.vertex_groups.items())
    #print(total_vg)
    #print("inserting")
    tracking_data = []
    for j in range(total_vg):
            track_per_group = []
            vg_index= j
            vs = [v for v in obj.data.vertices if (vg_index in [vg.group for vg in v.groups])]
            #print(vs)
            vertc = (vert.co for vert in vs)
            coords_2d = [world_to_camera_view(scene, cam, coord) for coord in vertc]
            #print(coords_2d)
            # 2d data printout:
            rnd = lambda i: round(i)
            rnd3 = lambda i: round(i, 3)

            #limit_finder = lambda f: f(coords_2d, key=lambda i: i[2])[2]
            #limits = limit_finder(min), limit_finder(max)
            #limits = [rnd3(d) for d in limits]

            # x, y, d=distance_to_lens
            print('x,y,d')
            print("Vertex_group for:",obj.vertex_groups.items()[j][0])
            track_per_group.append(frame_number)
            track_per_group.append(obj.vertex_groups.items()[j][0])
            for x, y, d in coords_2d:
                track_per_group.append((rnd(res_x*x), rnd(res_y*y), rnd3(d)))
                #print("{},{},{}".format(rnd(res_x*x), rnd(res_y*y), rnd3(d)))
            tracking_data.append(track_per_group)            
    with open("Point_tracking_"+bvhName+person_mhx2+".csv","a") as f:
        writer = csv.writer(f)
        writer.writerows(tracking_data)

how to verify that this code is updating locations of vertices after each frame, since when i checked in software itself, the object world matrix does not changes after updating frames because it shows that mhx model is fixed at origin as it was initially therefor locally vertices coordinates are also same after updating each frame.

enter image description here

location after retargetting bvh file changes which is shown in this picture, what i think is that as the mhx model body is fixed and therefore obj.data.vertices[0].co is producing same coordinates for all the frames.

if i did not explained it very clear please let me know! i know its hard to explain for me. Thank you in advanced

$\endgroup$
  • $\begingroup$ The vertices are moved by the armature modifier. The object matrix won't change. Python by default gives the undeformed positions. You need to make a copy with the modifiers applied each frame. $\endgroup$ – Sazerac Jul 8 at 12:19
  • $\begingroup$ @Sazerac did you mean something like this blender.stackexchange.com/a/3463/75100 , since i am new to blender i never used blender before this project, will you please exaplain it more! $\endgroup$ – Bunny Jul 8 at 13:00
  • $\begingroup$ Yeah, I think that should be what you need. $\endgroup$ – Sazerac Jul 8 at 13:02
  • $\begingroup$ @Sazerac but that answer also mentioned that it does not track same vertices always, indices can change after modifiers applied so the tracking coordinate of vertices miss lead $\endgroup$ – Bunny Jul 8 at 13:09
  • $\begingroup$ Depends on the modifiers, so long as none change the vert count you should be fine. Might need to remove subdivision if it is there. $\endgroup$ – Sazerac Jul 8 at 13:11

Your Answer

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

Browse other questions tagged or ask your own question.