Skip to content

Commit cd14449

Browse files
committed
Fixed some long-lasting update issue with the GUI
- Also improved the recently added Mohr-Coulomb theory feature - Fixed older bug with Estimate Cluster Radius
1 parent 87cbd6e commit cd14449

File tree

10 files changed

+321
-213
lines changed

10 files changed

+321
-213
lines changed

kk_bullet_constraints_builder.zip

1.13 KB
Binary file not shown.

kk_bullet_constraints_builder/build_data.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def getConfigDataFromScene(scene):
196196

197197
### Preprocessing Tools
198198

199+
props.update_lock = 1 # Suppress automatic updating to set a new property value
200+
199201
if "bcb_prop_preprocTools_aut" in scene.keys():
200202
props.preprocTools_aut = scene["bcb_prop_preprocTools_aut"]
201203

@@ -406,6 +408,11 @@ def getConfigDataFromScene(scene):
406408
props.detonPullBackDelay = scene["bcb_prop_detonPullBackDelay"]
407409
if "bcb_prop_detonGroundReflect" in scene.keys():
408410
props.detonGroundReflect = scene["bcb_prop_detonGroundReflect"]
411+
412+
props.update_lock = 0
413+
414+
###### Update global vars from menu properties
415+
props.props_update_globals()
409416

410417
#if len(warning): return warning
411418

kk_bullet_constraints_builder/builder_prep.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def initGeneralRigidBodyWorldSettings(scene):
5555
scene.render.fps_base = 1
5656
print("New Frame Rate set to:", scene.render.fps)
5757
else:
58+
props.update_lock = 1 # Suppress automatic updating to set a new property value
5859
props.stepsPerSecond = scene.render.fps *int(props.stepsPerSecond /scene.render.fps)
60+
props.update_lock = 0
5961
print("New Solver Steps set to:", props.stepsPerSecond)
6062
if props.stepsPerSecond %scene.render.fps != 0 or scene.render.fps_base != 1:
6163
fps = props.stepsPerSecond /int(props.stepsPerSecond /scene.render.fps)

kk_bullet_constraints_builder/file_io.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def importConfigData(scene):
189189
return 1
190190
else:
191191
props = bpy.context.window_manager.bcb
192+
props.update_lock = 1 # Suppress automatic updating to set a new property value
192193
i += 1
193194
props.stepsPerSecond = configData[i]; i += 1
194195
props.solverIterations = configData[i]; i += 1
@@ -227,7 +228,12 @@ def importConfigData(scene):
227228
props.detonBlastWaveVel = configData[i]; i += 1
228229
props.detonPullBackDelay = configData[i]; i += 1
229230
props.detonGroundReflect = configData[i]; i += 1
231+
props.update_lock = 0
232+
###### Update global vars from menu properties
233+
props.props_update_globals()
234+
230235
global_vars.elemGrps = configData[i]; i += 1
236+
231237
return 0
232238

233239
################################################################################

kk_bullet_constraints_builder/formula_props.py

Lines changed: 86 additions & 48 deletions
Large diffs are not rendered by default.

kk_bullet_constraints_builder/global_props.py

Lines changed: 154 additions & 124 deletions
Large diffs are not rendered by default.

kk_bullet_constraints_builder/gui.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
def dpifac100():
4242
prefs = bpy.context.user_preferences.system
43-
if hasattr(prefs, 'pixel_size'): # python access to this was only added recently, assume non-retina display is used if using older blender
43+
if hasattr(prefs, 'pixel_size'): # Python access to this was only added recently, assume non-retina display is used if using older blender
4444
retinafac = bpy.context.user_preferences.system.pixel_size
4545
else:
4646
retinafac = 1
@@ -50,31 +50,34 @@ class bcb_report(bpy.types.Operator):
5050
bl_idname = "bcb.report"
5151
bl_label = "Info"
5252
bl_description = "Report message operator"
53+
54+
message = bpy.props.StringProperty()
55+
icon = bpy.props.StringProperty()
56+
5357
def execute(self, context):
5458
return {'FINISHED'}
59+
5560
def invoke(self, context, event):
5661
wm = context.window_manager
57-
props = context.window_manager.bcb
58-
print(props.message)
62+
print(self.message)
5963
# Calculate safe width in pixel from char count of the string
60-
strSize = len(props.message)
64+
strSize = len(self.message)
6165
# widthPx = (strSize*12+40) /dpifac100() # Approx. width for capitals
6266
widthPx = (strSize*8+30) /dpifac100() # Approx. width for normal text
6367
#return wm.invoke_props_dialog(self)
6468
return wm.invoke_popup(self, width=widthPx, height=300)
69+
6570
def draw(self, context):
66-
layout = self.layout
67-
props = context.window_manager.bcb
68-
message = props.message
69-
row = layout.row()
70-
row.label(text=message, icon="ERROR")
71+
row = self.layout.row()
72+
row.label(text=self.message, icon=self.icon)
73+
row.alert = True # Red background
7174

