MobileRT  1.0
A multi platform C++ CPU progressive Ray Tracer.
OBJLoader.hpp
Go to the documentation of this file.
1 #ifndef COMPONENTS_LOADERS_OBJLOADER_HPP
2 #define COMPONENTS_LOADERS_OBJLOADER_HPP
3 
5 #include "MobileRT/Sampler.hpp"
6 #include "MobileRT/Scene.hpp"
7 #include "MobileRT/Texture.hpp"
8 
9 #include <mutex>
10 #include <unordered_map>
11 #include <tinyobjloader/tiny_obj_loader.h>
12 
13 namespace Components {
14 
18  class OBJLoader final : public ::MobileRT::ObjectLoader {
19  private:
20  template<typename T1, typename T2, typename T3>
21  using triple = ::std::tuple<T1, T2, T3>;
22 
23  private:
24  ::tinyobj::attrib_t attrib_ {};
25  ::std::vector<::tinyobj::shape_t> shapes_ {};
26  ::std::vector<::tinyobj::material_t> materials_ {};
27 
28  public:
29  explicit OBJLoader() = delete;
30 
31  explicit OBJLoader(::std::istream& isObj, ::std::istream& isMtl);
32 
33  OBJLoader(const OBJLoader &objLoader) = delete;
34 
35  OBJLoader(OBJLoader &&objLoader) noexcept = delete;
36 
37  ~OBJLoader() final;
38 
39  OBJLoader &operator=(const OBJLoader &objLoader) = delete;
40 
41  OBJLoader &operator=(OBJLoader &&objLoader) noexcept = delete;
42 
43  bool fillScene(::MobileRT::Scene *scene,
44  ::std::function<::std::unique_ptr<::MobileRT::Sampler>()> lambda,
45  ::std::string filePath,
46  ::std::unordered_map<::std::string, ::MobileRT::Texture> texturesCache) final;
47 
48  private:
50  const ::tinyobj::shape_t &index,
51  ::std::int32_t indexOffset,
53 
55  const ::tinyobj::shape_t &shape,
56  ::std::int32_t indexOffset) const;
57 
58  const ::MobileRT::Texture& getTextureFromCache(
59  ::std::unordered_map<::std::string, ::MobileRT::Texture> *const texturesCache,
60  const ::std::string &filePath,
61  const ::std::string &texPath
62  );
63 
69  void fillSceneThreadWork(::std::uint32_t threadId,
70  ::std::uint32_t numberOfThreads,
71  ::MobileRT::Scene *const scene,
72  const ::std::function<::std::unique_ptr<::MobileRT::Sampler>()> &lambda,
73  const ::std::string &filePath,
74  ::std::unordered_map<::std::string, ::MobileRT::Texture> *const texturesCache,
75  ::std::mutex *const mutex);
76 
77  public:
78  static const ::MobileRT::Texture& getTextureFromCache(
79  ::std::unordered_map<::std::string, ::MobileRT::Texture> *const texturesCache,
80  ::std::string &&textureBinary,
81  long size,
82  const ::std::string &texPath);
83 
84  private:
86  const MobileRT::Texture &texture,
87  const ::std::tuple<::glm::vec2, ::glm::vec2, ::glm::vec2> &texCoord);
88  };
89 }//namespace Components
90 
91 #endif //COMPONENTS_LOADERS_OBJLOADER_HPP
triple<::glm::vec3, ::glm::vec3, ::glm::vec3 > loadVertices(const ::tinyobj::shape_t &shape, ::std::int32_t indexOffset) const
Definition: OBJLoader.cpp:116
::std::vector<::tinyobj::shape_t > shapes_
Definition: OBJLoader.hpp:25
Definition: Orthographic.hpp:6
triple<::glm::vec3, ::glm::vec3, ::glm::vec3 > loadNormal(const ::tinyobj::shape_t &index, ::std::int32_t indexOffset, const triple<::glm::vec3, ::glm::vec3, ::glm::vec3 > &vertex) const
Definition: OBJLoader.cpp:154
Definition: OBJLoader.hpp:18
bool fillScene(::MobileRT::Scene *scene, ::std::function<::std::unique_ptr<::MobileRT::Sampler >()> lambda, ::std::string filePath, ::std::unordered_map<::std::string, ::MobileRT::Texture > texturesCache) final
Definition: OBJLoader.cpp:74
::std::tuple< T1, T2, T3 > triple
Definition: OBJLoader.hpp:21
::tinyobj::attrib_t attrib_
Definition: OBJLoader.hpp:24
~OBJLoader() final
Definition: OBJLoader.cpp:502
Definition: Scene.hpp:20
Definition: ObjectLoader.hpp:16
Definition: Texture.hpp:16
OBJLoader & operator=(const OBJLoader &objLoader)=delete
const ::MobileRT::Texture & getTextureFromCache(::std::unordered_map<::std::string, ::MobileRT::Texture > *const texturesCache, const ::std::string &filePath, const ::std::string &texPath)
::std::vector<::tinyobj::material_t > materials_
Definition: OBJLoader.hpp:26
static triple<::glm::vec2, ::glm::vec2, ::glm::vec2 > normalizeTexCoord(const MobileRT::Texture &texture, const ::std::tuple<::glm::vec2, ::glm::vec2, ::glm::vec2 > &texCoord)
Definition: OBJLoader.cpp:193
void fillSceneThreadWork(::std::uint32_t threadId, ::std::uint32_t numberOfThreads, ::MobileRT::Scene *const scene, const ::std::function<::std::unique_ptr<::MobileRT::Sampler >()> &lambda, const ::std::string &filePath, ::std::unordered_map<::std::string, ::MobileRT::Texture > *const texturesCache, ::std::mutex *const mutex)
Definition: OBJLoader.cpp:276