From 1ae13533a96083de3cadff4918763ce20d3c6231 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Sat, 6 Apr 2019 00:49:36 -0400 Subject: [PATCH 01/41] Include .asmdef files for correct UPM package generation --- .../Scripts/Tests/UnityGLTFTests.asmdef | 16 ++++++++++++++++ .../Scripts/Tests/UnityGLTFTests.asmdef.meta | 7 +++++++ .../UnityGLTF/Scripts/UnityGLTFScripts.asmdef | 3 +++ .../Scripts/UnityGLTFScripts.asmdef.meta | 7 +++++++ 4 files changed, 33 insertions(+) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef new file mode 100644 index 000000000..77a847114 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -0,0 +1,16 @@ +{ + "name": "UnityGLTFTests", + "references": [ + "UnityGLTFScripts" + ], + "optionalUnityReferences": [ + "TestAssemblies" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta new file mode 100644 index 000000000..ff76efede --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e5407060e0b39404cacbd1741581df2b +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef new file mode 100644 index 000000000..d949e7774 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef @@ -0,0 +1,3 @@ +{ + "name": "UnityGLTFScripts" +} diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta new file mode 100644 index 000000000..5ef7d0474 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 18d18f811ba286c49814567a3cfba688 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 3189a4c1eab246b6447e464bcfad95fbab2371bf Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:45:16 -0400 Subject: [PATCH 02/41] Fix missing Integrations .meta file position --- .../UnityGLTF/Scripts/Tests/{Editor => }/Integration.meta | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename UnityGLTF/Assets/UnityGLTF/Scripts/Tests/{Editor => }/Integration.meta (58%) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta similarity index 58% rename from UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta rename to UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta index ab5ce21da..55750aa52 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: e1c2c4a5d74bb304f8208a98cc16db22 +guid: 5783cb7e53a767047b9bbec12c1cd4cf folderAsset: yes -timeCreated: 1506549706 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: From 2531da1c5ca63578d4c5d9c68244af005f1fa25d Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:52:47 -0400 Subject: [PATCH 03/41] Splitting out UnityGLTFEditor scripts with its own asmdef file --- .../Scripts/Editor/UnityGLTFEditor.asmdef | 16 ++++++++++++++++ .../Scripts/Editor/UnityGLTFEditor.asmdef.meta | 7 +++++++ .../Scripts/Tests/UnityGLTFTests.asmdef | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef new file mode 100644 index 000000000..c9a3347a7 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef @@ -0,0 +1,16 @@ +{ + "name": "UnityGLTFEditor", + "references": [ + "UnityGLTFScripts" + ], + "optionalUnityReferences": [], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta new file mode 100644 index 000000000..68e4ef64f --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1a0324566af4ed544918d6837a1f4e11 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef index 77a847114..f5674c3bd 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -1,7 +1,8 @@ { "name": "UnityGLTFTests", "references": [ - "UnityGLTFScripts" + "UnityGLTFScripts", + "UnityGLTFEditor" ], "optionalUnityReferences": [ "TestAssemblies" From 03fdae4cd0c768ced25f7e27bc77f08ba575e45b Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:57:48 -0400 Subject: [PATCH 04/41] Build script updates to properly support UWP with UPM compliant package --- .travis.yml | 3 ++- scripts/export-upm-package.sh | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b4b2855d..7e9b52d53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,9 @@ before_script: - sudo chmod +x ./scripts/export-upm-package.sh script: - msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization /p:TargetFramework=net35 -- "./scripts/export-upm-package.sh" - "./scripts/export-unity-package.sh" +- msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization +- "./scripts/export-upm-package.sh" deploy: provider: releases file: diff --git a/scripts/export-upm-package.sh b/scripts/export-upm-package.sh index d1fcc202b..f3bcdde19 100644 --- a/scripts/export-upm-package.sh +++ b/scripts/export-upm-package.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash project_path=$(pwd)/UnityGLTF log_file=$(pwd)/build/unity-mac.log @@ -8,9 +8,22 @@ upm_name=org.khronos.UnityGLTF upm_src_folder_path=$(pwd)/UnityGLTF/Assets/UnityGLTF upm_manifest_path=$(pwd)/scripts/package.json upm_staging_path=$(pwd)/current-package/$upm_name +upm_staging_UWP_plugins_path=$upm_staging_path/Plugins/uap10.0.10586 upm_zip_export_path=$(pwd)/current-package/$upm_name.zip upm_targz_export_path=$(pwd)/current-package/$upm_name.tar.gz +# msbuild spits out every single dependency dll for UWP +# These are the only files that are needed by the UPM package for Unity 2018.3+ +# Including all the files in the UWP plugin directory causes name collision errors when +# building for UWP in Unity +upm_UWP_Plugins=( + "GLTFSerialization.dll" + "GLTFSerialization.dll.meta" + "GLTFSerialization.pdb" + "Newtonsoft.Json.dll" + "Newtonsoft.Json.dll.meta" +) + error_code=0 echo $upm_name echo $upm_src_folder_path @@ -28,14 +41,20 @@ cp -r $upm_src_folder_path $upm_staging_path echo "Changing to $upm_staging_path folder" cd $upm_staging_path +echo "Cleaning out UWP plugin DLLs that are not needed for Unity2018.3+" +echo "Only keeping the following files:" +printf '%s\n' "${upm_UWP_Plugins[@]}" +find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs -r rm + echo "Creating .zip of UPM package" -sudo zip -r $upm_zip_export_path ./ +sudo zip -q -r $upm_zip_export_path ./ echo "Creating .tar.gz of UPM package" -tar -zcvf $upm_targz_export_path ./ +tar -zcf $upm_targz_export_path ./ echo "Changing back to original folder $cached_folder" cd $cached_folder echo "Finishing with code $error_code" -exit $error_code \ No newline at end of file +exit $error_code + From 9081e880e381d7868336611f6e735e08fb2c520b Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Sat, 6 Apr 2019 00:49:36 -0400 Subject: [PATCH 05/41] Include .asmdef files for correct UPM package generation --- .../Scripts/Tests/UnityGLTFTests.asmdef | 16 ++++++++++++++++ .../Scripts/Tests/UnityGLTFTests.asmdef.meta | 7 +++++++ .../UnityGLTF/Scripts/UnityGLTFScripts.asmdef | 3 +++ .../Scripts/UnityGLTFScripts.asmdef.meta | 7 +++++++ 4 files changed, 33 insertions(+) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef new file mode 100644 index 000000000..77a847114 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -0,0 +1,16 @@ +{ + "name": "UnityGLTFTests", + "references": [ + "UnityGLTFScripts" + ], + "optionalUnityReferences": [ + "TestAssemblies" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta new file mode 100644 index 000000000..ff76efede --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e5407060e0b39404cacbd1741581df2b +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef new file mode 100644 index 000000000..d949e7774 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef @@ -0,0 +1,3 @@ +{ + "name": "UnityGLTFScripts" +} diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta new file mode 100644 index 000000000..5ef7d0474 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 18d18f811ba286c49814567a3cfba688 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 658bb4861079c547aba0880e234030e776570331 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:45:16 -0400 Subject: [PATCH 06/41] Fix missing Integrations .meta file position --- .../UnityGLTF/Scripts/Tests/{Editor => }/Integration.meta | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename UnityGLTF/Assets/UnityGLTF/Scripts/Tests/{Editor => }/Integration.meta (58%) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta similarity index 58% rename from UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta rename to UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta index ab5ce21da..55750aa52 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: e1c2c4a5d74bb304f8208a98cc16db22 +guid: 5783cb7e53a767047b9bbec12c1cd4cf folderAsset: yes -timeCreated: 1506549706 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: From b425c07bdf9fe9d5042790d86bcf5e88d4bc12f8 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:52:47 -0400 Subject: [PATCH 07/41] Splitting out UnityGLTFEditor scripts with its own asmdef file --- .../Scripts/Editor/UnityGLTFEditor.asmdef | 16 ++++++++++++++++ .../Scripts/Editor/UnityGLTFEditor.asmdef.meta | 7 +++++++ .../Scripts/Tests/UnityGLTFTests.asmdef | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef new file mode 100644 index 000000000..c9a3347a7 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef @@ -0,0 +1,16 @@ +{ + "name": "UnityGLTFEditor", + "references": [ + "UnityGLTFScripts" + ], + "optionalUnityReferences": [], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta new file mode 100644 index 000000000..68e4ef64f --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1a0324566af4ed544918d6837a1f4e11 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef index 77a847114..f5674c3bd 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -1,7 +1,8 @@ { "name": "UnityGLTFTests", "references": [ - "UnityGLTFScripts" + "UnityGLTFScripts", + "UnityGLTFEditor" ], "optionalUnityReferences": [ "TestAssemblies" From 4d77390c820bd54d53c17c2a604f0d4858304570 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:57:48 -0400 Subject: [PATCH 08/41] Build script updates to properly support UWP with UPM compliant package --- .travis.yml | 3 ++- scripts/export-upm-package.sh | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b4b2855d..7e9b52d53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,9 @@ before_script: - sudo chmod +x ./scripts/export-upm-package.sh script: - msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization /p:TargetFramework=net35 -- "./scripts/export-upm-package.sh" - "./scripts/export-unity-package.sh" +- msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization +- "./scripts/export-upm-package.sh" deploy: provider: releases file: diff --git a/scripts/export-upm-package.sh b/scripts/export-upm-package.sh index d1fcc202b..f3bcdde19 100644 --- a/scripts/export-upm-package.sh +++ b/scripts/export-upm-package.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash project_path=$(pwd)/UnityGLTF log_file=$(pwd)/build/unity-mac.log @@ -8,9 +8,22 @@ upm_name=org.khronos.UnityGLTF upm_src_folder_path=$(pwd)/UnityGLTF/Assets/UnityGLTF upm_manifest_path=$(pwd)/scripts/package.json upm_staging_path=$(pwd)/current-package/$upm_name +upm_staging_UWP_plugins_path=$upm_staging_path/Plugins/uap10.0.10586 upm_zip_export_path=$(pwd)/current-package/$upm_name.zip upm_targz_export_path=$(pwd)/current-package/$upm_name.tar.gz +# msbuild spits out every single dependency dll for UWP +# These are the only files that are needed by the UPM package for Unity 2018.3+ +# Including all the files in the UWP plugin directory causes name collision errors when +# building for UWP in Unity +upm_UWP_Plugins=( + "GLTFSerialization.dll" + "GLTFSerialization.dll.meta" + "GLTFSerialization.pdb" + "Newtonsoft.Json.dll" + "Newtonsoft.Json.dll.meta" +) + error_code=0 echo $upm_name echo $upm_src_folder_path @@ -28,14 +41,20 @@ cp -r $upm_src_folder_path $upm_staging_path echo "Changing to $upm_staging_path folder" cd $upm_staging_path +echo "Cleaning out UWP plugin DLLs that are not needed for Unity2018.3+" +echo "Only keeping the following files:" +printf '%s\n' "${upm_UWP_Plugins[@]}" +find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs -r rm + echo "Creating .zip of UPM package" -sudo zip -r $upm_zip_export_path ./ +sudo zip -q -r $upm_zip_export_path ./ echo "Creating .tar.gz of UPM package" -tar -zcvf $upm_targz_export_path ./ +tar -zcf $upm_targz_export_path ./ echo "Changing back to original folder $cached_folder" cd $cached_folder echo "Finishing with code $error_code" -exit $error_code \ No newline at end of file +exit $error_code + From c5de2bb5d0be7ce9ed132614f951fe3a25b614e3 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Tue, 16 Apr 2019 00:34:03 -0400 Subject: [PATCH 09/41] Fixing Travis build environment issues --- scripts/export-upm-package.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/export-upm-package.sh b/scripts/export-upm-package.sh index f3bcdde19..a0e861489 100644 --- a/scripts/export-upm-package.sh +++ b/scripts/export-upm-package.sh @@ -8,7 +8,7 @@ upm_name=org.khronos.UnityGLTF upm_src_folder_path=$(pwd)/UnityGLTF/Assets/UnityGLTF upm_manifest_path=$(pwd)/scripts/package.json upm_staging_path=$(pwd)/current-package/$upm_name -upm_staging_UWP_plugins_path=$upm_staging_path/Plugins/uap10.0.10586 +upm_staging_UWP_plugins_path=$upm_staging_path/UnityGLTF/Plugins/uap10.0.10586 upm_zip_export_path=$(pwd)/current-package/$upm_name.zip upm_targz_export_path=$(pwd)/current-package/$upm_name.tar.gz @@ -44,7 +44,7 @@ cd $upm_staging_path echo "Cleaning out UWP plugin DLLs that are not needed for Unity2018.3+" echo "Only keeping the following files:" printf '%s\n' "${upm_UWP_Plugins[@]}" -find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs -r rm +find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs rm echo "Creating .zip of UPM package" sudo zip -q -r $upm_zip_export_path ./ From 1e77076e001da3190d15c355edc01ae165f75be1 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Sat, 6 Apr 2019 00:49:36 -0400 Subject: [PATCH 10/41] Include .asmdef files for correct UPM package generation --- .../Scripts/Tests/UnityGLTFTests.asmdef | 16 ++++++++++++++++ .../Scripts/Tests/UnityGLTFTests.asmdef.meta | 7 +++++++ .../UnityGLTF/Scripts/UnityGLTFScripts.asmdef | 3 +++ .../Scripts/UnityGLTFScripts.asmdef.meta | 7 +++++++ 4 files changed, 33 insertions(+) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef new file mode 100644 index 000000000..77a847114 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -0,0 +1,16 @@ +{ + "name": "UnityGLTFTests", + "references": [ + "UnityGLTFScripts" + ], + "optionalUnityReferences": [ + "TestAssemblies" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta new file mode 100644 index 000000000..ff76efede --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e5407060e0b39404cacbd1741581df2b +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef new file mode 100644 index 000000000..d949e7774 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef @@ -0,0 +1,3 @@ +{ + "name": "UnityGLTFScripts" +} diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta new file mode 100644 index 000000000..5ef7d0474 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 18d18f811ba286c49814567a3cfba688 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 618e7fc5d14ef7a2287dd6be911ba6d9c36c0ba9 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:45:16 -0400 Subject: [PATCH 11/41] Fix missing Integrations .meta file position --- .../UnityGLTF/Scripts/Tests/{Editor => }/Integration.meta | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename UnityGLTF/Assets/UnityGLTF/Scripts/Tests/{Editor => }/Integration.meta (58%) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta similarity index 58% rename from UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta rename to UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta index ab5ce21da..55750aa52 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: e1c2c4a5d74bb304f8208a98cc16db22 +guid: 5783cb7e53a767047b9bbec12c1cd4cf folderAsset: yes -timeCreated: 1506549706 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: From bde9f8e4deaa5e9cafe0708267c58597812ea196 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:52:47 -0400 Subject: [PATCH 12/41] Splitting out UnityGLTFEditor scripts with its own asmdef file --- .../Scripts/Editor/UnityGLTFEditor.asmdef | 16 ++++++++++++++++ .../Scripts/Editor/UnityGLTFEditor.asmdef.meta | 7 +++++++ .../Scripts/Tests/UnityGLTFTests.asmdef | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef new file mode 100644 index 000000000..c9a3347a7 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef @@ -0,0 +1,16 @@ +{ + "name": "UnityGLTFEditor", + "references": [ + "UnityGLTFScripts" + ], + "optionalUnityReferences": [], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta new file mode 100644 index 000000000..68e4ef64f --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1a0324566af4ed544918d6837a1f4e11 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef index 77a847114..f5674c3bd 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -1,7 +1,8 @@ { "name": "UnityGLTFTests", "references": [ - "UnityGLTFScripts" + "UnityGLTFScripts", + "UnityGLTFEditor" ], "optionalUnityReferences": [ "TestAssemblies" From 6510efe2ee603708edd755fdaa965496401b7222 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:57:48 -0400 Subject: [PATCH 13/41] Build script updates to properly support UWP with UPM compliant package --- .travis.yml | 3 ++- scripts/export-upm-package.sh | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b4b2855d..7e9b52d53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,9 @@ before_script: - sudo chmod +x ./scripts/export-upm-package.sh script: - msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization /p:TargetFramework=net35 -- "./scripts/export-upm-package.sh" - "./scripts/export-unity-package.sh" +- msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization +- "./scripts/export-upm-package.sh" deploy: provider: releases file: diff --git a/scripts/export-upm-package.sh b/scripts/export-upm-package.sh index d1fcc202b..f3bcdde19 100644 --- a/scripts/export-upm-package.sh +++ b/scripts/export-upm-package.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash project_path=$(pwd)/UnityGLTF log_file=$(pwd)/build/unity-mac.log @@ -8,9 +8,22 @@ upm_name=org.khronos.UnityGLTF upm_src_folder_path=$(pwd)/UnityGLTF/Assets/UnityGLTF upm_manifest_path=$(pwd)/scripts/package.json upm_staging_path=$(pwd)/current-package/$upm_name +upm_staging_UWP_plugins_path=$upm_staging_path/Plugins/uap10.0.10586 upm_zip_export_path=$(pwd)/current-package/$upm_name.zip upm_targz_export_path=$(pwd)/current-package/$upm_name.tar.gz +# msbuild spits out every single dependency dll for UWP +# These are the only files that are needed by the UPM package for Unity 2018.3+ +# Including all the files in the UWP plugin directory causes name collision errors when +# building for UWP in Unity +upm_UWP_Plugins=( + "GLTFSerialization.dll" + "GLTFSerialization.dll.meta" + "GLTFSerialization.pdb" + "Newtonsoft.Json.dll" + "Newtonsoft.Json.dll.meta" +) + error_code=0 echo $upm_name echo $upm_src_folder_path @@ -28,14 +41,20 @@ cp -r $upm_src_folder_path $upm_staging_path echo "Changing to $upm_staging_path folder" cd $upm_staging_path +echo "Cleaning out UWP plugin DLLs that are not needed for Unity2018.3+" +echo "Only keeping the following files:" +printf '%s\n' "${upm_UWP_Plugins[@]}" +find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs -r rm + echo "Creating .zip of UPM package" -sudo zip -r $upm_zip_export_path ./ +sudo zip -q -r $upm_zip_export_path ./ echo "Creating .tar.gz of UPM package" -tar -zcvf $upm_targz_export_path ./ +tar -zcf $upm_targz_export_path ./ echo "Changing back to original folder $cached_folder" cd $cached_folder echo "Finishing with code $error_code" -exit $error_code \ No newline at end of file +exit $error_code + From d5378167142db9bb6f45f28446f571ac6b78dc6e Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Tue, 16 Apr 2019 00:34:03 -0400 Subject: [PATCH 14/41] Fixing Travis build environment issues --- scripts/export-upm-package.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/export-upm-package.sh b/scripts/export-upm-package.sh index f3bcdde19..a0e861489 100644 --- a/scripts/export-upm-package.sh +++ b/scripts/export-upm-package.sh @@ -8,7 +8,7 @@ upm_name=org.khronos.UnityGLTF upm_src_folder_path=$(pwd)/UnityGLTF/Assets/UnityGLTF upm_manifest_path=$(pwd)/scripts/package.json upm_staging_path=$(pwd)/current-package/$upm_name -upm_staging_UWP_plugins_path=$upm_staging_path/Plugins/uap10.0.10586 +upm_staging_UWP_plugins_path=$upm_staging_path/UnityGLTF/Plugins/uap10.0.10586 upm_zip_export_path=$(pwd)/current-package/$upm_name.zip upm_targz_export_path=$(pwd)/current-package/$upm_name.tar.gz @@ -44,7 +44,7 @@ cd $upm_staging_path echo "Cleaning out UWP plugin DLLs that are not needed for Unity2018.3+" echo "Only keeping the following files:" printf '%s\n' "${upm_UWP_Plugins[@]}" -find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs -r rm +find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs rm echo "Creating .zip of UPM package" sudo zip -q -r $upm_zip_export_path ./ From 3b11d75b411d792f4ae9279a71ef6c9c06ab8223 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Tue, 16 Apr 2019 14:11:33 -0400 Subject: [PATCH 15/41] Pull down upstream changes --- ...tion.meta~Fix missing Integrations .meta file position | 8 ++++++++ .../Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position new file mode 100644 index 000000000..55750aa52 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5783cb7e53a767047b9bbec12c1cd4cf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD new file mode 100644 index 000000000..55750aa52 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5783cb7e53a767047b9bbec12c1cd4cf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 0256aef1a3089d3d8f79c547725b5f3ded0d3e93 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Tue, 16 Apr 2019 14:17:15 -0400 Subject: [PATCH 16/41] Fixing merge conflict --- ...tion.meta~Fix missing Integrations .meta file position | 8 -------- .../Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD | 8 -------- 2 files changed, 16 deletions(-) delete mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position delete mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position deleted file mode 100644 index 55750aa52..000000000 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5783cb7e53a767047b9bbec12c1cd4cf -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD deleted file mode 100644 index 55750aa52..000000000 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5783cb7e53a767047b9bbec12c1cd4cf -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From 12683546d12c36479d4b4d71f25a88928d368a7d Mon Sep 17 00:00:00 2001 From: Robert Ferrese Date: Tue, 16 Apr 2019 13:56:42 -0700 Subject: [PATCH 17/41] Add Roughness float values to MetalRoughMap.cs --- .../Assets/UnityGLTF/Scripts/UniformMaps/MetalRoughMap.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/UniformMaps/MetalRoughMap.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/UniformMaps/MetalRoughMap.cs index e886d3eca..f2e1c5a68 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/UniformMaps/MetalRoughMap.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/UniformMaps/MetalRoughMap.cs @@ -86,6 +86,12 @@ public override int MetallicRoughnessXTexCoord set { return; } } + public override double RoughnessFactor + { + get { return _material.GetFloat("_Glossiness"); } + set { _material.SetFloat("_Glossiness", (float)value); } + } + public override IUniformMap Clone() { var copy = new MetalRoughMap(new Material(_material)); From ec7ee910163d40526d91fdb2e9616c7965fd5cf6 Mon Sep 17 00:00:00 2001 From: Robert Ferrese Date: Tue, 16 Apr 2019 13:59:56 -0700 Subject: [PATCH 18/41] Add names to textures created by GLTFSceneImporter --- UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs index 2e9dbad67..0a1de5c19 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs @@ -630,6 +630,7 @@ protected async Task ConstructImage(GLTFImage image, int imageCacheIndex, bool m protected virtual async Task ConstructUnityTexture(Stream stream, bool markGpuOnly, bool isLinear, GLTFImage image, int imageCacheIndex) { Texture2D texture = new Texture2D(0, 0, TextureFormat.RGBA32, true, isLinear); + texture.name = nameof(GLTFSceneImporter); if (stream is MemoryStream) { @@ -1912,6 +1913,7 @@ protected virtual async Task ConstructTexture(GLTFTexture texture, int textureIn protected virtual void ConstructImageFromGLB(GLTFImage image, int imageCacheIndex) { var texture = new Texture2D(0, 0); + texture.name = nameof(GLTFSceneImporter); var bufferView = image.BufferView.Value; var data = new byte[bufferView.ByteLength]; From 0d0d69af797a90cd355c40448dd2a07c926b67af Mon Sep 17 00:00:00 2001 From: Robert Ferrese Date: Tue, 16 Apr 2019 14:05:11 -0700 Subject: [PATCH 19/41] Fix texture memory leak --- .../Scripts/Cache/MaterialCacheData.cs | 11 ++-- .../UnityGLTF/Scripts/Cache/MeshCacheData.cs | 13 ++-- .../Scripts/Cache/RefCountedCacheData.cs | 43 ++++++++---- .../Scripts/Cache/TextureCacheData.cs | 11 +++- .../UnityGLTF/Scripts/GLTFSceneImporter.cs | 65 +++++++++++-------- 5 files changed, 91 insertions(+), 52 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/MaterialCacheData.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/MaterialCacheData.cs index 399d576ad..ff9083198 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/MaterialCacheData.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/MaterialCacheData.cs @@ -1,9 +1,10 @@ using GLTF.Schema; +using System; using UnityEngine; namespace UnityGLTF.Cache { - public class MaterialCacheData + public class MaterialCacheData : IDisposable { public Material UnityMaterial { get; set; } public Material UnityMaterialWithVertexColor { get; set; } @@ -17,16 +18,18 @@ public Material GetContents(bool useVertexColors) /// /// Unloads the materials in this cache. /// - public void Unload() + public void Dispose() { if (UnityMaterial != null) { - Object.Destroy(UnityMaterial); + UnityEngine.Object.Destroy(UnityMaterial); + UnityMaterial = null; } if (UnityMaterialWithVertexColor != null) { - Object.Destroy(UnityMaterialWithVertexColor); + UnityEngine.Object.Destroy(UnityMaterialWithVertexColor); + UnityMaterialWithVertexColor = null; } } } diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/MeshCacheData.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/MeshCacheData.cs index a04b282fc..064a65e17 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/MeshCacheData.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/MeshCacheData.cs @@ -1,14 +1,15 @@ using GLTF; +using System; using System.Collections.Generic; using UnityEngine; namespace UnityGLTF.Cache { - public class MeshCacheData + public class MeshCacheData : IDisposable { public Mesh LoadedMesh { get; set; } public Dictionary MeshAttributes { get; set; } - public GameObject PrimitiveGO { get; set; } + public GameObject PrimitiveGO { get; set; } public MeshCacheData() { @@ -18,9 +19,13 @@ public MeshCacheData() /// /// Unloads the meshes in this cache. /// - public void Unload() + public void Dispose() { - Object.Destroy(LoadedMesh); + if (LoadedMesh != null) + { + UnityEngine.Object.Destroy(LoadedMesh); + LoadedMesh = null; + } } } } diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs index db3e96ee6..ff3dc87a5 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs @@ -25,17 +25,30 @@ public class RefCountedCacheData /// /// Meshes used by this GLTF node. /// - public MeshCacheData[][] MeshCache { get; set; } + public MeshCacheData[][] MeshCache { get; private set; } /// /// Materials used by this GLTF node. /// - public MaterialCacheData[] MaterialCache { get; set; } + public MaterialCacheData[] MaterialCache { get; private set; } /// /// Textures used by this GLTF node. /// - public TextureCacheData[] TextureCache { get; set; } + public TextureCacheData[] TextureCache { get; private set; } + + /// + /// Textures from the AssetCache that might need to be cleaned up + /// + public Texture2D[] ImageCache { get; private set; } + + public RefCountedCacheData(MaterialCacheData[] materialCache, MeshCacheData[][] meshCache, TextureCacheData[] textureCache, Texture2D[] imageCache) + { + MaterialCache = materialCache; + MeshCache = meshCache; + TextureCache = textureCache; + ImageCache = imageCache; + } public void IncreaseRefCount() { @@ -80,28 +93,32 @@ private void DestroyCachedData() { for (int j = 0; j < MeshCache[i].Length; j++) { - if (MeshCache[i][j] != null) - { - MeshCache[i][j].Unload(); - } + MeshCache[i][j]?.Dispose(); + MeshCache[i][j] = null; } } // Destroy the cached textures for (int i = 0; i < TextureCache.Length; i++) { - if (TextureCache[i] != null) - { - TextureCache[i].Unload(); - } + TextureCache[i]?.Dispose(); + TextureCache[i] = null; } // Destroy the cached materials for (int i = 0; i < MaterialCache.Length; i++) { - if (MaterialCache[i] != null) + MaterialCache[i]?.Dispose(); + MaterialCache[i] = null; + } + + // Destroy the cached textures + for (int i = 0; i < ImageCache.Length; i++) + { + if (ImageCache[i] != null) { - MaterialCache[i].Unload(); + UnityEngine.Object.Destroy(ImageCache[i]); + ImageCache[i] = null; } } diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/TextureCacheData.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/TextureCacheData.cs index 90248769a..5f4bc1bdd 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/TextureCacheData.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/TextureCacheData.cs @@ -1,9 +1,10 @@ using GLTF.Schema; +using System; using UnityEngine; namespace UnityGLTF.Cache { - public class TextureCacheData + public class TextureCacheData : IDisposable { public GLTFTexture TextureDefinition; public Texture Texture; @@ -11,9 +12,13 @@ public class TextureCacheData /// /// Unloads the textures in this cache. /// - public void Unload() + public void Dispose() { - Object.Destroy(Texture); + if (Texture != null) + { + UnityEngine.Object.Destroy(Texture); + Texture = null; + } } } } diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs index 2e9dbad67..8b3785120 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs @@ -167,7 +167,7 @@ public GLTFSceneImporter(GLTFRoot rootNode, ILoader externalDataLoader, AsyncCor _loader = externalDataLoader; if (gltfStream != null) { - _gltfStream = new GLBStream {Stream = gltfStream, StartPosition = gltfStream.Position}; + _gltfStream = new GLBStream { Stream = gltfStream, StartPosition = gltfStream.Position }; } } @@ -346,11 +346,12 @@ private void InitializeGltfTopLevelObject() { InstantiatedGLTFObject instantiatedGltfObject = CreatedObject.AddComponent(); instantiatedGltfObject.CachedData = new RefCountedCacheData - { - MaterialCache = _assetCache.MaterialCache, - MeshCache = _assetCache.MeshCache, - TextureCache = _assetCache.TextureCache - }; + ( + _assetCache.MaterialCache, + _assetCache.MeshCache, + _assetCache.TextureCache, + _assetCache.ImageCache + ); } private async Task ConstructBufferData(Node node) @@ -439,10 +440,13 @@ protected async Task ConstructImageBuffer(GLTFTexture texture, int textureIndex) } } - _assetCache.TextureCache[textureIndex] = new TextureCacheData + if (_assetCache.TextureCache[textureIndex] == null) { - TextureDefinition = texture - }; + _assetCache.TextureCache[textureIndex] = new TextureCacheData + { + TextureDefinition = texture + }; + } } protected IEnumerator WaitUntilEnum(WaitUntil waitUntil) @@ -453,19 +457,19 @@ protected IEnumerator WaitUntilEnum(WaitUntil waitUntil) private async Task LoadJson(string jsonFilePath) { #if !WINDOWS_UWP - if (IsMultithreaded && _loader.HasSyncLoadMethod) - { + if (IsMultithreaded && _loader.HasSyncLoadMethod) + { Thread loadThread = new Thread(() => _loader.LoadStreamSync(jsonFilePath)); loadThread.Priority = ThreadPriority.Highest; loadThread.Start(); RunCoroutineSync(WaitUntilEnum(new WaitUntil(() => !loadThread.IsAlive))); - } - else + } + else #endif - { + { // HACK: Force the coroutine to run synchronously in the editor await _loader.LoadStream(jsonFilePath); - } + } _gltfStream.Stream = _loader.LoadedStream; _gltfStream.StartPosition = 0; @@ -745,11 +749,11 @@ protected void TransformAttributes(ref Dictionary att } } -#region Animation + #region Animation static string RelativePathFrom(Transform self, Transform root) { var path = new List(); - for (var current = self; current != null; current = current.parent) + for (var current = self; current != null; current = current.parent) { if (current == root) { @@ -838,7 +842,7 @@ protected void SetAnimationCurve( // copy all the key frame data to cache Keyframe[][] keyframes = new Keyframe[channelCount][]; - for( var ci = 0; ci < channelCount; ++ci) + for (var ci = 0; ci < channelCount; ++ci) { keyframes[ci] = new Keyframe[frameCount]; } @@ -849,13 +853,13 @@ protected void SetAnimationCurve( var values = getConvertedValues(output, i); - for( var ci = 0; ci < channelCount; ++ci) + for (var ci = 0; ci < channelCount; ++ci) { keyframes[ci][i] = new Keyframe(time, values[ci]); } } - for( var ci = 0; ci < channelCount; ++ci) + for (var ci = 0; ci < channelCount; ++ci) { // set interpolcation for each keyframe SetCurveMode(keyframes[ci], mode); @@ -912,9 +916,10 @@ protected AnimationClip ConstructClip(Transform root, GameObject[] nodes, int an SetAnimationCurve(clip, relativePath, propertyNames, input, output, samplerCache.Interpolation, typeof(Transform), - (data, frame) => { + (data, frame) => + { var position = data.AsVec3s[frame].ToUnityVector3Convert(); - return new float[] { position.x, position.y, position.z}; + return new float[] { position.x, position.y, position.z }; }); break; @@ -923,10 +928,11 @@ protected AnimationClip ConstructClip(Transform root, GameObject[] nodes, int an SetAnimationCurve(clip, relativePath, propertyNames, input, output, samplerCache.Interpolation, typeof(Transform), - (data, frame) => { + (data, frame) => + { var rotation = data.AsVec4s[frame]; var quaternion = new GLTF.Math.Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W).ToUnityQuaternionConvert(); - return new float[] { quaternion.x, quaternion.y, quaternion.z, quaternion.w}; + return new float[] { quaternion.x, quaternion.y, quaternion.z, quaternion.w }; }); break; @@ -936,9 +942,10 @@ protected AnimationClip ConstructClip(Transform root, GameObject[] nodes, int an SetAnimationCurve(clip, relativePath, propertyNames, input, output, samplerCache.Interpolation, typeof(Transform), - (data, frame) => { + (data, frame) => + { var scale = data.AsVec3s[frame].ToUnityVector3Raw(); - return new float[] { scale.x, scale.y, scale.z}; + return new float[] { scale.x, scale.y, scale.z }; }); break; @@ -1037,7 +1044,7 @@ public static void SetCurveMode(Keyframe[] keyframes, InterpolationType mode) key.outTangent = outtangent; } } -#endregion + #endregion protected virtual async Task ConstructScene(GLTFScene scene, bool showSceneObj) { @@ -1605,7 +1612,7 @@ protected virtual async Task ConstructMaterial(GLTFMaterial def, int materialInd mrMapper.BaseColorTexCoord = pbr.BaseColorTexture.TexCoord; var ext = GetTextureTransform(pbr.BaseColorTexture); - if(ext != null) + if (ext != null) { mrMapper.BaseColorXOffset = ext.Offset.ToUnityVector2Raw(); mrMapper.BaseColorXRotation = ext.Rotation; @@ -1891,6 +1898,7 @@ protected virtual async Task ConstructTexture(GLTFTexture texture, int textureIn var matchSamplerState = source.filterMode == desiredFilterMode && source.wrapMode == desiredWrapMode; if (matchSamplerState || markGpuOnly) { + Debug.Assert(_assetCache.TextureCache[textureIndex].Texture == null, "Texture should not be reset to prevent memory leaks"); _assetCache.TextureCache[textureIndex].Texture = source; if (!matchSamplerState) @@ -1904,6 +1912,7 @@ protected virtual async Task ConstructTexture(GLTFTexture texture, int textureIn unityTexture.filterMode = desiredFilterMode; unityTexture.wrapMode = desiredWrapMode; + Debug.Assert(_assetCache.TextureCache[textureIndex].Texture == null, "Texture should not be reset to prevent memory leaks"); _assetCache.TextureCache[textureIndex].Texture = unityTexture; } } From 72ab4458944ef509a4d93a9d1f1c512c709307a3 Mon Sep 17 00:00:00 2001 From: Robert Ferrese Date: Wed, 17 Apr 2019 14:43:03 -0700 Subject: [PATCH 20/41] Add task cancellation support --- .../UnityGLTF/Scripts/GLTFSceneImporter.cs | 67 +++++++++++-------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs index 2e9dbad67..12340866a 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs @@ -196,8 +196,9 @@ public GameObject LastLoadedScene /// The scene to load, If the index isn't specified, we use the default index in the file. Failing that we load index 0. /// /// Callback function for when load is completed + /// Cancellation token for loading /// - public async Task LoadSceneAsync(int sceneIndex = -1, bool showSceneObj = true, Action onLoadComplete = null) + public async Task LoadSceneAsync(int sceneIndex = -1, bool showSceneObj = true, Action onLoadComplete = null, CancellationToken cancellationToken = default(CancellationToken)) { try { @@ -216,12 +217,14 @@ public async Task LoadSceneAsync(int sceneIndex = -1, bool showSceneObj = true, await LoadJson(_gltfFileName); } + cancellationToken.ThrowIfCancellationRequested(); + if (_assetCache == null) { _assetCache = new AssetCache(_gltfRoot); } - await _LoadScene(sceneIndex, showSceneObj); + await _LoadScene(sceneIndex, showSceneObj, cancellationToken); } catch (Exception ex) { @@ -273,7 +276,7 @@ public async Task LoadNodeAsync(int nodeIndex) _assetCache = new AssetCache(_gltfRoot); } - await _LoadNode(nodeIndex); + await _LoadNode(nodeIndex, CancellationToken.None); CreatedObject = _assetCache.NodeCache[nodeIndex]; InitializeGltfTopLevelObject(); } @@ -353,8 +356,10 @@ private void InitializeGltfTopLevelObject() }; } - private async Task ConstructBufferData(Node node) + private async Task ConstructBufferData(Node node, CancellationToken cancellationToken) { + cancellationToken.ThrowIfCancellationRequested(); + MeshId mesh = node.Mesh; if (mesh != null) { @@ -368,7 +373,7 @@ private async Task ConstructBufferData(Node node) { foreach (NodeId child in node.Children) { - await ConstructBufferData(child.Value); + await ConstructBufferData(child.Value, cancellationToken); } } @@ -385,7 +390,7 @@ private async Task ConstructBufferData(Node node) for (int i = 0; i < lodsextension.MeshIds.Count; i++) { int lodNodeId = lodsextension.MeshIds[i]; - await ConstructBufferData(_gltfRoot.Nodes[lodNodeId]); + await ConstructBufferData(_gltfRoot.Nodes[lodNodeId], cancellationToken); } } } @@ -453,19 +458,19 @@ protected IEnumerator WaitUntilEnum(WaitUntil waitUntil) private async Task LoadJson(string jsonFilePath) { #if !WINDOWS_UWP - if (IsMultithreaded && _loader.HasSyncLoadMethod) - { + if (IsMultithreaded && _loader.HasSyncLoadMethod) + { Thread loadThread = new Thread(() => _loader.LoadStreamSync(jsonFilePath)); loadThread.Priority = ThreadPriority.Highest; loadThread.Start(); RunCoroutineSync(WaitUntilEnum(new WaitUntil(() => !loadThread.IsAlive))); - } - else + } + else #endif - { + { // HACK: Force the coroutine to run synchronously in the editor await _loader.LoadStream(jsonFilePath); - } + } _gltfStream.Stream = _loader.LoadedStream; _gltfStream.StartPosition = 0; @@ -508,7 +513,7 @@ private static void RunCoroutineSync(IEnumerator streamEnum) } } - private async Task _LoadNode(int nodeIndex) + private async Task _LoadNode(int nodeIndex, CancellationToken cancellationToken) { if (nodeIndex >= _gltfRoot.Nodes.Count) { @@ -517,16 +522,18 @@ private async Task _LoadNode(int nodeIndex) Node nodeToLoad = _gltfRoot.Nodes[nodeIndex]; + cancellationToken.ThrowIfCancellationRequested(); if (!IsMultithreaded) { - await ConstructBufferData(nodeToLoad); + await ConstructBufferData(nodeToLoad, cancellationToken); } else { - await Task.Run(() => ConstructBufferData(nodeToLoad)); + await Task.Run(() => ConstructBufferData(nodeToLoad, cancellationToken)); } - await ConstructNode(nodeToLoad, nodeIndex); + cancellationToken.ThrowIfCancellationRequested(); + await ConstructNode(nodeToLoad, nodeIndex, cancellationToken); } /// @@ -534,7 +541,7 @@ private async Task _LoadNode(int nodeIndex) /// /// The bufferIndex of scene in gltf file to load /// - protected async Task _LoadScene(int sceneIndex = -1, bool showSceneObj = true) + protected async Task _LoadScene(int sceneIndex = -1, bool showSceneObj = true, CancellationToken cancellationToken = default(CancellationToken)) { GLTFScene scene; @@ -552,7 +559,7 @@ protected async Task _LoadScene(int sceneIndex = -1, bool showSceneObj = true) throw new GLTFLoadException("No default scene in gltf file."); } - await ConstructScene(scene, showSceneObj); + await ConstructScene(scene, showSceneObj, cancellationToken); if (SceneParent != null) { @@ -745,7 +752,7 @@ protected void TransformAttributes(ref Dictionary att } } -#region Animation + #region Animation static string RelativePathFrom(Transform self, Transform root) { var path = new List(); @@ -1037,9 +1044,9 @@ public static void SetCurveMode(Keyframe[] keyframes, InterpolationType mode) key.outTangent = outtangent; } } -#endregion + #endregion - protected virtual async Task ConstructScene(GLTFScene scene, bool showSceneObj) + protected virtual async Task ConstructScene(GLTFScene scene, bool showSceneObj, CancellationToken cancellationToken) { var sceneObj = new GameObject(string.IsNullOrEmpty(scene.Name) ? ("GLTFScene") : scene.Name); sceneObj.SetActive(showSceneObj); @@ -1048,7 +1055,7 @@ protected virtual async Task ConstructScene(GLTFScene scene, bool showSceneObj) for (int i = 0; i < scene.Nodes.Count; ++i) { NodeId node = scene.Nodes[i]; - await _LoadNode(node.Id); + await _LoadNode(node.Id, cancellationToken); GameObject nodeObj = _assetCache.NodeCache[node.Id]; nodeObj.transform.SetParent(sceneObj.transform, false); nodeTransforms[i] = nodeObj.transform; @@ -1077,8 +1084,10 @@ protected virtual async Task ConstructScene(GLTFScene scene, bool showSceneObj) } - protected virtual async Task ConstructNode(Node node, int nodeIndex) + protected virtual async Task ConstructNode(Node node, int nodeIndex, CancellationToken cancellationToken) { + cancellationToken.ThrowIfCancellationRequested(); + if (_assetCache.NodeCache[nodeIndex] != null) { return; @@ -1098,7 +1107,7 @@ protected virtual async Task ConstructNode(Node node, int nodeIndex) if (node.Mesh != null) { - await ConstructMesh(node.Mesh.Value, nodeObj.transform, node.Mesh.Id, node.Skin != null ? node.Skin.Value : null); + await ConstructMesh(node.Mesh.Value, nodeObj.transform, node.Mesh.Id, node.Skin != null ? node.Skin.Value : null, cancellationToken); } /* TODO: implement camera (probably a flag to disable for VR as well) if (camera != null) @@ -1113,7 +1122,7 @@ protected virtual async Task ConstructNode(Node node, int nodeIndex) foreach (var child in node.Children) { // todo blgross: replace with an iterartive solution - await ConstructNode(child.Value, child.Id); + await ConstructNode(child.Value, child.Id, cancellationToken); GameObject childObj = _assetCache.NodeCache[child.Id]; childObj.transform.SetParent(nodeObj.transform, false); } @@ -1151,7 +1160,7 @@ protected virtual async Task ConstructNode(Node node, int nodeIndex) for (int i = 0; i < lodsextension.MeshIds.Count; i++) { int lodNodeId = lodsextension.MeshIds[i]; - await ConstructNode(_gltfRoot.Nodes[lodNodeId], lodNodeId); + await ConstructNode(_gltfRoot.Nodes[lodNodeId], lodNodeId, cancellationToken); int lodIndex = i + 1; GameObject lodNodeObj = _assetCache.NodeCache[lodNodeId]; lodNodeObj.transform.SetParent(lodGroupNodeObj.transform, false); @@ -1223,7 +1232,7 @@ protected virtual async Task SetupBones(Skin skin, MeshPrimitive primitive, Skin { if (_assetCache.NodeCache[skin.Joints[i].Id] == null) { - await ConstructNode(_gltfRoot.Nodes[skin.Joints[i].Id], skin.Joints[i].Id); + await ConstructNode(_gltfRoot.Nodes[skin.Joints[i].Id], skin.Joints[i].Id, CancellationToken.None); } bones[i] = _assetCache.NodeCache[skin.Joints[i].Id].transform; bindPoses[i] = gltfBindPoses[i].ToUnityMatrix4x4Convert(); @@ -1272,7 +1281,7 @@ private void NormalizeBoneWeightArray(Vector4[] weights) } } - protected virtual async Task ConstructMesh(GLTFMesh mesh, Transform parent, int meshId, Skin skin) + protected virtual async Task ConstructMesh(GLTFMesh mesh, Transform parent, int meshId, Skin skin, CancellationToken cancellationToken) { if (_assetCache.MeshCache[meshId] == null) { @@ -1281,6 +1290,8 @@ protected virtual async Task ConstructMesh(GLTFMesh mesh, Transform parent, int for (int i = 0; i < mesh.Primitives.Count; ++i) { + cancellationToken.ThrowIfCancellationRequested(); + var primitive = mesh.Primitives[i]; int materialIndex = primitive.Material != null ? primitive.Material.Id : -1; From 727637112896037806846934393e04b4f815e487 Mon Sep 17 00:00:00 2001 From: Robert Ferrese Date: Mon, 22 Apr 2019 09:27:39 -0700 Subject: [PATCH 21/41] Add image name to texture name --- UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs index 0a1de5c19..54c1ad8b9 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs @@ -630,7 +630,7 @@ protected async Task ConstructImage(GLTFImage image, int imageCacheIndex, bool m protected virtual async Task ConstructUnityTexture(Stream stream, bool markGpuOnly, bool isLinear, GLTFImage image, int imageCacheIndex) { Texture2D texture = new Texture2D(0, 0, TextureFormat.RGBA32, true, isLinear); - texture.name = nameof(GLTFSceneImporter); + texture.name = nameof(GLTFSceneImporter) + (image.Name != null ? ("." + image.Name) : ""); if (stream is MemoryStream) { @@ -1913,7 +1913,7 @@ protected virtual async Task ConstructTexture(GLTFTexture texture, int textureIn protected virtual void ConstructImageFromGLB(GLTFImage image, int imageCacheIndex) { var texture = new Texture2D(0, 0); - texture.name = nameof(GLTFSceneImporter); + texture.name = nameof(GLTFSceneImporter) + (image.Name != null ? ("." + image.Name) : ""); var bufferView = image.BufferView.Value; var data = new byte[bufferView.ByteLength]; From bf563f28c54d397a38e6301bc6f7cbfc66c6c7b3 Mon Sep 17 00:00:00 2001 From: Adam Mitchell <41760870+AdamMitchell-ms@users.noreply.github.com> Date: Mon, 22 Apr 2019 09:35:30 -0700 Subject: [PATCH 22/41] Update UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs Co-Authored-By: rferrese --- UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs index ff3dc87a5..92f0d198a 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs @@ -112,7 +112,7 @@ private void DestroyCachedData() MaterialCache[i] = null; } - // Destroy the cached textures + // Destroy the cached images for (int i = 0; i < ImageCache.Length; i++) { if (ImageCache[i] != null) From a1cdacbf1f8c60cac8ab162ac0df19bb04e8f691 Mon Sep 17 00:00:00 2001 From: Robert Ferrese Date: Mon, 22 Apr 2019 09:38:08 -0700 Subject: [PATCH 23/41] Change cancellation in ConstructMesh --- UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs index 12340866a..6de239bfb 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs @@ -1283,6 +1283,8 @@ private void NormalizeBoneWeightArray(Vector4[] weights) protected virtual async Task ConstructMesh(GLTFMesh mesh, Transform parent, int meshId, Skin skin, CancellationToken cancellationToken) { + cancellationToken.ThrowIfCancellationRequested(); + if (_assetCache.MeshCache[meshId] == null) { _assetCache.MeshCache[meshId] = new MeshCacheData[mesh.Primitives.Count]; @@ -1290,12 +1292,11 @@ protected virtual async Task ConstructMesh(GLTFMesh mesh, Transform parent, int for (int i = 0; i < mesh.Primitives.Count; ++i) { - cancellationToken.ThrowIfCancellationRequested(); - var primitive = mesh.Primitives[i]; int materialIndex = primitive.Material != null ? primitive.Material.Id : -1; await ConstructMeshPrimitive(primitive, meshId, i, materialIndex); + cancellationToken.ThrowIfCancellationRequested(); var primitiveObj = new GameObject("Primitive"); @@ -1316,6 +1317,7 @@ protected virtual async Task ConstructMesh(GLTFMesh mesh, Transform parent, int if (HasBones(skin)) { await SetupBones(skin, primitive, skinnedMeshRenderer, primitiveObj, curMesh); + cancellationToken.ThrowIfCancellationRequested(); } skinnedMeshRenderer.sharedMesh = curMesh; From 4d9782b7ae07b4a0fb881b4d34990bceadbf325e Mon Sep 17 00:00:00 2001 From: Adam Mitchell <41760870+AdamMitchell-ms@users.noreply.github.com> Date: Wed, 24 Apr 2019 14:42:40 -0700 Subject: [PATCH 24/41] Camera in test scenes now moves only when dragged (mousedown) and the movement math is cleaner and more accurate, and zoom is now exponential instead of linear. (#413) Also clean up some warnings around unused variables. --- .../Examples/OrbitCameraController.cs | 31 +++++++++++-------- .../UnityGLTF/Examples/UWPTestScene.unity | 7 +++-- .../Scripts/Tests/Editor/GLTFSceneTests.cs | 14 --------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs b/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs index 4fd81b667..8f0d7ce33 100644 --- a/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs +++ b/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs @@ -10,24 +10,31 @@ public class OrbitCameraController : MonoBehaviour public float distance = 5.0f; public float xSpeed = 120.0f; public float ySpeed = 120.0f; + public float zoomSpeed = 0.8f; - public float yMinLimit = -20f; - public float yMaxLimit = 80f; + public float yMinLimit = -85f; + public float yMaxLimit = 85f; public float distanceMin = .5f; - public float distanceMax = 15f; + public float distanceMax = 150f; private Rigidbody cameraRigidBody; float x = 0.0f; float y = 0.0f; + float prevMouseX; + float prevMouseY; + + Quaternion rotation; + // Use this for initialization void Start() { Vector3 angles = transform.eulerAngles; x = angles.y; y = angles.x; + rotation = Quaternion.Euler(y, x, 0); cameraRigidBody = GetComponent(); @@ -42,20 +49,18 @@ void LateUpdate() { if (target) { - x += Input.GetAxis("Mouse X") * xSpeed * distance * 0.02f; - y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; + if (Input.GetMouseButton(0)) + { + x += Input.GetAxis("Mouse X") * xSpeed * 0.06f; + y -= Input.GetAxis("Mouse Y") * ySpeed * 0.06f; - y = ClampAngle(y, yMinLimit, yMaxLimit); + y = ClampAngle(y, yMinLimit, yMaxLimit); - Quaternion rotation = Quaternion.Euler(y, x, 0); + rotation = Quaternion.Euler(y, x, 0); + } - distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * 5, distanceMin, distanceMax); + distance = Mathf.Clamp(distance * Mathf.Exp(-Input.GetAxis("Mouse ScrollWheel") * zoomSpeed), distanceMin, distanceMax); - RaycastHit hit; - if (Physics.Linecast(target.position, transform.position, out hit)) - { - distance -= hit.distance; - } Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance); Vector3 position = rotation * negDistance + target.position; diff --git a/UnityGLTF/Assets/UnityGLTF/Examples/UWPTestScene.unity b/UnityGLTF/Assets/UnityGLTF/Examples/UWPTestScene.unity index c1dc1d190..1e609f5c6 100644 --- a/UnityGLTF/Assets/UnityGLTF/Examples/UWPTestScene.unity +++ b/UnityGLTF/Assets/UnityGLTF/Examples/UWPTestScene.unity @@ -306,10 +306,11 @@ MonoBehaviour: distance: 5 xSpeed: 120 ySpeed: 120 - yMinLimit: -20 - yMaxLimit: 80 + zoomSpeed: 0.8 + yMinLimit: -85 + yMaxLimit: 85 distanceMin: 0.5 - distanceMax: 15 + distanceMax: 150 --- !u!81 &1650054228 AudioListener: m_ObjectHideFlags: 0 diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/GLTFSceneTests.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/GLTFSceneTests.cs index d5c968464..60b038b85 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/GLTFSceneTests.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/GLTFSceneTests.cs @@ -1,22 +1,14 @@ #if UNITY_EDITOR -using AssetGenerator; -using Newtonsoft.Json; -using NUnit.Compatibility; using NUnit.Framework; using System; using System.Collections; using System.Collections.Generic; using System.IO; -using System.Linq; -using UnityEditor.SceneManagement; using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.Rendering; using UnityEngine.SceneManagement; using UnityEngine.TestTools; using UnityGLTF; using Camera = UnityEngine.Camera; -using Object = System.Object; public class GLTFSceneTests { @@ -24,10 +16,6 @@ public class GLTFSceneTests static string GLTF_SCENARIO_OUTPUT_PATH = Application.dataPath + "/../ScenarioScenesTests/Output/"; private static bool GENERATE_REFERENCEDATA = false; - private Dictionary cameras = - new Dictionary(); - - public static IEnumerable SceneFilePaths { get @@ -37,10 +25,8 @@ public static IEnumerable SceneFilePaths string[] files = Directory.GetFiles(GLTF_SCENES_PATH, "*.unity", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { - string filename = Path.GetFileNameWithoutExtension(files[i]); var fileUri = new Uri(files[i]); files[i] = gltfPathUri.MakeRelativeUri(fileUri).ToString(); - } return files; } From f97889a9cc6a87545a04a342e6e05542b36bcb5f Mon Sep 17 00:00:00 2001 From: Adam Mitchell <41760870+AdamMitchell-ms@users.noreply.github.com> Date: Fri, 26 Apr 2019 09:42:08 -0700 Subject: [PATCH 25/41] Fix loading time issue (#414) * Simplify AsyncCoroutineHelper * revert default budget --- .../Scripts/Async/AsyncCoroutineHelper.cs | 121 +++++------------- .../UnityGLTF/Scripts/GLTFSceneImporter.cs | 2 +- 2 files changed, 33 insertions(+), 90 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Async/AsyncCoroutineHelper.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Async/AsyncCoroutineHelper.cs index 8e304ea2e..d1ea3437b 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Async/AsyncCoroutineHelper.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Async/AsyncCoroutineHelper.cs @@ -2,95 +2,38 @@ using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; + namespace UnityGLTF { - public interface IAsyncCoroutineHelper - { - Task RunAsTask(IEnumerator coroutine, string name); - Task YieldOnTimeout(); - } - - public class AsyncCoroutineHelper : MonoBehaviour, IAsyncCoroutineHelper - { - public float BudgetPerFrameInSeconds = 0.01f; - - private Queue _actions = new Queue(); - private WaitForEndOfFrame _waitForEndOfFrame = new WaitForEndOfFrame(); - private float _timeout; - - public Task RunAsTask(IEnumerator coroutine, string name) - { - TaskCompletionSource tcs = new TaskCompletionSource(); - lock (_actions) - { - _actions.Enqueue( - new CoroutineInfo - { - Coroutine = coroutine, - Tcs = tcs, - Name = name - } - ); - } - - return tcs.Task; - } - - public async Task YieldOnTimeout() - { - if (Time.realtimeSinceStartup > _timeout) - { - await RunAsTask(EmptyYieldEnum(), nameof(EmptyYieldEnum)); - } - } - - private void Start() - { - _timeout = Time.realtimeSinceStartup + BudgetPerFrameInSeconds; - } - - private void Update() - { - StartCoroutine(ResetFrameTimeout()); - - CoroutineInfo ? coroutineInfo = null; - - lock (_actions) - { - if (_actions.Count > 0) - { - coroutineInfo = _actions.Dequeue(); - } - } - - if (coroutineInfo != null) - { - StartCoroutine(CallMethodOnMainThread(coroutineInfo.Value)); - } - } - - private IEnumerator CallMethodOnMainThread(CoroutineInfo coroutineInfo) - { - yield return coroutineInfo.Coroutine; - coroutineInfo.Tcs.SetResult(true); - } - - private IEnumerator EmptyYieldEnum() - { - yield break; - } - - private IEnumerator ResetFrameTimeout() - { - yield return _waitForEndOfFrame; - _timeout = Time.realtimeSinceStartup + BudgetPerFrameInSeconds; - } - - private struct CoroutineInfo - { - public IEnumerator Coroutine; - public TaskCompletionSource Tcs; - public string Name; - } - } + public class AsyncCoroutineHelper : MonoBehaviour + { + public float BudgetPerFrameInSeconds = 0.01f; + + private WaitForEndOfFrame _waitForEndOfFrame = new WaitForEndOfFrame(); + private float _timeout; + + public async Task YieldOnTimeout() + { + if (Time.realtimeSinceStartup > _timeout) + { + await Task.Delay(1); + } + } + + private void Start() + { + _timeout = Time.realtimeSinceStartup + BudgetPerFrameInSeconds; + + StartCoroutine(ResetFrameTimeout()); + } + + private IEnumerator ResetFrameTimeout() + { + while (true) + { + yield return _waitForEndOfFrame; + _timeout = Time.realtimeSinceStartup + BudgetPerFrameInSeconds; + } + } + } } diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs index 0fc527cef..97e18a499 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs @@ -136,7 +136,7 @@ protected struct GLBStream public long StartPosition; } - protected IAsyncCoroutineHelper _asyncCoroutineHelper; + protected AsyncCoroutineHelper _asyncCoroutineHelper; protected GameObject _lastLoadedScene; protected readonly GLTFMaterial DefaultMaterial = new GLTFMaterial(); From ca479b55061bb5e1c60c302e6e322c25981c0516 Mon Sep 17 00:00:00 2001 From: admachina <1181494+admachina@users.noreply.github.com> Date: Mon, 29 Apr 2019 13:29:08 -0700 Subject: [PATCH 26/41] Add missing meta file for integration test directory (#419) --- UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta new file mode 100644 index 000000000..234623f56 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6b8a4635652423a409aba4569b5a5b92 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From e04883a873da9a34c739e2822a530bc32cac2ce6 Mon Sep 17 00:00:00 2001 From: Adam Mitchell <41760870+AdamMitchell-ms@users.noreply.github.com> Date: Tue, 30 Apr 2019 16:26:17 -0700 Subject: [PATCH 27/41] Add a component to display the list of models from gltf-Sample-Models and let you load them (#420) * Add a component to display the list of sample models and let you load them at runtime. * Some improvements to the model list loader and adding a main scene to host it * Fix warning suppression * Address pr feedback. Remove commented line. Give a nice error if the model list json fails to download. Also improve orbit camera so that scrolling the other list doesn't cause it to zoom. --- UnityGLTF/Assets/Main.unity | 546 ++++++++++++++++++ UnityGLTF/Assets/Main.unity.meta | 7 + .../Examples/OrbitCameraController.cs | 17 +- .../Assets/UnityGLTF/Scripts/GLTFComponent.cs | 3 + .../Tests/Editor/SampleModelListInspector.cs | 111 ++++ .../Editor/SampleModelListInspector.cs.meta | 11 + .../Tests/Editor/SampleModelListParser.cs | 155 +++++ .../Editor/SampleModelListParser.cs.meta | 11 + .../Scripts/Tests/SampleModelList.cs | 45 ++ .../Scripts/Tests/SampleModelList.cs.meta | 11 + 10 files changed, 913 insertions(+), 4 deletions(-) create mode 100644 UnityGLTF/Assets/Main.unity create mode 100644 UnityGLTF/Assets/Main.unity.meta create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListInspector.cs create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListInspector.cs.meta create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListParser.cs create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListParser.cs.meta create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/SampleModelList.cs create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/SampleModelList.cs.meta diff --git a/UnityGLTF/Assets/Main.unity b/UnityGLTF/Assets/Main.unity new file mode 100644 index 000000000..711c40193 --- /dev/null +++ b/UnityGLTF/Assets/Main.unity @@ -0,0 +1,546 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 8 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.45030367, g: 0.49799693, b: 0.56280375, a: 1} +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 11 + m_GIWorkflowMode: 0 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_TemporalCoherenceThreshold: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 1 + m_LightmapEditorSettings: + serializedVersion: 9 + m_Resolution: 2 + m_BakeResolution: 40 + m_TextureWidth: 1024 + m_TextureHeight: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_MixedBakeMode: 1 + m_BakeBackend: 0 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 500 + m_PVRBounces: 2 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVRFilteringMode: 1 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ShowResolutionOverlay: 1 + m_LightingDataAsset: {fileID: 0} + m_UseShadowmask: 1 +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1001 &10002063 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_RootOrder + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 114000010638385648, guid: 5255039e40b37b14fbcc0b72a30fc62e, + type: 2} + propertyPath: Url + value: http://localhost:8080/glTF-Sample-Models/2.0/AnimatedCube/glTF/AnimatedCube.gltf + objectReference: {fileID: 0} + - target: {fileID: 114000010638385648, guid: 5255039e40b37b14fbcc0b72a30fc62e, + type: 2} + propertyPath: GLTFStandard + value: + objectReference: {fileID: 4800000, guid: a5732b1b5b2e36d47a3da75e187eba06, type: 3} + - target: {fileID: 114000010638385648, guid: 5255039e40b37b14fbcc0b72a30fc62e, + type: 2} + propertyPath: Multithreaded + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 114000010638385648, guid: 5255039e40b37b14fbcc0b72a30fc62e, + type: 2} + propertyPath: GLTFUri + value: + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalScale.x + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalScale.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + propertyPath: m_LocalScale.z + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 114000010638385648, guid: 5255039e40b37b14fbcc0b72a30fc62e, + type: 2} + propertyPath: loadOnStart + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: 5255039e40b37b14fbcc0b72a30fc62e, type: 2} + m_IsPrefabParent: 0 +--- !u!4 &10002064 stripped +Transform: + m_PrefabParentObject: {fileID: 4000011406631220, guid: 5255039e40b37b14fbcc0b72a30fc62e, + type: 2} + m_PrefabInternal: {fileID: 10002063} +--- !u!114 &10002067 stripped +MonoBehaviour: + m_PrefabParentObject: {fileID: 114000010638385648, guid: 5255039e40b37b14fbcc0b72a30fc62e, + type: 2} + m_PrefabInternal: {fileID: 10002063} + m_Script: {fileID: 11500000, guid: 9087a95f22bcee64ebc45f6deec08714, type: 3} +--- !u!1 &328853373 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 100002, guid: 49a0e923d39ec3c4c8bb97699e2f2903, type: 2} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 328853379} + - component: {fileID: 328853378} + - component: {fileID: 328853376} + - component: {fileID: 328853375} + - component: {fileID: 328853374} + m_Layer: 0 + m_Name: Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &328853374 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 328853373} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 70ff706d2c89cc247a850af95597fcbb, type: 3} + m_Name: + m_EditorClassIdentifier: + target: {fileID: 10002064} + distance: 5 + xSpeed: 120 + ySpeed: 120 + zoomSpeed: 0.8 + yMinLimit: -80 + yMaxLimit: 80 + distanceMin: 0.05 + distanceMax: 500 +--- !u!81 &328853375 +AudioListener: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 8100000, guid: 49a0e923d39ec3c4c8bb97699e2f2903, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 328853373} + m_Enabled: 1 +--- !u!124 &328853376 +Behaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 12400000, guid: 49a0e923d39ec3c4c8bb97699e2f2903, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 328853373} + m_Enabled: 1 +--- !u!20 &328853378 +Camera: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 2000000, guid: 49a0e923d39ec3c4c8bb97699e2f2903, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 328853373} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.62552905, g: 0.684092, b: 0.7761194, a: 0.019607844} + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.02 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 100 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 0 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &328853379 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 400002, guid: 49a0e923d39ec3c4c8bb97699e2f2903, type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 328853373} + m_LocalRotation: {x: -0, y: 1, z: -0, w: -0.000000063325004} + m_LocalPosition: {x: 0, y: 0, z: 2} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &979359784 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 979359786} + - component: {fileID: 979359785} + m_Layer: 0 + m_Name: Server + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &979359785 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 979359784} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 946dbe02f30bd734c901251fcc62a97a, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &979359786 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 979359784} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1013584300 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1013584302} + - component: {fileID: 1013584301} + m_Layer: 0 + m_Name: Model List + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1013584301 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1013584300} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: df99c459245b3cd40be06aca24a19170, type: 3} + m_Name: + m_EditorClassIdentifier: + loader: {fileID: 10002067} + pathRoot: http://localhost:8080/glTF-Sample-Models/2.0/ + manifestRelativePath: model-index.json + modelRelativePath: + loadThisFrame: 0 +--- !u!4 &1013584302 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1013584300} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1667736112 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1667736114} + - component: {fileID: 1667736113} + m_Layer: 0 + m_Name: Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &1667736113 +Light: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1667736112} + m_Enabled: 1 + serializedVersion: 8 + m_Type: 1 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} + m_Intensity: 1.3 + m_Range: 10 + m_SpotAngle: 30 + m_CookieSize: 10 + m_Shadows: + m_Type: 2 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_Lightmapping: 4 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &1667736114 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1667736112} + m_LocalRotation: {x: 0.048932634, y: 0.9485057, z: -0.18261904, w: 0.2541514} + m_LocalPosition: {x: 3.56, y: 5.64, z: 6.41} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 21.796001, y: 150, z: 0} +--- !u!1 &1904599574 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1904599578} + - component: {fileID: 1904599577} + - component: {fileID: 1904599576} + - component: {fileID: 1904599575} + m_Layer: 0 + m_Name: Floor + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!23 &1904599575 +MeshRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1904599574} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 1 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!64 &1904599576 +MeshCollider: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1904599574} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Convex: 0 + m_CookingOptions: 14 + m_SkinWidth: 0.01 + m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} +--- !u!33 &1904599577 +MeshFilter: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1904599574} + m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1904599578 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1904599574} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: -0.778, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/UnityGLTF/Assets/Main.unity.meta b/UnityGLTF/Assets/Main.unity.meta new file mode 100644 index 000000000..8ab405a13 --- /dev/null +++ b/UnityGLTF/Assets/Main.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 4b3020fb0b0588247a945afb3e2d8de7 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs b/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs index 8f0d7ce33..071071fe7 100644 --- a/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs +++ b/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs @@ -23,9 +23,6 @@ public class OrbitCameraController : MonoBehaviour float x = 0.0f; float y = 0.0f; - float prevMouseX; - float prevMouseY; - Quaternion rotation; // Use this for initialization @@ -59,7 +56,19 @@ void LateUpdate() rotation = Quaternion.Euler(y, x, 0); } - distance = Mathf.Clamp(distance * Mathf.Exp(-Input.GetAxis("Mouse ScrollWheel") * zoomSpeed), distanceMin, distanceMax); + var height = Display.main.renderingHeight; + var width = Display.main.renderingWidth; + + var mouseOverRenderArea = + Input.mousePosition.x >= 0 && + Input.mousePosition.x <= width && + Input.mousePosition.y >= 0 && + Input.mousePosition.y <= height; + + if (Input.GetMouseButton(0) || mouseOverRenderArea) + { + distance = Mathf.Clamp(distance * Mathf.Exp(-Input.GetAxis("Mouse ScrollWheel") * zoomSpeed), distanceMin, distanceMax); + } Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance); Vector3 position = rotation * negDistance + target.position; diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFComponent.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFComponent.cs index 0e8b17948..6f037163b 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFComponent.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFComponent.cs @@ -35,6 +35,7 @@ public class GLTFComponent : MonoBehaviour public int MaximumLod = 300; public int Timeout = 8; public GLTFSceneImporter.ColliderType Collider = GLTFSceneImporter.ColliderType.None; + public GameObject LastLoadedScene { get; private set; } = null; private AsyncCoroutineHelper asyncCoroutineHelper; @@ -137,6 +138,8 @@ public async Task Load() } } + LastLoadedScene = sceneImporter.LastLoadedScene; + if (PlayAnimationOnLoad) { Animation[] animations = sceneImporter.LastLoadedScene.GetComponents(); diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListInspector.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListInspector.cs new file mode 100644 index 000000000..c31b14d8c --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListInspector.cs @@ -0,0 +1,111 @@ +using Newtonsoft.Json; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using UnityEditor; +using UnityEngine; +using UnityGLTF.Loader; + +[CustomEditor(typeof(SampleModelList))] +public class SampleModelListInspector : Editor +{ + private List models = null; + private bool requestedModelList = false; + private Vector2 scroll = Vector2.zero; + private SampleModel currentModel = null; + + public override void OnInspectorGUI() + { + EditorGUILayout.PropertyField(serializedObject.FindProperty(SampleModelList.LoaderFieldName)); + EditorGUILayout.PropertyField(serializedObject.FindProperty(SampleModelList.PathRootFieldName)); + EditorGUILayout.PropertyField(serializedObject.FindProperty(SampleModelList.ManifestRelativePathFieldName)); + EditorGUILayout.PropertyField(serializedObject.FindProperty(SampleModelList.ModelRelativePathFieldName)); + EditorGUILayout.PropertyField(serializedObject.FindProperty(SampleModelList.LoadThisFrameFieldName)); + + serializedObject.ApplyModifiedProperties(); + + if (!Application.isPlaying) + { + models = null; + requestedModelList = false; + scroll = Vector2.zero; + } + else + { + if (!requestedModelList) + { + requestedModelList = true; + + DownloadSampleModelList(); + } + + EditorGUILayout.LabelField("Models:"); + + if (models != null) + { + scroll = EditorGUILayout.BeginScrollView(scroll); + + foreach (var model in models) + { + EditorGUILayout.BeginHorizontal(); + GUIStyle style = new GUIStyle(GUI.skin.label); + if (model == currentModel) + { + style.fontStyle = FontStyle.Bold; + } + GUILayout.Label(model.Name, style); + + foreach (var variant in model.Variants) + { + var buttonPressed = GUILayout.Button(variant.Type); + + if (buttonPressed) + { + currentModel = model; + LoadModel(model.Name, variant.Type, variant.FileName); + } + } + + EditorGUILayout.EndHorizontal(); + } + + EditorGUILayout.EndScrollView(); + } + } + } + + private void LoadModel(string modelName, string variantType, string variantName) + { + string relativePath = $"{modelName}/{variantType}/{variantName}"; + + serializedObject.FindProperty(SampleModelList.ModelRelativePathFieldName).stringValue = relativePath; + serializedObject.FindProperty(SampleModelList.LoadThisFrameFieldName).boolValue = true; + serializedObject.ApplyModifiedProperties(); + } + + private async void DownloadSampleModelList() + { + var pathRoot = serializedObject.FindProperty(SampleModelList.PathRootFieldName).stringValue; + var manifestRelativePath = serializedObject.FindProperty(SampleModelList.ManifestRelativePathFieldName).stringValue; + + var loader = new WebRequestLoader(pathRoot); + try + { + await loader.LoadStream(manifestRelativePath); + } + catch (HttpRequestException) + { + Debug.LogError($"Failed to download sample model list manifest from: {pathRoot}{manifestRelativePath}", serializedObject.targetObject); + throw; + } + + loader.LoadedStream.Seek(0, SeekOrigin.Begin); + + var streamReader = new StreamReader(loader.LoadedStream); + + var reader = new JsonTextReader(streamReader); + + reader.Read(); + models = SampleModelListParser.ParseSampleModels(reader); + } +} diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListInspector.cs.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListInspector.cs.meta new file mode 100644 index 000000000..61712a23b --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f28130cf15191b44ea20112e38fb9a6c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListParser.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListParser.cs new file mode 100644 index 000000000..5fbfd73cb --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListParser.cs @@ -0,0 +1,155 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; + +public class SampleModelVariant +{ + public string Type; + public string FileName; +} + +public class SampleModel +{ + public string Name; + public string ScreenshotPath; + public List Variants; +} + +public static class SampleModelListParser +{ + public static List ParseSampleModels(JsonReader reader) + { + var models = new List(); + + ParseStartArray(reader, "models"); + + while (reader.TokenType != JsonToken.EndArray) + { + models.Add(ParseSampleModel(reader)); + } + + ParseEndArray(reader, "models"); + + return models; + } + + private static SampleModel ParseSampleModel(JsonReader reader) + { + var result = new SampleModel(); + + ParseStartObject(reader, "model"); + + while (reader.TokenType != JsonToken.EndObject) + { + if (reader.TokenType != JsonToken.PropertyName) + { + throw new Exception("Failed to parse model name property"); + } + var propertyName = reader.Value.ToString().ToLowerInvariant(); + reader.Read(); + + switch (propertyName) + { + case "name": + result.Name = ParsePropertyValueAsString(reader, propertyName); + break; + case "screenshot": + result.ScreenshotPath = ParsePropertyValueAsString(reader, propertyName); + break; + case "variants": + result.Variants = ParseVariants(reader); + break; + } + } + + ParseEndObject(reader, "model"); + + return result; + } + + private static string ParsePropertyValueAsString(JsonReader reader, string propertyName) + { + if (reader.TokenType != JsonToken.String) + { + throw new Exception($"Failed to parse string value for {propertyName}"); + } + var result = reader.Value.ToString(); + + reader.Read(); + + return result; + } + + private static List ParseVariants(JsonReader reader) + { + var variants = new List(); + + ParseStartObject(reader, "variants"); + + while (reader.TokenType != JsonToken.EndObject) + { + variants.Add(ParseVariant(reader)); + } + + ParseEndObject(reader, "variants"); + + return variants; + } + + private static SampleModelVariant ParseVariant(JsonReader reader) + { + var result = new SampleModelVariant(); + + if (reader.TokenType != JsonToken.PropertyName) + { + throw new Exception("Failed to parse model variant name"); + } + result.Type = reader.Value.ToString(); + reader.Read(); + + if (reader.TokenType != JsonToken.String) + { + throw new Exception("Failed to parse model variant filename"); + } + result.FileName = reader.Value.ToString(); + reader.Read(); + + return result; + } + + private static void ParseStartObject(JsonReader reader, string objectName) + { + if (reader.TokenType != JsonToken.StartObject) + { + throw new Exception($"Failed to parse {objectName} start"); + } + reader.Read(); + } + + private static void ParseEndObject(JsonReader reader, string objectName) + { + if (reader.TokenType != JsonToken.EndObject) + { + throw new Exception($"Failed to parse {objectName} end"); + } + reader.Read(); + } + + private static void ParseStartArray(JsonReader reader, string objectName) + { + if (reader.TokenType != JsonToken.StartArray) + { + throw new Exception($"Failed to parse {objectName} start"); + } + reader.Read(); + } + + private static void ParseEndArray(JsonReader reader, string objectName) + { + if (reader.TokenType != JsonToken.EndArray) + { + throw new Exception($"Failed to parse {objectName} end"); + } + reader.Read(); + } +} diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListParser.cs.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListParser.cs.meta new file mode 100644 index 000000000..0adfd8ab6 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/SampleModelListParser.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59a81a17ba63ebb4a9897bfeb7693a26 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/SampleModelList.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/SampleModelList.cs new file mode 100644 index 000000000..7efd839cf --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/SampleModelList.cs @@ -0,0 +1,45 @@ +using UnityEngine; +using UnityGLTF; + +public class SampleModelList : MonoBehaviour +{ + public static string LoaderFieldName => nameof(loader); + public static string PathRootFieldName => nameof(pathRoot); + public static string ManifestRelativePathFieldName => nameof(manifestRelativePath); + public static string ModelRelativePathFieldName => nameof(modelRelativePath); + public static string LoadThisFrameFieldName => nameof(loadThisFrame); + + [SerializeField] + private GLTFComponent loader = null; + + [SerializeField] + private string pathRoot = "http://localhost:8080/glTF-Sample-Models/2.0/"; + +// Disable "unused private field" because it is accessed by SampleModelListInspector using serialization. +#pragma warning disable 414 + [SerializeField] + private string manifestRelativePath = "model-index.json"; +#pragma warning restore 414 + + [SerializeField] + private string modelRelativePath = null; + + [SerializeField] + private bool loadThisFrame = false; + + private async void Update() + { + if (loadThisFrame) + { + loadThisFrame = false; + + var path = pathRoot + modelRelativePath; + if (loader.LastLoadedScene != null) + { + Destroy(loader.LastLoadedScene); + } + loader.GLTFUri = path; + await loader.Load(); + } + } +} diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/SampleModelList.cs.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/SampleModelList.cs.meta new file mode 100644 index 000000000..ba6d16c48 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/SampleModelList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: df99c459245b3cd40be06aca24a19170 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 740bbb8edb2c9ad789451b1110a2252e2509bff8 Mon Sep 17 00:00:00 2001 From: Adam Mitchell <41760870+AdamMitchell-ms@users.noreply.github.com> Date: Fri, 3 May 2019 16:57:27 -0700 Subject: [PATCH 28/41] OrbitCamera now supports right mouse buttons to change position (#422) * right mouse camera controls * More accurate right click mouse motion --- .../Examples/OrbitCameraController.cs | 76 ++++++++++++------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs b/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs index 071071fe7..a3d678389 100644 --- a/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs +++ b/UnityGLTF/Assets/UnityGLTF/Examples/OrbitCameraController.cs @@ -3,10 +3,11 @@ // Taken from http://wiki.unity3d.com/index.php?title=MouseOrbitImproved namespace UnityGLTF.Examples { + [RequireComponent(typeof(Camera))] [AddComponentMenu("Camera-Control/Mouse Orbit with zoom")] public class OrbitCameraController : MonoBehaviour { - public Transform target; + public Vector3 targetPosition = Vector3.zero; public float distance = 5.0f; public float xSpeed = 120.0f; public float ySpeed = 120.0f; @@ -18,21 +19,28 @@ public class OrbitCameraController : MonoBehaviour public float distanceMin = .5f; public float distanceMax = 150f; + private Camera camera; + private Rigidbody cameraRigidBody; - float x = 0.0f; - float y = 0.0f; + private float x = 0.0f; + private float y = 0.0f; + private Vector3 prevMousePosition; Quaternion rotation; // Use this for initialization void Start() { + camera = GetComponent(); + Vector3 angles = transform.eulerAngles; x = angles.y; y = angles.x; rotation = Quaternion.Euler(y, x, 0); + prevMousePosition = Input.mousePosition; + cameraRigidBody = GetComponent(); // Make the rigid body not change rotation @@ -44,38 +52,52 @@ void Start() void LateUpdate() { - if (target) + var height = Display.main.renderingHeight; + var width = Display.main.renderingWidth; + + if (Input.GetMouseButton(0)) { - if (Input.GetMouseButton(0)) - { - x += Input.GetAxis("Mouse X") * xSpeed * 0.06f; - y -= Input.GetAxis("Mouse Y") * ySpeed * 0.06f; + x += Input.GetAxis("Mouse X") * xSpeed * 0.06f; + y -= Input.GetAxis("Mouse Y") * ySpeed * 0.06f; - y = ClampAngle(y, yMinLimit, yMaxLimit); + y = ClampAngle(y, yMinLimit, yMaxLimit); - rotation = Quaternion.Euler(y, x, 0); - } + rotation = Quaternion.Euler(y, x, 0); + } + else if (Input.GetMouseButton(1)) + { + var prevMouseWorldPosition = ProjectScreenPointToTargetPlane(prevMousePosition); + var mouseWorldPosition = ProjectScreenPointToTargetPlane(Input.mousePosition); - var height = Display.main.renderingHeight; - var width = Display.main.renderingWidth; + targetPosition += prevMouseWorldPosition - mouseWorldPosition; + } - var mouseOverRenderArea = - Input.mousePosition.x >= 0 && - Input.mousePosition.x <= width && - Input.mousePosition.y >= 0 && - Input.mousePosition.y <= height; + var mouseOverRenderArea = + Input.mousePosition.x >= 0 && + Input.mousePosition.x <= width && + Input.mousePosition.y >= 0 && + Input.mousePosition.y <= height; - if (Input.GetMouseButton(0) || mouseOverRenderArea) - { - distance = Mathf.Clamp(distance * Mathf.Exp(-Input.GetAxis("Mouse ScrollWheel") * zoomSpeed), distanceMin, distanceMax); - } + if (Input.GetMouseButton(0) || mouseOverRenderArea) + { + distance = Mathf.Clamp(distance * Mathf.Exp(-Input.GetAxis("Mouse ScrollWheel") * zoomSpeed), distanceMin, distanceMax); + } - Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance); - Vector3 position = rotation * negDistance + target.position; + Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance); + Vector3 position = rotation * negDistance + targetPosition; - transform.rotation = rotation; - transform.position = position; - } + transform.rotation = rotation; + transform.position = position; + + prevMousePosition = Input.mousePosition; + } + + private Vector3 ProjectScreenPointToTargetPlane(Vector3 screenPosition) + { + var ray = camera.ScreenPointToRay(screenPosition); + var planeDistance = distance / Mathf.Cos(Mathf.Deg2Rad * Vector3.Angle(camera.transform.forward, ray.direction)); + + return camera.transform.position + (ray.direction * planeDistance); } public static float ClampAngle(float angle, float min, float max) From eaebdb03c459cff98814ac4ad869ea22fb00e152 Mon Sep 17 00:00:00 2001 From: Adam Mitchell <41760870+AdamMitchell-ms@users.noreply.github.com> Date: Fri, 3 May 2019 16:57:52 -0700 Subject: [PATCH 29/41] Set the correct filter mode when loading texture samplers (#421) --- UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs index 97e18a499..c4758c85a 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs @@ -1870,11 +1870,11 @@ protected virtual async Task ConstructTexture(GLTFTexture texture, int textureIn { case MinFilterMode.Nearest: case MinFilterMode.NearestMipmapNearest: - case MinFilterMode.NearestMipmapLinear: + case MinFilterMode.LinearMipmapNearest: desiredFilterMode = FilterMode.Point; break; case MinFilterMode.Linear: - case MinFilterMode.LinearMipmapNearest: + case MinFilterMode.NearestMipmapLinear: desiredFilterMode = FilterMode.Bilinear; break; case MinFilterMode.LinearMipmapLinear: From 03d7894d23a3bff65dacf5a23ede3a3a43704e50 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Sat, 6 Apr 2019 00:49:36 -0400 Subject: [PATCH 30/41] Include .asmdef files for correct UPM package generation --- .../Scripts/Tests/UnityGLTFTests.asmdef | 16 ++++++++++++++++ .../Scripts/Tests/UnityGLTFTests.asmdef.meta | 7 +++++++ .../UnityGLTF/Scripts/UnityGLTFScripts.asmdef | 3 +++ .../Scripts/UnityGLTFScripts.asmdef.meta | 7 +++++++ 4 files changed, 33 insertions(+) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef new file mode 100644 index 000000000..77a847114 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -0,0 +1,16 @@ +{ + "name": "UnityGLTFTests", + "references": [ + "UnityGLTFScripts" + ], + "optionalUnityReferences": [ + "TestAssemblies" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta new file mode 100644 index 000000000..ff76efede --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e5407060e0b39404cacbd1741581df2b +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef new file mode 100644 index 000000000..d949e7774 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef @@ -0,0 +1,3 @@ +{ + "name": "UnityGLTFScripts" +} diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta new file mode 100644 index 000000000..5ef7d0474 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/UnityGLTFScripts.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 18d18f811ba286c49814567a3cfba688 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 6752e0931bf459723a76dd81fe68ad5d834ea9ce Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:45:16 -0400 Subject: [PATCH 31/41] Fix missing Integrations .meta file position --- .../UnityGLTF/Scripts/Tests/Editor/Integration.meta | 9 --------- .../Assets/UnityGLTF/Scripts/Tests/Integration.meta | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta deleted file mode 100644 index ab5ce21da..000000000 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Editor/Integration.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: e1c2c4a5d74bb304f8208a98cc16db22 -folderAsset: yes -timeCreated: 1506549706 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta index 234623f56..55750aa52 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6b8a4635652423a409aba4569b5a5b92 +guid: 5783cb7e53a767047b9bbec12c1cd4cf folderAsset: yes DefaultImporter: externalObjects: {} From d11a94093f1325aea3020576d3c33b0b8ea87768 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:52:47 -0400 Subject: [PATCH 32/41] Splitting out UnityGLTFEditor scripts with its own asmdef file --- .../Scripts/Editor/UnityGLTFEditor.asmdef | 16 ++++++++++++++++ .../Scripts/Editor/UnityGLTFEditor.asmdef.meta | 7 +++++++ .../Scripts/Tests/UnityGLTFTests.asmdef | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef new file mode 100644 index 000000000..c9a3347a7 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef @@ -0,0 +1,16 @@ +{ + "name": "UnityGLTFEditor", + "references": [ + "UnityGLTFScripts" + ], + "optionalUnityReferences": [], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [] +} \ No newline at end of file diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta new file mode 100644 index 000000000..68e4ef64f --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Editor/UnityGLTFEditor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1a0324566af4ed544918d6837a1f4e11 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef index 77a847114..f5674c3bd 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -1,7 +1,8 @@ { "name": "UnityGLTFTests", "references": [ - "UnityGLTFScripts" + "UnityGLTFScripts", + "UnityGLTFEditor" ], "optionalUnityReferences": [ "TestAssemblies" From ff148a9d402f10beeb2acaf5315a0735e37ad09c Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:57:48 -0400 Subject: [PATCH 33/41] Build script updates to properly support UWP with UPM compliant package --- .travis.yml | 3 ++- scripts/export-upm-package.sh | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b4b2855d..7e9b52d53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,9 @@ before_script: - sudo chmod +x ./scripts/export-upm-package.sh script: - msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization /p:TargetFramework=net35 -- "./scripts/export-upm-package.sh" - "./scripts/export-unity-package.sh" +- msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization +- "./scripts/export-upm-package.sh" deploy: provider: releases file: diff --git a/scripts/export-upm-package.sh b/scripts/export-upm-package.sh index d1fcc202b..f3bcdde19 100644 --- a/scripts/export-upm-package.sh +++ b/scripts/export-upm-package.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash project_path=$(pwd)/UnityGLTF log_file=$(pwd)/build/unity-mac.log @@ -8,9 +8,22 @@ upm_name=org.khronos.UnityGLTF upm_src_folder_path=$(pwd)/UnityGLTF/Assets/UnityGLTF upm_manifest_path=$(pwd)/scripts/package.json upm_staging_path=$(pwd)/current-package/$upm_name +upm_staging_UWP_plugins_path=$upm_staging_path/Plugins/uap10.0.10586 upm_zip_export_path=$(pwd)/current-package/$upm_name.zip upm_targz_export_path=$(pwd)/current-package/$upm_name.tar.gz +# msbuild spits out every single dependency dll for UWP +# These are the only files that are needed by the UPM package for Unity 2018.3+ +# Including all the files in the UWP plugin directory causes name collision errors when +# building for UWP in Unity +upm_UWP_Plugins=( + "GLTFSerialization.dll" + "GLTFSerialization.dll.meta" + "GLTFSerialization.pdb" + "Newtonsoft.Json.dll" + "Newtonsoft.Json.dll.meta" +) + error_code=0 echo $upm_name echo $upm_src_folder_path @@ -28,14 +41,20 @@ cp -r $upm_src_folder_path $upm_staging_path echo "Changing to $upm_staging_path folder" cd $upm_staging_path +echo "Cleaning out UWP plugin DLLs that are not needed for Unity2018.3+" +echo "Only keeping the following files:" +printf '%s\n' "${upm_UWP_Plugins[@]}" +find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs -r rm + echo "Creating .zip of UPM package" -sudo zip -r $upm_zip_export_path ./ +sudo zip -q -r $upm_zip_export_path ./ echo "Creating .tar.gz of UPM package" -tar -zcvf $upm_targz_export_path ./ +tar -zcf $upm_targz_export_path ./ echo "Changing back to original folder $cached_folder" cd $cached_folder echo "Finishing with code $error_code" -exit $error_code \ No newline at end of file +exit $error_code + From 8e34f65a91c1f32e39e2cf8ce54a996b64c4efb0 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Sat, 6 Apr 2019 00:49:36 -0400 Subject: [PATCH 34/41] Include .asmdef files for correct UPM package generation --- UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef index f5674c3bd..77a847114 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -1,8 +1,7 @@ { "name": "UnityGLTFTests", "references": [ - "UnityGLTFScripts", - "UnityGLTFEditor" + "UnityGLTFScripts" ], "optionalUnityReferences": [ "TestAssemblies" From ae9e685215e7b8a29e7326839033116bd0048f6f Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:52:47 -0400 Subject: [PATCH 35/41] Splitting out UnityGLTFEditor scripts with its own asmdef file --- UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef index 77a847114..f5674c3bd 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -1,7 +1,8 @@ { "name": "UnityGLTFTests", "references": [ - "UnityGLTFScripts" + "UnityGLTFScripts", + "UnityGLTFEditor" ], "optionalUnityReferences": [ "TestAssemblies" From e4c461bc1e0b08159006fbb2fda844a901eea23e Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Tue, 16 Apr 2019 00:34:03 -0400 Subject: [PATCH 36/41] Fixing Travis build environment issues --- scripts/export-upm-package.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/export-upm-package.sh b/scripts/export-upm-package.sh index f3bcdde19..a0e861489 100644 --- a/scripts/export-upm-package.sh +++ b/scripts/export-upm-package.sh @@ -8,7 +8,7 @@ upm_name=org.khronos.UnityGLTF upm_src_folder_path=$(pwd)/UnityGLTF/Assets/UnityGLTF upm_manifest_path=$(pwd)/scripts/package.json upm_staging_path=$(pwd)/current-package/$upm_name -upm_staging_UWP_plugins_path=$upm_staging_path/Plugins/uap10.0.10586 +upm_staging_UWP_plugins_path=$upm_staging_path/UnityGLTF/Plugins/uap10.0.10586 upm_zip_export_path=$(pwd)/current-package/$upm_name.zip upm_targz_export_path=$(pwd)/current-package/$upm_name.tar.gz @@ -44,7 +44,7 @@ cd $upm_staging_path echo "Cleaning out UWP plugin DLLs that are not needed for Unity2018.3+" echo "Only keeping the following files:" printf '%s\n' "${upm_UWP_Plugins[@]}" -find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs -r rm +find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs rm echo "Creating .zip of UPM package" sudo zip -q -r $upm_zip_export_path ./ From 3bee462e7b376719c22e98889363f1b7cba50cb6 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Sat, 6 Apr 2019 00:49:36 -0400 Subject: [PATCH 37/41] Include .asmdef files for correct UPM package generation --- UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef index f5674c3bd..77a847114 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -1,8 +1,7 @@ { "name": "UnityGLTFTests", "references": [ - "UnityGLTFScripts", - "UnityGLTFEditor" + "UnityGLTFScripts" ], "optionalUnityReferences": [ "TestAssemblies" From 0417355226a8e32097d3fb5dc152b0001827ec40 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Mon, 15 Apr 2019 23:52:47 -0400 Subject: [PATCH 38/41] Splitting out UnityGLTFEditor scripts with its own asmdef file --- UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef index 77a847114..f5674c3bd 100644 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/UnityGLTFTests.asmdef @@ -1,7 +1,8 @@ { "name": "UnityGLTFTests", "references": [ - "UnityGLTFScripts" + "UnityGLTFScripts", + "UnityGLTFEditor" ], "optionalUnityReferences": [ "TestAssemblies" From 24f6c4925b248445b5cf2c118e68cd2924b68d73 Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Tue, 16 Apr 2019 14:11:33 -0400 Subject: [PATCH 39/41] Pull down upstream changes --- ...tion.meta~Fix missing Integrations .meta file position | 8 ++++++++ .../Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position create mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position new file mode 100644 index 000000000..55750aa52 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5783cb7e53a767047b9bbec12c1cd4cf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD new file mode 100644 index 000000000..55750aa52 --- /dev/null +++ b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5783cb7e53a767047b9bbec12c1cd4cf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 0afe060d96ba138da8edc61fc8132f3f6febd55e Mon Sep 17 00:00:00 2001 From: Varun Mani Date: Tue, 16 Apr 2019 14:17:15 -0400 Subject: [PATCH 40/41] Fixing merge conflict --- ...tion.meta~Fix missing Integrations .meta file position | 8 -------- .../Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD | 8 -------- 2 files changed, 16 deletions(-) delete mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position delete mode 100644 UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position deleted file mode 100644 index 55750aa52..000000000 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~Fix missing Integrations .meta file position +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5783cb7e53a767047b9bbec12c1cd4cf -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD b/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD deleted file mode 100644 index 55750aa52..000000000 --- a/UnityGLTF/Assets/UnityGLTF/Scripts/Tests/Integration.meta~HEAD +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5783cb7e53a767047b9bbec12c1cd4cf -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From 661944eecd0faea675e310a10eae48a8180f4db8 Mon Sep 17 00:00:00 2001 From: Varun Mani <44373229+ei2kpi-ptc@users.noreply.github.com> Date: Tue, 7 May 2019 17:32:24 -0400 Subject: [PATCH 41/41] Enable Azure Pipelines UPM releases (#2) * Update Export-upm-packages.sh to support Azure Pipelines * Remove UPM Package generation from .travis.yml UPM package generation now works with Azure Pipelines --- .travis.yml | 6 ++---- scripts/export-upm-package.sh | 31 +++++++++++++++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7e9b52d53..334315f8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,20 +5,18 @@ install: - sudo python2 ./scripts/install-unity.py --package Unity 2017.1.1f1 before_script: - sudo chmod -R a+rwx /Applications/Unity -- sudo chmod +x ./scripts/export-upm-package.sh script: - msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization /p:TargetFramework=net35 - "./scripts/export-unity-package.sh" -- msbuild ./GLTFSerialization/GLTFSerialization.sln /t:GLTFSerialization -- "./scripts/export-upm-package.sh" deploy: provider: releases file: - "./current-package/UnityGLTF.unitypackage" - - "./current-package/org.khronos.UnityGLTF.zip" skip_cleanup: true on: repo: KhronosGroup/UnityGLTF + branch: releases tags: true api-key: secure: "KBs5cOzqEoTDzsBv6AurzlFMtgfctKbJWsGorUW9BE/+B8pnriGQxc1Lt83kzkvHkcF+MgqD5M1KK6SebB/lgpE2Xo/Zu/al1Sr0M6MNijRgHCx0aqea+/mjXfHS7qhbOqgEqQHYoR4kOqIKFhJZOohtLBylnDgFojG42Z2UFnbSelZaAT8qISxndX5qjIqV9+CgkRlpwyY4tnQ2fzVwuyFMvEqSBUzAegzPa+nQu1HgJzx64OP0ONmoTPJnUr0C741GtsD1fA6SMjSpwhjiYezQXapN2a/YoZufEkrd5wYq8Q1UVNMDmkmtg1zA0LkmK1u6dEhE7VCjxL7CW13FWGWEMKR9h2afTl+QkRIZxNRxjVHcWG122oTSCOXaAwBtNHMnWEgBy+DYFWAYD/bMmZ+g70EZ2/bFEfPprhyOvK59No5V65FOyoIMSBZvgU1z2Kl3PPTUl/0vEljX3RiON6BvIbOxU7OdR+OI35naSfos76YWK58+b99fRC0rJq6egwhNTACPItrtdmZq13k/5PWfGSJ0IAegdoXCB1eFP6SqcoXDsxLJph8/nHrEHqyjtl9PYBturvzVfQThTzL4FQuB7Fypwql/PXB7mdG7HkOvcM5jJWiupIsQxw5VkArZhnBk188ds+UC42tUhF701ZrPJz6GF0Kqem7/Fr/6l7A=" + diff --git a/scripts/export-upm-package.sh b/scripts/export-upm-package.sh index a0e861489..70ce44cd3 100644 --- a/scripts/export-upm-package.sh +++ b/scripts/export-upm-package.sh @@ -5,6 +5,7 @@ log_file=$(pwd)/build/unity-mac.log cached_folder=$(pwd) upm_name=org.khronos.UnityGLTF +echo "##vso[task.setvariable variable=UPM_NAME]$upm_name" upm_src_folder_path=$(pwd)/UnityGLTF/Assets/UnityGLTF upm_manifest_path=$(pwd)/scripts/package.json upm_staging_path=$(pwd)/current-package/$upm_name @@ -12,6 +13,17 @@ upm_staging_UWP_plugins_path=$upm_staging_path/UnityGLTF/Plugins/uap10.0.10586 upm_zip_export_path=$(pwd)/current-package/$upm_name.zip upm_targz_export_path=$(pwd)/current-package/$upm_name.tar.gz +if [[ $BUILD_SOURCEBRANCH == *"refs/tags"* ]]; then + echo "Detected refs/tags in $BUILD_SOURCEBRANCH so this must be a tagged release build." + # Splits the string with "refs/tags", takes the second value and then + # swaps out any slashes for underscores + GIT_TAG=$(echo $BUILD_SOURCEBRANCH | awk -F'refs/tags/' '{print $2}' | tr '/' '_') + echo "Setting GIT_TAG variable to: $GIT_TAG" + echo "##vso[task.setvariable variable=GIT_TAG]$GIT_TAG" +else + echo "Did not detect refs/tags in $BUILD_SOURCEBRANCH so skipping GIT_TAG variable set" +fi + # msbuild spits out every single dependency dll for UWP # These are the only files that are needed by the UPM package for Unity 2018.3+ # Including all the files in the UWP plugin directory causes name collision errors when @@ -42,19 +54,10 @@ echo "Changing to $upm_staging_path folder" cd $upm_staging_path echo "Cleaning out UWP plugin DLLs that are not needed for Unity2018.3+" -echo "Only keeping the following files:" -printf '%s\n' "${upm_UWP_Plugins[@]}" find $upm_staging_UWP_plugins_path -maxdepth 1 -type f | grep -vE "$(IFS=\| && echo "${upm_UWP_Plugins[*]}")" | xargs rm -echo "Creating .zip of UPM package" -sudo zip -q -r $upm_zip_export_path ./ - -echo "Creating .tar.gz of UPM package" -tar -zcf $upm_targz_export_path ./ - -echo "Changing back to original folder $cached_folder" -cd $cached_folder - -echo "Finishing with code $error_code" -exit $error_code - +echo "Files left in $upm_staging_UWP_plugins_path" +for entry in "$upm_staging_UWP_plugins_path"/* +do + echo "$entry" +done \ No newline at end of file