Skip to main content

An obj model loader for Python

Project description

PyObjLoader

An obj model loader for python. Currently will only return a numpy array of vertices containing position, uv, and normals.

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

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']

Attribute names will always be some combination of 'in_position', 'in_uv', and 'in_normal'. Possible cominations 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)])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyobjloader-0.0.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyobjloader-0.0.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file pyobjloader-0.0.4.tar.gz.

File metadata

  • Download URL: pyobjloader-0.0.4.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for pyobjloader-0.0.4.tar.gz
Algorithm Hash digest
SHA256 2b6606c8a7056fa5d7c6d1aa2ac385c9591046cc2a6d7d4a5afab93a1ebe0bf4
MD5 3c85ce7a937b62c67d7a6dbdb4b2d16a
BLAKE2b-256 35af24fe799f4fd71c7ad8a71a35bdc137c7fe8b939328e90c6414ed3dd5a804

See more details on using hashes here.

File details

Details for the file pyobjloader-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pyobjloader-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for pyobjloader-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4d16055562c25f539ed51f6eb042b5422eec2ee47e0a08bde963f56d3625a0c4
MD5 7a5fdbde51bbaa423871896448000394
BLAKE2b-256 7b1116e0aecf5907dec63c9330d038906baabb7fae3df81bde97c7d02ba56eba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page