Fixed adaptive bone length, made it the default again.
This commit is contained in:
parent
d6e75ff4f3
commit
f0d6939bcd
|
@ -69,6 +69,23 @@ def debugCircle(vector, r, label):
|
||||||
obj.Placement = FreeCAD.Placement(vector, FreeCAD.Rotation(FreeCAD.Vector(0,0,1), 0))
|
obj.Placement = FreeCAD.Placement(vector, FreeCAD.Rotation(FreeCAD.Vector(0,0,1), 0))
|
||||||
obj.ViewObject.Transparency = 95
|
obj.ViewObject.Transparency = 95
|
||||||
|
|
||||||
|
def addAngle(a1, a2):
|
||||||
|
a = a1 + a2
|
||||||
|
while a <= -math.pi:
|
||||||
|
a += 2*math.pi
|
||||||
|
while a > math.pi:
|
||||||
|
a -= 2*math.pi
|
||||||
|
return a
|
||||||
|
|
||||||
|
def anglesAreParallel(a1, a2):
|
||||||
|
an1 = addAngle(a1, 0)
|
||||||
|
an2 = addAngle(a2, 0)
|
||||||
|
if an1 == an2:
|
||||||
|
return True
|
||||||
|
if an1 == addAngle(an2, math.pi):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
class Style:
|
class Style:
|
||||||
Dogbone = 'Dogbone'
|
Dogbone = 'Dogbone'
|
||||||
Tbone_H = 'T-bone horizontal'
|
Tbone_H = 'T-bone horizontal'
|
||||||
|
@ -82,6 +99,14 @@ class Side:
|
||||||
Right = 'Right'
|
Right = 'Right'
|
||||||
All = [Left, Right]
|
All = [Left, Right]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def oppositeOf(cls, side):
|
||||||
|
if side == cls.Left:
|
||||||
|
return cls.Right
|
||||||
|
if side == cls.Right:
|
||||||
|
return cls.Left
|
||||||
|
return None
|
||||||
|
|
||||||
class Incision:
|
class Incision:
|
||||||
Fixed = 'fixed'
|
Fixed = 'fixed'
|
||||||
Adaptive = 'adaptive'
|
Adaptive = 'adaptive'
|
||||||
|
@ -246,7 +271,7 @@ class ObjectDressup:
|
||||||
obj.setEditorMode('BoneBlacklist', 2) # hide this one
|
obj.setEditorMode('BoneBlacklist', 2) # hide this one
|
||||||
obj.addProperty("App::PropertyEnumeration", "Incision", "Dressup", QtCore.QT_TRANSLATE_NOOP("Dogbone_Dressup", "The algorithm to determine the bone length"))
|
obj.addProperty("App::PropertyEnumeration", "Incision", "Dressup", QtCore.QT_TRANSLATE_NOOP("Dogbone_Dressup", "The algorithm to determine the bone length"))
|
||||||
obj.Incision = Incision.All
|
obj.Incision = Incision.All
|
||||||
obj.Incision = Incision.Fixed
|
obj.Incision = Incision.Adaptive
|
||||||
obj.addProperty("App::PropertyFloat", "Custom", "Dressup", QtCore.QT_TRANSLATE_NOOP("Dogbone_Dressup", "Dressup length if Incision == custom"))
|
obj.addProperty("App::PropertyFloat", "Custom", "Dressup", QtCore.QT_TRANSLATE_NOOP("Dogbone_Dressup", "Dressup length if Incision == custom"))
|
||||||
obj.Custom = 0.0
|
obj.Custom = 0.0
|
||||||
obj.Proxy = self
|
obj.Proxy = self
|
||||||
|
@ -269,17 +294,22 @@ class ObjectDressup:
|
||||||
def shouldInsertDogbone(self, obj, inChord, outChord):
|
def shouldInsertDogbone(self, obj, inChord, outChord):
|
||||||
return outChord.foldsBackOrTurns(inChord, self.theOtherSideOf(obj.Side))
|
return outChord.foldsBackOrTurns(inChord, self.theOtherSideOf(obj.Side))
|
||||||
|
|
||||||
def adaptiveBoneLength(self, obj, inChord, outChord, angle):
|
def adaptiveBoneLength(self, obj, inChord, outChord, boneAngle):
|
||||||
iChord = inChord.offsetBy(self.toolRadius)
|
inAngle = inChord.getAngleXY()
|
||||||
oChord = outChord.offsetBy(self.toolRadius)
|
outAngle = outChord.getAngleXY()
|
||||||
v = iChord.intersection(oChord, self.toolRadius)
|
# if the bone is on any of the edges - the corner is tangential
|
||||||
dest = inChord.moveTo(FreeCAD.Vector(v.x, v.y, v.z))
|
if anglesAreParallel(boneAngle, inAngle) or anglesAreParallel(boneAngle, outAngle):
|
||||||
destAngle = dest.getAngleXY()
|
return self.toolRadius
|
||||||
distance = dest.getLength() - self.toolRadius * math.fabs(math.cos(destAngle - angle))
|
debugPrint("angle=%.2f in=%.2f out=%.2f" % (boneAngle/math.pi, inAngle/math.pi, outAngle/math.pi))
|
||||||
#debugPrint("adapt")
|
|
||||||
#debugPrint(" in = %s -> %s" % (inChord, iChord))
|
# TODO: need to figure out if there even is an intersection ...
|
||||||
#debugPrint(" out = %s -> %s" % (outChord, oChord))
|
|
||||||
#debugPrint(" = (%.2f, %.2f) -> %.2f (%.2f %.2f) -> %.2f" % (x, y, dest.getLength(), destAngle/math.pi, angle/math.pi, distance))
|
cornerRelAngle = inChord.getAngle(outChord) / 2
|
||||||
|
cornerDistance = self.toolRadius / math.cos(cornerRelAngle)
|
||||||
|
boneRelAngle = addAngle(inAngle, -boneAngle)
|
||||||
|
# only works if there is an intersection, but if there is no intersection, the bone is screwed up anyway
|
||||||
|
distance = cornerDistance - self.toolRadius * math.fabs(math.cos(addAngle(cornerRelAngle, boneRelAngle)))
|
||||||
|
debugPrint("corner=%.2f * %.2f -> bone=%.2f * %.2f" % (cornerDistance, cornerRelAngle, distance, boneRelAngle))
|
||||||
return distance
|
return distance
|
||||||
|
|
||||||
def smoothChordCommands(self, inChord, outChord, side, smooth):
|
def smoothChordCommands(self, inChord, outChord, side, smooth):
|
||||||
|
@ -344,13 +374,9 @@ class ObjectDressup:
|
||||||
def dogboneAngle(self, obj, inChord, outChord):
|
def dogboneAngle(self, obj, inChord, outChord):
|
||||||
baseAngle = inChord.getAngleXY()
|
baseAngle = inChord.getAngleXY()
|
||||||
turnAngle = outChord.getAngle(inChord)
|
turnAngle = outChord.getAngle(inChord)
|
||||||
boneAngle = baseAngle + (turnAngle - math.pi)/2
|
boneAngle = addAngle(baseAngle, (turnAngle - math.pi)/2)
|
||||||
if obj.Side == Side.Left:
|
if obj.Side == Side.Left:
|
||||||
boneAngle = boneAngle + math.pi
|
boneAngle = addAngle(boneAngle, math.pi)
|
||||||
while boneAngle < -math.pi:
|
|
||||||
boneAngle += 2*math.pi
|
|
||||||
while boneAngle > math.pi:
|
|
||||||
boneAngle -= 2*math.pi
|
|
||||||
#debugPrint("base=%+3.2f turn=%+3.2f bone=%+3.2f" % (baseAngle/math.pi, turnAngle/math.pi, boneAngle/math.pi))
|
#debugPrint("base=%+3.2f turn=%+3.2f bone=%+3.2f" % (baseAngle/math.pi, turnAngle/math.pi, boneAngle/math.pi))
|
||||||
return boneAngle
|
return boneAngle
|
||||||
|
|
||||||
|
@ -428,7 +454,7 @@ class ObjectDressup:
|
||||||
enabled = not blacklisted
|
enabled = not blacklisted
|
||||||
self.bones.append((boneId, loc, enabled, inaccessible))
|
self.bones.append((boneId, loc, enabled, inaccessible))
|
||||||
|
|
||||||
if debugDogbone and boneId > 3:
|
if False and debugDogbone and boneId > 5:
|
||||||
bones = self.boneCommands(obj, False, inChord, outChord, smooth)
|
bones = self.boneCommands(obj, False, inChord, outChord, smooth)
|
||||||
else:
|
else:
|
||||||
bones = self.boneCommands(obj, enabled, inChord, outChord, smooth)
|
bones = self.boneCommands(obj, enabled, inChord, outChord, smooth)
|
||||||
|
@ -468,6 +494,8 @@ class ObjectDressup:
|
||||||
for chord in (chord for chord in oddsAndEnds if lastChord.connectsTo(chord)):
|
for chord in (chord for chord in oddsAndEnds if lastChord.connectsTo(chord)):
|
||||||
if self.shouldInsertDogbone(obj, lastChord, chord):
|
if self.shouldInsertDogbone(obj, lastChord, chord):
|
||||||
boneId, lastCommand = self.insertBone(boneId, obj, lastChord, chord, commands, Smooth.In)
|
boneId, lastCommand = self.insertBone(boneId, obj, lastChord, chord, commands, Smooth.In)
|
||||||
|
lastCommand = None
|
||||||
|
commands.append(thisCmd)
|
||||||
elif thisIsACandidate:
|
elif thisIsACandidate:
|
||||||
lastCommand = thisCmd
|
lastCommand = thisCmd
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user