Geometry Classes
Obj
Bases: MeshData
Load and save Wavefront OBJ geometry as CPU-side mesh data.
Source code in ncca/ngl/obj.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
add_face(face)
Append a face.
Source code in ncca/ngl/obj.py
146 147 148 | |
add_normal(normal)
Append a vertex normal.
Source code in ncca/ngl/obj.py
138 139 140 | |
add_uv(uv)
Append a texture coordinate.
Source code in ncca/ngl/obj.py
142 143 144 | |
add_vertex(vertex)
Append a vertex position.
Source code in ncca/ngl/obj.py
129 130 131 | |
add_vertex_colour(vertex, colour)
Append a vertex position and its colour.
Source code in ncca/ngl/obj.py
133 134 135 136 | |
from_file(fname)
classmethod
Create an Obj instance from a Wavefront file.
Source code in ncca/ngl/obj.py
122 123 124 125 126 127 | |
load(file)
Append geometry from an OBJ file and update its dimensions.
Source code in ncca/ngl/obj.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
save(filename)
Save valid CPU mesh data as a Wavefront OBJ file.
Source code in ncca/ngl/obj.py
150 151 152 153 154 155 156 157 158 | |
MeshData
CPU-side mesh geometry shared by rendering back ends.
Source code in ncca/ngl/mesh.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
__init__()
Create an empty CPU-side mesh.
Source code in ncca/ngl/mesh.py
28 29 30 31 32 33 34 35 36 37 38 | |
calc_dimensions()
Calculate extents and bounding box from the vertex positions.
Source code in ncca/ngl/mesh.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
is_triangular()
Return True when every face has exactly three vertices.
Source code in ncca/ngl/mesh.py
40 41 42 | |
triangle_vertex_data(*, flip_v=False)
Pack expanded triangle data as position, normal and UV float32 values.
Source code in ncca/ngl/mesh.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
validate()
Validate indices and optional vertex attributes.
Source code in ncca/ngl/mesh.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
Face
Indices for one polygon face.
Source code in ncca/ngl/mesh.py
12 13 14 15 16 17 18 | |
Primitives
A static class for creating and drawing primitives.
Source code in ncca/ngl/opengl/primitives.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
create(type, name, *args, **kwargs)
classmethod
Creates and stores a primitive object of the specified type.
Prims.SPHERE : (radius: float, precision: int). Prims.TORUS : (radius: float, tube_radius: float, precision: int). Prims.LINE_GRID : (width: float, depth: float, steps: int). Prims.TRIANGLE_PLANE : ( width: float, depth: float, w_p: int, d_p: int, v_n: Vec3). Prims.CYLINDER : (radius: float, height: float, slices: int, stacks: int). Prims.CAPSULE : (radius: float, height: float, slices: int, stacks: int). Prims.CONE : (radius: float, height: float, slices: int, stacks: int).
| Parameters: |
|
|---|
| Raises: |
|
|---|
Example
Primitives.create(Prims.SPHERE, "sphere", 0.3, 32) Primitives.create(Prims.SPHERE, "sphere", radius=0.3, precision=32)
Source code in ncca/ngl/opengl/primitives.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
draw(name)
classmethod
Draws the specified primitive.
| Parameters: |
|
|---|
Source code in ncca/ngl/opengl/primitives.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
load_default_primitives()
classmethod
Loads the default primitives from the PrimData directory.
Source code in ncca/ngl/opengl/primitives.py
113 114 115 116 117 118 119 120 121 122 123 124 125 | |
BaseMesh
Bases: MeshData
MeshData with the legacy OpenGL drawing API.
Source code in ncca/ngl/opengl/base_mesh.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
vao
property
Return the VAO owned by the compatibility renderer.
__init__()
Create an empty mesh with a legacy OpenGL renderer.
Source code in ncca/ngl/opengl/base_mesh.py
15 16 17 18 19 20 | |
create_vao(reset_vao=False)
Create the legacy VAO using the OpenGLMesh adapter.
Source code in ncca/ngl/opengl/base_mesh.py
40 41 42 43 44 45 46 | |
draw()
Draw if the VAO has been created, matching the old no-op behaviour.
Source code in ncca/ngl/opengl/base_mesh.py
48 49 50 51 52 | |
OpenGLMesh
Upload and draw a MeshData instance with an OpenGL VAO.
Source code in ncca/ngl/opengl/mesh.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
vao
property
Return the VAO after upload.
__init__(mesh, *, texture_id=0)
Store the CPU mesh and an optional borrowed texture ID.
Source code in ncca/ngl/opengl/mesh.py
13 14 15 16 17 | |
cleanup()
Release the VAO whilst an OpenGL context is current.
Source code in ncca/ngl/opengl/mesh.py
52 53 54 55 56 | |
draw()
Draw the uploaded mesh.
Source code in ncca/ngl/opengl/mesh.py
43 44 45 46 47 48 49 50 | |
upload(*, force=False)
Create the VAO, replacing an existing one only when requested.
Source code in ncca/ngl/opengl/mesh.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
PrimData
Static methods generating packed vertex data for primitive shapes.
Source code in ncca/ngl/prim_data.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 | |
capsule(radius, height, precision)
staticmethod
Creates a capsule primitive.
The capsule is aligned along the y-axis and is composed of a cylinder and two hemispherical caps. Based on code from https://code.google.com/p/rgine/source/browse/trunk/RGine/opengl/src/RGLShapes.cpp and adapted.
Source code in ncca/ngl/prim_data.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
cone(base, height, slices, stacks)
staticmethod
Creates a cone primitive.
| Parameters: |
|
|---|
Source code in ncca/ngl/prim_data.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
cylinder(radius, height, slices, stacks)
staticmethod
Creates a cylinder primitive.
The cylinder is aligned along the y-axis. This method generates the cylinder walls, but not the top and bottom caps.
Source code in ncca/ngl/prim_data.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
disk(radius, slices)
staticmethod
Creates a disk primitive.
| Parameters: |
|
|---|
Source code in ncca/ngl/prim_data.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
line_grid(width, depth, steps)
staticmethod
Creates a line grid primitive.
| Parameters: |
|
|---|
Source code in ncca/ngl/prim_data.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
primitive(name)
staticmethod
Load pre-generated vertex data for the named primitive.
Source code in ncca/ngl/prim_data.py
617 618 619 620 621 622 623 624 625 626 627 628 | |
sphere(radius, precision)
staticmethod
Creates a sphere primitive.
| Parameters: |
|
|---|
Source code in ncca/ngl/prim_data.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
torus(minor_radius, major_radius, sides, rings)
staticmethod
Creates a torus primitive.
| Parameters: |
|
|---|
Source code in ncca/ngl/prim_data.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 | |
triangle_plane(width, depth, w_p, d_p, v_n)
staticmethod
Creates a triangle plane primitive.
| Parameters: |
|
|---|
Source code in ncca/ngl/prim_data.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
Prims
Bases: Enum
Enum for the default primitives that can be loaded.
Source code in ncca/ngl/prim_data.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
prim_data_to_ri_points_polygons
Convert a packed numpy array of triangles to RenderMan PointsPolygons format.
Designed to work with the PrimData class outputs.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/util.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
Obj parse errors
Obj raises these rather than returning a sentinel value when a line of
the file will not parse.
ObjParseVertexError
Bases: Exception
Raised when a vertex line in an OBJ file cannot be parsed.
Source code in ncca/ngl/obj.py
9 10 | |
ObjParseNormalError
Bases: Exception
Raised when a normal line in an OBJ file cannot be parsed.
Source code in ncca/ngl/obj.py
13 14 | |
ObjParseUVError
Bases: Exception
Raised when a UV line in an OBJ file cannot be parsed.
Source code in ncca/ngl/obj.py
17 18 | |