Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tessellation independence #54

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions CurvedArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def makeRibs(self, obj):
curvebox = FreeCAD.BoundBox(float("-inf"), float("-inf"), float("-inf"), float("inf"), float("inf"), float("inf"))

for n in range(0, len(obj.Hullcurves)):
cbbx = obj.Hullcurves[n].Shape.BoundBox
cbbx = obj.Hullcurves[n].Shape.optimalBoundingBox(False,False)
if self.doScaleXYZ[n][0]:
if cbbx.XMin > curvebox.XMin: curvebox.XMin = cbbx.XMin
if cbbx.XMax < curvebox.XMax: curvebox.XMax = cbbx.XMax
Expand All @@ -76,19 +76,20 @@ def makeRibs(self, obj):
if self.doScaleXYZ[n][2]:
if cbbx.ZMin > curvebox.ZMin: curvebox.ZMin = cbbx.ZMin
if cbbx.ZMax < curvebox.ZMax: curvebox.ZMax = cbbx.ZMax


h0bbox = obj.Hullcurves[0].Shape.optimalBoundingBox(False,False)
if curvebox.XMin == float("-inf"):
curvebox.XMin = obj.Hullcurves[0].Shape.BoundBox.XMin
curvebox.XMin = h0bbox.XMin
if curvebox.XMax == float("inf"):
curvebox.XMax = obj.Hullcurves[0].Shape.BoundBox.XMax
curvebox.XMax = h0bbox.XMax
if curvebox.YMin == float("-inf"):
curvebox.YMin = obj.Hullcurves[0].Shape.BoundBox.YMin
curvebox.YMin = h0bbox.YMin
if curvebox.YMax == float("inf"):
curvebox.YMax = obj.Hullcurves[0].Shape.BoundBox.YMax
curvebox.YMax = h0bbox.YMax
if curvebox.ZMin == float("-inf"):
curvebox.ZMin = obj.Hullcurves[0].Shape.BoundBox.ZMin
curvebox.ZMin = h0bbox.ZMin
if curvebox.ZMax == float("inf"):
curvebox.ZMax = obj.Hullcurves[0].Shape.BoundBox.ZMax
curvebox.ZMax = h0bbox.ZMax

areavec = Vector(curvebox.XLength, curvebox.YLength, curvebox.ZLength)
deltavec = areavec.scale(obj.Axis.x, obj.Axis.y ,obj.Axis.z) - (obj.OffsetStart + obj.OffsetEnd) * obj.Axis
Expand Down Expand Up @@ -137,10 +138,11 @@ def makeRibs(self, obj):
def makeRibRotate(self, obj, posvec, x, d, ribs):
dolly = self.makeRib(obj, posvec)
if dolly:
dbbox = dolly.optimalBoundingBox(False,False)
if x < len(obj.Twists):
dolly = dolly.rotate(dolly.BoundBox.Center, obj.Axis, obj.Twists[x])
dolly = dolly.rotate(dbbox.Center, obj.Axis, obj.Twists[x])
elif not obj.Twist == 0:
dolly = dolly.rotate(dolly.BoundBox.Center, obj.Axis, obj.Twist * d)
dolly = dolly.rotate(dbbox.Center, obj.Axis, obj.Twist * d)

ribs.append(dolly)

Expand All @@ -167,7 +169,7 @@ def execute(self, prop):
self.doScaleXYZsum = [False, False, False]
sumbbox=None #Define the variable other wise it causes error
for h in prop.Hullcurves:
bbox = h.Shape.BoundBox
bbox = h.Shape.optimalBoundingBox(False,False)
if h == prop.Hullcurves[0]:
sumbbox = bbox
else:
Expand Down
21 changes: 11 additions & 10 deletions CurvedPathArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def makeRibs(self, obj):
curvebox = FreeCAD.BoundBox(float("-inf"), float("-inf"), float("-inf"), float("inf"), float("inf"), float("inf"))

for n in range(0, len(obj.Hullcurves)):
cbbx = obj.Hullcurves[n].Shape.BoundBox
cbbx = obj.Hullcurves[n].Shape.optimalBoundingBox(False,False)
if self.doScaleXYZ[n][0]:
if cbbx.XMin > curvebox.XMin: curvebox.XMin = cbbx.XMin
if cbbx.XMax < curvebox.XMax: curvebox.XMax = cbbx.XMax
Expand All @@ -75,18 +75,19 @@ def makeRibs(self, obj):
if cbbx.ZMax < curvebox.ZMax: curvebox.ZMax = cbbx.ZMax

