summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2016-01-06 14:02:26 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2016-01-07 09:28:22 +0000
commit6d59b110d0db8ba3b99ee345e88ef4fb5e1d33fb (patch)
treef232b41323767de682a1ba709c3cc5dd5b31eacd /tools
parent7840241b0aec3e40c1bad7ea9bddfebf699e976d (diff)
qgltf: Promote rgb to rgba for common material values
The spec uses FLOAT_VEC4 for colors. This means that while in the custom material case we can use vec3 since we provide the type information, the common materials path needs to promote all colors to RGBA. Change-Id: I1ac403807d0d6f0e9dfe14ea704c7f4a325495fa Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/qgltf/qgltf.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/qgltf/qgltf.cpp b/tools/qgltf/qgltf.cpp
index 561e167b7..22ab5c84b 100644
--- a/tools/qgltf/qgltf.cpp
+++ b/tools/qgltf/qgltf.cpp
@@ -1750,6 +1750,23 @@ static inline QJsonArray vec2jsvec(const QVector<float> &v)
return arr;
}
+static inline void promoteColorsToRGBA(QJsonObject *obj)
+{
+ QJsonObject::iterator it = obj->begin(), itEnd = obj->end();
+ while (it != itEnd) {
+ QJsonArray arr = it.value().toArray();
+ if (arr.count() == 3) {
+ const QString key = it.key();
+ if (key == QStringLiteral("ambient")
+ || key == QStringLiteral("diffuse")
+ || key == QStringLiteral("specular"))
+ arr.append(1);
+ *it = arr;
+ }
+ ++it;
+ }
+}
+
void GltfExporter::exportMaterials(QJsonObject &materials, QHash<QString, QString> *textureNameMap)
{
for (uint i = 0; i < m_importer->materialCount(); ++i) {
@@ -1847,6 +1864,9 @@ void GltfExporter::exportMaterials(QJsonObject &materials, QHash<QString, QStrin
QJsonObject commonMat;
commonMat["technique"] = prog->commonTechniqueName;
// Set the values as-is. "normalmap" is our own extension, not in the spec.
+ // However, RGB colors have to be promoted to RGBA since the spec uses
+ // vec4, and all types are pre-defined for common material values.
+ promoteColorsToRGBA(&vals);
commonMat["values"] = vals;
if (!opaque)
commonMat["transparent"] = true;