Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More texture import options and missing ktx mipmap parameter #756

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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