Skip to content

Commit

Permalink
Merge remote-tracking branch 'khronos/feature/more-texture-import-opt…
Browse files Browse the repository at this point in the history
…ions-and-ktx-mipmap-fix' into dev
  • Loading branch information
hybridherbst committed Jul 23, 2024
2 parents 8b7f30d + d64d755 commit 0b9d9b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Editor/Scripts/GLTFImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ private static void EnsureShadersAreLoaded()
[SerializeField] internal bool _animationLoopPose = false;
[SerializeField] internal bool _importMaterials = true;
[SerializeField] internal bool _enableGpuInstancing = false;
[SerializeField] internal bool _texturesReadWriteEnabled = true;
[SerializeField] internal bool _generateMipMaps = true;
[Tooltip("Enable this to get the same main asset identifiers as glTFast uses. This is recommended for new asset imports. Note that changing this for already imported assets will break their scene references and require manually re-adding the affected assets.")]
[SerializeField] internal bool _useSceneNameIdentifier = false;
[Tooltip("Compress textures after import using the platform default settings. If you need more control, use a .gltf file instead.")]
Expand Down Expand Up @@ -912,7 +914,7 @@ private void CreateGLTFScene(GLTFImportContext context, out GameObject scene,
ImportTangents = _importTangents,
ImportBlendShapeNames = _importBlendShapeNames,
BlendShapeFrameWeight = _blendShapeFrameWeight,
CameraImport = _importCamera
CameraImport = _importCamera,
};

using (var stream = File.OpenRead(projectFilePath))
Expand Down Expand Up @@ -940,6 +942,8 @@ private void CreateGLTFScene(GLTFImportContext context, out GameObject scene,

stream.Position = 0; // Make sure the read position is changed back to the beginning of the file
var loader = new GLTFSceneImporter(gltfRoot, stream, importOptions);
loader.KeepCPUCopyOfTexture = _texturesReadWriteEnabled;
loader.GenerateMipMapsForTextures = _generateMipMaps;
loader.LoadUnreferencedImagesAndMaterials = true;
loader.MaximumLod = _maximumLod;
loader.IsMultithreaded = true;
Expand Down
4 changes: 3 additions & 1 deletion Editor/Scripts/GLTFImporterInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ private void ModelInspectorGUI()
var importedTextures = serializedObject.FindProperty("m_Textures");
if (importedTextures.arraySize > 0)
{
EditorGUILayout.LabelField("Compression", EditorStyles.boldLabel);
EditorGUILayout.LabelField("Textures", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(GLTFImporter._texturesReadWriteEnabled)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(GLTFImporter._generateMipMaps)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(GLTFImporter._textureCompression)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/SceneImporter/ImporterTextures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async Task<Texture2D> CheckMimeTypeAndLoadImage(GLTFImage image, Texture2D textu
#endif
var ktxTexture = new KtxUnity.KtxTexture();

var resultTextureData = await ktxTexture.LoadFromBytes(data, isLinear);
var resultTextureData = await ktxTexture.LoadFromBytes(data, isLinear, mipChain: GenerateMipMapsForTextures);
texture = resultTextureData.texture;
texture.name = textureName;
}
Expand Down

0 comments on commit 0b9d9b5

Please sign in to comment.