Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
WavefrontOBJ.cpp
1 /*
2  Harmonic Flow Framework
3  Copyright (C) 2016-2018 Andreas Widen <andreas@harmonicflow.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "WavefrontOBJ.h"
22 
24 #include "platform/PakInterface.h"
25 #include "platform/Environment.h"
26 #include <assert.h>
27 #include <unordered_map> // C++11
28 
29 // we only support fp32_hf (float) for now so #undef if needed but give
30 // message about it..
31 #ifdef TINYOBJLOADER_USE_DOUBLE
32 #undef TINYOBJLOADER_USE_DOUBLE
33 #pragma message "*** Forcing #undef TINYOBJLOADER_USE_DOUBLE .."
34 #endif
35 
36 #define TINYOBJLOADER_IMPLEMENTATION
37 #include "tiny_obj_loader.h"
38 
39 using namespace HFCore;
40 
41 #include "debug/CrtDbgNew.h"
42 
43 /**
44  * @cond DOXYGEN_EXCLUDE
45  */
46 namespace std
47 {
48  template<> struct hash<Geometry::VertexPosNorTex>
49  {
50  size_t operator()(Geometry::VertexPosNorTex const &vertex) const
51  {
52  return ((hash<glm::vec3>()(vertex.position) ^ (hash<glm::vec3>()(vertex.normal) << 1)) >> 1) ^
53  (hash<glm::vec2>()(vertex.uv) << 1);
54  }
55  };
56 }
57 
58 class MaterialStringStreamReader : public tinyobj::MaterialReader
59 {
60  public:
61  MaterialStringStreamReader(const std::string &matSStream) : mMatSStream(matSStream) {}
62  virtual ~MaterialStringStreamReader() {}
63 
64  virtual bool operator()(const std::string &matId,
65  std::vector<tinyobj::material_t> *materials,
66  std::map<std::string, int> *matMap,
67  std::string *err)
68  {
69  (void)matId;
70  (void)err;
71  tinyobj::LoadMtl(matMap, materials, &mMatSStream, &mWarningMsg);
72  return true;
73  }
74 
75  private:
76  std::stringstream mMatSStream;
77  std::string mWarningMsg;
78 };
79 /**
80  * @endcond
81  */
82 
83 WavefrontOBJ::WavefrontOBJ(ResourceLoader *loader, const std::string &path) :
84  Resource(loader, path)
85 {
86  mLoaded = false;
87 
88  mBasePath = path.substr(0, path.find_last_of("/"));
89  mBasePath += "/";
90 
91  int8_hf *fullFilePath = (int8_hf *)path.c_str();
92  if (HFCORE_ENV->getPakDataFileName().length() == 0)
93  {
94  fullFilePath = HFCORE_FDU->makeFilePath(fullFilePath);
95  envDebugLog("WavefrontOBJ::WavefrontOBJ fullFilePath is '%s'.\r\n",
96  fullFilePath);
97  }
98  mFullPath = fullFilePath;
99 }
100 
102 {
103 }
104 
105 bool WavefrontOBJ::init(bool includeSounds)
106 {
107  // only need to load once:
108  if (!mLoaded)
109  {
110  mLoaded = loadWavefrontOBJ();
111  }
112 
113  return mLoaded;
114 }
115 
116 void WavefrontOBJ::destroy(bool includeSounds)
117 {
118  // don't need to release anything.
119 }
120 
121 bool WavefrontOBJ::loadWavefrontOBJ()
122 {
123  bool triangulate = true;
124  tinyobj::attrib_t attrib;
125  std::vector<tinyobj::shape_t> shapes;
126  std::vector<tinyobj::material_t> materials;
127 
128  // get obj file buffer:
129  const std::string objFileBuffer = getFileBuffer(mFullPath);
130  if (objFileBuffer.length() == 0)
131  {
132  envDebugLog("WavefrontOBJ::getFileBuffer() failed for file: %s.\r\n",
133  mFullPath.c_str());
134  return false;
135  }
136 
137  // get stringstream from obj file buffer:
138  std::stringstream streamBuffer(objFileBuffer);
139 
140  // material reader:
141  std::string mtlPath(mFullPath.substr(0, mFullPath.find_last_of(".")));
142  mtlPath += ".mtl";
143  const std::string mtlFileBuffer = getFileBuffer(mtlPath);
144  if (mtlFileBuffer.length() == 0)
145  {
146  envDebugLog("WavefrontOBJ::getFileBuffer() failed for file: %s.\r\n",
147  mtlPath.c_str());
148  return false;
149  }
150  MaterialStringStreamReader mtlReader(mtlFileBuffer);
151 
152  std::string err;
153  bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, &streamBuffer,
154  &mtlReader, triangulate);
155  if (!ret)
156  {
157  envDebugLog("WavefrontOBJ::load() failed with error message: %s.\r\n",
158  err.c_str());
159  return false;
160  }
161 
162  // some debug info log:
163  envDebugLog("*** WavefrontOBJ::load() - '%s' loaded OK..\r\n", mFullPath.c_str());
164  envDebugLog("\t # of vertices : %u\r\n", attrib.vertices.size() / 3);
165  envDebugLog("\t # of normals : %u\r\n", attrib.normals.size() / 3);
166  envDebugLog("\t # of texcoords : %u\r\n", attrib.texcoords.size() / 2);
167 
168  envDebugLog("\t # of shapes : %u\r\n", shapes.size());
169  envDebugLog("\t # of materials : %u\r\n", materials.size());
170 
171  std::unordered_map<Geometry::VertexPosNorTex, int32_hf> uniqueVertices;
172  bool clearIndicesU16Vector = false;
173 
174  // Make sure we start fresh:
175  mMeshVector.clear();
176 
177  // shapes:
178  for (size_t s = 0; s < shapes.size(); s++)
179  {
180  envDebugLog("*** Mesh %u :\r\n", s);
181 
182  // per mesh vectors needed:
183  Geometry::VertexPosNorTexVector vertexPosNorTexVector;
184  Geometry::VertexIndicesU16Vector vertexIndicesU16Vector;
185  Geometry::VertexIndicesU32Vector vertexIndicesU32Vector;
186  TagVector tagVector;
187  MaterialVector materialVector;
188 
189  // faces:
190  size_t index_offset = 0;
191  for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++)
192  {
193  size_t fv = shapes[s].mesh.num_face_vertices[f];
194 
195  // vertices in the face:
196  for (size_t v = 0; v < fv; v++)
197  {
198  // access to vertex
199  tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v];
200 
201  // vertex struct holding position, normal and texture uv coords:
203 
204  // position:
205  vert.position = glm::vec3(attrib.vertices[3 * idx.vertex_index + 0],
206  attrib.vertices[3 * idx.vertex_index + 1],
207  attrib.vertices[3 * idx.vertex_index + 2]);
208 
209  // normal:
210  vert.normal = glm::vec3(attrib.normals[3 * idx.normal_index + 0],
211  attrib.normals[3 * idx.normal_index + 1],
212  attrib.normals[3 * idx.normal_index + 2]);
213 
214  // texture uv coords:
215  vert.uv = glm::vec2(attrib.texcoords[2 * idx.texcoord_index + 0],
216  1.0f - attrib.texcoords[2 * idx.texcoord_index + 1]);
217 
218  // push only unique vertices:
219  if (uniqueVertices.count(vert) == 0)
220  {
221  uniqueVertices[vert] = vertexPosNorTexVector.size();
222  vertexPosNorTexVector.push_back(vert);
223  }
224 
225  // indices:
226  assert((uint32_hf)uniqueVertices[vert] <= UINT_MAX);
227  vertexIndicesU32Vector.push_back(uniqueVertices[vert]);
228  if (!clearIndicesU16Vector && uniqueVertices[vert] <= USHRT_MAX)
229  {
230  vertexIndicesU16Vector.push_back(uniqueVertices[vert]);
231  }
232  else
233  {
234  clearIndicesU16Vector = true;
235  }
236  }
237  index_offset += fv;
238  }
239 
240  // current mesh material if any:
241  tinyobj::mesh_t current_mesh = shapes[s].mesh;
242  if (current_mesh.material_ids[0] >= 0)
243  {
244  tinyobj::material_t tmp = materials[current_mesh.material_ids[0]];
245 
246  Material mat;
247  mat.name = tmp.name;
248  mat.ambient = glm::vec3(tmp.ambient[0], tmp.ambient[1], tmp.ambient[2]);
249  mat.diffuse = glm::vec3(tmp.diffuse[0], tmp.diffuse[1], tmp.diffuse[2]);
250  mat.specular = glm::vec3(tmp.specular[0], tmp.specular[1], tmp.specular[2]);
251  mat.transmittance = glm::vec3(tmp.transmittance[0], tmp.transmittance[1], tmp.transmittance[2]);
252  mat.emission = glm::vec3(tmp.emission[0], tmp.emission[1], tmp.emission[2]);
253  mat.shininess = tmp.shininess;
254  mat.ior = tmp.ior;
255  mat.dissolve = tmp.dissolve;
256  mat.illum = tmp.illum;
257 
258  mat.tex_basepath = mBasePath;
259  mat.ambient_texname = tmp.ambient_texname;
260  mat.diffuse_texname = tmp.diffuse_texname;
261  mat.specular_texname = tmp.specular_texname;
262  mat.specular_highlight_texname = tmp.specular_highlight_texname;
263  mat.bump_texname = tmp.bump_texname;
264  mat.displacement_texname = tmp.displacement_texname;
265  mat.alpha_texname = tmp.alpha_texname;
266  mat.reflection_texname = tmp.reflection_texname;
267 
268  mat.ambient_texopt = getTextureOption(&tmp.ambient_texopt,
269  mat.ambient_texname);
270  mat.diffuse_texopt = getTextureOption(&tmp.diffuse_texopt,
271  mat.diffuse_texname);
272  mat.specular_texopt = getTextureOption(&tmp.specular_texopt,
273  mat.specular_texname);
274  mat.specular_highlight_texopt = getTextureOption(&tmp.specular_highlight_texopt,
276  mat.bump_texopt = getTextureOption(&tmp.bump_texopt,
277  mat.bump_texname);
278  mat.displacement_texopt = getTextureOption(&tmp.displacement_texopt,
280  mat.alpha_texopt = getTextureOption(&tmp.alpha_texopt,
281  mat.alpha_texname);
282  mat.reflection_texopt = getTextureOption(&tmp.reflection_texopt,
283  mat.reflection_texname);
284 
285  mat.roughness = tmp.roughness;
286  mat.metallic = tmp.metallic;
287  mat.sheen = tmp.sheen;
288  mat.clearcoat_thickness = tmp.clearcoat_thickness;
289  mat.clearcoat_roughness = tmp.clearcoat_roughness;
290  mat.anisotropy = tmp.anisotropy;
291  mat.anisotropy_rotation = tmp.anisotropy_rotation;
292 
293  mat.roughness_texname = tmp.roughness_texname;
294  mat.metallic_texname = tmp.metallic_texname;
295  mat.sheen_texname = tmp.sheen_texname;
296  mat.emissive_texname = tmp.emissive_texname;
297  mat.normal_texname = tmp.normal_texname;
298 
299  mat.roughness_texopt = getTextureOption(&tmp.roughness_texopt,
300  mat.roughness_texname);
301  mat.metallic_texopt = getTextureOption(&tmp.metallic_texopt,
302  mat.metallic_texname);
303  mat.sheen_texopt = getTextureOption(&tmp.sheen_texopt,
304  mat.sheen_texname);
305  mat.emissive_texopt = getTextureOption(&tmp.emissive_texopt,
306  mat.emissive_texname);
307  mat.normal_texopt = getTextureOption(&tmp.normal_texopt,
308  mat.normal_texname);
309 
310 #if defined (_DEBUG)
311  // debug info:
312  printMaterialDebugInfo(&mat);
313 #endif
314 
315  materialVector.push_back(mat);
316  }
317  envDebugLog("\t # of materials after processing : %u\r\n", materialVector.size());
318 
319  // clear out indices U16 vector as not within USHRT_MAX range:
320  if (clearIndicesU16Vector)
321  {
322  vertexIndicesU16Vector.clear();
323  }
324 
325  envDebugLog("\t # of unique vertices after processing : %u\r\n", vertexPosNorTexVector.size());
326  envDebugLog("\t # of indicesU32 after processing : %u\r\n", vertexIndicesU32Vector.size());
327  envDebugLog("\t # of indicesU16 after processing : %u\r\n", vertexIndicesU16Vector.size());
328 
329  // tags:
330  for (size_t t = 0; t < shapes[s].mesh.tags.size(); t++)
331  {
332  Tag tag;
333  tag.name = shapes[s].mesh.tags[t].name;
334  tag.int32Values = shapes[s].mesh.tags[t].intValues;
335  tag.float32Values = shapes[s].mesh.tags[t].floatValues;
336  tag.stringValues = shapes[s].mesh.tags[t].stringValues;
337 
338  tagVector.push_back(tag);
339  }
340  envDebugLog("\t # of tags after processing : %u\r\n\n", tagVector.size());
341 
342  // store Mesh attributes in vector:
343  Mesh m;
344  m.vertexPosNorTexVector = vertexPosNorTexVector;
345  m.vertexIndicesU16Vector = vertexIndicesU16Vector;
346  m.vertexIndicesU32Vector = vertexIndicesU32Vector;
347  m.tagVector = tagVector;
348  m.materialVector = materialVector;
349  mMeshVector.push_back(m);
350  }
351 
352  envDebugLog("*** WavefrontOBJ::load() - '%s' finished parsing. mMeshVector size is: %u\r\n",
353  mFullPath.c_str(), mMeshVector.size());
354 
355  // success:
356  return true;
357 }
358 
359 const std::string WavefrontOBJ::getFileBuffer(const std::string &path)
360 {
361  PFILE *file = p_fopen(path.c_str(), "rb");
362  if (file == NULL)
363  {
364  envDebugLog("WARNING: Unable to open '%s'\r\n", path.c_str());
365  return std::string("");
366  }
367 
368  uint32_hf fileSize = 0;
369  if (file->mRecord)
370  {
371  fileSize = file->mRecord->mSize;
372  }
373  else
374  {
375  p_fseek(file, 0, SEEK_END);
376  fileSize = p_ftell(file);
377  p_fseek(file, 0, SEEK_SET);
378  }
379  int8_hf *buf = new int8_hf[fileSize];
380  if (!buf)
381  {
382  p_fclose(file);
383  return std::string("");
384  }
385  memset(buf, 0, fileSize * sizeof(int8_hf));
386 
387  // do some reading young jedi:
388  p_fread(buf, 1, fileSize, file);
389  p_fclose(file);
390 
391  // create string outof buffer:
392  std::string out(buf, fileSize);
393 
394  // delete buffer:
395  HF_SAFE_DELETE_ARR(buf);
396 
397  return out;
398 }
399 
400 void WavefrontOBJ::printMaterialDebugInfo(Material *material)
401 {
402  assert(material != NULL);
403 
404  envDebugLog("\t material->name: %s\r\n", material->name.c_str());
405  envDebugLog("\t mat.ambient r: %f g: %f, b: %f\r\n",
406  material->ambient.r, material->ambient.g, material->ambient.b);
407  envDebugLog("\t mat.diffuse r: %f g: %f, b: %f\r\n",
408  material->diffuse.r, material->diffuse.g, material->diffuse.b);
409  envDebugLog("\t mat.specular r: %f g: %f, b: %f\r\n",
410  material->specular.r, material->specular.g, material->specular.b);
411  envDebugLog("\t mat.transmittance r: %f g: %f, b: %f\r\n",
412  material->transmittance.r, material->transmittance.g, material->transmittance.b);
413  envDebugLog("\t mat.emission r: %f g: %f, b: %f\r\n",
414  material->emission.r, material->emission.g, material->emission.b);
415  envDebugLog("\t mat.shininess: %f\r\n", material->shininess);
416  envDebugLog("\t mat.ior: %f\r\n", material->ior);
417  envDebugLog("\t mat.dissolve: %f\r\n", material->dissolve);
418  envDebugLog("\t mat.illum: %d\r\n", material->illum);
419 
420  envDebugLog("\t material->tex_basepath: %s\r\n", material->tex_basepath.c_str());
421  envDebugLog("\t material->ambient_texname: %s\r\n", material->ambient_texname.c_str());
422  envDebugLog("\t material->diffuse_texname: %s\r\n", material->diffuse_texname.c_str());
423  envDebugLog("\t material->specular_texname: %s\r\n", material->specular_texname.c_str());
424  envDebugLog("\t material->specular_highlight_texname: %s\r\n",
425  material->specular_highlight_texname.c_str());
426  envDebugLog("\t material->bump_texname: %s\r\n", material->bump_texname.c_str());
427  envDebugLog("\t material->displacement_texname: %s\r\n", material->displacement_texname.c_str());
428  envDebugLog("\t material->alpha_texname: %s\r\n", material->alpha_texname.c_str());
429  envDebugLog("\t material->reflection_texname: %s\r\n", material->reflection_texname.c_str());
430 
431  envDebugLog("\t material->ambient_texopt:\r\n");
432  printTextureOptionDebugInfo(&material->ambient_texopt);
433 
434  envDebugLog("\t material->diffuse_texopt:\r\n");
435  printTextureOptionDebugInfo(&material->diffuse_texopt);
436 
437  envDebugLog("\t material->specular_texopt:\r\n");
438  printTextureOptionDebugInfo(&material->specular_texopt);
439 
440  envDebugLog("\t material->specular_highlight_texopt:\r\n");
441  printTextureOptionDebugInfo(&material->specular_highlight_texopt);
442 
443  envDebugLog("\t material->bump_texopt:\r\n");
444  printTextureOptionDebugInfo(&material->bump_texopt);
445 
446  envDebugLog("\t material->displacement_texopt:\r\n");
447  printTextureOptionDebugInfo(&material->displacement_texopt);
448 
449  envDebugLog("\t material->alpha_texopt:\r\n");
450  printTextureOptionDebugInfo(&material->alpha_texopt);
451 
452  envDebugLog("\t material->reflection_texopt:\r\n");
453  printTextureOptionDebugInfo(&material->reflection_texopt);
454 
455  envDebugLog("\t material->roughness: %f\r\n", material->roughness);
456  envDebugLog("\t material->metallic: %f\r\n", material->metallic);
457  envDebugLog("\t material->sheen: %f\r\n", material->sheen);
458  envDebugLog("\t material->clearcoat_thickness: %f\r\n", material->clearcoat_thickness);
459  envDebugLog("\t material->clearcoat_roughness: %f\r\n", material->clearcoat_roughness);
460  envDebugLog("\t material->anisotropy: %f\r\n", material->anisotropy);
461  envDebugLog("\t material->anisotropy_rotation: %f\r\n", material->anisotropy_rotation);
462 
463  envDebugLog("\t material->roughness_texname: %s\r\n", material->roughness_texname.c_str());
464  envDebugLog("\t material->metallic_texname: %s\r\n", material->metallic_texname.c_str());
465  envDebugLog("\t material->sheen_texname: %s\r\n", material->sheen_texname.c_str());
466  envDebugLog("\t material->emissive_texname: %s\r\n", material->emissive_texname.c_str());
467  envDebugLog("\t material->normal_texname: %s\r\n", material->normal_texname.c_str());
468 
469  envDebugLog("\t material->roughness_texopt:\r\n");
470  printTextureOptionDebugInfo(&material->roughness_texopt);
471 
472  envDebugLog("\t material->metallic_texopt:\r\n");
473  printTextureOptionDebugInfo(&material->metallic_texopt);
474 
475  envDebugLog("\t material->sheen_texopt:\r\n");
476  printTextureOptionDebugInfo(&material->sheen_texopt);
477 
478  envDebugLog("\t material->emissive_texopt:\r\n");
479  printTextureOptionDebugInfo(&material->emissive_texopt);
480 
481  envDebugLog("\t material->normal_texopt:\r\n");
482  printTextureOptionDebugInfo(&material->normal_texopt);
483 
484  envDebugLog("\t material->unknown_parameter map size: %u\r\n", material->unknown_parameter.size());
485 }
486 
487 void WavefrontOBJ::printTextureOptionDebugInfo(TextureOption *textureOption)
488 {
489  assert(textureOption != NULL);
490 
491  envDebugLog("\t\t textureOption->type: %d\r\n", textureOption->type);
492  envDebugLog("\t\t textureOption->sharpness: %f\r\n", textureOption->sharpness);
493  envDebugLog("\t\t textureOption->brightness: %f\r\n", textureOption->brightness);
494  envDebugLog("\t\t textureOption->contrast: %f\r\n", textureOption->contrast);
495  envDebugLog("\t\t textureOption.origin_offset r: %f g: %f, b: %f\r\n",
496  textureOption->origin_offset.r, textureOption->origin_offset.g, textureOption->origin_offset.b);
497  envDebugLog("\t\t textureOption.scale r: %f g: %f, b: %f\r\n",
498  textureOption->scale.r, textureOption->scale.g, textureOption->scale.b);
499  envDebugLog("\t\t textureOption.turbulence r: %f g: %f, b: %f\r\n",
500  textureOption->turbulence.r, textureOption->turbulence.g, textureOption->turbulence.b);
501  envDebugLog("\t\t textureOption->clamp: %s\r\n", textureOption->clamp == true ? "true" : "false");
502  envDebugLog("\t\t textureOption->imfchan: %c\r\n", textureOption->imfchan);
503  envDebugLog("\t\t textureOption->blendu: %s\r\n", textureOption->blendu == true ? "true" : "false");
504  envDebugLog("\t\t textureOption->blendv: %s\r\n", textureOption->blendv == true ? "true" : "false");
505  envDebugLog("\t\t textureOption->bump_multiplier: %f\r\n", textureOption->bump_multiplier);
506 }
507 
509 {
510  return mMeshVector;
511 }
512 
513 WavefrontOBJ::TextureOption WavefrontOBJ::getTextureOption(void *textureOption,
514  const std::string &texName)
515 {
516  TextureOption ret;
517  memset(&ret, 0, sizeof(TextureOption));
518 
519  if (texName.length() > 0)
520  {
521  tinyobj::texture_option_t *tmp = (tinyobj::texture_option_t *)textureOption;
522  ret.type = getTextureType(&tmp->type);
523  ret.sharpness = tmp->sharpness;
524  ret.brightness = tmp->brightness;
525  ret.contrast = tmp->contrast;
526  ret.origin_offset = glm::vec3(tmp->origin_offset[0], tmp->origin_offset[1], tmp->origin_offset[2]);
527  ret.scale = glm::vec3(tmp->scale[0], tmp->scale[1], tmp->scale[2]);
528  ret.turbulence = glm::vec3(tmp->turbulence[0], tmp->turbulence[1], tmp->turbulence[2]);
529  ret.clamp = tmp->clamp;
530  ret.imfchan = tmp->imfchan;
531  ret.blendu = tmp->blendu;
532  ret.blendv = tmp->blendv;
533  ret.bump_multiplier = tmp->bump_multiplier;
534  }
535  // set default values to make sure they're initialized properly!
536  else
537  {
538  ret.type = TextureType::TEXTURE_TYPE_NONE;
539  ret.sharpness = 1.0f;
540  ret.brightness = 0.0f;
541  ret.contrast = 1.0f;
542  ret.origin_offset = glm::vec3(0, 0, 0);
543  ret.scale = glm::vec3(1, 1, 1);
544  ret.turbulence = glm::vec3(0, 0, 0);
545  ret.clamp = false;
546  ret.imfchan = 'u';
547  ret.blendu = true;
548  ret.blendv = true;
549  ret.bump_multiplier = 1.0f;
550  }
551 
552  return ret;
553 }
554 
555 WavefrontOBJ::TextureType WavefrontOBJ::getTextureType(void *textureOption)
556 {
557  TextureType ret = TextureType::TEXTURE_TYPE_NONE;
558 
559  tinyobj::texture_option_t *tmp = (tinyobj::texture_option_t *)textureOption;
560  if (tmp->type == tinyobj::TEXTURE_TYPE_NONE)
561  {
562  ret = TextureType::TEXTURE_TYPE_NONE;
563  }
564  else if (tmp->type == tinyobj::TEXTURE_TYPE_SPHERE)
565  {
566  ret = TextureType::TEXTURE_TYPE_SPHERE;
567  }
568  else if (tmp->type == tinyobj::TEXTURE_TYPE_CUBE_TOP)
569  {
570  ret = TextureType::TEXTURE_TYPE_CUBE_TOP;
571  }
572  else if (tmp->type == tinyobj::TEXTURE_TYPE_CUBE_BOTTOM)
573  {
574  ret = TextureType::TEXTURE_TYPE_CUBE_BOTTOM;
575  }
576  else if (tmp->type == tinyobj::TEXTURE_TYPE_CUBE_FRONT)
577  {
578  ret = TextureType::TEXTURE_TYPE_CUBE_FRONT;
579  }
580  else if (tmp->type == tinyobj::TEXTURE_TYPE_CUBE_BACK)
581  {
582  ret = TextureType::TEXTURE_TYPE_CUBE_BACK;
583  }
584  else if (tmp->type == tinyobj::TEXTURE_TYPE_CUBE_LEFT)
585  {
586  ret = TextureType::TEXTURE_TYPE_CUBE_LEFT;
587  }
588  else if (tmp->type == tinyobj::TEXTURE_TYPE_CUBE_RIGHT)
589  {
590  ret = TextureType::TEXTURE_TYPE_CUBE_RIGHT;
591  }
592 
593  return ret;
594 }
std::string roughness_texname
(pbr) map_Pr
Definition: WavefrontOBJ.h:283
unsigned int uint32_hf
A type definition for unsigned int.
Definition: HFDataTypes.h:354
Struct holding tag name, int32 vector, float32 vector and string vector.
Definition: WavefrontOBJ.h:302
TextureOption metallic_texopt
metallic TextureOption
Definition: WavefrontOBJ.h:290
TextureOption diffuse_texopt
diffuse TextureOption
Definition: WavefrontOBJ.h:267
TextureOption reflection_texopt
reflection TextureOption
Definition: WavefrontOBJ.h:273
glm::vec3 origin_offset
Origin offset (default (0, 0, 0)):
Definition: WavefrontOBJ.h:213
glm::vec3 scale
Scale (default (1, 1, 1)):
Definition: WavefrontOBJ.h:214
fp32_hf roughness
(pbr) [0, 1] default 0
Definition: WavefrontOBJ.h:275
Interface useful when rendering custom Geometry.
Definition: Geometry.h:70
virtual ~WavefrontOBJ()
Destructor.
TextureOption specular_texopt
specular TextureOption
Definition: WavefrontOBJ.h:268
fp32_hf metallic
(pbr) [0, 1] default 0
Definition: WavefrontOBJ.h:276
glm::vec3 normal
Vertex normal.
Definition: Geometry.h:237
HFCore::PFILE * p_fopen(const int8_hf *fileName, const int8_hf *access)
Open a file (within pak file or outside of it).
glm::vec3 emission
emission color RGB.
Definition: WavefrontOBJ.h:240
Struct holding mesh vertex attributes vector, indices vectors, tag vector and material vector...
Definition: WavefrontOBJ.h:327
std::string name
Tag name.
Definition: WavefrontOBJ.h:304
fp32_hf anisotropy_rotation
(pbr) anisor. [0, 1] default 0
Definition: WavefrontOBJ.h:281
StringUtil::StringMap unknown_parameter
holds unknown params.
Definition: WavefrontOBJ.h:295
fp32_hf sheen
(pbr) [0, 1] default 0
Definition: WavefrontOBJ.h:277
int32_hf p_fclose(HFCore::PFILE *file)
Closes and deletes a HFCore::PFILE.
StringUtil::Int32Vector int32Values
Tag int32_hf vector values.
Definition: WavefrontOBJ.h:305
size_t p_fread(void *ptr, int32_hf size, int32_hf count, HFCore::PFILE *file)
Reads an array of count elements, each one with a size of size bytes, from the stream and stores them...
std::string alpha_texname
map_d
Definition: WavefrontOBJ.h:263
TextureOption alpha_texopt
alpha TextureOption
Definition: WavefrontOBJ.h:272
fp32_hf clearcoat_thickness
(pbr) [0, 1] default 0
Definition: WavefrontOBJ.h:278
std::vector< Tag > TagVector
typedef for Vector holding Tag struct.
Definition: WavefrontOBJ.h:318
std::string displacement_texname
disp
Definition: WavefrontOBJ.h:262
glm::vec2 uv
Vertex texture uv coords.
Definition: Geometry.h:238
#define HF_SAFE_DELETE_ARR(p)
Check if not NULL, delete array and set to NULL.
Definition: HFDataTypes.h:56
glm::vec3 transmittance
transmittance color RGB.
Definition: WavefrontOBJ.h:239
std::string diffuse_texname
map_Kd
Definition: WavefrontOBJ.h:258
std::string metallic_texname
(pbr) map_Pm
Definition: WavefrontOBJ.h:284
std::string ambient_texname
map_Ka
Definition: WavefrontOBJ.h:257
std::string tex_basepath
Base path (ex: "data/models/cyborg/") to be appended when loading textures.
Definition: WavefrontOBJ.h:256
TextureOption bump_texopt
bump TextureOption
Definition: WavefrontOBJ.h:270
TextureOption emissive_texopt
emissive TextureOption
Definition: WavefrontOBJ.h:292
Geometry::VertexPosNorTexVector vertexPosNorTexVector
Vector holding Geometry::VertexPosNorTex struct.
Definition: WavefrontOBJ.h:332
std::string reflection_texname
refl
Definition: WavefrontOBJ.h:264
#define NULL
Convenient define for 0.
Definition: HFDataTypes.h:42
TextureOption sheen_texopt
sheen TextureOption
Definition: WavefrontOBJ.h:291
PakRecord * mRecord
Pointer to PakRecord.
Definition: PakInterface.h:148
fp32_hf brightness
Brightness (default 0).
Definition: WavefrontOBJ.h:211
fp32_hf anisotropy
(pbr) aniso. [0, 1] default 0
Definition: WavefrontOBJ.h:280
glm::vec3 diffuse
diffuse color RGB.
Definition: WavefrontOBJ.h:237
StringUtil::Float32Vector float32Values
Tag fp32_hf vector values.
Definition: WavefrontOBJ.h:306
char int8_hf
A type definition for char.
Definition: HFDataTypes.h:329
Interface for Resource base class.
Definition: Resource.h:39
Struct holding material attributes.
Definition: WavefrontOBJ.h:232
fp32_hf bump_multiplier
bm (for bump maps only, default 1).
Definition: WavefrontOBJ.h:223
glm::vec3 specular
specular color RGB.
Definition: WavefrontOBJ.h:238
int8_hf imfchan
imfchan (default for bump is &#39;l&#39;, decal is &#39;m&#39; and &#39;u&#39; when no texture.)
Definition: WavefrontOBJ.h:220
StringUtil::StringVector stringValues
Tag string vector values.
Definition: WavefrontOBJ.h:307
std::vector< VertexPosNorTex > VertexPosNorTexVector
typedef for Vector holding VertexPosNorTex struct.
Definition: Geometry.h:366
int32_hf p_fseek(HFCore::PFILE *file, long offset, int32_hf origin)
Sets the position indicator associated with the stream to a new position.
std::string emissive_texname
(pbr) map_Ke
Definition: WavefrontOBJ.h:286
fp32_hf sharpness
Sharpness (default 1).
Definition: WavefrontOBJ.h:210
std::vector< uint16_hf > VertexIndicesU16Vector
typedef for Vector holding vertex indices as uint16_hf.
Definition: Geometry.h:386
TextureType
Texture type enum.
Definition: WavefrontOBJ.h:192
fp32_hf shininess
shininess color RGB.
Definition: WavefrontOBJ.h:241
TextureType type
TextureType enum (default TEXTURE_TYPE_NONE).
Definition: WavefrontOBJ.h:209
fp32_hf contrast
Contrast (default 1).
Definition: WavefrontOBJ.h:212
std::string specular_texname
map_Ks
Definition: WavefrontOBJ.h:259
TextureOption displacement_texopt
displacement TextureOption
Definition: WavefrontOBJ.h:271
Struct holding texture option attributes.
Definition: WavefrontOBJ.h:207
std::string normal_texname
(pbr) norm. For normal mapping.
Definition: WavefrontOBJ.h:287
glm::vec3 ambient
ambient color RGB.
Definition: WavefrontOBJ.h:236
std::vector< Mesh > MeshVector
typedef for Vector holding Mesh struct.
Definition: WavefrontOBJ.h:358
Definition: Actor.h:34
Interface for Resource type WavefrontOBJ.
bool clamp
Clamp (default false).
Definition: WavefrontOBJ.h:216
TextureOption ambient_texopt
ambient TextureOption
Definition: WavefrontOBJ.h:266
TextureOption normal_texopt
normal TextureOption
Definition: WavefrontOBJ.h:293
glm::vec3 turbulence
Turbulence (default (0, 0, 0)).
Definition: WavefrontOBJ.h:215
Singleton interface for platform specific things.
Interface for Image and Sound loading (called from ResourceManager).
std::string specular_highlight_texname
map_Ns
Definition: WavefrontOBJ.h:260
#define HFCORE_FDU
Get HFCore::FileDirUtils instance shortcut macro.
Definition: Environment.h:83
Interface for Image and Sound loading (called from ResourceManager).
std::vector< uint32_hf > VertexIndicesU32Vector
typedef for Vector holding vertex indices as uint32_hf.
Definition: Geometry.h:381
Struct holding PakRecord, pointer to actual FILE and position.
Definition: PakInterface.h:146
int32_hf illum
illumination model (see http://www.fileformat.info/format/material/).
Definition: WavefrontOBJ.h:250
#define HFCORE_ENV
Get HFCore::Environment instance shortcut macro.
Definition: Environment.h:68
Struct holding vertex position, normal and texture UV coords.
Definition: Geometry.h:234
std::string bump_texname
map_bump, map_Bump, bump
Definition: WavefrontOBJ.h:261
bool blendv
blendv (default true).
Definition: WavefrontOBJ.h:222
int32_hf p_ftell(HFCore::PFILE *file)
Returns the current value of the position indicator of the HFCore::PFILE stream.
int32_hf mSize
Holds file size.
Definition: PakInterface.h:94
WavefrontOBJ(ResourceLoader *loader, const std::string &path)
Constructor.
std::string name
Material name.
Definition: WavefrontOBJ.h:234
TextureOption specular_highlight_texopt
specular_highlight TextureOption
Definition: WavefrontOBJ.h:269
TextureOption roughness_texopt
roughness TextureOption
Definition: WavefrontOBJ.h:289
std::vector< Material > MaterialVector
typedef for Vector holding Material struct.
Definition: WavefrontOBJ.h:313
#define envDebugLog(format, args...)
Shortcut macro for logging to &#39;debug.log&#39;.
Definition: Environment.h:2364
fp32_hf clearcoat_roughness
(pbr) [0, 1] default 0
Definition: WavefrontOBJ.h:279
bool blendu
blendu (default true).
Definition: WavefrontOBJ.h:221
Interface for accessing pak files created with tool hfpak.
glm::vec3 position
Vertex position.
Definition: Geometry.h:236
virtual MeshVector getMeshVector()
Get WavefrontOBJ::MeshVector holding all meshes.
fp32_hf dissolve
1 == opaque; 0 == fully transparent.
Definition: WavefrontOBJ.h:246
fp32_hf ior
index of refraction
Definition: WavefrontOBJ.h:242
std::string sheen_texname
(pbr) map_Ps
Definition: WavefrontOBJ.h:285