tinyobjloader 0.1__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tinyobjloader-2.0.0/LICENSE +42 -0
- tinyobjloader-2.0.0/MANIFEST.in +20 -0
- tinyobjloader-2.0.0/PKG-INFO +278 -0
- tinyobjloader-2.0.0/README.md +556 -0
- tinyobjloader-2.0.0/pyproject.toml +52 -0
- tinyobjloader-2.0.0/python/README.md +251 -0
- tinyobjloader-2.0.0/python/src/tobj_py_ext.inc +139 -0
- tinyobjloader-2.0.0/python/src/tobj_py_load.inc +922 -0
- tinyobjloader-2.0.0/python/src/tobj_py_stream.inc +440 -0
- tinyobjloader-2.0.0/python/src/tobj_python.c +1236 -0
- tinyobjloader-2.0.0/python/tinyobjloader/__init__.py +99 -0
- tinyobjloader-2.0.0/python/tinyobjloader/_api.py +937 -0
- tinyobjloader-2.0.0/python/tinyobjloader/_ext.py +333 -0
- tinyobjloader-2.0.0/python/tinyobjloader/py.typed +0 -0
- tinyobjloader-2.0.0/setup.py +85 -0
- tinyobjloader-2.0.0/tests/python/README.md +27 -0
- tinyobjloader-2.0.0/tests/python/benchmarks/bench_load.py +150 -0
- tinyobjloader-2.0.0/tests/python/pyproject.toml +19 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/__init__.py +0 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/_util.py +19 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/test_benchmark.py +73 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/test_errors.py +62 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/test_ext.py +177 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/test_load.py +233 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/test_materials.py +108 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/test_no_numpy.py +106 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/test_polish.py +92 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/test_stream.py +177 -0
- tinyobjloader-2.0.0/tests/python/tinyobjloader_tests/test_threads.py +35 -0
- tinyobjloader-2.0.0/tiny_obj_c.c +1326 -0
- tinyobjloader-2.0.0/tiny_obj_c.h +402 -0
- tinyobjloader-2.0.0/tiny_obj_c_impl.inc +2581 -0
- tinyobjloader-2.0.0/tiny_obj_c_pub.inc +299 -0
- tinyobjloader-2.0.0/tinyobjloader.egg-info/SOURCES.txt +48 -0
- tinyobjloader-2.0.0/tobj_core.inc +981 -0
- tinyobjloader-2.0.0/tobj_mtlx.c +1082 -0
- tinyobjloader-2.0.0/tobj_mtlx.h +91 -0
- tinyobjloader-2.0.0/tobj_read_real.inc +204 -0
- tinyobjloader-2.0.0/tobj_skel.c +452 -0
- tinyobjloader-2.0.0/tobj_skel.h +58 -0
- tinyobjloader-2.0.0/tobj_subd.c +694 -0
- tinyobjloader-2.0.0/tobj_subd.h +79 -0
- tinyobjloader-2.0.0/tobj_tess.c +324 -0
- tinyobjloader-2.0.0/tobj_tess.h +80 -0
- tinyobjloader-2.0.0/tobj_tess_impl.inc +463 -0
- tinyobjloader-2.0.0/tobj_tess_pub.inc +56 -0
- tinyobjloader-2.0.0/tobj_write.c +182 -0
- tinyobjloader-2.0.0/tobj_write.h +51 -0
- tinyobjloader-2.0.0/tobj_write_core.inc +35 -0
- tinyobjloader-2.0.0/tobj_write_real.inc +549 -0
- tinyobjloader-0.1/PKG-INFO +0 -73
- tinyobjloader-0.1/README.md +0 -61
- tinyobjloader-0.1/bindings.cc +0 -126
- tinyobjloader-0.1/setup.py +0 -28
- tinyobjloader-0.1/tiny_obj_loader.cc +0 -6
- tinyobjloader-0.1/tinyobjloader.egg-info/PKG-INFO +0 -73
- tinyobjloader-0.1/tinyobjloader.egg-info/SOURCES.txt +0 -8
- tinyobjloader-0.1/tinyobjloader.egg-info/dependency_links.txt +0 -1
- tinyobjloader-0.1/tinyobjloader.egg-info/top_level.txt +0 -1
- {tinyobjloader-0.1 → tinyobjloader-2.0.0}/setup.cfg +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2012-Present, Syoyo Fujita and many contributors.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
----------------------------------
|
|
24
|
+
|
|
25
|
+
mapbox/earcut.hpp
|
|
26
|
+
|
|
27
|
+
ISC License
|
|
28
|
+
|
|
29
|
+
Copyright (c) 2015, Mapbox
|
|
30
|
+
|
|
31
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
32
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
33
|
+
and this permission notice appear in all copies.
|
|
34
|
+
|
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
36
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
37
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
38
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
39
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
40
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
41
|
+
THIS SOFTWARE.
|
|
42
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
include pyproject.toml setup.py README.md LICENSE python/README.md
|
|
2
|
+
|
|
3
|
+
recursive-include python/tinyobjloader *.py py.typed
|
|
4
|
+
recursive-include python/src *.c *.h *.inc
|
|
5
|
+
recursive-include tests/python *.py *.toml README.md
|
|
6
|
+
|
|
7
|
+
# Loader core and sidecars (the .inc files are textual includes).
|
|
8
|
+
include tiny_obj_c.c tiny_obj_c.h tiny_obj_c_pub.inc tiny_obj_c_impl.inc
|
|
9
|
+
include tobj_core.inc tobj_read_real.inc tobj_write_core.inc tobj_write_real.inc
|
|
10
|
+
include tobj_tess.c tobj_tess.h tobj_tess_pub.inc tobj_tess_impl.inc
|
|
11
|
+
include tobj_subd.c tobj_subd.h
|
|
12
|
+
include tobj_skel.c tobj_skel.h
|
|
13
|
+
include tobj_mtlx.c tobj_mtlx.h
|
|
14
|
+
include tobj_write.c tobj_write.h
|
|
15
|
+
|
|
16
|
+
# Build/test state never belongs in the sdist.
|
|
17
|
+
prune tests/python/.pytest_cache
|
|
18
|
+
prune tinyobjloader.egg-info
|
|
19
|
+
prune python/build
|
|
20
|
+
global-exclude *.py[cod]
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tinyobjloader
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Tiny but powerful Wavefront OBJ loader (C11 core, numpy optional)
|
|
5
|
+
Author-email: Syoyo Fujita <syoyo@lighttransport.com>
|
|
6
|
+
License-Expression: MIT AND ISC
|
|
7
|
+
Project-URL: Homepage, https://github.com/tinyobjloader/tinyobjloader
|
|
8
|
+
Project-URL: Source, https://github.com/tinyobjloader/tinyobjloader
|
|
9
|
+
Keywords: obj,wavefront,3d,mesh,loader,tessellation,subdivision
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Topic :: Artistic Software
|
|
14
|
+
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: C
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: numpy
|
|
25
|
+
Requires-Dist: numpy>=1.26; extra == "numpy"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# tinyobjloader (Python)
|
|
29
|
+
|
|
30
|
+
Lightweight Python bindings for [tinyobjloader](https://github.com/tinyobjloader/tinyobjloader),
|
|
31
|
+
built directly on the pure-C11 loader with the CPython C API.
|
|
32
|
+
|
|
33
|
+
* **Stable ABI**: one `cp311-abi3` wheel runs on CPython 3.11 and newer.
|
|
34
|
+
* **Free-threaded**: dedicated `cp314t` wheels run without the GIL
|
|
35
|
+
(the module declares `Py_MOD_GIL_NOT_USED`), and parsing releases the GIL.
|
|
36
|
+
* **NumPy optional**: the extension returns zero-copy, read-only `memoryview`
|
|
37
|
+
objects; if numpy is importable they are wrapped in `numpy.ndarray` views.
|
|
38
|
+
NumPy is never needed to build or to load a mesh.
|
|
39
|
+
* **float32 or float64**, selected per load.
|
|
40
|
+
* Tessellation, subdivision tags, skeletons/skinning, MaterialX-in-MTL and a
|
|
41
|
+
canonical `.obj` writer ship in the same module.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python -m pip install tinyobjloader # add [numpy] to pull numpy in
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quick start
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import tinyobjloader as tobj
|
|
51
|
+
|
|
52
|
+
scene = tobj.load("model.obj") # float32 by default
|
|
53
|
+
print(scene.attrib.vertices.shape) # (num_vertices, 3)
|
|
54
|
+
|
|
55
|
+
mesh = scene.merged() # every shape's faces, one copy
|
|
56
|
+
print(mesh.triangles().shape) # (num_triangles, 3) vertex ids
|
|
57
|
+
print(mesh.shape_face_offsets) # faces of shape i: [o[i], o[i+1])
|
|
58
|
+
|
|
59
|
+
for shape in scene.shapes: # built lazily on first access
|
|
60
|
+
print(shape.name)
|
|
61
|
+
print(shape.mesh.indices.shape) # (num_corners, 3) int32
|
|
62
|
+
print(shape.mesh.num_face_vertices) # uint32 per face
|
|
63
|
+
print(shape.mesh.material_ids) # int32 per face, -1 = none
|
|
64
|
+
|
|
65
|
+
for material in scene.materials:
|
|
66
|
+
print(material.name, material.diffuse, material.diffuse_texname)
|
|
67
|
+
print(material.texopt["diffuse"].texture_resolution)
|
|
68
|
+
|
|
69
|
+
print(scene.warnings, scene.errors)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Loading from memory, with `.mtl` sidecars supplied in memory:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
with open("model.obj", "rb") as f:
|
|
76
|
+
obj = f.read()
|
|
77
|
+
mtl = {"model.mtl": open("model.mtl", "rb").read()}
|
|
78
|
+
scene = tobj.loads(obj, mtl=mtl) # bytes-like (no copy) or str
|
|
79
|
+
|
|
80
|
+
materials = tobj.parse_mtl("model.mtl") # a path-like object is accepted
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`mtl` accepts a single blob, a mapping of `name -> contents`, or a sequence of
|
|
84
|
+
`(name, contents)` pairs; contents may be bytes or `str` (encoded as UTF-8).
|
|
85
|
+
Names are matched case-insensitively against the `mtllib` line's basename.
|
|
86
|
+
|
|
87
|
+
## Streaming very large files
|
|
88
|
+
|
|
89
|
+
`load` keeps the whole scene in memory (about 12 bytes per face corner plus
|
|
90
|
+
the attribute arrays). For files that do not fit, `iter_load` parses a window
|
|
91
|
+
at a time, so memory stays proportional to `chunk_bytes`:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import numpy as np
|
|
95
|
+
|
|
96
|
+
for chunk in tobj.iter_load("huge.obj", chunk_bytes=64 << 20):
|
|
97
|
+
chunk.vertices # (n, 3) vertices defined in this window
|
|
98
|
+
chunk.vertex_offset # global id of chunk.vertices[0]
|
|
99
|
+
chunk.triangles() # (F, 3) global, 0-based vertex ids
|
|
100
|
+
chunk.material_ids # index into chunk.material_names (-1 = none)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The source may also be a binary file object such as `gzip.open(path, "rb")`.
|
|
104
|
+
Streaming covers `v`/`vn`/`vt`/`f`/`g`/`o`/`usemtl`; polygons are
|
|
105
|
+
fan-triangulated (the full loader's robust tessellator needs every vertex in
|
|
106
|
+
memory), and lines, points, materials, tags and skinning are only available
|
|
107
|
+
from `load`.
|
|
108
|
+
|
|
109
|
+
## Migrating from the pybind11 binding (2.0.0rc13 and earlier)
|
|
110
|
+
|
|
111
|
+
Releases up to `2.0.0rc13` shipped a pybind11 binding modelled on the C++
|
|
112
|
+
`ObjReader`. That API is gone; there is no compatibility shim.
|
|
113
|
+
|
|
114
|
+
| pybind11 binding | this package |
|
|
115
|
+
| --- | --- |
|
|
116
|
+
| `reader = tinyobjloader.ObjReader()`; `reader.ParseFromFile(path, config)` | `scene = tobj.load(path, ...)` |
|
|
117
|
+
| `reader.ParseFromString(obj_text, mtl_text)` | `tobj.loads(obj_text, mtl=mtl_text)` |
|
|
118
|
+
| `ObjReaderConfig().triangulate` / `.vertex_color` | `triangulate=` / `vertex_colors=` keywords |
|
|
119
|
+
| `ObjReaderConfig().mtl_search_path` | not needed: `.mtl` files resolve next to the `.obj`; pass `mtl=` to `loads` for in-memory sidecars |
|
|
120
|
+
| `reader.Valid()`, `reader.Error()`, `reader.Warning()` | failures raise `tobj.LoadError`; warnings in `scene.warnings` |
|
|
121
|
+
| `reader.GetAttrib()`, `GetShapes()`, `GetMaterials()` | `scene.attrib`, `scene.shapes`, `scene.materials` |
|
|
122
|
+
| `attrib.numpy_vertices()` (flat) | `scene.attrib.vertices` (`(N, 3)`, already a numpy view) |
|
|
123
|
+
| `mesh.numpy_indices()` (flat `v, vn, vt` triples) | `mesh.indices` (`(N, 3)` columns `v, vn, vt`), or `mesh.vertex_indices` |
|
|
124
|
+
| `mesh.indices[i].vertex_index` (`index_t` objects) | `mesh.indices[i, 0]` |
|
|
125
|
+
| `material.GetCustomParameter(key)` | `material.unknown_params[key]` |
|
|
126
|
+
|
|
127
|
+
Note the column order of `mesh.indices`: vertex, **normal**, texcoord, the
|
|
128
|
+
same as the C `tobj_index` struct.
|
|
129
|
+
|
|
130
|
+
## Numbers, arrays and lifetimes
|
|
131
|
+
|
|
132
|
+
`precision=32` (default) or `precision=64` picks the loader's float or double
|
|
133
|
+
family. Aliases (`"f4"`, `"f8"`, `"float64"`, ...) are accepted.
|
|
134
|
+
|
|
135
|
+
Every array is a **read-only zero-copy view** of the loaded scene:
|
|
136
|
+
|
|
137
|
+
* with numpy installed: a `numpy.ndarray` (`float32`/`float64`, `int32`,
|
|
138
|
+
`uint32`);
|
|
139
|
+
* without numpy: a one- or two-dimensional `memoryview` (empty arrays are
|
|
140
|
+
one-dimensional, since CPython cannot cast a zero-length view to a 2-D shape).
|
|
141
|
+
|
|
142
|
+
Views keep the loaded scene alive. `ObjScene.close()` only drops the scene's own
|
|
143
|
+
reference, so arrays you are still holding remain valid. Arrays are read-only by
|
|
144
|
+
design; copy them (e.g. `np.array(view)`) before mutating.
|
|
145
|
+
|
|
146
|
+
## Loading options
|
|
147
|
+
|
|
148
|
+
`load` / `loads` take keyword-only options (a misspelled one is a `TypeError`):
|
|
149
|
+
|
|
150
|
+
| option | default | meaning |
|
|
151
|
+
| --- | --- | --- |
|
|
152
|
+
| `precision` | `32` | `32` (float32) or `64` (float64) |
|
|
153
|
+
| `triangulate` | `True` | triangulate n-gons during the load |
|
|
154
|
+
| `vertex_colors` | `True` | store per-vertex RGB when present |
|
|
155
|
+
| `vertex_color_fallback` | `True` | fill vertices without color as white |
|
|
156
|
+
| `freeform` | `False` | parse and retain `curv`/`surf`/... records |
|
|
157
|
+
| `num_threads` | `None` | `None` uses the default (see Performance); `0` is the single-threaded verified core, `-1` all cores, `N` N threads |
|
|
158
|
+
| `limits` | `None` | a `tobj.Limits(max_vertices=..., max_input_bytes=..., ...)`; `0` fields keep the loader default |
|
|
159
|
+
|
|
160
|
+
`load_obj` / `load_obj_from_memory` (names from the 2.0.0 release candidates) still
|
|
161
|
+
work, emit a `DeprecationWarning`, and accept the old option names.
|
|
162
|
+
|
|
163
|
+
Errors raise `tinyobjloader.LoadError` with the loader's message; file loads
|
|
164
|
+
include the path (`I/O error (while loading 'model.obj')`), and non-fatal issues
|
|
165
|
+
land in `scene.warnings`.
|
|
166
|
+
|
|
167
|
+
## Extensions
|
|
168
|
+
|
|
169
|
+
### Tessellation
|
|
170
|
+
|
|
171
|
+
`tobj.tessellate(points, normal=None, assume_convex=False, force_fan=False)`
|
|
172
|
+
triangulates one polygon ring (concave, collinear, non-planar and
|
|
173
|
+
self-intersecting input included). `points` is an `(n, 3)` float array or a
|
|
174
|
+
sequence of triples. The result is a `TessResult` with ring-local indices:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
result = tobj.tessellate([(0,0,0), (1,0,0), (1,1,0), (0,1,0)])
|
|
178
|
+
result.indices # (num_triangles, 3) uint32
|
|
179
|
+
result.status # "ok" / "degenerate_besteffort" / "invalid" / "oom"
|
|
180
|
+
result.num_triangles
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Subdivision tags
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
scene = tobj.load("quad.obj", triangulate=False) # tags need raw faces
|
|
187
|
+
info = tobj.parse_subd(scene.shapes[0])
|
|
188
|
+
info.ok, info.errors, info.scheme, info.creases, info.corners, info.holes
|
|
189
|
+
info.canonical # bytes, canonical `t` lines
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Skeletons / skinning
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
info = tobj.parse_skel(scene)
|
|
196
|
+
info.joints[0].name, info.joints[0].parent, info.joints[0].bind
|
|
197
|
+
scene.attrib.skin_weights[0] # (vertex_id, {joint_id: weight})
|
|
198
|
+
scene.attrib.skin_weights.max_joint_id
|
|
199
|
+
scene.attrib.skel_lines
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### MaterialX-in-MTL
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
doc = tobj.parse_mtlx(open("model.mtl").read())
|
|
206
|
+
doc.materials[0].nodes, doc.materials[0].inputs, doc.materials[0].conns
|
|
207
|
+
xml = tobj.mtlx_render(open("model.mtl").read(), fmt="xml") # or "mtl", "dump"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Writing `.obj`
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
text = tobj.write_obj(scene) # bytes, canonical Wavefront .obj
|
|
214
|
+
tobj.write_obj(scene, "out.obj") # or straight to a file
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Only mesh topology is written (`v`, `vt`, `vn`, `g`, `usemtl`, `s`, `f`, plus
|
|
218
|
+
per-shape `t` lines); `.mtl` files, polylines and free-form geometry are not.
|
|
219
|
+
|
|
220
|
+
## Performance
|
|
221
|
+
|
|
222
|
+
Wheels are built with the loader's file features enabled:
|
|
223
|
+
|
|
224
|
+
* **mmap** file loads map the `.obj` instead of copying it into the heap, which
|
|
225
|
+
lowers peak memory for large scenes (POSIX; Windows falls back to stdio);
|
|
226
|
+
* **SIMD** newline scanning (x86 SSE2/AVX2, AArch64 NEON, scalar elsewhere);
|
|
227
|
+
* the **threaded prepass** is compiled in and stays opt-in at run time.
|
|
228
|
+
|
|
229
|
+
Choosing a loading mode for large files (`bench_load.py`, quad grid with
|
|
230
|
+
`vt`/`vn`, float32, x86_64 with all cores busy with another workload, so an
|
|
231
|
+
idle machine will be faster):
|
|
232
|
+
|
|
233
|
+
| mode | 156 MB file | 1.07 GB file | 11.3 GB file (173M triangles) | peak RSS |
|
|
234
|
+
| --- | --- | --- | --- | --- |
|
|
235
|
+
| `load(num_threads=0)` (default) | 4.2 s | 29.1 s | does not fit | ~10x file |
|
|
236
|
+
| `load(num_threads=-1)` | 1.6 s | 11.2 s | does not fit | ~4x file |
|
|
237
|
+
| `iter_load(chunk_bytes=64 MB)` | 1.0 s | 7.2 s | 74.9 s | ~380 MB, flat |
|
|
238
|
+
|
|
239
|
+
* `num_threads=0` runs the formally verified core, which keeps one 112-byte
|
|
240
|
+
record per vertex and face corner while it builds the scene.
|
|
241
|
+
* `num_threads=-1` / `N` uses the threaded dispatcher. It is faster and leaner
|
|
242
|
+
but it ignores `vw` skin weights and accepts some malformed input that the
|
|
243
|
+
verified core rejects, so it is not the default.
|
|
244
|
+
* `iter_load` never holds more than about one window, whatever the file size.
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
python tests/python/benchmarks/bench_load.py --size-mb 1000 --repeat 3
|
|
248
|
+
python tests/python/benchmarks/bench_load.py --size-mb 10000 --modes iter
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Fixtures are cached in `$TINYOBJ_BENCH_DIR` (default
|
|
252
|
+
`~/.cache/tinyobjloader-bench`); avoid a RAM-backed `/tmp` for multi-GB files.
|
|
253
|
+
Each mode runs in its own process so the reported peak RSS is its own.
|
|
254
|
+
`TINYOBJ_BENCH=1 pytest -q -s` runs a small load benchmark as a test.
|
|
255
|
+
|
|
256
|
+
## Free-threaded Python
|
|
257
|
+
|
|
258
|
+
On `cp314t` the module opts out of the GIL, and the parse itself
|
|
259
|
+
releases it on regular builds too, so loading from several threads scales. All
|
|
260
|
+
state lives in the returned scene object; the module keeps no globals.
|
|
261
|
+
|
|
262
|
+
## Building
|
|
263
|
+
|
|
264
|
+
Wheels are produced from the repository root:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
python -m build --wheel
|
|
268
|
+
# or: cibuildwheel --only cp311-manylinux_x86_64 .
|
|
269
|
+
cd tests/python && uv run --project . pytest -q
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The extension compiles `tiny_obj_c.c`, `tobj_tess.c`, `tobj_subd.c`,
|
|
273
|
+
`tobj_skel.c`, `tobj_mtlx.c` and `tobj_write.c`; there is no C++ or pybind11
|
|
274
|
+
dependency.
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
MIT (loader) and ISC (bundled tessellation-derived code). See `LICENSE`.
|