OBJParser
OBJ File Parser Powered by Boost Spirit
 All Classes Functions Variables Enumerations Enumerator Pages
OBJMaterial.hpp
1 /*
2  * Copyright 2016 Steven T Sell (ssell@vertexfragment.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __H__OBJ_PARSER_MTL_MATERIAL__H__
18 #define __H__OBJ_PARSER_MTL_MATERIAL__H__
19 
20 #include "OBJTextureDescriptor.hpp"
21 
22 #include <string>
23 #include <cstdint>
24 #include <array>
25 
26 //------------------------------------------------------------------------------------------
27 
31 enum class OBJMaterialPropertyType
32 {
33  None = 0,
34  RGB,
35  XYZ,
36  RFL
37 };
38 
43 {
45 
46  std::string path;
47  float factor;
48 };
49 
50 BOOST_FUSION_ADAPT_STRUCT(OBJMaterialPropertyRFL, (std::string, path), (float, factor));
51 
62 {
64  OBJMaterialProperty const& operator=(OBJMaterialProperty const& rhs);
65 
66  //--------------------------------------------------------------------
67 
68  OBJMaterialPropertyType type;
69 
70  union { float r, x; };
71  union { float g, y; };
72  union { float b, z; };
73 
75 };
76 
77 //------------------------------------------------------------------------------------------
78 
83 {
85 
86  bool halo;
87  float factor;
88 };
89 
90 BOOST_FUSION_ADAPT_STRUCT(OBJMaterialDissolve, (bool, halo), (float, factor));
91 
92 //------------------------------------------------------------------------------------------
93 
97 enum class OBJReflectionMapType
98 {
99  None = 0,
100  Sphere,
101  Cube
102 };
103 
107 enum class OBJReflectionMapCubeSide
108 {
109  Front = 0,
110  Back,
111  Top,
112  Bottom,
113  Left,
114  Right
115 };
116 
117 //------------------------------------------------------------------------------------------
118 
123 {
124 public:
125 
126  OBJMaterial();
127  ~OBJMaterial();
128 
129  //--------------------------------------------------------------------
130 
131  // Name
132 
133  void setName(std::string const& name);
134  std::string const& getName() const;
135 
136  // Ambient Reflectivity
137 
138  void setAmbientReflectivityRGB(OBJVector3 const& rgb);
139  void setAmbientReflectivityXYZ(OBJVector3 const& xyz);
140  void setAmbientReflectivityRFL(OBJMaterialPropertyRFL const& rfl);
141 
142  OBJMaterialProperty const& getAmbientReflectivity() const;
143 
144  // Diffuse Reflectivity
145 
146  void setDiffuseReflectivityRGB(OBJVector3 const& rgb);
147  void setDiffuseReflectivityXYZ(OBJVector3 const& xyz);
148  void setDiffuseReflectivityRFL(OBJMaterialPropertyRFL const& rfl);
149 
150  OBJMaterialProperty const& getDiffuseReflectivity() const;
151 
152  // Specular Reflectivity
153 
154  void setSpecularReflectivityRGB(OBJVector3 const& rgb);
155  void setSpecularReflectivityXYZ(OBJVector3 const& xyz);
156  void setSpecularReflectivityRFL(OBJMaterialPropertyRFL const& rfl);
157 
158  OBJMaterialProperty const& getSpecularReflectivity() const;
159 
160  // Emissive Reflectivity
161 
162  void setEmissiveReflectivityRGB(OBJVector3 const& rgb);
163  void setEmissiveReflectivityXYZ(OBJVector3 const& xyz);
164  void setEmissiveReflectivityRFL(OBJMaterialPropertyRFL const& rfl);
165 
166  OBJMaterialProperty const& getEmissiveReflectivity() const;
167 
168  // Transmission Filter
169 
170  void setTransmissionFilterRGB(OBJVector3 const& rgb);
171  void setTransmissionFilterXYZ(OBJVector3 const& xyz);
172  void setTransmissionFilterRFL(OBJMaterialPropertyRFL const& rfl);
173 
174  OBJMaterialProperty const& getTransmissionFilter() const;
175 
176  // Dissolve
177 
178  void setDissolve(OBJMaterialDissolve const& dissolve);
179  OBJMaterialDissolve const& getDissolve() const;
180 
181  // Transparency (inverse of dissolve)
182 
183  void setTransparency(float transparency);
184  float getTransparency() const;
185 
186  // Illumination Model
187 
188  void setIlluminationModel(uint32_t model);
189  uint32_t getIlluminationModel() const;
190 
191  // Sharpness
192 
193  void setSharpness(uint32_t sharpness);
194  uint32_t getSharpness() const;
195 
196  // Specular Exponent
197 
198  void setSpecularExponent(float exponent);
199  float getSpecularExponent() const;
200 
201  // Optical Density
202 
203  void setOpticalDensity(float density);
204  float getOpticalDensity() const;
205 
206  // Ambient Texture
207 
208  void setAmbientTexture(OBJTextureDescriptor const* descriptor);
209  OBJTextureDescriptor const& getAmbientTexture() const;
210 
211  // Diffuse Texture
212 
213  void setDiffuseTexture(OBJTextureDescriptor const* descriptor);
214  OBJTextureDescriptor const& getDiffuseTexture() const;
215 
216  // Specular Texture
217 
218  void setSpecularTexture(OBJTextureDescriptor const* descriptor);
219  OBJTextureDescriptor const& getSpecularTexture() const;
220 
221  // SpecularExponent Texture
222 
223  void setSpecularExponentTexture(OBJTextureDescriptor const* descriptor);
224  OBJTextureDescriptor const& getSpecularExponentTexture() const;
225 
226  // Emissive Texture
227 
228  void setEmissiveTexture(OBJTextureDescriptor const* descriptor);
229  OBJTextureDescriptor const& getEmissiveTexture() const;
230 
231  // Dissolve Texture
232 
233  void setDissolveTexture(OBJTextureDescriptor const* descriptor);
234  OBJTextureDescriptor const& getDissolveTexture() const;
235 
236  // Decal Texture
237 
238  void setDecalTexture(OBJTextureDescriptor const* descriptor);
239  OBJTextureDescriptor const& getDecalTexture() const;
240 
241  // Displacement Texture
242 
243  void setDisplacementTexture(OBJTextureDescriptor const* descriptor);
244  OBJTextureDescriptor const& getDisplacementTexture() const;
245 
246  // Bump Texture
247 
248  void setBumpTexture(OBJTextureDescriptor const* descriptor);
249  OBJTextureDescriptor const& getBumpTexture() const;
250 
251  // Anti-Aliasing
252 
253  void setAntiAliasing(bool aa);
254  bool getAntiAliasing() const;
255 
256  // Reflection Map
257 
258  OBJReflectionMapType getReflectionMapType() const;
259 
260  void setReflectionMapSphere(OBJTextureDescriptor const* descriptor);
261  OBJTextureDescriptor const& getReflectionMapSphere() const;
262 
263  void setReflectionMapCubeSide(OBJReflectionMapCubeSide side, OBJTextureDescriptor const* descriptor);
264  OBJTextureDescriptor const& getReflectionMapCubeSide(OBJReflectionMapCubeSide side) const;
265 
266 protected:
267 
268  //--------------------------------------------------------------------
269  // Member Variables
270  //--------------------------------------------------------------------
271 
272  std::string m_Name;
273 
274  //--------------------------------------------------------------------
275  // Color and Illumination
276 
277  OBJMaterialProperty m_AmbientReflectivity;
278  OBJMaterialProperty m_DiffuseReflectivity;
279  OBJMaterialProperty m_SpecularReflectivity;
280  OBJMaterialProperty m_EmissiveReflectivity;
281  OBJMaterialProperty m_TransmissionFilter;
282 
283  OBJMaterialDissolve m_Dissolve;
284 
286  uint32_t m_Sharpness;
287 
291 
292  //--------------------------------------------------------------------
293  // Texture Map
294 
295  OBJTextureDescriptor m_TextureAmbient;
296  OBJTextureDescriptor m_TextureDiffuse;
297  OBJTextureDescriptor m_TextureSpecular;
298  OBJTextureDescriptor m_TextureSpecularExponent;
299  OBJTextureDescriptor m_TextureEmissive;
300  OBJTextureDescriptor m_TextureDissolve;
301  OBJTextureDescriptor m_TextureDecal;
302  OBJTextureDescriptor m_TextureDisplacement;
303  OBJTextureDescriptor m_TextureBump;
304 
305  bool m_TextureAntiAliasing;
306 
307  //--------------------------------------------------------------------
308  // Reflection Map
309 
310  OBJReflectionMapType m_ReflectionMapType;
311 
312  OBJTextureDescriptor m_ReflectionMapSphere;
313  std::array<OBJTextureDescriptor, 8> m_ReflectionMapCube;
314 
315 private:
316 };
317 
318 //------------------------------------------------------------------------------------------
319 
320 #endif
bool halo
True if dissolve depends on surface orientation relative to viewer.
Definition: OBJMaterial.hpp:86
uint32_t m_IlluminationModel
Value between 0 and 10 corresponding to an illumination model. See MTL specification for model detail...
Definition: OBJMaterial.hpp:285
Definition: OBJTextureDescriptor.hpp:46
float factor
The amount the material dissolves. 0.0: fully dissolved, transparent; 1.0: opaque.
Definition: OBJMaterial.hpp:87
Definition: OBJMaterial.hpp:42
uint32_t m_Sharpness
Sharpness of reflections. Higher values result in sharper reflections. Typical range of (0 - 1000); D...
Definition: OBJMaterial.hpp:286
Definition: OBJMaterial.hpp:122
float m_Transparency
Optional value set by certain writers. Typically is the inverse of the 'dissolve' value...
Definition: OBJMaterial.hpp:288
float m_SpecularExponent
Focus of the specular highlight. Higher values result in tighter highlights. Typical range (0...
Definition: OBJMaterial.hpp:289
Definition: OBJMaterial.hpp:82
Simple three-component vector struct.
Definition: OBJStructs.hpp:41
Definition: OBJMaterial.hpp:61
float m_OpticalDensity
AKA index of refraction. Range (0.001 - 10.0). 1.0 indicates light does not bend as it passes through...
Definition: OBJMaterial.hpp:290