Skip to content

Commit b5828c5

Browse files
committed
Docs: Clean up geometry docs
1 parent 2617244 commit b5828c5

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

docs/user_guide/geometry.rst

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11

2+
Creating Geometry
3+
=================
4+
5+
In order to render something to the screen we need geometry as vertex arrays.
6+
7+
We have the following options:
8+
9+
* Using the :py:mod:`demosys.geometry` module (or extend the geometry module)
10+
* Loading scenes/meshes from file using the supported file formats (or create new loaders of other formats)
11+
* Generating your own geometry programmatically
12+
213
The geometry module
3-
===================
14+
-------------------
415

516
The ``demosys.geometry`` module currently provides some simple
617
functions to generate VAOs for simple things.
@@ -12,27 +23,32 @@ Examples:
1223
from demosys import geometry
1324
# Create a fullscreen quad for overing the entire screen
1425
vao = geometry.quad_fs()
26+
1527
# Create a 1 x 1 quad on the xy plane
1628
vao = geometry.quad_2f(with=1.0, height=1.0)
29+
1730
# Create a unit cube
1831
vao = geometry.cube(1.0, 1.0, 1.0)
32+
1933
# Create a bounding box
2034
vao = geometry.bbox()
35+
2136
# Create a sphere
2237
vao = geometry.sphere(radius=0.5, sectors=32, rings=16)
38+
2339
# Random 10.000 random points in 3d
2440
vao = geometry.points_random_3d(10_000)
2541
2642
.. Note:: Improvements or suggestions can be made by through pull
2743
requests or issues on github.
2844

29-
See the ``geometry`` reference for more info.
45+
See the :py:mod:`demosys.geometry` reference for more info.
3046

3147
Scene/Mesh File Formats
3248
-----------------------
3349

3450
The ``demosys.scene.loaders`` currently support loading
35-
wavefront obj files and gltf.
51+
wavefront obj files and gltf 2.0 files.
3652

3753
You can create your own scene loader by adding the loader
3854
class to ``SCENE_LOADERS``.
@@ -49,8 +65,13 @@ Generating Custom Geometry
4965

5066
To efficiently generate geometry in Python we must avoid as much memory
5167
allocation as possible. If performance doesn't matter, then take this
52-
section lightly. Lbraries like ``numpy`` can also be used to generate
53-
geometry.
68+
section lightly.
69+
70+
There are many lbraries out there such as ``numpy`` capable of generating
71+
geometry fairly efficiently. Here we mainly focus on creating it ourselves
72+
using pure python code. We're also using the :py:class:`demosys.opengl.vao.VAO`
73+
for vertex buffer construction. This can easily be translated into using
74+
``moderngl.VertexArray`` directly if needed.
5475

5576
The naive way of generating geometry would probably look something like this:
5677

@@ -75,8 +96,7 @@ The naive way of generating geometry would probably look something like this:
7596
7697
This works perfectly fine, but we allocate a new list for every iteration
7798
and pyrr internally creates a numpy array. The ``points`` list will also
78-
have to dynamically expand. This gets exponentially more ugly as the ``count``
79-
value increases.
99+
have to dynamically expand. This gets more ugly as the ``count`` value increases.
80100

81101
We move on to version 2:
82102

@@ -94,7 +114,7 @@ We move on to version 2:
94114
95115
points_data = numpy.array(points, dtype=numpy.float32)
96116
97-
This version is orders of magnitude faster because we don't allocate memory
117+
This version is at least and order of magnitude faster because we don't allocate memory
98118
in the loop. It has one glaring flaw. It's **not a very pleasant read**
99119
even for such simple task, and it will not get any better if we add more complexity.
100120

@@ -114,7 +134,7 @@ Let's move on to version 3:
114134
115135
Using generators in Python like this is much a cleaner way. We also take
116136
advantage of numpy's ``fromiter()`` that basically slurps up all the
117-
numbers we emit with yield into its internal buffers. By also telling
137+
numbers we yield into its internal buffers. By also telling
118138
numpy what the final size of the buffer will be using the ``count``
119139
parameter, it will pre-allocate this not having to dynamically increase
120140
its internal buffer.

0 commit comments

Comments
 (0)