PyObjLoader
An obj model loader for python. Ideal for 3D data and graphics. Includes object and group trees, and automatic normal, tangent, and bitangent calculations.
Setup
Run the install command.
pip install pyobjloader
Import
Import the load function
from pyobjloader import load_model
Use
To get the numpy array of vertices, first place the .obj somewhere in your project file (example shown)
project
│ main.py
│ my_model_directory
└─── my_model.obj
Then pass the file path into the load function
model = load_model('my_model_directory/my_model.obj')
vertex_data = model.vertex_data
Examples for how to access more data from the model are in the github examples folder.
Format
The format of the vertex data for an obj is stored in the model:
# ModernGL Specifications
vertex_format = model.format # ie. '3f 2f 3f'
vertex_attribs = model.attribs # ie. ['in_position', 'in_uv', 'in_normal']
Possible attributes include ['in_position', 'in_uv', 'in_normal'] and ['in_position', 'in_normal'] (Normals are calculated if not given)
Example with ModernGL
Here is an example VAO made with ModernGL and PyObjLoader
# Make sure you have a context and shader program (see moderngl docs)
ctx = ...
program = ...
# Load the model using pyobjloader
model = load_model('my_model_directory/my_model')
vertex_data = model.vertex_data
# Make a vertex buffer object with the vertex data
vbo = ctx.buffer(vertex_data)
# Create a vertex array object
vao = ctx.vertex_data(program, [(vbo, model.format, *model.attribs)])
Metadata
Release files for pyobjloader 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyobjloader-0.0.7.tar.gz | 5.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyobjloader-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / pyobjloader-0.0.7.tar.gz
| Download URL | pyobjloader-0.0.7.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61d8fe20ff8a48524bbac63dd7049153238d8fd5a63fffa0d0e16d9f43ab8d9d
|
|
BLAKE2b-256 checksum How to use checksums |
2e028ef7aac10e2ca883ec95f09d686cdd51786af46a3cfc86a67cc4b8abd6fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.13.0
|
Release files / pyobjloader-0.0.7-py3-none-any.whl
| Download URL | pyobjloader-0.0.7-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df69797cc3883a8cf830c2e0f1d63a7cce2528412e4f28d429477ca2fee03374
|
|
BLAKE2b-256 checksum How to use checksums |
5cfff06973d43ae913e1346ead7ab44d3ee8be567695b302768b40fad08eee8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.13.0
|