Compare commits
6 Commits
47aad5a129
...
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
|
||||
=============
|
||||
|
||||
[](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://ci.appveyor.com/project/syoyo/tinyobjloader/branch/master)
|
||||
|
||||
36
test.cc
36
test.cc
@@ -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;
|
||||
}
|
||||
|
||||
1245
tiny_obj_loader.cc
1245
tiny_obj_loader.cc
File diff suppressed because it is too large
Load Diff
@@ -13,82 +13,100 @@
|
||||
namespace tinyobj {
|
||||
|
||||
typedef struct {
|
||||
std::string name;
|
||||
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
|
||||
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;
|
||||
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 {
|
||||
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);
|
||||
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;
|
||||
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::vector<material_t> &materials, std::istream &inStream);
|
||||
}
|
||||
|
||||
#endif // _TINY_OBJ_LOADER_H
|
||||
|
||||
Reference in New Issue
Block a user