Skip to content

Commit 7f43aaf

Browse files
committed
Added new feature Damping Region
This feature comes with three new settings: Damping Region Object, Linear Damping, and Angular Damping. It allows to define an area using empty objects in which damping effects are to be simulated. This feature is intended to replicate 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 the same user-defined substring in the name.
1 parent 929b6ec commit 7f43aaf

File tree

7 files changed

+391
-24
lines changed

7 files changed

+391
-24
lines changed

kk_bullet_constraints_builder.zip

1.86 KB
Binary file not shown.

kk_bullet_constraints_builder/build_data.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ def storeConfigDataInScene(scene):
153153
scene["bcb_prop_disableCollision"] = props.disableCollision
154154
scene["bcb_prop_disableCollisionPerm"] = props.disableCollisionPerm
155155
scene["bcb_prop_lowerBrkThresPriority"] = props.lowerBrkThresPriority
156+
scene["bcb_prop_dampRegObj"] = props.dampRegObj
157+
scene["bcb_prop_dampRegLin"] = props.dampRegLin
158+
scene["bcb_prop_dampRegAng"] = props.dampRegAng
156159
scene["bcb_prop_detonatorObj"] = props.detonatorObj
157160
scene["bcb_prop_detonatorMul"] = props.detonatorMul
158161
scene["bcb_prop_detonatorMax"] = props.detonatorMax
@@ -388,6 +391,12 @@ def getConfigDataFromScene(scene):
388391
props.disableCollisionPerm = scene["bcb_prop_disableCollisionPerm"]
389392
if "bcb_prop_lowerBrkThresPriority" in scene.keys():
390393
props.lowerBrkThresPriority = scene["bcb_prop_lowerBrkThresPriority"]
394+
if "bcb_prop_dampRegObj" in scene.keys():
395+
props.dampRegObj = scene["bcb_prop_dampRegObj"]
396+
if "bcb_prop_dampRegLin" in scene.keys():
397+
props.dampRegLin = scene["bcb_prop_dampRegLin"]
398+
if "bcb_prop_dampRegAng" in scene.keys():
399+
props.dampRegAng = scene["bcb_prop_dampRegAng"]
391400
if "bcb_prop_detonatorObj" in scene.keys():
392401
props.detonatorObj = scene["bcb_prop_detonatorObj"]
393402
if "bcb_prop_detonatorMul" in scene.keys():

kk_bullet_constraints_builder/file_io.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ def exportConfigData(scene):
159159
configData.append(props.disableCollision)
160160
configData.append(props.disableCollisionPerm)
161161
configData.append(props.lowerBrkThresPriority)
162+
configData.append(props.dampRegObj)
163+
configData.append(props.dampRegLin)
164+
configData.append(props.dampRegAng)
162165
configData.append(props.detonatorObj)
163166
configData.append(props.detonatorMul)
164167
configData.append(props.detonatorMax)
@@ -218,6 +221,9 @@ def importConfigData(scene):
218221
props.disableCollision = configData[i]; i += 1
219222
props.disableCollisionPerm = configData[i]; i += 1
220223
props.lowerBrkThresPriority = configData[i]; i += 1
224+
props.dampRegObj = configData[i]; i += 1
225+
props.dampRegLin = configData[i]; i += 1
226+
props.dampRegAng = configData[i]; i += 1
221227
props.detonatorObj = configData[i]; i += 1
222228
props.detonatorMul = configData[i]; i += 1
223229
props.detonatorMax = configData[i]; i += 1

