HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeometryHandler.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_GEOMETRYHANDLER_H
7 #define MATERIALX_GEOMETRYHANDLER_H
8 
9 /// @file
10 /// Geometry loader interfaces
11 
12 #include <MaterialXRender/Export.h>
13 #include <MaterialXRender/Mesh.h>
14 
15 #include <MaterialXFormat/File.h>
16 
17 #include <map>
18 
20 
21 /// Shared pointer to a GeometryLoader
22 using GeometryLoaderPtr = std::shared_ptr<class GeometryLoader>;
23 
24 /// @class GeometryLoader
25 /// Base class representing a geometry loader. A loader can be
26 /// associated with one or more file extensions.
28 {
29  public:
31  {
32  }
33  virtual ~GeometryLoader() { }
34 
35  /// Returns a list of supported extensions
36  /// @return List of support extensions
38  {
39  return _extensions;
40  }
41 
42  /// Load geometry from disk. Must be implemented by derived classes.
43  /// @param filePath Path to file to load
44  /// @param meshList List of meshes to update
45  /// @param texcoordVerticalFlip Flip texture coordinates in V when loading
46  /// @return True if load was successful
47  virtual bool load(const FilePath& filePath, MeshList& meshList, bool texcoordVerticalFlip = false) = 0;
48 
49  protected:
50  // List of supported string extensions
52 };
53 
54 /// Shared pointer to an GeometryHandler
55 using GeometryHandlerPtr = std::shared_ptr<class GeometryHandler>;
56 
57 /// Map of extensions to image loaders
58 using GeometryLoaderMap = std::multimap<string, GeometryLoaderPtr>;
59 
60 /// @class GeometryHandler
61 /// Class which holds a set of geometry loaders. Each loader is associated with
62 /// a given set of file extensions.
64 {
65  public:
67  {
68  }
69  virtual ~GeometryHandler() { }
70 
71  /// Create a new geometry handler
73  {
74  return std::make_shared<GeometryHandler>();
75  }
76 
77  /// Add a geometry loader
78  /// @param loader Loader to add to list of available loaders.
79  void addLoader(GeometryLoaderPtr loader);
80 
81  /// Get a list of extensions supported by the handler
82  void supportedExtensions(StringSet& extensions);
83 
84  /// Clear all loaded geometry
85  void clearGeometry();
86 
87  // Determine if any meshes have been loaded from a given location
88  bool hasGeometry(const string& location);
89 
90  // Find all meshes loaded from a given location
91  void getGeometry(MeshList& meshes, const string& location);
92 
93  /// Load geometry from a given location
94  /// @param filePath Path to geometry
95  /// @param texcoordVerticalFlip Flip texture coordinates in V. Default is to not flip.
96  bool loadGeometry(const FilePath& filePath, bool texcoordVerticalFlip = false);
97 
98  /// Get list of meshes
99  const MeshList& getMeshes() const
100  {
101  return _meshes;
102  }
103 
104  /// Return the first mesh in our list containing the given partition.
105  /// If no matching mesh is found, then nullptr is returned.
106  MeshPtr findParentMesh(MeshPartitionPtr part);
107 
108  /// Return the minimum bounds for all meshes
109  const Vector3& getMinimumBounds() const
110  {
111  return _minimumBounds;
112  }
113 
114  /// Return the minimum bounds for all meshes
115  const Vector3& getMaximumBounds() const
116  {
117  return _maximumBounds;
118  }
119 
120  /// Utility to create a quad mesh
121  static MeshPtr createQuadMesh(const Vector2& uvMin = Vector2(0.0f, 0.0f),
122  const Vector2& uvMax = Vector2(1.0f, 1.0f),
123  bool flipTexCoordsHorizontally = false);
124 
125  protected:
126  // Recompute bounds for all stored geometry
127  void computeBounds();
128 
129  protected:
134 };
135 
137 
138 #endif
shared_ptr< class Mesh > MeshPtr
Shared pointer to a mesh.
Definition: Mesh.h:230
std::multimap< string, GeometryLoaderPtr > GeometryLoaderMap
Map of extensions to image loaders.
virtual ~GeometryLoader()
Definition: File.h:26
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
shared_ptr< class MeshPartition > MeshPartitionPtr
Shared pointer to a mesh partition.
Definition: Mesh.h:146
virtual ~GeometryHandler()
GeometryLoaderMap _geometryLoaders
GLfloat f
Definition: glcorearb.h:1926
const Vector3 & getMinimumBounds() const
Return the minimum bounds for all meshes.
const MeshList & getMeshes() const
Get list of meshes.
const StringSet & supportedExtensions() const
GLint location
Definition: glcorearb.h:805
Definition: Types.h:285
static GeometryHandlerPtr create()
Create a new geometry handler.
const Vector3 & getMaximumBounds() const
Return the minimum bounds for all meshes.
#define MX_RENDER_API
Definition: Export.h:18
Definition: Types.h:305
std::shared_ptr< class GeometryHandler > GeometryHandlerPtr
Shared pointer to an GeometryHandler.
StringSet _extensions
std::set< string > StringSet
A set of strings.
Definition: Library.h:61
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
vector< MeshPtr > MeshList
List of meshes.
Definition: Mesh.h:233
std::shared_ptr< class GeometryLoader > GeometryLoaderPtr
Shared pointer to a GeometryLoader.