Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
160d6be10f | ||
|
|
583590767e | ||
|
|
dc542d6638 | ||
|
|
c5976f931b | ||
|
|
0511658e86 | ||
|
|
54851f8ac7 | ||
|
|
a6c1d07560 | ||
|
|
4fe479453b | ||
|
|
af1bcf1e11 | ||
|
|
05f06d09d8 | ||
|
|
3c0196bfb7 | ||
|
|
dc4c970262 | ||
|
|
aeb0f05c0e | ||
|
|
c016910317 | ||
|
|
5d7f6bf539 | ||
|
|
b818a34f1a | ||
|
|
baa62f4d89 | ||
|
|
b2f07d10aa | ||
|
|
ee2c734c15 | ||
|
|
6e579f027f | ||
|
|
b434c2497f | ||
|
|
94fc413466 | ||
|
|
1c6dbf9bd8 | ||
|
|
88ad575f62 | ||
|
|
5cd30b70e0 | ||
|
|
eb1f395101 | ||
|
|
27bdd547f0 | ||
|
|
75a4bd1d35 | ||
|
|
7c7335c907 |
16
README.md
16
README.md
@@ -10,7 +10,7 @@
|
||||
|
||||
[](https://coveralls.io/github/syoyo/tinyobjloader?branch=master)
|
||||
|
||||
http://syoyo.github.io/tinyobjloader/
|
||||
[https://github.com/syoyo/tinyobjloader](https://github.com/syoyo/tinyobjloader)
|
||||
|
||||
Tiny but powerful single file wavefront obj loader written in C++. No dependency except for C++ STL. It can parse over 10M polygons with moderate memory and time.
|
||||
|
||||
@@ -58,7 +58,7 @@ TinyObjLoader is successfully used in ...
|
||||
* cudabox: CUDA Solid Voxelizer Engine https://github.com/gaspardzoss/cudavox
|
||||
* Drake: A planning, control, and analysis toolbox for nonlinear dynamical systems https://github.com/RobotLocomotion/drake
|
||||
* VFPR - a Vulkan Forward Plus Renderer : https://github.com/WindyDarian/Vulkan-Forward-Plus-Renderer
|
||||
* Your project here!
|
||||
* Your project here! (Letting us know via github issue is welcome!)
|
||||
|
||||
### Old version(v0.9.x)
|
||||
|
||||
@@ -89,6 +89,7 @@ TinyObjLoader is successfully used in ...
|
||||
|
||||
* Group(parse multiple group name)
|
||||
* Vertex
|
||||
* Vertex color(as an extension: https://blender.stackexchange.com/questions/31997/how-can-i-get-vertex-painted-obj-files-to-import-into-blender)
|
||||
* Texcoord
|
||||
* Normal
|
||||
* Material
|
||||
@@ -139,6 +140,13 @@ attrib_t::texcoords => 2 floats per vertex
|
||||
| u | v | u | v | u | v | u | v | .... | u | v |
|
||||
+-----------+-----------+-----------+-----------+ +-----------+
|
||||
|
||||
attrib_t::colors => 3 floats per vertex(vertex color. optional)
|
||||
|
||||
c[0] c[1] c[2] c[3] c[n-1]
|
||||
+-----------+-----------+-----------+-----------+ +-----------+
|
||||
| x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z |
|
||||
+-----------+-----------+-----------+-----------+ +-----------+
|
||||
|
||||
```
|
||||
|
||||
Each `shape_t::mesh_t` does not contain vertex data but contains array index to `attrib_t`.
|
||||
@@ -228,6 +236,10 @@ for (size_t s = 0; s < shapes.size(); s++) {
|
||||
tinyobj::real_t nz = attrib.normals[3*idx.normal_index+2];
|
||||
tinyobj::real_t tx = attrib.texcoords[2*idx.texcoord_index+0];
|
||||
tinyobj::real_t ty = attrib.texcoords[2*idx.texcoord_index+1];
|
||||
// Optional: vertex colors
|
||||
// tinyobj::real_t red = attrib.colors[3*idx.vertex_index+0];
|
||||
// tinyobj::real_t green = attrib.colors[3*idx.vertex_index+1];
|
||||
// tinyobj::real_t blue = attrib.colors[3*idx.vertex_index+2];
|
||||
}
|
||||
index_offset += fv;
|
||||
|
||||
|
||||
@@ -361,7 +361,7 @@ static bool TestStreamLoadObj() {
|
||||
virtual ~MaterialStringStreamReader() {}
|
||||
virtual bool operator()(const std::string& matId,
|
||||
std::vector<material_t>* materials,
|
||||
std::map<std::string, int>* matMap,
|
||||
std::map<unsigned int, int>* matMap,
|
||||
std::string* err) {
|
||||
(void)matId;
|
||||
std::string warning;
|
||||
|
||||
31
models/cube-vertexcol.obj
Normal file
31
models/cube-vertexcol.obj
Normal file
@@ -0,0 +1,31 @@
|
||||
mtllib cube.mtl
|
||||
|
||||
v 0.000000 2.000000 2.000000 0 0 0
|
||||
v 0.000000 0.000000 2.000000 0 0 1
|
||||
v 2.000000 0.000000 2.000000 0 1 0
|
||||
v 2.000000 2.000000 2.000000 0 1 1
|
||||
v 0.000000 2.000000 0.000000 1 0 0
|
||||
v 0.000000 0.000000 0.000000 1 0 1
|
||||
v 2.000000 0.000000 0.000000 1 1 0
|
||||
v 2.000000 2.000000 0.000000 1 1 1
|
||||
# 8 vertices
|
||||
|
||||
g front cube
|
||||
usemtl white
|
||||
f 1 2 3 4
|
||||
g back cube
|
||||
# expects white material
|
||||
f 8 7 6 5
|
||||
g right cube
|
||||
usemtl red
|
||||
f 4 3 7 8
|
||||
g top cube
|
||||
usemtl white
|
||||
f 5 1 4 8
|
||||
g left cube
|
||||
usemtl green
|
||||
f 5 6 2 1
|
||||
g bottom cube
|
||||
usemtl white
|
||||
f 2 6 7 3
|
||||
# 6 elements
|
||||
2
models/issue-140-zero-face-idx.mtl
Normal file
2
models/issue-140-zero-face-idx.mtl
Normal file
@@ -0,0 +1,2 @@
|
||||
newmtl main
|
||||
Kd 1 1 1
|
||||
17
models/issue-140-zero-face-idx.obj
Normal file
17
models/issue-140-zero-face-idx.obj
Normal file
@@ -0,0 +1,17 @@
|
||||
mtllib issue-140-zero-face-idx.mtl
|
||||
|
||||
v -0.5 -0.5 0
|
||||
v 0.5 -0.5 0
|
||||
v 0.5 0.5 0
|
||||
v -0.5 0.5 0
|
||||
|
||||
vt 0 0 0
|
||||
vt 1 0 0
|
||||
vt 1 1 0
|
||||
vt 0 1 0
|
||||
|
||||
vn 0 0 -1
|
||||
|
||||
usemtl main
|
||||
f 0/0/0 1/1/0 3/3/0
|
||||
f 1/1/0 3/3/0 2/2/0
|
||||
7
models/norm-texopt.mtl
Normal file
7
models/norm-texopt.mtl
Normal file
@@ -0,0 +1,7 @@
|
||||
newmtl default
|
||||
Ka 0 0 0
|
||||
Kd 0 0 0
|
||||
Ks 0 0 0
|
||||
Kt 0.1 0.2 0.3
|
||||
norm -bm 3 normalmap.jpg
|
||||
|
||||
7
models/norm-texopt.obj
Normal file
7
models/norm-texopt.obj
Normal file
@@ -0,0 +1,7 @@
|
||||
mtllib norm-texopt.mtl
|
||||
o Test
|
||||
v 1.864151 -1.219172 -5.532511
|
||||
v 0.575869 -0.666304 5.896140
|
||||
v 0.940448 1.000000 -1.971128
|
||||
usemtl default
|
||||
f 1 2 3
|
||||
28
models/texture-filename-with-whitespace.mtl
Normal file
28
models/texture-filename-with-whitespace.mtl
Normal file
@@ -0,0 +1,28 @@
|
||||
newmtl white
|
||||
Ka 0 0 0
|
||||
Kd 1 1 1
|
||||
Ks 0 0 0
|
||||
# filename with white space.
|
||||
map_Kd texture 01.png
|
||||
|
||||
newmtl red
|
||||
Ka 0 0 0
|
||||
Kd 1 0 0
|
||||
Ks 0 0 0
|
||||
# texture option + filename with white space.
|
||||
bump -bm 2 bump 01.png
|
||||
|
||||
newmtl green
|
||||
Ka 0 0 0
|
||||
Kd 0 1 0
|
||||
Ks 0 0 0
|
||||
|
||||
newmtl blue
|
||||
Ka 0 0 0
|
||||
Kd 0 0 1
|
||||
Ks 0 0 0
|
||||
|
||||
newmtl light
|
||||
Ka 20 20 20
|
||||
Kd 1 1 1
|
||||
Ks 0 0 0
|
||||
31
models/texture-filename-with-whitespace.obj
Normal file
31
models/texture-filename-with-whitespace.obj
Normal file
@@ -0,0 +1,31 @@
|
||||
mtllib texture-filename-with-whitespace.mtl
|
||||
|
||||
v 0.000000 2.000000 2.000000
|
||||
v 0.000000 0.000000 2.000000
|
||||
v 2.000000 0.000000 2.000000
|
||||
v 2.000000 2.000000 2.000000
|
||||
v 0.000000 2.000000 0.000000
|
||||
v 0.000000 0.000000 0.000000
|
||||
v 2.000000 0.000000 0.000000
|
||||
v 2.000000 2.000000 0.000000
|
||||
# 8 vertices
|
||||
|
||||
g front cube
|
||||
usemtl white
|
||||
f 1 2 3 4
|
||||
g back cube
|
||||
# expects white material
|
||||
f 8 7 6 5
|
||||
g right cube
|
||||
usemtl red
|
||||
f 4 3 7 8
|
||||
g top cube
|
||||
usemtl white
|
||||
f 5 1 4 8
|
||||
g left cube
|
||||
usemtl green
|
||||
f 5 6 2 1
|
||||
g bottom cube
|
||||
usemtl white
|
||||
f 2 6 7 3
|
||||
# 6 elements
|
||||
@@ -48,7 +48,7 @@ static PyObject* pyLoadObj(PyObject* self, PyObject* args) {
|
||||
|
||||
pyshapes = PyDict_New();
|
||||
pymaterials = PyDict_New();
|
||||
pymaterial_indices = PyDict_New();
|
||||
pymaterial_indices = PyList_New(0);
|
||||
rtndict = PyDict_New();
|
||||
|
||||
attribobj = PyDict_New();
|
||||
@@ -124,53 +124,52 @@ static PyObject* pyLoadObj(PyObject* self, PyObject* args) {
|
||||
PyDict_SetItemString(pyshapes, (*shape).name.c_str(), meshobj);
|
||||
}
|
||||
|
||||
long material_index = 0;
|
||||
for (std::vector<tinyobj::material_t>::iterator mat = materials.begin();
|
||||
mat != materials.end(); mat++) {
|
||||
PyObject* matobj = PyDict_New();
|
||||
PyObject* unknown_parameter = PyDict_New();
|
||||
|
||||
for (std::map<std::string, std::string>::iterator p =
|
||||
(*mat).unknown_parameter.begin();
|
||||
p != (*mat).unknown_parameter.end(); ++p) {
|
||||
mat->unknown_parameter.begin();
|
||||
p != mat->unknown_parameter.end(); ++p) {
|
||||
PyDict_SetItemString(unknown_parameter, p->first.c_str(),
|
||||
PyUnicode_FromString(p->second.c_str()));
|
||||
}
|
||||
|
||||
PyDict_SetItemString(matobj, "shininess",
|
||||
PyFloat_FromDouble((*mat).shininess));
|
||||
PyDict_SetItemString(matobj, "ior", PyFloat_FromDouble((*mat).ior));
|
||||
PyFloat_FromDouble(mat->shininess));
|
||||
PyDict_SetItemString(matobj, "ior", PyFloat_FromDouble(mat->ior));
|
||||
PyDict_SetItemString(matobj, "dissolve",
|
||||
PyFloat_FromDouble((*mat).dissolve));
|
||||
PyDict_SetItemString(matobj, "illum", PyLong_FromLong((*mat).illum));
|
||||
PyFloat_FromDouble(mat->dissolve));
|
||||
PyDict_SetItemString(matobj, "illum", PyLong_FromLong(mat->illum));
|
||||
PyDict_SetItemString(matobj, "ambient_texname",
|
||||
PyUnicode_FromString((*mat).ambient_texname.c_str()));
|
||||
PyUnicode_FromString(mat->ambient_texname.c_str()));
|
||||
PyDict_SetItemString(matobj, "diffuse_texname",
|
||||
PyUnicode_FromString((*mat).diffuse_texname.c_str()));
|
||||
PyUnicode_FromString(mat->diffuse_texname.c_str()));
|
||||
PyDict_SetItemString(matobj, "specular_texname",
|
||||
PyUnicode_FromString((*mat).specular_texname.c_str()));
|
||||
PyUnicode_FromString(mat->specular_texname.c_str()));
|
||||
PyDict_SetItemString(
|
||||
matobj, "specular_highlight_texname",
|
||||
PyUnicode_FromString((*mat).specular_highlight_texname.c_str()));
|
||||
PyUnicode_FromString(mat->specular_highlight_texname.c_str()));
|
||||
PyDict_SetItemString(matobj, "bump_texname",
|
||||
PyUnicode_FromString((*mat).bump_texname.c_str()));
|
||||
PyUnicode_FromString(mat->bump_texname.c_str()));
|
||||
PyDict_SetItemString(
|
||||
matobj, "displacement_texname",
|
||||
PyUnicode_FromString((*mat).displacement_texname.c_str()));
|
||||
PyUnicode_FromString(mat->displacement_texname.c_str()));
|
||||
PyDict_SetItemString(matobj, "alpha_texname",
|
||||
PyUnicode_FromString((*mat).alpha_texname.c_str()));
|
||||
PyDict_SetItemString(matobj, "ambient", pyTupleFromfloat3((*mat).ambient));
|
||||
PyDict_SetItemString(matobj, "diffuse", pyTupleFromfloat3((*mat).diffuse));
|
||||
PyUnicode_FromString(mat->alpha_texname.c_str()));
|
||||
PyDict_SetItemString(matobj, "ambient", pyTupleFromfloat3(mat->ambient));
|
||||
PyDict_SetItemString(matobj, "diffuse", pyTupleFromfloat3(mat->diffuse));
|
||||
PyDict_SetItemString(matobj, "specular",
|
||||
pyTupleFromfloat3((*mat).specular));
|
||||
pyTupleFromfloat3(mat->specular));
|
||||
PyDict_SetItemString(matobj, "transmittance",
|
||||
pyTupleFromfloat3((*mat).transmittance));
|
||||
pyTupleFromfloat3(mat->transmittance));
|
||||
PyDict_SetItemString(matobj, "emission",
|
||||
pyTupleFromfloat3((*mat).emission));
|
||||
pyTupleFromfloat3(mat->emission));
|
||||
PyDict_SetItemString(matobj, "unknown_parameter", unknown_parameter);
|
||||
|
||||
PyDict_SetItemString(pymaterials, (*mat).name.c_str(), matobj);
|
||||
PyDict_SetItemString(pymaterial_indices, PyLong_FromLong(material_index++), (*mat).name.c_str());
|
||||
PyDict_SetItemString(pymaterials, mat->name.c_str(), matobj);
|
||||
PyList_Append(pymaterial_indices, PyUnicode_FromString(mat->name.c_str()));
|
||||
}
|
||||
|
||||
PyDict_SetItemString(rtndict, "shapes", pyshapes);
|
||||
|
||||
@@ -303,7 +303,8 @@ std::string matStream(
|
||||
virtual bool operator() (
|
||||
const std::string& matId,
|
||||
std::vector<material_t>* materials,
|
||||
std::map<std::string, int>* matMap,
|
||||
//std::map<std::string, int>* matMap,
|
||||
std::map<uint32_t, int>* matMap,
|
||||
std::string* err)
|
||||
{
|
||||
(void)matId;
|
||||
@@ -625,6 +626,98 @@ TEST_CASE("g_ignored", "[Issue138]") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("vertex-col-ext", "[Issue144]") {
|
||||
tinyobj::attrib_t attrib;
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
|
||||
std::string err;
|
||||
|
||||
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/cube-vertexcol.obj", gMtlBasePath);
|
||||
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
|
||||
//PrintInfo(attrib, shapes, materials);
|
||||
|
||||
REQUIRE(true == ret);
|
||||
REQUIRE((8 * 3) == attrib.colors.size());
|
||||
|
||||
REQUIRE(0 == Approx(attrib.colors[3 * 0 + 0]));
|
||||
REQUIRE(0 == Approx(attrib.colors[3 * 0 + 1]));
|
||||
REQUIRE(0 == Approx(attrib.colors[3 * 0 + 2]));
|
||||
|
||||
REQUIRE(0 == Approx(attrib.colors[3 * 1 + 0]));
|
||||
REQUIRE(0 == Approx(attrib.colors[3 * 1 + 1]));
|
||||
REQUIRE(1 == Approx(attrib.colors[3 * 1 + 2]));
|
||||
|
||||
REQUIRE(1 == Approx(attrib.colors[3 * 4 + 0]));
|
||||
|
||||
REQUIRE(1 == Approx(attrib.colors[3 * 7 + 0]));
|
||||
REQUIRE(1 == Approx(attrib.colors[3 * 7 + 1]));
|
||||
REQUIRE(1 == Approx(attrib.colors[3 * 7 + 2]));
|
||||
}
|
||||
|
||||
TEST_CASE("norm_texopts", "[norm]") {
|
||||
tinyobj::attrib_t attrib;
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
|
||||
std::string err;
|
||||
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/norm-texopt.obj", gMtlBasePath);
|
||||
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
|
||||
REQUIRE(true == ret);
|
||||
REQUIRE(1 == shapes.size());
|
||||
REQUIRE(1 == materials.size());
|
||||
REQUIRE(3.0 == Approx(materials[0].normal_texopt.bump_multiplier));
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("zero-face-idx-value", "[Issue140]") {
|
||||
tinyobj::attrib_t attrib;
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
|
||||
std::string err;
|
||||
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/issue-140-zero-face-idx.obj", gMtlBasePath);
|
||||
|
||||
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(false == ret);
|
||||
REQUIRE(!err.empty());
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("texture-name-whitespace", "[Issue145]") {
|
||||
tinyobj::attrib_t attrib;
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
|
||||
std::string err;
|
||||
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/texture-filename-with-whitespace.obj", gMtlBasePath);
|
||||
|
||||
|
||||
if (!err.empty()) {
|
||||
std::cerr << "[Issue145] " << err << std::endl;
|
||||
}
|
||||
|
||||
REQUIRE(true == ret);
|
||||
REQUIRE(err.empty());
|
||||
REQUIRE(2 < materials.size());
|
||||
|
||||
REQUIRE(0 == materials[0].diffuse_texname.compare("texture 01.png"));
|
||||
REQUIRE(0 == materials[1].bump_texname.compare("bump 01.png"));
|
||||
REQUIRE(2 == Approx(materials[1].bump_texopt.bump_multiplier));
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
int
|
||||
main(
|
||||
|
||||
1850
tiny_obj_loader.h
1850
tiny_obj_loader.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user