kk_bullet_constraints_builder/global_props.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ class bcb_props(bpy.types.PropertyGroup):
182182
disableCollision = bool_(name="Disable Collisions", default=1, update=updGlob, description="Disables collisions between connected elements until breach")
183183
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")
184184
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")
185+
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")
186+
dampRegLin = float_(name="Linear Damping", default=0.9, min=0.0, max=1.0, update=updGlob, description="For a Damping Region: Amount of linear velocity that is lost over time")
187+
dampRegAng = float_(name="Angular Damping", default=0.1, min=0.0, max=1.0, update=updGlob, description="For a Damping Region: Amount of angular velocity that is lost over time")
185188
detonatorObj = string_(name="Detonator Object", default="Detonator", update=updGlob, description="Enter name of an object to be used to simulate the effects of an explosion. This feature replicates the damage caused by such an event by weakening the constraints within range of the object. It is recommended to use an Empty object with a sphere shape for this. The damage is calculated as gradient of the distance mapped to the size, from 200% weakening at center to 0% at boundary. Multiple detonators are supported if they contain this string in the name")
186189
detonatorMul = float_(name="Multiplier", default=1, min=0.0, max=1000.0, update=updGlob, description="Multiplier the weakening gradient strength derived from the Detonator object space will be multiplied with (not used for Advanced Detonator)")
187190
detonatorMax = float_(name="Maximum", default=1, min=0.0, max=1.0, update=updGlob, description="Detonator influence maximum to limit the weakening (not used for Advanced Detonator)")
@@ -231,6 +234,7 @@ class bcb_props(bpy.types.PropertyGroup):
231234
exec("elemGrp_%d_EGSidxPrio" %i +" = int_(name='Connection Priority', default=presets[j][EGSidxPrio], min=1, max=9, update=updGlob, description='Changes the connection priority for this element group which will override that the weaker breaking threshold of two elements is preferred for an connection. Lower Strength Priority has similar functionality but works on all groups, however, it is ignored if the priority here is different for a particular connection')")
232235
exec("elemGrp_%d_EGSidxFric" %i +" = float_(name='Friction', default=presets[j][EGSidxFric], min=0.0, max=100000, update=updGlob, description='Coefficient of friction for the given material (dimensionless)')")
233236
exec("elemGrp_%d_EGSidxBlnc" %i +" = float_(name='Balance Masses', default=presets[j][EGSidxBlnc], min=0.0, max=1.0, update=updGlob, description='Factor to balance the masses of elements within this group. A value of 1 assigns the same mass to each element, regardless of size, while maintaining the total mass of the group. This can be useful for force fields that require uniform element masses. A value of 0 (default) calculates masses proportionally based on the elements´ volume')")
237+
exec("elemGrp_%d_EGSidxIter" %i +" = int_(name='Solver Iterations Override', default=presets[j][EGSidxIter], min=0, max=100000, update=updGlob, description='Overrides the Constraint Solver Iterations value of the scene for constraints of this element group if set to a value greater 0. Higher numbers can help to reduce solver induced deformation on elements bearing extreme loads')")
234238
exec("elemGrp_%d_EGSidxSDFl" %i +" = bool_(name='Search Dist. Fallback', default=presets[j][EGSidxSDFl], update=updGlob, description='In case no geometry could be detected within mesh search distance while the neighbor element´s boundary box is still within range this enables a fallback using the intersection of the boundary boxes as contact area instead of the mesh surface. If disabled contact area will remain zero and no connection will be created in that case')")
235239
exec("elemGrp_%d_EGSidxMCTh" %i +" = bool_(name='Mohr-Coulomb Theory', default=presets[j][EGSidxMCTh], update=updGlob, description='Enables the calculation of shear and bending strength using the Mohr-Coulomb theory and makes it stress-related. This method is recommended for masonry structures in earthquake scenarios. Note that the Multiplier setting is also applied to the strength increase')")
236240
exec("elemGrp_%d_EGSidxScal" %i +" = float_(name='Rescale Factor', default=presets[j][EGSidxScal], min=0.0, max=10.0, update=updGlob, description='Applies scaling factor on elements to avoid `Jenga´ effect (undesired stability increase caused by incompressible rigid bodies). This has no influence on breaking threshold and mass calculations')")
@@ -241,7 +245,7 @@ class bcb_props(bpy.types.PropertyGroup):
241245
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')")
242246
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')")
243247
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)')")
244-
exec("elemGrp_%d_EGSidxIter" %i +" = int_(name='Solver Iterations Override', default=presets[j][EGSidxIter], min=0, max=100000, update=updGlob, description='Overrides the Constraint Solver Iterations value of the scene for constraints of this element group if set to a value greater 0. Higher numbers can help to reduce solver induced deformation on elements bearing extreme loads')")
248+
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')")
245249

