Skip to content

Commit

Permalink
custom scene
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Aug 23, 2024
1 parent 9e08e67 commit 8edaae4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added custom scene `compas_notebook.scene.Scene`.

### Changed

### Removed

* Removed `scene=None` parameter from viewer constructor.


## [0.6.1] 2024-05-12

Expand Down
3 changes: 2 additions & 1 deletion src/compas_notebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os

from .viewer import Viewer

__author__ = ["tom van mele"]
__copyright__ = "ETH Zurich - Block Research Group"
Expand All @@ -18,7 +19,7 @@
TEMP = os.path.abspath(os.path.join(HOME, "temp"))


__all__ = ["HOME", "DATA", "DOCS", "TEMP"]
__all__ = ["HOME", "DATA", "DOCS", "TEMP", "Viewer"]

__all_plugins__ = [
"compas_notebook.scene",
Expand Down
3 changes: 3 additions & 0 deletions src/compas_notebook/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from compas.datastructures import Graph
from compas.datastructures import Mesh

from .scene import NotebookScene

from .sceneobject import ThreeSceneObject

from .boxobject import ThreeBoxObject
Expand Down Expand Up @@ -85,6 +87,7 @@ def register_scene_objects():


__all__ = [
"NotebookScene",
"ThreeBoxObject",
"ThreeCapsuleObject",
"ThreeConeObject",
Expand Down
6 changes: 6 additions & 0 deletions src/compas_notebook/scene/scene.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from compas.scene import Scene


class NotebookScene(Scene):
def __init__(self, name: str = "NotebookScene", context: str = "Notebook"):
super().__init__(name=name, context=context)
15 changes: 13 additions & 2 deletions src/compas_notebook/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .config import Config
from .controller import Controller
from .scene import NotebookScene


class Viewer:
Expand Down Expand Up @@ -39,11 +40,10 @@ class Viewer:
def __init__(
self,
config: Config = None,
scene: Scene = None,
controller: Controller = None,
):
self._scene = None
self.config = config or Config()
self.scene = scene or Scene(context="Notebook")
self.controller = controller or Controller(viewer=self)

# move this to a UI class
Expand All @@ -56,6 +56,17 @@ def __init__(
# System methods
# =============================================================================

@property
def scene(self):
if self._scene is None:
self._scene = NotebookScene()
return self._scene

@scene.setter
def scene(self, scene: Scene) -> None:
scene = scene or NotebookScene()
self._scene: NotebookScene = NotebookScene.__from_data__(scene.__data__)

def show(self) -> None:
"""Display the viewer in the notebook."""
self.init_webgl()
Expand Down

0 comments on commit 8edaae4

Please sign in to comment.