-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_hinges.py
74 lines (55 loc) · 2.71 KB
/
move_hinges.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import bpy
#sce = bpy.context.scene
#ob = bpy.context.object
#bpy.ops.ptcache.bake_all(bake=True)
#print(dir(bpy.data.scenes["Scene"].rigidbody_world.constraints.objects["hip_front_r_hinge"].rotation_axis_angle))
print(dir(bpy.context.object.animation_data))
#print(bpy.data.scenes["Scene"].rigidbody_world.constraints.objects["hip_back_r_mot"].rotation_axis_angle[0])
def SetHingeOptions(object):
object.rigid_body_constraint.breaking_threshold = 0.1
object.rigid_body_constraint.use_breaking = False
object.rigid_body_constraint.solver_iterations = 100
object.rigid_body_constraint.use_override_solver_iterations = True
def SetMotorVelocity(object, velo = 0.0):
object.rigid_body_constraint.motor_ang_target_velocity = velo
object.rigid_body_constraint.motor_ang_max_impulse = 5000.0
if (velo == 0.0):
object.rigid_body_constraint.use_motor_ang = False
else:
object.rigid_body_constraint.use_motor_ang = True
def my_handler(scene):
try:
my_handler.my_velo += 0.0
if(bpy.context.scene.frame_current == 1):
my_handler.my_velo = 0.0
if(bpy.context.scene.frame_current > 100):
my_handler.my_velo -= 10.0
except AttributeError:
my_handler.my_velo = 0.0 # it doesn't exist yet, so initialize it
SetMotorVelocity(scene.objects["hip_front_l_mot"], my_handler.my_velo)
print(my_handler.my_velo)
print(scene.objects["hip_back_r_mot"].matrix_world.translation)
def register():
bpy.app.handlers.frame_change_post.clear()
bpy.app.handlers.frame_change_post.append(my_handler)
def unregister():
bpy.app.handlers.frame_change_post.remove(my_handler)
SetMotorVelocity(bpy.data.objects["knee_front_l_mot"], 0.0)
SetMotorVelocity(bpy.data.objects["knee_front_r_mot"], 0.0)
SetMotorVelocity(bpy.data.objects["knee_back_l_mot"], 0.0)
SetMotorVelocity(bpy.data.objects["knee_back_r_mot"], 0.0)
SetMotorVelocity(bpy.data.objects["hip_front_l_mot"], 0.0)
SetMotorVelocity(bpy.data.objects["hip_front_r_mot"], 0.0)
SetMotorVelocity(bpy.data.objects["hip_back_l_mot"], 0.0)
SetMotorVelocity(bpy.data.objects["hip_back_r_mot"], 0.0)
SetHingeOptions(bpy.data.objects["knee_front_l_hinge"])
SetHingeOptions(bpy.data.objects["knee_front_r_hinge"])
SetHingeOptions(bpy.data.objects["knee_back_l_hinge"])
SetHingeOptions(bpy.data.objects["knee_back_r_hinge"])
SetHingeOptions(bpy.data.objects["hip_front_l_hinge"])
SetHingeOptions(bpy.data.objects["hip_front_r_hinge"])
SetHingeOptions(bpy.data.objects["hip_back_l_hinge"])
SetHingeOptions(bpy.data.objects["hip_back_r_hinge"])
# get object list
print(bpy.data.objects["hip_back_r_mot"])
register()