1

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

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
Vikram
  • 41
  • 2
  • 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. – Sazerac Jul 08 '19 at 12:19
  • @Sazerac did you mean something like this https://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! – Vikram Jul 08 '19 at 13:00
  • Yeah, I think that should be what you need. – Sazerac Jul 08 '19 at 13:02
  • @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 – Vikram Jul 08 '19 at 13:09
  • 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. – Sazerac Jul 08 '19 at 13:11
  • @Sazerac what you mean by removing subdivision? as i am working with bvh armatures as modifiers, will it be fine ? – Vikram Jul 08 '19 at 13:17
  • Check that the mesh doesn't have a subdivision modifier. I can't remember whether the makehuman importer adds one of not. – Sazerac Jul 08 '19 at 13:19
  • @Sazerac i write the code same way as mentioned in https://blender.stackexchange.com/a/3463/75100 and i set camera at 3 unit distance from the origin where mhx model is set initially before retargetting, after retargetting my output z-coordinate for vertices is also fluctuating around 3 unit.. that means still the mesh is at origin, it is not translated by armature, in rendering animation there is no problem at all. – Vikram Jul 08 '19 at 14:51

0 Answers0