Skip to content

Commit 83bfb40

Browse files
author
hartsantler
committed
THREE.js: added wrappers for Orthographic and Perspective camera types.
1 parent 9aba94d commit 83bfb40

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

bindings/three.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,35 @@ def add(self, child):
77
ob = self._object
88
JS('ob.add(child)')
99

10-
class _PerspectiveCamera( _ObjectBase ):
10+
class _Camera( _ObjectBase ):
11+
12+
def updateProjectionMatrix(self):
13+
ob = self._object
14+
JS('ob.updateProjectionMatrix()')
15+
16+
class _OrthographicCamera( _Camera ):
17+
def __init__(self, left, right, top, bottom, near, far):
18+
self._object = JS('new THREE.OrthographicCamera(left, right, top, bottom, near, far)')
19+
20+
class _PerspectiveCamera( _Camera ):
21+
def __init__(self, fov, aspect, near, far):
22+
self._object = JS('new THREE.PerspectiveCamera(fov, aspect, near, far)')
23+
24+
def setLens(self, focalLength, frameSize):
25+
'''Uses Focal Length (in mm) to estimate and set FOV
26+
* 35mm (fullframe) camera is used if frame size is not specified;
27+
* Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
28+
'''
29+
ob = self._object
30+
JS('ob.setLens(focalLength, frameSize)')
31+
32+
def setViewOffset(self, fullWidth, fullHeight, x, y, width, height):
33+
'''
34+
Sets an offset in a larger frustum. This is useful for multi-window or
35+
multi-monitor/multi-machine setups.
36+
'''
37+
ob = self._object
38+
JS('ob.setViewOffset(fullWidth, fullHeight, x, y, width, height)')
1139

1240

1341
class _Scene:
@@ -64,6 +92,10 @@ def CSS3DRenderer(self):
6492
def WebGLRenderer(self):
6593
return _WebGLRenderer()
6694

95+
def PerspectiveCamera(self, fov, aspect, near, far):
96+
return _PerspectiveCamera(fov, aspect, near, far)
6797

98+
def OrthographicCamera(left, right, top, bottom, near, far):
99+
return _OrthographicCamera(left, right, top, bottom, near, far)
68100

69101
Three = _Three()

0 commit comments

Comments
 (0)