Compare commits
123 Commits
sopyer-mas
...
v0.9.20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc42bc47ad | ||
|
|
31611161df | ||
|
|
21c93c51ed | ||
|
|
b48d363dd2 | ||
|
|
0f00a3b3e8 | ||
|
|
ab10b76eda | ||
|
|
cf52401ca7 | ||
|
|
9c1826381c | ||
|
|
7eb029edaf | ||
|
|
d55863ce50 | ||
|
|
ecf1005c72 | ||
|
|
60ba85e9cd | ||
|
|
45b4924c27 | ||
|
|
04a7b206b7 | ||
|
|
4fa6c29e34 | ||
|
|
00ba666e7f | ||
|
|
bc737b613b | ||
|
|
1450980f91 | ||
|
|
f9e253c2f5 | ||
|
|
0889afb2ba | ||
|
|
e8418ccc8a | ||
|
|
1ae9a8ab4b | ||
|
|
5f7d21afeb | ||
|
|
8f58ef5b1d | ||
|
|
12a55a8f71 | ||
|
|
1afdd32131 | ||
|
|
6082a1a4f3 | ||
|
|
41515c8c78 | ||
|
|
968ad8248e | ||
|
|
b3eed44b3e | ||
|
|
6e711298a7 | ||
|
|
9f24c7c38e | ||
|
|
2fcdd32bc3 | ||
|
|
66d96ab3c2 | ||
|
|
0e23d499c7 | ||
|
|
74614d9fd9 | ||
|
|
320a670bc8 | ||
|
|
85d18ea7cd | ||
|
|
783b8c4886 | ||
|
|
3997ecf8e0 | ||
|
|
353d527fe8 | ||
|
|
ec78aa2bd1 | ||
|
|
c1be55ffe2 | ||
|
|
3681c44aa3 | ||
|
|
a13e1d6164 | ||
|
|
4f992f483d | ||
|
|
e7e7eed616 | ||
|
|
e867685194 | ||
|
|
fcad68bf2d | ||
|
|
475bc83ef3 | ||
|
|
7f2092b29f | ||
|
|
d299576eac | ||
|
|
191a7dfdc8 | ||
|
|
870ead273e | ||
|
|
aa07206fc1 | ||
|
|
8329bdd135 | ||
|
|
def9fe7f16 | ||
|
|
82ae20b833 | ||
|
|
164c152216 | ||
|
|
3058419d7d | ||
|
|
6727aeaca1 | ||
|
|
fb361547e5 | ||
|
|
805bd814fa | ||
|
|
1adfc794ae | ||
|
|
a2851fdf17 | ||
|
|
4e9e812b09 | ||
|
|
b963227246 | ||
|
|
a7759a740a | ||
|
|
2c005ddad1 | ||
|
|
42d6bfbafb | ||
|
|
59acd32d0a | ||
|
|
0aab63eb20 | ||
|
|
49e82e2e00 | ||
|
|
7a3e607898 | ||
|
|
d828e7521d | ||
|
|
911f0dd636 | ||
|
|
527000abd6 | ||
|
|
ba5fde9fd5 | ||
|
|
8b8435d436 | ||
|
|
8d300917a3 | ||
|
|
79af31df5a | ||
|
|
e8ed70b15f | ||
|
|
5615af5316 | ||
|
|
4ea1cf0b77 | ||
|
|
9d7012673e | ||
|
|
daaec1c9aa | ||
|
|
28005f9cdf | ||
|
|
32dcf7d535 | ||
|
|
8a384a057b | ||
|
|
32414c27b4 | ||
|
|
f020169c26 | ||
|
|
f0fdaa307d | ||
|
|
743cfcd861 | ||
|
|
285f5b0cfd | ||
|
|
2cceb53214 | ||
|
|
1390f7f707 | ||
|
|
9979275835 | ||
|
|
011e1b3ebd | ||
|
|
f28d2eef88 | ||
|
|
a67a60d19f | ||
|
|
672f252195 | ||
|
|
6796d61d07 | ||
|
|
0a500b77e7 | ||
|
|
5e5095cb8d | ||
|
|
41db59cde5 | ||
|
|
fae5b03e7c | ||
|
|
276c7e151e | ||
|
|
4779593e44 | ||
|
|
b5352a642b | ||
|
|
062f7a1b6d | ||
|
|
c5ed61f358 | ||
|
|
d535310c94 | ||
|
|
9b69811bb6 | ||
|
|
aabdad4bc4 | ||
|
|
9587ad9aee | ||
|
|
93d7232614 | ||
|
|
e5bbda3835 | ||
|
|
f750f3faeb | ||
|
|
c1ed13c36c | ||
|
|
878a6560cd | ||
|
|
80b243092b | ||
|
|
b214cfb4b9 | ||
|
|
b35f4989ad |
7
.clang-format
Normal file
7
.clang-format
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 2
|
||||||
|
TabWidth: 2
|
||||||
|
UseTab: Never
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
Standard: Cpp03
|
||||||
10
.drone.yml
Normal file
10
.drone.yml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
image: syoyo/ubu-dev
|
||||||
|
script:
|
||||||
|
- curl -L -o premake4 https://github.com/syoyo/orebuildenv/blob/master/build/linux/bin/premake4?raw=true
|
||||||
|
- chmod +x ./premake4
|
||||||
|
- ./premake4 gmake
|
||||||
|
- make
|
||||||
|
notify:
|
||||||
|
email:
|
||||||
|
recipients:
|
||||||
|
- syoyo@lighttransport.com
|
||||||
66
.travis.yml
Normal file
66
.travis.yml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
language: cpp
|
||||||
|
sudo: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- addons: &1
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- george-edison55-precise-backports
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
- llvm-toolchain-precise-3.7
|
||||||
|
packages:
|
||||||
|
- cmake
|
||||||
|
- cmake-data
|
||||||
|
- ninja-build
|
||||||
|
- g++-4.9
|
||||||
|
- clang-3.7
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER_VERSION=3.7 BUILD_TYPE=Debug
|
||||||
|
- addons: *1
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER_VERSION=3.7 BUILD_TYPE=Release
|
||||||
|
- addons: &2
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- george-edison55-precise-backports
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- cmake
|
||||||
|
- cmake-data
|
||||||
|
- ninja-build
|
||||||
|
- g++-4.9
|
||||||
|
compiler: gcc
|
||||||
|
env: COMPILER_VERSION=4.9 BUILD_TYPE=Debug
|
||||||
|
- addons: *2
|
||||||
|
compiler: gcc
|
||||||
|
env: COMPILER_VERSION=4.9 BUILD_TYPE=Release
|
||||||
|
- addons: *1
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER_VERSION=3.7 BUILD_TYPE=Debug CFLAGS="-O0 --coverage" CXXFLAGS="-O0
|
||||||
|
--coverage" REPORT_COVERAGE=1
|
||||||
|
before_install:
|
||||||
|
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew upgrade; fi
|
||||||
|
- if [ -n "$REPORT_COVERAGE" ]; then pip install --user cpp-coveralls; fi
|
||||||
|
script:
|
||||||
|
- mkdir build && cd build
|
||||||
|
- export CC="${CC}-${COMPILER_VERSION}"
|
||||||
|
- export CXX="${CXX}-${COMPILER_VERSION}"
|
||||||
|
- ${CC} -v
|
||||||
|
- cmake --version
|
||||||
|
- cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DTINYOBJLOADER_BUILD_TEST_LOADER=On -G Ninja
|
||||||
|
..
|
||||||
|
- ninja
|
||||||
|
- ./test_loader ../cornell_box.obj
|
||||||
|
- if [ -n "$REPORT_COVERAGE" ]; then coveralls -b . -r .. -e examples -e tools -e jni
|
||||||
|
-e python -e images -E ".*CompilerId.*" -E ".*feature_tests.*" ; fi
|
||||||
|
- cd ..
|
||||||
|
deploy:
|
||||||
|
provider: releases
|
||||||
|
api_key:
|
||||||
|
secure: AsXameK4GJn6h6wMmDrKTr7q/o9EI7hX7zWg1W6VaFBQKfkBvOmjJolWimjl6HMoRZ1NpMmK5GDm3zBlTUeABtgVBIyNWgE9vWS39ff6D5iQKcgScFsJkyILt0GikBqbN2pLGQ2t/M1Qh6n1sEIfzqekiCcF5Qvy5yYlYvHtaRGV02QeYAej/xx15/9SMuKTncHhjf63ClYPu8ODid7QUegJUvlQUeXoPsBDbaXMH2uDWoBWF7etX7G2Iob4NE8GX+ZP6dj+Ogi7p4HXThK650mzLL/pUl584EjjY/vePqx0cFhtpiRwvrW8SNPI1aJ1Phwa1enLRUgfS3bnkwQAMw/SCXSK2lnCvkUAXyTgpG03HWrZURj4vhEPXc7qHooO+dsfmi+JanYLaSDyrGpgQznLGjCMnVATimry0KxSufUY8Wt72Wh+nf7N0IgTUCjl32sWnQd/MRZPkxFuaf1h7r9RoH9KZY0yIOV09gABEFCGrOIZA2FcyhC2G26Bc4zyNrfMFpZ2DI76qdcWNdJGkRkpxtH9sGU8JgZu6Em2f1e6+SLgkBsPxbhRk5PwdhA9AXE2p9PmQqhO3jJKusGBZSoHAF7TlwagRY2J01yJxF7ge6zG9U8QuBqs1bB1zdnE34fHWOgs4st3inC+oBDOhvnEg1Nm/qeYVWMBzpwclSg=
|
||||||
|
file: tiny_obj_loader.h
|
||||||
|
all_branches: true
|
||||||
|
on:
|
||||||
|
repo: syoyo/tinyobjloader
|
||||||
|
tags: true
|
||||||
|
skip_cleanup: true
|
||||||
@@ -26,18 +26,26 @@ add_library(tinyobjloader
|
|||||||
${tinyobjloader-Source}
|
${tinyobjloader-Source}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(test ${tinyobjloader-Test-Source})
|
option(TINYOBJLOADER_BUILD_TEST_LOADER "Build Test Loader Application" OFF)
|
||||||
target_link_libraries(test tinyobjloader)
|
|
||||||
|
|
||||||
add_executable(obj_sticher ${tinyobjloader-examples-objsticher})
|
if(TINYOBJLOADER_BUILD_TEST_LOADER)
|
||||||
target_link_libraries(obj_sticher tinyobjloader)
|
add_executable(test_loader ${tinyobjloader-Test-Source})
|
||||||
|
target_link_libraries(test_loader tinyobjloader)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(TINYOBJLOADER_BUILD_OBJ_STICHER "Build OBJ Sticher Application" OFF)
|
||||||
|
if (TINYOBJLOADER_BUILD_OBJ_STICHER)
|
||||||
|
add_executable(obj_sticher ${tinyobjloader-examples-objsticher})
|
||||||
|
target_link_libraries(obj_sticher tinyobjloader)
|
||||||
|
|
||||||
|
install ( TARGETS
|
||||||
|
obj_sticher
|
||||||
|
DESTINATION
|
||||||
|
bin
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
#Installation
|
#Installation
|
||||||
install ( TARGETS
|
|
||||||
obj_sticher
|
|
||||||
DESTINATION
|
|
||||||
bin
|
|
||||||
)
|
|
||||||
install ( TARGETS
|
install ( TARGETS
|
||||||
tinyobjloader
|
tinyobjloader
|
||||||
DESTINATION
|
DESTINATION
|
||||||
|
|||||||
193
README.md
193
README.md
@@ -1,17 +1,32 @@
|
|||||||
tinyobjloader
|
tinyobjloader
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
[](https://gitter.im/syoyo/tinyobjloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
|
[](https://travis-ci.org/syoyo/tinyobjloader)
|
||||||
|
|
||||||
[](https://app.wercker.com/project/bykey/495a3bac400212cdacdeb4dd9397bf4f)
|
[](https://app.wercker.com/project/bykey/495a3bac400212cdacdeb4dd9397bf4f)
|
||||||
|
|
||||||
|
[](https://ci.appveyor.com/project/syoyo/tinyobjloader/branch/master)
|
||||||
|
|
||||||
|
[](https://coveralls.io/github/syoyo/tinyobjloader?branch=master)
|
||||||
|
|
||||||
http://syoyo.github.io/tinyobjloader/
|
http://syoyo.github.io/tinyobjloader/
|
||||||
|
|
||||||
Tiny but poweful single file wavefront obj loader written in C++. No dependency except for C++ STL. It can parse 10M over polygons with moderate memory and time.
|
Tiny but powerful single file wavefront obj loader written in C++. No dependency except for C++ STL. It can parse 10M over polygons with moderate memory and time.
|
||||||
|
|
||||||
|
`tinyobjloader` is good for embedding .obj loader to your (global illumination) renderer ;-)
|
||||||
|
|
||||||
Good for embedding .obj loader to your (global illumination) renderer ;-)
|
|
||||||
|
|
||||||
What's new
|
What's new
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* Jan 29, 2016 : Support n-polygon(no triangulation) and OpenSubdiv crease tag! Thanks dboogert!
|
||||||
|
* Nov 26, 2015 : Now single-header only!.
|
||||||
|
* Nov 08, 2015 : Improved API.
|
||||||
|
* Jun 23, 2015 : Various fixes and added more projects using tinyobjloader. Thanks many contributors!
|
||||||
|
* Mar 03, 2015 : Replace atof() with hand-written parser for robust reading of numeric value. Thanks skurmedel!
|
||||||
|
* Feb 06, 2015 : Fix parsing multi-material object
|
||||||
* Sep 14, 2014 : Add support for multi-material per object/group. Thanks Mykhailo!
|
* Sep 14, 2014 : Add support for multi-material per object/group. Thanks Mykhailo!
|
||||||
* Mar 17, 2014 : Fixed trim newline bugs. Thanks ardneran!
|
* Mar 17, 2014 : Fixed trim newline bugs. Thanks ardneran!
|
||||||
* Apr 29, 2014 : Add API to read .obj from std::istream. Good for reading compressed .obj or connecting to procedural primitive generator. Thanks burnse!
|
* Apr 29, 2014 : Add API to read .obj from std::istream. Good for reading compressed .obj or connecting to procedural primitive generator. Thanks burnse!
|
||||||
@@ -35,8 +50,16 @@ Use case
|
|||||||
TinyObjLoader is successfully used in ...
|
TinyObjLoader is successfully used in ...
|
||||||
|
|
||||||
* bullet3 https://github.com/erwincoumans/bullet3
|
* bullet3 https://github.com/erwincoumans/bullet3
|
||||||
* pbrt-v2 https://https://github.com/mmp/pbrt-v2
|
* pbrt-v2 https://github.com/mmp/pbrt-v2
|
||||||
* OpenGL game engine development http://swarminglogic.com/jotting/2013_10_gamedev01
|
* OpenGL game engine development http://swarminglogic.com/jotting/2013_10_gamedev01
|
||||||
|
* mallie https://lighttransport.github.io/mallie
|
||||||
|
* IBLBaker (Image Based Lighting Baker). http://www.derkreature.com/iblbaker/
|
||||||
|
* Stanford CS148 http://web.stanford.edu/class/cs148/assignments/assignment3.pdf
|
||||||
|
* Awesome Bump http://awesomebump.besaba.com/about/
|
||||||
|
* sdlgl3-wavefront OpenGL .obj viewer https://github.com/chrisliebert/sdlgl3-wavefront
|
||||||
|
* pbrt-v3 https://github.com/mmp/pbrt-v3
|
||||||
|
* cocos2d-x https://github.com/cocos2d/cocos2d-x/
|
||||||
|
* Android Vulkan demo https://github.com/SaschaWillems/Vulkan
|
||||||
* Your project here!
|
* Your project here!
|
||||||
|
|
||||||
Features
|
Features
|
||||||
@@ -47,17 +70,14 @@ Features
|
|||||||
* Texcoord
|
* Texcoord
|
||||||
* Normal
|
* Normal
|
||||||
* Material
|
* Material
|
||||||
* Unknown material attributes are treated as key-value.
|
* Unknown material attributes are returned as key-value(value is string) map.
|
||||||
|
* Crease tag('t'). This is OpenSubdiv specific(not in wavefront .obj specification)
|
||||||
|
|
||||||
Notes
|
|
||||||
-----
|
|
||||||
|
|
||||||
Polygon is converted into triangle.
|
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
----
|
----
|
||||||
|
|
||||||
* Support quad polygon and some tags for OpenSubdiv http://graphics.pixar.com/opensubdiv/
|
* [ ] Support different indices for vertex/normal/texcoord
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
@@ -67,59 +87,108 @@ Licensed under 2 clause BSD.
|
|||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
std::string inputfile = "cornell_box.obj";
|
TinyObjLoader triangulate input .obj by default.
|
||||||
std::vector<tinyobj::shape_t> shapes;
|
```c++
|
||||||
std::vector<tinyobj::material_t> materials;
|
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
|
||||||
|
#include "tiny_obj_loader.h"
|
||||||
std::string err = tinyobj::LoadObj(shapes, materials, inputfile.c_str());
|
|
||||||
|
|
||||||
if (!err.empty()) {
|
|
||||||
std::cerr << err << std::endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
std::string inputfile = "cornell_box.obj";
|
||||||
std::cout << "# of materials : " << materials.size() << std::endl;
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
|
std::vector<tinyobj::material_t> materials;
|
||||||
|
|
||||||
for (size_t i = 0; i < shapes.size(); i++) {
|
std::string err;
|
||||||
printf("shape[%ld].name = %s\n", i, shapes[i].name.c_str());
|
bool ret = tinyobj::LoadObj(shapes, materials, err, inputfile.c_str());
|
||||||
printf("Size of shape[%ld].indices: %ld\n", i, shapes[i].mesh.indices.size());
|
|
||||||
printf("Size of shape[%ld].material_ids: %ld\n", i, shapes[i].mesh.material_ids.size());
|
|
||||||
assert((shapes[i].mesh.indices.size() % 3) == 0);
|
|
||||||
for (size_t f = 0; f < shapes[i].mesh.indices.size() / 3; f++) {
|
|
||||||
printf(" idx[%ld] = %d, %d, %d. mat_id = %d\n", f, shapes[i].mesh.indices[3*f+0], shapes[i].mesh.indices[3*f+1], shapes[i].mesh.indices[3*f+2], shapes[i].mesh.material_ids[f]);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("shape[%ld].vertices: %ld\n", i, shapes[i].mesh.positions.size());
|
|
||||||
assert((shapes[i].mesh.positions.size() % 3) == 0);
|
|
||||||
for (size_t v = 0; v < shapes[i].mesh.positions.size() / 3; v++) {
|
|
||||||
printf(" v[%ld] = (%f, %f, %f)\n", v,
|
|
||||||
shapes[i].mesh.positions[3*v+0],
|
|
||||||
shapes[i].mesh.positions[3*v+1],
|
|
||||||
shapes[i].mesh.positions[3*v+2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < materials.size(); i++) {
|
|
||||||
printf("material[%ld].name = %s\n", i, materials[i].name.c_str());
|
|
||||||
printf(" material.Ka = (%f, %f ,%f)\n", materials[i].ambient[0], materials[i].ambient[1], materials[i].ambient[2]);
|
|
||||||
printf(" material.Kd = (%f, %f ,%f)\n", materials[i].diffuse[0], materials[i].diffuse[1], materials[i].diffuse[2]);
|
|
||||||
printf(" material.Ks = (%f, %f ,%f)\n", materials[i].specular[0], materials[i].specular[1], materials[i].specular[2]);
|
|
||||||
printf(" material.Tr = (%f, %f ,%f)\n", materials[i].transmittance[0], materials[i].transmittance[1], materials[i].transmittance[2]);
|
|
||||||
printf(" material.Ke = (%f, %f ,%f)\n", materials[i].emission[0], materials[i].emission[1], materials[i].emission[2]);
|
|
||||||
printf(" material.Ns = %f\n", materials[i].shininess);
|
|
||||||
printf(" material.Ni = %f\n", materials[i].ior);
|
|
||||||
printf(" material.dissolve = %f\n", materials[i].dissolve);
|
|
||||||
printf(" material.illum = %d\n", materials[i].illum);
|
|
||||||
printf(" material.map_Ka = %s\n", materials[i].ambient_texname.c_str());
|
|
||||||
printf(" material.map_Kd = %s\n", materials[i].diffuse_texname.c_str());
|
|
||||||
printf(" material.map_Ks = %s\n", materials[i].specular_texname.c_str());
|
|
||||||
printf(" material.map_Ns = %s\n", materials[i].normal_texname.c_str());
|
|
||||||
std::map<std::string, std::string>::const_iterator it(materials[i].unknown_parameter.begin());
|
|
||||||
std::map<std::string, std::string>::const_iterator itEnd(materials[i].unknown_parameter.end());
|
|
||||||
for (; it != itEnd; it++) {
|
|
||||||
printf(" material.%s = %s\n", it->first.c_str(), it->second.c_str());
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!err.empty()) { // `err` may contain warning message.
|
||||||
|
std::cerr << err << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
||||||
|
std::cout << "# of materials : " << materials.size() << std::endl;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < shapes.size(); i++) {
|
||||||
|
printf("shape[%ld].name = %s\n", i, shapes[i].name.c_str());
|
||||||
|
printf("Size of shape[%ld].indices: %ld\n", i, shapes[i].mesh.indices.size());
|
||||||
|
printf("Size of shape[%ld].material_ids: %ld\n", i, shapes[i].mesh.material_ids.size());
|
||||||
|
assert((shapes[i].mesh.indices.size() % 3) == 0);
|
||||||
|
for (size_t f = 0; f < shapes[i].mesh.indices.size() / 3; f++) {
|
||||||
|
printf(" idx[%ld] = %d, %d, %d. mat_id = %d\n", f, shapes[i].mesh.indices[3*f+0], shapes[i].mesh.indices[3*f+1], shapes[i].mesh.indices[3*f+2], shapes[i].mesh.material_ids[f]);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("shape[%ld].vertices: %ld\n", i, shapes[i].mesh.positions.size());
|
||||||
|
assert((shapes[i].mesh.positions.size() % 3) == 0);
|
||||||
|
for (size_t v = 0; v < shapes[i].mesh.positions.size() / 3; v++) {
|
||||||
|
printf(" v[%ld] = (%f, %f, %f)\n", v,
|
||||||
|
shapes[i].mesh.positions[3*v+0],
|
||||||
|
shapes[i].mesh.positions[3*v+1],
|
||||||
|
shapes[i].mesh.positions[3*v+2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < materials.size(); i++) {
|
||||||
|
printf("material[%ld].name = %s\n", i, materials[i].name.c_str());
|
||||||
|
printf(" material.Ka = (%f, %f ,%f)\n", materials[i].ambient[0], materials[i].ambient[1], materials[i].ambient[2]);
|
||||||
|
printf(" material.Kd = (%f, %f ,%f)\n", materials[i].diffuse[0], materials[i].diffuse[1], materials[i].diffuse[2]);
|
||||||
|
printf(" material.Ks = (%f, %f ,%f)\n", materials[i].specular[0], materials[i].specular[1], materials[i].specular[2]);
|
||||||
|
printf(" material.Tr = (%f, %f ,%f)\n", materials[i].transmittance[0], materials[i].transmittance[1], materials[i].transmittance[2]);
|
||||||
|
printf(" material.Ke = (%f, %f ,%f)\n", materials[i].emission[0], materials[i].emission[1], materials[i].emission[2]);
|
||||||
|
printf(" material.Ns = %f\n", materials[i].shininess);
|
||||||
|
printf(" material.Ni = %f\n", materials[i].ior);
|
||||||
|
printf(" material.dissolve = %f\n", materials[i].dissolve);
|
||||||
|
printf(" material.illum = %d\n", materials[i].illum);
|
||||||
|
printf(" material.map_Ka = %s\n", materials[i].ambient_texname.c_str());
|
||||||
|
printf(" material.map_Kd = %s\n", materials[i].diffuse_texname.c_str());
|
||||||
|
printf(" material.map_Ks = %s\n", materials[i].specular_texname.c_str());
|
||||||
|
printf(" material.map_Ns = %s\n", materials[i].specular_highlight_texname.c_str());
|
||||||
|
std::map<std::string, std::string>::const_iterator it(materials[i].unknown_parameter.begin());
|
||||||
|
std::map<std::string, std::string>::const_iterator itEnd(materials[i].unknown_parameter.end());
|
||||||
|
for (; it != itEnd; it++) {
|
||||||
|
printf(" material.%s = %s\n", it->first.c_str(), it->second.c_str());
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Reading .obj without triangulation. Use `num_vertices[i]` to iterate over faces(indices). `num_vertices[i]` stores the number of vertices for ith face.
|
||||||
|
```c++
|
||||||
|
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
|
||||||
|
#include "tiny_obj_loader.h"
|
||||||
|
|
||||||
|
std::string inputfile = "cornell_box.obj";
|
||||||
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
|
std::vector<tinyobj::material_t> materials;
|
||||||
|
|
||||||
|
std::string err;
|
||||||
|
bool triangulate = false;
|
||||||
|
bool ret = tinyobj::LoadObj(shapes, materials, err, inputfile.c_str(), triangulate);
|
||||||
|
|
||||||
|
if (!err.empty()) { // `err` may contain warning message.
|
||||||
|
std::cerr << err << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < shapes.size(); i++) {
|
||||||
|
|
||||||
|
size_t indexOffset = 0;
|
||||||
|
for (size_t n = 0; n < shapes[i].mesh.num_vertices.size(); n++) {
|
||||||
|
int ngon = shapes[i].mesh.num_vertices[n];
|
||||||
|
for (size_t f = 0; f < ngon; f++) {
|
||||||
|
unsigend int v = shapes[i].mesh.indices[indexOffset + f];
|
||||||
|
printf(" face[%ld] v[%ld] = (%f, %f, %f)\n", n,
|
||||||
|
shapes[i].mesh.positions[3*v+0],
|
||||||
|
shapes[i].mesh.positions[3*v+1],
|
||||||
|
shapes[i].mesh.positions[3*v+2]);
|
||||||
|
|
||||||
|
}
|
||||||
|
indexOffset += ngon;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
12
appveyor.yml
Normal file
12
appveyor.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
version: 0.9.{build}
|
||||||
|
|
||||||
|
# scripts that runs after repo cloning.
|
||||||
|
install:
|
||||||
|
- vcsetup.bat
|
||||||
|
|
||||||
|
platform: x64
|
||||||
|
configuration: Release
|
||||||
|
|
||||||
|
build:
|
||||||
|
parallel: true
|
||||||
|
project: TinyObjLoaderSolution.sln
|
||||||
16
build.ninja
Normal file
16
build.ninja
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# build.ninja
|
||||||
|
cc = clang
|
||||||
|
cxx = clang++
|
||||||
|
cflags = -Werror -Weverything
|
||||||
|
cxxflags = -Werror -Weverything
|
||||||
|
|
||||||
|
rule compile
|
||||||
|
command = $cxx $cxxflags -c $in -o $out
|
||||||
|
|
||||||
|
rule link
|
||||||
|
command = $cxx $in -o $out
|
||||||
|
|
||||||
|
build test.o: compile test.cc
|
||||||
|
build test: link test.o
|
||||||
|
|
||||||
|
default test
|
||||||
101
catmark_torus_creases0.obj
Normal file
101
catmark_torus_creases0.obj
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2013 Pixar
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||||
|
# with the following modification; you may not use this file except in
|
||||||
|
# compliance with the Apache License and the following modification to it:
|
||||||
|
# Section 6. Trademarks. is deleted and replaced with:
|
||||||
|
#
|
||||||
|
# 6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
# names, trademarks, service marks, or product names of the Licensor
|
||||||
|
# and its affiliates, except as required to comply with Section 4(c) of
|
||||||
|
# the License and to reproduce the content of the NOTICE file.
|
||||||
|
#
|
||||||
|
# You may obtain a copy of the Apache License at
|
||||||
|
#
|
||||||
|
# http:#www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the Apache License with the above modification is
|
||||||
|
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
# KIND, either express or implied. See the Apache License for the specific
|
||||||
|
# language governing permissions and limitations under the Apache License.
|
||||||
|
#
|
||||||
|
# This file uses centimeters as units for non-parametric coordinates.
|
||||||
|
|
||||||
|
v 1.25052 0.517982 0.353553
|
||||||
|
v 0.597239 0.247384 0.353553
|
||||||
|
v 0.597239 0.247384 -0.353553
|
||||||
|
v 1.25052 0.517982 -0.353553
|
||||||
|
v 0.517982 1.25052 0.353553
|
||||||
|
v 0.247384 0.597239 0.353553
|
||||||
|
v 0.247384 0.597239 -0.353553
|
||||||
|
v 0.517982 1.25052 -0.353553
|
||||||
|
v -0.517982 1.25052 0.353553
|
||||||
|
v -0.247384 0.597239 0.353553
|
||||||
|
v -0.247384 0.597239 -0.353553
|
||||||
|
v -0.517982 1.25052 -0.353553
|
||||||
|
v -1.25052 0.517982 0.353553
|
||||||
|
v -0.597239 0.247384 0.353553
|
||||||
|
v -0.597239 0.247384 -0.353553
|
||||||
|
v -1.25052 0.517982 -0.353553
|
||||||
|
v -1.25052 -0.517982 0.353553
|
||||||
|
v -0.597239 -0.247384 0.353553
|
||||||
|
v -0.597239 -0.247384 -0.353553
|
||||||
|
v -1.25052 -0.517982 -0.353553
|
||||||
|
v -0.517982 -1.25052 0.353553
|
||||||
|
v -0.247384 -0.597239 0.353553
|
||||||
|
v -0.247384 -0.597239 -0.353553
|
||||||
|
v -0.517982 -1.25052 -0.353553
|
||||||
|
v 0.517982 -1.25052 0.353553
|
||||||
|
v 0.247384 -0.597239 0.353553
|
||||||
|
v 0.247384 -0.597239 -0.353553
|
||||||
|
v 0.517982 -1.25052 -0.353553
|
||||||
|
v 1.25052 -0.517982 0.353553
|
||||||
|
v 0.597239 -0.247384 0.353553
|
||||||
|
v 0.597239 -0.247384 -0.353553
|
||||||
|
v 1.25052 -0.517982 -0.353553
|
||||||
|
vt 0 0
|
||||||
|
vt 1 0
|
||||||
|
vt 1 1
|
||||||
|
vt 0 1
|
||||||
|
f 5/1/1 6/2/2 2/3/3 1/4/4
|
||||||
|
f 6/1/5 7/2/6 3/3/7 2/4/8
|
||||||
|
f 7/1/9 8/2/10 4/3/11 3/4/12
|
||||||
|
f 8/1/13 5/2/14 1/3/15 4/4/16
|
||||||
|
f 9/1/17 10/2/18 6/3/19 5/4/20
|
||||||
|
f 10/1/21 11/2/22 7/3/23 6/4/24
|
||||||
|
f 11/1/25 12/2/26 8/3/27 7/4/28
|
||||||
|
f 12/1/29 9/2/30 5/3/31 8/4/32
|
||||||
|
f 13/1/33 14/2/34 10/3/35 9/4/36
|
||||||
|
f 14/1/37 15/2/38 11/3/39 10/4/40
|
||||||
|
f 15/1/41 16/2/42 12/3/43 11/4/44
|
||||||
|
f 16/1/45 13/2/46 9/3/47 12/4/48
|
||||||
|
f 17/1/49 18/2/50 14/3/51 13/4/52
|
||||||
|
f 18/1/53 19/2/54 15/3/55 14/4/56
|
||||||
|
f 19/1/57 20/2/58 16/3/59 15/4/60
|
||||||
|
f 20/1/61 17/2/62 13/3/63 16/4/64
|
||||||
|
f 21/1/65 22/2/66 18/3/67 17/4/68
|
||||||
|
f 22/1/69 23/2/70 19/3/71 18/4/72
|
||||||
|
f 23/1/73 24/2/74 20/3/75 19/4/76
|
||||||
|
f 24/1/77 21/2/78 17/3/79 20/4/80
|
||||||
|
f 25/1/81 26/2/82 22/3/83 21/4/84
|
||||||
|
f 26/1/85 27/2/86 23/3/87 22/4/88
|
||||||
|
f 27/1/89 28/2/90 24/3/91 23/4/92
|
||||||
|
f 28/1/93 25/2/94 21/3/95 24/4/96
|
||||||
|
f 29/1/97 30/2/98 26/3/99 25/4/100
|
||||||
|
f 30/1/101 31/2/102 27/3/103 26/4/104
|
||||||
|
f 31/1/105 32/2/106 28/3/107 27/4/108
|
||||||
|
f 32/1/109 29/2/110 25/3/111 28/4/112
|
||||||
|
f 1/1/113 2/2/114 30/3/115 29/4/116
|
||||||
|
f 2/1/117 3/2/118 31/3/119 30/4/120
|
||||||
|
f 3/1/121 4/2/122 32/3/123 31/4/124
|
||||||
|
f 4/1/125 1/2/126 29/3/127 32/4/128
|
||||||
|
t crease 2/1/0 1 5 4.7
|
||||||
|
t crease 2/1/0 5 9 4.7
|
||||||
|
t crease 2/1/0 9 13 4.7
|
||||||
|
t crease 2/1/0 13 17 4.7
|
||||||
|
t crease 2/1/0 17 21 4.7
|
||||||
|
t crease 2/1/0 21 25 4.7
|
||||||
|
t crease 2/1/0 25 29 4.7
|
||||||
|
t crease 2/1/0 29 1 4.7
|
||||||
146
cornell_box_multimaterial.obj
Normal file
146
cornell_box_multimaterial.obj
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
# cornell_box.obj and cornell_box.mtl are grabbed from Intel's embree project.
|
||||||
|
# original cornell box data
|
||||||
|
# comment
|
||||||
|
|
||||||
|
# empty line including some space
|
||||||
|
|
||||||
|
|
||||||
|
mtllib cornell_box.mtl
|
||||||
|
|
||||||
|
o floor
|
||||||
|
usemtl white
|
||||||
|
v 552.8 0.0 0.0
|
||||||
|
v 0.0 0.0 0.0
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
|
||||||
|
f 1 2 3 4
|
||||||
|
f 8 7 6 5
|
||||||
|
f 12 11 10 9
|
||||||
|
|
||||||
|
o light
|
||||||
|
usemtl light
|
||||||
|
v 343.0 548.0 227.0
|
||||||
|
v 343.0 548.0 332.0
|
||||||
|
v 213.0 548.0 332.0
|
||||||
|
v 213.0 548.0 227.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o ceiling
|
||||||
|
usemtl white
|
||||||
|
v 556.0 548.8 0.0
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
v 0.0 548.8 0.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o back_wall
|
||||||
|
usemtl white
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o front_wall
|
||||||
|
usemtl blue
|
||||||
|
v 549.6 0.0 0
|
||||||
|
v 0.0 0.0 0
|
||||||
|
v 0.0 548.8 0
|
||||||
|
v 556.0 548.8 0
|
||||||
|
#f -1 -2 -3 -4
|
||||||
|
|
||||||
|
o green_wall
|
||||||
|
usemtl green
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 0.0 0.0 0.0
|
||||||
|
v 0.0 548.8 0.0
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o red_wall
|
||||||
|
usemtl red
|
||||||
|
v 552.8 0.0 0.0
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
v 556.0 548.8 0.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o short_block
|
||||||
|
usemtl white
|
||||||
|
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o tall_block
|
||||||
|
usemtl white
|
||||||
|
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
usemtl white
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
usemtl green
|
||||||
|
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
@@ -81,13 +81,17 @@ main(
|
|||||||
std::vector<Shape> shapes;
|
std::vector<Shape> shapes;
|
||||||
std::vector<Material> materials;
|
std::vector<Material> materials;
|
||||||
shapes.resize(num_objfiles);
|
shapes.resize(num_objfiles);
|
||||||
|
materials.resize(num_objfiles);
|
||||||
|
|
||||||
for (int i = 0; i < num_objfiles; i++) {
|
for (int i = 0; i < num_objfiles; i++) {
|
||||||
std::cout << "Loading " << argv[i+1] << " ... " << std::flush;
|
std::cout << "Loading " << argv[i+1] << " ... " << std::flush;
|
||||||
|
|
||||||
std::string err = tinyobj::LoadObj(shapes[i], materials[i], argv[i+1]);
|
std::string err;
|
||||||
|
bool ret = tinyobj::LoadObj(shapes[i], materials[i], err, argv[i+1]);
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
|
}
|
||||||
|
if (!ret) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +102,8 @@ main(
|
|||||||
std::vector<tinyobj::material_t> out_material;
|
std::vector<tinyobj::material_t> out_material;
|
||||||
StichObjs(out_shape, out_material, shapes, materials);
|
StichObjs(out_shape, out_material, shapes, materials);
|
||||||
|
|
||||||
bool ret = WriteObj(out_filename, out_shape, out_material);
|
bool coordTransform = true;
|
||||||
|
bool ret = WriteObj(out_filename, out_shape, out_material, coordTransform);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ bool WriteMat(const std::string& filename, const std::vector<tinyobj::material_t
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteObj(const std::string& filename, const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials) {
|
bool WriteObj(const std::string& filename, const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials, bool coordTransform) {
|
||||||
FILE* fp = fopen(filename.c_str(), "w");
|
FILE* fp = fopen(filename.c_str(), "w");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
fprintf(stderr, "Failed to open file [ %s ] for write.\n", filename.c_str());
|
fprintf(stderr, "Failed to open file [ %s ] for write.\n", filename.c_str());
|
||||||
@@ -74,10 +74,17 @@ bool WriteObj(const std::string& filename, const std::vector<tinyobj::shape_t>&
|
|||||||
for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) {
|
for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) {
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
int idx = shapes[i].mesh.indices[3*k+j];
|
int idx = shapes[i].mesh.indices[3*k+j];
|
||||||
fprintf(fp, "v %f %f %f\n",
|
if (coordTransform) {
|
||||||
shapes[i].mesh.positions[3*idx+0],
|
fprintf(fp, "v %f %f %f\n",
|
||||||
shapes[i].mesh.positions[3*idx+1],
|
shapes[i].mesh.positions[3*idx+0],
|
||||||
shapes[i].mesh.positions[3*idx+2]);
|
shapes[i].mesh.positions[3*idx+2],
|
||||||
|
-shapes[i].mesh.positions[3*idx+1]);
|
||||||
|
} else {
|
||||||
|
fprintf(fp, "v %f %f %f\n",
|
||||||
|
shapes[i].mesh.positions[3*idx+0],
|
||||||
|
shapes[i].mesh.positions[3*idx+1],
|
||||||
|
shapes[i].mesh.positions[3*idx+2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,10 +93,17 @@ bool WriteObj(const std::string& filename, const std::vector<tinyobj::shape_t>&
|
|||||||
for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) {
|
for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) {
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
int idx = shapes[i].mesh.indices[3*k+j];
|
int idx = shapes[i].mesh.indices[3*k+j];
|
||||||
fprintf(fp, "vn %f %f %f\n",
|
if (coordTransform) {
|
||||||
shapes[i].mesh.normals[3*idx+0],
|
fprintf(fp, "vn %f %f %f\n",
|
||||||
shapes[i].mesh.normals[3*idx+1],
|
shapes[i].mesh.normals[3*idx+0],
|
||||||
shapes[i].mesh.normals[3*idx+2]);
|
shapes[i].mesh.normals[3*idx+2],
|
||||||
|
-shapes[i].mesh.normals[3*idx+1]);
|
||||||
|
} else {
|
||||||
|
fprintf(fp, "vn %f %f %f\n",
|
||||||
|
shapes[i].mesh.normals[3*idx+0],
|
||||||
|
shapes[i].mesh.normals[3*idx+1],
|
||||||
|
shapes[i].mesh.normals[3*idx+2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,6 +133,10 @@ bool WriteObj(const std::string& filename, const std::vector<tinyobj::shape_t>&
|
|||||||
int v1 = (3*k + 1) + 1 + v_offset;
|
int v1 = (3*k + 1) + 1 + v_offset;
|
||||||
int v2 = (3*k + 2) + 1 + v_offset;
|
int v2 = (3*k + 2) + 1 + v_offset;
|
||||||
|
|
||||||
|
int vt0 = (3*k + 0) + 1 + vt_offset;
|
||||||
|
int vt1 = (3*k + 1) + 1 + vt_offset;
|
||||||
|
int vt2 = (3*k + 2) + 1 + vt_offset;
|
||||||
|
|
||||||
int material_id = shapes[i].mesh.material_ids[k];
|
int material_id = shapes[i].mesh.material_ids[k];
|
||||||
if (material_id != prev_material_id) {
|
if (material_id != prev_material_id) {
|
||||||
std::string material_name = materials[material_id].name;
|
std::string material_name = materials[material_id].name;
|
||||||
@@ -128,7 +146,7 @@ bool WriteObj(const std::string& filename, const std::vector<tinyobj::shape_t>&
|
|||||||
|
|
||||||
if (has_vn && has_vt) {
|
if (has_vn && has_vt) {
|
||||||
fprintf(fp, "f %d/%d/%d %d/%d/%d %d/%d/%d\n",
|
fprintf(fp, "f %d/%d/%d %d/%d/%d %d/%d/%d\n",
|
||||||
v0, v0, v0, v1, v1, v1, v2, v2, v2);
|
v0, vt0, v0, v1, vt1, v1, v2, vt2, v2);
|
||||||
} else if (has_vn && !has_vt) {
|
} else if (has_vn && !has_vt) {
|
||||||
fprintf(fp, "f %d//%d %d//%d %d//%d\n", v0, v0, v1, v1, v2, v2);
|
fprintf(fp, "f %d//%d %d//%d %d//%d\n", v0, v0, v1, v1, v2, v2);
|
||||||
} else if (!has_vn && has_vt) {
|
} else if (!has_vn && has_vt) {
|
||||||
@@ -141,7 +159,7 @@ bool WriteObj(const std::string& filename, const std::vector<tinyobj::shape_t>&
|
|||||||
|
|
||||||
v_offset += shapes[i].mesh.indices.size();
|
v_offset += shapes[i].mesh.indices.size();
|
||||||
//vn_offset += shapes[i].mesh.normals.size() / 3;
|
//vn_offset += shapes[i].mesh.normals.size() / 3;
|
||||||
//vt_offset += shapes[i].mesh.texcoords.size() / 2;
|
vt_offset += shapes[i].mesh.texcoords.size() / 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "../../tiny_obj_loader.h"
|
#include "../../tiny_obj_loader.h"
|
||||||
|
|
||||||
extern bool WriteObj(const std::string& filename, const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials);
|
extern bool WriteObj(const std::string& filename, const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials, bool coordTransform = false);
|
||||||
|
|
||||||
|
|
||||||
#endif // __OBJ_WRITER_H__
|
#endif // __OBJ_WRITER_H__
|
||||||
|
|||||||
12
jni/Android.mk
Normal file
12
jni/Android.mk
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# A simple test for the minimal standard C++ library
|
||||||
|
#
|
||||||
|
|
||||||
|
LOCAL_PATH := $(call my-dir)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := tinyobjloader
|
||||||
|
LOCAL_SRC_FILES := ../tiny_obj_loader.cc ../test.cc
|
||||||
|
|
||||||
|
LOCAL_C_INCLUDES := ../
|
||||||
|
|
||||||
|
include $(BUILD_EXECUTABLE)
|
||||||
2
jni/Application.mk
Normal file
2
jni/Application.mk
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
APP_ABI := all
|
||||||
|
APP_STL := stlport_static
|
||||||
2
jni/Makefile
Normal file
2
jni/Makefile
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
all:
|
||||||
|
ndk-build
|
||||||
1
jni/README
Normal file
1
jni/README
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Just tests compilation with Android NDK r10.
|
||||||
145
missing_material_file.obj
Normal file
145
missing_material_file.obj
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
# cornell_box.obj and cornell_box.mtl are grabbed from Intel's embree project.
|
||||||
|
# original cornell box data
|
||||||
|
# comment
|
||||||
|
|
||||||
|
# empty line including some space
|
||||||
|
|
||||||
|
|
||||||
|
#mtllib no_material.mtl
|
||||||
|
|
||||||
|
o floor
|
||||||
|
usemtl white
|
||||||
|
v 552.8 0.0 0.0
|
||||||
|
v 0.0 0.0 0.0
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
|
||||||
|
f 1 2 3 4
|
||||||
|
f 8 7 6 5
|
||||||
|
f 12 11 10 9
|
||||||
|
|
||||||
|
o light
|
||||||
|
usemtl light
|
||||||
|
v 343.0 548.0 227.0
|
||||||
|
v 343.0 548.0 332.0
|
||||||
|
v 213.0 548.0 332.0
|
||||||
|
v 213.0 548.0 227.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o ceiling
|
||||||
|
usemtl white
|
||||||
|
v 556.0 548.8 0.0
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
v 0.0 548.8 0.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o back_wall
|
||||||
|
usemtl white
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o front_wall
|
||||||
|
usemtl blue
|
||||||
|
v 549.6 0.0 0
|
||||||
|
v 0.0 0.0 0
|
||||||
|
v 0.0 548.8 0
|
||||||
|
v 556.0 548.8 0
|
||||||
|
#f -1 -2 -3 -4
|
||||||
|
|
||||||
|
o green_wall
|
||||||
|
usemtl green
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 0.0 0.0 0.0
|
||||||
|
v 0.0 548.8 0.0
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o red_wall
|
||||||
|
usemtl red
|
||||||
|
v 552.8 0.0 0.0
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
v 556.0 548.8 0.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o short_block
|
||||||
|
usemtl white
|
||||||
|
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o tall_block
|
||||||
|
usemtl white
|
||||||
|
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
usemtl white
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
133
no_material.obj
Normal file
133
no_material.obj
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
# cornell_box.obj and cornell_box.mtl are grabbed from Intel's embree project.
|
||||||
|
# original cornell box data
|
||||||
|
# comment
|
||||||
|
|
||||||
|
# empty line including some space
|
||||||
|
|
||||||
|
|
||||||
|
o floor
|
||||||
|
v 552.8 0.0 0.0
|
||||||
|
v 0.0 0.0 0.0
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
|
||||||
|
f 1 2 3 4
|
||||||
|
f 8 7 6 5
|
||||||
|
f 12 11 10 9
|
||||||
|
|
||||||
|
o light
|
||||||
|
v 343.0 548.0 227.0
|
||||||
|
v 343.0 548.0 332.0
|
||||||
|
v 213.0 548.0 332.0
|
||||||
|
v 213.0 548.0 227.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o ceiling
|
||||||
|
v 556.0 548.8 0.0
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
v 0.0 548.8 0.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o back_wall
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o front_wall
|
||||||
|
v 549.6 0.0 0
|
||||||
|
v 0.0 0.0 0
|
||||||
|
v 0.0 548.8 0
|
||||||
|
v 556.0 548.8 0
|
||||||
|
#f -1 -2 -3 -4
|
||||||
|
|
||||||
|
o green_wall
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 0.0 0.0 0.0
|
||||||
|
v 0.0 548.8 0.0
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o red_wall
|
||||||
|
v 552.8 0.0 0.0
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
v 556.0 548.8 0.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o short_block
|
||||||
|
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o tall_block
|
||||||
|
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
lib_sources = {
|
|
||||||
"tiny_obj_loader.cc"
|
|
||||||
}
|
|
||||||
|
|
||||||
sources = {
|
sources = {
|
||||||
"test.cc",
|
"test.cc",
|
||||||
}
|
}
|
||||||
@@ -20,7 +16,7 @@ solution "TinyObjLoaderSolution"
|
|||||||
project "tinyobjloader"
|
project "tinyobjloader"
|
||||||
kind "ConsoleApp"
|
kind "ConsoleApp"
|
||||||
language "C++"
|
language "C++"
|
||||||
files { lib_sources, sources }
|
files { sources }
|
||||||
|
|
||||||
configuration "Debug"
|
configuration "Debug"
|
||||||
defines { "DEBUG" } -- -DDEBUG
|
defines { "DEBUG" } -- -DDEBUG
|
||||||
|
|||||||
581
python/cornell_box_multimaterial_output.json
Normal file
581
python/cornell_box_multimaterial_output.json
Normal file
@@ -0,0 +1,581 @@
|
|||||||
|
{
|
||||||
|
"shapes": {
|
||||||
|
"back_wall": {
|
||||||
|
"material_ids": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"normals": [],
|
||||||
|
"positions": [
|
||||||
|
549.5999755859375,
|
||||||
|
0.0,
|
||||||
|
559.2000122070312,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
559.2000122070312,
|
||||||
|
0.0,
|
||||||
|
548.7999877929688,
|
||||||
|
559.2000122070312,
|
||||||
|
556.0,
|
||||||
|
548.7999877929688,
|
||||||
|
559.2000122070312
|
||||||
|
],
|
||||||
|
"indicies": [
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
2.0,
|
||||||
|
0.0,
|
||||||
|
2.0,
|
||||||
|
3.0
|
||||||
|
],
|
||||||
|
"texcoords": []
|
||||||
|
},
|
||||||
|
"floor": {
|
||||||
|
"material_ids": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"normals": [],
|
||||||
|
"positions": [
|
||||||
|
552.7999877929688,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
559.2000122070312,
|
||||||
|
549.5999755859375,
|
||||||
|
0.0,
|
||||||
|
559.2000122070312,
|
||||||
|
290.0,
|
||||||
|
0.0,
|
||||||
|
114.0,
|
||||||
|
240.0,
|
||||||
|
0.0,
|
||||||
|
272.0,
|
||||||
|
82.0,
|
||||||
|
0.0,
|
||||||
|
225.0,
|
||||||
|
130.0,
|
||||||
|
0.0,
|
||||||
|
65.0,
|
||||||
|
472.0,
|
||||||
|
0.0,
|
||||||
|
406.0,
|
||||||
|
314.0,
|
||||||
|
0.0,
|
||||||
|
456.0,
|
||||||
|
265.0,
|
||||||
|
0.0,
|
||||||
|
296.0,
|
||||||
|
423.0,
|
||||||
|
0.0,
|
||||||
|
247.0
|
||||||
|
],
|
||||||
|
"indicies": [
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
2.0,
|
||||||
|
0.0,
|
||||||
|
2.0,
|
||||||
|
3.0,
|
||||||
|
4.0,
|
||||||
|
5.0,
|
||||||
|
6.0,
|
||||||
|
4.0,
|
||||||
|
6.0,
|
||||||
|
7.0,
|
||||||
|
8.0,
|
||||||
|
9.0,
|
||||||
|
10.0,
|
||||||
|
8.0,
|
||||||
|
10.0,
|
||||||
|
11.0
|
||||||
|
],
|
||||||
|
"texcoords": []
|
||||||
|
},
|
||||||
|
"red_wall": {
|
||||||
|
"material_ids": [
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
],
|
||||||
|
"normals": [],
|
||||||
|
"positions": [
|
||||||
|
552.7999877929688,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
549.5999755859375,
|
||||||
|
0.0,
|
||||||
|
559.2000122070312,
|
||||||
|
556.0,
|
||||||
|
548.7999877929688,
|
||||||
|
559.2000122070312,
|
||||||
|
556.0,
|
||||||
|
548.7999877929688,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"indicies": [
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
2.0,
|
||||||
|
0.0,
|
||||||
|
2.0,
|
||||||
|
3.0
|
||||||
|
],
|
||||||
|
"texcoords": []
|
||||||
|
},
|
||||||
|
"light": {
|
||||||
|
"material_ids": [
|
||||||
|
4.0,
|
||||||
|
4.0
|
||||||
|
],
|
||||||
|
"normals": [],
|
||||||
|
"positions": [
|
||||||
|
343.0,
|
||||||
|
548.0,
|
||||||
|
227.0,
|
||||||
|
343.0,
|
||||||
|
548.0,
|
||||||
|
332.0,
|
||||||
|
213.0,
|
||||||
|
548.0,
|
||||||
|
332.0,
|
||||||
|
213.0,
|
||||||
|
548.0,
|
||||||
|
227.0
|
||||||
|
],
|
||||||
|
"indicies": [
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
2.0,
|
||||||
|
0.0,
|
||||||
|
2.0,
|
||||||
|
3.0
|
||||||
|
],
|
||||||
|
"texcoords": []
|
||||||
|
},
|
||||||
|
"tall_block": {
|
||||||
|
"material_ids": [
|
||||||
|
2.0,
|
||||||
|
2.0,
|
||||||
|
2.0,
|
||||||
|
2.0
|
||||||
|
],
|
||||||
|
"normals": [],
|
||||||
|
"positions": [
|
||||||
|
314.0,
|
||||||
|
0.0,
|
||||||
|
456.0,
|
||||||
|
314.0,
|
||||||
|
330.0,
|
||||||
|
456.0,
|
||||||
|
265.0,
|
||||||
|
330.0,
|
||||||
|
296.0,
|
||||||
|
265.0,
|
||||||
|
0.0,
|
||||||
|
296.0,
|
||||||
|
265.0,
|
||||||
|
0.0,
|
||||||
|
296.0,
|
||||||
|
265.0,
|
||||||
|
330.0,
|
||||||
|
296.0,
|
||||||
|
423.0,
|
||||||
|
330.0,
|
||||||
|
247.0,
|
||||||
|
423.0,
|
||||||
|
0.0,
|
||||||
|
247.0
|
||||||
|
],
|
||||||
|
"indicies": [
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
2.0,
|
||||||
|
0.0,
|
||||||
|
2.0,
|
||||||
|
3.0,
|
||||||
|
4.0,
|
||||||
|
5.0,
|
||||||
|
6.0,
|
||||||
|
4.0,
|
||||||
|
6.0,
|
||||||
|
7.0
|
||||||
|
],
|
||||||
|
"texcoords": []
|
||||||
|
},
|
||||||
|
"short_block": {
|
||||||
|
"material_ids": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"normals": [],
|
||||||
|
"positions": [
|
||||||
|
130.0,
|
||||||
|
165.0,
|
||||||
|
65.0,
|
||||||
|
82.0,
|
||||||
|
165.0,
|
||||||
|
225.0,
|
||||||
|
240.0,
|
||||||
|
165.0,
|
||||||
|
272.0,
|
||||||
|
290.0,
|
||||||
|
165.0,
|
||||||
|
114.0,
|
||||||
|
290.0,
|
||||||
|
0.0,
|
||||||
|
114.0,
|
||||||
|
290.0,
|
||||||
|
165.0,
|
||||||
|
114.0,
|
||||||
|
240.0,
|
||||||
|
165.0,
|
||||||
|
272.0,
|
||||||
|
240.0,
|
||||||
|
0.0,
|
||||||
|
272.0,
|
||||||
|
130.0,
|
||||||
|
0.0,
|
||||||
|
65.0,
|
||||||
|
130.0,
|
||||||
|
165.0,
|
||||||
|
65.0,
|
||||||
|
290.0,
|
||||||
|
165.0,
|
||||||
|
114.0,
|
||||||
|
290.0,
|
||||||
|
0.0,
|
||||||
|
114.0,
|
||||||
|
82.0,
|
||||||
|
0.0,
|
||||||
|
225.0,
|
||||||
|
82.0,
|
||||||
|
165.0,
|
||||||
|
225.0,
|
||||||
|
130.0,
|
||||||
|
165.0,
|
||||||
|
65.0,
|
||||||
|
130.0,
|
||||||
|
0.0,
|
||||||
|
65.0,
|
||||||
|
240.0,
|
||||||
|
0.0,
|
||||||
|
272.0,
|
||||||
|
240.0,
|
||||||
|
165.0,
|
||||||
|
272.0,
|
||||||
|
82.0,
|
||||||
|
165.0,
|
||||||
|
225.0,
|
||||||
|
82.0,
|
||||||
|
0.0,
|
||||||
|
225.0
|
||||||
|
],
|
||||||
|
"indicies": [
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
2.0,
|
||||||
|
0.0,
|
||||||
|
2.0,
|
||||||
|
3.0,
|
||||||
|
4.0,
|
||||||
|
5.0,
|
||||||
|
6.0,
|
||||||
|
4.0,
|
||||||
|
6.0,
|
||||||
|
7.0,
|
||||||
|
8.0,
|
||||||
|
9.0,
|
||||||
|
10.0,
|
||||||
|
8.0,
|
||||||
|
10.0,
|
||||||
|
11.0,
|
||||||
|
12.0,
|
||||||
|
13.0,
|
||||||
|
14.0,
|
||||||
|
12.0,
|
||||||
|
14.0,
|
||||||
|
15.0,
|
||||||
|
16.0,
|
||||||
|
17.0,
|
||||||
|
18.0,
|
||||||
|
16.0,
|
||||||
|
18.0,
|
||||||
|
19.0
|
||||||
|
],
|
||||||
|
"texcoords": []
|
||||||
|
},
|
||||||
|
"green_wall": {
|
||||||
|
"material_ids": [
|
||||||
|
2.0,
|
||||||
|
2.0
|
||||||
|
],
|
||||||
|
"normals": [],
|
||||||
|
"positions": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
559.2000122070312,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
548.7999877929688,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
548.7999877929688,
|
||||||
|
559.2000122070312
|
||||||
|
],
|
||||||
|
"indicies": [
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
2.0,
|
||||||
|
0.0,
|
||||||
|
2.0,
|
||||||
|
3.0
|
||||||
|
],
|
||||||
|
"texcoords": []
|
||||||
|
},
|
||||||
|
"ceiling": {
|
||||||
|
"material_ids": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"normals": [],
|
||||||
|
"positions": [
|
||||||
|
556.0,
|
||||||
|
548.7999877929688,
|
||||||
|
0.0,
|
||||||
|
556.0,
|
||||||
|
548.7999877929688,
|
||||||
|
559.2000122070312,
|
||||||
|
0.0,
|
||||||
|
548.7999877929688,
|
||||||
|
559.2000122070312,
|
||||||
|
0.0,
|
||||||
|
548.7999877929688,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"indicies": [
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
2.0,
|
||||||
|
0.0,
|
||||||
|
2.0,
|
||||||
|
3.0
|
||||||
|
],
|
||||||
|
"texcoords": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"materials": {
|
||||||
|
"blue": {
|
||||||
|
"diffuse_texname": "",
|
||||||
|
"ambient_texname": "",
|
||||||
|
"illum": 0,
|
||||||
|
"displacement_texname": "",
|
||||||
|
"alpha_texname": "",
|
||||||
|
"emission": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"transmittance": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"ambient": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"bump_texname": "",
|
||||||
|
"diffuse": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
1.0
|
||||||
|
],
|
||||||
|
"shininess": 1.0,
|
||||||
|
"specular_highlight_texname": "",
|
||||||
|
"unknown_parameter": {},
|
||||||
|
"ior": 1.0,
|
||||||
|
"dissolve": 1.0,
|
||||||
|
"specular": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"specular_texname": ""
|
||||||
|
},
|
||||||
|
"white": {
|
||||||
|
"diffuse_texname": "",
|
||||||
|
"ambient_texname": "",
|
||||||
|
"illum": 0,
|
||||||
|
"displacement_texname": "",
|
||||||
|
"alpha_texname": "",
|
||||||
|
"emission": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"transmittance": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"ambient": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"bump_texname": "",
|
||||||
|
"diffuse": [
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
],
|
||||||
|
"shininess": 1.0,
|
||||||
|
"specular_highlight_texname": "",
|
||||||
|
"unknown_parameter": {},
|
||||||
|
"ior": 1.0,
|
||||||
|
"dissolve": 1.0,
|
||||||
|
"specular": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"specular_texname": ""
|
||||||
|
},
|
||||||
|
"red": {
|
||||||
|
"diffuse_texname": "",
|
||||||
|
"ambient_texname": "",
|
||||||
|
"illum": 0,
|
||||||
|
"displacement_texname": "",
|
||||||
|
"alpha_texname": "",
|
||||||
|
"emission": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"transmittance": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"ambient": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"bump_texname": "",
|
||||||
|
"diffuse": [
|
||||||
|
1.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"shininess": 1.0,
|
||||||
|
"specular_highlight_texname": "",
|
||||||
|
"unknown_parameter": {},
|
||||||
|
"ior": 1.0,
|
||||||
|
"dissolve": 1.0,
|
||||||
|
"specular": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"specular_texname": ""
|
||||||
|
},
|
||||||
|
"light": {
|
||||||
|
"diffuse_texname": "",
|
||||||
|
"ambient_texname": "",
|
||||||
|
"illum": 0,
|
||||||
|
"displacement_texname": "",
|
||||||
|
"alpha_texname": "",
|
||||||
|
"emission": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"transmittance": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"ambient": [
|
||||||
|
20.0,
|
||||||
|
20.0,
|
||||||
|
20.0
|
||||||
|
],
|
||||||
|
"bump_texname": "",
|
||||||
|
"diffuse": [
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
],
|
||||||
|
"shininess": 1.0,
|
||||||
|
"specular_highlight_texname": "",
|
||||||
|
"unknown_parameter": {},
|
||||||
|
"ior": 1.0,
|
||||||
|
"dissolve": 1.0,
|
||||||
|
"specular": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"specular_texname": ""
|
||||||
|
},
|
||||||
|
"green": {
|
||||||
|
"diffuse_texname": "",
|
||||||
|
"ambient_texname": "",
|
||||||
|
"illum": 0,
|
||||||
|
"displacement_texname": "",
|
||||||
|
"alpha_texname": "",
|
||||||
|
"emission": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"transmittance": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"ambient": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"bump_texname": "",
|
||||||
|
"diffuse": [
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"shininess": 1.0,
|
||||||
|
"specular_highlight_texname": "",
|
||||||
|
"unknown_parameter": {},
|
||||||
|
"ior": 1.0,
|
||||||
|
"dissolve": 1.0,
|
||||||
|
"specular": [
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"specular_texname": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
python/howto.py
Normal file
9
python/howto.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import tinyobjloader as tol
|
||||||
|
import json
|
||||||
|
|
||||||
|
model = tol.LoadObj("cornell_box_multimaterial.obj")
|
||||||
|
|
||||||
|
#print(model["shapes"], model["materials"])
|
||||||
|
print( json.dumps(model, indent=4) )
|
||||||
|
|
||||||
|
#see cornell_box_output.json
|
||||||
160
python/main.cpp
Normal file
160
python/main.cpp
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
//python3 module for tinyobjloader
|
||||||
|
//
|
||||||
|
//usage:
|
||||||
|
// import tinyobjloader as tol
|
||||||
|
// model = tol.LoadObj(name)
|
||||||
|
// print(model["shapes"])
|
||||||
|
// print(model["materials"]
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
#include <vector>
|
||||||
|
#include "../tiny_obj_loader.h"
|
||||||
|
|
||||||
|
typedef std::vector<double> vectd;
|
||||||
|
|
||||||
|
PyObject*
|
||||||
|
pyTupleFromfloat3 (float array[3])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
PyObject* tuple = PyTuple_New(3);
|
||||||
|
|
||||||
|
for(i=0; i<=2 ; i++){
|
||||||
|
PyTuple_SetItem(tuple, i, PyFloat_FromDouble(array[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return tuple;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
pyLoadObj(PyObject* self, PyObject* args)
|
||||||
|
{
|
||||||
|
PyObject *rtndict, *pyshapes, *pymaterials,
|
||||||
|
*current, *meshobj;
|
||||||
|
|
||||||
|
char const* filename;
|
||||||
|
char *current_name;
|
||||||
|
vectd vect;
|
||||||
|
|
||||||
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
|
std::vector<tinyobj::material_t> materials;
|
||||||
|
|
||||||
|
if(!PyArg_ParseTuple(args, "s", &filename))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
std::string err;
|
||||||
|
tinyobj::LoadObj(shapes, materials, err, filename);
|
||||||
|
|
||||||
|
pyshapes = PyDict_New();
|
||||||
|
pymaterials = PyDict_New();
|
||||||
|
rtndict = PyDict_New();
|
||||||
|
|
||||||
|
for (std::vector<tinyobj::shape_t>::iterator shape = shapes.begin() ;
|
||||||
|
shape != shapes.end(); shape++)
|
||||||
|
{
|
||||||
|
meshobj = PyDict_New();
|
||||||
|
tinyobj::mesh_t cm = (*shape).mesh;
|
||||||
|
|
||||||
|
for (int i = 0; i <= 4; i++ )
|
||||||
|
{
|
||||||
|
current = PyList_New(0);
|
||||||
|
|
||||||
|
switch(i) {
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
current_name = "positions";
|
||||||
|
vect = vectd(cm.positions.begin(), cm.positions.end()); break;
|
||||||
|
case 1:
|
||||||
|
current_name = "normals";
|
||||||
|
vect = vectd(cm.normals.begin(), cm.normals.end()); break;
|
||||||
|
case 2:
|
||||||
|
current_name = "texcoords";
|
||||||
|
vect = vectd(cm.texcoords.begin(), cm.texcoords.end()); break;
|
||||||
|
case 3:
|
||||||
|
current_name = "indicies";
|
||||||
|
vect = vectd(cm.indices.begin(), cm.indices.end()); break;
|
||||||
|
case 4:
|
||||||
|
current_name = "material_ids";
|
||||||
|
vect = vectd(cm.material_ids.begin(), cm.material_ids.end()); break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (vectd::iterator it = vect.begin() ;
|
||||||
|
it != vect.end(); it++)
|
||||||
|
{
|
||||||
|
PyList_Insert(current, it - vect.begin(), PyFloat_FromDouble(*it));
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDict_SetItemString(meshobj, current_name, current);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDict_SetItemString(pyshapes, (*shape).name.c_str(), meshobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
PyDict_SetItemString(matobj, "dissolve", PyFloat_FromDouble((*mat).dissolve));
|
||||||
|
PyDict_SetItemString(matobj, "illum", PyLong_FromLong((*mat).illum));
|
||||||
|
PyDict_SetItemString(matobj, "ambient_texname", PyUnicode_FromString((*mat).ambient_texname.c_str()));
|
||||||
|
PyDict_SetItemString(matobj, "diffuse_texname", PyUnicode_FromString((*mat).diffuse_texname.c_str()));
|
||||||
|
PyDict_SetItemString(matobj, "specular_texname", PyUnicode_FromString((*mat).specular_texname.c_str()));
|
||||||
|
PyDict_SetItemString(matobj, "specular_highlight_texname", PyUnicode_FromString((*mat).specular_highlight_texname.c_str()));
|
||||||
|
PyDict_SetItemString(matobj, "bump_texname", PyUnicode_FromString((*mat).bump_texname.c_str()));
|
||||||
|
PyDict_SetItemString(matobj, "displacement_texname", 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));
|
||||||
|
PyDict_SetItemString(matobj, "specular", pyTupleFromfloat3((*mat).specular));
|
||||||
|
PyDict_SetItemString(matobj, "transmittance", pyTupleFromfloat3((*mat).transmittance));
|
||||||
|
PyDict_SetItemString(matobj, "emission", pyTupleFromfloat3((*mat).emission));
|
||||||
|
PyDict_SetItemString(matobj, "unknown_parameter", unknown_parameter);
|
||||||
|
|
||||||
|
PyDict_SetItemString(pymaterials, (*mat).name.c_str(), matobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDict_SetItemString(rtndict, "shapes", pyshapes);
|
||||||
|
PyDict_SetItemString(rtndict, "materials", pymaterials);
|
||||||
|
|
||||||
|
return rtndict;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static PyMethodDef mMethods[] = {
|
||||||
|
|
||||||
|
{"LoadObj", pyLoadObj, METH_VARARGS},
|
||||||
|
{NULL, NULL, 0, NULL}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static struct PyModuleDef moduledef = {
|
||||||
|
PyModuleDef_HEAD_INIT,
|
||||||
|
"tinyobjloader",
|
||||||
|
NULL,
|
||||||
|
-1,
|
||||||
|
mMethods
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
PyMODINIT_FUNC
|
||||||
|
PyInit_tinyobjloader(void)
|
||||||
|
{
|
||||||
|
return PyModule_Create(&moduledef);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
13
python/setup.py
Normal file
13
python/setup.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from distutils.core import setup, Extension
|
||||||
|
|
||||||
|
|
||||||
|
m = Extension('tinyobjloader',
|
||||||
|
sources = ['main.cpp', '../tiny_obj_loader.cc'])
|
||||||
|
|
||||||
|
|
||||||
|
setup (name = 'tinyobjloader',
|
||||||
|
version = '0.1',
|
||||||
|
description = 'Python module for tinyobjloader',
|
||||||
|
ext_modules = [m])
|
||||||
|
|
||||||
|
|
||||||
145
test-nan.obj
Normal file
145
test-nan.obj
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
# cornell_box.obj and cornell_box.mtl are grabbed from Intel's embree project.
|
||||||
|
# original cornell box data
|
||||||
|
# comment
|
||||||
|
|
||||||
|
# empty line including some space
|
||||||
|
|
||||||
|
|
||||||
|
mtllib cornell_box.mtl
|
||||||
|
|
||||||
|
o floor
|
||||||
|
usemtl white
|
||||||
|
v nan -nan nan
|
||||||
|
v inf -inf inf
|
||||||
|
v 1.#IND -1.#IND 1.#IND
|
||||||
|
v 1.#INF -1.#INF 1.#INF
|
||||||
|
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
|
||||||
|
f 1 2 3 4
|
||||||
|
f 8 7 6 5
|
||||||
|
f 12 11 10 9
|
||||||
|
|
||||||
|
o light
|
||||||
|
usemtl light
|
||||||
|
v 343.0 548.0 227.0
|
||||||
|
v 343.0 548.0 332.0
|
||||||
|
v 213.0 548.0 332.0
|
||||||
|
v 213.0 548.0 227.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o ceiling
|
||||||
|
usemtl white
|
||||||
|
v 556.0 548.8 0.0
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
v 0.0 548.8 0.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o back_wall
|
||||||
|
usemtl white
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o front_wall
|
||||||
|
usemtl blue
|
||||||
|
v 549.6 0.0 0
|
||||||
|
v 0.0 0.0 0
|
||||||
|
v 0.0 548.8 0
|
||||||
|
v 556.0 548.8 0
|
||||||
|
#f -1 -2 -3 -4
|
||||||
|
|
||||||
|
o green_wall
|
||||||
|
usemtl green
|
||||||
|
v 0.0 0.0 559.2
|
||||||
|
v 0.0 0.0 0.0
|
||||||
|
v 0.0 548.8 0.0
|
||||||
|
v 0.0 548.8 559.2
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o red_wall
|
||||||
|
usemtl red
|
||||||
|
v 552.8 0.0 0.0
|
||||||
|
v 549.6 0.0 559.2
|
||||||
|
v 556.0 548.8 559.2
|
||||||
|
v 556.0 548.8 0.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o short_block
|
||||||
|
usemtl white
|
||||||
|
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 290.0 165.0 114.0
|
||||||
|
v 290.0 0.0 114.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 130.0 165.0 65.0
|
||||||
|
v 130.0 0.0 65.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 240.0 0.0 272.0
|
||||||
|
v 240.0 165.0 272.0
|
||||||
|
v 82.0 165.0 225.0
|
||||||
|
v 82.0 0.0 225.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
o tall_block
|
||||||
|
usemtl white
|
||||||
|
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
usemtl white
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 472.0 0.0 406.0
|
||||||
|
v 472.0 330.0 406.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 314.0 0.0 456.0
|
||||||
|
v 314.0 330.0 456.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
|
v 265.0 0.0 296.0
|
||||||
|
v 265.0 330.0 296.0
|
||||||
|
v 423.0 330.0 247.0
|
||||||
|
v 423.0 0.0 247.0
|
||||||
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
116
test.cc
116
test.cc
@@ -1,3 +1,4 @@
|
|||||||
|
#define TINYOBJLOADER_IMPLEMENTATION
|
||||||
#include "tiny_obj_loader.h"
|
#include "tiny_obj_loader.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -7,7 +8,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
static void PrintInfo(const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials)
|
static void PrintInfo(const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials, bool triangulate = true)
|
||||||
{
|
{
|
||||||
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
||||||
std::cout << "# of materials : " << materials.size() << std::endl;
|
std::cout << "# of materials : " << materials.size() << std::endl;
|
||||||
@@ -15,10 +16,32 @@ static void PrintInfo(const std::vector<tinyobj::shape_t>& shapes, const std::ve
|
|||||||
for (size_t i = 0; i < shapes.size(); i++) {
|
for (size_t i = 0; i < shapes.size(); i++) {
|
||||||
printf("shape[%ld].name = %s\n", i, shapes[i].name.c_str());
|
printf("shape[%ld].name = %s\n", i, shapes[i].name.c_str());
|
||||||
printf("Size of shape[%ld].indices: %ld\n", i, shapes[i].mesh.indices.size());
|
printf("Size of shape[%ld].indices: %ld\n", i, shapes[i].mesh.indices.size());
|
||||||
printf("Size of shape[%ld].material_ids: %ld\n", i, shapes[i].mesh.material_ids.size());
|
|
||||||
assert((shapes[i].mesh.indices.size() % 3) == 0);
|
if (triangulate)
|
||||||
for (size_t f = 0; f < shapes[i].mesh.indices.size() / 3; f++) {
|
{
|
||||||
printf(" idx[%ld] = %d, %d, %d. mat_id = %d\n", f, shapes[i].mesh.indices[3*f+0], shapes[i].mesh.indices[3*f+1], shapes[i].mesh.indices[3*f+2], shapes[i].mesh.material_ids[f]);
|
printf("Size of shape[%ld].material_ids: %ld\n", i, shapes[i].mesh.material_ids.size());
|
||||||
|
assert((shapes[i].mesh.indices.size() % 3) == 0);
|
||||||
|
for (size_t f = 0; f < shapes[i].mesh.indices.size() / 3; f++) {
|
||||||
|
printf(" idx[%ld] = %d, %d, %d. mat_id = %d\n", f, shapes[i].mesh.indices[3*f+0], shapes[i].mesh.indices[3*f+1], shapes[i].mesh.indices[3*f+2], shapes[i].mesh.material_ids[f]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (size_t f = 0; f < shapes[i].mesh.indices.size(); f++) {
|
||||||
|
printf(" idx[%ld] = %d\n", f, shapes[i].mesh.indices[f]);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Size of shape[%ld].material_ids: %ld\n", i, shapes[i].mesh.material_ids.size());
|
||||||
|
assert(shapes[i].mesh.material_ids.size() == shapes[i].mesh.num_vertices.size());
|
||||||
|
for (size_t m = 0; m < shapes[i].mesh.material_ids.size(); m++) {
|
||||||
|
printf(" material_id[%ld] = %d\n", m,
|
||||||
|
shapes[i].mesh.material_ids[m]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("shape[%ld].num_faces: %ld\n", i, shapes[i].mesh.num_vertices.size());
|
||||||
|
for (size_t v = 0; v < shapes[i].mesh.num_vertices.size(); v++) {
|
||||||
|
printf(" num_vertices[%ld] = %ld\n", v,
|
||||||
|
static_cast<long>(shapes[i].mesh.num_vertices[v]));
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("shape[%ld].vertices: %ld\n", i, shapes[i].mesh.positions.size());
|
printf("shape[%ld].vertices: %ld\n", i, shapes[i].mesh.positions.size());
|
||||||
@@ -29,6 +52,44 @@ static void PrintInfo(const std::vector<tinyobj::shape_t>& shapes, const std::ve
|
|||||||
shapes[i].mesh.positions[3*v+1],
|
shapes[i].mesh.positions[3*v+1],
|
||||||
shapes[i].mesh.positions[3*v+2]);
|
shapes[i].mesh.positions[3*v+2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("shape[%ld].num_tags: %ld\n", i, shapes[i].mesh.tags.size());
|
||||||
|
for (size_t t = 0; t < shapes[i].mesh.tags.size(); t++) {
|
||||||
|
printf(" tag[%ld] = %s ", t, shapes[i].mesh.tags[t].name.c_str());
|
||||||
|
printf(" ints: [");
|
||||||
|
for (size_t j = 0; j < shapes[i].mesh.tags[t].intValues.size(); ++j)
|
||||||
|
{
|
||||||
|
printf("%ld", static_cast<long>(shapes[i].mesh.tags[t].intValues[j]));
|
||||||
|
if (j < (shapes[i].mesh.tags[t].intValues.size()-1))
|
||||||
|
{
|
||||||
|
printf(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("]");
|
||||||
|
|
||||||
|
printf(" floats: [");
|
||||||
|
for (size_t j = 0; j < shapes[i].mesh.tags[t].floatValues.size(); ++j)
|
||||||
|
{
|
||||||
|
printf("%f", shapes[i].mesh.tags[t].floatValues[j]);
|
||||||
|
if (j < (shapes[i].mesh.tags[t].floatValues.size()-1))
|
||||||
|
{
|
||||||
|
printf(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("]");
|
||||||
|
|
||||||
|
printf(" strings: [");
|
||||||
|
for (size_t j = 0; j < shapes[i].mesh.tags[t].stringValues.size(); ++j)
|
||||||
|
{
|
||||||
|
printf("%s", shapes[i].mesh.tags[t].stringValues[j].c_str());
|
||||||
|
if (j < (shapes[i].mesh.tags[t].stringValues.size()-1))
|
||||||
|
{
|
||||||
|
printf(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("]");
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < materials.size(); i++) {
|
for (size_t i = 0; i < materials.size(); i++) {
|
||||||
@@ -45,9 +106,13 @@ static void PrintInfo(const std::vector<tinyobj::shape_t>& shapes, const std::ve
|
|||||||
printf(" material.map_Ka = %s\n", materials[i].ambient_texname.c_str());
|
printf(" material.map_Ka = %s\n", materials[i].ambient_texname.c_str());
|
||||||
printf(" material.map_Kd = %s\n", materials[i].diffuse_texname.c_str());
|
printf(" material.map_Kd = %s\n", materials[i].diffuse_texname.c_str());
|
||||||
printf(" material.map_Ks = %s\n", materials[i].specular_texname.c_str());
|
printf(" material.map_Ks = %s\n", materials[i].specular_texname.c_str());
|
||||||
printf(" material.map_Ns = %s\n", materials[i].normal_texname.c_str());
|
printf(" material.map_Ns = %s\n", materials[i].specular_highlight_texname.c_str());
|
||||||
|
printf(" material.map_bump = %s\n", materials[i].bump_texname.c_str());
|
||||||
|
printf(" material.map_d = %s\n", materials[i].alpha_texname.c_str());
|
||||||
|
printf(" material.disp = %s\n", materials[i].displacement_texname.c_str());
|
||||||
std::map<std::string, std::string>::const_iterator it(materials[i].unknown_parameter.begin());
|
std::map<std::string, std::string>::const_iterator it(materials[i].unknown_parameter.begin());
|
||||||
std::map<std::string, std::string>::const_iterator itEnd(materials[i].unknown_parameter.end());
|
std::map<std::string, std::string>::const_iterator itEnd(materials[i].unknown_parameter.end());
|
||||||
|
|
||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
printf(" material.%s = %s\n", it->first.c_str(), it->second.c_str());
|
printf(" material.%s = %s\n", it->first.c_str(), it->second.c_str());
|
||||||
}
|
}
|
||||||
@@ -58,20 +123,27 @@ static void PrintInfo(const std::vector<tinyobj::shape_t>& shapes, const std::ve
|
|||||||
static bool
|
static bool
|
||||||
TestLoadObj(
|
TestLoadObj(
|
||||||
const char* filename,
|
const char* filename,
|
||||||
const char* basepath = NULL)
|
const char* basepath = NULL,
|
||||||
|
bool triangulate = true)
|
||||||
{
|
{
|
||||||
std::cout << "Loading " << filename << std::endl;
|
std::cout << "Loading " << filename << std::endl;
|
||||||
|
|
||||||
std::vector<tinyobj::shape_t> shapes;
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
std::vector<tinyobj::material_t> materials;
|
std::vector<tinyobj::material_t> materials;
|
||||||
std::string err = tinyobj::LoadObj(shapes, materials, filename, basepath);
|
|
||||||
|
std::string err;
|
||||||
|
bool ret = tinyobj::LoadObj(shapes, materials, err, filename, basepath, triangulate);
|
||||||
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
printf("Failed to load/parse .obj.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintInfo(shapes, materials);
|
PrintInfo(shapes, materials, triangulate);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -83,7 +155,7 @@ TestStreamLoadObj()
|
|||||||
std::cout << "Stream Loading " << std::endl;
|
std::cout << "Stream Loading " << std::endl;
|
||||||
|
|
||||||
std::stringstream objStream;
|
std::stringstream objStream;
|
||||||
objStream
|
objStream
|
||||||
<< "mtllib cube.mtl\n"
|
<< "mtllib cube.mtl\n"
|
||||||
"\n"
|
"\n"
|
||||||
"v 0.000000 2.000000 2.000000\n"
|
"v 0.000000 2.000000 2.000000\n"
|
||||||
@@ -116,7 +188,7 @@ TestStreamLoadObj()
|
|||||||
"f 2 6 7 3\n"
|
"f 2 6 7 3\n"
|
||||||
"# 6 elements";
|
"# 6 elements";
|
||||||
|
|
||||||
std::string matStream(
|
std::string matStream(
|
||||||
"newmtl white\n"
|
"newmtl white\n"
|
||||||
"Ka 0 0 0\n"
|
"Ka 0 0 0\n"
|
||||||
"Kd 1 1 1\n"
|
"Kd 1 1 1\n"
|
||||||
@@ -149,25 +221,33 @@ std::string matStream(
|
|||||||
public:
|
public:
|
||||||
MaterialStringStreamReader(const std::string& matSStream): m_matSStream(matSStream) {}
|
MaterialStringStreamReader(const std::string& matSStream): m_matSStream(matSStream) {}
|
||||||
virtual ~MaterialStringStreamReader() {}
|
virtual ~MaterialStringStreamReader() {}
|
||||||
virtual std::string operator() (
|
virtual bool operator() (
|
||||||
const std::string& matId,
|
const std::string& matId,
|
||||||
std::vector<material_t>& materials,
|
std::vector<material_t>& materials,
|
||||||
std::map<std::string, int>& matMap)
|
std::map<std::string, int>& matMap,
|
||||||
|
std::string& err)
|
||||||
{
|
{
|
||||||
return LoadMtl(matMap, materials, m_matSStream);
|
(void)matId;
|
||||||
|
(void)err;
|
||||||
|
LoadMtl(matMap, materials, m_matSStream);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::stringstream m_matSStream;
|
std::stringstream m_matSStream;
|
||||||
};
|
};
|
||||||
|
|
||||||
MaterialStringStreamReader matSSReader(matStream);
|
MaterialStringStreamReader matSSReader(matStream);
|
||||||
std::vector<tinyobj::shape_t> shapes;
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
std::vector<tinyobj::material_t> materials;
|
std::vector<tinyobj::material_t> materials;
|
||||||
std::string err = tinyobj::LoadObj(shapes, materials, objStream, matSSReader);
|
std::string err;
|
||||||
|
bool ret = tinyobj::LoadObj(shapes, materials, err, objStream, matSSReader);
|
||||||
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +261,6 @@ main(
|
|||||||
int argc,
|
int argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
const char* basepath = NULL;
|
const char* basepath = NULL;
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
@@ -192,7 +271,8 @@ main(
|
|||||||
//assert(true == TestLoadObj("cornell_box.obj"));
|
//assert(true == TestLoadObj("cornell_box.obj"));
|
||||||
//assert(true == TestLoadObj("cube.obj"));
|
//assert(true == TestLoadObj("cube.obj"));
|
||||||
assert(true == TestStreamLoadObj());
|
assert(true == TestStreamLoadObj());
|
||||||
|
assert(true == TestLoadObj("catmark_torus_creases0.obj", NULL, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
725
tiny_obj_loader.cc
Executable file → Normal file
725
tiny_obj_loader.cc
Executable file → Normal file
@@ -1,725 +1,2 @@
|
|||||||
//
|
#define TINYOBJLOADER_IMPLEMENTATION
|
||||||
// Copyright 2012-2013, Syoyo Fujita.
|
|
||||||
//
|
|
||||||
// Licensed under 2-clause BSD liecense.
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// version 0.9.7: Support multi-materials(per-face material ID) per object/group.
|
|
||||||
// version 0.9.6: Support Ni(index of refraction) mtl parameter.
|
|
||||||
// Parse transmittance material parameter correctly.
|
|
||||||
// version 0.9.5: Parse multiple group name.
|
|
||||||
// Add support of specifying the base path to load material file.
|
|
||||||
// version 0.9.4: Initial suupport of group tag(g)
|
|
||||||
// version 0.9.3: Fix parsing triple 'x/y/z'
|
|
||||||
// version 0.9.2: Add more .mtl load support
|
|
||||||
// version 0.9.1: Add initial .mtl load support
|
|
||||||
// version 0.9.0: Initial
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "tiny_obj_loader.h"
|
#include "tiny_obj_loader.h"
|
||||||
|
|
||||||
namespace tinyobj {
|
|
||||||
|
|
||||||
struct vertex_index {
|
|
||||||
int v_idx, vt_idx, vn_idx;
|
|
||||||
vertex_index() {};
|
|
||||||
vertex_index(int idx) : v_idx(idx), vt_idx(idx), vn_idx(idx) {};
|
|
||||||
vertex_index(int vidx, int vtidx, int vnidx) : v_idx(vidx), vt_idx(vtidx), vn_idx(vnidx) {};
|
|
||||||
|
|
||||||
};
|
|
||||||
// for std::map
|
|
||||||
static inline bool operator<(const vertex_index& a, const vertex_index& b)
|
|
||||||
{
|
|
||||||
if (a.v_idx != b.v_idx) return (a.v_idx < b.v_idx);
|
|
||||||
if (a.vn_idx != b.vn_idx) return (a.vn_idx < b.vn_idx);
|
|
||||||
if (a.vt_idx != b.vt_idx) return (a.vt_idx < b.vt_idx);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct obj_shape {
|
|
||||||
std::vector<float> v;
|
|
||||||
std::vector<float> vn;
|
|
||||||
std::vector<float> vt;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline bool isSpace(const char c) {
|
|
||||||
return (c == ' ') || (c == '\t');
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool isNewLine(const char c) {
|
|
||||||
return (c == '\r') || (c == '\n') || (c == '\0');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make index zero-base, and also support relative index.
|
|
||||||
static inline int fixIndex(int idx, int n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (idx > 0) {
|
|
||||||
i = idx - 1;
|
|
||||||
} else if (idx == 0) {
|
|
||||||
i = 0;
|
|
||||||
} else { // negative value = relative
|
|
||||||
i = n + idx;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline std::string parseString(const char*& token)
|
|
||||||
{
|
|
||||||
std::string s;
|
|
||||||
int b = strspn(token, " \t");
|
|
||||||
int e = strcspn(token, " \t\r");
|
|
||||||
s = std::string(&token[b], &token[e]);
|
|
||||||
|
|
||||||
token += (e - b);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int parseInt(const char*& token)
|
|
||||||
{
|
|
||||||
token += strspn(token, " \t");
|
|
||||||
int i = atoi(token);
|
|
||||||
token += strcspn(token, " \t\r");
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline float parseFloat(const char*& token)
|
|
||||||
{
|
|
||||||
token += strspn(token, " \t");
|
|
||||||
float f = (float)atof(token);
|
|
||||||
token += strcspn(token, " \t\r");
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void parseFloat2(
|
|
||||||
float& x, float& y,
|
|
||||||
const char*& token)
|
|
||||||
{
|
|
||||||
x = parseFloat(token);
|
|
||||||
y = parseFloat(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void parseFloat3(
|
|
||||||
float& x, float& y, float& z,
|
|
||||||
const char*& token)
|
|
||||||
{
|
|
||||||
x = parseFloat(token);
|
|
||||||
y = parseFloat(token);
|
|
||||||
z = parseFloat(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Parse triples: i, i/j/k, i//k, i/j
|
|
||||||
static vertex_index parseTriple(
|
|
||||||
const char* &token,
|
|
||||||
int vsize,
|
|
||||||
int vnsize,
|
|
||||||
int vtsize)
|
|
||||||
{
|
|
||||||
vertex_index vi(-1);
|
|
||||||
|
|
||||||
vi.v_idx = fixIndex(atoi(token), vsize);
|
|
||||||
token += strcspn(token, "/ \t\r");
|
|
||||||
if (token[0] != '/') {
|
|
||||||
return vi;
|
|
||||||
}
|
|
||||||
token++;
|
|
||||||
|
|
||||||
// i//k
|
|
||||||
if (token[0] == '/') {
|
|
||||||
token++;
|
|
||||||
vi.vn_idx = fixIndex(atoi(token), vnsize);
|
|
||||||
token += strcspn(token, "/ \t\r");
|
|
||||||
return vi;
|
|
||||||
}
|
|
||||||
|
|
||||||
// i/j/k or i/j
|
|
||||||
vi.vt_idx = fixIndex(atoi(token), vtsize);
|
|
||||||
token += strcspn(token, "/ \t\r");
|
|
||||||
if (token[0] != '/') {
|
|
||||||
return vi;
|
|
||||||
}
|
|
||||||
|
|
||||||
// i/j/k
|
|
||||||
token++; // skip '/'
|
|
||||||
vi.vn_idx = fixIndex(atoi(token), vnsize);
|
|
||||||
token += strcspn(token, "/ \t\r");
|
|
||||||
return vi;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned int
|
|
||||||
updateVertex(
|
|
||||||
std::map<vertex_index, unsigned int>& vertexCache,
|
|
||||||
std::vector<float>& positions,
|
|
||||||
std::vector<float>& normals,
|
|
||||||
std::vector<float>& texcoords,
|
|
||||||
const std::vector<float>& in_positions,
|
|
||||||
const std::vector<float>& in_normals,
|
|
||||||
const std::vector<float>& in_texcoords,
|
|
||||||
const vertex_index& i)
|
|
||||||
{
|
|
||||||
const std::map<vertex_index, unsigned int>::iterator it = vertexCache.find(i);
|
|
||||||
|
|
||||||
if (it != vertexCache.end()) {
|
|
||||||
// found cache
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(in_positions.size() > (unsigned int) (3*i.v_idx+2));
|
|
||||||
|
|
||||||
positions.push_back(in_positions[3*i.v_idx+0]);
|
|
||||||
positions.push_back(in_positions[3*i.v_idx+1]);
|
|
||||||
positions.push_back(in_positions[3*i.v_idx+2]);
|
|
||||||
|
|
||||||
if (i.vn_idx >= 0) {
|
|
||||||
normals.push_back(in_normals[3*i.vn_idx+0]);
|
|
||||||
normals.push_back(in_normals[3*i.vn_idx+1]);
|
|
||||||
normals.push_back(in_normals[3*i.vn_idx+2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i.vt_idx >= 0) {
|
|
||||||
texcoords.push_back(in_texcoords[2*i.vt_idx+0]);
|
|
||||||
texcoords.push_back(in_texcoords[2*i.vt_idx+1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int idx = positions.size() / 3 - 1;
|
|
||||||
vertexCache[i] = idx;
|
|
||||||
|
|
||||||
return idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitMaterial(material_t& material) {
|
|
||||||
material.name = "";
|
|
||||||
material.ambient_texname = "";
|
|
||||||
material.diffuse_texname = "";
|
|
||||||
material.specular_texname = "";
|
|
||||||
material.normal_texname = "";
|
|
||||||
for (int i = 0; i < 3; i ++) {
|
|
||||||
material.ambient[i] = 0.f;
|
|
||||||
material.diffuse[i] = 0.f;
|
|
||||||
material.specular[i] = 0.f;
|
|
||||||
material.transmittance[i] = 0.f;
|
|
||||||
material.emission[i] = 0.f;
|
|
||||||
}
|
|
||||||
material.illum = 0;
|
|
||||||
material.dissolve = 1.f;
|
|
||||||
material.shininess = 1.f;
|
|
||||||
material.ior = 1.f;
|
|
||||||
material.unknown_parameter.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
exportFaceGroupToShape(
|
|
||||||
shape_t& shape,
|
|
||||||
std::map<vertex_index, unsigned int> vertexCache,
|
|
||||||
const std::vector<float> &in_positions,
|
|
||||||
const std::vector<float> &in_normals,
|
|
||||||
const std::vector<float> &in_texcoords,
|
|
||||||
const std::vector<std::vector<vertex_index> >& faceGroup,
|
|
||||||
const int material_id,
|
|
||||||
const std::string &name,
|
|
||||||
bool clearCache)
|
|
||||||
{
|
|
||||||
if (faceGroup.empty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t offset;
|
|
||||||
|
|
||||||
offset = shape.mesh.indices.size();
|
|
||||||
|
|
||||||
// Flatten vertices and indices
|
|
||||||
for (size_t i = 0; i < faceGroup.size(); i++) {
|
|
||||||
const std::vector<vertex_index>& face = faceGroup[i];
|
|
||||||
|
|
||||||
vertex_index i0 = face[0];
|
|
||||||
vertex_index i1(-1);
|
|
||||||
vertex_index i2 = face[1];
|
|
||||||
|
|
||||||
size_t npolys = face.size();
|
|
||||||
|
|
||||||
// Polygon -> triangle fan conversion
|
|
||||||
for (size_t k = 2; k < npolys; k++) {
|
|
||||||
i1 = i2;
|
|
||||||
i2 = face[k];
|
|
||||||
|
|
||||||
unsigned int v0 = updateVertex(vertexCache, shape.mesh.positions, shape.mesh.normals, shape.mesh.texcoords, in_positions, in_normals, in_texcoords, i0);
|
|
||||||
unsigned int v1 = updateVertex(vertexCache, shape.mesh.positions, shape.mesh.normals, shape.mesh.texcoords, in_positions, in_normals, in_texcoords, i1);
|
|
||||||
unsigned int v2 = updateVertex(vertexCache, shape.mesh.positions, shape.mesh.normals, shape.mesh.texcoords, in_positions, in_normals, in_texcoords, i2);
|
|
||||||
|
|
||||||
shape.mesh.indices.push_back(v0);
|
|
||||||
shape.mesh.indices.push_back(v1);
|
|
||||||
shape.mesh.indices.push_back(v2);
|
|
||||||
|
|
||||||
shape.mesh.material_ids.push_back(material_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
shape.name = name;
|
|
||||||
|
|
||||||
if (clearCache)
|
|
||||||
vertexCache.clear();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string LoadMtl (
|
|
||||||
std::map<std::string, int>& material_map,
|
|
||||||
std::vector<material_t>& materials,
|
|
||||||
std::istream& inStream)
|
|
||||||
{
|
|
||||||
material_map.clear();
|
|
||||||
std::stringstream err;
|
|
||||||
|
|
||||||
material_t material;
|
|
||||||
|
|
||||||
int maxchars = 8192; // Alloc enough size.
|
|
||||||
std::vector<char> buf(maxchars); // Alloc enough size.
|
|
||||||
while (inStream.peek() != -1) {
|
|
||||||
inStream.getline(&buf[0], maxchars);
|
|
||||||
|
|
||||||
std::string linebuf(&buf[0]);
|
|
||||||
|
|
||||||
// Trim newline '\r\n' or '\n'
|
|
||||||
if (linebuf.size() > 0) {
|
|
||||||
if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1);
|
|
||||||
}
|
|
||||||
if (linebuf.size() > 0) {
|
|
||||||
if (linebuf[linebuf.size()-1] == '\r') linebuf.erase(linebuf.size()-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip if empty line.
|
|
||||||
if (linebuf.empty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip leading space.
|
|
||||||
const char* token = linebuf.c_str();
|
|
||||||
token += strspn(token, " \t");
|
|
||||||
|
|
||||||
assert(token);
|
|
||||||
if (token[0] == '\0') continue; // empty line
|
|
||||||
|
|
||||||
if (token[0] == '#') continue; // comment line
|
|
||||||
|
|
||||||
// new mtl
|
|
||||||
if ((0 == strncmp(token, "newmtl", 6)) && isSpace((token[6]))) {
|
|
||||||
// flush previous material.
|
|
||||||
if (!material.name.empty())
|
|
||||||
{
|
|
||||||
material_map.insert(std::pair<std::string, int>(material.name, materials.size()));
|
|
||||||
materials.push_back(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
// initial temporary material
|
|
||||||
InitMaterial(material);
|
|
||||||
|
|
||||||
// set new mtl name
|
|
||||||
char namebuf[4096];
|
|
||||||
token += 7;
|
|
||||||
sscanf(token, "%s", namebuf);
|
|
||||||
material.name = namebuf;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ambient
|
|
||||||
if (token[0] == 'K' && token[1] == 'a' && isSpace((token[2]))) {
|
|
||||||
token += 2;
|
|
||||||
float r, g, b;
|
|
||||||
parseFloat3(r, g, b, token);
|
|
||||||
material.ambient[0] = r;
|
|
||||||
material.ambient[1] = g;
|
|
||||||
material.ambient[2] = b;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// diffuse
|
|
||||||
if (token[0] == 'K' && token[1] == 'd' && isSpace((token[2]))) {
|
|
||||||
token += 2;
|
|
||||||
float r, g, b;
|
|
||||||
parseFloat3(r, g, b, token);
|
|
||||||
material.diffuse[0] = r;
|
|
||||||
material.diffuse[1] = g;
|
|
||||||
material.diffuse[2] = b;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// specular
|
|
||||||
if (token[0] == 'K' && token[1] == 's' && isSpace((token[2]))) {
|
|
||||||
token += 2;
|
|
||||||
float r, g, b;
|
|
||||||
parseFloat3(r, g, b, token);
|
|
||||||
material.specular[0] = r;
|
|
||||||
material.specular[1] = g;
|
|
||||||
material.specular[2] = b;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// transmittance
|
|
||||||
if (token[0] == 'K' && token[1] == 't' && isSpace((token[2]))) {
|
|
||||||
token += 2;
|
|
||||||
float r, g, b;
|
|
||||||
parseFloat3(r, g, b, token);
|
|
||||||
material.transmittance[0] = r;
|
|
||||||
material.transmittance[1] = g;
|
|
||||||
material.transmittance[2] = b;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ior(index of refraction)
|
|
||||||
if (token[0] == 'N' && token[1] == 'i' && isSpace((token[2]))) {
|
|
||||||
token += 2;
|
|
||||||
material.ior = parseFloat(token);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// emission
|
|
||||||
if(token[0] == 'K' && token[1] == 'e' && isSpace(token[2])) {
|
|
||||||
token += 2;
|
|
||||||
float r, g, b;
|
|
||||||
parseFloat3(r, g, b, token);
|
|
||||||
material.emission[0] = r;
|
|
||||||
material.emission[1] = g;
|
|
||||||
material.emission[2] = b;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// shininess
|
|
||||||
if(token[0] == 'N' && token[1] == 's' && isSpace(token[2])) {
|
|
||||||
token += 2;
|
|
||||||
material.shininess = parseFloat(token);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// illum model
|
|
||||||
if (0 == strncmp(token, "illum", 5) && isSpace(token[5])) {
|
|
||||||
token += 6;
|
|
||||||
material.illum = parseInt(token);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// dissolve
|
|
||||||
if ((token[0] == 'd' && isSpace(token[1]))) {
|
|
||||||
token += 1;
|
|
||||||
material.dissolve = parseFloat(token);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (token[0] == 'T' && token[1] == 'r' && isSpace(token[2])) {
|
|
||||||
token += 2;
|
|
||||||
material.dissolve = parseFloat(token);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ambient texture
|
|
||||||
if ((0 == strncmp(token, "map_Ka", 6)) && isSpace(token[6])) {
|
|
||||||
token += 7;
|
|
||||||
material.ambient_texname = token;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// diffuse texture
|
|
||||||
if ((0 == strncmp(token, "map_Kd", 6)) && isSpace(token[6])) {
|
|
||||||
token += 7;
|
|
||||||
material.diffuse_texname = token;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// specular texture
|
|
||||||
if ((0 == strncmp(token, "map_Ks", 6)) && isSpace(token[6])) {
|
|
||||||
token += 7;
|
|
||||||
material.specular_texname = token;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// normal texture
|
|
||||||
if ((0 == strncmp(token, "map_Ns", 6)) && isSpace(token[6])) {
|
|
||||||
token += 7;
|
|
||||||
material.normal_texname = token;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// unknown parameter
|
|
||||||
const char* _space = strchr(token, ' ');
|
|
||||||
if(!_space) {
|
|
||||||
_space = strchr(token, '\t');
|
|
||||||
}
|
|
||||||
if(_space) {
|
|
||||||
int len = _space - token;
|
|
||||||
std::string key(token, len);
|
|
||||||
std::string value = _space + 1;
|
|
||||||
material.unknown_parameter.insert(std::pair<std::string, std::string>(key, value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// flush last material.
|
|
||||||
material_map.insert(std::pair<std::string, int>(material.name, materials.size()));
|
|
||||||
materials.push_back(material);
|
|
||||||
|
|
||||||
return err.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MaterialFileReader::operator() (
|
|
||||||
const std::string& matId,
|
|
||||||
std::vector<material_t>& materials,
|
|
||||||
std::map<std::string, int>& matMap)
|
|
||||||
{
|
|
||||||
std::string filepath;
|
|
||||||
|
|
||||||
if (!m_mtlBasePath.empty()) {
|
|
||||||
filepath = std::string(m_mtlBasePath) + matId;
|
|
||||||
} else {
|
|
||||||
filepath = matId;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream matIStream(filepath.c_str());
|
|
||||||
return LoadMtl(matMap, materials, matIStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string
|
|
||||||
LoadObj(
|
|
||||||
std::vector<shape_t>& shapes,
|
|
||||||
std::vector<material_t>& materials, // [output]
|
|
||||||
const char* filename,
|
|
||||||
const char* mtl_basepath)
|
|
||||||
{
|
|
||||||
|
|
||||||
shapes.clear();
|
|
||||||
|
|
||||||
std::stringstream err;
|
|
||||||
|
|
||||||
std::ifstream ifs(filename);
|
|
||||||
if (!ifs) {
|
|
||||||
err << "Cannot open file [" << filename << "]" << std::endl;
|
|
||||||
return err.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string basePath;
|
|
||||||
if (mtl_basepath) {
|
|
||||||
basePath = mtl_basepath;
|
|
||||||
}
|
|
||||||
MaterialFileReader matFileReader( basePath );
|
|
||||||
|
|
||||||
return LoadObj(shapes, materials, ifs, matFileReader);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string LoadObj(
|
|
||||||
std::vector<shape_t>& shapes,
|
|
||||||
std::vector<material_t>& materials, // [output]
|
|
||||||
std::istream& inStream,
|
|
||||||
MaterialReader& readMatFn)
|
|
||||||
{
|
|
||||||
std::stringstream err;
|
|
||||||
|
|
||||||
std::vector<float> v;
|
|
||||||
std::vector<float> vn;
|
|
||||||
std::vector<float> vt;
|
|
||||||
std::vector<std::vector<vertex_index> > faceGroup;
|
|
||||||
std::string name;
|
|
||||||
|
|
||||||
// material
|
|
||||||
std::map<std::string, int> material_map;
|
|
||||||
std::map<vertex_index, unsigned int> vertexCache;
|
|
||||||
int material = -1;
|
|
||||||
|
|
||||||
shape_t shape;
|
|
||||||
|
|
||||||
int maxchars = 8192; // Alloc enough size.
|
|
||||||
std::vector<char> buf(maxchars); // Alloc enough size.
|
|
||||||
while (inStream.peek() != -1) {
|
|
||||||
inStream.getline(&buf[0], maxchars);
|
|
||||||
|
|
||||||
std::string linebuf(&buf[0]);
|
|
||||||
|
|
||||||
// Trim newline '\r\n' or '\n'
|
|
||||||
if (linebuf.size() > 0) {
|
|
||||||
if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1);
|
|
||||||
}
|
|
||||||
if (linebuf.size() > 0) {
|
|
||||||
if (linebuf[linebuf.size()-1] == '\r') linebuf.erase(linebuf.size()-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip if empty line.
|
|
||||||
if (linebuf.empty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip leading space.
|
|
||||||
const char* token = linebuf.c_str();
|
|
||||||
token += strspn(token, " \t");
|
|
||||||
|
|
||||||
assert(token);
|
|
||||||
if (token[0] == '\0') continue; // empty line
|
|
||||||
|
|
||||||
if (token[0] == '#') continue; // comment line
|
|
||||||
|
|
||||||
// vertex
|
|
||||||
if (token[0] == 'v' && isSpace((token[1]))) {
|
|
||||||
token += 2;
|
|
||||||
float x, y, z;
|
|
||||||
parseFloat3(x, y, z, token);
|
|
||||||
v.push_back(x);
|
|
||||||
v.push_back(y);
|
|
||||||
v.push_back(z);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// normal
|
|
||||||
if (token[0] == 'v' && token[1] == 'n' && isSpace((token[2]))) {
|
|
||||||
token += 3;
|
|
||||||
float x, y, z;
|
|
||||||
parseFloat3(x, y, z, token);
|
|
||||||
vn.push_back(x);
|
|
||||||
vn.push_back(y);
|
|
||||||
vn.push_back(z);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// texcoord
|
|
||||||
if (token[0] == 'v' && token[1] == 't' && isSpace((token[2]))) {
|
|
||||||
token += 3;
|
|
||||||
float x, y;
|
|
||||||
parseFloat2(x, y, token);
|
|
||||||
vt.push_back(x);
|
|
||||||
vt.push_back(y);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// face
|
|
||||||
if (token[0] == 'f' && isSpace((token[1]))) {
|
|
||||||
token += 2;
|
|
||||||
token += strspn(token, " \t");
|
|
||||||
|
|
||||||
std::vector<vertex_index> face;
|
|
||||||
while (!isNewLine(token[0])) {
|
|
||||||
vertex_index vi = parseTriple(token, v.size() / 3, vn.size() / 3, vt.size() / 2);
|
|
||||||
face.push_back(vi);
|
|
||||||
int n = strspn(token, " \t\r");
|
|
||||||
token += n;
|
|
||||||
}
|
|
||||||
|
|
||||||
faceGroup.push_back(face);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// use mtl
|
|
||||||
if ((0 == strncmp(token, "usemtl", 6)) && isSpace((token[6]))) {
|
|
||||||
|
|
||||||
char namebuf[4096];
|
|
||||||
token += 7;
|
|
||||||
sscanf(token, "%s", namebuf);
|
|
||||||
|
|
||||||
bool ret = exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, material, name, false);
|
|
||||||
faceGroup.clear();
|
|
||||||
|
|
||||||
if (material_map.find(namebuf) != material_map.end()) {
|
|
||||||
material = material_map[namebuf];
|
|
||||||
} else {
|
|
||||||
// { error!! material not found }
|
|
||||||
material = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// load mtl
|
|
||||||
if ((0 == strncmp(token, "mtllib", 6)) && isSpace((token[6]))) {
|
|
||||||
char namebuf[4096];
|
|
||||||
token += 7;
|
|
||||||
sscanf(token, "%s", namebuf);
|
|
||||||
|
|
||||||
std::string err_mtl = readMatFn(namebuf, materials, material_map);
|
|
||||||
if (!err_mtl.empty()) {
|
|
||||||
faceGroup.clear(); // for safety
|
|
||||||
return err_mtl;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// group name
|
|
||||||
if (token[0] == 'g' && isSpace((token[1]))) {
|
|
||||||
|
|
||||||
// flush previous face group.
|
|
||||||
bool ret = exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, material, name, true);
|
|
||||||
if (ret) {
|
|
||||||
shapes.push_back(shape);
|
|
||||||
}
|
|
||||||
|
|
||||||
shape = shape_t();
|
|
||||||
|
|
||||||
//material = -1;
|
|
||||||
faceGroup.clear();
|
|
||||||
|
|
||||||
std::vector<std::string> names;
|
|
||||||
while (!isNewLine(token[0])) {
|
|
||||||
std::string str = parseString(token);
|
|
||||||
names.push_back(str);
|
|
||||||
token += strspn(token, " \t\r"); // skip tag
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(names.size() > 0);
|
|
||||||
|
|
||||||
// names[0] must be 'g', so skipt 0th element.
|
|
||||||
if (names.size() > 1) {
|
|
||||||
name = names[1];
|
|
||||||
} else {
|
|
||||||
name = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// object name
|
|
||||||
if (token[0] == 'o' && isSpace((token[1]))) {
|
|
||||||
|
|
||||||
// flush previous face group.
|
|
||||||
bool ret = exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, material, name, true);
|
|
||||||
if (ret) {
|
|
||||||
shapes.push_back(shape);
|
|
||||||
}
|
|
||||||
|
|
||||||
//material = -1;
|
|
||||||
faceGroup.clear();
|
|
||||||
shape = shape_t();
|
|
||||||
|
|
||||||
// @todo { multiple object name? }
|
|
||||||
char namebuf[4096];
|
|
||||||
token += 2;
|
|
||||||
sscanf(token, "%s", namebuf);
|
|
||||||
name = std::string(namebuf);
|
|
||||||
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore unknown command.
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ret = exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, material, name, true);
|
|
||||||
if (ret) {
|
|
||||||
shapes.push_back(shape);
|
|
||||||
}
|
|
||||||
faceGroup.clear(); // for safety
|
|
||||||
|
|
||||||
return err.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
1177
tiny_obj_loader.h
1177
tiny_obj_loader.h
File diff suppressed because it is too large
Load Diff
BIN
tools/windows/premake5.exe
Normal file
BIN
tools/windows/premake5.exe
Normal file
Binary file not shown.
1
vcsetup.bat
Normal file
1
vcsetup.bat
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.\\tools\\windows\\premake5.exe vs2013
|
||||||
Reference in New Issue
Block a user