70 Commits

Author SHA1 Message Date
Syoyo Fujita
98da6829ac Initial support of parsing curve primitive('curv')
Add clang-format style file.
2015-08-20 18:17:13 +09:00
Syoyo Fujita
aa07206fc1 Suppress double -> float conversion warning. Fixes #50 2015-07-24 11:46:30 +09:00
Syoyo Fujita
8329bdd135 Merge pull request #48 from gitter-badger/gitter-badge
Add a Gitter chat badge to README.md
2015-07-17 01:14:43 +09:00
The Gitter Badger
def9fe7f16 Added Gitter badge 2015-07-16 16:02:50 +00:00
Syoyo Fujita
82ae20b833 +1 version num. 2015-06-25 20:32:46 +09:00
Syoyo Fujita
164c152216 Initialized a material.
Add warning message to `err` when material file not found.
2015-06-25 20:24:24 +09:00
Syoyo Fujita
3058419d7d Update README. Add bugfix notes. 2015-06-23 16:18:29 +09:00
Syoyo Fujita
6727aeaca1 Merge pull request #44 from obviousengineering/oe
Fix groups being ignored if they have 'usemtl' just before 'g'
2015-06-23 16:14:59 +09:00
Ricardo Sánchez-Sáez
fb361547e5 Fix groups being ignored if they have 'usemtl' just before 'g' 2015-06-22 16:14:16 +01:00
Syoyo Fujita
805bd814fa Invert 'Tr'. Fixes #43. 2015-06-20 19:41:41 +09:00
Syoyo Fujita
1adfc794ae Fix sscanf_s seg fault on windows. Fixes #41 2015-06-09 23:49:52 +09:00
Syoyo Fujita
a2851fdf17 Add more links to project using tinyobjloader. 2015-06-08 14:18:35 +09:00
Syoyo Fujita
4e9e812b09 Add Appveyor batch. 2015-06-04 00:06:56 +09:00
Syoyo Fujita
b963227246 Merge branch 'master' of github.com:syoyo/tinyobjloader 2015-06-04 00:02:17 +09:00
Syoyo Fujita
a7759a740a Add Appveyor settings. 2015-06-04 00:01:51 +09:00
Syoyo Fujita
2c005ddad1 Merge pull request #40 from MutterOberin/master
Changed pow function to use double overload
2015-06-02 17:46:38 +09:00
MutterOberin
42d6bfbafb Changed pow function to use double overload 2015-06-01 16:39:36 +02:00
Syoyo Fujita
59acd32d0a Merge pull request #38 from OpenSpace/master
Fix compile warnings under VS 2013 /W4 warning level
2015-05-24 22:19:13 +09:00
Alexander Bock
0aab63eb20 Fixing ptrdiff_t compile error 2015-05-23 22:15:23 +02:00
Alexander Bock
49e82e2e00 Fix compile warnings under VS 2013 /W4 warning level 2015-05-23 22:13:00 +02:00
Syoyo Fujita
7a3e607898 Merge pull request #37 from OpenSpace/master
Add CMake options
2015-05-22 13:37:23 +09:00
Alexander Bock
d828e7521d Add CMake options to toggle the TestLoader application and OBJ Sticher application so that including the project has a smaller footprint 2015-05-21 22:22:59 +02:00
Syoyo Fujita
911f0dd636 Merge pull request #36 from Twinklebear/master
Add support for referencing multiple mtllibs
2015-05-02 15:27:52 +09:00
Will Usher
527000abd6 Add support for referencing multiple mtllibs 2015-05-01 17:32:25 -06:00
Syoyo Fujita
ba5fde9fd5 Remove #28 TODO. 2015-03-03 13:22:56 +09:00
Syoyo Fujita
8b8435d436 Merge branch 'skurmedel-master' 2015-03-03 13:17:28 +09:00
Syoyo Fujita
8d300917a3 Update README.
Bump version 0.9.9.
2015-03-03 13:16:56 +09:00
Syoyo Fujita
79af31df5a Merge branch 'master' of https://github.com/skurmedel/tinyobjloader into skurmedel-master 2015-03-03 12:16:38 +09:00
Syoyo Fujita
e8ed70b15f Merge pull request #33 from expipiplus1/fix-typo
Fix a small typo
2015-03-03 12:13:15 +09:00
Simon Otter
5615af5316 Removed stray parser test file. 2015-03-03 01:39:38 +01:00
Simon Otter
4ea1cf0b77 Implemented a parser and updated tiny_obj_loader.cc to use it unless a define is set. 2015-03-03 01:37:28 +01:00
Joe Hermaszewski
9d7012673e Fix a small typo 2015-02-27 19:58:43 +00:00
Syoyo Fujita
daaec1c9aa Small update. 2015-02-28 01:09:18 +09:00
Syoyo Fujita
28005f9cdf Update copyright year. 2015-02-28 00:47:13 +09:00
Syoyo Fujita
32dcf7d535 Use syoyo/ubu-dev image. 2015-02-27 15:54:04 +09:00
Syoyo Fujita
8a384a057b Update drone.yml 2015-02-27 12:45:44 +09:00
Syoyo Fujita
32414c27b4 Update TODO. 2015-02-27 12:07:02 +09:00
Simon Otter
f020169c26 Created a bunch of tests for the parser, and a spec. 2015-02-23 23:34:16 +01:00
Syoyo Fujita
f0fdaa307d slight change to fixIndex 2015-02-18 12:48:50 +09:00
Syoyo Fujita
743cfcd861 Merge branch 'CoolerExtreme-patch-1' 2015-02-18 12:45:42 +09:00
Syoyo Fujita
285f5b0cfd Merge branch 'patch-1' of https://github.com/CoolerExtreme/tinyobjloader into CoolerExtreme-patch-1
Conflicts:
	tiny_obj_loader.cc
