Commit d539e524 authored by Weizhen Huang's avatar Weizhen Huang

extend the materialNode class with refractive materials

parent 1275ee2d
......@@ -141,7 +141,9 @@ QString Material::serializeToJson() const {
matMap["specularColor"] = col2vl(specularColor_);
matMap["overlayColor"] = col2vl(overlayColor_);
matMap["shininess"] = shininess_;
matMap["illum"] = illum_;
matMap["reflectance"] = reflectance_;
matMap["indexOfRefraction"] = indexOfRefraction_;
matMap["pointSize"] = pointSize_;
matMap["lineWidth"] = lineWidth_;
matMap["roundPoints"] = roundPoints_;
......@@ -177,7 +179,9 @@ void Material::deserializeFromVariantMap(const QVariantMap &matMap) {
if (matMap.contains("specularColor")) specularColor_ = vl2col(matMap["specularColor"].toList());
if (matMap.contains("overlayColor")) overlayColor_ = vl2col(matMap["overlayColor"].toList());
if (matMap.contains("shininess")) shininess_ = matMap["shininess"].toFloat();
if (matMap.contains("illum")) illum_ = matMap["illum"].toInt();
if (matMap.contains("reflectance")) reflectance_ = matMap["reflectance"].toDouble();
if (matMap.contains("indexOfRefraction")) indexOfRefraction_ = matMap["indexOfRefraction"].toDouble();
if (matMap.contains("pointSize")) pointSize_ = matMap["pointSize"].toFloat();
if (matMap.contains("lineWidth")) lineWidth_ = matMap["lineWidth"].toFloat();
if (matMap.contains("roundPoints")) roundPoints_ = matMap["roundPoints"].toBool();
......@@ -480,6 +484,7 @@ MaterialNode::read(std::istream& _is)
char s[200];
float x, y, z, u;
int i;
while (_is && (!_is.eof()) && _is.getline(s,200) ) {
std::istringstream buffer(s);
......@@ -541,6 +546,22 @@ MaterialNode::read(std::istream& _is)
material_.shininess(x);
}
}
// Illumination model
else if (specifier == "Illum") {
buffer >> i;
if (buffer.good()) {
material_.illum(i);
}
}
// OverlayColor
else if (specifier == "indexOfRefraction") {
buffer >> x;
if (buffer.good()) {
material_.indexOfRefraction(x);
}
}
// PointSize
else if (specifier == "PointSize") {
buffer >> x;
......
......@@ -95,7 +95,9 @@ public:
specularColor_(GLState::default_specular_color),
overlayColor_(GLState::default_overlay_color),
shininess_(GLState::default_shininess),
illum_(0),
reflectance_(0.0),
indexOfRefraction_(1.0),
pointSize_(1.0),
lineWidth_(1.0),
roundPoints_(false),
......@@ -120,7 +122,9 @@ public:
specularColor_(_m.specularColor_),
overlayColor_(_m.overlayColor_),
shininess_(_m.shininess_),
illum_(_m.illum_),
reflectance_(_m.reflectance_),
indexOfRefraction_(_m.indexOfRefraction_),
pointSize_(_m.pointSize_),
lineWidth_(_m.lineWidth_),
roundPoints_(_m.roundPoints_),
......@@ -168,6 +172,11 @@ public:
/// get the base color
const Vec4f& baseColor() const { return baseColor_; }
/// set emission
void emission(const Vec4f& _c) { baseColor_ = _c;}
/// get emission
const Vec4f& emission() const { return baseColor_; }
/// set the ambient color.
void ambientColor(const Vec4f& _a) { ambientColor_ = _a; }
/// get the ambient color.
......@@ -202,11 +211,24 @@ public:
/// get shininess
float shininess() const { return shininess_; }
/// set illumnation model
void illum(int _m) { illum_ = _m; }
/// get illumination model
int illum() const { return illum_; }
/// set reflectance ( not used in OpenGL Rendering)
void reflectance(double _m) { reflectance_ = _m; }
/// get reflectance ( not used in OpenGL Rendering)
double reflectance() const { return reflectance_; }
/// set index of refraction
void indexOfRefraction(double _m) { indexOfRefraction_ = _m; }
/// get index of refraction ( not used in OpenGL Rendering)
double indexOfRefraction() const { return indexOfRefraction_; }
bool isRefractive() const {return illum_ == 4 || illum_ == 6 || illum_ == 7 || illum_ == 9;}
/// set point size (default: 1.0)
void pointSize(float _sz) { pointSize_ = _sz; }
/// get point size
......@@ -280,6 +302,8 @@ public:
/// disable backface culling (not active by default, see applyProperties)
void disableBackfaceCulling() { backfaceCulling_ = false; }
bool isEmissive() const { return baseColor_[0] > 0.f || baseColor_[1] > 0.f || baseColor_[2] > 0.f; }
protected:
Vec4f baseColor_;
......@@ -289,7 +313,9 @@ protected:
Vec4f overlayColor_;
float shininess_;
int illum_;
double reflectance_;
double indexOfRefraction_;
float pointSize_;
float lineWidth_;
......@@ -405,6 +431,11 @@ public:
/// get the base color
const Vec4f& base_color() const { return material_.baseColor(); }
/// set emission
void set_emission(const Vec4f& _c) { material_.baseColor(_c); }
/// get emission
const Vec4f& emission() const { return material_.baseColor(); }
/// set the ambient color.
void set_ambient_color(const Vec4f& _a) { material_.ambientColor(_a); }
/// get the ambient color.
......@@ -439,11 +470,21 @@ public:
/// get shininess
float shininess() const { return material_.shininess(); }
/// set illumination model
void set_illum(int _m) { material_.illum(_m); }
/// get illumination model
int illum() const { return material_.illum(); }
/// set reflectance
void set_reflectance(double _m) { material_.reflectance(_m); }
/// get reflectance
double reflectance() const { return material_.reflectance(); }
/// set index of refraction
void set_indexOfRefraction(double _m) { material_.indexOfRefraction(_m); }
/// get index of refraction
double indexOfRefraction() const { return material_.indexOfRefraction(); }
/** @} */
//===========================================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment