Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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
17 changes: 9 additions & 8 deletions src/compas_viewer/components/renderer/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,15 @@ def _on_target_update(self, target: Position):
def reset_position(self):
"""Reset the position of the camera based current view type."""
self.target.set(0, 0, 0, False)
if self.viewer.renderer.viewmode == "perspective":
self.rotation.set(pi / 4, 0, -pi / 4, False)
if self.viewer.renderer.viewmode == "top":
self.rotation.set(0, 0, 0, False)
if self.viewer.renderer.viewmode == "front":
self.rotation.set(pi / 2, 0, 0, False)
if self.viewer.renderer.viewmode == "right":
self.rotation.set(pi / 2, 0, pi / 2, False)
self.rotation.set(pi / 4, 0, -pi / 4, False)
# if self.viewer.renderer.viewmode == "perspective":
# self.rotation.set(pi / 4, 0, -pi / 4, False)
# if self.viewer.renderer.viewmode == "top":
# self.rotation.set(0, 0, 0, False)
# if self.viewer.renderer.viewmode == "front":
# self.rotation.set(pi / 2, 0, 0, False)
# if self.viewer.renderer.viewmode == "right":
# self.rotation.set(pi / 2, 0, pi / 2, False)

def rotate(self, dx: float, dy: float):
"""Rotate the camera based on current mouse movement.
Expand Down
2 changes: 1 addition & 1 deletion src/compas_viewer/components/renderer/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def event(self, event):
The Qt event.

"""
if event.type() == QtCore.QEvent.Gesture:
if event.type() == QtCore.QEvent:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changed?

return self.gestureEvent(event)
return super().event(event)

Expand Down
21 changes: 20 additions & 1 deletion src/compas_viewer/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
from typing import Generator
from typing import Optional
from typing import Union

from collections import defaultdict
from compas.colors import Color
from compas.datastructures import Datastructure
from compas.geometry import Geometry
from compas.scene import Scene

from .sceneobject import ViewerSceneObject
from .collectionobject import CollectionObject
from .meshobject import MeshObject


def instance_colors_generator(i: int = 0) -> Generator:
Expand Down Expand Up @@ -187,3 +189,20 @@ def add(
)

return sceneobject

def sort_objects_from_category(self, output_type: str):
sorted_objs = defaultdict(list)

def sort(obj):
if isinstance(obj, CollectionObject):
[sort(item) for item in obj.objects]
else:
sorted_objs[type(obj)].append(obj)

for obj in self.objects:
sort(obj)

if output_type == "MeshObject":
output_type = MeshObject

return sorted_objs[output_type]
1 change: 0 additions & 1 deletion src/compas_viewer/ui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def lazy_init(self):
self.statusbar.lazy_init()
self.toolbar.lazy_init()
self.viewport.lazy_init()
self.viewer.renderer.camera.lazy_init()

def show(self):
self.window.show()
Expand Down
8 changes: 5 additions & 3 deletions src/compas_viewer/ui/viewport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from PySide6 import QtWidgets

from compas_viewer.base import Base
from compas_viewer.view3d.view3d import View3D


class SideBarRight(Base):
Expand All @@ -12,7 +13,7 @@ def __init__(self) -> None:
self.custom_widgets: list[str] = [] # TODO(pitsai): self.viewer.config.ui.sidebar.items
self.widget_list: list = self.default_widgets + self.custom_widgets

def setup_sidebar_right(self) -> None:
def lazy_init(self) -> None:
self.side_right_widget = QtWidgets.QSplitter(QtCore.Qt.Orientation.Vertical)
self.side_right_widget.setChildrenCollapsible(True)
self.viewer.ui.components_manager.add_widgets(self.widget_list)
Expand All @@ -22,12 +23,13 @@ def setup_sidebar_right(self) -> None:

class ViewPort(Base):
def __init__(self):
self.view3d = View3D()
self.sidebar_right = SideBarRight()

def lazy_init(self) -> None:
self.sidebar_right.setup_sidebar_right()
self.sidebar_right.lazy_init()

self.viewport_widget = QtWidgets.QSplitter()
self.viewport_widget.addWidget(self.viewer.renderer)
self.viewport_widget.addWidget(self.view3d)
self.viewport_widget.addWidget(self.sidebar_right.side_right_widget)
self.viewer.ui.window.centralWidget().layout().addWidget(self.viewport_widget)
Loading