2015-02-18 12:45:34 +09:00
Syoyo Fujita
2cceb53214 Update drone.yml. 2015-02-16 00:47:23 +09:00
Syoyo Fujita
1390f7f707 Fix compilation. 2015-02-15 17:05:57 +09:00
Syoyo Fujita
9979275835 Format source code. 2015-02-15 16:51:38 +09:00
CoolerExtreme
011e1b3ebd Slight typo 2015-02-13 06:37:37 +05:30
CoolerExtreme
f28d2eef88 Fix parseString ? and slight change to fixIndex
function parseString seemed to not increment token after it used strspn to get the length of the whitespace characters at the beginning of token. So strcspn called right after that would return 0 and the created string would be an empty string.

Seems to have been working so far since it gets passed strings that don't begin with whitespace characters.
2015-02-12 23:31:06 +05:30
Syoyo Fujita
a67a60d19f Update README. 2015-02-07 00:04:17 +09:00
Syoyo Fujita
672f252195 Fix per-face material. 2015-02-07 00:01:37 +09:00
Syoyo Fujita
6796d61d07 Merge branch 'master' of github.com:syoyo/tinyobjloader 2015-02-02 17:43:28 +09:00
Syoyo Fujita
0a500b77e7 Small update for README. 2015-02-02 17:43:08 +09:00
Syoyo Fujita
5e5095cb8d Merge pull request #26 from maskman113/master
Fixed cmake warning that targets shouldn't be named test.
2015-01-27 11:25:30 +09:00
Maurice Laveaux
41db59cde5 Fixed cmake warning that targets shouldn't be named test. 2015-01-26 17:32:56 +01:00
Syoyo Fujita
fae5b03e7c Update README. 2015-01-17 23:04:15 +09:00
Syoyo Fujita
276c7e151e Update drone.yml
Add Zup conversion in obj_writer.
2015-01-17 22:37:31 +09:00
Syoyo Fujita
4779593e44 Update drone.yml. 2015-01-17 22:30:02 +09:00
Syoyo Fujita
b5352a642b Add drone.yml 2015-01-17 22:27:20 +09:00
Syoyo Fujita
062f7a1b6d Merge branch 'master' of github.com:syoyo/tinyobjloader 2014-11-30 13:00:05 +09:00
Syoyo Fujita
c5ed61f358 Add link to IBLBaker. 2014-11-30 11:59:55 +09:00
Syoyo Fujita
d535310c94 Merge pull request #24 from Ododo/master
Fix bugs in python module.
2014-11-17 16:28:35 -06:00
Syoyo Fujita
9b69811bb6 Merge branch 'master' of https://github.com/Ododo/tinyobjloader 2014-11-17 16:27:50 -06:00
root
aabdad4bc4 changed to switch structure 2014-11-17 22:06:25 +01:00
root
9587ad9aee cleaning code.. 2014-11-16 23:53:21 +01:00
root
93d7232614 fix shapes / adding setup file 2014-11-16 23:39:20 +01:00
Ododo
e5bbda3835 Update howto.py 2014-11-16 21:08:44 +01:00
root
f750f3faeb adding setup.py file 2014-11-16 19:35:18 +01:00
Syoyo Fujita
c1ed13c36c Merge pull request #23 from Ododo/master
Python interface
2014-11-15 11:54:38 +09:00
root
878a6560cd fix makefile 2014-11-14 15:22:50 +01:00
root
80b243092b base of python module 2014-11-14 14:32:20 +01:00
Julian Simioni
b214cfb4b9 Fix unused variable warnings 2014-10-29 18:54:35 -07:00
Syoyo Fujita
b35f4989ad Add link to mallie. 2014-09-29 19:08:46 +09:00
19 changed files with 2054 additions and 672 deletions