246250
# Update fromula assistant submenu according to the chosen element group
247251
exec("assistant_menu = enum_(name='Type of Building Material', items=assistant_menu_data, default=presets[j][EGSidxAsst]['ID'], update=updGlob)")
@@ -286,6 +290,7 @@ def props_update_menu(self):
286290
exec("self.elemGrp_%d_EGSidxPrio" %i +" = elemGrps[i][EGSidxPrio]")
287291
exec("self.elemGrp_%d_EGSidxFric" %i +" = elemGrps[i][EGSidxFric]")
288292
exec("self.elemGrp_%d_EGSidxBlnc" %i +" = elemGrps[i][EGSidxBlnc]")
293+
exec("self.elemGrp_%d_EGSidxIter" %i +" = elemGrps[i][EGSidxIter]")
289294
exec("self.elemGrp_%d_EGSidxSDFl" %i +" = elemGrps[i][EGSidxSDFl]")
290295
exec("self.elemGrp_%d_EGSidxMCTh" %i +" = elemGrps[i][EGSidxMCTh]")
291296
exec("self.elemGrp_%d_EGSidxScal" %i +" = elemGrps[i][EGSidxScal]")
@@ -296,7 +301,7 @@ def props_update_menu(self):
296301
exec("self.elemGrp_%d_EGSidxCyln" %i +" = elemGrps[i][EGSidxCyln]")
297302
exec("self.elemGrp_%d_EGSidxDCor" %i +" = elemGrps[i][EGSidxDCor]")
298303
exec("self.elemGrp_%d_EGSidxDClP" %i +" = elemGrps[i][EGSidxDClP]")
299-
exec("self.elemGrp_%d_EGSidxIter" %i +" = elemGrps[i][EGSidxIter]")
304+
exec("self.elemGrp_%d_EGSidxDmpR" %i +" = elemGrps[i][EGSidxDmpR]")
300305

301306
# Update fromula assistant submenu according to the chosen element group
302307
i = self.menu_selectedElemGrp
@@ -357,6 +362,7 @@ def props_update_globals(self):
357362
elemGrps[i][EGSidxPrio] = eval("self.elemGrp_%d_EGSidxPrio" %i)
358363
elemGrps[i][EGSidxFric] = eval("self.elemGrp_%d_EGSidxFric" %i)
359364
elemGrps[i][EGSidxBlnc] = eval("self.elemGrp_%d_EGSidxBlnc" %i)
365+
elemGrps[i][EGSidxIter] = eval("self.elemGrp_%d_EGSidxIter" %i)
360366
elemGrps[i][EGSidxSDFl] = eval("self.elemGrp_%d_EGSidxSDFl" %i)
361367
lastValue = elemGrps[i][EGSidxMCTh]
362368
elemGrps[i][EGSidxMCTh] = eval("self.elemGrp_%d_EGSidxMCTh" %i)
@@ -369,7 +375,7 @@ def props_update_globals(self):
369375
elemGrps[i][EGSidxCyln] = eval("self.elemGrp_%d_EGSidxCyln" %i)
370376
elemGrps[i][EGSidxDCor] = eval("self.elemGrp_%d_EGSidxDCor" %i)
371377
elemGrps[i][EGSidxDClP] = eval("self.elemGrp_%d_EGSidxDClP" %i)
372-
elemGrps[i][EGSidxIter] = eval("self.elemGrp_%d_EGSidxIter" %i)
378+
elemGrps[i][EGSidxDmpR] = eval("self.elemGrp_%d_EGSidxDmpR" %i)
373379
# Remove surface variable if existing (will be added in setConstraintSettings()
374380
elemGrps[i][EGSidxBTC] = elemGrps[i][EGSidxBTC].replace('*a','')
375381
elemGrps[i][EGSidxBTT] = elemGrps[i][EGSidxBTT].replace('*a','')

0 commit comments

Comments
 (0)