Skip to content

Commit

Permalink
fixes for color import
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Mar 15, 2021
1 parent de4991a commit 1cc8768
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,14 @@ public static void ToUnityVector4Raw(this GLTF.Math.Vector4[] inArr, Vector4[] o

public static UnityEngine.Color ToUnityColorRaw(this GLTF.Math.Color color)
{
return new UnityEngine.Color(color.R, color.G, color.B, color.A).gamma;
var c = new UnityEngine.Color(color.R, color.G, color.B, color.A).gamma;
return c;
}

public static UnityEngine.Color ToUnityColorLinear(this GLTF.Math.Color color)
{
var c = new UnityEngine.Color(color.R, color.G, color.B, color.A);
return c;
}

public static GLTF.Math.Color ToNumericsColorRaw(this UnityEngine.Color color)
Expand Down Expand Up @@ -375,6 +382,14 @@ public static void ToUnityColorRaw(this GLTF.Math.Color[] inArr, Color[] outArr,
}
}

public static void ToUnityColorLinear(this GLTF.Math.Color[] inArr, Color[] outArr, int offset = 0)
{
for (int i = 0; i < inArr.Length; i++)
{
outArr[offset + i] = inArr[i].ToUnityColorLinear();
}
}

public static int[] ToIntArrayRaw(this uint[] uintArr)
{
int[] intArr = new int[uintArr.Length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ protected virtual async Task ConstructMesh(GLTFMesh mesh, int meshIndex, Cancell
}
if (meshAttributes.ContainsKey(SemanticProperties.Color[0]))
{
meshAttributes[SemanticProperties.Color[0]].AccessorContent.AsColors.ToUnityColorRaw(unityData.Colors, vertOffset);
meshAttributes[SemanticProperties.Color[0]].AccessorContent.AsColors.ToUnityColorLinear(unityData.Colors, vertOffset);
}

var targets = primData.Targets;
Expand Down Expand Up @@ -2077,7 +2077,7 @@ protected virtual async Task ConstructMaterial(GLTFMaterial def, int materialInd
if (unlitMapper != null)
{
var pbr = def.PbrMetallicRoughness;
unlitMapper.BaseColorFactor = pbr.BaseColorFactor.ToUnityColorRaw().gamma;
unlitMapper.BaseColorFactor = pbr.BaseColorFactor.ToUnityColorRaw();

if (pbr.BaseColorTexture != null)
{
Expand Down

0 comments on commit 1cc8768

Please sign in to comment.