All Projects β†’ pywavefront β†’ Pywavefront

pywavefront / Pywavefront

Licence: bsd-3-clause
Python library for importing Wavefront .obj files

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Labels

Projects that are alternatives of or similar to Pywavefront

Tinyobjloader
Tiny but powerful single file wavefront obj loader
Stars: ✭ 2,363 (+1150.26%)
Mutual labels:  3d, loader
Aframe
πŸ…°οΈ web framework for building virtual reality experiences.
Stars: ✭ 13,428 (+7004.76%)
Mutual labels:  3d
Visvis
Visvis - the object oriented approach to visualization
Stars: ✭ 180 (-4.76%)
Mutual labels:  3d
Babylonhx
Port of Babylon.js 3D engine to Haxe.
Stars: ✭ 182 (-3.7%)
Mutual labels:  3d
Vxr
General purpose engine written in C++ with emphasis on materials rendering (PBR, clear coat, anisotropy, iridescence)
Stars: ✭ 181 (-4.23%)
Mutual labels:  3d
Awesome Webgpu
😎 Curated list of awesome things around WebGPU ecosystem.
Stars: ✭ 182 (-3.7%)
Mutual labels:  3d
Material Ui Image
Material style image with loading animation
Stars: ✭ 178 (-5.82%)
Mutual labels:  loader
Pixel2meshplusplus
Pixel2Mesh++: Multi-View 3D Mesh Generation via Deformation. In ICCV2019.
Stars: ✭ 188 (-0.53%)
Mutual labels:  3d
Vu
Virtual Universe 3D Engine
Stars: ✭ 183 (-3.17%)
Mutual labels:  3d
Purs Loader
PureScript loader for webpack
Stars: ✭ 182 (-3.7%)
Mutual labels:  loader
I3s Spec
This repository hosts the specification for Scene Layers which are containers for arbitrarily large amounts of geographic data. The delivery and persistence model for Scene Layers, referred to as Indexed 3d Scene Layer (I3S) and Scene Layer Package (SLPK) respectively, are specified.
Stars: ✭ 182 (-3.7%)
Mutual labels:  3d
Robot Gui
A three.js based 3D robot interface.
Stars: ✭ 181 (-4.23%)
Mutual labels:  3d
Cq Editor
CadQuery GUI editor based on PyQT
Stars: ✭ 183 (-3.17%)
Mutual labels:  3d
Flextgl
OpenGL and Vulkan header and loader generator.
Stars: ✭ 180 (-4.76%)
Mutual labels:  loader
Lambdacube Edsl
Previous version of LambdaCube 3D as Embedded Domain Specific Language in Haskell. Check the latest system:
Stars: ✭ 186 (-1.59%)
Mutual labels:  3d
Euc
A software rendering crate that lets you write shaders with Rust
Stars: ✭ 180 (-4.76%)
Mutual labels:  3d
Satin
A 3D Graphics Framework built on Apple's Metal
Stars: ✭ 182 (-3.7%)
Mutual labels:  3d
React Redux Webpack Starter
Learning react
Stars: ✭ 189 (+0%)
Mutual labels:  loader
Webpack2 Lessons
πŸ“–γ€Šwebpack2 εŒ…ζ•™δΈεŒ…δΌšγ€‹
Stars: ✭ 187 (-1.06%)
Mutual labels:  loader
Ocskeleton
[OCSkeleton] - Make your loading view a little difference.
Stars: ✭ 184 (-2.65%)
Mutual labels:  loader

pypi CircleCI

preview

PyWavefront

PyWavefront reads Wavefront 3D object files (something.obj, something.obj.gz and something.mtl) and generates interleaved vertex data for each material ready for rendering.

  • Python 3.4+ is supported in 1.x versions
  • Python 2.7 is supported in 0.x versions

A simple (optional) visualization module is also provided for rendering the object(s). The interleaved data can also be used by more modern renderers thought VBOs or VAOs.

Currently the most commonly used features in the specification has been implemented:

  • Positions
  • Texture Coordinates
  • Normals
  • Vertex Color
  • Material parsing
  • Texture and texture parameters

We currently don't support parameter space vertices, line elements or smoothing groups. Create an issue or pull request on github if needed features are missing.

