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 setup a directory containing the .obj

project
│ main.py
│ my_model_directory
└─── my_model.obj

Then pass the directory into the load function

model = load_model('my_model_directory')
vertex_array = model.vertex_array

Format

The format of the vertex array is as follows:

# ModernGL Specifications
vertex_format = '3f 2f 3f'
vertex_attribs = ['in_position', 'in_texcoord', 'in_normal']

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')
vertex_array = model.vertex_array

# Make a vertex buffer object with the vertex data
vbo = ctx.buffer(vertex_data)

# VBO Formatting
vertex_format = '3f 2f 3f'
vertex_attribs = ['in_position', 'in_texcoord', 'in_normal']

# Create a vertex array object
vao = ctx.vertex_array(program, [(vbo, vertex_format, *vertex_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.2.tar.gz (4.1 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.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyobjloader-0.0.2.tar.gz
  • Upload date:
  • Size: 4.1 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.2.tar.gz
Algorithm Hash digest
SHA256 be0a2069590a33c751d2981f3b2ef18b38124efa2009f68608de8473d14e8290
MD5 a204ddf0dfd591f5f1cab6d9956ce319
BLAKE2b-256 f4deae217ec4034fb7e7518b17efc60b20a0acce5181f3218111b507e37dd336

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyobjloader-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 64eedd0b7f8258848be9d8ef66b995f15590c73b822c3146d6b65c8a92f3326f
MD5 4d0335fe1811dbf494471f7027143298
BLAKE2b-256 c78ac1dee229c0ebff0580d36408a763956bcb0bd6ff20c9bd260eec54893f1b

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