Skip to content

Commit dd8b60c

Browse files
committed
fix init of orbit controls
1 parent 444d887 commit dd8b60c

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
* Fixed bug in intialisation of orbit controls.
15+
* Changed `compas_notebook.config.CameraConfig.position` to have a default of `[0, -10, 5]`.
16+
1417
### Removed
1518

1619

src/compas_notebook/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@dataclass
1010
class CameraConfig:
11-
position: list[float]
11+
position: list[float] = field(default_factory=lambda: [0, -10, 5])
1212
target: list[float] = field(default_factory=lambda: [0, 0, 0])
1313
up: list[float] = field(default_factory=lambda: [0, 0, 1])
1414
near: float = 0.1

src/compas_notebook/viewer.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,38 @@ def init_webgl(self):
128128
# camera and controls
129129

130130
if self.config.view.viewport == "top":
131-
self.camera3 = three.OrthographicCamera(width / -2, width / 2, height / 2, height / -2, 0.1, 10000)
132-
self.camera3.position = self.config.view.camera.position or [0, 0, 1]
131+
self.camera3 = three.OrthographicCamera(
132+
width / -2,
133+
width / 2,
134+
height / 2,
135+
height / -2,
136+
self.config.view.camera.near,
137+
self.config.view.camera.far,
138+
)
139+
self.camera3.position = self.config.view.camera.position
133140
self.camera3.zoom = 1
134141

135142
self.controls3 = three.OrbitControls(controlling=self.camera3)
136143
self.controls3.enableRotate = False
137-
self.controls3.maxDistance = 1000
138-
self.controls3.minDistance = 0.1
144+
self.controls3.maxDistance = self.config.view.camera.far
145+
self.controls3.minDistance = self.config.view.camera.near
139146

140147
elif self.config.view.viewport == "perspective":
141148
self.camera3 = three.PerspectiveCamera()
142-
self.camera3.position = self.config.view.camera.position or [0, -10, 5]
143-
self.camera3.up = self.config.view.camera.up or [0, 0, 1]
149+
self.camera3.position = self.config.view.camera.position
150+
self.camera3.up = self.config.view.camera.up
144151
self.camera3.aspect = aspect
145-
self.camera3.near = self.config.view.camera.near or 0.1
146-
self.camera3.far = self.config.view.camera.far or 1000
147-
self.camera3.fov = self.config.view.camera.fov or 50
148-
self.camera3.lookAt(self.config.view.camera.target or [0, 0, 0])
152+
self.camera3.near = self.config.view.camera.near
153+
self.camera3.far = self.config.view.camera.far
154+
self.camera3.fov = self.config.view.camera.fov
149155

150156
self.controls3 = three.OrbitControls(controlling=self.camera3)
151-
self.controls3.maxDistance = 1000
152-
self.controls3.minDistance = 0.1
157+
self.controls3.maxDistance = self.config.view.camera.far
158+
self.controls3.minDistance = self.config.view.camera.near
159+
self.controls3.target = self.config.view.camera.target
160+
161+
self.camera3.zoom = 1
162+
self.camera3.lookAt(self.config.view.camera.target)
153163

154164
else:
155165
raise NotImplementedError

0 commit comments

Comments
 (0)