From f750f3faebb688a0c7f3d918fb29a96c2ec652e4 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 16 Nov 2014 19:35:18 +0100 Subject: [PATCH 1/5] adding setup.py file --- python/setup.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 python/setup.py diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 0000000..de7b976 --- /dev/null +++ b/python/setup.py @@ -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]) + + From e5bbda3835e2e848c951a2aa052847864b956b7d Mon Sep 17 00:00:00 2001 From: Ododo Date: Sun, 16 Nov 2014 21:08:44 +0100 Subject: [PATCH 2/5] Update howto.py --- python/howto.py | 560 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 559 insertions(+), 1 deletion(-) diff --git a/python/howto.py b/python/howto.py index 1342dac..099a1af 100644 --- a/python/howto.py +++ b/python/howto.py @@ -1,5 +1,563 @@ import tinyobjloader as tol +import json model = tol.LoadObj("cube.obj") -print(model["shapes"], model["materials"]) +#print(model["shapes"], model["materials"]) +print( json.dumps(model, indent=4) ) + +#EXAMPLE OUTPUT + +##{ +## "shapes": { +## "left": [ +## [ +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0 +## ], +## [ +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0 +## ], +## [ +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0 +## ], +## [ +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0 +## ], +## [ +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0, +## 2.0 +## ] +## ], +## "bottom": [ +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ] +## ], +## "right": [ +## [ +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0 +## ], +## [ +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0 +## ], +## [ +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0 +## ], +## [ +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0 +## ], +## [ +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0, +## 1.0 +## ] +## ], +## "front": [ +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ] +## ], +## "top": [ +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ] +## ], +## "back": [ +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ], +## [ +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0, +## 0.0 +## ] +## ] +## }, +## "materials": { +## "green": { +## "emission": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "specular": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "illum": 0, +## "ior": 1.0, +## "shininess": 1.0, +## "normal_texname": "", +## "specular_texname": "", +## "transmittance": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "dissolve": 1.0, +## "ambient": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "diffuse": [ +## 0.0, +## 1.0, +## 0.0 +## ], +## "diffuse_texname": "", +## "ambient_texname": "" +## }, +## "blue": { +## "emission": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "specular": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "illum": 0, +## "ior": 1.0, +## "shininess": 1.0, +## "normal_texname": "", +## "specular_texname": "", +## "transmittance": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "dissolve": 1.0, +## "ambient": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "diffuse": [ +## 0.0, +## 0.0, +## 1.0 +## ], +## "diffuse_texname": "", +## "ambient_texname": "" +## }, +## "red": { +## "emission": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "specular": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "illum": 0, +## "ior": 1.0, +## "shininess": 1.0, +## "normal_texname": "", +## "specular_texname": "", +## "transmittance": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "dissolve": 1.0, +## "ambient": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "diffuse": [ +## 1.0, +## 0.0, +## 0.0 +## ], +## "diffuse_texname": "", +## "ambient_texname": "" +## }, +## "white": { +## "emission": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "specular": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "illum": 0, +## "ior": 1.0, +## "shininess": 1.0, +## "normal_texname": "", +## "specular_texname": "", +## "transmittance": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "dissolve": 1.0, +## "ambient": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "diffuse": [ +## 1.0, +## 1.0, +## 1.0 +## ], +## "diffuse_texname": "", +## "ambient_texname": "" +## }, +## "light": { +## "emission": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "specular": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "illum": 0, +## "ior": 1.0, +## "shininess": 1.0, +## "normal_texname": "", +## "specular_texname": "", +## "transmittance": [ +## 0.0, +## 0.0, +## 0.0 +## ], +## "dissolve": 1.0, +## "ambient": [ +## 20.0, +## 20.0, +## 20.0 +## ], +## "diffuse": [ +## 1.0, +## 1.0, +## 1.0 +## ], +## "diffuse_texname": "", +## "ambient_texname": "" +## } +## } +##} From 93d72326144fdea4ec876ae0494a17106647f065 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 16 Nov 2014 23:39:20 +0100 Subject: [PATCH 3/5] fix shapes / adding setup file --- python/cornell_box_output.json | 601 +++++++++++++++++++++++++++++++++ python/howto.py | 558 +----------------------------- python/main.cpp | 63 ++-- 3 files changed, 635 insertions(+), 587 deletions(-) create mode 100644 python/cornell_box_output.json diff --git a/python/cornell_box_output.json b/python/cornell_box_output.json new file mode 100644 index 0000000..ba2e7e1 --- /dev/null +++ b/python/cornell_box_output.json @@ -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 + } + } +} diff --git a/python/howto.py b/python/howto.py index 099a1af..c526821 100644 --- a/python/howto.py +++ b/python/howto.py @@ -1,563 +1,11 @@ import tinyobjloader as tol import json -model = tol.LoadObj("cube.obj") +model = tol.LoadObj("cornell_box.obj") #print(model["shapes"], model["materials"]) print( json.dumps(model, indent=4) ) -#EXAMPLE OUTPUT +#see cornell_box_output.json + -##{ -## "shapes": { -## "left": [ -## [ -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0 -## ], -## [ -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0 -## ], -## [ -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0 -## ], -## [ -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0 -## ], -## [ -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0, -## 2.0 -## ] -## ], -## "bottom": [ -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ] -## ], -## "right": [ -## [ -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0 -## ], -## [ -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0 -## ], -## [ -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0 -## ], -## [ -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0 -## ], -## [ -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0, -## 1.0 -## ] -## ], -## "front": [ -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ] -## ], -## "top": [ -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ] -## ], -## "back": [ -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ], -## [ -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0, -## 0.0 -## ] -## ] -## }, -## "materials": { -## "green": { -## "emission": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "specular": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "illum": 0, -## "ior": 1.0, -## "shininess": 1.0, -## "normal_texname": "", -## "specular_texname": "", -## "transmittance": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "dissolve": 1.0, -## "ambient": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "diffuse": [ -## 0.0, -## 1.0, -## 0.0 -## ], -## "diffuse_texname": "", -## "ambient_texname": "" -## }, -## "blue": { -## "emission": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "specular": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "illum": 0, -## "ior": 1.0, -## "shininess": 1.0, -## "normal_texname": "", -## "specular_texname": "", -## "transmittance": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "dissolve": 1.0, -## "ambient": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "diffuse": [ -## 0.0, -## 0.0, -## 1.0 -## ], -## "diffuse_texname": "", -## "ambient_texname": "" -## }, -## "red": { -## "emission": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "specular": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "illum": 0, -## "ior": 1.0, -## "shininess": 1.0, -## "normal_texname": "", -## "specular_texname": "", -## "transmittance": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "dissolve": 1.0, -## "ambient": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "diffuse": [ -## 1.0, -## 0.0, -## 0.0 -## ], -## "diffuse_texname": "", -## "ambient_texname": "" -## }, -## "white": { -## "emission": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "specular": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "illum": 0, -## "ior": 1.0, -## "shininess": 1.0, -## "normal_texname": "", -## "specular_texname": "", -## "transmittance": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "dissolve": 1.0, -## "ambient": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "diffuse": [ -## 1.0, -## 1.0, -## 1.0 -## ], -## "diffuse_texname": "", -## "ambient_texname": "" -## }, -## "light": { -## "emission": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "specular": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "illum": 0, -## "ior": 1.0, -## "shininess": 1.0, -## "normal_texname": "", -## "specular_texname": "", -## "transmittance": [ -## 0.0, -## 0.0, -## 0.0 -## ], -## "dissolve": 1.0, -## "ambient": [ -## 20.0, -## 20.0, -## 20.0 -## ], -## "diffuse": [ -## 1.0, -## 1.0, -## 1.0 -## ], -## "diffuse_texname": "", -## "ambient_texname": "" -## } -## } -##} diff --git a/python/main.cpp b/python/main.cpp index 636a24d..8999563 100644 --- a/python/main.cpp +++ b/python/main.cpp @@ -5,6 +5,7 @@ // model = tol.LoadObj(name) // print(model["shapes"]) // print(model["materials"] + #include #include #include "../tiny_obj_loader.h" @@ -30,7 +31,7 @@ extern "C" static PyObject* pyLoadObj(PyObject* self, PyObject* args) { - PyObject *rtntpl, *pyshapes, *pymaterials; + PyObject *rtndict, *pyshapes, *pymaterials; char const* filename; std::vector shapes; std::vector materials; @@ -42,48 +43,46 @@ pyLoadObj(PyObject* self, PyObject* args) pyshapes = PyDict_New(); pymaterials = PyDict_New(); - rtntpl = PyDict_New(); + rtndict = PyDict_New(); for (std::vector::iterator shape = shapes.begin() ; shape != shapes.end(); shape++) { - PyObject *meshobj; - PyObject *positions, *normals, *texcoords, *indices, *material_ids; - - meshobj = PyTuple_New(5); - positions = PyList_New(0); - normals = PyList_New(0); - texcoords = PyList_New(0); - indices = PyList_New(0); - material_ids = PyList_New(0); + PyObject *meshobj, *current; + char *current_name; + vectd vect; + meshobj = PyDict_New(); tinyobj::mesh_t cm = (*shape).mesh; - for (int i = 0; i <= 4 ; i++ ) + + for (int i = 0; i <= 4; i++ ) { - PyObject *current; - vectd vect; + current = PyList_New(0); - switch (i) - { - case 0: current = positions; - vect = vectd(cm.positions.begin(), cm.positions.end()); - case 1: current = normals; - vect = vectd(cm.normals.begin(), cm.normals.end()); - case 2: current = texcoords; - vect = vectd(cm.texcoords.begin(), cm.texcoords.end()); - case 3: current = indices; - vect = vectd(cm.indices.begin(), cm.indices.end()); - case 4: current = material_ids; - vect = vectd(cm.material_ids.begin(), cm.material_ids.end()); - } + if (i == 0){ + current_name = "positions"; + vect = vectd(cm.positions.begin(), cm.positions.end()); } + else if (i==1){ + current_name = "normals"; + vect = vectd(cm.normals.begin(), cm.normals.end()); } + else if (i == 2) { + current_name = "texcoords"; + vect = vectd(cm.texcoords.begin(), cm.texcoords.end()); } + else if (i==3) { + current_name = "indicies"; + vect = vectd(cm.indices.begin(), cm.indices.end()); } + else if (i == 4) { + current_name = "material_ids"; + vect = vectd(cm.material_ids.begin(), cm.material_ids.end()); } - for (std::vector::iterator it = vect.begin() ; + for (vectd::iterator it = vect.begin() ; it != vect.end(); it++) { PyList_Insert(current, it - vect.begin(), PyFloat_FromDouble(*it)); } - PyTuple_SetItem(meshobj, i, current); + PyDict_SetItemString(meshobj, current_name, current); + } PyDict_SetItemString(pyshapes, (*shape).name.c_str(), meshobj); @@ -111,10 +110,10 @@ pyLoadObj(PyObject* self, PyObject* args) PyDict_SetItemString(pymaterials, (*mat).name.c_str(), matobj); } - PyDict_SetItemString(rtntpl, "shapes", pyshapes); - PyDict_SetItemString(rtntpl, "materials", pymaterials); + PyDict_SetItemString(rtndict, "shapes", pyshapes); + PyDict_SetItemString(rtndict, "materials", pymaterials); - return rtntpl; + return rtndict; } From 9587ad9aee5b5801ab1b3eb244bbc06ed38b891a Mon Sep 17 00:00:00 2001 From: root Date: Sun, 16 Nov 2014 23:53:21 +0100 Subject: [PATCH 4/5] cleaning code.. --- python/main.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/python/main.cpp b/python/main.cpp index 8999563..81f7476 100644 --- a/python/main.cpp +++ b/python/main.cpp @@ -31,8 +31,13 @@ extern "C" static PyObject* pyLoadObj(PyObject* self, PyObject* args) { - PyObject *rtndict, *pyshapes, *pymaterials; + PyObject *rtndict, *pyshapes, *pymaterials, + *current, *meshobj; + char const* filename; + char *current_name; + vectd vect; + std::vector shapes; std::vector materials; @@ -48,10 +53,6 @@ pyLoadObj(PyObject* self, PyObject* args) for (std::vector::iterator shape = shapes.begin() ; shape != shapes.end(); shape++) { - PyObject *meshobj, *current; - char *current_name; - vectd vect; - meshobj = PyDict_New(); tinyobj::mesh_t cm = (*shape).mesh; @@ -62,13 +63,13 @@ pyLoadObj(PyObject* self, PyObject* args) if (i == 0){ current_name = "positions"; vect = vectd(cm.positions.begin(), cm.positions.end()); } - else if (i==1){ + else if (i == 1){ current_name = "normals"; vect = vectd(cm.normals.begin(), cm.normals.end()); } else if (i == 2) { current_name = "texcoords"; vect = vectd(cm.texcoords.begin(), cm.texcoords.end()); } - else if (i==3) { + else if (i == 3) { current_name = "indicies"; vect = vectd(cm.indices.begin(), cm.indices.end()); } else if (i == 4) { From aabdad4bc48067ce0f3a6535257b06bd22c0238a Mon Sep 17 00:00:00 2001 From: root Date: Mon, 17 Nov 2014 22:06:25 +0100 Subject: [PATCH 5/5] changed to switch structure --- python/main.cpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/python/main.cpp b/python/main.cpp index 81f7476..b2c6e96 100644 --- a/python/main.cpp +++ b/python/main.cpp @@ -60,23 +60,27 @@ pyLoadObj(PyObject* self, PyObject* args) { current = PyList_New(0); - if (i == 0){ - current_name = "positions"; - vect = vectd(cm.positions.begin(), cm.positions.end()); } - else if (i == 1){ - current_name = "normals"; - vect = vectd(cm.normals.begin(), cm.normals.end()); } - else if (i == 2) { - current_name = "texcoords"; - vect = vectd(cm.texcoords.begin(), cm.texcoords.end()); } - else if (i == 3) { - current_name = "indicies"; - vect = vectd(cm.indices.begin(), cm.indices.end()); } - else if (i == 4) { - current_name = "material_ids"; - vect = vectd(cm.material_ids.begin(), cm.material_ids.end()); } + switch(i) { - for (vectd::iterator it = vect.begin() ; + 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));