Skip to content

Commit 2552f7a

Browse files
committed
Made Disable Collision Connection an element group setting for better control
Also added handling of possible division by zero in frame rate calculation.
1 parent 3f3b00e commit 2552f7a

File tree

9 files changed

+82
-70
lines changed

9 files changed

+82
-70
lines changed

kk_bullet_constraints_builder.zip

140 Bytes
Binary file not shown.

kk_bullet_constraints_builder/build_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def storeConfigDataInScene(scene):
152152
scene["bcb_prop_progrWeakLimit"] = props.progrWeakLimit
153153
scene["bcb_prop_progrWeakStartFact"] = props.progrWeakStartFact
154154
scene["bcb_prop_snapToAreaOrient"] = props.snapToAreaOrient
155-
scene["bcb_prop_disableCollision"] = props.disableCollision
155+
scene["bcb_prop_disableCollisionCon"] = props.disableCollisionCon
156156
scene["bcb_prop_disableCollisionPerm"] = props.disableCollisionPerm
157157
scene["bcb_prop_lowerBrkThresPriority"] = props.lowerBrkThresPriority
158158
scene["bcb_prop_dampRegObj"] = props.dampRegObj
@@ -390,8 +390,8 @@ def getConfigDataFromScene(scene):
390390
props.progrWeakStartFact = scene["bcb_prop_progrWeakStartFact"]
391391
if "bcb_prop_snapToAreaOrient" in scene.keys():
392392
props.snapToAreaOrient = scene["bcb_prop_snapToAreaOrient"]
393-
if "bcb_prop_disableCollision" in scene.keys():
394-
props.disableCollision = scene["bcb_prop_disableCollision"]
393+
if "bcb_prop_disableCollisionCon" in scene.keys():
394+
props.disableCollisionCon = scene["bcb_prop_disableCollisionCon"]
395395
if "bcb_prop_disableCollisionPerm" in scene.keys():
396396
props.disableCollisionPerm = scene["bcb_prop_disableCollisionPerm"]
397397
if "bcb_prop_lowerBrkThresPriority" in scene.keys():

kk_bullet_constraints_builder/builder_fm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def build_fm(use_handler=0):
182182

183183
# Change some FM settings
184184
md.fracture_mode = 'PREFRACTURED'
185-
md.use_constraint_collision = not props.disableCollision
185+
md.use_constraint_collision = not props.disableCollisionCon
186186
md.fracture_mode = 'EXTERNAL'
187187

188188
# Enable Dynamic Paint brush settings for FM object to make it interact with dynamic surfaces like water

kk_bullet_constraints_builder/builder_prep.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def initGeneralRigidBodyWorldSettings(scene):
4949
# Automatically correct the FPS rate or Solver Steps as the FPS must be multiples of the Solver Steps to avoid stuttering
5050
if props.stepsPerSecond %scene.render.fps != 0 or scene.render.fps_base != 1:
5151
print("Warning: Solver Steps should be multiples of the Frame Rate, trying to fix it...")
52-
fps = props.stepsPerSecond /int(props.stepsPerSecond /scene.render.fps)
52+
multiple = int(props.stepsPerSecond /scene.render.fps)
53+
if multiple > 0: fps = props.stepsPerSecond /multiple
54+
else: fps = props.stepsPerSecond
5355
if fps %int(fps) == 0:
5456
scene.render.fps = fps
5557
scene.render.fps_base = 1

kk_bullet_constraints_builder/builder_setc.py

Lines changed: 39 additions & 34 deletions
Large diffs are not rendered by default.

kk_bullet_constraints_builder/file_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def exportConfigData(scene):
156156
configData.append(props.progrWeakLimit)
157157
configData.append(props.progrWeakStartFact)
158158
configData.append(props.snapToAreaOrient)
159-
configData.append(props.disableCollision)
159+
configData.append(props.disableCollisionCon)
160160
configData.append(props.disableCollisionPerm)
161161
configData.append(props.lowerBrkThresPriority)
162162
configData.append(props.dampRegObj)
@@ -218,7 +218,7 @@ def importConfigData(scene):
218218
props.progrWeakLimit = configData[i]; i += 1
219219
props.progrWeakStartFact = configData[i]; i += 1
220220
props.snapToAreaOrient = configData[i]; i += 1
221-
props.disableCollision = configData[i]; i += 1
221+
props.disableCollisionCon = configData[i]; i += 1
222222
props.disableCollisionPerm = configData[i]; i += 1
223223
props.lowerBrkThresPriority = configData[i]; i += 1
224224
props.dampRegObj = configData[i]; i += 1

