Add support of group tag('g')
This commit is contained in:
24
cube.mtl
Normal file
24
cube.mtl
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
newmtl white
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 0 0 0
|
||||||
|
|
||||||
|
newmtl red
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 0 0
|
||||||
|
Ks 0 0 0
|
||||||
|
|
||||||
|
newmtl green
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0 1 0
|
||||||
|
Ks 0 0 0
|
||||||
|
|
||||||
|
newmtl blue
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0 0 1
|
||||||
|
Ks 0 0 0
|
||||||
|
|
||||||
|
newmtl light
|
||||||
|
Ka 20 20 20
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 0 0 0
|
||||||
31
cube.obj
Normal file
31
cube.obj
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
mtllib cube.mtl
|
||||||
|
|
||||||
|
v 0.000000 2.000000 2.000000
|
||||||
|
v 0.000000 0.000000 2.000000
|
||||||
|
v 2.000000 0.000000 2.000000
|
||||||
|
v 2.000000 2.000000 2.000000
|
||||||
|
v 0.000000 2.000000 0.000000
|
||||||
|
v 0.000000 0.000000 0.000000
|
||||||
|
v 2.000000 0.000000 0.000000
|
||||||
|
v 2.000000 2.000000 0.000000
|
||||||
|
# 8 vertices
|
||||||
|
|
||||||
|
g front cube
|
||||||
|
usemtl white
|
||||||
|
f 1 2 3 4
|
||||||
|
g back cube
|
||||||
|
# expects white material
|
||||||
|
f 8 7 6 5
|
||||||
|
g right cube
|
||||||
|
usemtl red
|
||||||
|
f 4 3 7 8
|
||||||
|
g top cube
|
||||||
|
usemtl white
|
||||||
|
f 5 1 4 8
|
||||||
|
g left cube
|
||||||
|
usemtl green
|
||||||
|
f 5 6 2 1
|
||||||
|
g bottom cube
|
||||||
|
usemtl white
|
||||||
|
f 2 6 7 3
|
||||||
|
# 6 elements
|
||||||
33
test.cc
33
test.cc
@@ -5,22 +5,17 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int
|
static bool
|
||||||
main(
|
TestLoadObj(const char* filename)
|
||||||
int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
{
|
||||||
std::string inputfile = "cornell_box.obj";
|
std::cout << "Loading " << filename << std::endl;
|
||||||
std::vector<tinyobj::shape_t> shapes;
|
|
||||||
|
|
||||||
if (argc > 1) {
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
inputfile = std::string(argv[1]);
|
std::string err = tinyobj::LoadObj(shapes, filename);
|
||||||
}
|
|
||||||
|
|
||||||
std::string err = tinyobj::LoadObj(shapes, inputfile.c_str());
|
|
||||||
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
std::cerr << err << std::endl;
|
std::cerr << err << std::endl;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
std::cout << "# of shapes : " << shapes.size() << std::endl;
|
||||||
@@ -61,5 +56,21 @@ main(
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(
|
||||||
|
int argc,
|
||||||
|
char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (argc > 1) {
|
||||||
|
assert(true == TestLoadObj(argv[1]));
|
||||||
|
} else {
|
||||||
|
assert(true == TestLoadObj("cornell_box.obj"));
|
||||||
|
assert(true == TestLoadObj("cube.obj"));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2012, Syoyo Fujita.
|
// Copyright 2012-2013, Syoyo Fujita.
|
||||||
//
|
//
|
||||||
// Licensed under 2-clause BSD liecense.
|
// Licensed under 2-clause BSD liecense.
|
||||||
//
|
//
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// version 0.9.4: Initial suupport of group tag(g)
|
||||||
// version 0.9.3: Fix parsing triple 'x/y/z'
|
// version 0.9.3: Fix parsing triple 'x/y/z'
|
||||||
// version 0.9.2: Add more .mtl load support
|
// version 0.9.2: Add more .mtl load support
|
||||||
// version 0.9.1: Add initial .mtl load support
|
// version 0.9.1: Add initial .mtl load support
|
||||||
@@ -560,6 +561,29 @@ LoadObj(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// group name
|
||||||
|
if (token[0] == 'g' && isSpace((token[1]))) {
|
||||||
|
|
||||||
|
printf("group\n");
|
||||||
|
|
||||||
|
// flush previous face group.
|
||||||
|
shape_t shape;
|
||||||
|
bool ret = exportFaceGroupToShape(shape, v, vn, vt, faceGroup, material, name);
|
||||||
|
if (ret) {
|
||||||
|
shapes.push_back(shape);
|
||||||
|
}
|
||||||
|
|
||||||
|
faceGroup.clear();
|
||||||
|
|
||||||
|
// @todo { multiple group name. }
|
||||||
|
char namebuf[4096];
|
||||||
|
token += 2;
|
||||||
|
sscanf(token, "%s", namebuf);
|
||||||
|
name = std::string(namebuf);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// object name
|
// object name
|
||||||
if (token[0] == 'o' && isSpace((token[1]))) {
|
if (token[0] == 'o' && isSpace((token[1]))) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user