ncca-ngl 0.1.6__py3-none-any.whl → 0.2.1__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/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
- def perspective(fov, aspect, near, far):
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
- m.m[2][2] = -(far + near) / (far - near)
57
- m.m[2][3] = -1.0
58
- m.m[3][2] = -(2.0 * far * near) / (far - near)
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
- m.m[2][2] = -2.0 / (far - near)
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ncca-ngl
3
- Version: 0.1.6
3
+ Version: 0.2.1
4
4
  Summary: A Python version of the NGL graphics library.
5
5
  Author: Jon Macey
6
6
  Author-email: Jon Macey <jmacey@bournemouth.ac.uk>
@@ -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=vnvVyQjWGkGEF1mCIJRfa53GmkKdD4Dn3oQIOWmBeJc,2497
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/primitives.py,sha256=G4X5kPROgcO2hZf8YkYvviS5C2kPLXrlSerJUdD6Fog,22575
33
+ ncca/ngl/prim_data.py,sha256=Y-Y748_3-VgimuUlbengPyJvZIJQAPBFmnlMbsLPCVU,18853
34
+ ncca/ngl/primitives.py,sha256=YitjEsxDKo94mLeYclDOeG41ZVr9VM9TGhMCiKqGAgs,7651
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=RLgGmxTq4gzlMKdAfLrO3gtV8VUSP5WtQK4hyLV6waQ,3558
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.1.6.dist-info/WHEEL,sha256=NHRAbdxxzyL9K3IO2LjmlNqKSyPZnKv2BD16YYVKo18,79
63
- ncca_ngl-0.1.6.dist-info/METADATA,sha256=Mu1XM1Y4C8JaSvpNJVa_ZYSEJHiecu7jWdSSk6uemPQ,1596
64
- ncca_ngl-0.1.6.dist-info/RECORD,,
63
+ ncca_ngl-0.2.1.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
64
+ ncca_ngl-0.2.1.dist-info/METADATA,sha256=DvVhD66ulcT-u9WQEmfkzZtGy2iaQstB_9dEM_xK_Xo,1596
65
+ ncca_ngl-0.2.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.8.14
2
+ Generator: uv 0.8.24
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any