kk_bullet_constraints_builder/global_props.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class bcb_props(bpy.types.PropertyGroup):
181181
progrWeakLimit = int_(name="Progr. Weak. Limit", default=10, min=0, max=10000, update=updGlob, description="For progressive weakening: Limits the weakening process by the number of broken connections per frame. If the limit is exceeded weakening will be disabled for the rest of the simulation")
182182
progrWeakStartFact = float_(name="Start Weakness", default=1, min=0.0, max=1.0, update=updGlob, description="Start weakness as factor all breaking thresholds will be multiplied with. This can be used to quick-change the initial thresholds without performing a full update")
183183
snapToAreaOrient = bool_(name="90° Axis Snapping for Const. Orient.", default=1, update=updGlob, description="Enables axis snapping based on contact area orientation for constraints rotation instead of using center to center vector alignment (old method)")
184-
disableCollision = bool_(name="Disable Collisions", default=1, update=updGlob, description="Disables collisions between connected elements until breach")
184+
disableCollisionCon = bool_(name="Dis. Col. Connection", default=1, update=updGlob, description="Disables collisions between connected elements until breach")
185185
disableCollisionPerm = bool_(name="Dis. Col. Permanently", default=0, update=updGlob, description="Disables collisions between initially connected elements permanently. This can help to make simulations with intersecting geometry more stable at the cost of accuracy")
186186
lowerBrkThresPriority = bool_(name="Lower Strength Priority", default=1, update=updGlob, description="Gives priority to the weaker breaking threshold of two elements from different element groups with same Priority value to be connected, if disabled the stronger value is used for the connection")
187187
dampRegObj = string_(name="Damping Region Object", default="Waterbody", update=updGlob, description="Enter the name of an object to define the region in which the damping effects should be simulated. This feature is intended to simulate environments with a higher viscosity than air, e.g. water. Note: The element groups must be activated individually for the effect to take effect. Multiple damping regions are supported if they contain this string in the name")
@@ -246,6 +246,7 @@ class bcb_props(bpy.types.PropertyGroup):
246246
exec("elemGrp_%d_EGSidxFacg" %i +" = bool_(name='Facing', default=presets[j][EGSidxFacg], update=updGlob, description='Generates an addional layer of elements only for display (will only be used together with bevel and scale option, also serves as backup and for mass calculation)')")
247247
exec("elemGrp_%d_EGSidxCyln" %i +" = bool_(name='Cylindric Shape', default=presets[j][EGSidxCyln], update=updGlob, description='Interpret connection area as round instead of rectangular (ar = a *pi/4). This can be useful when you have to deal with cylindrical columns')")
248248
exec("elemGrp_%d_EGSidxDCor" %i +" = bool_(name='Displ. Correction', default=presets[j][EGSidxDCor], update=updGlob, description='Enables the correction of initial displacements. This can compensate for sagging structures such as bridges that would otherwise require a very high solver step count to be straight. To do this, the simulation must be run twice. On the first run, the displacements are saved into an external file when the warm-up period ends. In the second run (rebuilding required), the differences are integrated into the mesh. Delete the external file to reset')")
249+
exec("elemGrp_%d_EGSidxDCol" %i +" = bool_(name='Dis. Col. Connection', default=presets[j][EGSidxDCol], update=updGlob, description='Disables collisions between connected elements of this element group until breach (overrides global setting)')")
249250
exec("elemGrp_%d_EGSidxDClP" %i +" = bool_(name='Dis. Col. Permanently', default=presets[j][EGSidxDClP], update=updGlob, description='Disables collisions between initially connected elements of this element group permanently (overrides global setting)')")
250251
exec("elemGrp_%d_EGSidxDmpR" %i +" = bool_(name='Damp. Region', default=presets[j][EGSidxDmpR], update=updGlob, description='Enables the Damping Region feature for this element group. Refer to Advanced Global Settings to define boundary objects and damping parameters')")
251252

@@ -302,6 +303,7 @@ def props_update_menu(self):
302303
exec("self.elemGrp_%d_EGSidxFacg" %i +" = elemGrps[i][EGSidxFacg]")
303304
exec("self.elemGrp_%d_EGSidxCyln" %i +" = elemGrps[i][EGSidxCyln]")
304305
exec("self.elemGrp_%d_EGSidxDCor" %i +" = elemGrps[i][EGSidxDCor]")
306+
exec("self.elemGrp_%d_EGSidxDCol" %i +" = elemGrps[i][EGSidxDCol]")
305307
exec("self.elemGrp_%d_EGSidxDClP" %i +" = elemGrps[i][EGSidxDClP]")
306308
exec("self.elemGrp_%d_EGSidxDmpR" %i +" = elemGrps[i][EGSidxDmpR]")
307309

@@ -376,6 +378,7 @@ def props_update_globals(self):
376378
elemGrps[i][EGSidxFacg] = eval("self.elemGrp_%d_EGSidxFacg" %i)
377379
elemGrps[i][EGSidxCyln] = eval("self.elemGrp_%d_EGSidxCyln" %i)
378380
elemGrps[i][EGSidxDCor] = eval("self.elemGrp_%d_EGSidxDCor" %i)
381+
elemGrps[i][EGSidxDCol] = eval("self.elemGrp_%d_EGSidxDCol" %i)
379382
elemGrps[i][EGSidxDClP] = eval("self.elemGrp_%d_EGSidxDClP" %i)
380383
elemGrps[i][EGSidxDmpR] = eval("self.elemGrp_%d_EGSidxDmpR" %i)
381384
# Remove surface variable if existing (will be added in setConstraintSettings()

0 commit comments

Comments
 (0)