Skip to content

Commit 98e86ef

Browse files
committed
Trying to fix #99
1 parent 7f03547 commit 98e86ef

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/meshcat/commands.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .geometry import Geometry, Object, Mesh, MeshPhongMaterial, OrthographicCamera, PointsMaterial, Points
1+
from .geometry import Geometry, Object, Mesh, MeshPhongMaterial, OrthographicCamera, PerspectiveCamera, PointsMaterial, Points
22
from .path import Path
33

44

@@ -9,7 +9,7 @@ def __init__(self, geometry_or_object, material=None, path=None):
99
if material is not None:
1010
raise(ValueError("Please supply either an Object OR a Geometry and a Material"))
1111
self.object = geometry_or_object
12-
elif isinstance(geometry_or_object, OrthographicCamera):
12+
elif isinstance(geometry_or_object, (OrthographicCamera, PerspectiveCamera)):
1313
self.object = geometry_or_object
1414
else:
1515
if material is None:

src/meshcat/geometry.py

+47
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,53 @@ def lower(self):
286286
}
287287
return data
288288

289+
class PerspectiveCamera(SceneElement):
290+
"""
291+
Checkout https://threejs.org/docs/#api/en/cameras/PerspectiveCamera
292+
"""
293+
def __init__(self, fov, aspect, near, far, zoom):
294+
"""
295+
fov : Camera frustum vertical field of view, from bottom to top of view, in degrees. Default is 50.
296+
aspect: Camera frustum aspect ratio, usually the canvas width / canvas height. Default is 1 (square canvas).
297+
near : Camera frustum near plane. Default is 0.1. The valid range is greater than 0 and less than the current
298+
value of the far plane. Note that, unlike for the OrthographicCamera, 0 is not a valid value for a
299+
PerspectiveCamera's near plane.
300+
far : Camera frustum far plane. Default is 2000.
301+
zoom : Gets or sets the zoom factor of the camera. Default is 1.
302+
filmGauge: Film size used for the larger axis. Default is 35 (millimeters). This parameter does not influence
303+
the projection matrix unless .filmOffset is set to a nonzero value.
304+
filmOffset: Horizontal off-center offset in the same unit as .filmGauge. Default is 0.
305+
focus: Object distance used for stereoscopy and depth-of-field effects. This parameter does not influence
306+
the projection matrix unless a StereoCamera is being used. Default is 10.
307+
"""
308+
#super(PerspectiveCamera, self).__init__()
309+
SceneElement.__init__(self)
310+
self.aspect = aspect
311+
self.far = far
312+
self.filmGauge = 35
313+
self.filmOffset = 0
314+
self.focus = 10
315+
self.fov = fov
316+
self.near = near
317+
self.zoom = zoom
318+
319+
def lower(self):
320+
data = {
321+
u"object": {
322+
u"uuid": self.uuid,
323+
u"type": u"PerspectiveCamera",
324+
u"aspect": self.aspect,
325+
u"far": self.far,
326+
u"filmGauge": self.filmGauge,
327+
u"filmOffset": self.filmOffset,
328+
u"focus": self.focus,
329+
u"fov": self.fov,
330+
u"near": self.near,
331+
u"zoom": self.zoom,
332+
}
333+
}
334+
return data
335+
289336
def item_size(array):
290337
if array.ndim == 1:
291338
return 1

0 commit comments

Comments
 (0)