Skip to content

Commit 00e2574

Browse files
committed
Further improvements to the Mohr-Coulomb theory feature
1 parent 773da46 commit 00e2574

File tree

3 files changed

+55
-22
lines changed

3 files changed

+55
-22
lines changed

kk_bullet_constraints_builder.zip

394 Bytes
Binary file not shown.

kk_bullet_constraints_builder/builder_setc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ def setConstraintSettings(objs, objsEGrp, emptyObjs, objsID, connectsPair, conne
11241124
elif i == 1: vec = Vector((0, radius, -radius))
11251125
elif i == 2: vec = Vector((0, -radius, 0))
11261126
vec.rotate(rotN)
1127-
locN = loc +vec
1127+
locN = Vector(loc) +vec
11281128
### Enable linear spring
11291129
setConstParams(cData,cDatb,cDef, loc=locN,rotm=rotm, ct='GENERIC_SPRING')
11301130
if CT != 7:
@@ -1160,7 +1160,7 @@ def setConstraintSettings(objs, objsEGrp, emptyObjs, objsID, connectsPair, conne
11601160
elif i == 2: vec = Vector((0, -radius, -radius))
11611161
elif i == 3: vec = Vector((0, -radius, radius))
11621162
vec.rotate(rotN)
1163-
locN = loc +vec
1163+
locN = Vector(loc) +vec
11641164
### Enable linear spring
11651165
setConstParams(cData,cDatb,cDef, loc=locN,rotm=rotm, ct='GENERIC_SPRING')
11661166
if CT != 8:
@@ -1225,7 +1225,7 @@ def setConstraintSettings(objs, objsEGrp, emptyObjs, objsID, connectsPair, conne
12251225
elif j == 1: vec = Vector((0, radius, -radius))
12261226
elif j == 2: vec = Vector((0, -radius, 0))
12271227
vec.rotate(rotN)
1228-
locN = loc +vec
1228+
locN = Vector(loc) +vec
12291229
### Lock direction for compressive force and enable linear spring
12301230
setConstParams(cData,cDatb,cDef, loc=locN,rotm=rotm, ct='GENERIC_SPRING', ullx=1,ully=0,ullz=0, llxl=llxl,llxu=99999, ulax=0,ulay=0,ulaz=0)
12311231
if props.asciiExport:
@@ -1242,7 +1242,7 @@ def setConstraintSettings(objs, objsEGrp, emptyObjs, objsID, connectsPair, conne
12421242
elif j == 1: vec = Vector((0, radius, -radius))
12431243
elif j == 2: vec = Vector((0, -radius, 0))
12441244
vec.rotate(rotN)
1245-
locN = loc +vec
1245+
locN = Vector(loc) +vec
12461246
### Lock direction for tensile force and enable linear spring
12471247
setConstParams(cData,cDatb,cDef, loc=locN,rotm=rotm, ct='GENERIC_SPRING', ullx=1,ully=0,ullz=0, llxl=-99999,llxu=llxu, ulax=0,ulay=0,ulaz=0, uslx=1,usly=1,uslz=1, sdlx=springDamp,sdly=springDamp,sdlz=springDamp)
12481248
if props.asciiExport:
@@ -1259,7 +1259,7 @@ def setConstraintSettings(objs, objsEGrp, emptyObjs, objsID, connectsPair, conne
12591259
elif j == 1: vec = Vector((0, radius, -radius))
12601260
elif j == 2: vec = Vector((0, -radius, 0))
12611261
vec.rotate(rotN)
1262-
locN = loc +vec
1262+
locN = Vector(loc) +vec
12631263
### Lock directions for shearing force and enable linear spring
12641264
setConstParams(cData,cDatb,cDef, loc=locN,rotm=rotm, ct='GENERIC_SPRING', ullx=0,ully=1,ullz=1, llyl=llyl,llyu=llyu,llzl=llzl,llzu=llzu, ulax=0,ulay=0,ulaz=0, uslx=1,usly=1,uslz=1, sdlx=springDamp,sdly=springDamp,sdlz=springDamp)
12651265
if props.asciiExport:
@@ -1295,7 +1295,7 @@ def setConstraintSettings(objs, objsEGrp, emptyObjs, objsID, connectsPair, conne
12951295
elif j == 2: vec = Vector((0, -radius, -radius))
12961296
elif j == 3: vec = Vector((0, -radius, radius))
12971297
vec.rotate(rotN)
1298-
locN = loc +vec
1298+
locN = Vector(loc) +vec
12991299
### Lock direction for compressive force and enable linear spring
13001300
setConstParams(cData,cDatb,cDef, loc=locN,rotm=rotm, ct='GENERIC_SPRING', ullx=1,ully=0,ullz=0, llxl=llxl,llxu=99999, ulax=0,ulay=0,ulaz=0)
13011301
if props.asciiExport:
@@ -1313,7 +1313,7 @@ def setConstraintSettings(objs, objsEGrp, emptyObjs, objsID, connectsPair, conne
13131313
elif j == 2: vec = Vector((0, -radius, -radius))
13141314
elif j == 3: vec = Vector((0, -radius, radius))
13151315
vec.rotate(rotN)
1316-
locN = loc +vec
1316+
locN = Vector(loc) +vec
13171317
### Lock direction for tensile force and enable linear spring
13181318
setConstParams(cData,cDatb,cDef, loc=locN,rotm=rotm, ct='GENERIC_SPRING', ullx=1,ully=0,ullz=0, llxl=-99999,llxu=llxu, ulax=0,ulay=0,ulaz=0, uslx=1,usly=1,uslz=1, sdlx=springDamp,sdly=springDamp,sdlz=springDamp)
13191319
if props.asciiExport:
@@ -1331,7 +1331,7 @@ def setConstraintSettings(objs, objsEGrp, emptyObjs, objsID, connectsPair, conne
13311331
elif j == 2: vec = Vector((0, -radius, -radius))
13321332
elif j == 3: vec = Vector((0, -radius, radius))
13331333
vec.rotate(rotN)
1334-
locN = loc +vec
1334+
locN = Vector(loc) +vec
13351335
### Lock directions for shearing force and enable linear spring
13361336
setConstParams(cData,cDatb,cDef, loc=locN,rotm=rotm, ct='GENERIC_SPRING', ullx=0,ully=1,ullz=1, llyl=llyl,llyu=llyu,llzl=llzl,llzu=llzu, ulax=0,ulay=0,ulaz=0, uslx=1,usly=1,uslz=1, sdlx=springDamp,sdly=springDamp,sdlz=springDamp)
13371337
if props.asciiExport:

kk_bullet_constraints_builder/monitor.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ def monitor_checkForChange(scene):
498498
rbw_steps_per_second = scene.rigidbody_world.steps_per_second
499499
rbw_time_scale = scene.rigidbody_world.time_scale
500500

501+
# Diagnostic verbose
502+
if props.submenu_assistant_advanced:
503+
brokenC, brokenT, brokenS, brokenB = 0, 0, 0, 0
504+
501505
d = 0; e = 0; cntP = 0; cntB = 0
502506
for connect in connects:
503507
conMode = connect[12]
@@ -558,21 +562,30 @@ def monitor_checkForChange(scene):
558562

559563
### Dynamic change of breaking thresholds depending on pressure (Mohr-Coulomb theory)
560564
if qMohrCoulomb:
561-
# Find the maximum force of the compressive constraints in connection
562-
forceMax = 0
563-
for const in consts:
565+
### Diagnostic verbose
566+
if props.submenu_assistant_advanced:
567+
for i in range(0, len(consts)):
568+
con = consts[i].rigid_body_constraint
569+
if not con.isIntact():
570+
if i == 0: brokenC += 1
571+
elif i == 1: brokenT += 1
572+
elif i == 2 or i == 3: brokenS += 1
573+
elif i == 4 or i == 5: brokenB += 1
574+
### Determine force of the compressive constraints in connection
575+
force = 0
576+
for const in consts[:2]: # Only first two constraints can provide a compressive force for most CTs (except spring arrays)
564577
con = const.rigid_body_constraint
565578
### For Point and Fixed costraints
566579
### For Generic constraints
567580
# Compressive constraints
568581
if con.type != 'GENERIC' \
569582
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
583+
forceCon = abs(con.appliedImpulse()) *rbw_steps_per_second /rbw_time_scale # Conversion from impulses to forces
584+
force += forceCon
572585
# Compute new breaking threshold incease based on force
573586
# σ = F /A
574587
# τ = c +σ *tan(ϕ)
575-
brkThresInc = forceMax /contactArea *0.577 *mul
588+
brkThresInc = abs(force) /contactArea *1 *mul
576589
# Modify constraints
577590
for i in range(1, len(consts)): # We know that first constraint is always pressure
578591
con = consts[i].rigid_body_constraint
@@ -584,7 +597,7 @@ def monitor_checkForChange(scene):
584597
if con.type != 'GENERIC' \
585598
or con.use_limit_lin_x \
586599
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:
600+
or con.use_limit_ang_x or con.use_limit_ang_y or con.use_limit_ang_z:
588601
# Apply breaking threshold incease
589602
con.breaking_threshold = constsBrkThres[i] +(brkThresInc *rbw_time_scale /rbw_steps_per_second)
590603

@@ -698,6 +711,9 @@ def monitor_checkForChange(scene):
698711
if cntP > 0: sys.stdout.write(" | Deformed: %d" %cntP)
699712
if cntB > 0: sys.stdout.write(" | Broken: %d" %cntB)
700713
print()
714+
# Diagnostic verbose
715+
if props.submenu_assistant_advanced and (brokenC or brokenT or brokenS or brokenB):
716+
print("Individual constraints broken - C: %d, T: %d, S: %d, B: %d" %(brokenC, brokenT, brokenS, brokenB))
701717

702718
return cntB
703719

@@ -842,6 +858,10 @@ def monitor_checkForChange_fm(scene):
842858
if len(consts) > 0: consIntact.append(consts[0].isIntact())
843859
else: consIntact.append(0)
844860

861+
# Diagnostic verbose
862+
if props.submenu_assistant_advanced:
863+
brokenC, brokenT, brokenS, brokenB = 0, 0, 0, 0
864+
845865
c = 0
846866
for connect in connects:
847867
consts = connect[2]
@@ -858,20 +878,29 @@ def monitor_checkForChange_fm(scene):
858878

859879
### Dynamic change of breaking thresholds depending on pressure (Mohr-Coulomb theory)
860880
if qMohrCoulomb:
861-
# Find the maximum force of the compressive constraints in connection
862-
forceMax = 0
863-
for con in consts:
881+
### Diagnostic verbose
882+
if props.submenu_assistant_advanced:
883+
for i in range(0, len(consts)):
884+
con = consts[i]
885+
if not con.isIntact():
886+
if i == 0: brokenC += 1
887+
elif i == 1: brokenT += 1
888+
elif i == 2 or i == 3: brokenS += 1
889+
elif i == 4 or i == 5: brokenB += 1
890+
### Determine force of the compressive constraints in connection
891+
force = 0
892+
for con in consts[:2]: # Only first two constraints can provide a compressive force for most CTs (except spring arrays)
864893
### For Point and Fixed costraints
865894
### For Generic constraints
866895
# Compressive constraints
867896
if con.type != 'GENERIC' \
868897
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
898+
forceCon = abs(con.appliedImpulse()) *rbw_steps_per_second /rbw_time_scale # Conversion from impulses to forces
899+
force += forceCon
871900
# Compute new breaking threshold incease based on force
872901
# σ = F /A
873902
# τ = c +σ *tan(ϕ)
874-
brkThresInc = forceMax /contactArea *0.577 *mul
903+
brkThresInc = abs(force) /contactArea *1 *mul
875904
# Modify constraints
876905
for i in range(1, len(consts)): # First constraint is always pressure
877906
con = consts[i]
@@ -883,10 +912,14 @@ def monitor_checkForChange_fm(scene):
883912
if con.type != 'GENERIC' \
884913
or con.use_limit_lin_x \
885914
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:
915+
or con.use_limit_ang_x or con.use_limit_ang_y or con.use_limit_ang_z:
887916
# Apply breaking threshold incease
888917
con.breaking_threshold = constsBrkThres[i] +(brkThresInc *rbw_time_scale /rbw_steps_per_second)
889918

919+
# Diagnostic verbose
920+
if props.submenu_assistant_advanced and (brokenC or brokenT or brokenS or brokenB):
921+
print("Individual constraints broken - C: %d, T: %d, S: %d, B: %d" %(brokenC, brokenT, brokenS, brokenB))
922+
890923
################################################################################
891924

892925
def monitor_countIntactConnections_fm(scene):

0 commit comments

Comments
 (0)