ncca-ngl 0.1.6__py3-none-any.whl → 0.2.2__py3-none-any.whl
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.
- ncca/ngl/__init__.py +3 -1
- ncca/ngl/prim_data.py +611 -0
- ncca/ngl/primitives.py +51 -636
- ncca/ngl/util.py +46 -18
- {ncca_ngl-0.1.6.dist-info → ncca_ngl-0.2.2.dist-info}/METADATA +1 -1
- {ncca_ngl-0.1.6.dist-info → ncca_ngl-0.2.2.dist-info}/RECORD +7 -6
- {ncca_ngl-0.1.6.dist-info → ncca_ngl-0.2.2.dist-info}/WHEEL +1 -1
ncca/ngl/util.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Most of these functions are based on functions found in other libraries such as GLM, NGL or GLU
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
+
import enum
|
|
6
7
|
import math
|
|
7
8
|
|
|
8
9
|
from .mat4 import Mat4
|
|
@@ -44,7 +45,32 @@ def look_at(eye, look, up):
|
|
|
44
45
|
return result
|
|
45
46
|
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
class PerspMode(enum.Enum):
|
|
49
|
+
OpenGL = "OpenGL"
|
|
50
|
+
WebGPU = "WebGPU"
|
|
51
|
+
Vulkan = "Vulkan"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def perspective(
|
|
55
|
+
fov: float,
|
|
56
|
+
aspect: float,
|
|
57
|
+
near: float,
|
|
58
|
+
far: float,
|
|
59
|
+
mode: PerspMode = PerspMode.OpenGL,
|
|
60
|
+
) -> Mat4:
|
|
61
|
+
"""
|
|
62
|
+
Calculate a perspective matrix for various 3D graphics API's default mode is OpenGL but will covert for Vulkan and Web GPU if
|
|
63
|
+
required.
|
|
64
|
+
|
|
65
|
+
Args :
|
|
66
|
+
fov : float - Field of view angle in degrees.
|
|
67
|
+
aspect : float - Aspect ratio of the viewport.
|
|
68
|
+
near : float - Near clipping plane distance.
|
|
69
|
+
far : float - Far clipping plane distance.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Mat4 - The perspective matrix.
|
|
73
|
+
"""
|
|
48
74
|
m = Mat4.zero() # as per glm
|
|
49
75
|
_range = math.tan(math.radians(fov / 2.0)) * near
|
|
50
76
|
left = -_range * aspect
|
|
@@ -53,34 +79,36 @@ def perspective(fov, aspect, near, far):
|
|
|
53
79
|
top = _range
|
|
54
80
|
m.m[0][0] = (2.0 * near) / (right - left)
|
|
55
81
|
m.m[1][1] = (2.0 * near) / (top - bottom)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
match mode:
|
|
83
|
+
case PerspMode.OpenGL:
|
|
84
|
+
m.m[2][2] = -(far + near) / (far - near)
|
|
85
|
+
m.m[2][3] = -1.0
|
|
86
|
+
m.m[3][2] = -(2.0 * far * near) / (far - near)
|
|
87
|
+
|
|
88
|
+
# This ensures the clip space Z range is [0, 1] as required by Vulkan and WebGPU.
|
|
89
|
+
case PerspMode.WebGPU | PerspMode.Vulkan:
|
|
90
|
+
m.m[2][2] = -far / (far - near)
|
|
91
|
+
m.m[2][3] = -1.0
|
|
92
|
+
m.m[3][2] = -(far * near) / (far - near)
|
|
59
93
|
return m
|
|
60
94
|
|
|
61
95
|
|
|
62
|
-
def ortho(left, right, bottom, top, near, far):
|
|
63
|
-
"""Create an orthographic projection matrix."""
|
|
96
|
+
def ortho(left, right, bottom, top, near, far, mode=PerspMode.OpenGL):
|
|
64
97
|
m = Mat4.identity()
|
|
65
98
|
m.m[0][0] = 2.0 / (right - left)
|
|
66
99
|
m.m[1][1] = 2.0 / (top - bottom)
|
|
67
|
-
|
|
100
|
+
match mode:
|
|
101
|
+
case PerspMode.OpenGL:
|
|
102
|
+
m.m[2][2] = -2.0 / (far - near)
|
|
103
|
+
m.m[3][2] = -(far + near) / (far - near)
|
|
104
|
+
case PerspMode.WebGPU | PerspMode.Vulkan:
|
|
105
|
+
m.m[2][2] = -1.0 / (far - near)
|
|
106
|
+
m.m[3][2] = -near / (far - near)
|
|
68
107
|
m.m[3][0] = -(right + left) / (right - left)
|
|
69
108
|
m.m[3][1] = -(top + bottom) / (top - bottom)
|
|
70
|
-
m.m[3][2] = -(far + near) / (far - near)
|
|
71
109
|
return m
|
|
72
110
|
|
|
73
111
|
|
|
74
|
-
# Mat4 result(1.0f);
|
|
75
|
-
# result.m_00= 2.0f / (_right - _left);
|
|
76
|
-
# result.m_11= 2.0f / (_top - _bottom);
|
|
77
|
-
# result.m_22= - 2.0f / (_zFar - _zNear);
|
|
78
|
-
# result.m_30= - (_right + _left) / (_right - _left);
|
|
79
|
-
# result.m_31= - (_top + _bottom) / (_top - _bottom);
|
|
80
|
-
# result.m_32= - (_zFar + _zNear) / (_zFar - _zNear);
|
|
81
|
-
# return result;
|
|
82
|
-
|
|
83
|
-
|
|
84
112
|
def frustum(left, right, bottom, top, near, far):
|
|
85
113
|
"""Create a frustum projection matrix."""
|
|
86
114
|
m = Mat4.zero()
|
|
@@ -15,7 +15,7 @@ ncca/ngl/PrimData/pack_arrays.py,sha256=aWShJX8QPHXKTj66C8yu1DskmD3VEzFXyaADcxw6
|
|
|
15
15
|
ncca/ngl/PrimData/teapot.npy,sha256=fiOfYtB5SkegO7uTSitpjl_HmnS_iIy0sXAGfxCXXjY,1350560
|
|
16
16
|
ncca/ngl/PrimData/tetrahedron.npy,sha256=_KCSpflFXhYB4gGVxFmF5Cv6pQyPHuUlCj9xfL2oyEM,512
|
|
17
17
|
ncca/ngl/PrimData/troll.npy,sha256=ohgGgxLCJrmsFdNrlfRY2Rg9eJgcmvArf6IAspO2BKA,3505280
|
|
18
|
-
ncca/ngl/__init__.py,sha256=
|
|
18
|
+
ncca/ngl/__init__.py,sha256=tyDe5m-1jd51kIOU-f2m1kU0XU10mebwrQ3td0Wdhko,2543
|
|
19
19
|
ncca/ngl/abstract_vao.py,sha256=VLKp3pmPYK_dQgEImMOAQ0DufAswK_0H4DR4r8flp2U,2104
|
|
20
20
|
ncca/ngl/base_mesh.py,sha256=2JmVT5_bvgLHra1VnwRld-mh-20IqqekgEu1dbGU1a4,5736
|
|
21
21
|
ncca/ngl/base_mesh.pyi,sha256=kobLuNnCSZlRRobIgVopQaS7Bjg0tJ3m4M64WXt5I-M,173
|
|
@@ -30,7 +30,8 @@ ncca/ngl/mat4.py,sha256=eGvmLfw_wwKuuVh29wAKrvSZJB41jgmcYV5EufzyXbo,17273
|
|
|
30
30
|
ncca/ngl/multi_buffer_vao.py,sha256=cuNE6gSrqkNcYvfIOYOZp4MVnpCvChUgnzsf7b60pWg,1752
|
|
31
31
|
ncca/ngl/obj.py,sha256=AGldNouHrkrDs2UhATClGkgo4dzr6lzArR4YeCxQKmo,13667
|
|
32
32
|
ncca/ngl/plane.py,sha256=96WuGzexYKhoeRVevGP2pZcustt9fzyyAjuwJHT25tk,1299
|
|
33
|
-
ncca/ngl/
|
|
33
|
+
ncca/ngl/prim_data.py,sha256=sBynXeAfVtYXK7dkdLYELo0VIbN1lK1KZ8KMmCWzjBA,19047
|
|
34
|
+
ncca/ngl/primitives.py,sha256=pThdSWLv7jJa9weBVOXhRgTfVVH54AWCbsDFCEI1YLg,4841
|
|
34
35
|
ncca/ngl/pyside_event_handling_mixin.py,sha256=L8obXeTp-g2Va2eXyd1hnmSp-sY7p4GX6EcFYRnH1F4,10588
|
|
35
36
|
ncca/ngl/quaternion.py,sha256=agmbW8i125FyLOV2Z9SpTY5yQwmnnm0rxQawwHqq1YI,3858
|
|
36
37
|
ncca/ngl/random.py,sha256=wX1R2rMpb76TP4rk44NUp5XoVuMisH9d-eBG5kFBZsM,5579
|
|
@@ -51,7 +52,7 @@ ncca/ngl/simple_vao.py,sha256=jfU2O3yliaM6iWNvfcRbjQ6o2_IVSPrOR3GthDiul6Q,1419
|
|
|
51
52
|
ncca/ngl/text.py,sha256=yWNfKHnuWn0bxbwhW1H-EkRZ7bEM9DAyjES16cxTnME,13608
|
|
52
53
|
ncca/ngl/texture.py,sha256=OgBBEItgUDohCsVWgmjEWcQWBJaXl9w070PTOOywPx4,2303
|
|
53
54
|
ncca/ngl/transform.py,sha256=_PibgtFoU_exfvQUWucmts0WF5OreSTNbftvSa3zT8g,2938
|
|
54
|
-
ncca/ngl/util.py,sha256=
|
|
55
|
+
ncca/ngl/util.py,sha256=8jp5vTVuGfVHMSktFEubtoaQ8SvLIQtM2UNbUeMTOFk,4372
|
|
55
56
|
ncca/ngl/vao_factory.py,sha256=v87VfrUMaoqcsE-CS9kM7h5Fyk_e0LGl_iA6xqaomPg,930
|
|
56
57
|
ncca/ngl/vec2.py,sha256=3bhd03y5E3HRnBdXJZ4xMsTMMAte5IEr6u4qqWT_UL4,10361
|
|
57
58
|
ncca/ngl/vec2_array.py,sha256=7QRgXh75fORsmNnSnNxNQWk6_rnDgfmRX3tmJZ4ES9E,3420
|
|
@@ -59,6 +60,6 @@ ncca/ngl/vec3.py,sha256=ntgqB3sc_jzcGO5vlHKgDqloOoMkykVcWPxpYdWFy5Q,12449
|
|
|
59
60
|
ncca/ngl/vec3_array.py,sha256=fLRC8k0TwcaU7CnR2GmJ0prud4dcvvUX0JTbQH_2W3Y,3535
|
|
60
61
|
ncca/ngl/vec4.py,sha256=95b7yr82JtC3FqVDC8Hwn3wzPmVzSYTDCR1A6h_w9RM,6884
|
|
61
62
|
ncca/ngl/vec4_array.py,sha256=PSJXfG0g2AT4oQCLHiVAP6EC5n7vMXRQy0N1rGvv1iw,3426
|
|
62
|
-
ncca_ngl-0.
|
|
63
|
-
ncca_ngl-0.
|
|
64
|
-
ncca_ngl-0.
|
|
63
|
+
ncca_ngl-0.2.2.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
|
|
64
|
+
ncca_ngl-0.2.2.dist-info/METADATA,sha256=7mdnns3adaYNydJ1fvfPeSO_alBW080SZQfnx6wGhGY,1596
|
|
65
|
+
ncca_ngl-0.2.2.dist-info/RECORD,,
|