This is the code for the full python version of NGL the ncca graphics library.
More details soon as this is work in progress.
use
uv run pytest
To run tests,
uv run pytest --cov=src --cov-report=term-missing
For coverage reports.
VertexData: A simple data structure to hold vertex data for a VAO. It stores the data as a numpy array, the size of the data, and the drawing mode.AbstractVAO: An abstract base class for Vertex Array Objects (VAOs). It defines the interface for different VAO implementations, including methods for binding, drawing, setting data, and managing the VAO's lifecycle.
Face: A simple data structure for a mesh face, holding indices for vertices, UVs, and normals.BaseMesh: A base class for mesh geometry. It provides storage for vertices, normals, UVs, and faces, and includes methods for creating a VAO from the mesh data, calculating dimensions, and drawing the mesh.
BBox: Represents a 3D bounding box. It stores the center, dimensions, and extents of the box, and provides methods to calculate these values and retrieve the box's vertices and normals.
BezierCurve: A class for creating and evaluating Bézier curves. It stores control points and knots, and can calculate points on the curve using the Cox-de Boor algorithm.
FirstPersonCamera: Implements a first-person camera with movement, rotation, and projection matrix calculation. It handles mouse and keyboard input for camera control.
Image: A class for loading, saving, and manipulating images. It uses the Pillow library to handle different image formats and stores image data as a NumPy array.
ColoredFormatter: A custom logging formatter that adds color to log messages based on their severity level.setup_logger: A function to set up a logger with both file and console handlers.
Mat2: A 2x2 matrix class with support for identity, multiplication (matrix-matrix and matrix-vector), and conversion to a NumPy array.
Mat3: A 3x3 matrix class for 3D transformations. It includes methods for identity, zero, scale, rotation, transpose, inverse, and matrix multiplication.
Mat4: A 4x4 matrix class for 3D transformations. It supports creation of identity, zero, scale, translation, and rotation matrices, as well as matrix multiplication and inversion.
MultiBufferVAO: A VAO implementation that can manage multiple vertex buffers. This is useful for separating different types of vertex attributes (e.g., positions, colors, normals) into different buffers.
Obj: A class for loading and saving Wavefront OBJ files. It extendsBaseMeshand handles parsing of vertices, normals, UVs, and faces from an OBJ file, including support for negative indices.
Plane: Represents a mathematical plane in 3D space. It can be defined by three points or a normal and a point, and can calculate the distance from a point to the plane.
Prims: An enum of available primitive types.PrimData: A class that provides static methods to generate vertex data for various geometric primitives like spheres, cubes, and tori.
Primitives: A static class for creating and drawing pre-defined geometric primitives. It usesPrimDatato generate the vertex data andVAOFactoryto create VAOs for rendering.
PySideEventHandlingMixin: A mixin class for PySide6 applications that provides common event handling for mouse-based camera control (rotation, translation, zoom) and keyboard shortcuts.
Quaternion: A class for representing rotations using quaternions. It includes methods for converting from a rotation matrix, multiplication, normalization, and applying the rotation to a vector.
Random: A static class for generating random numbers and vectors. It provides methods to get random floats, integers, and vectors of different dimensions.
Shader: Represents a single OpenGL shader object (e.g., vertex, fragment). It handles loading source from a file, compiling the shader, and checking for errors.
ShaderLib: A singleton class that manages a library of shader programs. It provides a global point of access for loading, compiling, linking, and using shaders, as well as for setting uniform variables.
ShaderProgram: A wrapper for an OpenGL shader program. It manages attaching shaders, linking the program, and provides an interface for setting uniform variables.
SimpleIndexVAO: A VAO implementation that uses an index buffer for indexed drawing. This is more efficient for meshes where vertices are shared between multiple faces.
SimpleVAO: A basic VAO implementation that uses a single buffer for non-indexed drawing.
Text: A class for rendering text in OpenGL. It usesfreetype-pyto create a texture atlas of font glyphs and renders text using a geometry shader to create quads for each character.
Texture: A class for loading image files and creating OpenGL textures from them.
Transform: A class to represent a 3D transformation with position, rotation, and scale components. It can generate a transformation matrix based on a specified rotation order.
util.py: This module contains various utility functions for 3D math, includinglookAt,perspective,ortho, andfrustummatrix generation, as well asclampandlerpfunctions.
VAOFactory: A factory class for creating different types of VAOs. It allows for registering custom VAO creators and creating VAO instances by name.