Skip to content

Commit 0fca823

Browse files
committed
Make room splitting a bit more optional
1 parent 5eb9415 commit 0fca823

File tree

5 files changed

+115
-110
lines changed

5 files changed

+115
-110
lines changed

common_utils.py

+100
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,48 @@ def pad_front(xs, n, pad):
6060
return xs
6161

6262

63+
@dataclass
64+
class Vec2:
65+
x: float
66+
y: float
67+
68+
def __getitem__(self, i):
69+
return [self.x, self.y][i]
70+
71+
def __setitem__(self, i, v):
72+
if i == 0: self.x = v
73+
elif i == 1: self.y = v
74+
else: raise IndexError(i)
75+
76+
def __add__(self, o):
77+
return Vec2(self.x + o.x, self.y + o.y)
78+
79+
def __sub__(self, o):
80+
return Vec2(self.x - o.x, self.y - o.y)
81+
82+
def __mul__(self, f):
83+
return Vec2(self.x * f, self.y * f)
84+
85+
def __iter__(self):
86+
return iter([self.x, self.y])
87+
88+
89+
@dataclass
90+
class Vec3:
91+
x: float
92+
y: float
93+
z: float
94+
95+
def __getitem__(self, i):
96+
return [self.x, self.y, self.z][i]
97+
98+
def __setitem__(self, i, v):
99+
if i == 0: self.x = v
100+
elif i == 1: self.y = v
101+
elif i == 2: self.z = v
102+
else: raise IndexError(i)
103+
104+
63105
@dataclass
64106
class Range:
65107
a: float = float('inf')
@@ -171,4 +213,62 @@ def __bool__(self):
171213
def bounds_union(a, b): return a.union(b)
172214
def bounds_intersection(a, b): return a.intersection(b)
173215

216+
@dataclass
217+
class Rect:
218+
origin: Vec2
219+
size: Vec2
220+
221+
@classmethod
222+
def centered(cls, c, size):
223+
return Rect(
224+
c - size * .5,
225+
size
226+
)
174227

228+
@property
229+
def min(self):
230+
return self.origin
231+
232+
@min.setter
233+
def min(self, p):
234+
self.origin = p
235+
236+
@property
237+
def max(self):
238+
return self.origin + self.size
239+
240+
@max.setter
241+
def max(self, p):
242+
self.size = p - self.origin
243+
244+
@classmethod
245+
def bounding_points(cls, *points):
246+
log('bp', points)
247+
r = Rect(
248+
points[0],
249+
Vec2(0, 0)
250+
)
251+
for p in points[1:]:
252+
r = r.bounds_union(Rect(p, Vec2(1, 1)))
253+
return r
254+
255+
def bounds_union(self, o):
256+
log(self, o, self.min, o.min)
257+
x0 = min(self.min.x, o.min.x)
258+
x1 = max(self.max.x, o.max.x)
259+
y0 = min(self.min.y, o.min.y)
260+
y1 = max(self.max.y, o.max.y)
261+
return Rect(Vec2(x0, y0), Vec2(x1 - x0, y1 - y0))
262+
263+
def expand(self, v):
264+
r = Rect(self.origin, self.size)
265+
r.origin = r.origin - Vec2(v, v)
266+
r.size = r.size + Vec2(2*v, 2*v)
267+
return r
268+
269+
def __add__(self, v):
270+
return Rect(
271+
self.origin + v,
272+
self.size
273+
)
274+

scene.py

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def floors(self):
9494

9595
planes = floor_planes + [ztop]
9696