7
.clang-format Normal file
View File

@@ -0,0 +1,7 @@
---
BasedOnStyle: LLVM
IndentWidth: 2
TabWidth: 2
UseTab: Always
BreakBeforeBraces: Attach
Standard: Cpp03

10
.drone.yml Normal file
View 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

View File

@@ -26,18 +26,26 @@ add_library(tinyobjloader
${tinyobjloader-Source}
)
add_executable(test ${tinyobjloader-Test-Source})
target_link_libraries(test tinyobjloader)
option(TINYOBJLOADER_BUILD_TEST_LOADER "Build Test Loader Application" OFF)
add_executable(obj_sticher ${tinyobjloader-examples-objsticher})
target_link_libraries(obj_sticher tinyobjloader)
if(TINYOBJLOADER_BUILD_TEST_LOADER)
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
install ( TARGETS
obj_sticher
DESTINATION
bin
)
install ( TARGETS
tinyobjloader
DESTINATION

View File

@@ -1,17 +1,25 @@
tinyobjloader
=============
[![Join the chat at https://gitter.im/syoyo/tinyobjloader](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/syoyo/tinyobjloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![wercker status](https://app.wercker.com/status/495a3bac400212cdacdeb4dd9397bf4f/m "wercker status")](https://app.wercker.com/project/bykey/495a3bac400212cdacdeb4dd9397bf4f)
[![Build status](https://ci.appveyor.com/api/projects/status/tlb421q3t2oyobcn/branch/master?svg=true)](https://ci.appveyor.com/project/syoyo/tinyobjloader/branch/master)
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.
Good for embedding .obj loader to your (global illumination) renderer ;-)
`tinyobjloader` is good for embedding .obj loader to your (global illumination) renderer ;-)
What's new
----------
* 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!
* 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!
@@ -37,6 +45,12 @@ TinyObjLoader is successfully used in ...
* bullet3 https://github.com/erwincoumans/bullet3
* pbrt-v2 https://https://github.com/mmp/pbrt-v2
* 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://https://github.com/mmp/pbrt-v3
* Your project here!
Features
@@ -47,7 +61,7 @@ Features
* Texcoord
* Normal
* Material
* Unknown material attributes are treated as key-value.
* Unknown material attributes are returned as key-value(value is string) map.
Notes
-----
@@ -57,7 +71,7 @@ Polygon is converted into triangle.
TODO
----
* Support quad polygon and some tags for OpenSubdiv http://graphics.pixar.com/opensubdiv/
- [ ] Support quad polygon and some tags for OpenSubdiv http://graphics.pixar.com/opensubdiv/
License
-------

12
appveyor.yml Normal file
View 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

View 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

View File

@@ -81,6 +81,7 @@ main(
std::vector<Shape> shapes;
std::vector<Material> materials;
shapes.resize(num_objfiles);
materials.resize(num_objfiles);
for (int i = 0; i < num_objfiles; i++) {
std::cout << "Loading " << argv[i+1] << " ... " << std::flush;
@@ -98,7 +99,8 @@ main(
std::vector<tinyobj::material_t> out_material;
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);
return 0;

View File

@@ -38,7 +38,7 @@ bool WriteMat(const std::string& filename, const std::vector<tinyobj::material_t
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");
if (!fp) {
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 (int j = 0; j < 3; j++) {
int idx = shapes[i].mesh.indices[3*k+j];
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]);
if (coordTransform) {
fprintf(fp, "v %f %f %f\n",
shapes[i].mesh.positions[3*idx+0],
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 (int j = 0; j < 3; j++) {
int idx = shapes[i].mesh.indices[3*k+j];
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]);
if (coordTransform) {
fprintf(fp, "vn %f %f %f\n",
shapes[i].mesh.normals[3*idx+0],
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 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];
if (material_id != prev_material_id) {
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) {
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) {
fprintf(fp, "f %d//%d %d//%d %d//%d\n", v0, v0, v1, v1, v2, v2);
} 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();
//vn_offset += shapes[i].mesh.normals.size() / 3;
//vt_offset += shapes[i].mesh.texcoords.size() / 2;
vt_offset += shapes[i].mesh.texcoords.size() / 2;
}

View File

@@ -3,7 +3,7 @@
#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__

View File

@@ -0,0 +1,601 @@
{
"shapes": {
"ceiling": {
"texcoords": [],
"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
],
"material_ids": [
0.0,
0.0
],
"normals": []
},
"floor": {
"texcoords": [],
"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
],
"material_ids": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"normals": []
},
"light": {
"texcoords": [],
"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
],
"material_ids": [
4.0,
4.0
],
"normals": []
},
"green_wall": {
"texcoords": [],
"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
],
"material_ids": [
2.0,
2.0
],
"normals": []
},
"back_wall": {
"texcoords": [],
"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
],
"material_ids": [
0.0,
0.0
],
"normals": []
},
"short_block": {
"texcoords": [],
"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
],
"material_ids": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"normals": []
},
"tall_block": {
"texcoords": [],
"positions": [
423.0,
0.0,
247.0,
423.0,
330.0,
247.0,
472.0,
330.0,
406.0,
472.0,
0.0,
406.0,
472.0,
0.0,
406.0,
472.0,
330.0,
406.0,
314.0,
330.0,
456.0,
314.0,
0.0,
456.0,
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,
8.0,
9.0,
10.0,
8.0,
10.0,
11.0,
12.0,
13.0,
14.0,
12.0,
14.0,
15.0
],
"material_ids": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"normals": []
},
"red_wall": {
"texcoords": [],
"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
],
"material_ids": [
1.0,
1.0
],
"normals": []
}
},
"materials": {
"blue": {
"transmittance": [
0.0,
0.0,
0.0
],
"illum": 0,
"emission": [
0.0,
0.0,
0.0
],
"diffuse_texname": "",
"ambient_texname": "",
"normal_texname": "",
"shininess": 1.0,
"ior": 1.0,
"specular": [
0.0,
0.0,
0.0
],
"specular_texname": "",
"diffuse": [
0.0,
0.0,
1.0
],
"ambient": [
0.0,
0.0,
0.0
],
"dissolve": 1.0
},
"light": {
"transmittance": [
0.0,
0.0,
0.0
],
"illum": 0,
"emission": [
0.0,
0.0,
0.0
],
"diffuse_texname": "",
"ambient_texname": "",
"normal_texname": "",
"shininess": 1.0,
"ior": 1.0,
"specular": [
0.0,
0.0,
0.0
],
"specular_texname": "",
"diffuse": [
1.0,
1.0,
1.0
],
"ambient": [
20.0,
20.0,
20.0
],
"dissolve": 1.0
},
"white": {
"transmittance": [
0.0,
0.0,
0.0
],
"illum": 0,
"emission": [
0.0,
0.0,
0.0
],
"diffuse_texname": "",
"ambient_texname": "",
"normal_texname": "",
"shininess": 1.0,
"ior": 1.0,
"specular": [
0.0,
0.0,
0.0
],
"specular_texname": "",
"diffuse": [
1.0,
1.0,
1.0
],
"ambient": [
0.0,
0.0,
0.0
],
"dissolve": 1.0
},
"green": {
"transmittance": [
0.0,
0.0,
0.0
],
"illum": 0,
"emission": [
0.0,
0.0,
0.0
],
"diffuse_texname": "",
"ambient_texname": "",
"normal_texname": "",
"shininess": 1.0,
"ior": 1.0,
"specular": [
0.0,
0.0,
0.0
],
"specular_texname": "",
"diffuse": [
0.0,
1.0,
0.0
],
"ambient": [
0.0,
0.0,
0.0
],
"dissolve": 1.0
},
"red": {
"transmittance": [
0.0,
0.0,
0.0
],
"illum": 0,
"emission": [
0.0,
0.0,
0.0
],
"diffuse_texname": "",
"ambient_texname": "",
"normal_texname": "",
"shininess": 1.0,
"ior": 1.0,
"specular": [
0.0,
0.0,
0.0
],
"specular_texname": "",
"diffuse": [
1.0,
0.0,
0.0
],
"ambient": [
0.0,
0.0,
0.0
],
"dissolve": 1.0
}
}
}

11
python/howto.py Normal file
View File

@@ -0,0 +1,11 @@
import tinyobjloader as tol
import json
model = tol.LoadObj("cornell_box.obj")
#print(model["shapes"], model["materials"])
print( json.dumps(model, indent=4) )
#see cornell_box_output.json

148
python/main.cpp Normal file
View File

@@ -0,0 +1,148 @@
//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;
tinyobj::LoadObj(shapes, materials, 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();
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, "normal_texname", PyUnicode_FromString((*mat).normal_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(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);
}
}

96
python/pyTOL.cbp.mak Normal file
View File

@@ -0,0 +1,96 @@
#------------------------------------------------------------------------------#
# This makefile was generated by 'cbp2make' tool rev.147 #
#------------------------------------------------------------------------------#
WORKDIR = `pwd`
CC = gcc
CXX = g++
AR = ar
LD = g++
WINDRES = windres
INC =
CFLAGS = -Wall -fexceptions `python3-config --cflags`
RESINC =
LIBDIR =
LIB =
LDFLAGS = `python3-config --ldflags`
INC_DEBUG = $(INC)
CFLAGS_DEBUG = $(CFLAGS) -g
RESINC_DEBUG = $(RESINC)
RCFLAGS_DEBUG = $(RCFLAGS)
LIBDIR_DEBUG = $(LIBDIR)
LIB_DEBUG = $(LIB)
LDFLAGS_DEBUG = $(LDFLAGS)
OBJDIR_DEBUG = obj/Debug
DEP_DEBUG =
OUT_DEBUG = bin/Debug/tinyobjloader.so
INC_RELEASE = $(INC)
CFLAGS_RELEASE = $(CFLAGS) -O2
RESINC_RELEASE = $(RESINC)
RCFLAGS_RELEASE = $(RCFLAGS)
LIBDIR_RELEASE = $(LIBDIR)
LIB_RELEASE = $(LIB)
LDFLAGS_RELEASE = $(LDFLAGS) -s
OBJDIR_RELEASE = obj/Release
DEP_RELEASE =
OUT_RELEASE = bin/Release/tinyobjloader.so
OBJ_DEBUG = $(OBJDIR_DEBUG)/main.o $(OBJDIR_DEBUG)/tiny_obj_loader.o
OBJ_RELEASE = $(OBJDIR_RELEASE)/main.o $(OBJDIR_RELEASE)/tiny_obj_loader.o
all: debug release
clean: clean_debug clean_release
before_debug:
test -d bin/Debug || mkdir -p bin/Debug
test -d $(OBJDIR_DEBUG) || mkdir -p $(OBJDIR_DEBUG)
after_debug:
debug: before_debug out_debug after_debug
out_debug: before_debug $(OBJ_DEBUG) $(DEP_DEBUG)
$(LD) -shared $(LIBDIR_DEBUG) $(OBJ_DEBUG) -o $(OUT_DEBUG) $(LDFLAGS_DEBUG) $(LIB_DEBUG)
$(OBJDIR_DEBUG)/main.o: main.cpp
$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c main.cpp -o $(OBJDIR_DEBUG)/main.o
$(OBJDIR_DEBUG)/tiny_obj_loader.o: ../tiny_obj_loader.cc
$(CC) $(CFLAGS_DEBUG) $(INC_DEBUG) -c ../tiny_obj_loader.cc -o $(OBJDIR_DEBUG)/tiny_obj_loader.o
clean_debug:
rm -f $(OBJ_DEBUG) $(OUT_DEBUG)
rm -rf bin/Debug
rm -rf $(OBJDIR_DEBUG)
before_release:
test -d bin/Release || mkdir -p bin/Release
test -d $(OBJDIR_RELEASE) || mkdir -p $(OBJDIR_RELEASE)
after_release:
release: before_release out_release after_release
out_release: before_release $(OBJ_RELEASE) $(DEP_RELEASE)
$(LD) -shared $(LIBDIR_RELEASE) $(OBJ_RELEASE) -o $(OUT_RELEASE) $(LDFLAGS_RELEASE) $(LIB_RELEASE)
$(OBJDIR_RELEASE)/main.o: main.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c main.cpp -o $(OBJDIR_RELEASE)/main.o
$(OBJDIR_RELEASE)/tiny_obj_loader.o: ../tiny_obj_loader.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ../tiny_obj_loader.cc -o $(OBJDIR_RELEASE)/tiny_obj_loader.o
clean_release:
rm -f $(OBJ_RELEASE) $(OUT_RELEASE)
rm -rf bin/Release
rm -rf $(OBJDIR_RELEASE)
.PHONY: before_debug after_debug clean_debug before_release after_release clean_release

