Compare commits
6 Commits
normal-tex
...
curve
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98da6829ac | ||
|
|
aa07206fc1 | ||
|
|
8329bdd135 | ||
|
|
def9fe7f16 | ||
|
|
82ae20b833 | ||
|
|
164c152216 |
7
.clang-format
Normal file
7
.clang-format
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 2
|
||||||
|
TabWidth: 2
|
||||||
|
UseTab: Always
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
Standard: Cpp03
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
tinyobjloader
|
tinyobjloader
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
[](https://gitter.im/syoyo/tinyobjloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
[](https://app.wercker.com/project/bykey/495a3bac400212cdacdeb4dd9397bf4f)
|
[](https://app.wercker.com/project/bykey/495a3bac400212cdacdeb4dd9397bf4f)
|
||||||
|
|
||||||
[](https://ci.appveyor.com/project/syoyo/tinyobjloader/branch/master)
|
[](https://ci.appveyor.com/project/syoyo/tinyobjloader/branch/master)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ solution "TinyObjLoaderSolution"
|
|||||||
configurations { "Release", "Debug" }
|
configurations { "Release", "Debug" }
|
||||||
|
|
||||||
if (os.is("windows")) then
|
if (os.is("windows")) then
|
||||||
platforms { "x64", "x32" }
|
platforms { "x32", "x64" }
|
||||||
else
|
else
|
||||||
platforms { "native", "x32", "x64" }
|
platforms { "native", "x32", "x64" }
|
||||||
end
|
end
|
||||||
|
|||||||
38
test.cc
38
test.cc
@@ -7,16 +7,15 @@
|
|||||||
#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::curve_t>& curves, const std::vector<tinyobj::material_t>& materials)
|
||||||
{
|
{
|
||||||
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
||||||
|
std::cout << "# of curves : " << curves.size() << std::endl;
|
||||||
std::cout << "# of materials : " << materials.size() << std::endl;
|
std::cout << "# of materials : " << materials.size() << std::endl;
|
||||||
|
|
||||||
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].normal_indices: %ld\n", i, shapes[i].mesh.normal_indices.size());
|
|
||||||
printf("Size of shape[%ld].texcoord_indices: %ld\n", i, shapes[i].mesh.texcoord_indices.size());
|
|
||||||
printf("Size of shape[%ld].material_ids: %ld\n", i, shapes[i].mesh.material_ids.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);
|
assert((shapes[i].mesh.indices.size() % 3) == 0);
|
||||||
for (size_t f = 0; f < shapes[i].mesh.indices.size() / 3; f++) {
|
for (size_t f = 0; f < shapes[i].mesh.indices.size() / 3; f++) {
|
||||||
@@ -33,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++) {
|
for (size_t i = 0; i < materials.size(); i++) {
|
||||||
printf("material[%ld].name = %s\n", i, materials[i].name.c_str());
|
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.Ka = (%f, %f ,%f)\n", materials[i].ambient[0], materials[i].ambient[1], materials[i].ambient[2]);
|
||||||
@@ -65,15 +87,16 @@ TestLoadObj(
|
|||||||
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::curve_t> curves;
|
||||||
std::vector<tinyobj::material_t> materials;
|
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()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintInfo(shapes, materials);
|
PrintInfo(shapes, curves, materials);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -165,15 +188,16 @@ std::string matStream(
|
|||||||
|
|
||||||
MaterialStringStreamReader matSSReader(matStream);
|
MaterialStringStreamReader matSSReader(matStream);
|
||||||
std::vector<tinyobj::shape_t> shapes;
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
|
std::vector<tinyobj::curve_t> curves;
|
||||||
std::vector<tinyobj::material_t> materials;
|
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()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintInfo(shapes, materials);
|
PrintInfo(shapes, curves, materials);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
1261
tiny_obj_loader.cc
1261
tiny_obj_loader.cc
File diff suppressed because it is too large
Load Diff
@@ -13,84 +13,100 @@
|
|||||||
namespace tinyobj {
|
namespace tinyobj {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
float ambient[3];
|
float ambient[3];
|
||||||
float diffuse[3];
|
float diffuse[3];
|
||||||
float specular[3];
|
float specular[3];
|
||||||
float transmittance[3];
|
float transmittance[3];
|
||||||
float emission[3];
|
float emission[3];
|
||||||
float shininess;
|
float shininess;
|
||||||
float ior; // index of refraction
|
float ior; // index of refraction
|
||||||
float dissolve; // 1 == opaque; 0 == fully transparent
|
float dissolve; // 1 == opaque; 0 == fully transparent
|
||||||
// illumination model (see http://www.fileformat.info/format/material/)
|
// illumination model (see http://www.fileformat.info/format/material/)
|
||||||
int illum;
|
int illum;
|
||||||
|
|
||||||
std::string ambient_texname;
|
std::string ambient_texname;
|
||||||
std::string diffuse_texname;
|
std::string diffuse_texname;
|
||||||
std::string specular_texname;
|
std::string specular_texname;
|
||||||
std::string normal_texname;
|
std::string normal_texname;
|
||||||
std::map<std::string, std::string> unknown_parameter;
|
std::map<std::string, std::string> unknown_parameter;
|
||||||
} material_t;
|
} material_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
std::vector<float> positions;
|
std::vector<float> positions;
|
||||||
std::vector<float> normals;
|
std::vector<float> normals;
|
||||||
std::vector<float> texcoords;
|
std::vector<float> texcoords;
|
||||||
std::vector<unsigned int> indices; // indices for vertex
|
std::vector<unsigned int> indices;
|
||||||
std::vector<unsigned int> normal_indices; // indices for normal
|
std::vector<int> material_ids; // per-mesh material ID
|
||||||
std::vector<unsigned int> texcoord_indices; // indices for texcoord
|
|
||||||
std::vector<int> material_ids; // per-mesh material ID
|
|
||||||
} mesh_t;
|
} mesh_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
std::string name;
|
std::vector<float> positions;
|
||||||
mesh_t mesh;
|
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;
|
} shape_t;
|
||||||
|
|
||||||
class MaterialReader {
|
class MaterialReader {
|
||||||
public:
|
public:
|
||||||
MaterialReader() {}
|
MaterialReader() {}
|
||||||
virtual ~MaterialReader() {}
|
virtual ~MaterialReader() {}
|
||||||
|
|
||||||
virtual std::string operator()(const std::string &matId,
|
virtual std::string operator()(const std::string &matId,
|
||||||
std::vector<material_t> &materials,
|
std::vector<material_t> &materials,
|
||||||
std::map<std::string, int> &matMap) = 0;
|
std::map<std::string, int> &matMap) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MaterialFileReader : public MaterialReader {
|
class MaterialFileReader : public MaterialReader {
|
||||||
public:
|
public:
|
||||||
MaterialFileReader(const std::string &mtl_basepath)
|
MaterialFileReader(const std::string &mtl_basepath)
|
||||||
: m_mtlBasePath(mtl_basepath) {}
|
: m_mtlBasePath(mtl_basepath) {}
|
||||||
virtual ~MaterialFileReader() {}
|
virtual ~MaterialFileReader() {}
|
||||||
virtual std::string operator()(const std::string &matId,
|
virtual std::string operator()(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);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_mtlBasePath;
|
std::string m_mtlBasePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Loads .obj from a file.
|
/// Loads .obj from a file.
|
||||||
/// 'shapes' will be filled with parsed shape data
|
/// 'shapes' will be filled with parsed shape data
|
||||||
|
/// 'curves' will be filled with parsed curve data(NURBS, Bezier, etc)
|
||||||
/// The function returns error string.
|
/// The function returns error string.
|
||||||
/// Returns empty string when loading .obj success.
|
/// Returns empty string when loading .obj success.
|
||||||
/// 'mtl_basepath' is optional, and used for base path for .mtl file.
|
/// 'mtl_basepath' is optional, and used for base path for .mtl file.
|
||||||
std::string LoadObj(std::vector<shape_t> &shapes, // [output]
|
std::string LoadObj(std::vector<shape_t> &shapes, // [output]
|
||||||
std::vector<material_t> &materials, // [output]
|
std::vector<curve_t> &curves, // [output]
|
||||||
const char *filename, const char *mtl_basepath = NULL);
|
std::vector<material_t> &materials, // [output]
|
||||||
|
const char *filename, const char *mtl_basepath = NULL);
|
||||||
|
|
||||||
/// Loads object from a std::istream, uses GetMtlIStreamFn to retrieve
|
/// Loads object from a std::istream, uses GetMtlIStreamFn to retrieve
|
||||||
/// std::istream for materials.
|
/// std::istream for materials.
|
||||||
/// Returns empty string when loading .obj success.
|
/// Returns empty string when loading .obj success.
|
||||||
std::string LoadObj(std::vector<shape_t> &shapes, // [output]
|
std::string LoadObj(std::vector<shape_t> &shapes, // [output]
|
||||||
std::vector<material_t> &materials, // [output]
|
std::vector<curve_t> &curves, // [output]
|
||||||
std::istream &inStream, MaterialReader &readMatFn);
|
std::vector<material_t> &materials, // [output]
|
||||||
|
std::istream &inStream, MaterialReader &readMatFn);
|
||||||
|
|
||||||
/// Loads materials into std::map
|
/// Loads materials into std::map
|
||||||
/// Returns an empty string if successful
|
/// Returns an empty string if successful
|
||||||
std::string LoadMtl(std::map<std::string, int> &material_map,
|
std::string LoadMtl(std::map<std::string, int> &material_map,
|
||||||
std::vector<material_t> &materials, std::istream &inStream);
|
std::vector<material_t> &materials, std::istream &inStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _TINY_OBJ_LOADER_H
|
#endif // _TINY_OBJ_LOADER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user