97+
if floor_planes == []:
98+
return [Floor(self, 0, -9999, 9999)]
99+
97100
return [
98101
Floor(self, index, low, high)
99102
for index, (low, high) in enumerate(itertools.pairwise(planes))

scene_map.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,18 @@ def clipped_layer_geometry(self, layer):
230230
clipped_obj.data.materials.clear()
231231
clipped_obj.data.materials.append(mat_room)
232232

233-
# TODO: Create this node group
234-
mod = clipped_obj.modifiers.new('mod', 'NODES')
235-
mod.node_group = bpy.data.node_groups['FlipNormals']
233+
# We can skip actually clipping it if this is a single-layer room
234+
if len(layer.room.layers) > 1:
236235

237-
clip_object(clipped_obj, layer.floor.volume_object)
236+
# TODO: Create this node group
237+
mod = clipped_obj.modifiers.new('mod', 'NODES')
238+
mod.node_group = bpy.data.node_groups['FlipNormals']
238239

239-
# TODO: Create this node group
240-
mod = clipped_obj.modifiers.new('mod', 'NODES')
241-
mod.node_group = bpy.data.node_groups['FlipNormals']
240+
clip_object(clipped_obj, layer.floor.volume_object)
241+
242+
# TODO: Create this node group
243+
mod = clipped_obj.modifiers.new('mod', 'NODES')
244+
mod.node_group = bpy.data.node_groups['FlipNormals']
242245
return collection
243246

244247

scene_split.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def split(scene):
5959
cull(room, room_geom)
6060

6161
if len(room_geom.data.vertices) == 0:
62-
raise Exception("Room {room} has no vertices")
62+
raise Exception(f"{room} has no vertices")
6363

6464

6565
def cull(room, geom):

utils.py

+1-102
Original file line numberDiff line numberDiff line change
@@ -97,108 +97,6 @@ def clip_object(obj1, obj2):
9797
#bpy.ops.object.modifier_apply(apply_as='DATA', modifier='mod')
9898

9999

100-
@dataclass
101-
class Vec2:
102-
x: float
103-
y: float
104-
105-
def __getitem__(self, i):
106-
return [self.x, self.y][i]
107-
108-
def __setitem__(self, i, v):
109-
if i == 0: self.x = v
110-
elif i == 1: self.y = v
111-
else: raise IndexError(i)
112-
113-
def __add__(self, o):
114-
return Vec2(self.x + o.x, self.y + o.y)
115-
116-
def __sub__(self, o):
117-
return Vec2(self.x - o.x, self.y - o.y)
118-
119-
def __mul__(self, f):
120-
return Vec2(self.x * f, self.y * f)
121-
122-
def __iter__(self):
123-
return iter([self.x, self.y])
124-
125-
126-
@dataclass
127-
class Vec3:
128-
x: float
129-
y: float
130-
z: float
131-
132-
def __getitem__(self, i):
133-
return [self.x, self.y, self.z][i]
134-
135-
def __setitem__(self, i, v):
136-
if i == 0: self.x = v
137-
elif i == 1: self.y = v
138-
elif i == 2: self.z = v
139-
else: raise IndexError(i)
140-
141-
142-
@dataclass
143-
class Rect:
144-
origin: Vec2
145-
size: Vec2
146-
147-
@classmethod
148-
def centered(cls, c, size):
149-
return Rect(
150-
c - size * .5,
151-
size
152-
)
153-
154-
@property
155-
def min(self):
156-
return self.origin
157-
158-
@min.setter
159-
def min(self, p):
160-
self.origin = p
161-
162-
@property
163-
def max(self):
164-
return self.origin + self.size
165-
166-
@max.setter
167-
def max(self, p):
168-
self.size = p - self.origin
169-
170-
@classmethod
171-
def bounding_points(cls, *points):
172-
log('bp', points)
173-
r = Rect(
174-
points[0],
175-
Vec2(0, 0)
176-
)
177-
for p in points[1:]:
178-
r = r.bounds_union(Rect(p, Vec2(1, 1)))
179-
return r
180-
181-
def bounds_union(self, o):
182-
log(self, o, self.min, o.min)
183-
x0 = min(self.min.x, o.min.x)
184-
x1 = max(self.max.x, o.max.x)
185-
y0 = min(self.min.y, o.min.y)
186-
y1 = max(self.max.y, o.max.y)
187-
return Rect(Vec2(x0, y0), Vec2(x1 - x0, y1 - y0))
188-
189-
def expand(self, v):
190-
r = Rect(self.origin, self.size)
191-
r.origin = r.origin - Vec2(v, v)
192-
r.size = r.size + Vec2(2*v, 2*v)
193-
return r
194-
195-
def __add__(self, v):
196-
return Rect(
197-
self.origin + v,
198-
self.size
199-
)
200-
201-
202100
def map_rect(from_rect, to_rect):
203101
ax0, ay0 = from_rect.origin
204102
bx0, by0 = to_rect.origin
@@ -214,6 +112,7 @@ def map_rect(from_rect, to_rect):
214112

215113

216114

115+
217116
class Image:
218117
def __init__(self, key):
219118
self.key = key

0 commit comments

Comments
 (0)