13
python/setup.py Normal file
View 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])

36
test.cc
View File

@@ -7,9 +7,10 @@
#include <sstream>
#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::curve_t>& curves, const std::vector<tinyobj::material_t>& materials)
{
std::cout << "# of shapes : " << shapes.size() << std::endl;
std::cout << "# of curves : " << curves.size() << std::endl;
std::cout << "# of materials : " << materials.size() << std::endl;
for (size_t i = 0; i < shapes.size(); i++) {
@@ -31,6 +32,29 @@ static void PrintInfo(const std::vector<tinyobj::shape_t>& shapes, const std::ve
}
}
for (size_t i = 0; i < curves.size(); i++) {
printf("curve[%ld].name = %s\n", i, curves[i].name.c_str());
printf("Size of curve[%ld].indices: %ld\n", i, curves[i].indices.size());
printf("curves[%ld].vertices: %ld\n", i, curves[i].positions.size());
assert((curves[i].positions.size() % 3) == 0);
for (size_t v = 0; v < curves[i].positions.size() / 3; v++) {
printf(" v[%ld] = (%f, %f, %f)\n", v,
curves[i].positions[3*v+0],
curves[i].positions[3*v+1],
curves[i].positions[3*v+2]);
}
for (size_t v = 0; v < curves[i].u_params.size(); v++) {
printf(" u[%ld] = %f\n", v, curves[i].u_params[v]);
}
for (size_t v = 0; v < curves[i].v_params.size(); v++) {
printf(" u[%ld] = %f\n", v, curves[i].v_params[v]);
}
}
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]);
@@ -63,15 +87,16 @@ TestLoadObj(
std::cout << "Loading " << filename << std::endl;
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::curve_t> curves;
std::vector<tinyobj::material_t> materials;
std::string err = tinyobj::LoadObj(shapes, materials, filename, basepath);
std::string err = tinyobj::LoadObj(shapes, curves, materials, filename, basepath);
if (!err.empty()) {
std::cerr << err << std::endl;
return false;
}
PrintInfo(shapes, materials);
PrintInfo(shapes, curves, materials);
return true;
}
@@ -163,15 +188,16 @@ std::string matStream(
MaterialStringStreamReader matSSReader(matStream);
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::curve_t> curves;
std::vector<tinyobj::material_t> materials;
std::string err = tinyobj::LoadObj(shapes, materials, objStream, matSSReader);
std::string err = tinyobj::LoadObj(shapes, curves, materials, objStream, matSSReader);
if (!err.empty()) {
std::cerr << err << std::endl;
return false;
}
PrintInfo(shapes, materials);
PrintInfo(shapes, curves, materials);
return true;
}

