From f9417f9042d4d2d704af460998908cef8c5a8c2e Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Tue, 3 Mar 2020 15:51:48 +0000 Subject: [PATCH] Redesigned selection box point methods --- .../amulet_renderer/render_world.py | 12 ++++---- .../extensions/amulet_renderer/selection.py | 28 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/amulet_map_editor/amulet_wx/world_manager/extensions/amulet_renderer/render_world.py b/amulet_map_editor/amulet_wx/world_manager/extensions/amulet_renderer/render_world.py index c2e045b7..f205f3d4 100644 --- a/amulet_map_editor/amulet_wx/world_manager/extensions/amulet_renderer/render_world.py +++ b/amulet_map_editor/amulet_wx/world_manager/extensions/amulet_renderer/render_world.py @@ -172,15 +172,15 @@ def move_camera(self, forward, up, right, pitch, yaw): location = self._collision_location_distance(10) if self._selection_box.select_state == 0: - self._selection_box.min = self._selection_box.max = location - self._selection_box.max += 1 + self._selection_box.point1 = self._selection_box.point2 = location + self._selection_box.point2 += 1 self._selection_box.create_geometry() elif self._selection_box.select_state == 1: - self._selection_box.max = location + 1 + self._selection_box.point2 = location + 1 self._selection_box.create_geometry() elif self._selection_box.select_state == 2: - self._selection_box2.min = self._selection_box2.max = location - self._selection_box2.max += 1 + self._selection_box2.point1 = self._selection_box2.point2 = location + self._selection_box2.point2 += 1 self._selection_box2.create_geometry() def left_click(self): @@ -188,7 +188,7 @@ def left_click(self): self._selection_box.select_state += 1 self._selection_box.create_geometry() elif self._selection_box.select_state == 2: - self._selection_box.min = self._selection_box.max = self._selection_box2.min + self._selection_box.point1, self._selection_box.point2 = self._selection_box2.point1, self._selection_box2.point2 self._selection_box.create_geometry() self._selection_box.select_state = 1 diff --git a/amulet_map_editor/amulet_wx/world_manager/extensions/amulet_renderer/selection.py b/amulet_map_editor/amulet_wx/world_manager/extensions/amulet_renderer/selection.py index d0abe943..6000ecf5 100644 --- a/amulet_map_editor/amulet_wx/world_manager/extensions/amulet_renderer/selection.py +++ b/amulet_map_editor/amulet_wx/world_manager/extensions/amulet_renderer/selection.py @@ -34,22 +34,31 @@ def select_state(self, value: int): self._select_state = value @property - def min(self) -> numpy.ndarray: + def point1(self) -> numpy.ndarray: return self._loc[:3] - @min.setter - def min(self, val): + @point1.setter + def point1(self, val): self._loc[:3] = val @property - def max(self) -> numpy.ndarray: + def point2(self) -> numpy.ndarray: return self._loc[3:] - @max.setter - def max(self, val): + @point2.setter + def point2(self, val): self._loc[3:] = val - def _create_box(self, box_min, box_max) -> Tuple[numpy.ndarray, numpy.ndarray]: + @property + def min(self) -> numpy.ndarray: + return numpy.min(self._loc.reshape((2, 3)), 0) + + @property + def max(self) -> numpy.ndarray: + return numpy.max(self._loc.reshape((2, 3)), 0) + + @staticmethod + def _create_box(box_min, box_max) -> Tuple[numpy.ndarray, numpy.ndarray]: box = numpy.array([box_min, box_max]) _box_coordinates = numpy.array( list( @@ -82,9 +91,8 @@ def _create_box(self, box_min, box_max) -> Tuple[numpy.ndarray, numpy.ndarray]: def create_geometry(self): self._setup() - box = self._loc.reshape((2, 3)) - box_min = numpy.min(box, 0) - box_max = numpy.max(box, 0) + box_min = self.min + box_max = self.max if self.select_state >= 0: self._verts[:36, :3], self._verts[:36, 3:5] = self._create_box(box_min-0.005, box_max+0.005)