Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b29502

Browse files
committed
Add data layout description to README.
1 parent 156b709 commit 4b29502

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ TinyObjLoader is successfully used in ...
9797

9898
* [ ] Fix obj_sticker example.
9999
* [ ] More unit test codes.
100-
* [ ] Texture options
100+
* [x] Texture options
101101
* [ ] Normal vector generation
102102
* [ ] Support smoothing groups
103103

@@ -107,10 +107,76 @@ Licensed under MIT license.
107107

108108
## Usage
109109

110+
### Data format
111+
110112
`attrib_t` contains single and linear array of vertex data(position, normal and texcoord).
113+
114+
```
115+
attrib_t::vertices => 3 floats per vertex
116+
117+
v[0] v[1] v[2] v[3] v[n-1]
118+
+-----------+-----------+-----------+-----------+ +-----------+
119+
| x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z |
120+
+-----------+-----------+-----------+-----------+ +-----------+
121+
122+
attrib_t::normals => 3 floats per vertex
123+
124+
n[0] n[1] n[2] n[3] n[n-1]
125+
+-----------+-----------+-----------+-----------+ +-----------+
126+
| x | y | z | x | y | z | x | y | z | x | y | z | .... | x | y | z |
127+
+-----------+-----------+-----------+-----------+ +-----------+
128+
129+
attrib_t::texcoords => 2 floats per vertex
130+
131+
t[0] t[1] t[2] t[3] t[n-1]
132+
+-----------+-----------+-----------+-----------+ +-----------+
133+
| u | v | u | v | u | v | u | v | .... | u | v |
134+
+-----------+-----------+-----------+-----------+ +-----------+
135+
136+
```
137+
111138
Each `shape_t` does not contain vertex data but contains array index to `attrib_t`.
112139
See `loader_example.cc` for more details.
113140

141+
142+
```
143+
144+
mesh_t::indices => array of vertex indices.
145+
146+
+----+----+----+----+----+----+----+----+----+----+ +--------+
147+
| i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | ... | i(n-1) |
148+
+----+----+----+----+----+----+----+----+----+----+ +--------+
149+
150+
Each index has an array index to attrib_t::vertices, attrib_t::normals and attrib_t::texcoords.
151+
152+
mesh_t::num_face_vertices => array of the number of vertices per face(e.g. 3 = triangle, 4 = quad , 5 or more = N-gons).
153+
154+
155+
+---+---+---+ +---+
156+
| 3 | 4 | 3 | ...... | 3 |
157+
+---+---+---+ +---+
158+
| | | |
159+
| | | +-----------------------------------------+
160+
| | | |
161+
| | +------------------------------+ |
162+
| | | |
163+
| +------------------+ | |
164+
| | | |
165+
|/ |/ |/ |/
166+
167+
mesh_t::indices
168+
169+
| face[0] | face[1] | face[2] | | face[n-1] |
170+
+----+----+----+----+----+----+----+----+----+----+ +--------+--------+--------+
171+
| i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | ... | i(n-3) | i(n-2) | i(n-1) |
172+
+----+----+----+----+----+----+----+----+----+----+ +--------+--------+--------+
173+
174+
```
175+
176+
Note that when `triangulate` flas is true in `tinyobj::LoadObj()` argument, `num_face_vertices` are all filled with 3(triangle).
177+
178+
#### Example code
179+
114180
```c++
115181
#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
116182
#include "tiny_obj_loader.h"

0 commit comments

Comments
 (0)