Skip to content

Commit

Permalink
changed ExtTextureTransform.texCoord to nullable type. In some cases …
Browse files Browse the repository at this point in the history
…the texCoord is set in texture info and not in ExtTextureTransform
  • Loading branch information
pfcDorn committed Aug 8, 2023
1 parent afaa6ce commit 510b8a3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class ExtTextureTransformExtension : IExtension
/// <summary>
/// Overrides the textureInfo texCoord value if this extension is supported.
/// </summary>
public int TexCoord = 0;
public Nullable<int> TexCoord = null;
public static readonly int TEXCOORD_DEFAULT = 0;

public ExtTextureTransformExtension(Vector2 offset, double rotation, Vector2 scale, int texCoord)
public ExtTextureTransformExtension(Vector2 offset, double rotation, Vector2 scale, Nullable<int> texCoord)
{
Offset = offset;
Rotation = rotation;
Expand Down Expand Up @@ -74,7 +74,7 @@ public JProperty Serialize()
));
}

if (TexCoord != TEXCOORD_DEFAULT)
if (TexCoord != null)
{
ext.Add(new JProperty(
ExtTextureTransformExtensionFactory.TEXCOORD,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using System;
using Newtonsoft.Json.Linq;
using GLTF.Extensions;
using GLTF.Math;

Expand All @@ -22,7 +23,7 @@ public override IExtension Deserialize(GLTFRoot root, JProperty extensionToken)
Vector2 offset = new Vector2(ExtTextureTransformExtension.OFFSET_DEFAULT);
double rotation = 0;
Vector2 scale = new Vector2(ExtTextureTransformExtension.SCALE_DEFAULT);
int texCoord = ExtTextureTransformExtension.TEXCOORD_DEFAULT;
Nullable<int> texCoord = null;

if (extensionToken != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected virtual async Task ConstructMaterial(GLTFMaterial def, int materialInd

void CalculateYOffsetAndScale(TextureId textureId, ExtTextureTransformExtension ext, out Vector2 scale, out Vector2 offset)
{
offset = ext.Offset.ToUnityVector2Raw();
offset = ext.Offset.ToUnityVector2Raw();
scale = ext.Scale.ToUnityVector2Raw();

if (IsTextureFlipped(textureId.Value))
Expand Down Expand Up @@ -118,7 +118,7 @@ void SetTransformKeyword()
mrMapper.BaseColorXOffset = offset;
mrMapper.BaseColorXRotation = ext.Rotation;
mrMapper.BaseColorXScale = scale;
mrMapper.BaseColorXTexCoord = ext.TexCoord;
if (ext.TexCoord != null) mrMapper.BaseColorXTexCoord = ext.TexCoord.Value;

SetTransformKeyword();
}
Expand Down Expand Up @@ -147,7 +147,7 @@ void SetTransformKeyword()
mrMapper.MetallicRoughnessXOffset = offset;
mrMapper.MetallicRoughnessXRotation = ext.Rotation;
mrMapper.MetallicRoughnessXScale = scale;
mrMapper.MetallicRoughnessXTexCoord = ext.TexCoord;
if (ext.TexCoord != null) mrMapper.MetallicRoughnessXTexCoord = ext.TexCoord.Value;
SetTransformKeyword();
}
else
Expand Down Expand Up @@ -186,7 +186,7 @@ void SetTransformKeyword()
sgMapper.DiffuseXOffset = offset;
sgMapper.DiffuseXRotation = ext.Rotation;
sgMapper.DiffuseXScale = scale;
sgMapper.DiffuseXTexCoord = ext.TexCoord;
if (ext.TexCoord != null) sgMapper.DiffuseXTexCoord = ext.TexCoord.Value;
MatHelper.SetKeyword(mapper.Material, "_TEXTURE_TRANSFORM", true);
SetTransformKeyword();
}
Expand Down Expand Up @@ -215,7 +215,7 @@ void SetTransformKeyword()
sgMapper.SpecularGlossinessXOffset = offset;
sgMapper.SpecularGlossinessXRotation = ext.Rotation;
sgMapper.SpecularGlossinessXScale = scale;
sgMapper.SpecularGlossinessXTexCoord = ext.TexCoord;
if (ext.TexCoord != null) sgMapper.SpecularGlossinessXTexCoord = ext.TexCoord.Value;
SetTransformKeyword();
}
else
Expand Down Expand Up @@ -247,7 +247,7 @@ void SetTransformKeyword()
unlitMapper.BaseColorXOffset = offset;
unlitMapper.BaseColorXRotation = ext.Rotation;
unlitMapper.BaseColorXScale = scale;
unlitMapper.BaseColorXTexCoord = ext.TexCoord;
if (ext.TexCoord != null) unlitMapper.BaseColorXTexCoord = ext.TexCoord.Value;
SetTransformKeyword();
}
else
Expand Down Expand Up @@ -289,7 +289,7 @@ void SetTransformKeyword()
transmissionMapper.TransmissionTextureOffset = offset;
transmissionMapper.TransmissionTextureScale = scale;
transmissionMapper.TransmissionTextureRotation = td.Rotation;
transmissionMapper.TransmissionTextureTexCoord = td.TexCoordExtra;
if (td.TexCoordExtra != null) transmissionMapper.TransmissionTextureTexCoord = td.TexCoordExtra.Value;
SetTransformKeyword();
}
else
Expand Down Expand Up @@ -327,7 +327,7 @@ void SetTransformKeyword()
volumeMapper.ThicknessTextureOffset = offset;
volumeMapper.ThicknessTextureScale = scale;
volumeMapper.ThicknessTextureRotation = td.Rotation;
volumeMapper.ThicknessTextureTexCoord = td.TexCoordExtra;
if (td.TexCoordExtra != null) volumeMapper.ThicknessTextureTexCoord = td.TexCoordExtra.Value;
SetTransformKeyword();
}
else
Expand Down Expand Up @@ -365,7 +365,7 @@ void SetTransformKeyword()
iridescenceMapper.IridescenceTextureOffset = offset;
iridescenceMapper.IridescenceTextureScale = scale;
iridescenceMapper.IridescenceTextureRotation = td.Rotation;
iridescenceMapper.IridescenceTextureTexCoord = td.TexCoordExtra;
if (td.TexCoordExtra != null) iridescenceMapper.IridescenceTextureTexCoord = td.TexCoordExtra.Value;
SetTransformKeyword();
}
else
Expand All @@ -389,7 +389,7 @@ void SetTransformKeyword()
iridescenceMapper.IridescenceThicknessTextureOffset = offset;
iridescenceMapper.IridescenceThicknessTextureScale = scale;
iridescenceMapper.IridescenceThicknessTextureRotation = td2.Rotation;
iridescenceMapper.IridescenceThicknessTextureTexCoord = td2.TexCoordExtra;
if (td2.TexCoordExtra != null) iridescenceMapper.IridescenceThicknessTextureTexCoord = td2.TexCoordExtra.Value;
SetTransformKeyword();
}
else
Expand Down Expand Up @@ -425,7 +425,7 @@ void SetTransformKeyword()
specularMapper.SpecularTextureOffset = offset;
specularMapper.SpecularTextureScale = scale;
specularMapper.SpecularTextureRotation = td.Rotation;
specularMapper.SpecularTextureTexCoord = td.TexCoordExtra;
if (td.TexCoordExtra != null) specularMapper.SpecularTextureTexCoord = td.TexCoordExtra.Value;
SetTransformKeyword();
}
else
Expand All @@ -449,7 +449,7 @@ void SetTransformKeyword()
specularMapper.SpecularColorTextureOffset = offset;
specularMapper.SpecularColorTextureScale = scale;
specularMapper.SpecularColorTextureRotation = td2.Rotation;
specularMapper.SpecularColorTextureTexCoord = td2.TexCoordExtra;
if (td2.TexCoordExtra != null) specularMapper.SpecularColorTextureTexCoord = td2.TexCoordExtra.Value;
SetTransformKeyword();
}
else
Expand Down Expand Up @@ -485,7 +485,7 @@ void SetTransformKeyword()
clearcoatMapper.ClearcoatTextureOffset = offset;
clearcoatMapper.ClearcoatTextureScale = scale;
clearcoatMapper.ClearcoatTextureRotation = td.Rotation;
clearcoatMapper.ClearcoatTextureTexCoord = td.TexCoordExtra;
if (td.TexCoordExtra != null) clearcoatMapper.ClearcoatTextureTexCoord = td.TexCoordExtra.Value;
SetTransformKeyword();
}
else
Expand Down Expand Up @@ -530,7 +530,7 @@ void SetTransformKeyword()
uniformMapper.NormalXOffset = offset;
uniformMapper.NormalXRotation = ext.Rotation;
uniformMapper.NormalXScale = scale;
uniformMapper.NormalXTexCoord = ext.TexCoord;
if (ext.TexCoord != null) uniformMapper.NormalXTexCoord = ext.TexCoord.Value;
SetTransformKeyword();
}
else
Expand All @@ -555,7 +555,7 @@ void SetTransformKeyword()
uniformMapper.EmissiveXOffset = offset;
uniformMapper.EmissiveXRotation = ext.Rotation;
uniformMapper.EmissiveXScale = scale;
uniformMapper.EmissiveXTexCoord = ext.TexCoord;
if (ext.TexCoord != null) uniformMapper.EmissiveXTexCoord = ext.TexCoord.Value;
SetTransformKeyword();
}
else
Expand All @@ -582,7 +582,7 @@ void SetTransformKeyword()
uniformMapper.OcclusionXOffset = offset;
uniformMapper.OcclusionXRotation = ext.Rotation;
uniformMapper.OcclusionXScale = scale;
uniformMapper.OcclusionXTexCoord = ext.TexCoord;
if (ext.TexCoord != null) uniformMapper.OcclusionXTexCoord = ext.TexCoord.Value;
SetTransformKeyword();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private class TextureData
public Vector2 Offset = Vector2.zero;
public double Rotation = 0;
public Vector2 Scale = Vector2.one;
public int TexCoordExtra = 0;
public Nullable<int> TexCoordExtra = 0;
}

private async Task<TextureData> FromTextureInfo(TextureInfo textureInfo)
Expand Down

0 comments on commit 510b8a3

Please sign in to comment.