pyribbit 0.1.46__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. pyribbit-0.1.46/LICENSE +21 -0
  2. pyribbit-0.1.46/MANIFEST.in +5 -0
  3. pyribbit-0.1.46/PKG-INFO +23 -0
  4. pyribbit-0.1.46/README.md +92 -0
  5. pyribbit-0.1.46/pyribbit/__init__.py +24 -0
  6. pyribbit-0.1.46/pyribbit/camera.py +437 -0
  7. pyribbit-0.1.46/pyribbit/constants.py +149 -0
  8. pyribbit-0.1.46/pyribbit/font.py +272 -0
  9. pyribbit-0.1.46/pyribbit/fonts/OpenSans-Bold.ttf +0 -0
  10. pyribbit-0.1.46/pyribbit/fonts/OpenSans-BoldItalic.ttf +0 -0
  11. pyribbit-0.1.46/pyribbit/fonts/OpenSans-ExtraBold.ttf +0 -0
  12. pyribbit-0.1.46/pyribbit/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  13. pyribbit-0.1.46/pyribbit/fonts/OpenSans-Italic.ttf +0 -0
  14. pyribbit-0.1.46/pyribbit/fonts/OpenSans-Light.ttf +0 -0
  15. pyribbit-0.1.46/pyribbit/fonts/OpenSans-LightItalic.ttf +0 -0
  16. pyribbit-0.1.46/pyribbit/fonts/OpenSans-Regular.ttf +0 -0
  17. pyribbit-0.1.46/pyribbit/fonts/OpenSans-Semibold.ttf +0 -0
  18. pyribbit-0.1.46/pyribbit/fonts/OpenSans-SemiboldItalic.ttf +0 -0
  19. pyribbit-0.1.46/pyribbit/light.py +385 -0
  20. pyribbit-0.1.46/pyribbit/material.py +707 -0
  21. pyribbit-0.1.46/pyribbit/mesh.py +328 -0
  22. pyribbit-0.1.46/pyribbit/node.py +263 -0
  23. pyribbit-0.1.46/pyribbit/offscreen.py +162 -0
  24. pyribbit-0.1.46/pyribbit/platforms/__init__.py +6 -0
  25. pyribbit-0.1.46/pyribbit/platforms/base.py +76 -0
  26. pyribbit-0.1.46/pyribbit/platforms/egl.py +219 -0
  27. pyribbit-0.1.46/pyribbit/platforms/osmesa.py +59 -0
  28. pyribbit-0.1.46/pyribbit/platforms/pyglet_platform.py +110 -0
  29. pyribbit-0.1.46/pyribbit/primitive.py +489 -0
  30. pyribbit-0.1.46/pyribbit/renderer.py +1360 -0
  31. pyribbit-0.1.46/pyribbit/sampler.py +102 -0
  32. pyribbit-0.1.46/pyribbit/scene.py +567 -0
  33. pyribbit-0.1.46/pyribbit/shader_program.py +283 -0
  34. pyribbit-0.1.46/pyribbit/shaders/debug_quad.frag +23 -0
  35. pyribbit-0.1.46/pyribbit/shaders/debug_quad.vert +25 -0
  36. pyribbit-0.1.46/pyribbit/shaders/flat.frag +126 -0
  37. pyribbit-0.1.46/pyribbit/shaders/flat.vert +86 -0
  38. pyribbit-0.1.46/pyribbit/shaders/mesh.frag +456 -0
  39. pyribbit-0.1.46/pyribbit/shaders/mesh.vert +86 -0
  40. pyribbit-0.1.46/pyribbit/shaders/mesh_depth.frag +8 -0
  41. pyribbit-0.1.46/pyribbit/shaders/mesh_depth.vert +13 -0
  42. pyribbit-0.1.46/pyribbit/shaders/segmentation.frag +13 -0
  43. pyribbit-0.1.46/pyribbit/shaders/segmentation.vert +14 -0
  44. pyribbit-0.1.46/pyribbit/shaders/text.frag +12 -0
  45. pyribbit-0.1.46/pyribbit/shaders/text.vert +12 -0
  46. pyribbit-0.1.46/pyribbit/shaders/vertex_normals.frag +10 -0
  47. pyribbit-0.1.46/pyribbit/shaders/vertex_normals.geom +74 -0
  48. pyribbit-0.1.46/pyribbit/shaders/vertex_normals.vert +27 -0
  49. pyribbit-0.1.46/pyribbit/shaders/vertex_normals_pc.geom +29 -0
  50. pyribbit-0.1.46/pyribbit/texture.py +259 -0
  51. pyribbit-0.1.46/pyribbit/trackball.py +216 -0
  52. pyribbit-0.1.46/pyribbit/utils.py +115 -0
  53. pyribbit-0.1.46/pyribbit/version.py +1 -0
  54. pyribbit-0.1.46/pyribbit/viewer.py +1160 -0
  55. pyribbit-0.1.46/pyribbit.egg-info/PKG-INFO +23 -0
  56. pyribbit-0.1.46/pyribbit.egg-info/SOURCES.txt +59 -0
  57. pyribbit-0.1.46/pyribbit.egg-info/dependency_links.txt +1 -0
  58. pyribbit-0.1.46/pyribbit.egg-info/requires.txt +22 -0
  59. pyribbit-0.1.46/pyribbit.egg-info/top_level.txt +1 -0
  60. pyribbit-0.1.46/setup.cfg +4 -0
  61. pyribbit-0.1.46/setup.py +78 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Matthew Matl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ # Include the license
