From 57f80955069a4adfc7e979699bce778f4128a170 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 27 Sep 2019 12:00:45 -0700 Subject: [PATCH] Pass 4 on cleaning up that pr, put the SortFIlterModel.qml in the new skit/qml lib, setting the opacityMappMode correctly from script --- libraries/graphics/src/graphics/Material.cpp | 18 ++++++++++- libraries/graphics/src/graphics/Material.h | 11 ++++++- libraries/graphics/src/graphics/Material.slh | 21 ++++++------ .../src/material-networking/MaterialCache.cpp | 32 ++++++++++++------- .../cache/cash/ResourceCacheInspector.qml | 3 +- .../developer/utilities/lib/prop/PropItem.qml | 3 -- .../cash => lib/skit/qml}/SortFilterModel.qml | 0 .../developer/utilities/lib/skit/qml/qmldir | 1 + 8 files changed, 62 insertions(+), 27 deletions(-) rename scripts/developer/utilities/{cache/cash => lib/skit/qml}/SortFilterModel.qml (100%) create mode 100644 scripts/developer/utilities/lib/skit/qml/qmldir diff --git a/libraries/graphics/src/graphics/Material.cpp b/libraries/graphics/src/graphics/Material.cpp index ed98b1a1e4..5fcf8ba06a 100755 --- a/libraries/graphics/src/graphics/Material.cpp +++ b/libraries/graphics/src/graphics/Material.cpp @@ -30,10 +30,20 @@ const float Material::DEFAULT_OPACITY_CUTOFF { 0.5f }; std::string MaterialKey::getOpacityMapModeName(OpacityMapMode mode) { - const std::string names[3] = { "OPACITY_MAP_OPAQUE", "OAPCITY_MAP_MASK", "OPACITY_MAP_BLEND" }; + const std::string names[3] = { "OPACITY_MAP_OPAQUE", "OPACITY_MAP_MASK", "OPACITY_MAP_BLEND" }; return names[mode]; } + +bool MaterialKey::getOpacityMapModeFromName(const std::string& modeName, MaterialKey::OpacityMapMode& mode) { + for (mode = OPACITY_MAP_OPAQUE; mode <= OPACITY_MAP_BLEND; mode + 1) { + if (modeName == getOpacityMapModeName(mode)) { + return true; + } + } + return false; +} + Material::Material() { for (int i = 0; i < NUM_TOTAL_FLAGS; i++) { _propertyFallthroughs[i] = false; @@ -166,6 +176,12 @@ void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textur } bool Material::resetOpacityMap() const { + // If OpacityMapMode explicit then nothing need to change here. + if (_key.isOpacityMapMode()) { + return false; + } + + // Else, the legacy behavior is to interpret the albedo texture assigned to tune the opacity map mode value auto previous = _key.getOpacityMapMode(); // Clear the previous flags _key.setOpacityMaskMap(false); diff --git a/libraries/graphics/src/graphics/Material.h b/libraries/graphics/src/graphics/Material.h index d2bb7b77e3..25ff711c0c 100755 --- a/libraries/graphics/src/graphics/Material.h +++ b/libraries/graphics/src/graphics/Material.h @@ -43,6 +43,7 @@ public: OPACITY_VAL_BIT, OPACITY_MASK_MAP_BIT, // Opacity Map and Opacity MASK map are mutually exclusive OPACITY_TRANSLUCENT_MAP_BIT, + OPACITY_MAP_MODE_BIT, // Opacity map mode bit is set if the value has set explicitely and not deduced from the textures assigned OPACITY_CUTOFF_VAL_BIT, SCATTERING_VAL_BIT, @@ -79,6 +80,8 @@ public: OPACITY_MAP_BLEND, }; static std::string getOpacityMapModeName(OpacityMapMode mode); + // find the enum value from a string, return true if match found + static bool getOpacityMapModeFromName(const std::string& modeName, OpacityMapMode& mode); // The signature is the Flags Flags _flags; @@ -118,6 +121,7 @@ public: _flags.reset(OPACITY_MASK_MAP_BIT); break; }; + _flags.set(OPACITY_MAP_MODE_BIT); // Intentionally set the mode! return (*this); } Builder& withOpacityCutoff() { _flags.set(OPACITY_CUTOFF_VAL_BIT); return (*this); } @@ -213,7 +217,9 @@ public: _flags.reset(OPACITY_MASK_MAP_BIT); break; }; + _flags.set(OPACITY_MAP_MODE_BIT); // Intentionally set the mode! } + bool isOpacityMapMode() const { return _flags[OPACITY_MAP_MODE_BIT]; } OpacityMapMode getOpacityMapMode() const { return (isOpacityMaskMap() ? OPACITY_MAP_MASK : (isTranslucentMap() ? OPACITY_MAP_BLEND : OPACITY_MAP_OPAQUE)); } bool isTranslucent() const { return isTranslucentFactor() || isTranslucentMap(); } @@ -274,6 +280,9 @@ public: Builder& withoutMaskMap() { _value.reset(MaterialKey::OPACITY_MASK_MAP_BIT); _mask.set(MaterialKey::OPACITY_MASK_MAP_BIT); return (*this); } Builder& withMaskMap() { _value.set(MaterialKey::OPACITY_MASK_MAP_BIT); _mask.set(MaterialKey::OPACITY_MASK_MAP_BIT); return (*this); } + Builder& withoutOpacityMapMode() { _value.reset(MaterialKey::OPACITY_MAP_MODE_BIT); _mask.set(MaterialKey::OPACITY_MAP_MODE_BIT); return (*this); } + Builder& withOpacityMapMode() { _value.set(MaterialKey::OPACITY_MAP_MODE_BIT); _mask.set(MaterialKey::OPACITY_MAP_MODE_BIT); return (*this); } + Builder& withoutOpacityCutoff() { _value.reset(MaterialKey::OPACITY_CUTOFF_VAL_BIT); _mask.set(MaterialKey::OPACITY_CUTOFF_VAL_BIT); return (*this); } Builder& withOpacityCutoff() { _value.set(MaterialKey::OPACITY_CUTOFF_VAL_BIT); _mask.set(MaterialKey::OPACITY_CUTOFF_VAL_BIT); return (*this); } @@ -332,7 +341,7 @@ public: float getOpacity() const { return _opacity; } static const MaterialKey::OpacityMapMode DEFAULT_OPACITY_MAP_MODE; - void setOpacityMapMode(MaterialKey::OpacityMapMode alphaMode); + void setOpacityMapMode(MaterialKey::OpacityMapMode opacityMapMode); MaterialKey::OpacityMapMode getOpacityMapMode() const; static const float DEFAULT_OPACITY_CUTOFF; diff --git a/libraries/graphics/src/graphics/Material.slh b/libraries/graphics/src/graphics/Material.slh index fa2c4d0aa9..328ff4a3af 100644 --- a/libraries/graphics/src/graphics/Material.slh +++ b/libraries/graphics/src/graphics/Material.slh @@ -85,17 +85,18 @@ const BITFIELD GLOSSY_VAL_BIT = 0x00000010; const BITFIELD OPACITY_VAL_BIT = 0x00000020; const BITFIELD OPACITY_MASK_MAP_BIT = 0x00000040; const BITFIELD OPACITY_TRANSLUCENT_MAP_BIT = 0x00000080; -const BITFIELD OPACITY_CUTOFF_VAL_BIT = 0x00000100; -const BITFIELD SCATTERING_VAL_BIT = 0x00000200; +const BITFIELD OPACITY_MAP_MODE_BIT = 0x00000100; +const BITFIELD OPACITY_CUTOFF_VAL_BIT = 0x00000200; +const BITFIELD SCATTERING_VAL_BIT = 0x00000400; -const BITFIELD EMISSIVE_MAP_BIT = 0x00000400; -const BITFIELD ALBEDO_MAP_BIT = 0x00000800; -const BITFIELD METALLIC_MAP_BIT = 0x00001000; -const BITFIELD ROUGHNESS_MAP_BIT = 0x00002000; -const BITFIELD NORMAL_MAP_BIT = 0x00004000; -const BITFIELD OCCLUSION_MAP_BIT = 0x00008000; -const BITFIELD LIGHTMAP_MAP_BIT = 0x00010000; -const BITFIELD SCATTERING_MAP_BIT = 0x00020000; +const BITFIELD EMISSIVE_MAP_BIT = 0x00000800; +const BITFIELD ALBEDO_MAP_BIT = 0x00001000; +const BITFIELD METALLIC_MAP_BIT = 0x00002000; +const BITFIELD ROUGHNESS_MAP_BIT = 0x00004000; +const BITFIELD NORMAL_MAP_BIT = 0x00008000; +const BITFIELD OCCLUSION_MAP_BIT = 0x00010000; +const BITFIELD LIGHTMAP_MAP_BIT = 0x00020000; +const BITFIELD SCATTERING_MAP_BIT = 0x00040000; <@endif@> diff --git a/libraries/material-networking/src/material-networking/MaterialCache.cpp b/libraries/material-networking/src/material-networking/MaterialCache.cpp index dd55b7fd86..db4783d249 100644 --- a/libraries/material-networking/src/material-networking/MaterialCache.cpp +++ b/libraries/material-networking/src/material-networking/MaterialCache.cpp @@ -139,6 +139,14 @@ NetworkMaterialResource::ParsedMaterials NetworkMaterialResource::parseJSONMater * @property {string} opacityMap - The URL of the opacity texture image. Set the value the same as the albedoMap * value for transparency. * "hifi_pbr" model only. + * @property {number|string} opacityMapMode - The mode defining the interpretation of the opacity map. Values can be: + * "OPACITY_MAP_OPAQUE" for ignoring the opacity map information. + * "OPACITY_MAP_MASK" for using the opacity map as a mask, where only the texel greater than opacityCutoff are visible and rendered opaque. + * "OPACITY_MAP_BLEND" for using the opacity map for alpha blending the material surface with the background. + * Set to "fallthrough" to fall through to the material below. "hifi_pbr" model only. + * @property {number|string} opacityCutoff - The opacity cutoff threshold used to determine the opaque texels of the Opacity map + * when opacityMapMode is "OPACITY_MAP_MASK", range 0.01.0. + * Set to "fallthrough" to fall through to the material below. "hifi_pbr" model only. * @property {string} roughnessMap - The URL of the roughness texture image. You can use this or glossMap, but not * both. * Set to "fallthrough" to fall through to the material below. "hifi_pbr" model only. @@ -258,22 +266,24 @@ std::pair> NetworkMaterialResource } else if (value.isDouble()) { material->setMetallic(value.toDouble()); } - } else if (key == "opacityCuttoff") { + } else if (key == "opacityMapMode") { + auto value = materialJSON.value(key); + auto valueString = (value.isString() ? value.toString() : ""); + if (valueString == FALLTHROUGH) { + material->setPropertyDoesFallthrough(graphics::MaterialKey::FlagBit::OPACITY_MAP_MODE_BIT); + } else { + graphics::MaterialKey::OpacityMapMode mode; + if (graphics::MaterialKey::getOpacityMapModeFromName(valueString.toStdString(), mode)) { + material->setOpacityMapMode(mode); + } + } + } else if (key == "opacityCutoff") { auto value = materialJSON.value(key); if (value.isString() && value.toString() == FALLTHROUGH) { material->setPropertyDoesFallthrough(graphics::MaterialKey::FlagBit::OPACITY_CUTOFF_VAL_BIT); - } - else if (value.isDouble()) { + } else if (value.isDouble()) { material->setOpacityCutoff(value.toDouble()); } - /* SG TODO: Implement the set opacityMapMOde intentionaly } else if (key == "opacityMapMode") { - auto value = materialJSON.value(key); - if (value.isString() && value.toString() == FALLTHROUGH) { - material->setPropertyDoesFallthrough(graphics::MaterialKey::FlagBit::OPACITY_MAP_MODE_BIT); - } - else if (value.isDouble()) { - material->setOpacityCutoff(value.toDouble()); - }**/ } else if (key == "scattering") { auto value = materialJSON.value(key); if (value.isString() && value.toString() == FALLTHROUGH) { diff --git a/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml b/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml index 7d14a07e13..2fa0af8cbc 100644 --- a/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml +++ b/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml @@ -12,6 +12,7 @@ import QtQuick.Controls 2.5 import QtQuick.Layouts 1.3 import QtQml.Models 2.12 +import "../../lib/skit/qml" as Skit import "../../lib/prop" as Prop Item { @@ -313,7 +314,7 @@ Item { } } - SortFilterModel { + Skit.SortFilterModel { id: visualModel model: ListModel {} diff --git a/scripts/developer/utilities/lib/prop/PropItem.qml b/scripts/developer/utilities/lib/prop/PropItem.qml index 24e2ecaa9a..3779e7f4a9 100644 --- a/scripts/developer/utilities/lib/prop/PropItem.qml +++ b/scripts/developer/utilities/lib/prop/PropItem.qml @@ -24,7 +24,6 @@ Item { // By default, these just go get or set the value from the object[property] // function defaultGet() { var v = root.object[root.property]; return v; } - // function defaultGet() { return root.object[root.property]; } function defaultSet(value) { root.object[root.property] = value; } function defaultSetReadOnly(value) {} @@ -36,8 +35,6 @@ Item { height: global.lineHeight anchors.left: parent.left anchors.right: parent.right - // anchors.leftMargin: global.horizontalMargin - // anchors.rightMargin: global.horizontalMargin // LabelControl And SplitterControl are on the left side of the PropItem property bool showLabel: true diff --git a/scripts/developer/utilities/cache/cash/SortFilterModel.qml b/scripts/developer/utilities/lib/skit/qml/SortFilterModel.qml similarity index 100% rename from scripts/developer/utilities/cache/cash/SortFilterModel.qml rename to scripts/developer/utilities/lib/skit/qml/SortFilterModel.qml diff --git a/scripts/developer/utilities/lib/skit/qml/qmldir b/scripts/developer/utilities/lib/skit/qml/qmldir new file mode 100644 index 0000000000..14d11d998a --- /dev/null +++ b/scripts/developer/utilities/lib/skit/qml/qmldir @@ -0,0 +1 @@ +SortFilterModel 1.0 SortFilterModel.qml \ No newline at end of file