pyrender-maintained 1.0.0__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.
- pyrender_maintained-1.0.0/LICENSE +21 -0
- pyrender_maintained-1.0.0/PKG-INFO +55 -0
- pyrender_maintained-1.0.0/README.md +2 -0
- pyrender_maintained-1.0.0/pyrender/__init__.py +24 -0
- pyrender_maintained-1.0.0/pyrender/camera.py +435 -0
- pyrender_maintained-1.0.0/pyrender/constants.py +149 -0
- pyrender_maintained-1.0.0/pyrender/font.py +272 -0
- pyrender_maintained-1.0.0/pyrender/light.py +382 -0
- pyrender_maintained-1.0.0/pyrender/material.py +705 -0
- pyrender_maintained-1.0.0/pyrender/mesh.py +328 -0
- pyrender_maintained-1.0.0/pyrender/node.py +263 -0
- pyrender_maintained-1.0.0/pyrender/offscreen.py +160 -0
- pyrender_maintained-1.0.0/pyrender/platforms/__init__.py +6 -0
- pyrender_maintained-1.0.0/pyrender/platforms/base.py +73 -0
- pyrender_maintained-1.0.0/pyrender/platforms/egl.py +219 -0
- pyrender_maintained-1.0.0/pyrender/platforms/osmesa.py +59 -0
- pyrender_maintained-1.0.0/pyrender/platforms/pyglet_platform.py +90 -0
- pyrender_maintained-1.0.0/pyrender/primitive.py +489 -0
- pyrender_maintained-1.0.0/pyrender/renderer.py +1328 -0
- pyrender_maintained-1.0.0/pyrender/sampler.py +102 -0
- pyrender_maintained-1.0.0/pyrender/scene.py +585 -0
- pyrender_maintained-1.0.0/pyrender/shader_program.py +283 -0
- pyrender_maintained-1.0.0/pyrender/texture.py +259 -0
- pyrender_maintained-1.0.0/pyrender/trackball.py +216 -0
- pyrender_maintained-1.0.0/pyrender/utils.py +115 -0
- pyrender_maintained-1.0.0/pyrender/version.py +1 -0
- pyrender_maintained-1.0.0/pyrender/viewer.py +1157 -0
- pyrender_maintained-1.0.0/pyrender_maintained.egg-info/PKG-INFO +55 -0
- pyrender_maintained-1.0.0/pyrender_maintained.egg-info/SOURCES.txt +32 -0
- pyrender_maintained-1.0.0/pyrender_maintained.egg-info/dependency_links.txt +1 -0
- pyrender_maintained-1.0.0/pyrender_maintained.egg-info/requires.txt +21 -0
- pyrender_maintained-1.0.0/pyrender_maintained.egg-info/top_level.txt +1 -0
- pyrender_maintained-1.0.0/setup.cfg +4 -0
- pyrender_maintained-1.0.0/setup.py +72 -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,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyrender-maintained
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Easy-to-use Python renderer for 3D visualization (maintained fork)
|
|
5
|
+
Home-page: https://github.com/SimonKim4100/pyrender-maintained
|
|
6
|
+
Author: Simon Kim
|
|
7
|
+
Author-email: hohosemin@gmail.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 :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Natural Language :: English
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: freetype-py
|
|
24
|
+
Requires-Dist: imageio
|
|
25
|
+
Requires-Dist: networkx
|
|
26
|
+
Requires-Dist: numpy>=2.0
|
|
27
|
+
Requires-Dist: Pillow
|
|
28
|
+
Requires-Dist: pyglet>=2.0
|
|
29
|
+
Requires-Dist: PyOpenGL>=3.1.0
|
|
30
|
+
Requires-Dist: scipy
|
|
31
|
+
Requires-Dist: trimesh
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: flake8; extra == "dev"
|
|
34
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
37
|
+
Requires-Dist: tox; extra == "dev"
|
|
38
|
+
Provides-Extra: docs
|
|
39
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
40
|
+
Requires-Dist: sphinx_rtd_theme; extra == "docs"
|
|
41
|
+
Requires-Dist: sphinx-automodapi; extra == "docs"
|
|
42
|
+
Dynamic: author
|
|
43
|
+
Dynamic: author-email
|
|
44
|
+
Dynamic: classifier
|
|
45
|
+
Dynamic: description
|
|
46
|
+
Dynamic: home-page
|
|
47
|
+
Dynamic: keywords
|
|
48
|
+
Dynamic: license
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
Dynamic: provides-extra
|
|
51
|
+
Dynamic: requires-dist
|
|
52
|
+
Dynamic: requires-python
|
|
53
|
+
Dynamic: summary
|
|
54
|
+
|
|
55
|
+
A maintained fork of pyrender — a simple implementation of Physically-Based Rendering (PBR) in Python. Compliant with the glTF 2.0 standard. Supports modern Python (3.11+) and NumPy 2.x.
|
|
@@ -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,435 @@
|
|
|
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 sys
|
|
9
|
+
|
|
10
|
+
from .constants import DEFAULT_Z_NEAR, DEFAULT_Z_FAR
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Camera(abc.ABC):
|
|
14
|
+
"""Abstract base class for all cameras.
|
|
15
|
+
|
|
16
|
+
Note
|
|
17
|
+
----
|
|
18
|
+
Camera poses are specified in the OpenGL format,
|
|
19
|
+
where the z axis points away from the view direction and the
|
|
20
|
+
x and y axes point to the right and up in the image plane, respectively.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
znear : float
|
|
25
|
+
The floating-point distance to the near clipping plane.
|
|
26
|
+
zfar : float
|
|
27
|
+
The floating-point distance to the far clipping plane.
|
|
28
|
+
``zfar`` must be greater than ``znear``.
|
|
29
|
+
name : str, optional
|
|
30
|
+
The user-defined name of this object.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self,
|
|
34
|
+
znear=DEFAULT_Z_NEAR,
|
|
35
|
+
zfar=DEFAULT_Z_FAR,
|
|
36
|
+
name=None):
|
|
37
|
+
self.name = name
|
|
38
|
+
self.znear = znear
|
|
39
|
+
self.zfar = zfar
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def name(self):
|
|
43
|
+
"""str : The user-defined name of this object.
|
|
44
|
+
"""
|
|
45
|
+
return self._name
|
|
46
|
+
|
|
47
|
+
@name.setter
|
|
48
|
+
def name(self, value):
|
|
49
|
+
if value is not None:
|
|
50
|
+
value = str(value)
|
|
51
|
+
self._name = value
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def znear(self):
|
|
55
|
+
"""float : The distance to the near clipping plane.
|
|
56
|
+
"""
|
|
57
|
+
return self._znear
|
|
58
|
+
|
|
59
|
+
@znear.setter
|
|
60
|
+
def znear(self, value):
|
|
61
|
+
value = float(value)
|
|
62
|
+
if value < 0:
|
|
63
|
+
raise ValueError('z-near must be >= 0.0')
|
|
64
|
+
self._znear = value
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def zfar(self):
|
|
68
|
+
"""float : The distance to the far clipping plane.
|
|
69
|
+
"""
|
|
70
|
+
return self._zfar
|
|
71
|
+
|
|
72
|
+
@zfar.setter
|
|
73
|
+
def zfar(self, value):
|
|
74
|
+
value = float(value)
|
|
75
|
+
if value <= 0 or value <= self.znear:
|
|
76
|
+
raise ValueError('zfar must be >0 and >znear')
|
|
77
|
+
self._zfar = value
|
|
78
|
+
|
|
79
|
+
@abc.abstractmethod
|
|
80
|
+
def get_projection_matrix(self, width=None, height=None):
|
|
81
|
+
"""Return the OpenGL projection matrix for this camera.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
width : int
|
|
86
|
+
Width of the current viewport, in pixels.
|
|
87
|
+
height : int
|
|
88
|
+
Height of the current viewport, in pixels.
|
|
89
|
+
"""
|
|
90
|
+
pass
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class PerspectiveCamera(Camera):
|
|
94
|
+
|
|
95
|
+
"""A perspective camera for perspective projection.
|
|
96
|
+
|
|
97
|
+
Parameters
|
|
98
|
+
----------
|
|
99
|
+
yfov : float
|
|
100
|
+
The floating-point vertical field of view in radians.
|
|
101
|
+
znear : float
|
|
102
|
+
The floating-point distance to the near clipping plane.
|
|
103
|
+
If not specified, defaults to 0.05.
|
|
104
|
+
zfar : float, optional
|
|
105
|
+
The floating-point distance to the far clipping plane.
|
|
106
|
+
``zfar`` must be greater than ``znear``.
|
|
107
|
+
If None, the camera uses an infinite projection matrix.
|
|
108
|
+
aspectRatio : float, optional
|
|
109
|
+
The floating-point aspect ratio of the field of view.
|
|
110
|
+
If not specified, the camera uses the viewport's aspect ratio.
|
|
111
|
+
name : str, optional
|
|
112
|
+
The user-defined name of this object.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
def __init__(self,
|
|
116
|
+
yfov,
|
|
117
|
+
znear=DEFAULT_Z_NEAR,
|
|
118
|
+
zfar=None,
|
|
119
|
+
aspectRatio=None,
|
|
120
|
+
name=None):
|
|
121
|
+
super(PerspectiveCamera, self).__init__(
|
|
122
|
+
znear=znear,
|
|
123
|
+
zfar=zfar,
|
|
124
|
+
name=name,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
self.yfov = yfov
|
|
128
|
+
self.aspectRatio = aspectRatio
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def yfov(self):
|
|
132
|
+
"""float : The vertical field of view in radians.
|
|
133
|
+
"""
|
|
134
|
+
return self._yfov
|
|
135
|
+
|
|
136
|
+
@yfov.setter
|
|
137
|
+
def yfov(self, value):
|
|
138
|
+
value = float(value)
|
|
139
|
+
if value <= 0.0:
|
|
140
|
+
raise ValueError('Field of view must be positive')
|
|
141
|
+
self._yfov = value
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
def zfar(self):
|
|
145
|
+
"""float : The distance to the far clipping plane.
|
|
146
|
+
"""
|
|
147
|
+
return self._zfar
|
|
148
|
+
|
|
149
|
+
@zfar.setter
|
|
150
|
+
def zfar(self, value):
|
|
151
|
+
if value is not None:
|
|
152
|
+
value = float(value)
|
|
153
|
+
if value <= 0 or value <= self.znear:
|
|
154
|
+
raise ValueError('zfar must be >0 and >znear')
|
|
155
|
+
self._zfar = value
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def aspectRatio(self):
|
|
159
|
+
"""float : The ratio of the width to the height of the field of view.
|
|
160
|
+
"""
|
|
161
|
+
return self._aspectRatio
|
|
162
|
+
|
|
163
|
+
@aspectRatio.setter
|
|
164
|
+
def aspectRatio(self, value):
|
|
165
|
+
if value is not None:
|
|
166
|
+
value = float(value)
|
|
167
|
+
if value <= 0.0:
|
|
168
|
+
raise ValueError('Aspect ratio must be positive')
|
|
169
|
+
self._aspectRatio = value
|
|
170
|
+
|
|
171
|
+
def get_projection_matrix(self, width=None, height=None):
|
|
172
|
+
"""Return the OpenGL projection matrix for this camera.
|
|
173
|
+
|
|
174
|
+
Parameters
|
|
175
|
+
----------
|
|
176
|
+
width : int
|
|
177
|
+
Width of the current viewport, in pixels.
|
|
178
|
+
height : int
|
|
179
|
+
Height of the current viewport, in pixels.
|
|
180
|
+
"""
|
|
181
|
+
aspect_ratio = self.aspectRatio
|
|
182
|
+
if aspect_ratio is None:
|
|
183
|
+
if width is None or height is None:
|
|
184
|
+
raise ValueError('Aspect ratio of camera must be defined')
|
|
185
|
+
aspect_ratio = float(width) / float(height)
|
|
186
|
+
|
|
187
|
+
a = aspect_ratio
|
|
188
|
+
t = np.tan(self.yfov / 2.0)
|
|
189
|
+
n = self.znear
|
|
190
|
+
f = self.zfar
|
|
191
|
+
|
|
192
|
+
P = np.zeros((4,4))
|
|
193
|
+
P[0][0] = 1.0 / (a * t)
|
|
194
|
+
P[1][1] = 1.0 / t
|
|
195
|
+
P[3][2] = -1.0
|
|
196
|
+
|
|
197
|
+
if f is None:
|
|
198
|
+
P[2][2] = -1.0
|
|
199
|
+
P[2][3] = -2.0 * n
|
|
200
|
+
else:
|
|
201
|
+
P[2][2] = (f + n) / (n - f)
|
|
202
|
+
P[2][3] = (2 * f * n) / (n - f)
|
|
203
|
+
|
|
204
|
+
return P
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class OrthographicCamera(Camera):
|
|
208
|
+
"""An orthographic camera for orthographic projection.
|
|
209
|
+
|
|
210
|
+
Parameters
|
|
211
|
+
----------
|
|
212
|
+
xmag : float
|
|
213
|
+
The floating-point horizontal magnification of the view.
|
|
214
|
+
ymag : float
|
|
215
|
+
The floating-point vertical magnification of the view.
|
|
216
|
+
znear : float
|
|
217
|
+
The floating-point distance to the near clipping plane.
|
|
218
|
+
If not specified, defaults to 0.05.
|
|
219
|
+
zfar : float
|
|
220
|
+
The floating-point distance to the far clipping plane.
|
|
221
|
+
``zfar`` must be greater than ``znear``.
|
|
222
|
+
If not specified, defaults to 100.0.
|
|
223
|
+
name : str, optional
|
|
224
|
+
The user-defined name of this object.
|
|
225
|
+
"""
|
|
226
|
+
|
|
227
|
+
def __init__(self,
|
|
228
|
+
xmag,
|
|
229
|
+
ymag,
|
|
230
|
+
znear=DEFAULT_Z_NEAR,
|
|
231
|
+
zfar=DEFAULT_Z_FAR,
|
|
232
|
+
name=None):
|
|
233
|
+
super(OrthographicCamera, self).__init__(
|
|
234
|
+
znear=znear,
|
|
235
|
+
zfar=zfar,
|
|
236
|
+
name=name,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
self.xmag = xmag
|
|
240
|
+
self.ymag = ymag
|
|
241
|
+
|
|
242
|
+
@property
|
|
243
|
+
def xmag(self):
|
|
244
|
+
"""float : The horizontal magnification of the view.
|
|
245
|
+
"""
|
|
246
|
+
return self._xmag
|
|
247
|
+
|
|
248
|
+
@xmag.setter
|
|
249
|
+
def xmag(self, value):
|
|
250
|
+
value = float(value)
|
|
251
|
+
if value <= 0.0:
|
|
252
|
+
raise ValueError('X magnification must be positive')
|
|
253
|
+
self._xmag = value
|
|
254
|
+
|
|
255
|
+
@property
|
|
256
|
+
def ymag(self):
|
|
257
|
+
"""float : The vertical magnification of the view.
|
|
258
|
+
"""
|
|
259
|
+
return self._ymag
|
|
260
|
+
|
|
261
|
+
@ymag.setter
|
|
262
|
+
def ymag(self, value):
|
|
263
|
+
value = float(value)
|
|
264
|
+
if value <= 0.0:
|
|
265
|
+
raise ValueError('Y magnification must be positive')
|
|
266
|
+
self._ymag = value
|
|
267
|
+
|
|
268
|
+
@property
|
|
269
|
+
def znear(self):
|
|
270
|
+
"""float : The distance to the near clipping plane.
|
|
271
|
+
"""
|
|
272
|
+
return self._znear
|
|
273
|
+
|
|
274
|
+
@znear.setter
|
|
275
|
+
def znear(self, value):
|
|
276
|
+
value = float(value)
|
|
277
|
+
if value <= 0:
|
|
278
|
+
raise ValueError('z-near must be > 0.0')
|
|
279
|
+
self._znear = value
|
|
280
|
+
|
|
281
|
+
def get_projection_matrix(self, width=None, height=None):
|
|
282
|
+
"""Return the OpenGL projection matrix for this camera.
|
|
283
|
+
|
|
284
|
+
Parameters
|
|
285
|
+
----------
|
|
286
|
+
width : int
|
|
287
|
+
Width of the current viewport, in pixels.
|
|
288
|
+
Unused in this function.
|
|
289
|
+
height : int
|
|
290
|
+
Height of the current viewport, in pixels.
|
|
291
|
+
Unused in this function.
|
|
292
|
+
"""
|
|
293
|
+
xmag = self.xmag
|
|
294
|
+
ymag = self.ymag
|
|
295
|
+
|
|
296
|
+
# If screen width/height defined, rescale xmag
|
|
297
|
+
if width is not None and height is not None:
|
|
298
|
+
xmag = width / height * ymag
|
|
299
|
+
|
|
300
|
+
n = self.znear
|
|
301
|
+
f = self.zfar
|
|
302
|
+
P = np.zeros((4,4))
|
|
303
|
+
P[0][0] = 1.0 / xmag
|
|
304
|
+
P[1][1] = 1.0 / ymag
|
|
305
|
+
P[2][2] = 2.0 / (n - f)
|
|
306
|
+
P[2][3] = (f + n) / (n - f)
|
|
307
|
+
P[3][3] = 1.0
|
|
308
|
+
return P
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
class IntrinsicsCamera(Camera):
|
|
312
|
+
"""A perspective camera with custom intrinsics.
|
|
313
|
+
|
|
314
|
+
Parameters
|
|
315
|
+
----------
|
|
316
|
+
fx : float
|
|
317
|
+
X-axis focal length in pixels.
|
|
318
|
+
fy : float
|
|
319
|
+
Y-axis focal length in pixels.
|
|
320
|
+
cx : float
|
|
321
|
+
X-axis optical center in pixels.
|
|
322
|
+
cy : float
|
|
323
|
+
Y-axis optical center in pixels.
|
|
324
|
+
znear : float
|
|
325
|
+
The floating-point distance to the near clipping plane.
|
|
326
|
+
If not specified, defaults to 0.05.
|
|
327
|
+
zfar : float
|
|
328
|
+
The floating-point distance to the far clipping plane.
|
|
329
|
+
``zfar`` must be greater than ``znear``.
|
|
330
|
+
If not specified, defaults to 100.0.
|
|
331
|
+
name : str, optional
|
|
332
|
+
The user-defined name of this object.
|
|
333
|
+
"""
|
|
334
|
+
|
|
335
|
+
def __init__(self,
|
|
336
|
+
fx,
|
|
337
|
+
fy,
|
|
338
|
+
cx,
|
|
339
|
+
cy,
|
|
340
|
+
znear=DEFAULT_Z_NEAR,
|
|
341
|
+
zfar=DEFAULT_Z_FAR,
|
|
342
|
+
name=None):
|
|
343
|
+
super(IntrinsicsCamera, self).__init__(
|
|
344
|
+
znear=znear,
|
|
345
|
+
zfar=zfar,
|
|
346
|
+
name=name,
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
self.fx = fx
|
|
350
|
+
self.fy = fy
|
|
351
|
+
self.cx = cx
|
|
352
|
+
self.cy = cy
|
|
353
|
+
|
|
354
|
+
@property
|
|
355
|
+
def fx(self):
|
|
356
|
+
"""float : X-axis focal length in meters.
|
|
357
|
+
"""
|
|
358
|
+
return self._fx
|
|
359
|
+
|
|
360
|
+
@fx.setter
|
|
361
|
+
def fx(self, value):
|
|
362
|
+
self._fx = float(value)
|
|
363
|
+
|
|
364
|
+
@property
|
|
365
|
+
def fy(self):
|
|
366
|
+
"""float : Y-axis focal length in meters.
|
|
367
|
+
"""
|
|
368
|
+
return self._fy
|
|
369
|
+
|
|
370
|
+
@fy.setter
|
|
371
|
+
def fy(self, value):
|
|
372
|
+
self._fy = float(value)
|
|
373
|
+
|
|
374
|
+
@property
|
|
375
|
+
def cx(self):
|
|
376
|
+
"""float : X-axis optical center in pixels.
|
|
377
|
+
"""
|
|
378
|
+
return self._cx
|
|
379
|
+
|
|
380
|
+
@cx.setter
|
|
381
|
+
def cx(self, value):
|
|
382
|
+
self._cx = float(value)
|
|
383
|
+
|
|
384
|
+
@property
|
|
385
|
+
def cy(self):
|
|
386
|
+
"""float : Y-axis optical center in pixels.
|
|
387
|
+
"""
|
|
388
|
+
return self._cy
|
|
389
|
+
|
|
390
|
+
@cy.setter
|
|
391
|
+
def cy(self, value):
|
|
392
|
+
self._cy = float(value)
|
|
393
|
+
|
|
394
|
+
def get_projection_matrix(self, width, height):
|
|
395
|
+
"""Return the OpenGL projection matrix for this camera.
|
|
396
|
+
|
|
397
|
+
Parameters
|
|
398
|
+
----------
|
|
399
|
+
width : int
|
|
400
|
+
Width of the current viewport, in pixels.
|
|
401
|
+
height : int
|
|
402
|
+
Height of the current viewport, in pixels.
|
|
403
|
+
"""
|
|
404
|
+
width = float(width)
|
|
405
|
+
height = float(height)
|
|
406
|
+
|
|
407
|
+
cx, cy = self.cx, self.cy
|
|
408
|
+
fx, fy = self.fx, self.fy
|
|
409
|
+
if sys.platform == 'darwin':
|
|
410
|
+
cx = self.cx * 2.0
|
|
411
|
+
cy = self.cy * 2.0
|
|
412
|
+
fx = self.fx * 2.0
|
|
413
|
+
fy = self.fy * 2.0
|
|
414
|
+
|
|
415
|
+
P = np.zeros((4,4))
|
|
416
|
+
P[0][0] = 2.0 * fx / width
|
|
417
|
+
P[1][1] = 2.0 * fy / height
|
|
418
|
+
P[0][2] = 1.0 - 2.0 * cx / width
|
|
419
|
+
P[1][2] = 2.0 * cy / height - 1.0
|
|
420
|
+
P[3][2] = -1.0
|
|
421
|
+
|
|
422
|
+
n = self.znear
|
|
423
|
+
f = self.zfar
|
|
424
|
+
if f is None:
|
|
425
|
+
P[2][2] = -1.0
|
|
426
|
+
P[2][3] = -2.0 * n
|
|
427
|
+
else:
|
|
428
|
+
P[2][2] = (f + n) / (n - f)
|
|
429
|
+
P[2][3] = (2 * f * n) / (n - f)
|
|
430
|
+
|
|
431
|
+
return P
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
__all__ = ['Camera', 'PerspectiveCamera', 'OrthographicCamera',
|
|
435
|
+
'IntrinsicsCamera']
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
DEFAULT_Z_NEAR = 0.05 # Near clipping plane, in meters
|
|
2
|
+
DEFAULT_Z_FAR = 100.0 # Far clipping plane, in meters
|
|
3
|
+
DEFAULT_SCENE_SCALE = 2.0 # Default scene scale
|
|
4
|
+
MAX_N_LIGHTS = 4 # Maximum number of lights of each type allowed
|
|
5
|
+
TARGET_OPEN_GL_MAJOR = 4 # Target OpenGL Major Version
|
|
6
|
+
TARGET_OPEN_GL_MINOR = 1 # Target OpenGL Minor Version
|
|
7
|
+
MIN_OPEN_GL_MAJOR = 3 # Minimum OpenGL Major Version
|
|
8
|
+
MIN_OPEN_GL_MINOR = 3 # Minimum OpenGL Minor Version
|
|
9
|
+
FLOAT_SZ = 4 # Byte size of GL float32
|
|
10
|
+
UINT_SZ = 4 # Byte size of GL uint32
|
|
11
|
+
SHADOW_TEX_SZ = 2048 # Width and Height of Shadow Textures
|
|
12
|
+
TEXT_PADDING = 20 # Width of padding for rendering text (px)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Flags for render type
|
|
16
|
+
class RenderFlags(object):
|
|
17
|
+
"""Flags for rendering in the scene.
|
|
18
|
+
|
|
19
|
+
Combine them with the bitwise or. For example,
|
|
20
|
+
|
|
21
|
+
>>> flags = OFFSCREEN | SHADOWS_DIRECTIONAL | VERTEX_NORMALS
|
|
22
|
+
|
|
23
|
+
would result in an offscreen render with directional shadows and
|
|
24
|
+
vertex normals enabled.
|
|
25
|
+
"""
|
|
26
|
+
NONE = 0
|
|
27
|
+
"""Normal PBR Render."""
|
|
28
|
+
DEPTH_ONLY = 1
|
|
29
|
+
"""Only render the depth buffer."""
|
|
30
|
+
OFFSCREEN = 2
|
|
31
|
+
"""Render offscreen and return the depth and (optionally) color buffers."""
|
|
32
|
+
FLIP_WIREFRAME = 4
|
|
33
|
+
"""Invert the status of wireframe rendering for each mesh."""
|
|
34
|
+
ALL_WIREFRAME = 8
|
|
35
|
+
"""Render all meshes as wireframes."""
|
|
36
|
+
ALL_SOLID = 16
|
|
37
|
+
"""Render all meshes as solids."""
|
|
38
|
+
SHADOWS_DIRECTIONAL = 32
|
|
39
|
+
"""Render shadows for directional lights."""
|
|
40
|
+
SHADOWS_POINT = 64
|
|
41
|
+
"""Render shadows for point lights."""
|
|
42
|
+
SHADOWS_SPOT = 128
|
|
43
|
+
"""Render shadows for spot lights."""
|
|
44
|
+
SHADOWS_ALL = 32 | 64 | 128
|
|
45
|
+
"""Render shadows for all lights."""
|
|
46
|
+
VERTEX_NORMALS = 256
|
|
47
|
+
"""Render vertex normals."""
|
|
48
|
+
FACE_NORMALS = 512
|
|
49
|
+
"""Render face normals."""
|
|
50
|
+
SKIP_CULL_FACES = 1024
|
|
51
|
+
"""Do not cull back faces."""
|
|
52
|
+
RGBA = 2048
|
|
53
|
+
"""Render the color buffer with the alpha channel enabled."""
|
|
54
|
+
FLAT = 4096
|
|
55
|
+
"""Render the color buffer flat, with no lighting computations."""
|
|
56
|
+
SEG = 8192
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class TextAlign:
|
|
60
|
+
"""Text alignment options for captions.
|
|
61
|
+
|
|
62
|
+
Only use one at a time.
|
|
63
|
+
"""
|
|
64
|
+
CENTER = 0
|
|
65
|
+
"""Center the text by width and height."""
|
|
66
|
+
CENTER_LEFT = 1
|
|
67
|
+
"""Center the text by height and left-align it."""
|
|
68
|
+
CENTER_RIGHT = 2
|
|
69
|
+
"""Center the text by height and right-align it."""
|
|
70
|
+
BOTTOM_LEFT = 3
|
|
71
|
+
"""Put the text in the bottom-left corner."""
|
|
72
|
+
BOTTOM_RIGHT = 4
|
|
73
|
+
"""Put the text in the bottom-right corner."""
|
|
74
|
+
BOTTOM_CENTER = 5
|
|
75
|
+
"""Center the text by width and fix it to the bottom."""
|
|
76
|
+
TOP_LEFT = 6
|
|
77
|
+
"""Put the text in the top-left corner."""
|
|
78
|
+
TOP_RIGHT = 7
|
|
79
|
+
"""Put the text in the top-right corner."""
|
|
80
|
+
TOP_CENTER = 8
|
|
81
|
+
"""Center the text by width and fix it to the top."""
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class GLTF(object):
|
|
85
|
+
"""Options for GL objects."""
|
|
86
|
+
NEAREST = 9728
|
|
87
|
+
"""Nearest neighbor interpolation."""
|
|
88
|
+
LINEAR = 9729
|
|
89
|
+
"""Linear interpolation."""
|
|
90
|
+
NEAREST_MIPMAP_NEAREST = 9984
|
|
91
|
+
"""Nearest mipmapping."""
|
|
92
|
+
LINEAR_MIPMAP_NEAREST = 9985
|
|
93
|
+
"""Linear mipmapping."""
|
|
94
|
+
NEAREST_MIPMAP_LINEAR = 9986
|
|
95
|
+
"""Nearest mipmapping."""
|
|
96
|
+
LINEAR_MIPMAP_LINEAR = 9987
|
|
97
|
+
"""Linear mipmapping."""
|
|
98
|
+
CLAMP_TO_EDGE = 33071
|
|
99
|
+
"""Clamp to the edge of the texture."""
|
|
100
|
+
MIRRORED_REPEAT = 33648
|
|
101
|
+
"""Mirror the texture."""
|
|
102
|
+
REPEAT = 10497
|
|
103
|
+
"""Repeat the texture."""
|
|
104
|
+
POINTS = 0
|
|
105
|
+
"""Render as points."""
|
|
106
|
+
LINES = 1
|
|
107
|
+
"""Render as lines."""
|
|
108
|
+
LINE_LOOP = 2
|
|
109
|
+
"""Render as a line loop."""
|
|
110
|
+
LINE_STRIP = 3
|
|
111
|
+
"""Render as a line strip."""
|
|
112
|
+
TRIANGLES = 4
|
|
113
|
+
"""Render as triangles."""
|
|
114
|
+
TRIANGLE_STRIP = 5
|
|
115
|
+
"""Render as a triangle strip."""
|
|
116
|
+
TRIANGLE_FAN = 6
|
|
117
|
+
"""Render as a triangle fan."""
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class BufFlags(object):
|
|
121
|
+
POSITION = 0
|
|
122
|
+
NORMAL = 1
|
|
123
|
+
TANGENT = 2
|
|
124
|
+
TEXCOORD_0 = 4
|
|
125
|
+
TEXCOORD_1 = 8
|
|
126
|
+
COLOR_0 = 16
|
|
127
|
+
JOINTS_0 = 32
|
|
128
|
+
WEIGHTS_0 = 64
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class TexFlags(object):
|
|
132
|
+
NONE = 0
|
|
133
|
+
NORMAL = 1
|
|
134
|
+
OCCLUSION = 2
|
|
135
|
+
EMISSIVE = 4
|
|
136
|
+
BASE_COLOR = 8
|
|
137
|
+
METALLIC_ROUGHNESS = 16
|
|
138
|
+
DIFFUSE = 32
|
|
139
|
+
SPECULAR_GLOSSINESS = 64
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class ProgramFlags:
|
|
143
|
+
NONE = 0
|
|
144
|
+
USE_MATERIAL = 1
|
|
145
|
+
VERTEX_NORMALS = 2
|
|
146
|
+
FACE_NORMALS = 4
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
__all__ = ['RenderFlags', 'TextAlign', 'GLTF']
|