The package is on pypi or can be cloned on github.

pip install pywavefront

Also check out the roadmap for future plans.

Usage

Basic example loading an obj file:

import pywavefront
scene = pywavefront.Wavefront('something.obj')

A more complex example

  • strict (Default: False) will raise an exception if unsupported features are found in the obj or mtl file
  • encoding (Default: utf-8) of the obj and mtl file(s)
  • create_materials (Default: False) will create materials if mtl file is missing or obj file references non-existing materials
  • collect_faces (Default: False) will collect triangle face data for every mesh. In case faces with more than three vertices are specified they will be triangulated. See the documentation of ObjParser#consume_faces() in obj.py.
  • parse (Default: True) decides if parsing should start immediately.
  • cache (Default: False) writes the parsed geometry to a binary file for faster loading in the future
import pywavefront
scene = pywavefront.Wavefront('something.obj', strict=True, encoding="iso-8859-1", parse=False)
scene.parse()  # Explicit call to parse() needed when parse=False

# Iterate vertex data collected in each material
for name, material in scene.materials.items():
    # Contains the vertex format (string) such as "T2F_N3F_V3F"
    # T2F, C3F, N3F and V3F may appear in this string
    material.vertex_format
    # Contains the vertex list of floats in the format described above
    material.vertices
    # Material properties
    material.diffuse
    material.ambient
    material.texture
    # ..

Binary Cache

When cache=True the interleaved vertex data is written as floats to a .bin file after the file is loaded. A json file is also generated describing the contents of the binary file. The binary file will be loaded the next time we attempt to load the obj file reducing the loading time significantly.

Tests have shown loading time reduction by 10 to 100 times depending on the size and structure of the original obj file.

Loading myfile.obj will generate the following files in the same directory.

myfile.obj.bin
myfile.obj.json

Json file example:

{
  "created_at": "2018-07-16T14:28:43.451336",
  "version": "0.1",
  "materials": [
    "lost_empire.mtl"
  ],
  "vertex_buffers": [
    {
      "material": "Stone",
      "vertex_format": "T2F_N3F_V3F",
      "byte_offset": 0,
      "byte_length": 5637888
    },
    {
      "material": "Grass",
      "vertex_format": "T2F_N3F_V3F",
      "byte_offset": 5637888,
      "byte_length": 6494208
    }
  ]
}

These files will not be recreated until you delete them. The bin file is also compressed with gzip to greatly reduce size.

Visualization

Pyglet is required to use the visualization module.

pip install pyglet

Example:

import pywavefront
from pywavefront import visualization

[create a window and set up your OpenGl context]
obj = pywavefront.Wavefront('something.obj')

[inside your drawing loop]
visualization.draw(obj)

Logging

The default log level is ERROR. This is configurable including overriding the formatter.

import logging
import pywavefront

pywavefront.configure_logging(
    logging.DEBUG,
    formatter=logging.Formatter('%(name)s-%(levelname)s: %(message)s')
)

Examples

The examples directory contains some basic examples using the visualization module and further instructions on how to run them.

Generating a Wavefront file with Blender

The following presumes you are using Blender to generate your mesh:

  • Using Blender, create a mesh with a UV-mapped texture. The UV-mapping is important! If it is working properly, you will see the texture applied within Blender's 3d view.
  • Export the mesh from Blender using the Wavefront format, including normals.
  • Reference your *.obj file as in the pywavefront example above.

Tests

All tests can be found in the tests directory. To run the tests:

# Install pywavefront in develop mode
python setup.py develop

# Install required packages for running tests
pip install -r test-requirements.txt

# Run all tests
pytest

# Optionally specific tests modules can be runned separately
pytest tests/test_parser.py

Community

PyWavefront Discord server : https://discord.gg/h3Rh4QN

Owners & Maintainers

Contributors

In alphabetical order:

Project History

PyWavefront was originally started by @greenmoss (Kurt Yoder) in 2013. He was the sole maintainer of the project until February 2019 when the PyWavefront Maintainers organization was created adding @einarf (Einar Forselv) as an additional owner and maintainer of the project.

License

PyWavefront is BSD-licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].