diff --git a/Runtime/Plugins/GLTFSerialization/Schema/AnimationPointerData.cs b/Runtime/Plugins/GLTFSerialization/Schema/AnimationPointerData.cs index d0b6af020..4455e3ee5 100644 --- a/Runtime/Plugins/GLTFSerialization/Schema/AnimationPointerData.cs +++ b/Runtime/Plugins/GLTFSerialization/Schema/AnimationPointerData.cs @@ -12,9 +12,12 @@ public class AnimationPointerData public ImportValuesConversion importAccessorContentConversion; public string primaryPath = ""; + public string primaryProperty = ""; + public AttributeAccessor primaryData; public string secondaryPath = ""; + public string secondaryProperty = ""; public AttributeAccessor secondaryData; } diff --git a/Runtime/Scripts/Plugins/AnimationPointer/AnimationPointerUtilities.cs b/Runtime/Scripts/Plugins/AnimationPointer/AnimationPointerUtilities.cs index 049f90f28..b2d8804cd 100644 --- a/Runtime/Scripts/Plugins/AnimationPointer/AnimationPointerUtilities.cs +++ b/Runtime/Scripts/Plugins/AnimationPointer/AnimationPointerUtilities.cs @@ -1,4 +1,5 @@ -using GLTF.Schema; +using GLTF; +using GLTF.Schema; using UnityEngine; namespace UnityGLTF.Plugins @@ -8,18 +9,21 @@ internal static class AnimationPointerHelpers private static readonly string[] MATERIAL_PROPERTY_COMPONENTS = {"x", "y", "z", "w"}; private static readonly string[] MATERIAL_COLOR_PROPERTY_COMPONENTS = {"r", "g", "b", "a"}; - internal static bool BuildImportMaterialAnimationPointerData(MaterialPropertiesRemapper remapper, Material material, - string gltfProperty, GLTFAccessorAttributeType valueType, out AnimationPointerData pointerData) + internal static bool BuildImportMaterialAnimationPointerData(string pointerPath, MaterialPropertiesRemapper remapper, Material material, + string gltfProperty, AttributeAccessor accessor, out AnimationPointerData pointerData) { + var valueType = accessor.AccessorId.Value.Type; pointerData = new AnimationPointerData(); + pointerData.primaryPath = pointerPath; + pointerData.primaryData = accessor; + if (!remapper.GetUnityPropertyName(material, gltfProperty, out string unityPropertyName, out MaterialPointerPropertyMap propertyMap, out bool isSecondaryGltfProperty)) return false; - - // e.g. Emission Factor and Emission Color are combined into a single property - if (isSecondaryGltfProperty && propertyMap.CombinePrimaryAndSecondaryOnImport) - return false; + pointerData.primaryProperty = propertyMap.GltfPropertyName; + pointerData.secondaryProperty = propertyMap.GltfSecondaryPropertyName; + if (propertyMap.CombinePrimaryAndSecondaryOnImport) { if (propertyMap.CombinePrimaryAndSecondaryDataFunction == null) @@ -36,23 +40,31 @@ internal static bool BuildImportMaterialAnimationPointerData(MaterialPropertiesR valueType = propertyMap.OverrideCombineResultType; } + if (isSecondaryGltfProperty) + { + pointerData.primaryPath = ""; + pointerData.primaryData = null; + pointerData.secondaryPath = pointerPath; + pointerData.secondaryData = accessor; + } + switch (valueType) { case GLTFAccessorAttributeType.SCALAR: pointerData.unityPropertyNames = GetAnimationChannelProperties(unityPropertyName, 1, isSecondaryGltfProperty ? 1 : 0 ); - pointerData.importAccessorContentConversion = (data, frame) => MaterialValueConversion(data.primaryData.AccessorContent, frame, primaryComponentCount, propertyMap, pointerDataCopy); + pointerData.importAccessorContentConversion = (data, frame) => MaterialValueConversion(frame, primaryComponentCount, propertyMap, pointerDataCopy); break; case GLTFAccessorAttributeType.VEC2: pointerData.unityPropertyNames = GetAnimationChannelProperties(unityPropertyName, 2, isSecondaryGltfProperty ? 2 : 0); - pointerData.importAccessorContentConversion = (data, frame) => MaterialValueConversion(data.primaryData.AccessorContent, frame, primaryComponentCount, propertyMap, pointerDataCopy); + pointerData.importAccessorContentConversion = (data, frame) => MaterialValueConversion(frame, primaryComponentCount, propertyMap, pointerDataCopy); break; case GLTFAccessorAttributeType.VEC3: pointerData.unityPropertyNames = GetAnimationChannelProperties(unityPropertyName, 3, isColor: propertyMap.IsColor); - pointerData.importAccessorContentConversion = (data, frame) => MaterialValueConversion(data.primaryData.AccessorContent, frame, primaryComponentCount, propertyMap, pointerDataCopy); + pointerData.importAccessorContentConversion = (data, frame) => MaterialValueConversion(frame, primaryComponentCount, propertyMap, pointerDataCopy); break; case GLTFAccessorAttributeType.VEC4: pointerData.unityPropertyNames = GetAnimationChannelProperties(unityPropertyName, 4, isColor: propertyMap.IsColor); - pointerData.importAccessorContentConversion = (data, frame) => MaterialValueConversion(data.primaryData.AccessorContent, frame, primaryComponentCount, propertyMap, pointerDataCopy); + pointerData.importAccessorContentConversion = (data, frame) => MaterialValueConversion(frame, primaryComponentCount, propertyMap, pointerDataCopy); break; default: return false; @@ -81,63 +93,72 @@ internal static string[] GetAnimationChannelProperties(string propertyName, int return result; } - internal static float[] MaterialValueConversion(NumericArray data, int index, int componentCount, MaterialPointerPropertyMap map, AnimationPointerData pointerData) + internal static float[] MaterialValueConversion(int index, int componentCount, MaterialPointerPropertyMap map, AnimationPointerData pointerData) { int resultComponentCount = componentCount; if (map.CombineComponentResult == MaterialPointerPropertyMap.CombineResultType.Override) { resultComponentCount = map.OverrideCombineResultType.ComponentCount(); } + float[] primary = new float[0]; float[] result = new float[resultComponentCount]; - - - switch (componentCount) + if (pointerData.primaryData != null) { - case 1: - result[0] = data.AsFloats[index]; - break; - case 2: - var frameData2 = data.AsFloat2s[index]; - result[0] = frameData2.x; - result[1] = frameData2.y; - break; - case 3: - var frameData3 = data.AsFloat3s[index]; - if (map.PropertyType == MaterialPointerPropertyMap.PropertyTypeOption.SRGBColor) - { - Color gammaColor = new Color(frameData3.x, frameData3.y, frameData3.z).gamma; - result[0] = gammaColor.r; - result[1] = gammaColor.g; - result[2] = gammaColor.b; - } - else - { - result[0] = frameData3.x; - result[1] = frameData3.y; - result[2] = frameData3.z; - } - break; - case 4: - var frameData4 = data.AsFloat4s[index]; - if (map.PropertyType == MaterialPointerPropertyMap.PropertyTypeOption.SRGBColor) - { - Color gammaColor = new Color(frameData4.x, frameData4.y, frameData4.z, frameData4.z).gamma; - result[0] = gammaColor.r; - result[1] = gammaColor.g; - result[2] = gammaColor.b; - result[3] = gammaColor.a; - } - else - { - result[0] = frameData4.x; - result[1] = frameData4.y; - result[2] = frameData4.z; - result[3] = frameData4.w; - } + var primaryData = pointerData.primaryData.AccessorContent; + switch (componentCount) + { + case 1: + primary = new float[1]; + primary[0] = primaryData.AsFloats[index]; + break; + case 2: + primary = new float[2]; + var frameData2 = primaryData.AsFloat2s[index]; + primary[0] = frameData2.x; + primary[1] = frameData2.y; + break; + case 3: + primary = new float[3]; + var frameData3 = primaryData.AsFloat3s[index]; + if (map.PropertyType == MaterialPointerPropertyMap.PropertyTypeOption.SRGBColor) + { + Color gammaColor = new Color(frameData3.x, frameData3.y, frameData3.z).gamma; + primary[0] = gammaColor.r; + primary[1] = gammaColor.g; + primary[2] = gammaColor.b; + } + else + { + primary[0] = frameData3.x; + primary[1] = frameData3.y; + primary[2] = frameData3.z; + } - break; + break; + case 4: + primary = new float[4]; + var frameData4 = primaryData.AsFloat4s[index]; + if (map.PropertyType == MaterialPointerPropertyMap.PropertyTypeOption.SRGBColor) + { + Color gammaColor = new Color(frameData4.x, frameData4.y, frameData4.z, frameData4.z).gamma; + primary[0] = gammaColor.r; + primary[1] = gammaColor.g; + primary[2] = gammaColor.b; + primary[3] = gammaColor.a; + } + else + { + primary[0] = frameData4.x; + primary[1] = frameData4.y; + primary[2] = frameData4.z; + primary[3] = frameData4.w; + } + + break; + } } + if (map.CombinePrimaryAndSecondaryOnImport && map.CombinePrimaryAndSecondaryDataFunction != null) { float[] secondary = new float[0]; @@ -163,12 +184,14 @@ internal static float[] MaterialValueConversion(NumericArray data, int index, in secondary = new float[] { s4.x, s4.y, s4.z, s4.w }; break; default: - return result; + return primary; } } - result = map.CombinePrimaryAndSecondaryDataFunction(result, secondary); + result = map.CombinePrimaryAndSecondaryDataFunction(primary, secondary, result.Length); } + else + result = primary; return result; } diff --git a/Runtime/Scripts/Plugins/AnimationPointer/MaterialPropertiesRemapper.cs b/Runtime/Scripts/Plugins/AnimationPointer/MaterialPropertiesRemapper.cs index 330dfc7f8..37c75dcb1 100644 --- a/Runtime/Scripts/Plugins/AnimationPointer/MaterialPropertiesRemapper.cs +++ b/Runtime/Scripts/Plugins/AnimationPointer/MaterialPropertiesRemapper.cs @@ -64,7 +64,7 @@ public string[] PropertyNames public string ExtensionName = null; // The arrays contains the components of the primary and secondary properties. e.g. for a Vector3, the arrays will contain 3 elements - public delegate float[] CombinePrimaryAndSecondaryData(float[] primary, float[] secondary); + public delegate float[] CombinePrimaryAndSecondaryData(float[] primary, float[] secondary, int expectedResultLength); /// /// Function to combine primary and secondary data on import. @@ -119,13 +119,32 @@ private void CreatePropertyIds() } } - private static float[] CombineTextureTransform(float[] primary, float[] secondary) + private static float[] CombineTextureTransform(float[] primary, float[] secondary, int expectedResultLength) { - var result = new float[4]; - result[0] = primary[0]; - result[1] = primary[1]; - result[2] = secondary[0]; - result[3] = 1f - secondary[1] - primary[1]; + var result = new float[expectedResultLength]; + + if (primary.Length >= 2) + { + result[0] = primary[0]; + result[1] = primary[1]; + } + + if (primary.Length == 0) + { + result[0] = 1; + result[1] = 1; + } + + if (secondary.Length == 2) + { + result[2] = secondary[0]; + result[3] = 1f - secondary[1] - result[1]; + } + else + { + result[2] = 0; + result[3] = 0; + } return result; } @@ -151,6 +170,46 @@ public enum ImportExportUsageOption private Dictionary importMaps = new Dictionary(); private Dictionary exportMaps = new Dictionary (); + public void AddTextureExtTransforms(string gltfTextureName, string[] unityTextureNames, string extension = null) + { + var stNames = new string[unityTextureNames.Length]; + for (int i = 0; i < stNames.Length; i++) + stNames[i] = $"{unityTextureNames[i]}_ST"; + + var stMap = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.TextureTransform) + { + PropertyNames = stNames, + GltfPropertyName = $"{gltfTextureName}/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.SCALE}", + GltfSecondaryPropertyName = $"{gltfTextureName}/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.OFFSET}", + ExtensionName = extension + }; + AddMap(stMap); + + var rotNames = new string[unityTextureNames.Length]; + for (int i = 0; i < stNames.Length; i++) + rotNames[i] = $"{unityTextureNames[i]}Rotation"; + + var rotMap = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.Float) + { + PropertyNames = rotNames, + GltfPropertyName = $"{gltfTextureName}/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.ROTATION}", + ExtensionName = extension + }; + AddMap(rotMap); + + var texCoordNames = new string[unityTextureNames.Length]; + for (int i = 0; i < stNames.Length; i++) + texCoordNames[i] = $"{unityTextureNames[i]}TexCoord"; + + var texCoordMap = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.Float) + { + PropertyNames = texCoordNames, + GltfPropertyName = $"{gltfTextureName}/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.TEXCOORD}", + ExtensionName = extension + }; + AddMap(texCoordMap); + } + public void AddMap(MaterialPointerPropertyMap map, ImportExportUsageOption importExport = ImportExportUsageOption.ImportAndExport) { if (importExport == ImportExportUsageOption.ImportOnly || @@ -279,15 +338,6 @@ public DefaultMaterialPropertiesRemapper() }; AddMap(roughness); - var roughnessTex = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.TextureTransform) - { - PropertyNames = new[] { "metallicRoughnessTexture_ST", "_metallicRoughnessTexture_ST", "_MetallicRoughnessTexture_ST" }, - GltfPropertyName = $"pbrMetallicRoughness/metallicRoughnessTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.SCALE}", - GltfSecondaryPropertyName = $"pbrMetallicRoughness/metallicRoughnessTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.OFFSET}", - ExtensionName = ExtTextureTransformExtensionFactory.EXTENSION_NAME - }; - AddMap(roughnessTex); - var dispersion = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.Float) { PropertyNames = new[] { "dispersion"}, @@ -302,17 +352,6 @@ public DefaultMaterialPropertiesRemapper() }; AddMap(metallic); - var baseColorTexture = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.TextureTransform) - { - PropertyNames = new[] { "_MainTex_ST", "_BaseMap_ST", "_BaseColorTexture_ST", "baseColorTexture_ST" }, - GltfPropertyName = - $"pbrMetallicRoughness/baseColorTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.SCALE}", - GltfSecondaryPropertyName = - $"pbrMetallicRoughness/baseColorTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.OFFSET}", - ExtensionName = ExtTextureTransformExtensionFactory.EXTENSION_NAME, - }; - AddMap(baseColorTexture); - var emissiveFactor = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.SRGBColor) { PropertyNames = new[] { "_EmissionColor", "_EmissiveFactor", "emissiveFactor" }, @@ -322,10 +361,10 @@ public DefaultMaterialPropertiesRemapper() ExtensionName = KHR_materials_emissive_strength_Factory.EXTENSION_NAME, CombinePrimaryAndSecondaryOnImport = true, ExportKeepColorAlpha = false, - CombinePrimaryAndSecondaryDataFunction = (primary, secondary) => + CombinePrimaryAndSecondaryDataFunction = (primary, secondary, exptedResultLength) => { float strength = (secondary != null && secondary.Length > 0) ? secondary[0] : 1f; - var result = new float[primary.Length]; + var result = new float[exptedResultLength]; for (int i = 0; i < 3; i++) result[i] = primary[i] * strength; if (result.Length == 4) @@ -342,18 +381,7 @@ public DefaultMaterialPropertiesRemapper() } }; AddMap(emissiveFactor); - - var emissiveTexture = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.TextureTransform) - { - PropertyNames = new[] { "_EmissionMap_ST", "_EmissiveTexture_ST", "emissiveTexture_ST" }, - GltfPropertyName = - $"emissiveTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.SCALE}", - GltfSecondaryPropertyName = - $"emissiveTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.OFFSET}", - ExtensionName = ExtTextureTransformExtensionFactory.EXTENSION_NAME - }; - AddMap(emissiveTexture); - + var alphaCutoff = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.Float) { PropertyNames = new[] { "_AlphaCutoff", "alphaCutoff", "_Cutoff" }, @@ -367,18 +395,7 @@ public DefaultMaterialPropertiesRemapper() GltfPropertyName = "normalTexture/scale" }; AddMap(normalScale); - - var normalTexture = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.TextureTransform) - { - PropertyNames = new[] { "_BumpMap_ST", "_NormalTexture_ST", "normalTexture_ST" }, - GltfPropertyName = - $"normalTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.SCALE}", - GltfSecondaryPropertyName = - $"normalTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.OFFSET}", - ExtensionName = ExtTextureTransformExtensionFactory.EXTENSION_NAME - }; - AddMap(normalTexture); - + var occlusionStrength = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.Float) { PropertyNames = new[] { "_OcclusionStrength", "occlusionStrength", "occlusionTextureStrength" }, @@ -386,17 +403,6 @@ public DefaultMaterialPropertiesRemapper() }; AddMap(occlusionStrength); - var occlusionTexture = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.TextureTransform) - { - PropertyNames = new[] { "_OcclusionMap_ST", "_OcclusionTexture_ST", "occlusionTexture_ST" }, - GltfPropertyName = - $"occlusionTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.SCALE}", - GltfSecondaryPropertyName = - $"occlusionTexture/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.OFFSET}", - ExtensionName = ExtTextureTransformExtensionFactory.EXTENSION_NAME - }; - AddMap(occlusionTexture); - // KHR_materials_transmission var transmissionFactor = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.Float) { @@ -492,28 +498,26 @@ public DefaultMaterialPropertiesRemapper() }; AddMap(clearcoatRoughnessFactor); - var clearcoatTexture = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.TextureTransform) - { - PropertyNames = new[] { "_clearcoatTexture_ST", "clearcoatTexture_ST", "ClearcoatTexture_ST" }, - GltfPropertyName = - $"{nameof(KHR_materials_clearcoat.clearcoatTexture)}/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.SCALE}", - GltfSecondaryPropertyName = - $"{nameof(KHR_materials_clearcoat.clearcoatTexture)}/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.OFFSET}", - ExtensionName = ExtTextureTransformExtensionFactory.EXTENSION_NAME - }; - AddMap(clearcoatTexture); + AddTextureExtTransforms("pbrMetallicRoughness/baseColorTexture", new[] { "_MainTex", "_BaseMap", "_BaseColorTexture", "baseColorTexture" }); + AddTextureExtTransforms("emissiveTexture", new[] { "_EmissionMap", "_EmissiveTexture", "emissiveTexture" } ); + AddTextureExtTransforms("normalTexture", new[] { "_BumpMap", "_NormalTexture", "normalTexture" }); + AddTextureExtTransforms("occlusionTexture", new[] { "_OcclusionMap", "_OcclusionTexture", "occlusionTexture" }); + AddTextureExtTransforms("pbrMetallicRoughness/metallicRoughnessTexture", new[] { "metallicRoughnessTexture", "_metallicRoughnessTexture", "_MetallicRoughnessTexture" }); - var clearcoatRoughnessTexture = new MaterialPointerPropertyMap(MaterialPointerPropertyMap.PropertyTypeOption.TextureTransform) - { - PropertyNames = new[] { "_clearcoatRoughnessTexture_ST", "clearcoatRoughnessTexture_ST", "ClearcoatRoughnessTexture_ST" }, - GltfPropertyName = - $"{nameof(KHR_materials_clearcoat.clearcoatRoughnessTexture)}/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.SCALE}", - GltfSecondaryPropertyName = - $"{nameof(KHR_materials_clearcoat.clearcoatRoughnessTexture)}/extensions/{ExtTextureTransformExtensionFactory.EXTENSION_NAME}/{ExtTextureTransformExtensionFactory.OFFSET}", - ExtensionName = ExtTextureTransformExtensionFactory.EXTENSION_NAME - }; - AddMap(clearcoatRoughnessTexture); + string clearCoatExt = "extensions/"+nameof(KHR_materials_clearcoat)+"/"; + AddTextureExtTransforms(clearCoatExt+ nameof(KHR_materials_clearcoat.clearcoatTexture), new[] { "_ClearcoatTexture", "clearcoatTexture", "ClearcoatTexture" }, nameof(KHR_materials_clearcoat)); + AddTextureExtTransforms(clearCoatExt+ nameof(KHR_materials_clearcoat.clearcoatRoughnessTexture), new[] { "_ClearcoatRoughnessTexture", "clearcoatRoughnessTexture", "ClearcoatRoughnessTexture" }, nameof(KHR_materials_clearcoat)); + AddTextureExtTransforms(clearCoatExt+ nameof(KHR_materials_clearcoat.clearcoatNormalTexture), new[] { "_ClearcoatNormalTexture_", "clearcoatNormalTexture", "ClearcoatNormalTexture" }, nameof(KHR_materials_clearcoat)); + AddTextureExtTransforms("extensions/"+nameof(KHR_materials_volume)+"/"+nameof(KHR_materials_volume.thicknessTexture), new[] {"thicknessTexture", "_thicknessTexture"}, nameof(KHR_materials_volume)); + AddTextureExtTransforms("extensions/"+nameof(KHR_materials_transmission)+"/"+nameof(KHR_materials_transmission.transmissionTexture), new[] {"transmissionTexture", "_transmissionTexture"}, nameof(KHR_materials_transmission)); + + AddTextureExtTransforms("extensions/"+nameof(KHR_materials_iridescence)+"/"+nameof(KHR_materials_iridescence.iridescenceTexture), new[] { "iridescenceTexture", "_iridescenceTexture"}, nameof(KHR_materials_iridescence)); + AddTextureExtTransforms("extensions/"+nameof(KHR_materials_iridescence)+"/"+nameof(KHR_materials_iridescence.iridescenceThicknessTexture), new[] { "iridescenceThicknessTexture", "_iridescenceThicknessTexture"}, nameof(KHR_materials_iridescence)); + + AddTextureExtTransforms("extensions/"+nameof(KHR_materials_specular)+"/"+nameof(KHR_materials_specular.specularTexture), new[] { "specularTexture", "_specularTexture"}, nameof(KHR_materials_specular)); + AddTextureExtTransforms("extensions/"+nameof(KHR_materials_specular)+"/"+nameof(KHR_materials_specular.specularColorTexture), new[] { "specularColorTexture", "_specularColorTexture"}, nameof(KHR_materials_specular)); + // TODO KHR_materials_sheen // case "_SheenColorFactor": diff --git a/Runtime/Scripts/SceneImporter/ImporterAnimation.cs b/Runtime/Scripts/SceneImporter/ImporterAnimation.cs index 960c9df6c..79029c28e 100644 --- a/Runtime/Scripts/SceneImporter/ImporterAnimation.cs +++ b/Runtime/Scripts/SceneImporter/ImporterAnimation.cs @@ -384,16 +384,26 @@ AttributeAccessor FindSecondaryChannel(string animationPointerPath) if (!mat.UnityMaterial) continue; - if (!AnimationPointerHelpers.BuildImportMaterialAnimationPointerData(pointerImportContext.materialPropertiesRemapper, mat.UnityMaterial, gltfPropertyPath, samplerCache.Output.AccessorId.Value.Type, out pointerData)) + if (!AnimationPointerHelpers.BuildImportMaterialAnimationPointerData(pointer.path, pointerImportContext.materialPropertiesRemapper, mat.UnityMaterial, gltfPropertyPath, samplerCache.Output, out pointerData)) continue; - - pointerData.primaryData = samplerCache.Output; - pointerData.primaryPath = pointer.path; - if (!string.IsNullOrEmpty(pointerData.secondaryPath)) + pointerData.targetNodeIds = nodeIds; + if (string.IsNullOrEmpty(pointerData.primaryPath)) + { + pointerData.primaryPath = "/" + pointerHierarchy.ExtractPath().Replace(rootIndex.next.ExtractPath(), pointerData.primaryProperty); + pointerData.primaryData = FindSecondaryChannel(pointerData.primaryPath); + if (pointerData.primaryData != null) + { + //cancel here and process this combined property later when we found first the Primary Property + continue; + } + } + else + if (!string.IsNullOrEmpty(pointerData.secondaryProperty)) { // When an property has potentially a second Sampler, we need to find it. e.g. like EmissionFactor and EmissionStrength - string secondaryPath = $"/{pointerHierarchy.elementName}/{rootIndex.index.ToString()}/{pointerData.secondaryPath}"; - pointerData.secondaryData = FindSecondaryChannel(secondaryPath); + + pointerData.secondaryPath = "/" + pointerHierarchy.ExtractPath().Replace(rootIndex.next.ExtractPath(), pointerData.secondaryProperty); + pointerData.secondaryData = FindSecondaryChannel(pointerData.secondaryPath); } break; case "cameras":