ncca-ngl 0.2.1__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/prim_data.py CHANGED
@@ -21,6 +21,14 @@ class Prims(enum.Enum):
21
21
  TEAPOT = "teapot"
22
22
  TETRAHEDRON = "tetrahedron"
23
23
  TROLL = "troll"
24
+ SPHERE = "sphere"
25
+ TORUS = "torus"
26
+ LINE_GRID = "line_grid"
27
+ TRIANGLE_PLANE = "triangle_plane"
28
+ CONE = "cone"
29
+ CAPSULE = "capsule"
30
+ CYLINDER = "cylinder"
31
+ DISK = "disk"
24
32
 
25
33
 
26
34
  def _circle_table(n: int) -> np.ndarray:
ncca/ngl/primitives.py CHANGED
@@ -47,51 +47,62 @@ class Primitives:
47
47
  _primitives: Dict[str, _primitive] = {}
48
48
  _loaded: bool = False
49
49
 
50
+ @classmethod
51
+ def create(cls, type: str, name: str, *args: object, **kwargs: object) -> None:
52
+ """
53
+ Creates and stores a primitive object of the specified type from :-
54
+ Prims.SPHERE : (radius: float, precision: int).
55
+ Prims.TORUS : (radius: float, tube_radius: float, precision: int).
56
+ Prims.LINE_GRID : (width: float, depth: float, steps: int).
57
+ Prims.TRIANGLE_PLANE : ( width: float, depth: float, w_p: int, d_p: int, v_n: Vec3).
58
+ Prims.CYLINDER : (radius: float, height: float, slices: int, stacks: int).
59
+ Prims.CAPSULE : (radius: float, height: float, slices: int, stacks: int).
60
+ Prims.CONE : (radius: float, height: float, slices: int, stacks: int).
61
+
62
+ Args:
63
+ type (str): The primitive type, typically from the Prims enum (e.g., Prims.SPHERE).
64
+ name (str): The name to associate with the created primitive.
65
+ *args: Positional arguments to pass to the primitive creation function (e.g., radius, precision).
66
+ **kwargs: Keyword arguments to pass to the primitive creation function.
67
+
68
+ Raises:
69
+ ValueError: If the primitive type is not recognized.
70
+
71
+ Example:
72
+ Primitives.create(Prims.SPHERE, "sphere", 0.3, 32)
73
+ Primitives.create(Prims.SPHERE, "sphere", radius=0.3, precision=32)
74
+ """
75
+ prim_methods = {
76
+ Prims.SPHERE: PrimData.sphere,
77
+ Prims.TORUS: PrimData.torus,
78
+ Prims.LINE_GRID: PrimData.line_grid,
79
+ Prims.TRIANGLE_PLANE: PrimData.triangle_plane,
80
+ Prims.CYLINDER: PrimData.cylinder,
81
+ Prims.DISK: PrimData.disk,
82
+ Prims.CAPSULE: PrimData.capsule,
83
+ Prims.CONE: PrimData.cone,
84
+ }
85
+ try:
86
+ method = prim_methods[type]
87
+ except KeyError:
88
+ raise ValueError(f"Unknown primitive: {name}")
89
+
90
+ cls._primitives[name] = _primitive(method(*args, **kwargs))
91
+
50
92
  @classmethod
51
93
  def load_default_primitives(cls) -> None:
52
94
  """Loads the default primitives from the PrimData directory."""
53
95
  logger.info("Loading default primitives...")
54
96
  if not cls._loaded:
55
97
  for p in Prims:
56
- prim_data = PrimData.primitive(p.value)
57
- prim = _primitive(prim_data)
58
- cls._primitives[p.value] = prim
98
+ try:
99
+ prim_data = PrimData.primitive(p.value)
100
+ prim = _primitive(prim_data)
101
+ cls._primitives[p.value] = prim
102
+ except Exception:
103
+ pass
59
104
  cls._loaded = True
60
105
 
61
- @classmethod
62
- def create_line_grid(cls, name: str, width: float, depth: float, steps: int) -> None:
63
- """
64
- Creates a line grid primitive.
65
-
66
- Args:
67
- name: The name of the primitive to create.
68
- width: The width of the grid.
69
- depth: The depth of the grid.
70
- steps: The number of steps in the grid.
71
- """
72
- # Convert the list to a NumPy array
73
- data_array = PrimData.line_grid(width, depth, steps)
74
- prim = _primitive(data_array)
75
- cls._primitives[name] = prim
76
-
77
- @classmethod
78
- def create_triangle_plane(cls, name: str, width: float, depth: float, w_p: int, d_p: int, v_n: Vec3) -> None:
79
- """
80
- Creates a triangle plane primitive.
81
-
82
- Args:
83
- name: The name of the primitive.
84
- width: The width of the plane.
85
- depth: The depth of the plane.
86
- w_p: The number of width partitions.
87
- d_p: The number of depth partitions.
88
- v_n: The normal vector for the plane.
89
- """
90
-
91
- data_array = PrimData.triangle_plane(width, depth, w_p, d_p, v_n)
92
- prim = _primitive(data_array)
93
- cls._primitives[name] = prim
94
-
95
106
  @classmethod
96
107
  def draw(cls, name: Union[str, Prims]) -> None:
