From 378f17f05652ed86897be85dd26b161b77344e35 Mon Sep 17 00:00:00 2001 From: Robert Dorn Date: Thu, 11 Jul 2024 13:54:24 +0200 Subject: [PATCH 1/2] exposed texture readwrite enabled and generate mipmaps option to importer --- Editor/Scripts/GLTFImporter.cs | 6 +++++- Editor/Scripts/GLTFImporterInspector.cs | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Editor/Scripts/GLTFImporter.cs b/Editor/Scripts/GLTFImporter.cs index ba92c260e..080872f31 100644 --- a/Editor/Scripts/GLTFImporter.cs +++ b/Editor/Scripts/GLTFImporter.cs @@ -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.")] @@ -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)) @@ -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; diff --git a/Editor/Scripts/GLTFImporterInspector.cs b/Editor/Scripts/GLTFImporterInspector.cs index 173b36fd2..34544ed22 100644 --- a/Editor/Scripts/GLTFImporterInspector.cs +++ b/Editor/Scripts/GLTFImporterInspector.cs @@ -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))); } } From d64d755de633c0777bf99d36eb7952e7189bd2a5 Mon Sep 17 00:00:00 2001 From: Robert Dorn Date: Thu, 11 Jul 2024 13:58:05 +0200 Subject: [PATCH 2/2] fixes #752 - added missing generate mitmaps to ktx texture load --- Runtime/Scripts/SceneImporter/ImporterTextures.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Scripts/SceneImporter/ImporterTextures.cs b/Runtime/Scripts/SceneImporter/ImporterTextures.cs index b5f0e2e86..104601fb2 100644 --- a/Runtime/Scripts/SceneImporter/ImporterTextures.cs +++ b/Runtime/Scripts/SceneImporter/ImporterTextures.cs @@ -164,7 +164,7 @@ async Task 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; }