Commit 393aa27f authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

Changed ACG::Scenegraph::Material interface.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18014 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 54b86165
......@@ -65,20 +65,48 @@
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
namespace {
enum ClassProperties {
#ifdef ENABLE_QJSON
CP_JSON_SERIALIZABLE = 1
#else
CP_JSON_SERIALIZABLE = 0
#endif
};
//== IMPLEMENTATION ==========================================================
inline QVariantList col2vl(const ACG::Vec4f &col) {
return QVariantList() << col[0] << col[1] << col[2] << col[3];
}
inline ACG::Vec4f vl2col(const QVariantList &vl) {
if (vl.size() < 4) return ACG::Vec4f();
return ACG::Vec4f(vl[0].toFloat(), vl[1].toFloat(), vl[2].toFloat(), vl[3].toFloat());
}
static inline QVariantList col2vl(const Vec4f &col) {
return QVariantList() << col[0] << col[1] << col[2] << col[3];
} /* anonymous namespace */
namespace ACG {
QVariantMap json_to_variant_map(QString json) {
#ifdef ENABLE_QJSON
QJson::Parser parser;
bool ok;
QVariantMap matMap = parser.parse(json.toUtf8(), &ok).toMap();
if (!ok) return QVariantMap();
return matMap;
#else
return QVariantMap();
#endif
}
static inline Vec4f vl2col(const QVariantList &vl) {
if (vl.size() < 4) return Vec4f();
return Vec4f(vl[0].toFloat(), vl[1].toFloat(), vl[2].toFloat(), vl[3].toFloat());
namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
bool Material::support_json_serialization() {
return CP_JSON_SERIALIZABLE;
}
QString Material::serializeToJson() const {
......@@ -113,14 +141,7 @@ QString Material::serializeToJson() const {
#endif
}
void Material::deserializeFromJson(const QString &json) {
#ifdef ENABLE_QJSON
QJson::Parser parser;
bool ok;
QVariantMap matMap = parser.parse(json.toUtf8(), &ok).toMap();
if (!ok) return;
//QVariantMap matMap;
void Material::deserializeFromVariantMap(const QVariantMap &matMap) {
if (matMap.contains("baseColor")) baseColor_ = vl2col(matMap["baseColor"].toList());
if (matMap.contains("ambientColor")) ambientColor_ = vl2col(matMap["ambientColor"].toList());
if (matMap.contains("diffuseColor")) diffuseColor_ = vl2col(matMap["diffuseColor"].toList());
......@@ -140,6 +161,15 @@ void Material::deserializeFromJson(const QString &json) {
if (matMap.contains("colorMaterial")) colorMaterial_ = matMap["colorMaterial"].toBool();
if (matMap.contains("backfaceCulling")) backfaceCulling_ = matMap["backfaceCulling"].toBool();
if (matMap.contains("multiSampling")) multiSampling_ = matMap["multiSampling"].toBool();
}
void Material::deserializeFromJson(const QString &json) {
#ifdef ENABLE_QJSON
QJson::Parser parser;
bool ok;
QVariantMap matMap = parser.parse(json.toUtf8(), &ok).toMap();
if (!ok) return;
deserializeFromVariantMap(matMap);
#endif
}
......
......@@ -57,10 +57,14 @@
#include "BaseNode.hh"
#include <string>
#include <QVariantMap>
//== NAMESPACES ===============================================================
namespace ACG {
QVariantMap json_to_variant_map(QString json);
namespace SceneGraph {
......@@ -76,14 +80,6 @@ class ACGDLLEXPORT Material {
friend class MaterialNode;
public:
enum ClassProperties {
#ifdef ENABLE_QJSON
CP_JSON_SERIALIZABLE = 1
#else
CP_JSON_SERIALIZABLE = 0
#endif
};
/// Default constructor
Material() :
baseColor_(GLState::default_base_color),
......@@ -131,8 +127,10 @@ public:
backfaceCulling_(_m.backfaceCulling_),
multiSampling_(_m.multiSampling_) {};
static bool support_json_serialization();
QString serializeToJson() const;
void deserializeFromJson(const QString &json);
void deserializeFromVariantMap(const QVariantMap &matMap);
/** \brief Set color based on _c
*
......
......@@ -1120,7 +1120,7 @@ QStringList collectObjectComments(bool visibleOnly, bool targetedOnly) {
}
QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly) {
if (!ACG::SceneGraph::Material::CP_JSON_SERIALIZABLE)
if (!ACG::SceneGraph::Material::support_json_serialization())
return QStringList();
QStringList result;
......
......@@ -521,7 +521,7 @@ void CoreWidget::viewerSnapshotDialog() {
SnapshotDialog dialog(suggest, true, w, h, 0);
if (!ACG::SceneGraph::Material::CP_JSON_SERIALIZABLE)
if (!ACG::SceneGraph::Material::support_json_serialization())
dialog.metaData_storeMatInfo_cb->setVisible(false);
bool ok = dialog.exec();
......@@ -547,7 +547,8 @@ void CoreWidget::viewerSnapshotDialog() {
}
QString materials;
if (ACG::SceneGraph::Material::CP_JSON_SERIALIZABLE &&
if (ACG::SceneGraph::Material::support_json_serialization() &&
//if (ACG::SceneGraph::Material::CP_JSON_SERIALIZABLE &&
dialog.metaData_storeMatInfo_cb->isChecked()) {
materials = PluginFunctions::collectObjectMaterials(
dialog.metaData_comments_visibleOnly_cb->isChecked(),
......
Supports Markdown
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