7275
########################################
7376

7477
class bcb_add_preset(bpy.types.Menu):
7578
bl_idname = "bcb.add_preset"
7679
bl_label = "Available Presets"
77-
bl_description = "Duplicates selected element group"
80+
bl_description = "Adds a preset element group to list"
7881
def draw(self, context):
7982
layout = self.layout
8083
#layout.operator("wm.open_mainfile")
@@ -148,9 +151,6 @@ def draw(self, context):
148151
split2 = split.split(align=1)
149152
split2.operator("bcb.set_config", icon="NEW")
150153

151-
### Update global vars from menu related properties
152-
props.props_update_globals()
153-
154154
########################################
155155

156156
class bcb_panel_preprocessing_tools(bpy.types.Panel):

kk_bullet_constraints_builder/gui_buttons.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from tools import * # Contains smaller independently working tools
4646

4747
################################################################################
48-
48+
4949
class OBJECT_OT_bcb_set_config(bpy.types.Operator):
5050
bl_idname = "bcb.set_config"
5151
bl_label = ""
@@ -203,7 +203,8 @@ class OBJECT_OT_bcb_export_ascii_fm(bpy.types.Operator):
203203
use_handler = int_(default = 0)
204204
def execute(self, context):
205205
if not hasattr(bpy.types.DATA_PT_modifiers, 'FRACTURE'):
206-
self.report({'ERROR'}, "Fracture Modifier not available in this Blender version. Visit kaikostack.com/fracture for the FM-enabled Blender version.") # Create popup message
206+
# Create popup message
207+
self.report({'ERROR'}, "This feature requires a Blender version with Fracture Modifier. Visit kaikostack.com/fracture for the FM-enabled Blender version.")
207208
else:
208209
###### Execute main building process from scratch
209210
scene = bpy.context.scene
@@ -337,8 +338,11 @@ def execute(self, context):
337338
if self.menuIdx < 0:
338339
# Call menu
339340
bpy.ops.wm.call_menu(name="bcb.add_preset")
340-
else:
341+
print("DEBUG button", self.menuIdx)
342+
if self.menuIdx >= 0:
341343
props = context.window_manager.bcb
344+
# Update global vars (only for initializing on new scene)
345+
props.props_update_globals()
342346
elemGrps = global_vars.elemGrps
343347
# Add element group (syncing element group indices happens on execution)
344348
elemGrps.append(presets[self.menuIdx].copy())

kk_bullet_constraints_builder/monitor.py

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -558,24 +558,35 @@ def monitor_checkForChange(scene):
558558

559559
### Dynamic change of breaking thresholds depending on pressure (Mohr-Coulomb theory)
560560
if qMohrCoulomb:
561-
# Get force acting on the compressive constraints in connection
562-
force = abs(consts[0].rigid_body_constraint.appliedImpulse()) *rbw_steps_per_second /rbw_time_scale # Conversion from impulses to forces
561+
# Find the maximum force of the compressive constraints in connection
562+
forceMax = 0
563+
for const in consts:
564+
con = const.rigid_body_constraint
565+
### For Point and Fixed costraints
566+
### For Generic constraints
567+
# Compressive constraints
568+
if con.type != 'GENERIC' \
569+
or con.use_limit_lin_x:
570+
force = abs(con.appliedImpulse()) *rbw_steps_per_second /rbw_time_scale # Conversion from impulses to forces
571+
if force > forceMax: forceMax = force
563572
# Compute new breaking threshold incease based on force
564573
# σ = F /A
565574
# τ = c +σ *tan(ϕ)
566-
brkThresInc = force /contactArea *0.577 *mul
575+
brkThresInc = forceMax /contactArea *0.577 *mul
567576
# Modify constraints
568577
for i in range(1, len(consts)): # We know that first constraint is always pressure
569578
con = consts[i].rigid_body_constraint
570-
# Set override to shear connections in connection
571-
if con.type != 'GENERIC': # For Point and Fixed costraints
579+
### For Point and Fixed costraints
580+
### For Generic constraints
581+
# Tensile constraints - Comment this line out to include all constraints
582+
# Shear constraints - Comment this line out to include all constraints
583+
# Bend constraints - Comment this line out to include all constraints
584+
if con.type != 'GENERIC' \
585+
or con.use_limit_lin_x \
586+
or con.use_limit_lin_y or con.use_limit_lin_z \
587+
or con.use_limit_ang_y or con.use_limit_ang_z:
588+
# Apply breaking threshold incease
572589
con.breaking_threshold = constsBrkThres[i] +(brkThresInc *rbw_time_scale /rbw_steps_per_second)
573-
else: # For Generic constraints
574-
if con.use_limit_lin_y or con.use_limit_lin_z: # Shear constraints - Comment this line out to include all constraints
575-
con.breaking_threshold = constsBrkThres[i] +(brkThresInc *rbw_time_scale /rbw_steps_per_second)
576-
# Set override to bend connections in connection
577-
if con.use_limit_ang_y or con.use_limit_ang_z: # Bend constraints - Comment this line out to include all constraints
578-
con.breaking_threshold = constsBrkThres[i] +(brkThresInc *rbw_time_scale /rbw_steps_per_second)
579590

