Skip to content

Commit 6c6390f

Browse files
committed
Fix typo.
1 parent 4d6649c commit 6c6390f

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

‎examples/voxelize/main.cc‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#define VOXELIZER_IMPLEMENTATION
2+
#include "voxelizer.h"
3+
4+
#define TINYOBJLOADER_IMPLEMENTATION
5+
#include "../../tiny_obj_loader.h"
6+
7+
bool Voxelize(const char* filename, float voxelsizex, float voxelsizey, float voxelsizez, float precision)
8+
{
9+
tinyobj::attrib_t attrib;
10+
std::vector<tinyobj::shape_t> shapes;
11+
std::vector<tinyobj::material_t> materials;
12+
std::string err;
13+
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, filename);
14+
15+
if (!err.empty()) {
16+
printf("err: %s\n", err.c_str());
17+
}
18+
19+
if (!ret) {
20+
printf("failed to load : %s\n", filename);
21+
return false;
22+
}
23+
24+
if (shapes.size() == 0) {
25+
printf("err: # of shapes are zero.\n");
26+
return false;
27+
}
28+
29+
// Only use first shape.
30+
{
31+
vx_mesh_t* mesh;
32+
vx_mesh_t* result;
33+
34+
mesh = vx_mesh_alloc(attrib.vertices.size(), shapes[0].mesh.indices.size());
35+
36+
for (size_t f = 0; f < shapes[0].mesh.indices.size(); f++) {
37+
mesh->indices[f] = shapes[0].mesh.indices[f].vertex_index;
38+
}
39+
40+
for (size_t v = 0; v < attrib.vertices.size() / 3; v++) {
41+
mesh->vertices[v].x = attrib.vertices[3*v+0];
42+
mesh->vertices[v].y = attrib.vertices[3*v+1];
43+
mesh->vertices[v].z = attrib.vertices[3*v+2];
44+
}
45+
46+
result = vx_voxelize(mesh, voxelsizex, voxelsizey, voxelsizez, precision);
47+
48+
printf("Number of vertices: %ld\n", result->nvertices);
49+
printf("Number of indices: %ld\n", result->nindices);
50+
}
51+
return true;
52+
}
53+
54+
55+
int
56+
main(
57+
int argc,
58+
char** argv)
59+
{
60+
if (argc < 4) {
61+
printf("Usage: voxelize input.obj voxelsizex voxelsizey voxelsizez precision\n");
62+
exit(-1);
63+
}
64+
65+
const char* filename = argv[1];
66+
float voxelsizex = atof(argv[2]);
67+
float voxelsizey = atof(argv[3]);
68+
float voxelsizez = atof(argv[4]);
69+
float prec = atof(argv[5]);
70+
bool ret = Voxelize(filename, voxelsizex, voxelsizey, voxelsizez, prec);
71+
72+
return ret ? EXIT_SUCCESS : EXIT_FAILURE;
73+
}
74+

0 commit comments

Comments
 (0)