if len(obj.Hullcurves) > 0:
h0bbox = obj.Hullcurves[0].Shape.optimalBoundingBox(False,False)
if curvebox.XMin == float("-inf"):
curvebox.XMin = obj.Hullcurves[0].Shape.BoundBox.XMin
curvebox.XMin = h0bbox.XMin
if curvebox.XMax == float("inf"):
curvebox.XMax = obj.Hullcurves[0].Shape.BoundBox.XMax
curvebox.XMax = h0bbox.XMax
if curvebox.YMin == float("-inf"):
curvebox.YMin = obj.Hullcurves[0].Shape.BoundBox.YMin
curvebox.YMin = h0bbox.YMin
if curvebox.YMax == float("inf"):
curvebox.YMax = obj.Hullcurves[0].Shape.BoundBox.YMax
curvebox.YMax = h0bbox.YMax
if curvebox.ZMin == float("-inf"):
curvebox.ZMin = obj.Hullcurves[0].Shape.BoundBox.ZMin
curvebox.ZMin = h0bbox.ZMin
if curvebox.ZMax == float("inf"):
curvebox.ZMax = obj.Hullcurves[0].Shape.BoundBox.ZMax
curvebox.ZMax = h0bbox.ZMax

maxlen = 0
edgelen = []
Expand Down Expand Up @@ -114,7 +115,7 @@ def makeRibs(self, obj):
#dolly = self.makeRib(obj, posvec, direction)
dolly = obj.Base.Shape.copy()
if rotaxis.Length > epsilon:
dolly = dolly.rotate(dolly.BoundBox.Center, rotaxis, angle)
dolly = dolly.rotate(dolly.optimalBoundingBox(False,False).Center, rotaxis, angle)

dolly.Placement.Base = posvec
if dolly:
Expand Down Expand Up @@ -152,7 +153,7 @@ def execute(self, prop):
self.doScaleXYZsum = [False, False, False]
bbox = None
for h in prop.Hullcurves:
bbox = h.Shape.BoundBox
bbox = h.Shape.optimalBoundingBox(False,False)
doScale = [False, False, False]

if bbox.XLength > epsilon:
Expand All @@ -168,7 +169,7 @@ def execute(self, prop):

if bbox:
for h in prop.Hullcurves:
bbox.add(h.Shape.BoundBox)
bbox.add(h.Shape.optimalBoundingBox(False,False))

if bbox.XLength > epsilon:
self.doScaleXYZsum[0] = prop.ScaleX
Expand Down
8 changes: 4 additions & 4 deletions CurvedSegment.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def execute(self, fp):
self.doScaleXYZ = []
self.doScaleXYZsum = [False, False, False]
for h in fp.Hullcurves:
bbox = h.Shape.BoundBox
bbox = h.Shape.optimalBoundingBox(False,False)
doScale = [False, False, False]

if bbox.XLength > epsilon:
Expand Down Expand Up @@ -174,7 +174,7 @@ def rescaleRibs(self, fp, ribs):
for i in range(start, end):
d = CurvedShapes.distribute(i / items, fp.Distribution, fp.DistributionReverse)
normal = CurvedShapes.vectorMiddle(fp.NormalShape1, fp.NormalShape2, d)
#Draft.makeLine(ribs[i].BoundBox.Center, ribs[i].BoundBox.Center + normal)
#Draft.makeLine(ribs[i].optimalBoundingBox(False,False).Center, ribs[i].optimalBoundingBox(False,False).Center + normal)
ribs[i] = ribs[i].rotate(bc0+d*(bc1-bc0), normal, fp.Twist * d)
direction = normal
if maxlen>0:
Expand All @@ -193,7 +193,7 @@ def rescaleRibs(self, fp, ribs):
ribs[i].Placement.Base = posvec

if len(fp.Hullcurves) > 0:
bbox = CurvedShapes.boundbox_from_intersect(fp.Hullcurves, ribs[i].BoundBox.Center, direction, self.doScaleXYZ)
bbox = CurvedShapes.boundbox_from_intersect(fp.Hullcurves, ribs[i].optimalBoundingBox(False,False).Center, direction, self.doScaleXYZ)
if bbox:
ribs[i] = CurvedShapes.scaleByBoundbox(ribs[i], bbox, self.doScaleXYZsum, copy=False)

Expand Down Expand Up @@ -235,7 +235,7 @@ def vectorMiddlePlaneNormal(vec1, vec2, fraction, normalShape1, normalShape2):


def getMidPlane(fp, fraction):
midvec = CurvedShapes.vectorMiddle(fp.Shape1.Shape.BoundBox.Center, fp.Shape2.Shape.BoundBox.Center, fraction)
midvec = CurvedShapes.vectorMiddle(fp.Shape1.Shape.optimalBoundingBox(False,False).Center, fp.Shape2.Shape.optimalBoundingBox(False,False).Center, fraction)
midnorm = CurvedShapes.vectorMiddle(fp.NormalShape1, fp.NormalShape2, fraction)
return Part.Plane(midvec, midnorm)