1418
tiny_obj_loader.cc Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
//
// Copyright 2012-2013, Syoyo Fujita.
// Copyright 2012-2015, Syoyo Fujita.
//
// Licensed under 2-clause BSD liecense.
//
@@ -12,96 +12,101 @@
namespace tinyobj {
typedef struct
{
std::string name;
typedef struct {
std::string name;
float ambient[3];
float diffuse[3];
float specular[3];
float transmittance[3];
float emission[3];
float shininess;
float ior; // index of refraction
float dissolve; // 1 == opaque; 0 == fully transparent
// illumination model (see http://www.fileformat.info/format/material/)
int illum;
float ambient[3];
float diffuse[3];
float specular[3];
float transmittance[3];
float emission[3];
float shininess;
float ior; // index of refraction
float dissolve; // 1 == opaque; 0 == fully transparent
// illumination model (see http://www.fileformat.info/format/material/)
int illum;
std::string ambient_texname;
std::string diffuse_texname;
std::string specular_texname;
std::string normal_texname;
std::map<std::string, std::string> unknown_parameter;
std::string ambient_texname;
std::string diffuse_texname;
std::string specular_texname;
std::string normal_texname;
std::map<std::string, std::string> unknown_parameter;
} material_t;
typedef struct
{
std::vector<float> positions;
std::vector<float> normals;
std::vector<float> texcoords;
std::vector<unsigned int> indices;
std::vector<int> material_ids; // per-mesh material ID
typedef struct {
std::vector<float> positions;
std::vector<float> normals;
std::vector<float> texcoords;
std::vector<unsigned int> indices;
std::vector<int> material_ids; // per-mesh material ID
} mesh_t;
typedef struct
{
std::string name;
mesh_t mesh;
typedef struct {
std::vector<float> positions;
std::vector<unsigned int> indices;
} line_t;
typedef struct {
std::string name;
std::vector<float> positions; // control points. xyz
std::vector<unsigned int> indices; // index to control point
std::vector<float> u_params;
std::vector<float> v_params;
int degree;
int type; // 0: bspline, 1: bezier, 2: cardinal
} curve_t;
typedef struct {
std::string name;
mesh_t mesh;
} shape_t;
class MaterialReader
{
class MaterialReader {
public:
MaterialReader(){}
virtual ~MaterialReader(){}
MaterialReader() {}
virtual ~MaterialReader() {}
virtual std::string operator() (
const std::string& matId,
std::vector<material_t>& materials,
std::map<std::string, int>& matMap) = 0;
virtual std::string operator()(const std::string &matId,
std::vector<material_t> &materials,
std::map<std::string, int> &matMap) = 0;
};
class MaterialFileReader:
public MaterialReader
{
public:
MaterialFileReader(const std::string& mtl_basepath): m_mtlBasePath(mtl_basepath) {}
virtual ~MaterialFileReader() {}
virtual std::string operator() (
const std::string& matId,
std::vector<material_t>& materials,
std::map<std::string, int>& matMap);
class MaterialFileReader : public MaterialReader {
public:
MaterialFileReader(const std::string &mtl_basepath)
: m_mtlBasePath(mtl_basepath) {}
virtual ~MaterialFileReader() {}
virtual std::string operator()(const std::string &matId,
std::vector<material_t> &materials,
std::map<std::string, int> &matMap);
private:
std::string m_mtlBasePath;
private:
std::string m_mtlBasePath;
};
/// Loads .obj from a file.
/// 'shapes' will be filled with parsed shape data
/// 'curves' will be filled with parsed curve data(NURBS, Bezier, etc)
/// The function returns error string.
/// Returns empty string when loading .obj success.
/// 'mtl_basepath' is optional, and used for base path for .mtl file.
std::string LoadObj(
std::vector<shape_t>& shapes, // [output]
std::vector<material_t>& materials, // [output]
const char* filename,
const char* mtl_basepath = NULL);
std::string LoadObj(std::vector<shape_t> &shapes, // [output]
std::vector<curve_t> &curves, // [output]
std::vector<material_t> &materials, // [output]
const char *filename, const char *mtl_basepath = NULL);
/// Loads object from a std::istream, uses GetMtlIStreamFn to retrieve
/// std::istream for materials.
/// Returns empty string when loading .obj success.
std::string LoadObj(
std::vector<shape_t>& shapes, // [output]
std::vector<material_t>& materials, // [output]
std::istream& inStream,
MaterialReader& readMatFn);
std::string LoadObj(std::vector<shape_t> &shapes, // [output]
std::vector<curve_t> &curves, // [output]
std::vector<material_t> &materials, // [output]
std::istream &inStream, MaterialReader &readMatFn);
/// Loads materials into std::map
/// Returns an empty string if successful
std::string LoadMtl (
std::map<std::string, int>& material_map,
std::vector<material_t>& materials,
std::istream& inStream);
std::string LoadMtl(std::map<std::string, int> &material_map,
std::vector<material_t> &materials, std::istream &inStream);
}
#endif // _TINY_OBJ_LOADER_H
#endif // _TINY_OBJ_LOADER_H

BIN
tools/windows/premake5.exe Normal file

Binary file not shown.

1
vcsetup.bat Normal file
View File

@@ -0,0 +1 @@
.\\tools\\windows\\premake5.exe vs2013