Extended OBJ loader to parse specular and normal maps

This commit is contained in:
2014-04-23 16:55:51 +02:00
parent 84d6911744
commit 530b16e31b
3 changed files with 242 additions and 29 deletions
+69 -9
View File
@@ -10,21 +10,78 @@
#include <map>
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
class OBJ
{
public:
struct MaterialInfo
{
std::string TextureFile;
std::tuple<float, float, float> AmbientColor;
std::tuple<float, float, float> DiffuseColor;
std::tuple<float, float, float> SpecularColor;
std::tuple<float, float, float> TransmissionFilter;
float OpticalDensity;
float Alpha;
float Shininess;
int IlluminationModel;
struct TextureMap
{
TextureMap()
: blendu(true)
, blendv(true)
, clamp(false)
, o(std::make_tuple(0.f, 0.f, 0.f))
, s(std::make_tuple(1.f, 1.f, 1.f)) { }
std::string FileName;
// http://paulbourke.net/dataformats/mtl/
// "These options are described in detail in 'Options for texture map statements' on page 5-18."
// Horizontal texture blending
bool blendu; // = true
// Vertical texture blending
bool blendv; // = true
// Clamping
bool clamp; // = false
// Offset
std::tuple<float, float, float> o; // = (0, 0, 0)
// Scale
std::tuple<float, float, float> s; // = (1, 1, 1)
};
struct ColorMap : public TextureMap
{
ColorMap()
: cc(false) { }
// Color correction
bool cc; // = false
};
struct BumpMap : public TextureMap
{
BumpMap()
: bm(1.f) { }
// Bump multiplier
float bm; // = 1?
};
MaterialInfo()
: AmbientColor(std::make_tuple(0.2f, 0.2f, 0.2f))
, DiffuseColor(std::make_tuple(0.8f, 0.8f, 0.8f))
, SpecularColor(std::make_tuple(1.0f, 1.0f, 1.0f))
, TransmissionFilter(std::make_tuple(1.0f, 1.0f, 1.0f))
, OpticalDensity(1.0f)
, Alpha(1.0f)
, Shininess(0.0f)
, IlluminationModel(0) { }
ColorMap DiffuseTexture;
ColorMap SpecularMap;
BumpMap NormalMap;
std::tuple<float, float, float> AmbientColor; // = (0.2, 0.2, 0.2)
std::tuple<float, float, float> DiffuseColor; // = (0.8, 0.8, 0.8)
std::tuple<float, float, float> SpecularColor; // = (1, 1, 1)
std::tuple<float, float, float> TransmissionFilter; // = (1, 1, 1)
float OpticalDensity; // = 1
float Alpha; // = 1
float Shininess; // = 0
int IlluminationModel; // = 0
};
struct FaceDefinition
@@ -59,6 +116,9 @@ private:
MaterialInfo* m_CurrentMaterial;
void ParseMaterial();
void ParseTextureMap(unsigned int line, std::stringstream &ss, std::string prefix, std::string arg, MaterialInfo::TextureMap &textureMap);
void ParseColorMap(unsigned int line, std::stringstream &ss, std::string prefix, std::string arg, MaterialInfo::ColorMap &textureMap);
void ParseBumpMap(unsigned int line, std::stringstream &ss, std::string prefix, std::string arg, MaterialInfo::BumpMap &textureMap);
};
#endif // OBJ_h__