Changeset View
Changeset View
Standalone View
Standalone View
mocap/mocap_constraints.py
| Show First 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | if m_constraint.type == "point": | ||||
| real_constraint.use_min_y = True | real_constraint.use_min_y = True | ||||
| real_constraint.use_min_z = True | real_constraint.use_min_z = True | ||||
| if m_constraint.type == "freeze": | if m_constraint.type == "freeze": | ||||
| context.scene.frame_set(s) | context.scene.frame_set(s) | ||||
| real_constraint.owner_space = m_constraint.targetSpace | real_constraint.owner_space = m_constraint.targetSpace | ||||
| bpy.context.scene.frame_set(m_constraint.s_frame) | bpy.context.scene.frame_set(m_constraint.s_frame) | ||||
| if isinstance(cons_obj, bpy.types.PoseBone): | if isinstance(cons_obj, bpy.types.PoseBone): | ||||
| vec = obj.matrix_world * (cons_obj.matrix.to_translation()) | vec = obj.matrix_world @ (cons_obj.matrix.to_translation()) | ||||
| #~ if obj.parent: | #~ if obj.parent: | ||||
| #~ vec = obj.parent.matrix_world * vec | #~ vec = obj.parent.matrix_world @ vec | ||||
| x, y, z = vec | x, y, z = vec | ||||
| else: | else: | ||||
| x, y, z = cons_obj.matrix_world.to_translation() | x, y, z = cons_obj.matrix_world.to_translation() | ||||
| real_constraint.max_x = x | real_constraint.max_x = x | ||||
| real_constraint.max_y = y | real_constraint.max_y = y | ||||
| real_constraint.max_z = z | real_constraint.max_z = z | ||||
| real_constraint.min_x = x | real_constraint.min_x = x | ||||
| Show All 24 Lines | if m_constraint.type == "floor" and m_constraint.targetMesh: | ||||
| s -= s_in | s -= s_in | ||||
| e += s_out | e += s_out | ||||
| bakedPos = {} | bakedPos = {} | ||||
| floor = bpy.data.objects[m_constraint.targetMesh] | floor = bpy.data.objects[m_constraint.targetMesh] | ||||
| c_frame = context.scene.frame_current | c_frame = context.scene.frame_current | ||||
| print("please wait a moment, calculating fix") | print("please wait a moment, calculating fix") | ||||
| for t in range(s, e): | for t in range(s, e): | ||||
| context.scene.frame_set(t) | context.scene.frame_set(t) | ||||
| axis = obj.matrix_world.to_3x3() * Vector((0, 0, 1)) | axis = obj.matrix_world.to_3x3() @ Vector((0, 0, 1)) | ||||
| offset = obj.matrix_world.to_3x3() * Vector((0, 0, m_constraint.targetDist)) | offset = obj.matrix_world.to_3x3() @ Vector((0, 0, m_constraint.targetDist)) | ||||
| ray_origin = (cons_obj.matrix * obj.matrix_world).to_translation() - offset # world position of constrained bone | ray_origin = (cons_obj.matrix @ obj.matrix_world).to_translation() - offset # world position of constrained bone | ||||
| ray_target = ray_origin + axis | ray_target = ray_origin + axis | ||||
| #convert ray points to floor's object space | #convert ray points to floor's object space | ||||
| ray_origin = floor.matrix_world.inverted() * ray_origin | ray_origin = floor.matrix_world.inverted() @ ray_origin | ||||
| ray_target = floor.matrix_world.inverted() * ray_target | ray_target = floor.matrix_world.inverted() @ ray_target | ||||
| ray_direction = ray_target - ray_origin | ray_direction = ray_target - ray_origin | ||||
| ok, hit, nor, ind = floor.ray_cast(ray_origin, ray_direction) | ok, hit, nor, ind = floor.ray_cast(ray_origin, ray_direction) | ||||
| if ok: | if ok: | ||||
| bakedPos[t] = (floor.matrix_world * hit) | bakedPos[t] = (floor.matrix_world @ hit) | ||||
| bakedPos[t] += Vector((0, 0, m_constraint.targetDist)) | bakedPos[t] += Vector((0, 0, m_constraint.targetDist)) | ||||
| else: | else: | ||||
| bakedPos[t] = (cons_obj.matrix * obj.matrix_world).to_translation() | bakedPos[t] = (cons_obj.matrix @ obj.matrix_world).to_translation() | ||||
| context.scene.frame_set(c_frame) | context.scene.frame_set(c_frame) | ||||
| #create keyframes for real constraint | #create keyframes for real constraint | ||||
| xCurves, yCurves, zCurves = createConstraintFCurves(cons_obj, obj, real_constraint) | xCurves, yCurves, zCurves = createConstraintFCurves(cons_obj, obj, real_constraint) | ||||
| for frame in bakedPos.keys(): | for frame in bakedPos.keys(): | ||||
| pos = bakedPos[frame] | pos = bakedPos[frame] | ||||
| for xCurve in xCurves: | for xCurve in xCurves: | ||||
| xCurve.keyframe_points.insert(frame=frame, value=pos.x) | xCurve.keyframe_points.insert(frame=frame, value=pos.x) | ||||
| for yCurve in yCurves: | for yCurve in yCurves: | ||||
| ▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines | |||||