Skip to content

Commit 12483db

Browse files
committed
Added support for Warm Up Period to also work on motor constraints
Also fixed rigid body cache start frame number not being updated from Blender timeline.
1 parent 6747136 commit 12483db

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

kk_bullet_constraints_builder.zip

364 Bytes
Binary file not shown.

kk_bullet_constraints_builder/builder_prep.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def initGeneralRigidBodyWorldSettings(scene):
7272
scene.rigidbody_world.steps_per_second = props.stepsPerSecond
7373
scene.rigidbody_world.solver_iterations = props.solverIterations
7474
# Set the length of the point cache to match the scene length
75+
scene.rigidbody_world.point_cache.frame_start = scene.frame_start
7576
scene.rigidbody_world.point_cache.frame_end = scene.frame_end
7677
# Set Split Impulse for rigid body simulation
7778
#scene.rigidbody_world.use_split_impulse = True

kk_bullet_constraints_builder/monitor.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def monitor_eventHandler(scene):
149149
if props.progrWeakStartFact != 1:
150150
monitor_progressiveWeakening(scene, props.progrWeakStartFact)
151151

152+
### Motor constraint warm up period
153+
monitor_motorWarmUp(scene)
154+
152155
### Displacement correction initialization
153156
monitor_displCorrectDiffExport(scene)
154157

@@ -207,6 +210,10 @@ def monitor_eventHandler(scene):
207210
###### Function
208211
monitor_fixSprings(scene)
209212

213+
### Motor constraint warm up period
214+
if scene.frame_current < scene.frame_start +props.warmUpPeriod:
215+
monitor_motorWarmUp(scene)
216+
210217
### Displacement correction vertex location differences export
211218
if scene.frame_current == scene.frame_start +props.warmUpPeriod:
212219
monitor_displCorrectDiffExport(scene)
@@ -241,6 +248,9 @@ def monitor_eventHandler(scene):
241248
if props.progrWeakStartFact != 1:
242249
monitor_progressiveWeakening_fm(scene, props.progrWeakStartFact)
243250

251+
### Motor constraint warm up period
252+
monitor_motorWarmUp_fm(scene)
253+
244254
### Displacement correction initialization
245255
monitor_displCorrectDiffExport(scene)
246256

@@ -294,6 +304,10 @@ def monitor_eventHandler(scene):
294304
###### Function
295305
monitor_fixSprings_fm(scene)
296306

307+
### Motor constraint warm up period
308+
if scene.frame_current < scene.frame_start +props.warmUpPeriod:
309+
monitor_motorWarmUp_fm(scene)
310+
297311
### Displacement correction vertex location differences export
298312
if scene.frame_current == scene.frame_start +props.warmUpPeriod:
299313
monitor_displCorrectDiffExport(scene)
@@ -1288,6 +1302,61 @@ def monitor_progressiveWeakening_fm(scene, progrWeakVar):
12881302

12891303
################################################################################
12901304

1305+
def monitor_motorWarmUp(scene):
1306+
1307+
if debug: print("Calling motorWarmUp")
1308+
1309+
props = bpy.context.window_manager.bcb
1310+
1311+
# Find motor constraints (not BCB generated)
1312+
try: emptyObjs = bpy.data.groups["RigidBodyConstraints"].objects
1313+
except: emptyObjs = []
1314+
emptyObjs = [obj for obj in emptyObjs if obj.type == 'EMPTY' and not obj.hide and obj.is_visible(bpy.context.scene) and obj.rigid_body_constraint != None]
1315+
1316+
if scene.frame_current == scene.frame_start:
1317+
factor = 1 /props.warmUpPeriod
1318+
else:
1319+
factor = 1 /(scene.frame_current -scene.frame_start) +1
1320+
1321+
for objConst in emptyObjs:
1322+
const = objConst.rigid_body_constraint
1323+
if const.type == 'MOTOR' and const.enabled:
1324+
if const.use_motor_lin:
1325+
const.motor_lin_target_velocity *= factor
1326+
const.motor_lin_max_impulse *= factor
1327+
if const.use_motor_ang:
1328+
const.motor_ang_target_velocity *= factor
1329+
const.motor_ang_max_impulse *= factor
1330+
1331+
########################################
1332+
1333+
def monitor_motorWarmUp_fm(scene):
1334+
1335+
if debug: print("Calling motorWarmUp_fm")
1336+
1337+
props = bpy.context.window_manager.bcb
1338+
1339+
# Get Fracture Modifier
1340+
try: ob = scene.objects[asciiExportName]
1341+
except: print("Error: Fracture Modifier object expected but not found."); return
1342+
md = ob.modifiers["Fracture"]
1343+
1344+
if scene.frame_current == scene.frame_start:
1345+
factor = 1 /props.warmUpPeriod
1346+
else:
1347+
factor = 1 /(scene.frame_current -scene.frame_start) +1
1348+
1349+
for const in md.mesh_constraints:
1350+
if const.type == 'MOTOR' and const.enabled:
1351+
if const.use_motor_lin:
1352+
const.motor_lin_target_velocity *= factor
1353+
const.motor_lin_max_impulse *= factor
1354+
if const.use_motor_ang:
1355+
const.motor_ang_target_velocity *= factor
1356+
const.motor_ang_max_impulse *= factor
1357+
1358+
################################################################################
1359+
12911360
def monitor_dampingRegion(scene):
12921361

12931362
if debug: print("Calling dampingRegion")

0 commit comments

Comments
 (0)