580591
# ### Modify limits from applied forces
581592
# strainDist = .001 # Maximum linear strain for the given breaking threshold
@@ -634,7 +645,7 @@ def monitor_checkForChange(scene):
634645
# strain = abs(force) /brkThres # Normalized to breaking threshold
635646
# if strain > strainMax: strainMax = strain
636647
# strainIters = iterMin +(iterMax -iterMin) *strainMax # Compute iterations from strain
637-
# # Set override only to shear connections in connection
648+
# # Set override only to shear constraints in connection
638649
# for const in consts:
639650
# con = const.rigid_body_constraint
640651
# if con.use_limit_lin_y or con.use_limit_lin_z: # Shear constraints - Comment this line out to include all constraints
@@ -847,25 +858,35 @@ def monitor_checkForChange_fm(scene):
847858

848859
### Dynamic change of breaking thresholds depending on pressure (Mohr-Coulomb theory)
849860
if qMohrCoulomb:
850-
# Get force acting on the compressive constraints in connection
851-
force = abs(consts[0].appliedImpulse()) *rbw_steps_per_second /rbw_time_scale # Conversion from impulses to forces
861+
# Find the maximum force of the compressive constraints in connection
862+
forceMax = 0
863+
for con in consts:
864+
### For Point and Fixed costraints
865+
### For Generic constraints
866+
# Compressive constraints
867+
if con.type != 'GENERIC' \
868+
or con.use_limit_lin_x:
869+
force = abs(con.appliedImpulse()) *rbw_steps_per_second /rbw_time_scale # Conversion from impulses to forces
870+
if force > forceMax: forceMax = force
852871
# Compute new breaking threshold incease based on force
853872
# σ = F /A
854873
# τ = c +σ *tan(ϕ)
855-
brkThresInc = force /contactArea *0.577 *mul
874+
brkThresInc = forceMax /contactArea *0.577 *mul
856875
# Modify constraints
857876
for i in range(1, len(consts)): # First constraint is always pressure
858877
con = consts[i]
859-
# Set override to shear connections in connection
860-
if con.type != 'GENERIC': # For Point and Fixed costraints
878+
### For Point and Fixed costraints
879+
### For Generic constraints
880+
# Tensile constraints - Comment this line out to include all constraints
881+
# Shear constraints - Comment this line out to include all constraints
882+
# Bend constraints - Comment this line out to include all constraints
883+
if con.type != 'GENERIC' \
884+
or con.use_limit_lin_x \
885+
or con.use_limit_lin_y or con.use_limit_lin_z \
886+
or con.use_limit_ang_y or con.use_limit_ang_z:
887+
# Apply breaking threshold incease
861888
con.breaking_threshold = constsBrkThres[i] +(brkThresInc *rbw_time_scale /rbw_steps_per_second)
862-
else: # For Generic constraints
863-
if con.use_limit_lin_y or con.use_limit_lin_z: # Shear constraints - Comment this line out to include all constraints
864-
con.breaking_threshold = constsBrkThres[i] +(brkThresInc *rbw_time_scale /rbw_steps_per_second)
865-
# Set override to bend connections in connection
866-
if con.use_limit_ang_y or con.use_limit_ang_z: # Bend constraints - Comment this line out to include all constraints
867-
con.breaking_threshold = constsBrkThres[i] +(brkThresInc *rbw_time_scale /rbw_steps_per_second)
868-
889+
869890
################################################################################
870891

871892
def monitor_countIntactConnections_fm(scene):

kk_bullet_constraints_builder/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
def tool_estimateClusterRadius(scene):
5555

56-
objs, emptyObjs = gatherObjects(scene)
56+
objs, emptyObjs, objsID = gatherObjects(scene)
5757

5858
if len(objs) > 0:
5959
print("Estimating optimal cluster radius...")

0 commit comments

Comments
 (0)