tinymetabobjloader 2.0.0rc14.dev2__cp314-cp314-win_amd64.whl
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.
- python/LICENSE +21 -0
- python/Makefile +7 -0
- python/README.md +87 -0
- python/_version.py +4 -0
- python/bindings.cc +248 -0
- python/sample.py +138 -0
- python/tiny_obj_loader.cc +9 -0
- tinymetabobjloader-2.0.0rc14.dev2.dist-info/METADATA +469 -0
- tinymetabobjloader-2.0.0rc14.dev2.dist-info/RECORD +13 -0
- tinymetabobjloader-2.0.0rc14.dev2.dist-info/WHEEL +5 -0
- tinymetabobjloader-2.0.0rc14.dev2.dist-info/licenses/LICENSE +42 -0
- tinymetabobjloader-2.0.0rc14.dev2.dist-info/top_level.txt +2 -0
- tinyobjloader.cp314-win_amd64.pyd +0 -0
python/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2012-2019 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.
|
python/Makefile
ADDED
python/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# tinyobjloader, Wavefront .obj loader
|
|
2
|
+
|
|
3
|
+
`tinyobjloader` is a python wrapper for C++ wavefront .obj loader.
|
|
4
|
+
`tinyobjloader` is rather fast and feature rich than other pure python version of .obj loader.
|
|
5
|
+
|
|
6
|
+
## Requirements
|
|
7
|
+
|
|
8
|
+
* python 3.6+
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
You can install `tinyobjloader` with pip.
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
$ pip install tinyobjloader
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick tutorial
|
|
19
|
+
|
|
20
|
+
```py
|
|
21
|
+
import sys
|
|
22
|
+
import tinyobjloader
|
|
23
|
+
|
|
24
|
+
# Create reader.
|
|
25
|
+
reader = tinyobjloader.ObjReader()
|
|
26
|
+
|
|
27
|
+
filename = "cornellbox.obj"
|
|
28
|
+
|
|
29
|
+
# Load .obj(and .mtl) using default configuration
|
|
30
|
+
ret = reader.ParseFromFile(filename)
|
|
31
|
+
|
|
32
|
+
if ret == False:
|
|
33
|
+
print("Warn:", reader.Warning())
|
|
34
|
+
pint("Err:", reader.Error())
|
|
35
|
+
print("Failed to load : ", filename)
|
|
36
|
+
|
|
37
|
+
sys.exit(-1)
|
|
38
|
+
|
|
39
|
+
if reader.Warning():
|
|
40
|
+
print("Warn:", reader.Warning())
|
|
41
|
+
|
|
42
|
+
attrib = reader.GetAttrib()
|
|
43
|
+
print("attrib.vertices = ", len(attrib.vertices))
|
|
44
|
+
print("attrib.normals = ", len(attrib.normals))
|
|
45
|
+
print("attrib.texcoords = ", len(attrib.texcoords))
|
|
46
|
+
|
|
47
|
+
materials = reader.GetMaterials()
|
|
48
|
+
print("Num materials: ", len(materials))
|
|
49
|
+
for m in materials:
|
|
50
|
+
print(m.name)
|
|
51
|
+
print(m.diffuse)
|
|
52
|
+
|
|
53
|
+
shapes = reader.GetShapes()
|
|
54
|
+
print("Num shapes: ", len(shapes))
|
|
55
|
+
for shape in shapes:
|
|
56
|
+
print(shape.name)
|
|
57
|
+
print("num_indices = {}".format(len(shape.mesh.indices)))
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## More detailed usage
|
|
62
|
+
|
|
63
|
+
Please take a look at `python/sample.py` file in tinyobjloader git repo.
|
|
64
|
+
|
|
65
|
+
https://github.com/syoyo/tinyobjloader/blob/master/python/sample.py
|
|
66
|
+
|
|
67
|
+
## How to build
|
|
68
|
+
|
|
69
|
+
Using `cibuildwheel` is a recommended way to build a python module.
|
|
70
|
+
See $tinyobjloader/azure-pipelines.yml for details.
|
|
71
|
+
|
|
72
|
+
### Developer build
|
|
73
|
+
|
|
74
|
+
Assume pip is installed.
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
$ git clone https://github.com/tinyobjloader/tinyobjloader
|
|
78
|
+
$ cd tinyobjloader
|
|
79
|
+
$ python -m pip install .
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT(tinyobjloader) and ISC(mapbox earcut) license.
|
|
85
|
+
|
|
86
|
+
## TODO
|
|
87
|
+
* [ ] Writer saver
|
python/_version.py
ADDED
python/bindings.cc
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
#include <pybind11/pybind11.h>
|
|
2
|
+
#include <pybind11/stl.h>
|
|
3
|
+
#include <pybind11/numpy.h>
|
|
4
|
+
#include <cstring>
|
|
5
|
+
|
|
6
|
+
// Use double precision for better python integration.
|
|
7
|
+
#define TINYOBJLOADER_USE_DOUBLE
|
|
8
|
+
|
|
9
|
+
// define some helper functions for pybind11
|
|
10
|
+
#define TINY_OBJ_LOADER_PYTHON_BINDING
|
|
11
|
+
#include "../tiny_obj_loader.h"
|
|
12
|
+
|
|
13
|
+
namespace py = pybind11;
|
|
14
|
+
|
|
15
|
+
using namespace tinyobj;
|
|
16
|
+
|
|
17
|
+
PYBIND11_MODULE(tinyobjloader, tobj_module)
|
|
18
|
+
{
|
|
19
|
+
tobj_module.doc() = "Python bindings for TinyObjLoader.";
|
|
20
|
+
|
|
21
|
+
// register struct
|
|
22
|
+
py::class_<ObjReaderConfig>(tobj_module, "ObjReaderConfig")
|
|
23
|
+
.def(py::init<>())
|
|
24
|
+
.def_readwrite("triangulate", &ObjReaderConfig::triangulate);
|
|
25
|
+
|
|
26
|
+
// py::init<>() for default constructor
|
|
27
|
+
py::class_<ObjReader>(tobj_module, "ObjReader")
|
|
28
|
+
.def(py::init<>())
|
|
29
|
+
.def("ParseFromFile", &ObjReader::ParseFromFile, py::arg("filename"), py::arg("option") = ObjReaderConfig())
|
|
30
|
+
.def("ParseFromString", &ObjReader::ParseFromString, py::arg("obj_text"), py::arg("mtl_text"), py::arg("option") = ObjReaderConfig())
|
|
31
|
+
.def("Valid", &ObjReader::Valid)
|
|
32
|
+
.def("GetAttrib", &ObjReader::GetAttrib)
|
|
33
|
+
.def("GetShapes", &ObjReader::GetShapes)
|
|
34
|
+
.def("GetMaterials", &ObjReader::GetMaterials)
|
|
35
|
+
.def("Warning", &ObjReader::Warning)
|
|
36
|
+
.def("Error", &ObjReader::Error);
|
|
37
|
+
|
|
38
|
+
py::class_<attrib_t>(tobj_module, "attrib_t")
|
|
39
|
+
.def(py::init<>())
|
|
40
|
+
.def_readonly("vertices", &attrib_t::vertices)
|
|
41
|
+
.def_readonly("vertex_weights", &attrib_t::vertex_weights)
|
|
42
|
+
.def_readonly("skin_weights", &attrib_t::skin_weights)
|
|
43
|
+
.def_readonly("normals", &attrib_t::normals)
|
|
44
|
+
.def_readonly("texcoords", &attrib_t::texcoords)
|
|
45
|
+
.def_readonly("colors", &attrib_t::colors)
|
|
46
|
+
.def("numpy_vertices", [] (attrib_t &instance) {
|
|
47
|
+
auto ret = py::array_t<real_t>(instance.vertices.size());
|
|
48
|
+
py::buffer_info buf = ret.request();
|
|
49
|
+
memcpy(buf.ptr, instance.vertices.data(), instance.vertices.size() * sizeof(real_t));
|
|
50
|
+
return ret;
|
|
51
|
+
})
|
|
52
|
+
.def("numpy_vertex_weights", [] (attrib_t &instance) {
|
|
53
|
+
auto ret = py::array_t<real_t>(instance.vertex_weights.size());
|
|
54
|
+
py::buffer_info buf = ret.request();
|
|
55
|
+
memcpy(buf.ptr, instance.vertex_weights.data(), instance.vertex_weights.size() * sizeof(real_t));
|
|
56
|
+
return ret;
|
|
57
|
+
})
|
|
58
|
+
.def("numpy_normals", [] (attrib_t &instance) {
|
|
59
|
+
auto ret = py::array_t<real_t>(instance.normals.size());
|
|
60
|
+
py::buffer_info buf = ret.request();
|
|
61
|
+
memcpy(buf.ptr, instance.normals.data(), instance.normals.size() * sizeof(real_t));
|
|
62
|
+
return ret;
|
|
63
|
+
})
|
|
64
|
+
.def("numpy_texcoords", [] (attrib_t &instance) {
|
|
65
|
+
auto ret = py::array_t<real_t>(instance.texcoords.size());
|
|
66
|
+
py::buffer_info buf = ret.request();
|
|
67
|
+
memcpy(buf.ptr, instance.texcoords.data(), instance.texcoords.size() * sizeof(real_t));
|
|
68
|
+
return ret;
|
|
69
|
+
})
|
|
70
|
+
.def("numpy_colors", [] (attrib_t &instance) {
|
|
71
|
+
auto ret = py::array_t<real_t>(instance.colors.size());
|
|
72
|
+
py::buffer_info buf = ret.request();
|
|
73
|
+
memcpy(buf.ptr, instance.colors.data(), instance.colors.size() * sizeof(real_t));
|
|
74
|
+
return ret;
|
|
75
|
+
})
|
|
76
|
+
;
|
|
77
|
+
|
|
78
|
+
py::class_<shape_t>(tobj_module, "shape_t")
|
|
79
|
+
.def(py::init<>())
|
|
80
|
+
.def_readwrite("name", &shape_t::name)
|
|
81
|
+
.def_readwrite("mesh", &shape_t::mesh)
|
|
82
|
+
.def_readwrite("lines", &shape_t::lines)
|
|
83
|
+
.def_readwrite("points", &shape_t::points);
|
|
84
|
+
|
|
85
|
+
py::class_<index_t>(tobj_module, "index_t")
|
|
86
|
+
.def(py::init<>())
|
|
87
|
+
.def_readwrite("vertex_index", &index_t::vertex_index)
|
|
88
|
+
.def_readwrite("normal_index", &index_t::normal_index)
|
|
89
|
+
.def_readwrite("texcoord_index", &index_t::texcoord_index)
|
|
90
|
+
;
|
|
91
|
+
|
|
92
|
+
// NOTE(syoyo): It looks it is rather difficult to expose assignment by array index to
|
|
93
|
+
// python world for array variable.
|
|
94
|
+
// For example following python scripting does not work well.
|
|
95
|
+
//
|
|
96
|
+
// print(mat.diffuse)
|
|
97
|
+
// >>> [0.1, 0.2, 0.3]
|
|
98
|
+
// mat.diffuse[1] = 1.0
|
|
99
|
+
// print(mat.diffuse)
|
|
100
|
+
// >>> [0.1, 0.2, 0.3] # No modification
|
|
101
|
+
//
|
|
102
|
+
// https://github.com/pybind/pybind11/issues/1134
|
|
103
|
+
//
|
|
104
|
+
// so, we need to update array variable like this:
|
|
105
|
+
//
|
|
106
|
+
// diffuse = mat.diffuse
|
|
107
|
+
// diffuse[1] = 1.0
|
|
108
|
+
// mat.diffuse = diffuse
|
|
109
|
+
//
|
|
110
|
+
py::class_<material_t>(tobj_module, "material_t")
|
|
111
|
+
.def(py::init<>())
|
|
112
|
+
.def_readwrite("name", &material_t::name)
|
|
113
|
+
.def_property("ambient", &material_t::GetAmbient, &material_t::SetAmbient)
|
|
114
|
+
.def_property("diffuse", &material_t::GetDiffuse, &material_t::SetDiffuse)
|
|
115
|
+
.def_property("specular", &material_t::GetSpecular, &material_t::SetSpecular)
|
|
116
|
+
.def_property("transmittance", &material_t::GetTransmittance, &material_t::SetTransmittance)
|
|
117
|
+
.def_readwrite("shininess", &material_t::shininess)
|
|
118
|
+
.def_readwrite("ior", &material_t::ior)
|
|
119
|
+
.def_readwrite("dissolve", &material_t::dissolve)
|
|
120
|
+
.def_readwrite("illum", &material_t::illum)
|
|
121
|
+
.def_readwrite("ambient_texname", &material_t::ambient_texname)
|
|
122
|
+
.def_readwrite("diffuse_texname", &material_t::diffuse_texname)
|
|
123
|
+
.def_readwrite("specular_texname", &material_t::specular_texname)
|
|
124
|
+
.def_readwrite("specular_highlight_texname", &material_t::specular_highlight_texname)
|
|
125
|
+
.def_readwrite("bump_texname", &material_t::bump_texname)
|
|
126
|
+
.def_readwrite("displacement_texname", &material_t::displacement_texname)
|
|
127
|
+
.def_readwrite("alpha_texname", &material_t::alpha_texname)
|
|
128
|
+
.def_readwrite("reflection_texname", &material_t::reflection_texname)
|
|
129
|
+
// TODO(syoyo): Expose texture parameter
|
|
130
|
+
// PBR
|
|
131
|
+
.def_readwrite("roughness", &material_t::roughness)
|
|
132
|
+
.def_readwrite("metallic", &material_t::metallic)
|
|
133
|
+
.def_readwrite("sheen", &material_t::sheen)
|
|
134
|
+
.def_readwrite("clearcoat_thickness", &material_t::clearcoat_thickness)
|
|
135
|
+
.def_readwrite("clearcoat_roughness", &material_t::clearcoat_roughness)
|
|
136
|
+
.def_readwrite("anisotropy", &material_t::anisotropy)
|
|
137
|
+
.def_readwrite("anisotropy_rotation", &material_t::anisotropy_rotation)
|
|
138
|
+
|
|
139
|
+
.def_readwrite("roughness_texname", &material_t::roughness_texname)
|
|
140
|
+
.def_readwrite("metallic_texname", &material_t::metallic_texname)
|
|
141
|
+
.def_readwrite("sheen_texname", &material_t::sheen_texname)
|
|
142
|
+
.def_readwrite("emissive_texname", &material_t::emissive_texname)
|
|
143
|
+
.def_readwrite("normal_texname", &material_t::normal_texname)
|
|
144
|
+
|
|
145
|
+
.def("GetCustomParameter", &material_t::GetCustomParameter)
|
|
146
|
+
;
|
|
147
|
+
|
|
148
|
+
py::class_<mesh_t>(tobj_module, "mesh_t", py::buffer_protocol())
|
|
149
|
+
.def(py::init<>())
|
|
150
|
+
.def_readonly("num_face_vertices", &mesh_t::num_face_vertices)
|
|
151
|
+
.def("numpy_num_face_vertices", [] (mesh_t &instance) {
|
|
152
|
+
auto ret = py::array_t<unsigned int>(instance.num_face_vertices.size());
|
|
153
|
+
py::buffer_info buf = ret.request();
|
|
154
|
+
memcpy(buf.ptr, instance.num_face_vertices.data(), instance.num_face_vertices.size() * sizeof(unsigned int));
|
|
155
|
+
return ret;
|
|
156
|
+
})
|
|
157
|
+
.def("vertex_indices", [](mesh_t &self) {
|
|
158
|
+
// NOTE: we cannot use py::buffer_info and py:buffer as a return type.
|
|
159
|
+
// py::memoriview is not suited for vertex indices usecase, since indices data may be used after
|
|
160
|
+
// deleting C++ mesh_t object in Python world.
|
|
161
|
+
//
|
|
162
|
+
// So create a dedicated Python object(std::vector<int>)
|
|
163
|
+
|
|
164
|
+
std::vector<int> indices;
|
|
165
|
+
indices.resize(self.indices.size());
|
|
166
|
+
for (size_t i = 0; i < self.indices.size(); i++) {
|
|
167
|
+
indices[i] = self.indices[i].vertex_index;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return indices;
|
|
171
|
+
})
|
|
172
|
+
.def("normal_indices", [](mesh_t &self) {
|
|
173
|
+
|
|
174
|
+
std::vector<int> indices;
|
|
175
|
+
indices.resize(self.indices.size());
|
|
176
|
+
for (size_t i = 0; i < self.indices.size(); i++) {
|
|
177
|
+
indices[i] = self.indices[i].normal_index;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return indices;
|
|
181
|
+
})
|
|
182
|
+
.def("texcoord_indices", [](mesh_t &self) {
|
|
183
|
+
|
|
184
|
+
std::vector<int> indices;
|
|
185
|
+
indices.resize(self.indices.size());
|
|
186
|
+
for (size_t i = 0; i < self.indices.size(); i++) {
|
|
187
|
+
indices[i] = self.indices[i].texcoord_index;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return indices;
|
|
191
|
+
})
|
|
192
|
+
.def_readonly("indices", &mesh_t::indices)
|
|
193
|
+
.def("numpy_indices", [] (mesh_t &instance) {
|
|
194
|
+
// Flatten indexes. index_t is composed of 3 ints(vertex_index, normal_index, texcoord_index).
|
|
195
|
+
// numpy_indices = [0, -1, -1, 1, -1, -1, ...]
|
|
196
|
+
// C++11 or later should pack POD struct tightly and does not reorder variables,
|
|
197
|
+
// so we can memcpy to copy data.
|
|
198
|
+
// Still, we check the size of struct and byte offsets of each variable just for sure.
|
|
199
|
+
static_assert(sizeof(index_t) == 12, "sizeof(index_t) must be 12");
|
|
200
|
+
static_assert(offsetof(index_t, vertex_index) == 0, "offsetof(index_t, vertex_index) must be 0");
|
|
201
|
+
static_assert(offsetof(index_t, normal_index) == 4, "offsetof(index_t, normal_index) must be 4");
|
|
202
|
+
static_assert(offsetof(index_t, texcoord_index) == 8, "offsetof(index_t, texcoord_index) must be 8");
|
|
203
|
+
|
|
204
|
+
auto ret = py::array_t<int>(instance.indices.size() * 3);
|
|
205
|
+
py::buffer_info buf = ret.request();
|
|
206
|
+
memcpy(buf.ptr, instance.indices.data(), instance.indices.size() * 3 * sizeof(int));
|
|
207
|
+
return ret;
|
|
208
|
+
})
|
|
209
|
+
.def_readonly("material_ids", &mesh_t::material_ids)
|
|
210
|
+
.def("numpy_material_ids", [] (mesh_t &instance) {
|
|
211
|
+
auto ret = py::array_t<int>(instance.material_ids.size());
|
|
212
|
+
py::buffer_info buf = ret.request();
|
|
213
|
+
memcpy(buf.ptr, instance.material_ids.data(), instance.material_ids.size() * sizeof(int));
|
|
214
|
+
return ret;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
py::class_<lines_t>(tobj_module, "lines_t")
|
|
218
|
+
.def(py::init<>())
|
|
219
|
+
.def_readonly("indices", &lines_t::indices)
|
|
220
|
+
.def_readonly("num_line_vertices", &lines_t::num_line_vertices)
|
|
221
|
+
;
|
|
222
|
+
|
|
223
|
+
py::class_<points_t>(tobj_module, "points_t")
|
|
224
|
+
.def(py::init<>())
|
|
225
|
+
.def_readonly("indices", &points_t::indices)
|
|
226
|
+
;
|
|
227
|
+
|
|
228
|
+
py::class_<joint_and_weight_t>(tobj_module, "joint_and_weight_t")
|
|
229
|
+
.def(py::init<>())
|
|
230
|
+
.def_readonly("joint_id", &joint_and_weight_t::joint_id, "Joint index(NOTE: Joint info is provided externally, not from .obj")
|
|
231
|
+
.def_readonly("weight", &joint_and_weight_t::weight, "Weight value(NOTE: weight is not normalized)")
|
|
232
|
+
;
|
|
233
|
+
|
|
234
|
+
py::class_<skin_weight_t>(tobj_module, "skin_weight_t")
|
|
235
|
+
.def(py::init<>())
|
|
236
|
+
.def_readonly("vertex_id", &skin_weight_t::vertex_id)
|
|
237
|
+
.def_readonly("weightValues", &skin_weight_t::weightValues)
|
|
238
|
+
;
|
|
239
|
+
|
|
240
|
+
py::class_<tag_t>(tobj_module, "tag_t")
|
|
241
|
+
.def(py::init<>())
|
|
242
|
+
.def_readonly("name", &tag_t::name)
|
|
243
|
+
.def_readonly("intValues", &tag_t::intValues)
|
|
244
|
+
.def_readonly("floatValues", &tag_t::floatValues)
|
|
245
|
+
.def_readonly("stringValues", &tag_t::stringValues)
|
|
246
|
+
;
|
|
247
|
+
}
|
|
248
|
+
|
python/sample.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import tinyobjloader
|
|
3
|
+
|
|
4
|
+
is_numpy_available = False
|
|
5
|
+
try:
|
|
6
|
+
import numpy
|
|
7
|
+
|
|
8
|
+
is_numpy_available = True
|
|
9
|
+
except:
|
|
10
|
+
print(
|
|
11
|
+
"NumPy not installed. Do not use numpy_*** API. If you encounter slow performance, see a performance tips for non-numpy API https://github.com/tinyobjloader/tinyobjloader/issues/275"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
filename = "../models/cornell_box.obj"
|
|
15
|
+
|
|
16
|
+
if len(sys.argv) > 1:
|
|
17
|
+
filename = sys.argv[1]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
reader = tinyobjloader.ObjReader()
|
|
21
|
+
|
|
22
|
+
# Load .obj(and .mtl) using default configuration
|
|
23
|
+
ret = reader.ParseFromFile(filename)
|
|
24
|
+
|
|
25
|
+
# Optionally you can set custom `config`
|
|
26
|
+
# config = tinyobj.ObjReaderConfig()
|
|
27
|
+
# config.triangulate = False
|
|
28
|
+
# ret = reader.ParseFromFile(filename, config)
|
|
29
|
+
|
|
30
|
+
if ret == False:
|
|
31
|
+
print("Failed to load : ", filename)
|
|
32
|
+
print("Warn:", reader.Warning())
|
|
33
|
+
print("Err:", reader.Error())
|
|
34
|
+
sys.exit(-1)
|
|
35
|
+
|
|
36
|
+
if reader.Warning():
|
|
37
|
+
print("Warn:", reader.Warning())
|
|
38
|
+
|
|
39
|
+
attrib = reader.GetAttrib()
|
|
40
|
+
print("len(attrib.vertices) = ", len(attrib.vertices))
|
|
41
|
+
print("len(attrib.vertex_weights) = ", len(attrib.vertex_weights))
|
|
42
|
+
print("len(attrib.normals) = ", len(attrib.normals))
|
|
43
|
+
print("len(attrib.texcoords) = ", len(attrib.texcoords))
|
|
44
|
+
print("len(attrib.colors) = ", len(attrib.colors))
|
|
45
|
+
print("len(attrib.skin_weights) = ", len(attrib.skin_weights))
|
|
46
|
+
|
|
47
|
+
# vertex data must be `xyzxyzxyz...`
|
|
48
|
+
assert len(attrib.vertices) % 3 == 0
|
|
49
|
+
|
|
50
|
+
# normal data must be `xyzxyzxyz...`
|
|
51
|
+
assert len(attrib.normals) % 3 == 0
|
|
52
|
+
|
|
53
|
+
# texcoords data must be `uvuvuv...`
|
|
54
|
+
assert len(attrib.texcoords) % 2 == 0
|
|
55
|
+
|
|
56
|
+
# colors data must be `rgbrgbrgb...`
|
|
57
|
+
assert len(attrib.texcoords) % 3 == 0
|
|
58
|
+
|
|
59
|
+
# Performance note
|
|
60
|
+
# (direct?) array access through member variable is quite slow.
|
|
61
|
+
# https://github.com/tinyobjloader/tinyobjloader/issues/275#issuecomment-753465833
|
|
62
|
+
#
|
|
63
|
+
# We encourage first copy(?) varible to Python world:
|
|
64
|
+
#
|
|
65
|
+
# vertices = attrib.vertices
|
|
66
|
+
#
|
|
67
|
+
# for i in range(...)
|
|
68
|
+
# v = vertices[i]
|
|
69
|
+
#
|
|
70
|
+
# Or please consider using numpy_*** interface(e.g. numpy_vertices())
|
|
71
|
+
|
|
72
|
+
for i, v in enumerate(attrib.vertices):
|
|
73
|
+
print("v[{}] = {}".format(i, v))
|
|
74
|
+
|
|
75
|
+
# vw is filled with 1.0 if [w] component is not present in `v` line in .obj
|
|
76
|
+
for i, w in enumerate(attrib.vertex_weights):
|
|
77
|
+
print("vweight[{}] = {}".format(i, w))
|
|
78
|
+
|
|
79
|
+
for i, v in enumerate(attrib.normals):
|
|
80
|
+
print("vn[{}] = {}".format(i, v))
|
|
81
|
+
|
|
82
|
+
for i, v in enumerate(attrib.texcoords):
|
|
83
|
+
print("vt[{}] = {}".format(i, v))
|
|
84
|
+
|
|
85
|
+
for i, v in enumerate(attrib.colors):
|
|
86
|
+
print("vcol[{}] = {}".format(i, v))
|
|
87
|
+
|
|
88
|
+
if len(attrib.skin_weights):
|
|
89
|
+
print("num skin weights", len(attrib.skin_weights))
|
|
90
|
+
|
|
91
|
+
for i, skin in enumerate(attrib.skin_weights):
|
|
92
|
+
print("skin_weight[{}]".format(i))
|
|
93
|
+
print(" vertex_id = ", skin.vertex_id)
|
|
94
|
+
print(" len(weights) = ", len(skin.weightValues))
|
|
95
|
+
for k, w in enumerate(skin.weightValues):
|
|
96
|
+
print(" [{}] joint_id: {}, weight: {}".format(k, w.joint_id, w.weight))
|
|
97
|
+
|
|
98
|
+
if is_numpy_available:
|
|
99
|
+
print("numpy_v = {}".format(attrib.numpy_vertices()))
|
|
100
|
+
print("numpy_vn = {}".format(attrib.numpy_normals()))
|
|
101
|
+
print("numpy_vt = {}".format(attrib.numpy_texcoords()))
|
|
102
|
+
print("numpy_vcol = {}".format(attrib.numpy_colors()))
|
|
103
|
+
|
|
104
|
+
materials = reader.GetMaterials()
|
|
105
|
+
print("Num materials: ", len(materials))
|
|
106
|
+
for m in materials:
|
|
107
|
+
print(m.name)
|
|
108
|
+
print(m.diffuse)
|
|
109
|
+
print(m.diffuse_texname)
|
|
110
|
+
# Partial update(array indexing) does not work
|
|
111
|
+
# m.diffuse[1] = 1.0
|
|
112
|
+
|
|
113
|
+
# Update with full object assignment works
|
|
114
|
+
m.diffuse = [1, 2, 3]
|
|
115
|
+
print(m.diffuse)
|
|
116
|
+
|
|
117
|
+
# print(m.shininess)
|
|
118
|
+
# print(m.illum)
|
|
119
|
+
|
|
120
|
+
shapes = reader.GetShapes()
|
|
121
|
+
print("Num shapes: ", len(shapes))
|
|
122
|
+
for shape in shapes:
|
|
123
|
+
print(shape.name)
|
|
124
|
+
print("len(num_indices) = {}".format(len(shape.mesh.indices)))
|
|
125
|
+
for i, idx in enumerate(shape.mesh.indices):
|
|
126
|
+
print("[{}] v_idx {}".format(i, idx.vertex_index))
|
|
127
|
+
print("[{}] vn_idx {}".format(i, idx.normal_index))
|
|
128
|
+
print("[{}] vt_idx {}".format(i, idx.texcoord_index))
|
|
129
|
+
print("material_ids = {}".format(shape.mesh.material_ids))
|
|
130
|
+
|
|
131
|
+
# faster access to indices
|
|
132
|
+
a = shape.mesh.vertex_indices()
|
|
133
|
+
print("vertex_indices", shape.mesh.vertex_indices())
|
|
134
|
+
|
|
135
|
+
if is_numpy_available:
|
|
136
|
+
print("numpy_indices = {}".format(shape.mesh.numpy_indices()))
|
|
137
|
+
print("numpy_num_face_vertices = {}".format(shape.mesh.numpy_num_face_vertices()))
|
|
138
|
+
print("numpy_material_ids = {}".format(shape.mesh.numpy_material_ids()))
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Use double precision for better python integration.
|
|
2
|
+
// Need also define this in `binding.cc`(and all compilation units)
|
|
3
|
+
#define TINYOBJLOADER_USE_DOUBLE
|
|
4
|
+
|
|
5
|
+
// Use robust triangulation by using Mapbox earcut.
|
|
6
|
+
#define TINYOBJLOADER_USE_MAPBOX_EARCUT
|
|
7
|
+
|
|
8
|
+
#define TINYOBJLOADER_IMPLEMENTATION
|
|
9
|
+
#include "../tiny_obj_loader.h"
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tinymetabobjloader
|
|
3
|
+
Version: 2.0.0rc14.dev2
|
|
4
|
+
Summary: Tiny but powerful Wavefront OBJ loader
|
|
5
|
+
Home-page: https://github.com/curvewise-forks/tinyobjloader
|
|
6
|
+
Author: Syoyo Fujita, Paul Melnikow
|
|
7
|
+
Author-email: syoyo@lighttransport.com, github@paulmelnikow.com
|
|
8
|
+
License: MIT AND ISC
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Intended Audience :: Manufacturing
|
|
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 :: Python :: 3
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Dynamic: author
|
|
21
|
+
Dynamic: author-email
|
|
22
|
+
Dynamic: classifier
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# tinyobjloader
|
|
28
|
+
|
|
29
|
+
[](https://badge.fury.io/py/tinyobjloader)
|
|
30
|
+
|
|
31
|
+
[](https://dev.azure.com/tinyobjloader/tinyobjloader/_build/latest?definitionId=1&branchName=master)
|
|
32
|
+
|
|
33
|
+
[](https://ci.appveyor.com/project/syoyo/tinyobjloader-6e4qf/branch/master)
|
|
34
|
+
|
|
35
|
+
[](https://coveralls.io/github/syoyo/tinyobjloader?branch=master)
|
|
36
|
+
|
|
37
|
+
[](https://aur.archlinux.org/packages/tinyobjloader)
|
|
38
|
+
|
|
39
|
+
Tiny but powerful single file wavefront obj loader written in C++03. No dependency except for C++ STL. It can parse over 10M polygons with moderate memory and time.
|
|
40
|
+
|
|
41
|
+
`tinyobjloader` is good for embedding .obj loader to your (global illumination) renderer ;-)
|
|
42
|
+
|
|
43
|
+
If you are looking for C99 version, please see https://github.com/syoyo/tinyobjloader-c .
|
|
44
|
+
|
|
45
|
+
Version notice
|
|
46
|
+
--------------
|
|
47
|
+
|
|
48
|
+
We recommend to use `master`(`main`) branch. Its v2.0 release candidate. Most features are now nearly robust and stable(Remaining task for release v2.0 is polishing C++ and Python API, and fix built-in triangulation code).
|
|
49
|
+
|
|
50
|
+
We have released new version v1.0.0 on 20 Aug, 2016.
|
|
51
|
+
Old version is available as `v0.9.x` branch https://github.com/syoyo/tinyobjloader/tree/v0.9.x
|
|
52
|
+
|
|
53
|
+
## What's new
|
|
54
|
+
|
|
55
|
+
* 29 Jul, 2021 : Added Mapbox's earcut for robust triangulation. Also fixes triangulation bug(still there is some issue in built-in triangulation algorithm: https://github.com/tinyobjloader/tinyobjloader/issues/319).
|
|
56
|
+
* 19 Feb, 2020 : The repository has been moved to https://github.com/tinyobjloader/tinyobjloader !
|
|
57
|
+
* 18 May, 2019 : Python binding!(See `python` folder. Also see https://pypi.org/project/tinyobjloader/)
|
|
58
|
+
* 14 Apr, 2019 : Bump version v2.0.0 rc0. New C++ API and python bindings!(1.x API still exists for backward compatibility)
|
|
59
|
+
* 20 Aug, 2016 : Bump version v1.0.0. New data structure and API!
|
|
60
|
+
|
|
61
|
+
## Requirements
|
|
62
|
+
|
|
63
|
+
* C++03 compiler
|
|
64
|
+
|
|
65
|
+
### Old version
|
|
66
|
+
|
|
67
|
+
Previous old version is available in `v0.9.x` branch.
|
|
68
|
+
|
|
69
|
+
## Example
|
|
70
|
+
|
|
71
|
+

|
|
72
|
+
|
|
73
|
+
tinyobjloader can successfully load 6M triangles Rungholt scene.
|
|
74
|
+
http://casual-effects.com/data/index.html
|
|
75
|
+
|
|
76
|
+

|
|
77
|
+
|
|
78
|
+
* [examples/viewer/](examples/viewer) OpenGL .obj viewer
|
|
79
|
+
* [examples/callback_api/](examples/callback_api/) Callback API example
|
|
80
|
+
* [examples/voxelize/](examples/voxelize/) Voxelizer example
|
|
81
|
+
|
|
82
|
+
## Use case
|
|
83
|
+
|
|
84
|
+
TinyObjLoader is successfully used in ...
|
|
85
|
+
|
|
86
|
+
### New version(v1.0.x)
|
|
87
|
+
|
|
88
|
+
* Double precision support through `TINYOBJLOADER_USE_DOUBLE` thanks to noma
|
|
89
|
+
* Loading models in Vulkan Tutorial https://vulkan-tutorial.com/Loading_models
|
|
90
|
+
* .obj viewer with Metal https://github.com/middlefeng/NuoModelViewer/tree/master
|
|
91
|
+
* Vulkan Cookbook https://github.com/PacktPublishing/Vulkan-Cookbook
|
|
92
|
+
* cudabox: CUDA Solid Voxelizer Engine https://github.com/gaspardzoss/cudavox
|
|
93
|
+
* Drake: A planning, control, and analysis toolbox for nonlinear dynamical systems https://github.com/RobotLocomotion/drake
|
|
94
|
+
* VFPR - a Vulkan Forward Plus Renderer : https://github.com/WindyDarian/Vulkan-Forward-Plus-Renderer
|
|
95
|
+
* glslViewer: https://github.com/patriciogonzalezvivo/glslViewer
|
|
96
|
+
* Lighthouse2: https://github.com/jbikker/lighthouse2
|
|
97
|
+
* rayrender(an open source R package for raytracing scenes in created in R): https://github.com/tylermorganwall/rayrender
|
|
98
|
+
* liblava - A modern C++ and easy-to-use framework for the Vulkan API. [MIT]: https://github.com/liblava/liblava
|
|
99
|
+
* rtxON - Simple Vulkan raytracing tutorials https://github.com/iOrange/rtxON
|
|
100
|
+
* metal-ray-tracer - Writing ray-tracer using Metal Performance Shaders https://github.com/sergeyreznik/metal-ray-tracer https://sergeyreznik.github.io/metal-ray-tracer/index.html
|
|
101
|
+
* Supernova Engine - 2D and 3D projects with Lua or C++ in data oriented design: https://github.com/supernovaengine/supernova
|
|
102
|
+
* AGE (Arc Game Engine) - An open-source engine for building 2D & 3D real-time rendering and interactive contents: https://github.com/MohitSethi99/ArcGameEngine
|
|
103
|
+
* [Wicked Engine<img src="https://github.com/turanszkij/WickedEngine/blob/master/Content/logo_small.png" width="28px" align="center"/>](https://github.com/turanszkij/WickedEngine) - 3D engine with modern graphics
|
|
104
|
+
* [Lumina Game Engine](https://github.com/MrDrElliot/LuminaEngine) - A modern, high-performance game engine built with Vulkan
|
|
105
|
+
* Your project here! (Plese send PR)
|
|
106
|
+
|
|
107
|
+
### Old version(v0.9.x)
|
|
108
|
+
|
|
109
|
+
* bullet3 https://github.com/erwincoumans/bullet3
|
|
110
|
+
* pbrt-v2 https://github.com/mmp/pbrt-v2
|
|
111
|
+
* OpenGL game engine development http://swarminglogic.com/jotting/2013_10_gamedev01
|
|
112
|
+
* mallie https://lighttransport.github.io/mallie
|
|
113
|
+
* IBLBaker (Image Based Lighting Baker). http://www.derkreature.com/iblbaker/
|
|
114
|
+
* Stanford CS148 http://web.stanford.edu/class/cs148/assignments/assignment3.pdf
|
|
115
|
+
* Awesome Bump http://awesomebump.besaba.com/about/
|
|
116
|
+
* sdlgl3-wavefront OpenGL .obj viewer https://github.com/chrisliebert/sdlgl3-wavefront
|
|
117
|
+
* pbrt-v3 https://github.com/mmp/pbrt-v3
|
|
118
|
+
* cocos2d-x https://github.com/cocos2d/cocos2d-x/
|
|
119
|
+
* Android Vulkan demo https://github.com/SaschaWillems/Vulkan
|
|
120
|
+
* voxelizer https://github.com/karimnaaji/voxelizer
|
|
121
|
+
* Probulator https://github.com/kayru/Probulator
|
|
122
|
+
* OptiX Prime baking https://github.com/nvpro-samples/optix_prime_baking
|
|
123
|
+
* FireRays SDK https://github.com/GPUOpen-LibrariesAndSDKs/FireRays_SDK
|
|
124
|
+
* parg, tiny C library of various graphics utilities and GL demos https://github.com/prideout/parg
|
|
125
|
+
* Opengl unit of ChronoEngine https://github.com/projectchrono/chrono-opengl
|
|
126
|
+
* Point Based Global Illumination on modern GPU https://pbgi.wordpress.com/code-source/
|
|
127
|
+
* Fast OBJ file importing and parsing in CUDA http://researchonline.jcu.edu.au/42515/1/2015.CVM.OBJCUDA.pdf
|
|
128
|
+
* Sorted Shading for Uni-Directional Pathtracing by Joshua Bainbridge https://nccastaff.bournemouth.ac.uk/jmacey/MastersProjects/MSc15/02Josh/joshua_bainbridge_thesis.pdf
|
|
129
|
+
* GeeXLab http://www.geeks3d.com/hacklab/20160531/geexlab-0-12-0-0-released-for-windows/
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
## Features
|
|
133
|
+
|
|
134
|
+
* Group(parse multiple group name)
|
|
135
|
+
* Vertex
|
|
136
|
+
* Vertex color(as an extension: https://blender.stackexchange.com/questions/31997/how-can-i-get-vertex-painted-obj-files-to-import-into-blender)
|
|
137
|
+
* Texcoord
|
|
138
|
+
* Normal
|
|
139
|
+
* Crease tag('t'). This is OpenSubdiv specific(not in wavefront .obj specification)
|
|
140
|
+
* Callback API for custom loading.
|
|
141
|
+
* Double precision support(for HPC application).
|
|
142
|
+
* Smoothing group
|
|
143
|
+
* Python binding : See `python` folder.
|
|
144
|
+
* Precompiled binary(manylinux1-x86_64 only) is hosted at pypi https://pypi.org/project/tinyobjloader/)
|
|
145
|
+
|
|
146
|
+
### Primitives
|
|
147
|
+
|
|
148
|
+
* [x] face(`f`)
|
|
149
|
+
* [x] lines(`l`)
|
|
150
|
+
* [ ] points(`p`)
|
|
151
|
+
* [ ] curve
|
|
152
|
+
* [ ] 2D curve
|
|
153
|
+
* [ ] surface.
|
|
154
|
+
* [ ] Free form curve/surfaces
|
|
155
|
+
|
|
156
|
+
### Material
|
|
157
|
+
|
|
158
|
+
* PBR material extension for .MTL. Please see [pbr-mtl.md](pbr-mtl.md) for details.
|
|
159
|
+
* Texture options
|
|
160
|
+
* Unknown material attributes are returned as key-value(value is string) map.
|
|
161
|
+
|
|
162
|
+
## TODO
|
|
163
|
+
|
|
164
|
+
* [ ] Fix obj_sticker example.
|
|
165
|
+
* [ ] More unit test codes.
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
TinyObjLoader is licensed under MIT license.
|
|
170
|
+
|
|
171
|
+
### Third party licenses.
|
|
172
|
+
|
|
173
|
+
* pybind11 : BSD-style license.
|
|
174
|
+
* mapbox earcut.hpp: ISC License.
|
|
175
|
+
|
|
176
|
+
## Usage
|
|
177
|
+
|
|
178
|
+
### Installation
|
|
179
|
+
|
|
180
|
+
One option is to simply copy the header file into your project and to make sure that `TINYOBJLOADER_IMPLEMENTATION` is defined exactly once.
|
|
181
|
+
|
|
182
|
+
### Building tinyobjloader - Using vcpkg(not recommended though)
|
|
183
|
+
|
|
184
|
+
Although it is not a recommended way, you can download and install tinyobjloader using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
|
185
|
+
|
|
186
|
+
git clone https://github.com/Microsoft/vcpkg.git
|
|
187
|
+
cd vcpkg
|
|
188
|
+
./bootstrap-vcpkg.sh
|
|
189
|
+
./vcpkg integrate install
|
|
190
|
+
./vcpkg install tinyobjloader
|
|
191
|
+
|
|
192
|
+
The tinyobjloader port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
|
193
|
+
|
|
194
|
+
### Data format
|
|
195
|
+
|
|
196
|
+
`attrib_t` contains single and linear array of vertex data(position, normal and texcoord).
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
attrib_t::vertices => 3 floats per vertex
|
|
200
|
+
|
|
201
|
+
v[0] v[1] v[2] v[3] v[n-1]
|
|
202
|
+
+-----------+-----------+-----------+-----------+ +-----------+
|
|
203
|
+
| x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z |
|
|
204
|
+
+-----------+-----------+-----------+-----------+ +-----------+
|
|
205
|
+
|
|
206
|
+
attrib_t::normals => 3 floats per vertex
|
|
207
|
+
|
|
208
|
+
n[0] n[1] n[2] n[3] n[n-1]
|
|
209
|
+
+-----------+-----------+-----------+-----------+ +-----------+
|
|
210
|
+
| x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z |
|
|
211
|
+
+-----------+-----------+-----------+-----------+ +-----------+
|
|
212
|
+
|
|
213
|
+
attrib_t::texcoords => 2 floats per vertex
|
|
214
|
+
|
|
215
|
+
t[0] t[1] t[2] t[3] t[n-1]
|
|
216
|
+
+-----------+-----------+-----------+-----------+ +-----------+
|
|
217
|
+
| u | v | u | v | u | v | u | v | .... | u | v |
|
|
218
|
+
+-----------+-----------+-----------+-----------+ +-----------+
|
|
219
|
+
|
|
220
|
+
attrib_t::colors => 3 floats per vertex(vertex color. optional)
|
|
221
|
+
|
|
222
|
+
c[0] c[1] c[2] c[3] c[n-1]
|
|
223
|
+
+-----------+-----------+-----------+-----------+ +-----------+
|
|
224
|
+
| x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z |
|
|
225
|
+
+-----------+-----------+-----------+-----------+ +-----------+
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Each `shape_t::mesh_t` does not contain vertex data but contains array index to `attrib_t`.
|
|
230
|
+
See `loader_example.cc` for more details.
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
mesh_t::indices => array of vertex indices.
|
|
236
|
+
|
|
237
|
+
+----+----+----+----+----+----+----+----+----+----+ +--------+
|
|
238
|
+
| i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | ... | i(n-1) |
|
|
239
|
+
+----+----+----+----+----+----+----+----+----+----+ +--------+
|
|
240
|
+
|
|
241
|
+
Each index has an array index to attrib_t::vertices, attrib_t::normals and attrib_t::texcoords.
|
|
242
|
+
|
|
243
|
+
mesh_t::num_face_vertices => array of the number of vertices per face(e.g. 3 = triangle, 4 = quad , 5 or more = N-gons).
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
+---+---+---+ +---+
|
|
247
|
+
| 3 | 4 | 3 | ...... | 3 |
|
|
248
|
+
+---+---+---+ +---+
|
|
249
|
+
| | | |
|
|
250
|
+
| | | +-----------------------------------------+
|
|
251
|
+
| | | |
|
|
252
|
+
| | +------------------------------+ |
|
|
253
|
+
| | | |
|
|
254
|
+
| +------------------+ | |
|
|
255
|
+
| | | |
|
|
256
|
+
|/ |/ |/ |/
|
|
257
|
+
|
|
258
|
+
mesh_t::indices
|
|
259
|
+
|
|
260
|
+
| face[0] | face[1] | face[2] | | face[n-1] |
|
|
261
|
+
+----+----+----+----+----+----+----+----+----+----+ +--------+--------+--------+
|
|
262
|
+
| i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | ... | i(n-3) | i(n-2) | i(n-1) |
|
|
263
|
+
+----+----+----+----+----+----+----+----+----+----+ +--------+--------+--------+
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Note that when `triangulate` flag is true in `tinyobj::LoadObj()` argument, `num_face_vertices` are all filled with 3(triangle).
|
|
268
|
+
|
|
269
|
+
### float data type
|
|
270
|
+
|
|
271
|
+
TinyObjLoader now use `real_t` for floating point data type.
|
|
272
|
+
Default is `float(32bit)`.
|
|
273
|
+
You can enable `double(64bit)` precision by using `TINYOBJLOADER_USE_DOUBLE` define.
|
|
274
|
+
|
|
275
|
+
### Robust triangulation
|
|
276
|
+
|
|
277
|
+
When you enable `triangulation`(default is enabled),
|
|
278
|
+
TinyObjLoader triangulate polygons(faces with 4 or more vertices).
|
|
279
|
+
|
|
280
|
+
Built-in triangulation code may not work well in some polygon shape.
|
|
281
|
+
|
|
282
|
+
You can define `TINYOBJLOADER_USE_MAPBOX_EARCUT` for robust triangulation using `mapbox/earcut.hpp`.
|
|
283
|
+
This requires C++11 compiler though. And you need to copy `mapbox/earcut.hpp` to your project.
|
|
284
|
+
If you have your own `mapbox/earcut.hpp` file incuded in your project, you can define `TINYOBJLOADER_DONOT_INCLUDE_MAPBOX_EARCUT` so that `mapbox/earcut.hpp` is not included inside of `tiny_obj_loader.h`.
|
|
285
|
+
|
|
286
|
+
#### Example code (Deprecated API)
|
|
287
|
+
|
|
288
|
+
```c++
|
|
289
|
+
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
|
|
290
|
+
// Optional. define TINYOBJLOADER_USE_MAPBOX_EARCUT gives robust triangulation. Requires C++11
|
|
291
|
+
//#define TINYOBJLOADER_USE_MAPBOX_EARCUT
|
|
292
|
+
#include "tiny_obj_loader.h"
|
|
293
|
+
|
|
294
|
+
std::string inputfile = "cornell_box.obj";
|
|
295
|
+
tinyobj::attrib_t attrib;
|
|
296
|
+
std::vector<tinyobj::shape_t> shapes;
|
|
297
|
+
std::vector<tinyobj::material_t> materials;
|
|
298
|
+
|
|
299
|
+
std::string warn;
|
|
300
|
+
std::string err;
|
|
301
|
+
|
|
302
|
+
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, inputfile.c_str());
|
|
303
|
+
|
|
304
|
+
if (!warn.empty()) {
|
|
305
|
+
std::cout << warn << std::endl;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (!err.empty()) {
|
|
309
|
+
std::cerr << err << std::endl;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (!ret) {
|
|
313
|
+
exit(1);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Loop over shapes
|
|
317
|
+
for (size_t s = 0; s < shapes.size(); s++) {
|
|
318
|
+
// Loop over faces(polygon)
|
|
319
|
+
size_t index_offset = 0;
|
|
320
|
+
for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++) {
|
|
321
|
+
size_t fv = size_t(shapes[s].mesh.num_face_vertices[f]);
|
|
322
|
+
|
|
323
|
+
// Loop over vertices in the face.
|
|
324
|
+
for (size_t v = 0; v < fv; v++) {
|
|
325
|
+
// access to vertex
|
|
326
|
+
tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v];
|
|
327
|
+
|
|
328
|
+
tinyobj::real_t vx = attrib.vertices[3*size_t(idx.vertex_index)+0];
|
|
329
|
+
tinyobj::real_t vy = attrib.vertices[3*size_t(idx.vertex_index)+1];
|
|
330
|
+
tinyobj::real_t vz = attrib.vertices[3*size_t(idx.vertex_index)+2];
|
|
331
|
+
|
|
332
|
+
// Check if `normal_index` is zero or positive. negative = no normal data
|
|
333
|
+
if (idx.normal_index >= 0) {
|
|
334
|
+
tinyobj::real_t nx = attrib.normals[3*size_t(idx.normal_index)+0];
|
|
335
|
+
tinyobj::real_t ny = attrib.normals[3*size_t(idx.normal_index)+1];
|
|
336
|
+
tinyobj::real_t nz = attrib.normals[3*size_t(idx.normal_index)+2];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Check if `texcoord_index` is zero or positive. negative = no texcoord data
|
|
340
|
+
if (idx.texcoord_index >= 0) {
|
|
341
|
+
tinyobj::real_t tx = attrib.texcoords[2*size_t(idx.texcoord_index)+0];
|
|
342
|
+
tinyobj::real_t ty = attrib.texcoords[2*size_t(idx.texcoord_index)+1];
|
|
343
|
+
}
|
|
344
|
+
// Optional: vertex colors
|
|
345
|
+
// tinyobj::real_t red = attrib.colors[3*size_t(idx.vertex_index)+0];
|
|
346
|
+
// tinyobj::real_t green = attrib.colors[3*size_t(idx.vertex_index)+1];
|
|
347
|
+
// tinyobj::real_t blue = attrib.colors[3*size_t(idx.vertex_index)+2];
|
|
348
|
+
}
|
|
349
|
+
index_offset += fv;
|
|
350
|
+
|
|
351
|
+
// per-face material
|
|
352
|
+
shapes[s].mesh.material_ids[f];
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### Example code (New Object Oriented API)
|
|
359
|
+
|
|
360
|
+
```c++
|
|
361
|
+
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
|
|
362
|
+
// Optional. define TINYOBJLOADER_USE_MAPBOX_EARCUT gives robust triangulation. Requires C++11
|
|
363
|
+
//#define TINYOBJLOADER_USE_MAPBOX_EARCUT
|
|
364
|
+
#include "tiny_obj_loader.h"
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
std::string inputfile = "cornell_box.obj";
|
|
368
|
+
tinyobj::ObjReaderConfig reader_config;
|
|
369
|
+
reader_config.mtl_search_path = "./"; // Path to material files
|
|
370
|
+
|
|
371
|
+
tinyobj::ObjReader reader;
|
|
372
|
+
|
|
373
|
+
if (!reader.ParseFromFile(inputfile, reader_config)) {
|
|
374
|
+
if (!reader.Error().empty()) {
|
|
375
|
+
std::cerr << "TinyObjReader: " << reader.Error();
|
|
376
|
+
}
|
|
377
|
+
exit(1);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (!reader.Warning().empty()) {
|
|
381
|
+
std::cout << "TinyObjReader: " << reader.Warning();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
auto& attrib = reader.GetAttrib();
|
|
385
|
+
auto& shapes = reader.GetShapes();
|
|
386
|
+
auto& materials = reader.GetMaterials();
|
|
387
|
+
|
|
388
|
+
// Loop over shapes
|
|
389
|
+
for (size_t s = 0; s < shapes.size(); s++) {
|
|
390
|
+
// Loop over faces(polygon)
|
|
391
|
+
size_t index_offset = 0;
|
|
392
|
+
for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++) {
|
|
393
|
+
size_t fv = size_t(shapes[s].mesh.num_face_vertices[f]);
|
|
394
|
+
|
|
395
|
+
// Loop over vertices in the face.
|
|
396
|
+
for (size_t v = 0; v < fv; v++) {
|
|
397
|
+
// access to vertex
|
|
398
|
+
tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v];
|
|
399
|
+
tinyobj::real_t vx = attrib.vertices[3*size_t(idx.vertex_index)+0];
|
|
400
|
+
tinyobj::real_t vy = attrib.vertices[3*size_t(idx.vertex_index)+1];
|
|
401
|
+
tinyobj::real_t vz = attrib.vertices[3*size_t(idx.vertex_index)+2];
|
|
402
|
+
|
|
403
|
+
// Check if `normal_index` is zero or positive. negative = no normal data
|
|
404
|
+
if (idx.normal_index >= 0) {
|
|
405
|
+
tinyobj::real_t nx = attrib.normals[3*size_t(idx.normal_index)+0];
|
|
406
|
+
tinyobj::real_t ny = attrib.normals[3*size_t(idx.normal_index)+1];
|
|
407
|
+
tinyobj::real_t nz = attrib.normals[3*size_t(idx.normal_index)+2];
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Check if `texcoord_index` is zero or positive. negative = no texcoord data
|
|
411
|
+
if (idx.texcoord_index >= 0) {
|
|
412
|
+
tinyobj::real_t tx = attrib.texcoords[2*size_t(idx.texcoord_index)+0];
|
|
413
|
+
tinyobj::real_t ty = attrib.texcoords[2*size_t(idx.texcoord_index)+1];
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Optional: vertex colors
|
|
417
|
+
// tinyobj::real_t red = attrib.colors[3*size_t(idx.vertex_index)+0];
|
|
418
|
+
// tinyobj::real_t green = attrib.colors[3*size_t(idx.vertex_index)+1];
|
|
419
|
+
// tinyobj::real_t blue = attrib.colors[3*size_t(idx.vertex_index)+2];
|
|
420
|
+
}
|
|
421
|
+
index_offset += fv;
|
|
422
|
+
|
|
423
|
+
// per-face material
|
|
424
|
+
shapes[s].mesh.material_ids[f];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
## Optimized loader
|
|
433
|
+
|
|
434
|
+
Optimized multi-threaded .obj loader is available at `experimental/` directory.
|
|
435
|
+
If you want absolute performance to load .obj data, this optimized loader will fit your purpose.
|
|
436
|
+
Note that the optimized loader uses C++11 thread and it does less error checks but may work most .obj data.
|
|
437
|
+
|
|
438
|
+
Here is some benchmark result. Time are measured on MacBook 12(Early 2016, Core m5 1.2GHz).
|
|
439
|
+
|
|
440
|
+
* Rungholt scene(6M triangles)
|
|
441
|
+
* old version(v0.9.x): 15500 msecs.
|
|
442
|
+
* baseline(v1.0.x): 6800 msecs(2.3x faster than old version)
|
|
443
|
+
* optimised: 1500 msecs(10x faster than old version, 4.5x faster than baseline)
|
|
444
|
+
|
|
445
|
+
## Python binding
|
|
446
|
+
|
|
447
|
+
```
|
|
448
|
+
$ python -m pip install tinyobjloader
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
See [python/sample.py](python/sample.py) for example use of Python binding of tinyobjloader.
|
|
452
|
+
|
|
453
|
+
### CI + PyPI upload
|
|
454
|
+
|
|
455
|
+
cibuildwheels + twine upload for each git tagging event is handled in Github Actions and Cirrus CI(arm builds).
|
|
456
|
+
|
|
457
|
+
#### How to bump version(For developer)
|
|
458
|
+
|
|
459
|
+
* Apply `black` to python files(`python/sample.py`)
|
|
460
|
+
* Bump version in CMakeLists.txt
|
|
461
|
+
* Commit and push `release`. Confirm C.I. build is OK.
|
|
462
|
+
* Create tag starting with `v`(e.g. `v2.1.0`)
|
|
463
|
+
* `git push --tags`
|
|
464
|
+
* version settings is automatically handled in python binding through setuptools_scm.
|
|
465
|
+
* cibuildwheels + pypi upload(through twine) will be automatically triggered in Github Actions + Cirrus CI.
|
|
466
|
+
|
|
467
|
+
## Tests
|
|
468
|
+
|
|
469
|
+
Unit tests are provided in `tests` directory. See `tests/README.md` for details.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
tinyobjloader.cp314-win_amd64.pyd,sha256=wlVZZrnh7xVJa4r-9hJ197Co6JNpLkB0F3eaZEl64kw,403968
|
|
2
|
+
python/LICENSE,sha256=zxZlfK-dwbDoKmVi6SSoKzvbGR7TGeDQxXHf36TOPJs,1128
|
|
3
|
+
python/Makefile,sha256=uDtusDhGSIW8p_fe4S73bQNzdl6Oaqpxv9qutjsGfYA,79
|
|
4
|
+
python/README.md,sha256=EaY4a53EUCIKY954YFcZQJcSxBXpgGK1UXqpI3Ehhjg,1893
|
|
5
|
+
python/_version.py,sha256=XpkgYRA-nGXDvYmS6BQq8GHknkH4ia1gytHze5v6hks,181
|
|
6
|
+
python/bindings.cc,sha256=ujGUjeEBf40yl8aKq0PIGT5rINjXFltORAjObmRs6Tc,10777
|
|
7
|
+
python/sample.py,sha256=r4GCwMYeWz9d5-8fM32w-7kE3RdgTTeNiErIBoYnJE0,4499
|
|
8
|
+
python/tiny_obj_loader.cc,sha256=HuUwlkfSXxD_YYsL27VPzkq0pjCa4_NY0WFmDmH_IOg,328
|
|
9
|
+
tinymetabobjloader-2.0.0rc14.dev2.dist-info/licenses/LICENSE,sha256=ddIXyxs8b0qljS_X4P-c8squ9ukaQetbeJPbio08y_s,1944
|
|
10
|
+
tinymetabobjloader-2.0.0rc14.dev2.dist-info/METADATA,sha256=JW5RFGbkSlOKuRc7OdjYM6ybQ6MDuyQ-DHDfMhiMbdA,19824
|
|
11
|
+
tinymetabobjloader-2.0.0rc14.dev2.dist-info/WHEEL,sha256=MRIqJmWGXGbCDxvKAKUMbTPbbQhv9CNuiiNgFEELfOM,101
|
|
12
|
+
tinymetabobjloader-2.0.0rc14.dev2.dist-info/top_level.txt,sha256=JcbQXTgJJCPmQ8h_DXoxzE9oLfj8MSkGGZAz9PQdCzY,21
|
|
13
|
+
tinymetabobjloader-2.0.0rc14.dev2.dist-info/RECORD,,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2012-2019 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
|
+
|
|
Binary file
|