Rename varialble for better understanding.
Write some API usage in README.md.
This commit is contained in:
36
README.md
36
README.md
@@ -79,9 +79,9 @@ Features
|
|||||||
TODO
|
TODO
|
||||||
----
|
----
|
||||||
|
|
||||||
* [ ] Read .obj/.mtl from memory.
|
|
||||||
* [ ] Fix Python binding.
|
* [ ] Fix Python binding.
|
||||||
* [ ] Unit test codes.
|
* [ ] Fix obj_sticker example.
|
||||||
|
* [ ] More unit test codes.
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
@@ -91,6 +91,10 @@ Licensed under MIT license.
|
|||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
`attrib_t` contains single and linear array of vertex data(position, normal and texcoord).
|
||||||
|
Each `shape_t` does not contain vertex data but contains array index to `attrib_t`.
|
||||||
|
See `loader_example.cc` for more details.
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
|
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
|
||||||
#include "tiny_obj_loader.h"
|
#include "tiny_obj_loader.h"
|
||||||
@@ -111,7 +115,33 @@ if (!ret) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// See loader_example.cc for more details.
|
// Loop over shapes
|
||||||
|
for (size_t s = 0; s < shapes.size(); s++) {
|
||||||
|
// Loop over faces(polygon)
|
||||||
|
size_t index_offset = 0;
|
||||||
|
for (size_t f = 0; f < shapes[i].mesh.num_face_vertices; f++) {
|
||||||
|
int fv = shapes[i].mesh.num_face_vertices[f];
|
||||||
|
|
||||||
|
// Loop over vertices in the face.
|
||||||
|
for (size_t v = 0; v < fv; f++) {
|
||||||
|
// access to vertex
|
||||||
|
tinyobj::index_t idx = shapes[i].mesh.indices[index_offset + v];
|
||||||
|
float vx = attrib.positions[3*idx.vertex_index+0];
|
||||||
|
float vy = attrib.positions[3*idx.vertex_index+1];
|
||||||
|
float vz = attrib.positions[3*idx.vertex_index+2];
|
||||||
|
float nx = attrib.normals[3*idx.normal_index+0];
|
||||||
|
float ny = attrib.normals[3*idx.normal_index+1];
|
||||||
|
float nz = attrib.normals[3*idx.normal_index+2];
|
||||||
|
float tx = attrib.texcoords[2*idx.texcoord_index+0];
|
||||||
|
float ty = attrib.texcoords[2*idx.texcoord_index+1];
|
||||||
|
}
|
||||||
|
index_offset += fv;
|
||||||
|
|
||||||
|
// per-face material
|
||||||
|
shapes[i].mesh.material_ids[f];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj
|
|||||||
}
|
}
|
||||||
|
|
||||||
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.material_ids.size() == shapes[i].mesh.num_vertices.size());
|
assert(shapes[i].mesh.material_ids.size() == shapes[i].mesh.num_face_vertices.size());
|
||||||
for (size_t m = 0; m < shapes[i].mesh.material_ids.size(); m++) {
|
for (size_t m = 0; m < shapes[i].mesh.material_ids.size(); m++) {
|
||||||
printf(" material_id[%ld] = %d\n", m,
|
printf(" material_id[%ld] = %d\n", m,
|
||||||
shapes[i].mesh.material_ids[m]);
|
shapes[i].mesh.material_ids[m]);
|
||||||
@@ -73,10 +73,10 @@ static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("shape[%ld].num_faces: %ld\n", i, shapes[i].mesh.num_vertices.size());
|
printf("shape[%ld].num_faces: %ld\n", i, shapes[i].mesh.num_face_vertices.size());
|
||||||
for (size_t v = 0; v < shapes[i].mesh.num_vertices.size(); v++) {
|
for (size_t v = 0; v < shapes[i].mesh.num_face_vertices.size(); v++) {
|
||||||
printf(" num_vertices[%ld] = %ld\n", v,
|
printf(" num_face_vertices[%ld] = %ld\n", v,
|
||||||
static_cast<long>(shapes[i].mesh.num_vertices[v]));
|
static_cast<long>(shapes[i].mesh.num_face_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());
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj
|
|||||||
}
|
}
|
||||||
|
|
||||||
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.material_ids.size() == shapes[i].mesh.num_vertices.size());
|
assert(shapes[i].mesh.material_ids.size() == shapes[i].mesh.num_face_vertices.size());
|
||||||
for (size_t m = 0; m < shapes[i].mesh.material_ids.size(); m++) {
|
for (size_t m = 0; m < shapes[i].mesh.material_ids.size(); m++) {
|
||||||
printf(" material_id[%ld] = %d\n", m,
|
printf(" material_id[%ld] = %d\n", m,
|
||||||
shapes[i].mesh.material_ids[m]);
|
shapes[i].mesh.material_ids[m]);
|
||||||
@@ -73,10 +73,10 @@ static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("shape[%ld].num_faces: %ld\n", i, shapes[i].mesh.num_vertices.size());
|
printf("shape[%ld].num_faces: %ld\n", i, shapes[i].mesh.num_face_vertices.size());
|
||||||
for (size_t v = 0; v < shapes[i].mesh.num_vertices.size(); v++) {
|
for (size_t v = 0; v < shapes[i].mesh.num_face_vertices.size(); v++) {
|
||||||
printf(" num_vertices[%ld] = %ld\n", v,
|
printf(" num_vertices[%ld] = %ld\n", v,
|
||||||
static_cast<long>(shapes[i].mesh.num_vertices[v]));
|
static_cast<long>(shapes[i].mesh.num_face_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());
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
std::vector<index_t> indices;
|
std::vector<index_t> indices;
|
||||||
std::vector<unsigned char>
|
std::vector<unsigned char>
|
||||||
num_vertices; // The number of vertices per face. Up to 255.
|
num_face_vertices; // The number of vertices per face. 3 = polygon, 4 = quad, ... Up to 255.
|
||||||
std::vector<int> material_ids; // per-face material ID
|
std::vector<int> material_ids; // per-face material ID
|
||||||
std::vector<tag_t> tags; // SubD tag
|
std::vector<tag_t> tags; // SubD tag
|
||||||
} mesh_t;
|
} mesh_t;
|
||||||
@@ -604,7 +604,7 @@ static bool exportFaceGroupToShape(
|
|||||||
shape->mesh.indices.push_back(idx1);
|
shape->mesh.indices.push_back(idx1);
|
||||||
shape->mesh.indices.push_back(idx2);
|
shape->mesh.indices.push_back(idx2);
|
||||||
|
|
||||||
shape->mesh.num_vertices.push_back(3);
|
shape->mesh.num_face_vertices.push_back(3);
|
||||||
shape->mesh.material_ids.push_back(material_id);
|
shape->mesh.material_ids.push_back(material_id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -615,7 +615,7 @@ static bool exportFaceGroupToShape(
|
|||||||
idx.texcoord_index = face[k].vt_idx;
|
idx.texcoord_index = face[k].vt_idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
shape->mesh.num_vertices.push_back(static_cast<unsigned char>(npolys));
|
shape->mesh.num_face_vertices.push_back(static_cast<unsigned char>(npolys));
|
||||||
shape->mesh.material_ids.push_back(material_id); // per face
|
shape->mesh.material_ids.push_back(material_id); // per face
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user