# vr_overlay.py - compare the model with the user's front render 5.jpg pixel by pixel. # pose_ref5(): the render's pose without the bow (joint positions read off a pixel grid on 5.jpg, # 1.37 mm/px, centre x = 1000 px, floor y = 1525 px; depths guessed). # camera_ref5(): a camera matching 5.jpg (85 mm, 36 mm sensor, 2000 x 1611, level at 0.99 m). # render_mask(path): flat silhouette render with alpha, for vr_overlay_compose.py (system Python). import bpy, math from mathutils import Vector as V, Matrix REF5 = { # world targets (m) for the joints in 5.jpg "elbow_r": (-0.40, 0.02, 1.285), "wrist_r": (-0.15, -0.16, 1.29), "elbow_l": (0.29, 0.10, 1.31), "wrist_l": (0.165, -0.07, 1.05), "knee_l": (0.28, -0.01, 0.61), "ankle_l": (0.31, 0.02, 0.165), "knee_r": (-0.30, -0.01, 0.61), "ankle_r": (-0.33, 0.02, 0.165), } def pose_ref5(ps): rig = bpy.data.objects["VR_Rig"] ps["rest"](rig) P = lambda b: rig.matrix_world @ rig.pose.bones[b].head for s in ("_l", "_r"): foot = rig.pose.bones["foot" + s].matrix.copy() ps["_aim"](rig, "thigh" + s, V(REF5["knee" + s]) - P("thigh" + s)) ps["_aim"](rig, "calf" + s, V(REF5["ankle" + s]) - P("calf" + s)) fy = Matrix.Rotation(math.radians(22 if s == "_l" else -22), 3, 'Z') @ V((foot[0][1], foot[1][1], foot[2][1])) ps["_aim"](rig, "foot" + s, fy) # toes turned out, as in 5.jpg ps["_aim"](rig, "upperarm" + s, V(REF5["elbow" + s]) - P("upperarm" + s)) ps["_aim"](rig, "lowerarm" + s, V(REF5["wrist" + s]) - P("lowerarm" + s)) for pb in rig.pose.bones: if pb.name.split("_")[0] in ("index", "middle", "ring", "pinky", "thumb"): pb.rotation_mode = 'XYZ' pb.rotation_euler = (math.radians(-55 if not pb.name.startswith("thumb") else -30), 0, 0) bpy.context.view_layer.update() def camera_ref5(): sc = bpy.context.scene cam = bpy.data.objects.get("VR_Cam_Ref5") if cam is None: cam = bpy.data.objects.new("VR_Cam_Ref5", bpy.data.cameras.new("VR_Cam_Ref5")) bpy.data.collections["VR | Studio"].objects.link(cam) cam.data.lens = 85; cam.data.sensor_fit = 'HORIZONTAL'; cam.data.sensor_width = 36 cam.location = (0, -6.47, 0.99); cam.rotation_euler = (math.radians(90), 0, 0) sc.camera = cam sc.render.resolution_x = 2000; sc.render.resolution_y = 1611; sc.render.resolution_percentage = 100 return cam def render_mask(path): sc = bpy.context.scene keep = (sc.render.engine, sc.render.film_transparent, sc.display.shading.light, sc.display.shading.color_type) floor = bpy.data.objects.get("VR_Studio_Floor") if floor: floor.hide_render = True sc.render.engine = 'BLENDER_WORKBENCH'; sc.render.film_transparent = True sc.display.shading.light = 'FLAT'; sc.display.shading.color_type = 'SINGLE' sc.display.shading.single_color = (1, 1, 1) sc.render.filepath = path bpy.ops.render.render(write_still=True) sc.render.engine, sc.render.film_transparent, sc.display.shading.light, sc.display.shading.color_type = keep if floor: floor.hide_render = False