Expand Down
6 changes: 3 additions & 3 deletions CurvedShapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import math
import CompoundTools.Explode

epsilon = 1e-7
epsilon = 1e-6


def addObjectProperty(obj, ptype, pname, *args, init_val=None):
Expand Down Expand Up @@ -140,7 +140,7 @@ def boundbox_from_intersect(curves, pos, normal, doScaleXYZ, nearestpoints=True)


def scaleByBoundbox(shape, boundbox, doScaleXYZ, copy=True):
basebbox = shape.BoundBox
basebbox = shape.optimalBoundingBox(False,False)

scalevec = Vector(1, 1, 1)
if doScaleXYZ[0] and basebbox.XLength > epsilon: scalevec.x = boundbox.XLength / basebbox.XLength
Expand Down Expand Up @@ -283,7 +283,7 @@ def getNormal(obj):
if hasattr(obj, 'Dir'):
return obj.Dir
else:
bbox = obj.Shape.BoundBox
bbox = obj.Shape.optimalBoundingBox(False,False)
if bbox.XLength < epsilon: return Vector(1.0,0.0,0.0)
elif bbox.YLength < epsilon: return Vector(0.0,1.0,0.0)
elif bbox.ZLength < epsilon: return Vector(0.0,0.0,1.0)
Expand Down
2 changes: 1 addition & 1 deletion FlyingWingS800.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def draw_S800():

doc.recompute()
axis=cutpathPoints[1].sub(cutpathPoints[0])
center = ElevonLeft.Placement.Base.add(Vector(midWidth/2, midLength, ElevonLeft.Shape.BoundBox.ZMax))
center = ElevonLeft.Placement.Base.add(Vector(midWidth/2, midLength, ElevonLeft.Shape.optimalBoundingBox(False,False).ZMax))
Draft.rotate([ElevonLeft], ElevonLeftAngle, center, axis=axis, copy=False)
Draft.rotate([ElevonRight1], ElevonRightAngle, center, axis=axis, copy=False)

Expand Down
2 changes: 1 addition & 1 deletion Horten_HIX.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def draw_HortenHIX():
Wing.Tool = TurbineCut
doc.recompute()

ymax = WingSurface.Shape.BoundBox.YMin + WingSurface.Shape.BoundBox.YLength
ymax = WingSurface.Shape.optimalBoundingBox(False,False).YMin + WingSurface.Shape.optimalBoundingBox(False,False).YLength
rota = FreeCAD.Rotation(Vector(0,0,1), 28)
vecToWingEnd28 = rota.multVec(Vector(0,1,0))
WingCutFront = CurvedShapes.cutSurfaces([Wing], Normal = vecToWingEnd28, Position=Vector(0, ymax * 0.85, 0), Face=False, Simplify=0)
Expand Down
10 changes: 5 additions & 5 deletions NotchConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def execute(self, fp):

fp.Proxy = None
if fp.CutDirection == Vector(0.0,0.0,0.0):
bbox1 = self.extractCompounds([fp.Base])[0].Shape.BoundBox
bbox2 = self.extractCompounds(fp.Tools)[0].Shape.BoundBox
bbox1 = self.extractCompounds([fp.Base])[0].Shape.optimalBoundingBox(False,False)
bbox2 = self.extractCompounds(fp.Tools)[0].Shape.optimalBoundingBox(False,False)
v = Vector(1,1,1)

if abs(bbox1.XLength - bbox2.XLength) > epsilon:
Expand Down Expand Up @@ -115,11 +115,11 @@ def cutNotches(self, fp):

for tool in self.extractShapes(fp.Tools):
if fp.ShiftLength == 0:
tbox = tool.optimalBoundingBox()
tbox = tool.optimalBoundingBox(False,False)
common = tool.common(bShape)
cbox = common.BoundBox
cbox = common.optimalBoundingBox(False,False)
if cbox.XLength + cbox.YLength + cbox.ZLength > epsilon:
cbox = common.optimalBoundingBox()
cbox = common.optimalBoundingBox(False,False)
vSize = Vector(cbox.XLength, cbox.YLength, cbox.ZLength)
vPlace = Vector(cbox.XMin, cbox.YMin, cbox.ZMin)
if vSize.x < epsilon or vSize.x > tbox.XLength:
Expand Down
5 changes: 3 additions & 2 deletions SurfaceCut.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ def cutSurfaces(self, fp):
else:
bbox = None
for obj in fp.Surfaces:
obbox = obj.Shape.optimalBoundingBox(False,False)
if not bbox:
bbox = obj.Shape.BoundBox
bbox = obbox
else:
bbox = bbox.united(obj.Shape.BoundBox)
bbox = bbox.united(obbox)

vOffset = Vector(bbox.XMin, bbox.YMin, bbox.ZMin)

Expand Down