97
108
  """
@@ -108,112 +119,3 @@ class Primitives:
108
119
  except KeyError:
109
120
  logger.error(f"Failed to draw primitive {key}")
110
121
  return
111
-
112
- @classmethod
113
- def create_sphere(cls, name: str, radius: float, precision: int) -> None:
114
- """
115
- Creates a sphere primitive.
116
-
117
- Args:
118
- name: The name of the primitive.
119
- radius: The radius of the sphere.
120
- precision: The precision of the sphere (number of slices).
121
- """
122
-
123
- data_array = PrimData.sphere(radius, precision)
124
- prim = _primitive(data_array)
125
- cls._primitives[name] = prim
126
-
127
- @classmethod
128
- def create_cone(cls, name: str, base: float, height: float, slices: int, stacks: int) -> None:
129
- """
130
- Creates a cone primitive.
131
-
132
- Args:
133
- name: The name of the primitive.
134
- base: The radius of the cone's base.
135
- height: The height of the cone.
136
- slices: The number of divisions around the cone.
137
- stacks: The number of divisions along the cone's height.
138
- """
139
- data_array = PrimData.cone(base, height, slices, stacks)
140
- prim = _primitive(data_array)
141
- cls._primitives[name] = prim
142
-
143
- @classmethod
144
- def create_capsule(cls, name: str, radius: float, height: float, precision: int) -> None:
145
- """
146
- Creates a capsule primitive.
147
- The capsule is aligned along the y-axis.
148
- It is composed of a cylinder and two hemispherical caps.
149
- based on code from here https://code.google.com/p/rgine/source/browse/trunk/RGine/opengl/src/RGLShapes.cpp
150
- and adapted
151
-
152
- Args:
153
- name: The name of the primitive.
154
- radius: The radius of the capsule.
155
- height: The height of the capsule.
156
- precision: The precision of the capsule.
157
- """
158
-
159
- data_array = PrimData.capsule(radius, height, precision)
160
- prim = _primitive(data_array)
161
- cls._primitives[name] = prim
162
-
163
- @classmethod
164
- def create_cylinder(cls, name: str, radius: float, height: float, slices: int, stacks: int) -> None:
165
- """
166
- Creates a cylinder primitive.
167
- The cylinder is aligned along the y-axis.
168
- This method generates the cylinder walls, but not the top and bottom caps.
169
-
170
- Args:
171
- name: The name of the primitive.
172
- radius: The radius of the cylinder.
173
- height: The height of the cylinder.
174
- slices: The number of slices.
175
- stacks: The number of stacks.
176
- """
177
-
178
- data_array = PrimData.cylinder(radius, height, slices, stacks)
179
- prim = _primitive(data_array)
180
- cls._primitives[name] = prim
181
-
182
- @classmethod
183
- def create_disk(cls, name: str, radius: float, slices: int) -> None:
184
- """
185
- Creates a disk primitive.
186
-
187
- Args:
188
- name: The name of the primitive.
189
- radius: The radius of the disk.
190
- slices: The number of slices to divide the disk into.
191
- """
192
-
193
- data_array = PrimData.disk(radius, slices)
194
- prim = _primitive(data_array)
195
- cls._primitives[name] = prim
196
-
197
- @classmethod
198
- def create_torus(
199
- cls,
200
- name: str,
201
- minor_radius: float,
202
- major_radius: float,
203
- sides: int,
204
- rings: int,
205
- ) -> None:
206
- """
207
- Creates a torus primitive.
208
-
209
- Args:
210
- name: The name of the primitive.
211
- minor_radius: The minor radius of the torus.
212
- major_radius: The major radius of the torus.
213
- sides: The number of sides for each ring.
214
- rings: The number of rings for the torus.
215
- """
216
-
217
- data_array = PrimData.torus(minor_radius, major_radius, sides, rings)
218
- prim = _primitive(data_array)
219
- cls._primitives[name] = prim
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ncca-ngl
3
- Version: 0.2.1
3
+ Version: 0.2.2
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>
@@ -30,8 +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/prim_data.py,sha256=Y-Y748_3-VgimuUlbengPyJvZIJQAPBFmnlMbsLPCVU,18853
34
- ncca/ngl/primitives.py,sha256=YitjEsxDKo94mLeYclDOeG41ZVr9VM9TGhMCiKqGAgs,7651
33
+ ncca/ngl/prim_data.py,sha256=sBynXeAfVtYXK7dkdLYELo0VIbN1lK1KZ8KMmCWzjBA,19047
34
+ ncca/ngl/primitives.py,sha256=pThdSWLv7jJa9weBVOXhRgTfVVH54AWCbsDFCEI1YLg,4841
35
35
  ncca/ngl/pyside_event_handling_mixin.py,sha256=L8obXeTp-g2Va2eXyd1hnmSp-sY7p4GX6EcFYRnH1F4,10588
36
36
  ncca/ngl/quaternion.py,sha256=agmbW8i125FyLOV2Z9SpTY5yQwmnnm0rxQawwHqq1YI,3858
37
37
  ncca/ngl/random.py,sha256=wX1R2rMpb76TP4rk44NUp5XoVuMisH9d-eBG5kFBZsM,5579
@@ -60,6 +60,6 @@ ncca/ngl/vec3.py,sha256=ntgqB3sc_jzcGO5vlHKgDqloOoMkykVcWPxpYdWFy5Q,12449
60
60
  ncca/ngl/vec3_array.py,sha256=fLRC8k0TwcaU7CnR2GmJ0prud4dcvvUX0JTbQH_2W3Y,3535
61
61
  ncca/ngl/vec4.py,sha256=95b7yr82JtC3FqVDC8Hwn3wzPmVzSYTDCR1A6h_w9RM,6884
62
62
  ncca/ngl/vec4_array.py,sha256=PSJXfG0g2AT4oQCLHiVAP6EC5n7vMXRQy0N1rGvv1iw,3426
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,,
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,,