Skip to main content

For parsing obj files to be suitable to feed to a vertex buffer.

Project description

.obj to vertex data

pypi version python versions python package passing

A spinning blahaj The above spinning blahaj was rendered in a browser with typescript, see at alternyxx.com/blahaj! The model can be found here.

Intended Usage

The program aims to make .obj files with triangle data, for example,

v 1 0 0
v 0 1 0
v 0 0 1

vn 0.577 0.577 0.577

f 1//1 2//2 3//3

to

1, 0, 0, 0.5777, 0.5777, 0.5777,
0, 1, 0, 0.5777, 0.5777, 0.5777,
0, 0, 1, 0.5777, 0.5777, 0.5777,

This is for parsing obj files to be suitable to feed to a vertex buffer. For most cases, it'd be better to just use an index buffer though. If your .obj file has faces with quads, which is usually the case, eg.

f 1/1/1 2/1/1 3/1/1 4/1/1

Then, you could change your vertex buffer accordingly to have 4 vertex coordinates in the case the graphics api you're using supports quads. Else, there is github.com/StefanJohnsen/TriangulateOBJ-App to triangulate quads in a .obj file which is what I did for the blahaj!

Installation

pip

Make sure Python and pip is installed. Python version needs to be >= 3.10. Then run

pip install vertexdata

Build

In case pip is blocked (happens to me), you can simply clone the repository and build from scratch. This should be especially trivial as the project has 0 dependancies.

git clone https://github.com/alternyxx/VertexData
cd VertexData
pip install .

Command Line Usage

Once installed, you can run

vertexdata obj_file {target_file}

to get vertex data in the target_file. By default, the program will generate all given vertex data, positions, textures and normals if given. To override this, you can pass in

vertexdata obj_file {target_file} -nvn -nvt

to only generate the positions of the vertices. For more information, run

vertexdata --help

Library

If you want to parse the vertices in this way in a python project, you can

import vertexdata as vtd

def main():
    vertex_parser = vtd.VertexParser(
        source, target_file, no_normal_data=true, no_texture_data=true
    )
    vertex_parser.parse()
    your_vertices_data = vertexparser.target.data

source can be a file which then you can do

vertexparser = vtd.VertexParser(
    source, target_file, file=true
)

If you don't need to output target as a file then you can pass an empty string. And, finally, there's the flags, no_normal_data and no_texture_data.

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

vertexdata-0.0.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

vertexdata-0.0.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file vertexdata-0.0.3.tar.gz.

File metadata

  • Download URL: vertexdata-0.0.3.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.0 Windows/11

File hashes

Hashes for vertexdata-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4d7d30c4494d2b634723c08400b254af6c9beaa1e1718d8c47a7289d227bdbf8
MD5 25df57f74f199b54b01289a3c0d37106
BLAKE2b-256 e44452f1b82b6fac1b8b3ec5733bb01a91bc732ec5eafbd58ba602cb574e7a2c

See more details on using hashes here.

File details

Details for the file vertexdata-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: vertexdata-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.0 Windows/11

File hashes

Hashes for vertexdata-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 28a067370fa43f2eb8debc71f1d3e09e50f2125f743b85329be21052609f1066
MD5 2c6e585e39f9620e4c99092cd6c06476
BLAKE2b-256 f0bfc8cfd6fdfcb22e86658cc44ab6322fbb6e45f43994532406b51e0ef40e7a

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