[Bf-extensions-cvs] [fde9aa0a] master: archipack: Fix issue with curved segments in walls/slab/floor
Stephen Leger
noreply at git.blender.org
Mon Aug 14 01:16:37 CEST 2017
Commit: fde9aa0a3fe223e7f2eb03010faf626bac925780
Author: Stephen Leger
Date: Thu Aug 3 15:59:40 2017 +0200
Branches: master
https://developer.blender.org/rBAfde9aa0a3fe223e7f2eb03010faf626bac925780
archipack: Fix issue with curved segments in walls/slab/floor
===================================================================
M archipack/archipack_2d.py
M archipack/archipack_cutter.py
M archipack/archipack_fence.py
M archipack/archipack_floor.py
M archipack/archipack_slab.py
M archipack/archipack_wall2.py
M archipack/panel.py
===================================================================
diff --git a/archipack/archipack_2d.py b/archipack/archipack_2d.py
index fcd578da..4bf0d1f1 100644
--- a/archipack/archipack_2d.py
+++ b/archipack/archipack_2d.py
@@ -116,6 +116,7 @@ class Line(Projection):
else:
self.p = Vector((0, 0))
self.v = Vector((0, 0))
+ self.line = None
@property
def copy(self):
@@ -162,6 +163,10 @@ class Line(Projection):
return atan2(self.v.y, self.v.x)
@property
+ def a0(self):
+ return self.angle
+
+ @property
def angle_normal(self):
"""
2d angle of perpendicular
@@ -365,7 +370,7 @@ class Line(Projection):
if hasattr(last, "r"):
res, d, t = line.point_sur_segment(last.c)
c = (last.r * last.r) - (d * d)
- print("t:%s" % t)
+ # print("t:%s" % t)
if c <= 0:
# no intersection !
p0 = line.lerp(t)
@@ -455,8 +460,6 @@ class Arc(Circle):
"""
Represent a 2d Arc
TODO:
- Add some sugar here
- like being able to set p0 and p1 of line
make it possible to define an arc by start point end point and center
"""
def __init__(self, c, radius, a0, da):
@@ -473,6 +476,7 @@ class Arc(Circle):
stored internally as radians
"""
Circle.__init__(self, Vector(c).to_2d(), radius)
+ self.line = None
self.a0 = a0
self.da = da
@@ -575,6 +579,15 @@ class Arc(Circle):
"""
return self.r * abs(self.da)
+ @property
+ def oposite(self):
+ a0 = self.a0 + self.da
+ if a0 > pi:
+ a0 -= 2 * pi
+ if a0 < -pi:
+ a0 += 2 * pi
+ return Arc(self.c, self.r, a0, -self.da)
+
def normal(self, t=0):
"""
Perpendicular line starting at t
@@ -628,6 +641,26 @@ class Arc(Circle):
steps = max(1, round(abs(self.da) / step_angle, 0))
return 1.0 / steps, int(steps)
+ def as_lines(self, steps):
+ """
+ convert Arc to lines
+ """
+ res = []
+ p0 = self.lerp(0)
+ for step in range(steps):
+ p1 = self.lerp((step + 1) / steps)
+ s = Line(p0=p0, p1=p1)
+ res.append(s)
+ p0 = p1
+
+ if self.line is not None:
+ p0 = self.line.lerp(0)
+ for step in range(steps):
+ p1 = self.line.lerp((step + 1) / steps)
+ res[step].line = Line(p0=p0, p1=p1)
+ p0 = p1
+ return res
+
def offset(self, offset):
"""
Offset circle
diff --git a/archipack/archipack_cutter.py b/archipack/archipack_cutter.py
index 69bd16c2..b5a64776 100644
--- a/archipack/archipack_cutter.py
+++ b/archipack/archipack_cutter.py
@@ -62,7 +62,7 @@ class CutterSegment(Line):
def offset(self, offset):
s = self.copy
- s.p += offset * self.cross_z.normalized()
+ s.p += self.sized_normal(0, offset).v
return s
@property
@@ -206,6 +206,18 @@ class CutAblePolygon():
- holes
- convex
"""
+ def as_lines(self, step_angle=0.104):
+ """
+ Convert curved segments to straight lines
+ """
+ segs = []
+ for s in self.segs:
+ if "Curved" in type(s).__name__:
+ dt, steps = s.steps_by_angle(step_angle)
+ segs.extend(s.as_lines(steps))
+ else:
+ segs.append(s)
+ self.segs = segs
def inside(self, pt, segs=None):
"""
@@ -471,8 +483,9 @@ class CutAbleGenerator():
of = offset[s.type]
else:
of = offset['DEFAULT']
- p0 = s.p0 + s.cross_z.normalized() * of
- self.bissect(bm, p0.to_3d(), s.cross_z.to_3d(), clear_outer=False)
+ n = s.sized_normal(0, 1).v
+ p0 = s.p0 + n * of
+ self.bissect(bm, p0.to_3d(), n.to_3d(), clear_outer=False)
# compute boundary with offset
new_s = None
@@ -495,7 +508,8 @@ class CutAbleGenerator():
else:
for s in hole.segs:
if s.length > 0:
- self.bissect(bm, s.p0.to_3d(), s.cross_z.to_3d(), clear_outer=False)
+ n = s.sized_normal(0, 1).v
+ self.bissect(bm, s.p0.to_3d(), n.to_3d(), clear_outer=False)
# use hole boundary
segs = hole.segs
if len(segs) > 0:
@@ -518,12 +532,14 @@ class CutAbleGenerator():
of = offset[s.type]
else:
of = offset['DEFAULT']
- p0 = s.p0 + s.cross_z.normalized() * of
- self.bissect(bm, p0.to_3d(), s.cross_z.to_3d(), clear_outer=cutable.convex)
+ n = s.sized_normal(0, 1).v
+ p0 = s.p0 + n * of
+ self.bissect(bm, p0.to_3d(), n.to_3d(), clear_outer=cutable.convex)
else:
for s in cutable.segs:
if s.length > 0:
- self.bissect(bm, s.p0.to_3d(), s.cross_z.to_3d(), clear_outer=cutable.convex)
+ n = s.sized_normal(0, 1).v
+ self.bissect(bm, s.p0.to_3d(), n.to_3d(), clear_outer=cutable.convex)
if not cutable.convex:
f_geom = [f for f in bm.faces
diff --git a/archipack/archipack_fence.py b/archipack/archipack_fence.py
index 7006b3b1..0f5f3b37 100644
--- a/archipack/archipack_fence.py
+++ b/archipack/archipack_fence.py
@@ -52,7 +52,6 @@ class Fence():
self.t_end = 0
self.dz = 0
self.z0 = 0
- self.a0 = 0
def set_offset(self, offset, last=None):
"""
@@ -622,12 +621,19 @@ def update_type(self, context):
else:
w = w0.curved_fence(part.a0, part.da, part.radius)
else:
- g = FenceGenerator(None)
- g.add_part(self)
- w = g.segs[0]
+ if "C_" in self.type:
+ p = Vector((0, 0))
+ v = self.length * Vector((cos(self.a0), sin(self.a0)))
+ w = StraightFence(p, v)
+ a0 = pi / 2
+ else:
+ c = -self.radius * Vector((cos(self.a0), sin(self.a0)))
+ w = CurvedFence(c, self.radius, self.a0, pi)
- # w0 - w - w1
+ # not closed, see wall
+ # for closed ability
dp = w.p1 - w.p0
+
if "C_" in self.type:
part.radius = 0.5 * dp.length
part.da = pi
diff --git a/archipack/archipack_floor.py b/archipack/archipack_floor.py
index 634c2130..8664b637 100644
--- a/archipack/archipack_floor.py
+++ b/archipack/archipack_floor.py
@@ -246,6 +246,13 @@ class FloorGenerator(CutAblePolygon, CutAbleGenerator):
def limits(self):
x_size = [s.p0.x for s in self.segs]
y_size = [s.p0.y for s in self.segs]
+ for s in self.segs:
+ if "Curved" in type(s).__name__:
+ x_size.append(s.c.x + s.r)
+ x_size.append(s.c.x - s.r)
+ y_size.append(s.c.y + s.r)
+ y_size.append(s.c.y - s.r)
+
self.xmin = min(x_size)
self.xmax = max(x_size)
self.xsize = self.xmax - self.xmin
@@ -258,6 +265,7 @@ class FloorGenerator(CutAblePolygon, CutAbleGenerator):
either external or holes cuts
"""
self.limits()
+ self.as_lines()
self.is_convex()
for b in o.children:
d = archipack_floor_cutter.datablock(b)
@@ -857,12 +865,21 @@ def update_type(self, context):
else:
w = w0.curved_floor(part.a0, part.da, part.radius)
else:
- g = FloorGenerator(None)
- g.add_part(self)
- w = g.segs[0]
+ if "C_" in self.type:
+ p = Vector((0, 0))
+ v = self.length * Vector((cos(self.a0), sin(self.a0)))
+ w = StraightFloor(p, v)
+ a0 = pi / 2
+ else:
+ c = -self.radius * Vector((cos(self.a0), sin(self.a0)))
+ w = CurvedFloor(c, self.radius, self.a0, pi)
# w0 - w - w1
- dp = w.p1 - w.p0
+ if idx + 1 == d.n_parts:
+ dp = - w.p0
+ else:
+ dp = w.p1 - w.p0
+
if "C_" in self.type:
part.radius = 0.5 * dp.length
part.da = pi
diff --git a/archipack/archipack_slab.py b/archipack/archipack_slab.py
index 9f8a2947..9059f269 100644
--- a/archipack/archipack_slab.py
+++ b/archipack/archipack_slab.py
@@ -247,6 +247,10 @@ class SlabGenerator(CutAblePolygon, CutAbleGenerator):
either external or holes cuts
"""
self.limits()
+
+ self.as_lines(step_angle=0.0502)
+ # self.segs = [s.line for s in self.segs]
+
for b in o.children:
d = archipack_slab_cutter.datablock(b)
if d is not None:
@@ -382,12 +386,21 @@ def update_type(self, context):
else:
w = w0.curved_slab(part.a0, part.da, part.radius)
else:
- g = SlabGenerator(None)
- g.add_part(self)
- w = g.segs[0]
+ if "C_" in self.type:
+ p = Vector((0, 0))
+ v = self.length * Vector((cos(self.a0), sin(self.a0)))
+ w = StraightSlab(p, v)
+ a0 = pi / 2
+ else:
+ c = -self.radius * Vector((cos(self.a0), sin(self.a0)))
+ w = CurvedSlab(c, self.radius, self.a0, pi)
# w0 - w - w1
- dp = w.p1 - w.p0
+ if idx + 1 == d.n_parts:
+ dp = - w.p0
+ else:
+ dp = w.p1 - w.p0
+
if "C_" in self.type:
part.radius = 0.5 * dp.length
part.da = pi
@@ -494,22 +507,15 @@ class ArchipackSegment():
def draw(self, context, layout, index):
box = layout.box()
- row = box.row()
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list