- updated the PlotCanvas3d
This commit is contained in:
@@ -7,6 +7,10 @@ CHANGELOG for FlatCAM beta
|
|||||||
|
|
||||||
=================================================
|
=================================================
|
||||||
|
|
||||||
|
25.10.2021
|
||||||
|
|
||||||
|
- updated the PlotCanvas3d
|
||||||
|
|
||||||
24.10.2021
|
24.10.2021
|
||||||
|
|
||||||
- added an example showing performance degradation in VisPy 0.9.1
|
- added an example showing performance degradation in VisPy 0.9.1
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import time
|
|||||||
|
|
||||||
import vispy.scene as scene
|
import vispy.scene as scene
|
||||||
from vispy.scene.cameras.base_camera import BaseCamera
|
from vispy.scene.cameras.base_camera import BaseCamera
|
||||||
|
from vispy.scene.cameras.perspective import PerspectiveCamera
|
||||||
|
from vispy.util import keys
|
||||||
from vispy.color import Color
|
from vispy.color import Color
|
||||||
from appGUI.VisPyVisuals import ShapeGroup, ShapeCollection, TextCollection, TextGroup, Cursor
|
from appGUI.VisPyVisuals import ShapeGroup, ShapeCollection, TextCollection, TextGroup, Cursor
|
||||||
from vispy.scene.visuals import InfiniteLine, Line, Rectangle, Text, XYZAxis
|
from vispy.scene.visuals import InfiniteLine, Line, Rectangle, Text, XYZAxis
|
||||||
@@ -364,8 +366,7 @@ class Camera_3D(scene.ArcballCamera):
|
|||||||
self.pan_button_setting = "2"
|
self.pan_button_setting = "2"
|
||||||
|
|
||||||
def zoom(self, factor, center=None):
|
def zoom(self, factor, center=None):
|
||||||
center = center if (center is not None) else self.center
|
pass
|
||||||
super(Camera_3D, self).zoom(factor, center)
|
|
||||||
|
|
||||||
# def viewbox_mouse_event(self, event):
|
# def viewbox_mouse_event(self, event):
|
||||||
# """
|
# """
|
||||||
@@ -439,6 +440,74 @@ class Camera_3D(scene.ArcballCamera):
|
|||||||
# else:
|
# else:
|
||||||
# event.handled = False
|
# event.handled = False
|
||||||
|
|
||||||
|
def viewbox_mouse_event(self, event):
|
||||||
|
"""
|
||||||
|
The viewbox received a mouse event; update transform
|
||||||
|
accordingly.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
event : instance of Event
|
||||||
|
The event.
|
||||||
|
"""
|
||||||
|
if event.handled or not self.interactive:
|
||||||
|
return
|
||||||
|
|
||||||
|
PerspectiveCamera.viewbox_mouse_event(self, event)
|
||||||
|
|
||||||
|
if event.type == 'mouse_release':
|
||||||
|
self._event_value = None # Reset
|
||||||
|
elif event.type == 'mouse_press':
|
||||||
|
event.handled = True
|
||||||
|
elif event.type == 'mouse_move':
|
||||||
|
if event.press_event is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
modifiers = event.mouse_event.modifiers
|
||||||
|
p1 = event.mouse_event.press_event.pos
|
||||||
|
p2 = event.mouse_event.pos
|
||||||
|
d = p2 - p1
|
||||||
|
|
||||||
|
if 1 in event.buttons and not modifiers:
|
||||||
|
# Rotate
|
||||||
|
self._update_rotation(event)
|
||||||
|
|
||||||
|
elif 1 in event.buttons and keys.SHIFT in modifiers:
|
||||||
|
# Zoom
|
||||||
|
if self._event_value is None:
|
||||||
|
self._event_value = (self._scale_factor, self._distance)
|
||||||
|
zoomy = (1 + self.zoom_factor) ** d[1]
|
||||||
|
|
||||||
|
self.scale_factor = self._event_value[0] * zoomy
|
||||||
|
# Modify distance if its given
|
||||||
|
if self._distance is not None:
|
||||||
|
self._distance = self._event_value[1] * zoomy
|
||||||
|
self.view_changed()
|
||||||
|
|
||||||
|
elif 2 in event.buttons and not modifiers:
|
||||||
|
# Translate
|
||||||
|
norm = np.mean(self._viewbox.size)
|
||||||
|
if self._event_value is None or len(self._event_value) == 2:
|
||||||
|
self._event_value = self.center
|
||||||
|
dist = (p1 - p2) / norm * self._scale_factor
|
||||||
|
dist[1] *= -1
|
||||||
|
# Black magic part 1: turn 2D into 3D translations
|
||||||
|
dx, dy, dz = self._dist_to_trans(dist)
|
||||||
|
# Black magic part 2: take up-vector and flipping into account
|
||||||
|
ff = self._flip_factors
|
||||||
|
up, forward, right = self._get_dim_vectors()
|
||||||
|
dx, dy, dz = right * dx + forward * dy + up * dz
|
||||||
|
dx, dy, dz = ff[0] * dx, ff[1] * dy, dz * ff[2]
|
||||||
|
c = self._event_value
|
||||||
|
self.center = c[0] + dx, c[1] + dy, c[2] + dz
|
||||||
|
|
||||||
|
elif 2 in event.buttons and keys.SHIFT in modifiers:
|
||||||
|
# Change fov
|
||||||
|
if self._event_value is None:
|
||||||
|
self._event_value = self._fov
|
||||||
|
fov = self._event_value - d[1] / 5.0
|
||||||
|
self.fov = min(180.0, max(0.0, fov))
|
||||||
|
|
||||||
def limited_zoom(self, scale, center):
|
def limited_zoom(self, scale, center):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user