52 #ifndef TINY_OBJ_LOADER_H_
53 #define TINY_OBJ_LOADER_H_
62 #pragma clang diagnostic push
63 #if __has_warning("-Wzero-as-null-pointer-constant")
64 #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
67 #pragma clang diagnostic ignored "-Wpadded"
126 #ifdef TINYOBJLOADER_USE_DOUBLE
313 std::vector<material_t> *materials,
314 std::map<std::string, int> *matMap,
std::string *warn,
321 : m_mtlBaseDir(mtl_basedir) {}
324 std::vector<material_t> *materials,
325 std::map<std::string, int> *matMap,
std::string *warn,
335 : m_inStream(inStream) {}
338 std::vector<material_t> *materials,
339 std::map<std::string, int> *matMap,
std::string *warn,
343 std::istream &m_inStream;
358 bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
359 std::vector<material_t> *materials,
std::string *warn,
361 const char *mtl_basedir = NULL,
bool triangulate =
true,
362 bool default_vcols_fallback =
true);
371 void *user_data = NULL,
372 MaterialReader *readMatFn = NULL,
379 bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
380 std::vector<material_t> *materials,
std::string *warn,
382 MaterialReader *readMatFn = NULL,
bool triangulate =
true,
383 bool default_vcols_fallback =
true);
386 void LoadMtl(std::map<std::string, int> *material_map,
387 std::vector<material_t> *materials, std::istream *inStream,
399 texture_option_t *texopt,
404 #endif // TINY_OBJ_LOADER_H_
406 #ifdef TINYOBJLOADER_IMPLEMENTATION
423 struct vertex_index_t {
424 int v_idx, vt_idx, vn_idx;
425 vertex_index_t() : v_idx(-1), vt_idx(-1), vn_idx(-1) {}
426 explicit vertex_index_t(
int idx) : v_idx(idx), vt_idx(idx), vn_idx(idx) {}
427 vertex_index_t(
int vidx,
int vtidx,
int vnidx)
428 : v_idx(vidx), vt_idx(vtidx), vn_idx(vnidx) {}
437 std::vector<vertex_index_t> vertex_indices;
439 face_t() : smoothing_group_id(0) {}
448 tag_sizes() : num_ints(0), num_reals(0), num_strings(0) {}
455 std::vector<real_t>
v;
456 std::vector<real_t>
vn;
457 std::vector<real_t> vt;
462 static std::istream &safeGetline(std::istream &is,
std::string &
t) {
471 std::istream::sentry se(is,
true);
472 std::streambuf *sb = is.rdbuf();
476 int c = sb->sbumpc();
481 if (sb->sgetc() ==
'\n') sb->sbumpc();
485 if (t.empty()) is.setstate(std::ios::eofbit);
488 t +=
static_cast<char>(
c);
496 #define IS_SPACE(x) (((x) == ' ') || ((x) == '\t'))
497 #define IS_DIGIT(x) \
498 (static_cast<unsigned int>((x) - '0') < static_cast<unsigned int>(10))
499 #define IS_NEW_LINE(x) (((x) == '\r') || ((x) == '\n') || ((x) == '\0'))
502 static inline bool fixIndex(
int idx,
int n,
int *ret) {
525 static inline std::string parseString(
const char **token) {
527 (*token) += strspn((*token),
" \t");
528 size_t e = strcspn((*token),
" \t\r");
534 static inline int parseInt(
const char **token) {
535 (*token) += strspn((*token),
" \t");
536 int i = atoi((*token));
537 (*token) += strcspn((*token),
" \t\r");
568 static bool tryParseDouble(
const char *s,
const char *s_end,
double *
result) {
573 double mantissa = 0.0;
587 char const *curr =
s;
592 bool end_not_reached =
false;
599 if (*curr ==
'+' || *curr ==
'-') {
602 }
else if (IS_DIGIT(*curr)) {
608 end_not_reached = (curr != s_end);
609 while (end_not_reached && IS_DIGIT(*curr)) {
611 mantissa +=
static_cast<int>(*curr - 0x30);
614 end_not_reached = (curr != s_end);
618 if (read == 0)
goto fail;
620 if (!end_not_reached)
goto assemble;
626 end_not_reached = (curr != s_end);
627 while (end_not_reached && IS_DIGIT(*curr)) {
628 static const double pow_lut[] = {
629 1.0, 0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001,
631 const int lut_entries =
sizeof pow_lut /
sizeof pow_lut[0];
634 mantissa +=
static_cast<int>(*curr - 0x30) *
635 (read < lut_entries ? pow_lut[read] :
std::pow(10.0, -read));
638 end_not_reached = (curr != s_end);
640 }
else if (*curr ==
'e' || *curr ==
'E') {
645 if (!end_not_reached)
goto assemble;
648 if (*curr ==
'e' || *curr ==
'E') {
651 end_not_reached = (curr != s_end);
652 if (end_not_reached && (*curr ==
'+' || *curr ==
'-')) {
655 }
else if (IS_DIGIT(*curr)) {
662 end_not_reached = (curr != s_end);
663 while (end_not_reached && IS_DIGIT(*curr)) {
665 exponent +=
static_cast<int>(*curr - 0x30);
668 end_not_reached = (curr != s_end);
670 exponent *= (exp_sign ==
'+' ? 1 : -1);
671 if (read == 0)
goto fail;
675 *result = (sign ==
'+' ? 1 : -1) *
676 (exponent ? std::ldexp(mantissa *
std::pow(5.0, exponent), exponent)
683 static inline real_t parseReal(
const char **token,
double default_value = 0.0) {
684 (*token) += strspn((*token),
" \t");
685 const char *
end = (*token) + strcspn((*token),
" \t\r");
686 double val = default_value;
687 tryParseDouble((*token), end, &val);
693 static inline bool parseReal(
const char **token,
real_t *out) {
694 (*token) += strspn((*token),
" \t");
695 const char *end = (*token) + strcspn((*token),
" \t\r");
697 bool ret = tryParseDouble((*token), end, &val);
706 static inline void parseReal2(
real_t *
x,
real_t *
y,
const char **token,
707 const double default_x = 0.0,
708 const double default_y = 0.0) {
709 (*x) = parseReal(token, default_x);
710 (*y) = parseReal(token, default_y);
714 const char **token,
const double default_x = 0.0,
715 const double default_y = 0.0,
716 const double default_z = 0.0) {
717 (*x) = parseReal(token, default_x);
718 (*y) = parseReal(token, default_y);
719 (*z) = parseReal(token, default_z);
723 const char **token,
const double default_x = 0.0,
724 const double default_y = 0.0,
725 const double default_z = 0.0,
726 const double default_w = 1.0) {
727 (*x) = parseReal(token, default_x);
728 (*y) = parseReal(token, default_y);
729 (*z) = parseReal(token, default_z);
730 (*w) = parseReal(token, default_w);
737 const double default_x = 0.0,
738 const double default_y = 0.0,
739 const double default_z = 0.0) {
740 (*x) = parseReal(token, default_x);
741 (*y) = parseReal(token, default_y);
742 (*z) = parseReal(token, default_z);
744 const bool found_color =
745 parseReal(token, r) && parseReal(token, g) && parseReal(token, b);
748 (*r) = (*g) = (*b) = 1.0;
754 static inline bool parseOnOff(
const char **token,
bool default_value =
true) {
755 (*token) += strspn((*token),
" \t");
756 const char *end = (*token) + strcspn((*token),
" \t\r");
758 bool ret = default_value;
759 if ((0 == strncmp((*token),
"on", 2))) {
761 }
else if ((0 == strncmp((*token),
"off", 3))) {
771 (*token) += strspn((*token),
" \t");
772 const char *end = (*token) + strcspn((*token),
" \t\r");
775 if ((0 == strncmp((*token),
"cube_top", strlen(
"cube_top")))) {
777 }
else if ((0 == strncmp((*token),
"cube_bottom", strlen(
"cube_bottom")))) {
779 }
else if ((0 == strncmp((*token),
"cube_left", strlen(
"cube_left")))) {
781 }
else if ((0 == strncmp((*token),
"cube_right", strlen(
"cube_right")))) {
783 }
else if ((0 == strncmp((*token),
"cube_front", strlen(
"cube_front")))) {
785 }
else if ((0 == strncmp((*token),
"cube_back", strlen(
"cube_back")))) {
787 }
else if ((0 == strncmp((*token),
"sphere", strlen(
"sphere")))) {
795 static tag_sizes parseTagTriple(
const char **token) {
798 (*token) += strspn((*token),
" \t");
799 ts.num_ints = atoi((*token));
800 (*token) += strcspn((*token),
"/ \t\r");
801 if ((*token)[0] !=
'/') {
807 (*token) += strspn((*token),
" \t");
808 ts.num_reals = atoi((*token));
809 (*token) += strcspn((*token),
"/ \t\r");
810 if ((*token)[0] !=
'/') {
815 ts.num_strings = parseInt(token);
821 static bool parseTriple(
const char **token,
int vsize,
int vnsize,
int vtsize,
822 vertex_index_t *ret) {
827 vertex_index_t vi(-1);
829 if (!fixIndex(atoi((*token)), vsize, &(vi.v_idx))) {
833 (*token) += strcspn((*token),
"/ \t\r");
834 if ((*token)[0] !=
'/') {
841 if ((*token)[0] ==
'/') {
843 if (!fixIndex(atoi((*token)), vnsize, &(vi.vn_idx))) {
846 (*token) += strcspn((*token),
"/ \t\r");
852 if (!fixIndex(atoi((*token)), vtsize, &(vi.vt_idx))) {
856 (*token) += strcspn((*token),
"/ \t\r");
857 if ((*token)[0] !=
'/') {
864 if (!fixIndex(atoi((*token)), vnsize, &(vi.vn_idx))) {
867 (*token) += strcspn((*token),
"/ \t\r");
875 static vertex_index_t parseRawTriple(
const char **token) {
876 vertex_index_t vi(static_cast<int>(0));
878 vi.v_idx = atoi((*token));
879 (*token) += strcspn((*token),
"/ \t\r");
880 if ((*token)[0] !=
'/') {
886 if ((*token)[0] ==
'/') {
888 vi.vn_idx = atoi((*token));
889 (*token) += strcspn((*token),
"/ \t\r");
894 vi.vt_idx = atoi((*token));
895 (*token) += strcspn((*token),
"/ \t\r");
896 if ((*token)[0] !=
'/') {
902 vi.vn_idx = atoi((*token));
903 (*token) += strcspn((*token),
"/ \t\r");
908 texture_option_t *texopt,
909 const char *linebuf,
const bool is_bump) {
911 bool found_texname =
false;
916 texopt->imfchan =
'l';
918 texopt->imfchan =
'm';
920 texopt->bump_multiplier =
static_cast<real_t>(1.0);
921 texopt->clamp =
false;
922 texopt->blendu =
true;
923 texopt->blendv =
true;
924 texopt->sharpness =
static_cast<real_t>(1.0);
925 texopt->brightness =
static_cast<real_t>(0.0);
926 texopt->contrast =
static_cast<real_t>(1.0);
927 texopt->origin_offset[0] =
static_cast<real_t>(0.0);
928 texopt->origin_offset[1] =
static_cast<real_t>(0.0);
929 texopt->origin_offset[2] =
static_cast<real_t>(0.0);
930 texopt->scale[0] =
static_cast<real_t>(1.0);
931 texopt->scale[1] =
static_cast<real_t>(1.0);
932 texopt->scale[2] =
static_cast<real_t>(1.0);
933 texopt->turbulence[0] =
static_cast<real_t>(0.0);
934 texopt->turbulence[1] =
static_cast<real_t>(0.0);
935 texopt->turbulence[2] =
static_cast<real_t>(0.0);
938 const char *token = linebuf;
940 while (!IS_NEW_LINE((*token))) {
941 token += strspn(token,
" \t");
942 if ((0 == strncmp(token,
"-blendu", 7)) && IS_SPACE((token[7]))) {
944 texopt->blendu = parseOnOff(&token,
true);
945 }
else if ((0 == strncmp(token,
"-blendv", 7)) && IS_SPACE((token[7]))) {
947 texopt->blendv = parseOnOff(&token,
true);
948 }
else if ((0 == strncmp(token,
"-clamp", 6)) && IS_SPACE((token[6]))) {
950 texopt->clamp = parseOnOff(&token,
true);
951 }
else if ((0 == strncmp(token,
"-boost", 6)) && IS_SPACE((token[6]))) {
953 texopt->sharpness = parseReal(&token, 1.0);
954 }
else if ((0 == strncmp(token,
"-bm", 3)) && IS_SPACE((token[3]))) {
956 texopt->bump_multiplier = parseReal(&token, 1.0);
957 }
else if ((0 == strncmp(token,
"-o", 2)) && IS_SPACE((token[2]))) {
959 parseReal3(&(texopt->origin_offset[0]), &(texopt->origin_offset[1]),
960 &(texopt->origin_offset[2]), &token);
961 }
else if ((0 == strncmp(token,
"-s", 2)) && IS_SPACE((token[2]))) {
963 parseReal3(&(texopt->scale[0]), &(texopt->scale[1]), &(texopt->scale[2]),
964 &token, 1.0, 1.0, 1.0);
965 }
else if ((0 == strncmp(token,
"-t", 2)) && IS_SPACE((token[2]))) {
967 parseReal3(&(texopt->turbulence[0]), &(texopt->turbulence[1]),
968 &(texopt->turbulence[2]), &token);
969 }
else if ((0 == strncmp(token,
"-type", 5)) && IS_SPACE((token[5]))) {
972 }
else if ((0 == strncmp(token,
"-imfchan", 8)) && IS_SPACE((token[8]))) {
974 token += strspn(token,
" \t");
975 const char *end = token + strcspn(token,
" \t\r");
976 if ((end - token) == 1) {
977 texopt->imfchan = (*token);
980 }
else if ((0 == strncmp(token,
"-mm", 3)) && IS_SPACE((token[3]))) {
982 parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0, 1.0);
983 }
else if ((0 == strncmp(token,
"-colorspace", 11)) &&
984 IS_SPACE((token[11]))) {
986 texopt->colorspace = parseString(&token);
990 size_t len = strcspn(token,
" \t\r");
994 token += strspn(token,
" \t");
999 token += texture_name.length();
1002 found_texname =
true;
1006 if (found_texname) {
1007 (*texname) = texture_name;
1014 static void InitMaterial(material_t *material) {
1015 material->name =
"";
1016 material->ambient_texname =
"";
1017 material->diffuse_texname =
"";
1018 material->specular_texname =
"";
1019 material->specular_highlight_texname =
"";
1020 material->bump_texname =
"";
1021 material->displacement_texname =
"";
1022 material->reflection_texname =
"";
1023 material->alpha_texname =
"";
1024 for (
int i = 0; i < 3; i++) {
1025 material->ambient[i] =
static_cast<real_t>(0.0);
1026 material->diffuse[i] =
static_cast<real_t>(0.0);
1027 material->specular[i] =
static_cast<real_t>(0.0);
1028 material->transmittance[i] =
static_cast<real_t>(0.0);
1029 material->emission[i] =
static_cast<real_t>(0.0);
1031 material->illum = 0;
1032 material->dissolve =
static_cast<real_t>(1.0);
1033 material->shininess =
static_cast<real_t>(1.0);
1034 material->ior =
static_cast<real_t>(1.0);
1036 material->roughness =
static_cast<real_t>(0.0);
1037 material->metallic =
static_cast<real_t>(0.0);
1038 material->sheen =
static_cast<real_t>(0.0);
1039 material->clearcoat_thickness =
static_cast<real_t>(0.0);
1040 material->clearcoat_roughness =
static_cast<real_t>(0.0);
1041 material->anisotropy_rotation =
static_cast<real_t>(0.0);
1042 material->anisotropy =
static_cast<real_t>(0.0);
1043 material->roughness_texname =
"";
1044 material->metallic_texname =
"";
1045 material->sheen_texname =
"";
1046 material->emissive_texname =
"";
1047 material->normal_texname =
"";
1049 material->unknown_parameter.clear();
1053 template <
typename T>
1054 static int pnpoly(
int nvert, T *vertx, T *verty, T testx, T testy) {
1056 for (i = 0, j = nvert - 1; i < nvert; j = i++) {
1057 if (((verty[i] > testy) != (verty[j] > testy)) &&
1059 (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) +
1067 static bool exportGroupsToShape(shape_t *shape,
1068 const std::vector<face_t> &faceGroup,
1069 std::vector<int> &lineGroup,
1070 const std::vector<tag_t> &tags,
1073 const std::vector<real_t> &
v) {
1074 if (faceGroup.empty() && lineGroup.empty()) {
1078 if (!faceGroup.empty()) {
1080 for (
size_t i = 0; i < faceGroup.size(); i++) {
1081 const face_t &face = faceGroup[i];
1083 size_t npolys = face.vertex_indices.size();
1090 vertex_index_t i0 = face.vertex_indices[0];
1091 vertex_index_t
i1(-1);
1092 vertex_index_t
i2 = face.vertex_indices[1];
1096 size_t axes[2] = {1, 2};
1097 for (
size_t k = 0; k < npolys; ++k) {
1098 i0 = face.vertex_indices[(k + 0) % npolys];
1099 i1 = face.vertex_indices[(k + 1) % npolys];
1100 i2 = face.vertex_indices[(k + 2) % npolys];
1101 size_t vi0 = size_t(i0.v_idx);
1102 size_t vi1 = size_t(
i1.v_idx);
1103 size_t vi2 = size_t(i2.v_idx);
1105 if (((3 * vi0 + 2) >= v.size()) || ((3 * vi1 + 2) >= v.size()) ||
1106 ((3 * vi2 + 2) >= v.size())) {
1111 real_t v0x = v[vi0 * 3 + 0];
1112 real_t v0y = v[vi0 * 3 + 1];
1113 real_t v0z = v[vi0 * 3 + 2];
1114 real_t v1x = v[vi1 * 3 + 0];
1115 real_t v1y = v[vi1 * 3 + 1];
1116 real_t v1z = v[vi1 * 3 + 2];
1117 real_t v2x = v[vi2 * 3 + 0];
1118 real_t v2y = v[vi2 * 3 + 1];
1119 real_t v2z = v[vi2 * 3 + 2];
1126 real_t cx = std::fabs(e0y * e1z - e0z * e1y);
1127 real_t cy = std::fabs(e0z * e1x - e0x * e1z);
1128 real_t cz = std::fabs(e0x * e1y - e0y * e1x);
1129 const real_t epsilon = std::numeric_limits<real_t>::epsilon();
1130 if (cx > epsilon || cy > epsilon || cz > epsilon) {
1132 if (cx > cy && cx > cz) {
1135 if (cz > cx && cz > cy) axes[1] = 1;
1142 for (
size_t k = 0; k < npolys; ++k) {
1143 i0 = face.vertex_indices[(k + 0) % npolys];
1144 i1 = face.vertex_indices[(k + 1) % npolys];
1145 size_t vi0 = size_t(i0.v_idx);
1146 size_t vi1 = size_t(
i1.v_idx);
1147 if (((vi0 * 3 + axes[0]) >= v.size()) ||
1148 ((vi0 * 3 + axes[1]) >= v.size()) ||
1149 ((vi1 * 3 + axes[0]) >= v.size()) ||
1150 ((vi1 * 3 + axes[1]) >= v.size())) {
1154 real_t v0x = v[vi0 * 3 + axes[0]];
1155 real_t v0y = v[vi0 * 3 + axes[1]];
1156 real_t v1x = v[vi1 * 3 + axes[0]];
1157 real_t v1y = v[vi1 * 3 + axes[1]];
1158 area += (v0x * v1y - v0y * v1x) * static_cast<real_t>(0.5);
1164 face_t remainingFace = face;
1165 size_t guess_vert = 0;
1166 vertex_index_t ind[3];
1169 while (remainingFace.vertex_indices.size() > 3 && maxRounds > 0) {
1170 npolys = remainingFace.vertex_indices.size();
1171 if (guess_vert >= npolys) {
1173 guess_vert -= npolys;
1175 for (
size_t k = 0; k < 3; k++) {
1176 ind[k] = remainingFace.vertex_indices[(guess_vert + k) % npolys];
1177 size_t vi = size_t(ind[k].v_idx);
1178 if (((vi * 3 + axes[0]) >= v.size()) ||
1179 ((vi * 3 + axes[1]) >= v.size())) {
1181 vx[k] =
static_cast<real_t>(0.0);
1182 vy[k] =
static_cast<real_t>(0.0);
1184 vx[k] = v[vi * 3 + axes[0]];
1185 vy[k] = v[vi * 3 + axes[1]];
1188 real_t e0x = vx[1] - vx[0];
1189 real_t e0y = vy[1] - vy[0];
1190 real_t e1x = vx[2] - vx[1];
1191 real_t e1y = vy[2] - vy[1];
1194 if (cross * area < static_cast<real_t>(0.0)) {
1200 bool overlap =
false;
1201 for (
size_t otherVert = 3; otherVert < npolys; ++otherVert) {
1202 size_t idx = (guess_vert + otherVert) % npolys;
1204 if (idx >= remainingFace.vertex_indices.size()) {
1209 size_t ovi = size_t(remainingFace.vertex_indices[idx].v_idx);
1211 if (((ovi * 3 + axes[0]) >= v.size()) ||
1212 ((ovi * 3 + axes[1]) >= v.size())) {
1216 real_t tx = v[ovi * 3 + axes[0]];
1217 real_t ty = v[ovi * 3 + axes[1]];
1218 if (pnpoly(3, vx, vy, tx, ty)) {
1232 idx0.vertex_index = ind[0].v_idx;
1233 idx0.normal_index = ind[0].vn_idx;
1234 idx0.texcoord_index = ind[0].vt_idx;
1235 idx1.vertex_index = ind[1].v_idx;
1236 idx1.normal_index = ind[1].vn_idx;
1237 idx1.texcoord_index = ind[1].vt_idx;
1238 idx2.vertex_index = ind[2].v_idx;
1239 idx2.normal_index = ind[2].vn_idx;
1240 idx2.texcoord_index = ind[2].vt_idx;
1242 shape->mesh.indices.push_back(idx0);
1243 shape->mesh.indices.push_back(idx1);
1244 shape->mesh.indices.push_back(idx2);
1246 shape->mesh.num_face_vertices.push_back(3);
1247 shape->mesh.material_ids.push_back(material_id);
1248 shape->mesh.smoothing_group_ids.push_back(face.smoothing_group_id);
1252 size_t removed_vert_index = (guess_vert + 1) % npolys;
1253 while (removed_vert_index + 1 < npolys) {
1254 remainingFace.vertex_indices[removed_vert_index] =
1255 remainingFace.vertex_indices[removed_vert_index + 1];
1256 removed_vert_index += 1;
1258 remainingFace.vertex_indices.pop_back();
1261 if (remainingFace.vertex_indices.size() == 3) {
1262 i0 = remainingFace.vertex_indices[0];
1263 i1 = remainingFace.vertex_indices[1];
1264 i2 = remainingFace.vertex_indices[2];
1267 idx0.vertex_index = i0.v_idx;
1268 idx0.normal_index = i0.vn_idx;
1269 idx0.texcoord_index = i0.vt_idx;
1270 idx1.vertex_index =
i1.v_idx;
1271 idx1.normal_index =
i1.vn_idx;
1272 idx1.texcoord_index =
i1.vt_idx;
1273 idx2.vertex_index = i2.v_idx;
1274 idx2.normal_index = i2.vn_idx;
1275 idx2.texcoord_index = i2.vt_idx;
1277 shape->mesh.indices.push_back(idx0);
1278 shape->mesh.indices.push_back(idx1);
1279 shape->mesh.indices.push_back(idx2);
1281 shape->mesh.num_face_vertices.push_back(3);
1282 shape->mesh.material_ids.push_back(material_id);
1283 shape->mesh.smoothing_group_ids.push_back(face.smoothing_group_id);
1287 for (
size_t k = 0; k < npolys; k++) {
1289 idx.vertex_index = face.vertex_indices[k].v_idx;
1290 idx.normal_index = face.vertex_indices[k].vn_idx;
1291 idx.texcoord_index = face.vertex_indices[k].vt_idx;
1292 shape->mesh.indices.push_back(idx);
1295 shape->mesh.num_face_vertices.push_back(
1296 static_cast<unsigned char>(npolys));
1297 shape->mesh.material_ids.push_back(material_id);
1298 shape->mesh.smoothing_group_ids.push_back(
1299 face.smoothing_group_id);
1304 shape->mesh.tags = tags;
1307 if (!lineGroup.empty()) {
1308 shape->path.indices.swap(lineGroup);
1316 static void SplitString(
const std::string &s,
char delim,
1317 std::vector<std::string> &elems) {
1318 std::stringstream ss;
1321 while (std::getline(ss, item, delim)) {
1322 elems.push_back(item);
1326 void LoadMtl(std::map<std::string, int> *material_map,
1327 std::vector<material_t> *materials, std::istream *inStream,
1332 material_t material;
1333 InitMaterial(&material);
1337 bool has_tr =
false;
1339 std::stringstream warn_ss;
1343 while (inStream->peek() != -1) {
1344 safeGetline(*inStream, linebuf);
1348 if (linebuf.size() > 0) {
1349 linebuf = linebuf.substr(0, linebuf.find_last_not_of(
" \t") + 1);
1353 if (linebuf.size() > 0) {
1354 if (linebuf[linebuf.size() - 1] ==
'\n')
1355 linebuf.erase(linebuf.size() - 1);
1357 if (linebuf.size() > 0) {
1358 if (linebuf[linebuf.size() - 1] ==
'\r')
1359 linebuf.erase(linebuf.size() - 1);
1363 if (linebuf.empty()) {
1368 const char *token = linebuf.c_str();
1369 token += strspn(token,
" \t");
1372 if (token[0] ==
'\0')
continue;
1374 if (token[0] ==
'#')
continue;
1377 if ((0 == strncmp(token,
"newmtl", 6)) && IS_SPACE((token[6]))) {
1379 if (!material.name.empty()) {
1380 material_map->insert(std::pair<std::string, int>(
1381 material.name, static_cast<int>(materials->size())));
1382 materials->push_back(material);
1386 InitMaterial(&material);
1394 std::stringstream sstr;
1396 material.name = sstr.str();
1402 if (token[0] ==
'K' && token[1] ==
'a' && IS_SPACE((token[2]))) {
1405 parseReal3(&r, &g, &b, &token);
1406 material.ambient[0] =
r;
1407 material.ambient[1] =
g;
1408 material.ambient[2] =
b;
1413 if (token[0] ==
'K' && token[1] ==
'd' && IS_SPACE((token[2]))) {
1416 parseReal3(&r, &g, &b, &token);
1417 material.diffuse[0] =
r;
1418 material.diffuse[1] =
g;
1419 material.diffuse[2] =
b;
1424 if (token[0] ==
'K' && token[1] ==
's' && IS_SPACE((token[2]))) {
1427 parseReal3(&r, &g, &b, &token);
1428 material.specular[0] =
r;
1429 material.specular[1] =
g;
1430 material.specular[2] =
b;
1435 if ((token[0] ==
'K' && token[1] ==
't' && IS_SPACE((token[2]))) ||
1436 (token[0] ==
'T' && token[1] ==
'f' && IS_SPACE((token[2])))) {
1439 parseReal3(&r, &g, &b, &token);
1440 material.transmittance[0] =
r;
1441 material.transmittance[1] =
g;
1442 material.transmittance[2] =
b;
1447 if (token[0] ==
'N' && token[1] ==
'i' && IS_SPACE((token[2]))) {
1449 material.ior = parseReal(&token);
1454 if (token[0] ==
'K' && token[1] ==
'e' && IS_SPACE(token[2])) {
1457 parseReal3(&r, &g, &b, &token);
1458 material.emission[0] =
r;
1459 material.emission[1] =
g;
1460 material.emission[2] =
b;
1465 if (token[0] ==
'N' && token[1] ==
's' && IS_SPACE(token[2])) {
1467 material.shininess = parseReal(&token);
1472 if (0 == strncmp(token,
"illum", 5) && IS_SPACE(token[5])) {
1474 material.illum = parseInt(&token);
1479 if ((token[0] ==
'd' && IS_SPACE(token[1]))) {
1481 material.dissolve = parseReal(&token);
1484 warn_ss <<
"Both `d` and `Tr` parameters defined for \""
1485 << material.name <<
"\". Use the value of `d` for dissolve (line "
1486 << line_no <<
" in .mtl.)"
1492 if (token[0] ==
'T' && token[1] ==
'r' && IS_SPACE(token[2])) {
1496 warn_ss <<
"Both `d` and `Tr` parameters defined for \""
1497 << material.name <<
"\". Use the value of `d` for dissolve (line "
1498 << line_no <<
" in .mtl.)"
1504 material.dissolve =
static_cast<real_t>(1.0) - parseReal(&token);
1511 if (token[0] ==
'P' && token[1] ==
'r' && IS_SPACE(token[2])) {
1513 material.roughness = parseReal(&token);
1518 if (token[0] ==
'P' && token[1] ==
'm' && IS_SPACE(token[2])) {
1520 material.metallic = parseReal(&token);
1525 if (token[0] ==
'P' && token[1] ==
's' && IS_SPACE(token[2])) {
1527 material.sheen = parseReal(&token);
1532 if (token[0] ==
'P' && token[1] ==
'c' && IS_SPACE(token[2])) {
1534 material.clearcoat_thickness = parseReal(&token);
1539 if ((0 == strncmp(token,
"Pcr", 3)) && IS_SPACE(token[3])) {
1541 material.clearcoat_roughness = parseReal(&token);
1546 if ((0 == strncmp(token,
"aniso", 5)) && IS_SPACE(token[5])) {
1548 material.anisotropy = parseReal(&token);
1553 if ((0 == strncmp(token,
"anisor", 6)) && IS_SPACE(token[6])) {
1555 material.anisotropy_rotation = parseReal(&token);
1560 if ((0 == strncmp(token,
"map_Ka", 6)) && IS_SPACE(token[6])) {
1563 &(material.ambient_texopt), token,
1569 if ((0 == strncmp(token,
"map_Kd", 6)) && IS_SPACE(token[6])) {
1572 &(material.diffuse_texopt), token,
1578 if ((0 == strncmp(token,
"map_Ks", 6)) && IS_SPACE(token[6])) {
1581 &(material.specular_texopt), token,
1587 if ((0 == strncmp(token,
"map_Ns", 6)) && IS_SPACE(token[6])) {
1590 &(material.specular_highlight_texopt), token,
1596 if ((0 == strncmp(token,
"map_bump", 8)) && IS_SPACE(token[8])) {
1599 &(material.bump_texopt), token,
1605 if ((0 == strncmp(token,
"map_Bump", 8)) && IS_SPACE(token[8])) {
1608 &(material.bump_texopt), token,
1614 if ((0 == strncmp(token,
"bump", 4)) && IS_SPACE(token[4])) {
1617 &(material.bump_texopt), token,
1623 if ((0 == strncmp(token,
"map_d", 5)) && IS_SPACE(token[5])) {
1625 material.alpha_texname = token;
1627 &(material.alpha_texopt), token,
1633 if ((0 == strncmp(token,
"disp", 4)) && IS_SPACE(token[4])) {
1636 &(material.displacement_texopt), token,
1642 if ((0 == strncmp(token,
"refl", 4)) && IS_SPACE(token[4])) {
1645 &(material.reflection_texopt), token,
1651 if ((0 == strncmp(token,
"map_Pr", 6)) && IS_SPACE(token[6])) {
1654 &(material.roughness_texopt), token,
1660 if ((0 == strncmp(token,
"map_Pm", 6)) && IS_SPACE(token[6])) {
1663 &(material.metallic_texopt), token,
1669 if ((0 == strncmp(token,
"map_Ps", 6)) && IS_SPACE(token[6])) {
1672 &(material.sheen_texopt), token,
1678 if ((0 == strncmp(token,
"map_Ke", 6)) && IS_SPACE(token[6])) {
1681 &(material.emissive_texopt), token,
1687 if ((0 == strncmp(token,
"norm", 4)) && IS_SPACE(token[4])) {
1690 &(material.normal_texname), &(material.normal_texopt), token,
1696 const char *_space = strchr(token,
' ');
1698 _space = strchr(token,
'\t');
1701 std::ptrdiff_t len = _space - token;
1704 material.unknown_parameter.insert(
1705 std::pair<std::string, std::string>(key, value));
1709 material_map->insert(std::pair<std::string, int>(
1710 material.name, static_cast<int>(materials->size())));
1711 materials->push_back(material);
1714 (*warning) = warn_ss.str();
1719 std::vector<material_t> *materials,
1720 std::map<std::string, int> *matMap,
1724 if (!m_mtlBaseDir.empty()) {
1732 std::stringstream ss;
1733 ss <<
"Material file [ " << filepath <<
" ] not found." << std::endl;
1735 (*warn) += ss.str();
1740 LoadMtl(matMap, materials, &matIStream, warn, err);
1746 std::vector<material_t> *materials,
1747 std::map<std::string, int> *matMap,
1752 std::stringstream ss;
1753 ss <<
"Material stream in error state. " << std::endl;
1755 (*warn) += ss.str();
1760 LoadMtl(matMap, materials, &m_inStream, warn, err);
1765 bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
1766 std::vector<material_t> *materials,
std::string *warn,
1768 bool trianglulate,
bool default_vcols_fallback) {
1769 attrib->vertices.clear();
1770 attrib->normals.clear();
1771 attrib->texcoords.clear();
1772 attrib->colors.clear();
1775 std::stringstream errss;
1779 errss <<
"Cannot open file [" << filename <<
"]" << std::endl;
1781 (*err) = errss.str();
1786 std::string baseDir = mtl_basedir ? mtl_basedir :
"";
1787 if (!baseDir.empty()) {
1789 const char dirsep =
'/';
1791 const char dirsep =
'\\';
1793 if (baseDir[baseDir.length() - 1] != dirsep) baseDir += dirsep;
1795 MaterialFileReader matFileReader(baseDir);
1797 return LoadObj(attrib, shapes, materials, warn, err, &ifs, &matFileReader,
1798 trianglulate, default_vcols_fallback);
1801 bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
1802 std::vector<material_t> *materials,
std::string *warn,
1804 MaterialReader *readMatFn ,
bool triangulate,
1805 bool default_vcols_fallback) {
1806 std::stringstream errss;
1808 std::vector<real_t>
v;
1809 std::vector<real_t>
vn;
1810 std::vector<real_t> vt;
1811 std::vector<real_t> vc;
1812 std::vector<tag_t> tags;
1813 std::vector<face_t> faceGroup;
1814 std::vector<int> lineGroup;
1818 std::map<std::string, int> material_map;
1822 unsigned int current_smoothing_id =
1825 int greatest_v_idx = -1;
1826 int greatest_vn_idx = -1;
1827 int greatest_vt_idx = -1;
1831 bool found_all_colors =
true;
1833 size_t line_num = 0;
1835 while (inStream->peek() != -1) {
1836 safeGetline(*inStream, linebuf);
1841 if (linebuf.size() > 0) {
1842 if (linebuf[linebuf.size() - 1] ==
'\n')
1843 linebuf.erase(linebuf.size() - 1);
1845 if (linebuf.size() > 0) {
1846 if (linebuf[linebuf.size() - 1] ==
'\r')
1847 linebuf.erase(linebuf.size() - 1);
1851 if (linebuf.empty()) {
1856 const char *token = linebuf.c_str();
1857 token += strspn(token,
" \t");
1860 if (token[0] ==
'\0')
continue;
1862 if (token[0] ==
'#')
continue;
1865 if (token[0] ==
'v' && IS_SPACE((token[1]))) {
1870 found_all_colors &= parseVertexWithColor(&x, &y, &z, &r, &g, &b, &token);
1876 if (found_all_colors || default_vcols_fallback) {
1886 if (token[0] ==
'v' && token[1] ==
'n' && IS_SPACE((token[2]))) {
1889 parseReal3(&x, &y, &z, &token);
1897 if (token[0] ==
'v' && token[1] ==
't' && IS_SPACE((token[2]))) {
1900 parseReal2(&x, &y, &token);
1907 if (token[0] ==
'l' && IS_SPACE((token[1]))) {
1911 bool end_line_bit = 0;
1912 while (!IS_NEW_LINE(token[0])) {
1915 fixIndex(parseInt(&token), 0, &idx);
1917 size_t n = strspn(token,
" \t\r");
1920 if (!end_line_bit) {
1921 line_cache.idx0 = idx;
1923 line_cache.idx1 = idx;
1924 lineGroup.push_back(line_cache.idx0);
1925 lineGroup.push_back(line_cache.idx1);
1926 line_cache = line_t();
1928 end_line_bit = !end_line_bit;
1934 if (token[0] ==
'f' && IS_SPACE((token[1]))) {
1936 token += strspn(token,
" \t");
1940 face.smoothing_group_id = current_smoothing_id;
1941 face.vertex_indices.reserve(3);
1943 while (!IS_NEW_LINE(token[0])) {
1945 if (!parseTriple(&token, static_cast<int>(v.size() / 3),
1946 static_cast<int>(vn.size() / 3),
1947 static_cast<int>(vt.size() / 2), &vi)) {
1949 std::stringstream ss;
1950 ss <<
"Failed parse `f' line(e.g. zero value for face index. line " << line_num <<
".)\n";
1956 greatest_v_idx = greatest_v_idx > vi.v_idx ? greatest_v_idx : vi.v_idx;
1958 greatest_vn_idx > vi.vn_idx ? greatest_vn_idx : vi.vn_idx;
1960 greatest_vt_idx > vi.vt_idx ? greatest_vt_idx : vi.vt_idx;
1962 face.vertex_indices.push_back(vi);
1963 size_t n = strspn(token,
" \t\r");
1968 faceGroup.push_back(face);
1974 if ((0 == strncmp(token,
"usemtl", 6)) && IS_SPACE((token[6]))) {
1976 std::stringstream ss;
1980 int newMaterialId = -1;
1981 if (material_map.find(namebuf) != material_map.end()) {
1982 newMaterialId = material_map[namebuf];
1987 if (newMaterialId != material) {
1991 exportGroupsToShape(&shape, faceGroup, lineGroup, tags, material, name,
1994 material = newMaterialId;
2001 if ((0 == strncmp(token,
"mtllib", 6)) && IS_SPACE((token[6]))) {
2005 std::vector<std::string> filenames;
2008 if (filenames.empty()) {
2010 std::stringstream ss;
2011 ss <<
"Looks like empty filename for mtllib. Use default "
2012 "material (line " << line_num <<
".)\n";
2014 (*warn) += ss.str();
2018 for (
size_t s = 0; s < filenames.size(); s++) {
2021 bool ok = (*readMatFn)(filenames[
s].c_str(), materials,
2022 &material_map, &warn_mtl, &err_mtl);
2023 if (warn && (!warn_mtl.empty())) {
2024 (*warn) += warn_mtl;
2027 if (err && (!err_mtl.empty())) {
2040 "Failed to load material file(s). Use default "
2051 if (token[0] ==
'g' && IS_SPACE((token[1]))) {
2053 bool ret = exportGroupsToShape(&shape, faceGroup, lineGroup, tags,
2054 material, name, triangulate, v);
2057 if (shape.mesh.indices.size() > 0) {
2058 shapes->push_back(shape);
2066 std::vector<std::string> names;
2068 while (!IS_NEW_LINE(token[0])) {
2070 names.push_back(str);
2071 token += strspn(token,
" \t\r");
2076 if (names.size() < 2) {
2079 std::stringstream ss;
2080 ss <<
"Empty group name. line: " << line_num <<
"\n";
2081 (*warn) += ss.str();
2085 std::stringstream ss;
2092 for (
size_t i = 2; i < names.size(); i++) {
2093 ss <<
" " << names[i];
2103 if (token[0] ==
'o' && IS_SPACE((token[1]))) {
2105 bool ret = exportGroupsToShape(&shape, faceGroup, lineGroup, tags,
2106 material, name, triangulate, v);
2108 shapes->push_back(shape);
2117 std::stringstream ss;
2124 if (token[0] ==
't' && IS_SPACE(token[1])) {
2125 const int max_tag_nums = 8192;
2130 tag.name = parseString(&token);
2132 tag_sizes ts = parseTagTriple(&token);
2134 if (ts.num_ints < 0) {
2137 if (ts.num_ints > max_tag_nums) {
2138 ts.num_ints = max_tag_nums;
2141 if (ts.num_reals < 0) {
2144 if (ts.num_reals > max_tag_nums) {
2145 ts.num_reals = max_tag_nums;
2148 if (ts.num_strings < 0) {
2151 if (ts.num_strings > max_tag_nums) {
2152 ts.num_strings = max_tag_nums;
2155 tag.intValues.resize(static_cast<size_t>(ts.num_ints));
2157 for (
size_t i = 0; i < static_cast<size_t>(ts.num_ints); ++i) {
2158 tag.intValues[i] = parseInt(&token);
2161 tag.floatValues.resize(static_cast<size_t>(ts.num_reals));
2162 for (
size_t i = 0; i < static_cast<size_t>(ts.num_reals); ++i) {
2163 tag.floatValues[i] = parseReal(&token);
2166 tag.stringValues.resize(static_cast<size_t>(ts.num_strings));
2167 for (
size_t i = 0; i < static_cast<size_t>(ts.num_strings); ++i) {
2168 tag.stringValues[i] = parseString(&token);
2171 tags.push_back(tag);
2176 if (token[0] ==
's' && IS_SPACE(token[1])) {
2181 token += strspn(token,
" \t");
2183 if (token[0] ==
'\0') {
2187 if (token[0] ==
'\r' || token[1] ==
'\n') {
2191 if (strlen(token) >= 3) {
2192 if (token[0] ==
'o' && token[1] ==
'f' && token[2] ==
'f') {
2193 current_smoothing_id = 0;
2197 int smGroupId = parseInt(&token);
2198 if (smGroupId < 0) {
2201 current_smoothing_id = 0;
2203 current_smoothing_id =
static_cast<unsigned int>(smGroupId);
2214 if (!found_all_colors && !default_vcols_fallback) {
2218 if (greatest_v_idx >= static_cast<int>(v.size() / 3)) {
2220 std::stringstream ss;
2221 ss <<
"Vertex indices out of bounds (line " << line_num <<
".)\n" << std::endl;
2222 (*warn) += ss.str();
2225 if (greatest_vn_idx >= static_cast<int>(vn.size() / 3)) {
2227 std::stringstream ss;
2228 ss <<
"Vertex normal indices out of bounds (line " << line_num <<
".)\n" << std::endl;
2229 (*warn) += ss.str();
2232 if (greatest_vt_idx >= static_cast<int>(vt.size() / 2)) {
2234 std::stringstream ss;
2235 ss <<
"Vertex texcoord indices out of bounds (line " << line_num <<
".)\n" << std::endl;
2236 (*warn) += ss.str();
2240 bool ret = exportGroupsToShape(&shape, faceGroup, lineGroup, tags, material,
2241 name, triangulate, v);
2246 if (ret || shape.mesh.indices.size()) {
2247 shapes->push_back(shape);
2252 (*err) += errss.str();
2255 attrib->vertices.swap(v);
2256 attrib->normals.swap(vn);
2257 attrib->texcoords.swap(vt);
2258 attrib->colors.swap(vc);
2265 MaterialReader *readMatFn ,
2268 std::stringstream errss;
2271 std::map<std::string, int> material_map;
2272 int material_id = -1;
2275 std::vector<material_t> materials;
2276 std::vector<std::string> names;
2278 std::vector<const char *> names_out;
2281 while (inStream.peek() != -1) {
2282 safeGetline(inStream, linebuf);
2285 if (linebuf.size() > 0) {
2286 if (linebuf[linebuf.size() - 1] ==
'\n')
2287 linebuf.erase(linebuf.size() - 1);
2289 if (linebuf.size() > 0) {
2290 if (linebuf[linebuf.size() - 1] ==
'\r')
2291 linebuf.erase(linebuf.size() - 1);
2295 if (linebuf.empty()) {
2300 const char *token = linebuf.c_str();
2301 token += strspn(token,
" \t");
2304 if (token[0] ==
'\0')
continue;
2306 if (token[0] ==
'#')
continue;
2309 if (token[0] ==
'v' && IS_SPACE((token[1]))) {
2313 parseV(&x, &y, &z, &w, &token);
2314 if (callback.vertex_cb) {
2315 callback.vertex_cb(user_data, x, y, z, w);
2321 if (token[0] ==
'v' && token[1] ==
'n' && IS_SPACE((token[2]))) {
2324 parseReal3(&x, &y, &z, &token);
2325 if (callback.normal_cb) {
2326 callback.normal_cb(user_data, x, y, z);
2332 if (token[0] ==
'v' && token[1] ==
't' && IS_SPACE((token[2]))) {
2335 parseReal3(&x, &y, &z, &token);
2336 if (callback.texcoord_cb) {
2337 callback.texcoord_cb(user_data, x, y, z);
2343 if (token[0] ==
'f' && IS_SPACE((token[1]))) {
2345 token += strspn(token,
" \t");
2348 while (!IS_NEW_LINE(token[0])) {
2349 vertex_index_t vi = parseRawTriple(&token);
2352 idx.vertex_index = vi.v_idx;
2353 idx.normal_index = vi.vn_idx;
2354 idx.texcoord_index = vi.vt_idx;
2356 indices.push_back(idx);
2357 size_t n = strspn(token,
" \t\r");
2361 if (callback.index_cb && indices.size() > 0) {
2362 callback.index_cb(user_data, &indices.at(0),
2363 static_cast<int>(indices.size()));
2370 if ((0 == strncmp(token,
"usemtl", 6)) && IS_SPACE((token[6]))) {
2372 std::stringstream ss;
2376 int newMaterialId = -1;
2377 if (material_map.find(namebuf) != material_map.end()) {
2378 newMaterialId = material_map[namebuf];
2383 if (newMaterialId != material_id) {
2384 material_id = newMaterialId;
2387 if (callback.usemtl_cb) {
2388 callback.usemtl_cb(user_data, namebuf.c_str(), material_id);
2395 if ((0 == strncmp(token,
"mtllib", 6)) && IS_SPACE((token[6]))) {
2399 std::vector<std::string> filenames;
2402 if (filenames.empty()) {
2405 "Looks like empty filename for mtllib. Use default "
2410 for (
size_t s = 0; s < filenames.size(); s++) {
2413 bool ok = (*readMatFn)(filenames[
s].c_str(), &materials,
2414 &material_map, &warn_mtl, &err_mtl);
2416 if (warn && (!warn_mtl.empty())) {
2417 (*warn) += warn_mtl;
2420 if (err && (!err_mtl.empty())) {
2433 "Failed to load material file(s). Use default "
2437 if (callback.mtllib_cb) {
2438 callback.mtllib_cb(user_data, &materials.at(0),
2439 static_cast<int>(materials.size()));
2449 if (token[0] ==
'g' && IS_SPACE((token[1]))) {
2452 while (!IS_NEW_LINE(token[0])) {
2454 names.push_back(str);
2455 token += strspn(token,
" \t\r");
2458 assert(names.size() > 0);
2460 if (callback.group_cb) {
2461 if (names.size() > 1) {
2463 names_out.resize(names.size() - 1);
2464 for (
size_t j = 0; j < names_out.size(); j++) {
2465 names_out[
j] = names[j + 1].c_str();
2467 callback.group_cb(user_data, &names_out.at(0),
2468 static_cast<int>(names_out.size()));
2471 callback.group_cb(user_data, NULL, 0);
2479 if (token[0] ==
'o' && IS_SPACE((token[1]))) {
2483 std::stringstream ss;
2487 if (callback.object_cb) {
2488 callback.object_cb(user_data, object_name.c_str());
2495 if (token[0] ==
't' && IS_SPACE(token[1])) {
2499 std::stringstream ss;
2501 tag.name = ss.str();
2503 token += tag.name.size() + 1;
2505 tag_sizes ts = parseTagTriple(&token);
2507 tag.intValues.resize(static_cast<size_t>(ts.num_ints));
2509 for (
size_t i = 0; i < static_cast<size_t>(ts.num_ints); ++i) {
2510 tag.intValues[i] = atoi(token);
2511 token += strcspn(token,
"/ \t\r") + 1;
2514 tag.floatValues.resize(static_cast<size_t>(ts.num_reals));
2515 for (
size_t i = 0; i < static_cast<size_t>(ts.num_reals); ++i) {
2516 tag.floatValues[i] = parseReal(&token);
2517 token += strcspn(token,
"/ \t\r") + 1;
2520 tag.stringValues.resize(static_cast<size_t>(ts.num_strings));
2521 for (
size_t i = 0; i < static_cast<size_t>(ts.num_strings); ++i) {
2522 std::stringstream ss;
2524 tag.stringValues[i] = ss.str();
2525 token += tag.stringValues[i].size() + 1;
2528 tags.push_back(tag);
2536 (*err) += errss.str();
2543 #pragma clang diagnostic pop
void(* vertex_cb)(void *user_data, real_t x, real_t y, real_t z, real_t w)
void(* index_cb)(void *user_data, index_t *indices, int num_indices)
GT_API const UT_StringHolder filename
void(* group_cb)(void *user_data, const char **names, int num_names)
std::string specular_highlight_texname
GLsizei GLenum const void * indices
std::string specular_texname
texture_option_t alpha_texopt
OIIO_NAMESPACE_BEGIN typedef std::ifstream ifstream
std::vector< real_t > texcoords
virtual bool operator()(const std::string &matId, std::vector< material_t > *materials, std::map< std::string, int > *matMap, std::string *warn, std::string *err)
GLsizei const GLchar *const * string
std::vector< index_t > indices
std::vector< std::string > stringValues
GLdouble GLdouble GLdouble z
bool ParseTextureNameAndOption(std::string *texname, texture_option_t *texopt, const char *linebuf, const bool is_bump)
real_t clearcoat_roughness
real_t anisotropy_rotation
**But if you need a result
struct tinyobj::callback_t_ callback_t
std::string reflection_texname
void read(T &in, bool &v)
std::vector< int > indices
texture_option_t displacement_texopt
std::vector< real_t > floatValues
virtual ~MaterialStreamReader()
virtual ~MaterialReader()
std::string ambient_texname
ImageBuf OIIO_API pow(const ImageBuf &A, cspan< float > B, ROI roi={}, int nthreads=0)
GA_API const UT_StringHolder scale
texture_option_t roughness_texopt
std::string sheen_texname
std::vector< int > material_ids
texture_option_t specular_texopt
void LoadMtl(std::map< std::string, int > *material_map, std::vector< material_t > *materials, std::istream *inStream, std::string *warning, std::string *err)
Loads materials into std::map.
std::vector< unsigned int > smoothing_group_ids
void(* normal_cb)(void *user_data, real_t x, real_t y, real_t z)
texture_option_t diffuse_texopt
void(* texcoord_cb)(void *user_data, real_t x, real_t y, real_t z)
real_t clearcoat_thickness
std::string diffuse_texname
texture_option_t normal_texopt
GT_API const UT_StringHolder object_name
MaterialStreamReader(std::istream &inStream)
std::vector< real_t > normals
GLuint const GLchar * name
IMATH_HOSTDEVICE constexpr int sign(T a) IMATH_NOEXCEPT
GLboolean GLboolean GLboolean b
virtual ~MaterialFileReader()
std::string roughness_texname
std::vector< unsigned char > num_face_vertices
void(* object_cb)(void *user_data, const char *name)
std::vector< tag_t > tags
void(* usemtl_cb)(void *user_data, const char *name, int material_id)
texture_option_t sheen_texopt
std::string metallic_texname
bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback, void *user_data=NULL, MaterialReader *readMatFn=NULL, std::string *warn=NULL, std::string *err=NULL)
texture_option_t emissive_texopt
std::map< std::string, std::string > unknown_parameter
std::vector< int > intValues
virtual bool operator()(const std::string &matId, std::vector< material_t > *materials, std::map< std::string, int > *matMap, std::string *warn, std::string *err)
texture_option_t ambient_texopt
bool LoadObj(attrib_t *attrib, std::vector< shape_t > *shapes, std::vector< material_t > *materials, std::string *warn, std::string *err, const char *filename, const char *mtl_basedir=NULL, bool triangulate=true, bool default_vcols_fallback=true)
std::string alpha_texname
std::string normal_texname
std::string displacement_texname
std::vector< real_t > vertices
MaterialFileReader(const std::string &mtl_basedir)
std::string emissive_texname
GLubyte GLubyte GLubyte GLubyte w
texture_option_t specular_highlight_texopt
texture_option_t metallic_texopt
texture_option_t bump_texopt
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)
texture_option_t reflection_texopt
GLdouble GLdouble GLint vn
virtual bool operator()(const std::string &matId, std::vector< material_t > *materials, std::map< std::string, int > *matMap, std::string *warn, std::string *err)=0
GA_API const UT_StringHolder area
void(* mtllib_cb)(void *user_data, const material_t *materials, int num_materials)
std::vector< real_t > colors