Browse Source

Added gltf2 KHR_materials_volume write support.

diharaw 4 years ago
parent
commit
d3276de47d
2 changed files with 27 additions and 0 deletions
  1. 1 0
      code/AssetLib/glTF2/glTF2AssetWriter.h
  2. 26 0
      code/AssetLib/glTF2/glTF2AssetWriter.inl

+ 1 - 0
code/AssetLib/glTF2/glTF2AssetWriter.h

@@ -49,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *   KHR_materials_sheen: full
  *   KHR_materials_clearcoat: full
  *   KHR_materials_transmission: full
+ *   KHR_materials_volume: full
  */
 #ifndef GLTF2ASSETWRITER_H_INC
 #define GLTF2ASSETWRITER_H_INC

+ 26 - 0
code/AssetLib/glTF2/glTF2AssetWriter.inl

@@ -474,6 +474,28 @@ namespace glTF2 {
             }
         }
 
+        if (m.materialVolume.isPresent) {
+            Value materialVolume(rapidjson::Type::kObjectType);
+
+            MaterialVolume &volume = m.materialVolume.value;
+
+            if (volume.thicknessFactor != 0.f) {
+                WriteFloat(materialVolume, volume.thicknessFactor, "thicknessFactor", w.mAl);
+            }
+
+            WriteTex(materialVolume, volume.thicknessTexture, "thicknessTexture", w.mAl);
+
+            if (volume.attenuationDistance != INFINITY) {
+                WriteFloat(materialVolume, volume.attenuationDistance, "attenuationDistance", w.mAl);
+            }
+
+            WriteVec(materialVolume, volume.attenuationColor, "attenuationColor", defaultAttenuationColor, w.mAl);
+
+            if (!materialVolume.ObjectEmpty()) {
+                exts.AddMember("KHR_materials_volume", materialVolume, w.mAl);
+            }
+        }
+
         if (!exts.ObjectEmpty()) {
             obj.AddMember("extensions", exts, w.mAl);
         }
@@ -890,6 +912,10 @@ namespace glTF2 {
                 exts.PushBack(StringRef("KHR_materials_transmission"), mAl);
             }
 
+            if (this->mAsset.extensionsUsed.KHR_materials_volume) {
+                exts.PushBack(StringRef("KHR_materials_volume"), mAl);
+            }
+
             if (this->mAsset.extensionsUsed.FB_ngon_encoding) {
                 exts.PushBack(StringRef("FB_ngon_encoding"), mAl);
             }