From 01e038d7ff4f7de5a31a69fb2e6463a506e9f204 Mon Sep 17 00:00:00 2001 From: Nick Constantinidis Date: Thu, 18 Jan 2024 11:29:37 -0500 Subject: [PATCH 1/7] Post Release 6.1.0 (#84) --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b49fe5db..d05ac0e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + ## [6.1.0] - 2024-01-17 ### Added From 1ebd5c29bdd2507fde1f0ca678b28d8d5b984753 Mon Sep 17 00:00:00 2001 From: Andreas Atteneder Date: Wed, 24 Jan 2024 16:56:56 +0100 Subject: [PATCH 2/7] fix: Compiler error when Newtonsoft JSON package was not installed. (#86) --- CHANGELOG.md | 3 +++ Samples/Documentation/Manual/CustomGltfImport.cs | 7 ++++--- .../Unity.Cloud.Gltfast.Documentation.asmdef | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d05ac0e4..b947ffc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Compiler error when Newtonsoft JSON package was not installed. + ## [6.1.0] - 2024-01-17 ### Added diff --git a/Samples/Documentation/Manual/CustomGltfImport.cs b/Samples/Documentation/Manual/CustomGltfImport.cs index ea617af1..5ce6da08 100644 --- a/Samples/Documentation/Manual/CustomGltfImport.cs +++ b/Samples/Documentation/Manual/CustomGltfImport.cs @@ -1,7 +1,7 @@ +#if NEWTONSOFT_JSON namespace Samples.Documentation.Manual { - - #region CustomGltfImport +#region CustomGltfImport using GLTFast; using GLTFast.Addons; using System; @@ -96,6 +96,7 @@ void OnNodeCreated(uint nodeIndex, GameObject gameObject) } } } - #endregion +#endregion } +#endif diff --git a/Samples/Documentation/Unity.Cloud.Gltfast.Documentation.asmdef b/Samples/Documentation/Unity.Cloud.Gltfast.Documentation.asmdef index 1b779752..378bf6cb 100644 --- a/Samples/Documentation/Unity.Cloud.Gltfast.Documentation.asmdef +++ b/Samples/Documentation/Unity.Cloud.Gltfast.Documentation.asmdef @@ -12,6 +12,12 @@ "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], - "versionDefines": [], + "versionDefines": [ + { + "name": "com.unity.nuget.newtonsoft-json", + "expression": "3", + "define": "NEWTONSOFT_JSON" + } + ], "noEngineReferences": false } \ No newline at end of file From faeb35f2762a98e5f9e06413967543df288a83ff Mon Sep 17 00:00:00 2001 From: Andreas Atteneder Date: Thu, 25 Jan 2024 14:30:27 +0100 Subject: [PATCH 3/7] Feature/draco for unity (#82) * chore: Support for Draco 3D Data Compression is now provided by *Draco for Unity* (com.unity.cloud.draco), which is a fork of and replaces *DracoUnity* (com.atteneder.draco). (#77) * doc: Updated documentation regarding switching to Draco for Unity. note: The links are projected and not life yet. * fix: Mention correct package in log messages * fix: Updated Draco for Unity API * chore: Draco for Unity API update * refactor: Updated Draco for Unity API --- CHANGELOG.md | 5 ++ Documentation~/ExportRuntime.md | 4 +- Documentation~/UpgradeGuides.md | 2 +- Documentation~/features.md | 4 +- Documentation~/installation.md | 4 +- Runtime/Scripts/Export/DracoExportSettings.cs | 18 +++++ Runtime/Scripts/Export/GltfWriter.cs | 12 ++-- Runtime/Scripts/Export/glTFast.Export.asmdef | 4 +- Runtime/Scripts/GltfImport.cs | 5 +- .../Scripts/PrimitiveDracoCreateContext.cs | 65 +++++++++++++++---- Runtime/Scripts/glTFast.asmdef | 6 +- 11 files changed, 95 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b947ffc9..3f4c796f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- Support for Draco 3D Data Compression is now provided by [*Draco for Unity* (com.unity.cloud.draco)][DracoForUnity], which is a fork of and replaces [*DracoUnity* (com.atteneder.draco)][DracoUnity]. + ### Fixed - Compiler error when Newtonsoft JSON package was not installed. +- All Draco vertex attributes are assigned by identifier instead of type. As a result, tangents are now decoded properly instead of recalculated. ## [6.1.0] - 2024-01-17 @@ -1067,6 +1071,7 @@ This release contains multiple breaking changes. Please read the [upgrade guide] [Entities1.0]: https://docs.unity3d.com/Packages/com.unity.entities@1.0 [KtxUnity]: https://github.com/atteneder/KtxUnity [DanDovi]: https://github.com/DanDovi +[DracoForUnity]: https://docs.unity3d.com/Packages/com.unity.cloud.draco@latest [DracoUnity]: https://github.com/atteneder/DracoUnity [aurorahcx]: https://github.com/aurorahcx [Battlehub0x]: https://github.com/Battlehub0x diff --git a/Documentation~/ExportRuntime.md b/Documentation~/ExportRuntime.md index f767f208..057b582e 100644 --- a/Documentation~/ExportRuntime.md +++ b/Documentation~/ExportRuntime.md @@ -122,7 +122,7 @@ public class TestExport : MonoBehaviour { ### Draco Compression -*Unity glTFast* supports applying [Google Draco™ 3D Data compression][Draco] to meshes. This requires the [DracoUnity][DracoUnity] package to be installed. +*Unity glTFast* supports applying [Google Draco™ 3D Data compression][Draco] to meshes. This requires the [Draco for Unity][DracoForUnity] package to be installed. ```csharp // ExportSettings provides generic export settings @@ -147,7 +147,7 @@ var exportSettings = new ExportSettings { [asmdef]: https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html [Draco]: https://google.github.io/draco/ -[DracoUnity]: https://github.com/atteneder/DracoUnity +[DracoForUnity]: https://docs.unity3d.com/Packages/com.unity.cloud.draco@latest [GoogleLLC]: https://about.google/ [khronos]: https://www.khronos.org [unity]: https://unity.com diff --git a/Documentation~/UpgradeGuides.md b/Documentation~/UpgradeGuides.md index 27a18ce9..96b98c0e 100644 --- a/Documentation~/UpgradeGuides.md +++ b/Documentation~/UpgradeGuides.md @@ -31,7 +31,7 @@ Unity forks have been created for *KtxUnity* and *DracoUnity* as well. If you've See their respective upgrade guides - Upgrade to [*KTX for Unity*](https://docs.unity3d.com/Packages/com.unity.cloud.ktx@3.2/manual/upgrade-guide.html) -- Upgrade to *Draco for Unity* (coming soon) +- Upgrade to [*Draco for Unity*](https://docs.unity3d.com/Packages/com.unity.cloud.draco@5.0/manual/upgrade-guide.html) ### Keep using the original glTFast diff --git a/Documentation~/features.md b/Documentation~/features.md index b6e27e05..250d2e07 100644 --- a/Documentation~/features.md +++ b/Documentation~/features.md @@ -67,7 +67,7 @@ The glTF 2.0 specification is fully supported, with only a few minor remarks. | Texture coordinates / UV sets | ✅ | `?` | Three or more texture coordinates / UV sets | 2☑️ | `?` | Vertex colors | ✅ | `?` -| Draco™ mesh compression (via [DracoUnity]) | ✅ | ✅ +| Draco™ mesh compression (via [DracoForUnity]) | ✅ | ✅ | Implicit (no) indices | ✅ | | Per primitive material | ✅ | ✅ | Joints (up to 4 per vertex) | ✅ | @@ -268,7 +268,7 @@ Possibly incomplete list of things that are known to not work with Entities yet: [AnimationMecanim]: https://github.com/atteneder/glTFast/issues/167 [AnimationPlayables]: https://github.com/atteneder/glTFast/issues/166 [ClearCoat]: https://github.com/atteneder/glTFast/issues/68 -[DracoUnity]: https://github.com/atteneder/DracoUnity +[DracoForUnity]: https://docs.unity3d.com/Packages/com.unity.cloud.draco@latest [DOTS]: https://unity.com/dots [Entities]: https://docs.unity3d.com/Packages/com.unity.entities@latest [EntitiesGraphics]: https://docs.unity3d.com/Packages/com.unity.entities.graphics@latest diff --git a/Documentation~/installation.md b/Documentation~/installation.md index b4f486fc..7a5528ec 100644 --- a/Documentation~/installation.md +++ b/Documentation~/installation.md @@ -15,7 +15,7 @@ To install the *Unity glTFast* package, follow these steps: There are some related package that improve *Unity glTFast* by extending its feature set. -- [Draco™ 3D Data Compression Unity Package][DracoUnity] (provides support for [KHR_draco_mesh_compression][ExtDraco]) +- [Draco™ for Unity][DracoForUnity] (provides support for [KHR_draco_mesh_compression][ExtDraco]) - [KTX™ for Unity][KtxUnity] (provides support for [KHR_texture_basisu][ExtBasisU]) - [*meshoptimizer decompression for Unity*][Meshopt] (provides support for [EXT_meshopt_compression][ExtMeshopt]) @@ -29,7 +29,7 @@ There are some related package that improve *Unity glTFast* by extending its fea *Draco™* is a trademark of [*Google LLC*][GoogleLLC]. -[DracoUnity]: https://github.com/atteneder/DracoUnity +[DracoForUnity]: https://docs.unity3d.com/Packages/com.unity.cloud.draco@latest [ExtBasisU]: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu [ExtDraco]: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression [ExtMeshopt]: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_meshopt_compression diff --git a/Runtime/Scripts/Export/DracoExportSettings.cs b/Runtime/Scripts/Export/DracoExportSettings.cs index 7cc2e1dd..1d5c5b76 100644 --- a/Runtime/Scripts/Export/DracoExportSettings.cs +++ b/Runtime/Scripts/Export/DracoExportSettings.cs @@ -1,6 +1,10 @@ // SPDX-FileCopyrightText: 2023 Unity Technologies and the glTFast authors // SPDX-License-Identifier: Apache-2.0 +#if DRACO_UNITY +using Draco.Encode; +#endif + namespace GLTFast.Export { /// @@ -28,5 +32,19 @@ public class DracoExportSettings /// Color quantization. public int colorQuantization = 8; + +#if DRACO_UNITY + public static implicit operator QuantizationSettings(DracoExportSettings s) => new QuantizationSettings( + s.positionQuantization, + s.normalQuantization, + s.texCoordQuantization, + s.colorQuantization + ); + + public static implicit operator SpeedSettings(DracoExportSettings s) => new SpeedSettings( + s.encodingSpeed, + s.decodingSpeed + ); +#endif } } diff --git a/Runtime/Scripts/Export/GltfWriter.cs b/Runtime/Scripts/Export/GltfWriter.cs index 77c741e7..32944ad1 100644 --- a/Runtime/Scripts/Export/GltfWriter.cs +++ b/Runtime/Scripts/Export/GltfWriter.cs @@ -14,7 +14,7 @@ using System.Threading.Tasks; #if DRACO_UNITY -using Draco.Encoder; +using Draco.Encode; #endif using GLTFast.Schema; using Unity.Collections; @@ -926,7 +926,7 @@ async Task BakeMeshes() { m_Logger.Warning(LogCode.UncompressedFallbackNotSupported); } #else - m_Logger?.Error(LogCode.PackageMissing, "DracoUnity", ExtensionName.DracoMeshCompression); + m_Logger?.Error(LogCode.PackageMissing, "Draco For Unity", ExtensionName.DracoMeshCompression); return false; #endif } @@ -1296,12 +1296,8 @@ async Task BakeMeshDraco(int meshId, UnityEngine.Mesh.MeshData meshData) var results = await DracoEncoder.EncodeMesh( unityMesh, meshData, - m_Settings.DracoSettings.encodingSpeed, - m_Settings.DracoSettings.decodingSpeed, - m_Settings.DracoSettings.positionQuantization, - m_Settings.DracoSettings.normalQuantization, - m_Settings.DracoSettings.texCoordQuantization, - m_Settings.DracoSettings.colorQuantization + (QuantizationSettings) m_Settings.DracoSettings, + (SpeedSettings) m_Settings.DracoSettings ); if (results == null) return; diff --git a/Runtime/Scripts/Export/glTFast.Export.asmdef b/Runtime/Scripts/Export/glTFast.Export.asmdef index f779a6c7..71eb66bd 100644 --- a/Runtime/Scripts/Export/glTFast.Export.asmdef +++ b/Runtime/Scripts/Export/glTFast.Export.asmdef @@ -7,7 +7,7 @@ "Unity.Burst", "Unity.RenderPipelines.Universal.Runtime", "Unity.RenderPipelines.HighDefinition.Runtime", - "DracoEncoder" + "Draco.Encode" ], "includePlatforms": [], "excludePlatforms": [], @@ -33,7 +33,7 @@ "define": "UNITY_IMAGECONVERSION" }, { - "name": "com.atteneder.draco", + "name": "com.unity.cloud.draco", "expression": "5.0.0-pre.1", "define": "DRACO_UNITY" } diff --git a/Runtime/Scripts/GltfImport.cs b/Runtime/Scripts/GltfImport.cs index 85117473..0d2377af 100644 --- a/Runtime/Scripts/GltfImport.cs +++ b/Runtime/Scripts/GltfImport.cs @@ -44,7 +44,6 @@ using UnityEngine.Experimental.Rendering; using UnityEngine.Profiling; using UnityEngine; - using Debug = UnityEngine.Debug; [assembly: InternalsVisibleTo("glTFast.Editor")] @@ -1154,7 +1153,7 @@ bool CheckExtensionSupport(IEnumerable extensions, bool required = true) #if !DRACO_UNITY if (ext == ExtensionName.DracoMeshCompression) { - m_Logger?.Error(LogCode.PackageMissing, "DracoUnity", ext); + m_Logger?.Error(LogCode.PackageMissing, "Draco for Unity", ext); } #endif @@ -3473,7 +3472,7 @@ void PreparePrimitiveDraco( RootBase gltf, MeshPrimitiveBase primitive, ref Prim var bufferView = gltf.BufferViews[dracoExt.bufferView]; var buffer = GetBufferViewSlice(bufferView); - c.StartDecode(buffer, dracoExt.attributes.WEIGHTS_0, dracoExt.attributes.JOINTS_0); + c.StartDecode(buffer, dracoExt.attributes); } #endif diff --git a/Runtime/Scripts/PrimitiveDracoCreateContext.cs b/Runtime/Scripts/PrimitiveDracoCreateContext.cs index 35d20209..98850826 100644 --- a/Runtime/Scripts/PrimitiveDracoCreateContext.cs +++ b/Runtime/Scripts/PrimitiveDracoCreateContext.cs @@ -4,17 +4,19 @@ #if DRACO_UNITY using System; +using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; using Unity.Collections; using Draco; +using GLTFast.Schema; using UnityEngine.Rendering; +using Mesh = UnityEngine.Mesh; namespace GLTFast { class PrimitiveDracoCreateContext : PrimitiveCreateContextBase { - DracoMeshLoader m_Draco; Task m_DracoTask; Bounds? m_Bounds; @@ -39,16 +41,23 @@ public PrimitiveDracoCreateContext( m_Bounds = bounds; } - public void StartDecode(NativeSlice data, int weightsAttributeId, int jointsAttributeId) { - m_Draco = new DracoMeshLoader(); - m_DracoTask = m_Draco.ConvertDracoMeshToUnity( - data, - m_NeedsNormals, - m_NeedsTangents, - weightsAttributeId, - jointsAttributeId, - morphTargetsContext!=null - ); + public void StartDecode(NativeSlice data, Attributes dracoAttributes) + { + var flags = DecodeSettings.ConvertSpace; + if (m_NeedsTangents) + { + flags |= DecodeSettings.RequireNormalsAndTangents; + } else + if (m_NeedsNormals) + { + flags |= DecodeSettings.RequireNormals; + } + if (morphTargetsContext != null) + { + flags |= DecodeSettings.ForceUnityVertexLayout; + } + + m_DracoTask = DracoDecoder.DecodeMesh(data, flags, GenerateAttributeIdMap(dracoAttributes)); } public override async Task CreatePrimitive() { @@ -102,6 +111,40 @@ public void StartDecode(NativeSlice data, int weightsAttributeId, int join mesh ); } + + static Dictionary GenerateAttributeIdMap(Attributes attributes) + { + var result = new Dictionary(); + if (attributes.POSITION >= 0) + result[VertexAttribute.Position] = attributes.POSITION; + if (attributes.NORMAL >= 0) + result[VertexAttribute.Normal] = attributes.NORMAL; + if (attributes.TANGENT >= 0) + result[VertexAttribute.Normal] = attributes.TANGENT; + if (attributes.COLOR_0 >= 0) + result[VertexAttribute.Color] = attributes.COLOR_0; + if (attributes.TEXCOORD_0 >= 0) + result[VertexAttribute.TexCoord0] = attributes.TEXCOORD_0; + if (attributes.TEXCOORD_1 >= 0) + result[VertexAttribute.TexCoord1] = attributes.TEXCOORD_1; + if (attributes.TEXCOORD_2 >= 0) + result[VertexAttribute.TexCoord2] = attributes.TEXCOORD_2; + if (attributes.TEXCOORD_3 >= 0) + result[VertexAttribute.TexCoord3] = attributes.TEXCOORD_3; + if (attributes.TEXCOORD_4 >= 0) + result[VertexAttribute.TexCoord4] = attributes.TEXCOORD_4; + if (attributes.TEXCOORD_5 >= 0) + result[VertexAttribute.TexCoord5] = attributes.TEXCOORD_5; + if (attributes.TEXCOORD_6 >= 0) + result[VertexAttribute.TexCoord6] = attributes.TEXCOORD_6; + if (attributes.TEXCOORD_7 >= 0) + result[VertexAttribute.TexCoord7] = attributes.TEXCOORD_7; + if (attributes.WEIGHTS_0 >= 0) + result[VertexAttribute.BlendWeight] = attributes.WEIGHTS_0; + if (attributes.JOINTS_0 >= 0) + result[VertexAttribute.BlendIndices] = attributes.JOINTS_0; + return result; + } } } #endif // DRACO_UNITY diff --git a/Runtime/Scripts/glTFast.asmdef b/Runtime/Scripts/glTFast.asmdef index 565dddda..ef0b734f 100644 --- a/Runtime/Scripts/glTFast.asmdef +++ b/Runtime/Scripts/glTFast.asmdef @@ -21,8 +21,8 @@ "defineConstraints": [], "versionDefines": [ { - "name": "com.atteneder.draco", - "expression": "3.1.0", + "name": "com.unity.cloud.draco", + "expression": "5.0.0-pre.1", "define": "DRACO_UNITY" }, { @@ -102,4 +102,4 @@ } ], "noEngineReferences": false -} +} \ No newline at end of file From a3b22e3bde2f8d137dddcf9f6bacbb32fd8982e1 Mon Sep 17 00:00:00 2001 From: Andreas Atteneder Date: Thu, 25 Jan 2024 17:57:13 +0100 Subject: [PATCH 4/7] fix: Compilation error when scripting define `GLTFAST_BUILTIN_SHADER_GRAPH` is set. (#88) --- CHANGELOG.md | 1 + .../Scripts/Material/BuiltInShaderGraphMaterialGenerator.cs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f4c796f..f2436635 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Compiler error when Newtonsoft JSON package was not installed. - All Draco vertex attributes are assigned by identifier instead of type. As a result, tangents are now decoded properly instead of recalculated. +- Compilation error when scripting define `GLTFAST_BUILTIN_SHADER_GRAPH` is set. ## [6.1.0] - 2024-01-17 diff --git a/Runtime/Scripts/Material/BuiltInShaderGraphMaterialGenerator.cs b/Runtime/Scripts/Material/BuiltInShaderGraphMaterialGenerator.cs index 81f8b7cc..feb1e43d 100644 --- a/Runtime/Scripts/Material/BuiltInShaderGraphMaterialGenerator.cs +++ b/Runtime/Scripts/Material/BuiltInShaderGraphMaterialGenerator.cs @@ -3,8 +3,10 @@ #if UNITY_SHADER_GRAPH_12_OR_NEWER && GLTFAST_BUILTIN_SHADER_GRAPH +using GLTFast.Schema; using UnityEngine; using UnityEngine.Rendering; +using Material = UnityEngine.Material; namespace GLTFast.Materials { public class BuiltInShaderGraphMaterialGenerator : ShaderGraphMaterialGenerator { @@ -17,12 +19,12 @@ public class BuiltInShaderGraphMaterialGenerator : ShaderGraphMaterialGenerator static readonly int k_SurfacePropId = Shader.PropertyToID("_BUILTIN_Surface"); static readonly int k_ZWritePropId = Shader.PropertyToID("_BUILTIN_ZWrite"); - protected override void SetDoubleSided(Schema.Material gltfMaterial, Material material) { + protected override void SetDoubleSided(MaterialBase gltfMaterial, Material material) { base.SetDoubleSided(gltfMaterial,material); material.SetFloat(k_CullModePropId, (int)CullMode.Off); } - protected override void SetShaderModeBlend(Schema.Material gltfMaterial, Material material) { + protected override void SetShaderModeBlend(MaterialBase gltfMaterial, Material material) { material.EnableKeyword(AlphaTestOnKeyword); material.EnableKeyword(k_SurfaceTypeTransparent); material.renderQueue = (int)RenderQueue.Transparent; From 7d2da81ca95d35568e55e4bbbc8f2614a73abc7d Mon Sep 17 00:00:00 2001 From: Nick Constantinidis Date: Thu, 25 Jan 2024 12:24:37 -0500 Subject: [PATCH 5/7] Fix IsTextureYFlipped for non-KTX textures (#85) * return correct result for non-KTX in GltfImport.IsTextureYFlipped * update changelog --- CHANGELOG.md | 1 + Runtime/Scripts/GltfImport.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2436635..e06b8b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Compiler error when Newtonsoft JSON package was not installed. - All Draco vertex attributes are assigned by identifier instead of type. As a result, tangents are now decoded properly instead of recalculated. - Compilation error when scripting define `GLTFAST_BUILTIN_SHADER_GRAPH` is set. +- `GltfImport.IsTextureYFlipped` returns correct result for non-KTX textures. ## [6.1.0] - 2024-01-17 diff --git a/Runtime/Scripts/GltfImport.cs b/Runtime/Scripts/GltfImport.cs index 0d2377af..89f785dc 100644 --- a/Runtime/Scripts/GltfImport.cs +++ b/Runtime/Scripts/GltfImport.cs @@ -831,7 +831,7 @@ public Texture2D GetTexture(int index = 0) public bool IsTextureYFlipped(int index = 0) { #if KTX - return m_NonFlippedYTextureIndices == null || !m_NonFlippedYTextureIndices.Contains(index); + return (m_NonFlippedYTextureIndices == null || !m_NonFlippedYTextureIndices.Contains(index)) && GetSourceTexture(index).IsKtx; #else return false; #endif From 9692dc0e3a5710bf9b23916818b8019ffbe90fa5 Mon Sep 17 00:00:00 2001 From: Andreas Atteneder Date: Mon, 29 Jan 2024 11:24:03 +0100 Subject: [PATCH 6/7] feat: Deprecated soft-dependency packages are detected and a warning with upgrade instructions is shown in the console. (#87) --- CHANGELOG.md | 3 + Editor/Scripts/PackageSetupCheck.cs | 158 +++++++++++++++++++++++ Editor/Scripts/PackageSetupCheck.cs.meta | 11 ++ 3 files changed, 172 insertions(+) create mode 100644 Editor/Scripts/PackageSetupCheck.cs create mode 100644 Editor/Scripts/PackageSetupCheck.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index e06b8b62..a9dde4b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Deprecated soft-dependency packages are detected and a warning with upgrade instructions is shown in the console. + ### Changed - Support for Draco 3D Data Compression is now provided by [*Draco for Unity* (com.unity.cloud.draco)][DracoForUnity], which is a fork of and replaces [*DracoUnity* (com.atteneder.draco)][DracoUnity]. diff --git a/Editor/Scripts/PackageSetupCheck.cs b/Editor/Scripts/PackageSetupCheck.cs new file mode 100644 index 00000000..775fa47a --- /dev/null +++ b/Editor/Scripts/PackageSetupCheck.cs @@ -0,0 +1,158 @@ +// SPDX-FileCopyrightText: 2023 Unity Technologies and the glTFast authors +// SPDX-License-Identifier: Apache-2.0 + +#if UNITY_2021_2_OR_NEWER +#define HYPERLINK +#define COMBINED +#endif + +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEditor.PackageManager; +using UnityEditor.PackageManager.Requests; +using UnityEngine; + +namespace GLTFast.Editor +{ + [InitializeOnLoad] + static class PackageSetupCheck + { + static ListRequest s_ListRequest; + + static PackageReplacement[] s_Packages = new PackageReplacement[] + { + new PackageReplacement() + { + name = "Draco for Unity", + identifier = "com.unity.cloud.draco", + legacyName = "Draco 3D Data Compression", + legacyIdentifier = "com.atteneder.draco", + feature = "KHR_draco_mesh_compression", + featureUri = "https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md", + upgradeDocsUri = "https://docs.unity3d.com/Packages/com.unity.cloud.draco@5.0/manual/upgrade-guide.html#transition-to-draco-for-unity" + }, + new PackageReplacement() + { + name = "KTX for Unity", + identifier = "com.unity.cloud.ktx", + legacyName = "KTX/Basis Universal Texture", + legacyIdentifier = "com.atteneder.ktx", + feature = "KHR_texture_basisu", + featureUri = "https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md", + upgradeDocsUri = "https://docs.unity3d.com/Packages/com.unity.cloud.ktx@3.2/manual/upgrade-guide.html#transition-to-ktx-for-unity" + } + }; + + static PackageSetupCheck() + { + EditorApplication.update += WaitForPackageList; + s_ListRequest = Client.List(true); +#if HYPERLINK + EditorGUI.hyperLinkClicked += HyperLinkClicked; +#endif + } + + static void WaitForPackageList() + { + if (s_ListRequest != null && s_ListRequest.IsCompleted) + { + if (s_ListRequest.Error == null) + { + foreach (var package in s_Packages) + { + CheckForLegacyPackage(s_ListRequest.Result, package); + } + } + + s_ListRequest = null; + EditorApplication.update -= WaitForPackageList; + } + } + + static void CheckForLegacyPackage( + PackageCollection packages, + PackageReplacement pkg + ) + { + var legacyFound = false; + + foreach (var packageInfo in packages) + { + if (packageInfo.name == pkg.legacyIdentifier) + { + legacyFound = true; + } + } + if (legacyFound) + { + pkg.LogUpgradeMessage(); + } + } + +#if HYPERLINK + static void HyperLinkClicked(EditorWindow window, HyperLinkClickedEventArgs args) + { + if(args.hyperLinkData.TryGetValue("command", out var command) && command=="replace") + { + if (args.hyperLinkData.TryGetValue("arg", out var pkg)) + { + foreach (var package in s_Packages) + { + if (package.legacyIdentifier == pkg) + { + ReplacePackage(package); + } + } + } + } + } +#endif + +#if COMBINED + static void ReplacePackage(PackageReplacement package) + { + if (EditorUtility.DisplayDialog( + "Package Upgrade", + $"Replace deprecated {package.legacyName} ({package.legacyIdentifier}) by {package.name} ({package.identifier})?", + "Replace", + "Cancel" + ) + ) + { + Client.AddAndRemove( + new[] { package.identifier }, + new[] { package.legacyIdentifier } + ); + } + } +#endif + } + + struct PackageReplacement + { + public string name; + public string identifier; + public string legacyName; + public string legacyIdentifier; + public string feature; + public string featureUri; + public string upgradeDocsUri; + + public void LogUpgradeMessage() + { + var message = $"Deprecated package {legacyName} ({legacyIdentifier}) detected!\n" + + $"glTFast now requires {name} ({identifier}) instead to provide support for " + + $"{feature}.\n"; +#if HYPERLINK + message += + $"You can automatically replace the " + + $"deprecated package or do it manually following the documentation."; +#else + message += "To upgrade the package, follow the documentation at " + + $"{upgradeDocsUri}"; +#endif + Debug.LogWarning(message); + } + } +} diff --git a/Editor/Scripts/PackageSetupCheck.cs.meta b/Editor/Scripts/PackageSetupCheck.cs.meta new file mode 100644 index 00000000..5c96ba7a --- /dev/null +++ b/Editor/Scripts/PackageSetupCheck.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 433625e5684fd4f83b3ee45f614c2d7d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 28bb7fc6f2d34d2d3e93bd77e768ec730d5494aa Mon Sep 17 00:00:00 2001 From: Andreas Atteneder Date: Mon, 29 Jan 2024 13:29:09 +0100 Subject: [PATCH 7/7] Release 6.2.0 (#89) --- CHANGELOG.md | 2 +- Runtime/Scripts/Export/Constants.cs | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9dde4b4..6e273e9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [6.2.0] - 2024-01-29 ### Added - Deprecated soft-dependency packages are detected and a warning with upgrade instructions is shown in the console. diff --git a/Runtime/Scripts/Export/Constants.cs b/Runtime/Scripts/Export/Constants.cs index dea1f81c..b1bedbfc 100644 --- a/Runtime/Scripts/Export/Constants.cs +++ b/Runtime/Scripts/Export/Constants.cs @@ -7,7 +7,7 @@ namespace GLTFast.Export { static class Constants { - public const string version = "6.1.0"; + public const string version = "6.2.0"; internal const string mimeTypePNG = "image/png"; internal const string mimeTypeJPG = "image/jpeg"; diff --git a/package.json b/package.json index 24048a81..6a3977eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.unity.cloud.gltfast", - "version": "6.1.0", + "version": "6.2.0", "displayName": "Unity glTFast", "description": "Use glTFast to import and export glTF 3D files efficiently at runtime or in the Editor", "unity": "2020.3",