Skip to content

Commit

Permalink
cache active colorspace because it can only be read from the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
pfcDorn committed Jan 10, 2024
1 parent caa3f4c commit 216c03d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Runtime/Scripts/GLTFSceneImporter.cs
Expand Up @@ -272,6 +272,8 @@ public GameObject LastLoadedScene

private static ILogger Debug = UnityEngine.Debug.unityLogger;

protected ColorSpace _activeColorSpace;

public GLTFSceneImporter(string gltfFileName, ImportOptions options)
{
if (options.ImportContext != null)
Expand All @@ -282,6 +284,8 @@ public GLTFSceneImporter(string gltfFileName, ImportOptions options)
_gltfFileName = gltfFileName;
_options = options;

_activeColorSpace = QualitySettings.activeColorSpace;

if (options.logger != null)
Debug = options.logger;
else
Expand All @@ -297,6 +301,8 @@ public GLTFSceneImporter(GLTFRoot rootNode, Stream gltfStream, ImportOptions opt
options.ImportContext.SceneImporter = this;
}

_activeColorSpace = QualitySettings.activeColorSpace;

_gltfRoot = rootNode;

if (gltfStream != null)
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/SceneImporter/ImporterMeshes.cs
Expand Up @@ -840,7 +840,7 @@ protected virtual async Task ConstructPrimitiveAttributes(MeshPrimitive primitiv
}
if (meshAttributes.TryGetValue(SemanticProperties.Color[0], out var attrColor))
{
if (QualitySettings.activeColorSpace == ColorSpace.Gamma)
if (_activeColorSpace == ColorSpace.Gamma)
attrColor.AccessorContent.AsColors.ToUnityColorRaw(unityData.Colors, (int)vertOffset);
else
attrColor.AccessorContent.AsColors.ToUnityColorLinear(unityData.Colors, (int)vertOffset);
Expand Down

0 comments on commit 216c03d

Please sign in to comment.