summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/MeshBaker/scripts/TextureBlenders/TextureBlenderMaterialPropertyCacheHelper.cs
diff options
context:
space:
mode:
authortylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
committertylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
commiteb84bb298d2b95aec7b2ae12cbf25ac64f25379a (patch)
treeefd616a157df06ab661c6d56651853431ac6b08b /VRCSDK3Worlds/Assets/MeshBaker/scripts/TextureBlenders/TextureBlenderMaterialPropertyCacheHelper.cs
downloadunityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.gz
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.bz2
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.zip
move to self host
Diffstat (limited to 'VRCSDK3Worlds/Assets/MeshBaker/scripts/TextureBlenders/TextureBlenderMaterialPropertyCacheHelper.cs')
-rw-r--r--VRCSDK3Worlds/Assets/MeshBaker/scripts/TextureBlenders/TextureBlenderMaterialPropertyCacheHelper.cs84
1 files changed, 84 insertions, 0 deletions
diff --git a/VRCSDK3Worlds/Assets/MeshBaker/scripts/TextureBlenders/TextureBlenderMaterialPropertyCacheHelper.cs b/VRCSDK3Worlds/Assets/MeshBaker/scripts/TextureBlenders/TextureBlenderMaterialPropertyCacheHelper.cs
new file mode 100644
index 00000000..ebaf3cba
--- /dev/null
+++ b/VRCSDK3Worlds/Assets/MeshBaker/scripts/TextureBlenders/TextureBlenderMaterialPropertyCacheHelper.cs
@@ -0,0 +1,84 @@
+using UnityEngine;
+using System.Collections;
+using System.Collections.Generic;
+using System;
+
+namespace DigitalOpus.MB.Core
+{
+ public class TextureBlenderMaterialPropertyCacheHelper
+ {
+ private struct MaterialPropertyPair
+ {
+ public Material material;
+ public string property;
+
+ public MaterialPropertyPair(Material m, string prop)
+ {
+ material = m;
+ property = prop;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (!(obj is MaterialPropertyPair)) return false;
+ MaterialPropertyPair b = (MaterialPropertyPair)obj;
+ if (!material.Equals(b.material)) return false;
+ if (property != b.property) return false;
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+ }
+
+ private Dictionary<MaterialPropertyPair, object> nonTexturePropertyValuesForSourceMaterials = new Dictionary<MaterialPropertyPair, object>();
+
+ private bool AllNonTexturePropertyValuesAreEqual(string prop)
+ {
+ bool foundFirst = false;
+ object firstVal = null;
+ foreach (MaterialPropertyPair k in nonTexturePropertyValuesForSourceMaterials.Keys)
+ {
+ if (k.property.Equals(prop))
+ {
+ if (!foundFirst)
+ {
+ firstVal = nonTexturePropertyValuesForSourceMaterials[k];
+ foundFirst = true;
+ }
+ else
+ {
+ if (!firstVal.Equals(nonTexturePropertyValuesForSourceMaterials[k]))
+ {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ public void CacheMaterialProperty(Material m, string property, object value)
+ {
+ nonTexturePropertyValuesForSourceMaterials[new MaterialPropertyPair(m, property)] = value;
+ }
+
+ public object GetValueIfAllSourceAreTheSameOrDefault(string property, object defaultValue)
+ {
+ if (AllNonTexturePropertyValuesAreEqual(property))
+ {
+ foreach (MaterialPropertyPair k in nonTexturePropertyValuesForSourceMaterials.Keys)
+ {
+ if (k.property.Equals(property))
+ {
+ return nonTexturePropertyValuesForSourceMaterials[k];
+ }
+ }
+ }
+
+ return defaultValue;
+ }
+ }
+} \ No newline at end of file