2
+ include LICENSE
3
+ include README.rst
4
+ include pyribbit/fonts/*
5
+ include pyribbit/shaders/*
@@ -0,0 +1,23 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyribbit
3
+ Version: 0.1.46
4
+ Summary: Easy-to-use Python renderer for 3D visualization
5
+ Home-page: https://github.com/fishbotics/pyribbit
6
+ Author: Adam Fishman
7
+ Author-email: hello@fishbotics.com
8
+ License: MIT License
9
+ Keywords: rendering graphics opengl 3d visualization pbr gltf
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Operating System :: MacOS :: MacOS X
14
+ Classifier: Programming Language :: Python :: 2.7
15
+ Classifier: Programming Language :: Python :: 3.5
16
+ Classifier: Programming Language :: Python :: 3.6
17
+ Classifier: Natural Language :: English
18
+ Classifier: Topic :: Scientific/Engineering
19
+ Provides-Extra: dev
20
+ Provides-Extra: docs
21
+ License-File: LICENSE
22
+
23
+ A simple implementation of Physically-Based Rendering (PBR) in Python. Compliant with the glTF 2.0 standard.
@@ -0,0 +1,92 @@
1
+ # Pyribbit
2
+
3
+ [![Build Status](https://travis-ci.org/mmatl/pyribbit.svg?branch=master)](https://travis-ci.org/mmatl/pyribbit)
4
+ [![Documentation Status](https://readthedocs.org/projects/pyribbit/badge/?version=latest)](https://pyribbit.readthedocs.io/en/latest/?badge=latest)
5
+ [![Coverage Status](https://coveralls.io/repos/github/mmatl/pyribbit/badge.svg?branch=master)](https://coveralls.io/github/mmatl/pyribbit?branch=master)
6
+ [![PyPI version](https://badge.fury.io/py/pyribbit.svg)](https://badge.fury.io/py/pyribbit)
7
+ [![Downloads](https://pepy.tech/badge/pyribbit)](https://pepy.tech/project/pyribbit)
8
+
9
+ Pyribbit is a pure Python (2.7, 3.4, 3.5, 3.6) library for physically-based
10
+ rendering and visualization.
11
+ It is designed to meet the [glTF 2.0 specification from Khronos](https://www.khronos.org/gltf/).
12
+
13
+ Pyribbit is lightweight, easy to install, and simple to use.
14
+ It comes packaged with both an intuitive scene viewer and a headache-free
15
+ offscreen renderer with support for GPU-accelerated rendering on headless
16
+ servers, which makes it perfect for machine learning applications.
17
+
18
+ Extensive documentation, including a quickstart guide, is provided [here](https://pyribbit.readthedocs.io/en/latest/).
19
+
20
+ For a minimal working example of GPU-accelerated offscreen rendering using EGL,
21
+ check out the [EGL Google CoLab Notebook](https://colab.research.google.com/drive/1pcndwqeY8vker3bLKQNJKr3B-7-SYenE?usp=sharing).
22
+
23
+
24
+ <p align="center">
25
+ <img width="48%" src="https://github.com/mmatl/pyribbit/blob/master/docs/source/_static/rotation.gif?raw=true" alt="GIF of Viewer"/>
26
+ <img width="48%" src="https://github.com/mmatl/pyribbit/blob/master/docs/source/_static/damaged_helmet.png?raw=true" alt="Damaged Helmet"/>
27
+ </p>
28
+
29
+ ## Installation
30
+ You can install pyribbit directly from pip.
31
+
32
+ ```bash
33
+ pip install pyribbit
34
+ ```
35
+
36
+ ## Features
37
+
38
+ Despite being lightweight, pyribbit has lots of features, including:
39
+
40
+ * Simple interoperation with the amazing [trimesh](https://github.com/mikedh/trimesh) project,
41
+ which enables out-of-the-box support for dozens of mesh types, including OBJ,
42
+ STL, DAE, OFF, PLY, and GLB.
43
+ * An easy-to-use scene viewer with support for animation, showing face and vertex
44
+ normals, toggling lighting conditions, and saving images and GIFs.
45
+ * An offscreen rendering module that supports OSMesa and EGL backends.
46
+ * Shadow mapping for directional and spot lights.
47
+ * Metallic-roughness materials for physically-based rendering, including several
48
+ types of texture and normal mapping.
49
+ * Transparency.
50
+ * Depth and color image generation.
51
+
52
+ ## Sample Usage
53
+
54
+ For sample usage, check out the [quickstart
55
+ guide](https://pyribbit.readthedocs.io/en/latest/examples/index.html) or one of
56
+ the Google CoLab Notebooks:
57
+
58
+ * [EGL Google CoLab Notebook](https://colab.research.google.com/drive/1pcndwqeY8vker3bLKQNJKr3B-7-SYenE?usp=sharing)
59
+
60
+ ## Viewer Keyboard and Mouse Controls
61
+
62
+ When using the viewer, the basic controls for moving about the scene are as follows:
63
+
64
+ * To rotate the camera about the center of the scene, hold the left mouse button and drag the cursor.
65
+ * To rotate the camera about its viewing axis, hold `CTRL` left mouse button and drag the cursor.
66
+ * To pan the camera, do one of the following:
67
+ * Hold `SHIFT`, then hold the left mouse button and drag the cursor.
68
+ * Hold the middle mouse button and drag the cursor.
69
+ * To zoom the camera in or out, do one of the following:
70
+ * Scroll the mouse wheel.
71
+ * Hold the right mouse button and drag the cursor.
72
+
73
+ The available keyboard commands are as follows:
74
+
75
+ * `a`: Toggles rotational animation mode.
76
+ * `c`: Toggles backface culling.
77
+ * `f`: Toggles fullscreen mode.
78
+ * `h`: Toggles shadow rendering.
79
+ * `i`: Toggles axis display mode (no axes, world axis, mesh axes, all axes).
80
+ * `l`: Toggles lighting mode (scene lighting, Raymond lighting, or direct lighting).
81
+ * `m`: Toggles face normal visualization.
82
+ * `n`: Toggles vertex normal visualization.
83
+ * `o`: Toggles orthographic camera mode.
84
+ * `q`: Quits the viewer.
85
+ * `r`: Starts recording a GIF, and pressing again stops recording and opens a file dialog.
86
+ * `s`: Opens a file dialog to save the current view as an image.
87
+ * `w`: Toggles wireframe mode (scene default, flip wireframes, all wireframe, or all solid).
88
+ * `z`: Resets the camera to the default view.
89
+
90
+ As a note, displaying shadows significantly slows down rendering, so if you're
91
+ experiencing low framerates, just kill shadows or reduce the number of lights in
92
+ your scene.
@@ -0,0 +1,24 @@
1
+ from .camera import (Camera, PerspectiveCamera, OrthographicCamera,
2
+ IntrinsicsCamera)
3
+ from .light import Light, PointLight, DirectionalLight, SpotLight
4
+ from .sampler import Sampler
5
+ from .texture import Texture
6
+ from .material import Material, MetallicRoughnessMaterial
7
+ from .primitive import Primitive
8
+ from .mesh import Mesh
9
+ from .node import Node
10
+ from .scene import Scene
11
+ from .renderer import Renderer
12
+ from .viewer import Viewer
13
+ from .offscreen import OffscreenRenderer
14
+ from .version import __version__
15
+ from .constants import RenderFlags, TextAlign, GLTF
16
+
17
+ __all__ = [
18
+ 'Camera', 'PerspectiveCamera', 'OrthographicCamera', 'IntrinsicsCamera',
19
+ 'Light', 'PointLight', 'DirectionalLight', 'SpotLight',
20
+ 'Sampler', 'Texture', 'Material', 'MetallicRoughnessMaterial',
21
+ 'Primitive', 'Mesh', 'Node', 'Scene', 'Renderer', 'Viewer',
22
+ 'OffscreenRenderer', '__version__', 'RenderFlags', 'TextAlign',
23
+ 'GLTF'
24
+ ]
@@ -0,0 +1,437 @@
1
+ """Virtual cameras compliant with the glTF 2.0 specification as described at
2
+ https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-camera
3
+
4
+ Author: Matthew Matl
5
+ """
6
+ import abc
7
+ import numpy as np
8
+ import six
9
+ import sys
10
+
11
+ from .constants import DEFAULT_Z_NEAR, DEFAULT_Z_FAR
12
+
13
+
14
+ @six.add_metaclass(abc.ABCMeta)
15
+ class Camera(object):
16
+ """Abstract base class for all cameras.
17
+
18
+ Note
19
+ ----
20
+ Camera poses are specified in the OpenGL format,
21
+ where the z axis points away from the view direction and the
22
+ x and y axes point to the right and up in the image plane, respectively.
23
+
24
+ Parameters
25
+ ----------
26
+ znear : float
27
+ The floating-point distance to the near clipping plane.
28
+ zfar : float
29
+ The floating-point distance to the far clipping plane.
30
+ ``zfar`` must be greater than ``znear``.
31
+ name : str, optional
32
+ The user-defined name of this object.
33
+ """
34
+
35
+ def __init__(self,
36
+ znear=DEFAULT_Z_NEAR,
37
+ zfar=DEFAULT_Z_FAR,
38
+ name=None):
39
+ self.name = name
40
+ self.znear = znear
41
+ self.zfar = zfar
42
+
43
+ @property
44
+ def name(self):
45
+ """str : The user-defined name of this object.
46
+ """
47
+ return self._name
48
+
49
+ @name.setter
50
+ def name(self, value):
51
+ if value is not None:
52
+ value = str(value)
53
+ self._name = value
54
+
55
+ @property
56
+ def znear(self):
57
+ """float : The distance to the near clipping plane.
58
+ """
59
+ return self._znear
60
+
61
+ @znear.setter
62
+ def znear(self, value):
63
+ value = float(value)
64
+ if value < 0:
65
+ raise ValueError('z-near must be >= 0.0')
66
+ self._znear = value
67
+
68
+ @property
69
+ def zfar(self):
70
+ """float : The distance to the far clipping plane.
71
+ """
72
+ return self._zfar
73
+
74
+ @zfar.setter
75
+ def zfar(self, value):
76
+ value = float(value)
77
+ if value <= 0 or value <= self.znear:
78
+ raise ValueError('zfar must be >0 and >znear')
79
+ self._zfar = value
80
+
81
+ @abc.abstractmethod
82
+ def get_projection_matrix(self, width=None, height=None):
83
+ """Return the OpenGL projection matrix for this camera.
84
+
85
+ Parameters
86
+ ----------
87
+ width : int
88
+ Width of the current viewport, in pixels.
89
+ height : int
90
+ Height of the current viewport, in pixels.
91
+ """
92
+ pass
93
+
94
+
95
+ class PerspectiveCamera(Camera):
96
+
97
+ """A perspective camera for perspective projection.
98
+
99
+ Parameters
100
+ ----------
101
+ yfov : float
102
+ The floating-point vertical field of view in radians.
103
+ znear : float
104
+ The floating-point distance to the near clipping plane.
105
+ If not specified, defaults to 0.05.
106
+ zfar : float, optional
107
+ The floating-point distance to the far clipping plane.
108
+ ``zfar`` must be greater than ``znear``.
109
+ If None, the camera uses an infinite projection matrix.
110
+ aspectRatio : float, optional
111
+ The floating-point aspect ratio of the field of view.
112
+ If not specified, the camera uses the viewport's aspect ratio.
113
+ name : str, optional
114
+ The user-defined name of this object.
115
+ """
116
+
117
+ def __init__(self,
118
+ yfov,
119
+ znear=DEFAULT_Z_NEAR,
120
+ zfar=None,
121
+ aspectRatio=None,
122
+ name=None):
123
+ super(PerspectiveCamera, self).__init__(
124
+ znear=znear,
125
+ zfar=zfar,
126
+ name=name,
127
+ )
128
+
129
+ self.yfov = yfov
130
+ self.aspectRatio = aspectRatio
131
+
132
+ @property
133
+ def yfov(self):
134
+ """float : The vertical field of view in radians.
135
+ """
136
+ return self._yfov
137
+
138
+ @yfov.setter
139
+ def yfov(self, value):
140
+ value = float(value)
141
+ if value <= 0.0:
142
+ raise ValueError('Field of view must be positive')
143
+ self._yfov = value
144
+
145
+ @property
146
+ def zfar(self):
147
+ """float : The distance to the far clipping plane.
148
+ """
149
+ return self._zfar
150
+
151
+ @zfar.setter
152
+ def zfar(self, value):
153
+ if value is not None:
154
+ value = float(value)
155
+ if value <= 0 or value <= self.znear:
156
+ raise ValueError('zfar must be >0 and >znear')
157
+ self._zfar = value
158
+
159
+ @property
160
+ def aspectRatio(self):
161
+ """float : The ratio of the width to the height of the field of view.
162
+ """
163
+ return self._aspectRatio
164
+
165
+ @aspectRatio.setter
166
+ def aspectRatio(self, value):
167
+ if value is not None:
168
+ value = float(value)
169
+ if value <= 0.0:
170
+ raise ValueError('Aspect ratio must be positive')
171
+ self._aspectRatio = value
172
+
173
+ def get_projection_matrix(self, width=None, height=None):
174
+ """Return the OpenGL projection matrix for this camera.
175
+
176
+ Parameters
177
+ ----------
178
+ width : int
179
+ Width of the current viewport, in pixels.
180
+ height : int
181
+ Height of the current viewport, in pixels.
182
+ """
183
+ aspect_ratio = self.aspectRatio
184
+ if aspect_ratio is None:
185
+ if width is None or height is None:
186
+ raise ValueError('Aspect ratio of camera must be defined')
187
+ aspect_ratio = float(width) / float(height)
188
+
189
+ a = aspect_ratio
190
+ t = np.tan(self.yfov / 2.0)
191
+ n = self.znear
192
+ f = self.zfar
193
+
194
+ P = np.zeros((4,4))
195
+ P[0][0] = 1.0 / (a * t)
196
+ P[1][1] = 1.0 / t
197
+ P[3][2] = -1.0
198
+
199
+ if f is None:
200
+ P[2][2] = -1.0
201
+ P[2][3] = -2.0 * n
202
+ else:
203
+ P[2][2] = (f + n) / (n - f)
204
+ P[2][3] = (2 * f * n) / (n - f)
205
+
206
+ return P
207
+
208
+
209
+ class OrthographicCamera(Camera):
210
+ """An orthographic camera for orthographic projection.
211
+
212
+ Parameters
213
+ ----------
214
+ xmag : float
215
+ The floating-point horizontal magnification of the view.
216
+ ymag : float
217
+ The floating-point vertical magnification of the view.
218
+ znear : float
219
+ The floating-point distance to the near clipping plane.
220
+ If not specified, defaults to 0.05.
221
+ zfar : float
222
+ The floating-point distance to the far clipping plane.
223
+ ``zfar`` must be greater than ``znear``.
224
+ If not specified, defaults to 100.0.
225
+ name : str, optional
226
+ The user-defined name of this object.
227
+ """
228
+
229
+ def __init__(self,
230
+ xmag,
231
+ ymag,
232
+ znear=DEFAULT_Z_NEAR,
233
+ zfar=DEFAULT_Z_FAR,
234
+ name=None):
235
+ super(OrthographicCamera, self).__init__(
236
+ znear=znear,
237
+ zfar=zfar,
238
+ name=name,
239
+ )
240
+
241
+ self.xmag = xmag
242
+ self.ymag = ymag
243
+
244
+ @property
245
+ def xmag(self):
246
+ """float : The horizontal magnification of the view.
247
+ """
248
+ return self._xmag
249
+
250
+ @xmag.setter
251
+ def xmag(self, value):
252
+ value = float(value)
253
+ if value <= 0.0:
254
+ raise ValueError('X magnification must be positive')
255
+ self._xmag = value
256
+
257
+ @property
258
+ def ymag(self):
259
+ """float : The vertical magnification of the view.
260
+ """
261
+ return self._ymag
262
+
263
+ @ymag.setter
264
+ def ymag(self, value):
265
+ value = float(value)
266
+ if value <= 0.0:
267
+ raise ValueError('Y magnification must be positive')
268
+ self._ymag = value
269
+
270
+ @property
271
+ def znear(self):
272
+ """float : The distance to the near clipping plane.
273
+ """
274
+ return self._znear
275
+
276
+ @znear.setter
277
+ def znear(self, value):
278
+ value = float(value)
279
+ if value <= 0:
280
+ raise ValueError('z-near must be > 0.0')
281
+ self._znear = value
282
+
283
+ def get_projection_matrix(self, width=None, height=None):
284
+ """Return the OpenGL projection matrix for this camera.
285
+
286
+ Parameters
287
+ ----------
288
+ width : int
289
+ Width of the current viewport, in pixels.
290
+ Unused in this function.
291
+ height : int
292
+ Height of the current viewport, in pixels.
293
+ Unused in this function.
294
+ """
295
+ xmag = self.xmag
296
+ ymag = self.ymag
297
+
298
+ # If screen width/height defined, rescale xmag
299
+ if width is not None and height is not None:
300
+ xmag = width / height * ymag
301
+
302
+ n = self.znear
303
+ f = self.zfar
304
+ P = np.zeros((4,4))
305
+ P[0][0] = 1.0 / xmag
306
+ P[1][1] = 1.0 / ymag
307
+ P[2][2] = 2.0 / (n - f)
308
+ P[2][3] = (f + n) / (n - f)
309
+ P[3][3] = 1.0
310
+ return P
311
+
312
+
313
+ class IntrinsicsCamera(Camera):
314
+ """A perspective camera with custom intrinsics.
315
+
316
+ Parameters
317
+ ----------
318
+ fx : float
319
+ X-axis focal length in pixels.
320
+ fy : float
321
+ Y-axis focal length in pixels.
322
+ cx : float
323
+ X-axis optical center in pixels.
324
+ cy : float
325
+ Y-axis optical center in pixels.
326
+ znear : float
327
+ The floating-point distance to the near clipping plane.
328
+ If not specified, defaults to 0.05.
329
+ zfar : float
330
+ The floating-point distance to the far clipping plane.
331
+ ``zfar`` must be greater than ``znear``.
332
+ If not specified, defaults to 100.0.
333
+ name : str, optional
334
+ The user-defined name of this object.
335
+ """
336
+
337
+ def __init__(self,
338
+ fx,
339
+ fy,
340
+ cx,
341
+ cy,
342
+ znear=DEFAULT_Z_NEAR,
343
+ zfar=DEFAULT_Z_FAR,
344
+ name=None):
345
+ super(IntrinsicsCamera, self).__init__(
346
+ znear=znear,
347
+ zfar=zfar,
348
+ name=name,
349
+ )
350
+
351
+ self.fx = fx
352
+ self.fy = fy
353
+ self.cx = cx
354
+ self.cy = cy
355
+
356
+ @property
357
+ def fx(self):
358
+ """float : X-axis focal length in meters.
359
+ """
360
+ return self._fx
361
+
362
+ @fx.setter
363
+ def fx(self, value):
364
+ self._fx = float(value)
365
+
366
+ @property
367
+ def fy(self):
368
+ """float : Y-axis focal length in meters.
369
+ """
370
+ return self._fy
371
+
372
+ @fy.setter
373
+ def fy(self, value):
374
+ self._fy = float(value)
375
+
376
+ @property
377
+ def cx(self):
378
+ """float : X-axis optical center in pixels.
379
+ """
380
+ return self._cx
381
+
382
+ @cx.setter
383
+ def cx(self, value):
384
+ self._cx = float(value)
385
+
386
+ @property
387
+ def cy(self):
388
+ """float : Y-axis optical center in pixels.
389
+ """
390
+ return self._cy
391
+
392
+ @cy.setter
393
+ def cy(self, value):
394
+ self._cy = float(value)
395
+
396
+ def get_projection_matrix(self, width, height):
397
+ """Return the OpenGL projection matrix for this camera.
398
+
399
+ Parameters
400
+ ----------
401
+ width : int
402
+ Width of the current viewport, in pixels.
403
+ height : int
404
+ Height of the current viewport, in pixels.
405
+ """
406
+ width = float(width)
407
+ height = float(height)
408
+
409
+ cx, cy = self.cx, self.cy
410
+ fx, fy = self.fx, self.fy
411
+ if sys.platform == 'darwin':
412
+ cx = self.cx * 2.0
413
+ cy = self.cy * 2.0
414
+ fx = self.fx * 2.0
415
+ fy = self.fy * 2.0
416
+
417
+ P = np.zeros((4,4))
418
+ P[0][0] = 2.0 * fx / width
419
+ P[1][1] = 2.0 * fy / height
420
+ P[0][2] = 1.0 - 2.0 * cx / width
421
+ P[1][2] = 2.0 * cy / height - 1.0
422
+ P[3][2] = -1.0
423
+
424
+ n = self.znear
425
+ f = self.zfar
426
+ if f is None:
427
+ P[2][2] = -1.0
428
+ P[2][3] = -2.0 * n
429
+ else:
430
+ P[2][2] = (f + n) / (n - f)
431
+ P[2][3] = (2 * f * n) / (n - f)
432
+
433
+ return P
434
+
435
+
436
+ __all__ = ['Camera', 'PerspectiveCamera', 'OrthographicCamera',
437
+ 'IntrinsicsCamera']