From 89454b9aea525db6821dc9e136f69f5280b51193 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira <4420556+btco@users.noreply.github.com> Date: Thu, 7 Dec 2017 11:38:25 -0500 Subject: [PATCH] Patch release (1.0.3) of Poly Toolkit. --- Assets/Editor/BuildPackage.cs | 50 ++++++++++++++++--- Assets/Editor/PrepForUASExport.cs | 38 ++++++++++++++ Assets/Editor/PrepForUASExport.cs.meta | 12 +++++ Assets/Editor/Tests/TestImportGltf.cs | 18 +++---- .../Editor/Importer/PolyImporter.cs | 21 +++++--- .../PolyToolkit/Editor/PostInstallHandler.cs | 24 +++++---- Assets/PolyToolkit/Editor/PtAnalytics.cs | 3 +- Assets/PolyToolkit/Internal/ImportGltf.cs | 16 ++++-- .../Internal/entitlement/OAuth2Identity.cs | 2 +- Assets/PolyToolkit/Resources/PtSettings.asset | 9 ++-- Assets/PolyToolkit/Scripts/PolyApi.cs | 10 +++- ProjectSettings/ProjectSettings.asset | 5 +- README.txt | 22 -------- 13 files changed, 161 insertions(+), 69 deletions(-) create mode 100644 Assets/Editor/PrepForUASExport.cs create mode 100644 Assets/Editor/PrepForUASExport.cs.meta delete mode 100644 README.txt diff --git a/Assets/Editor/BuildPackage.cs b/Assets/Editor/BuildPackage.cs index 9a6d71d..f17e613 100644 --- a/Assets/Editor/BuildPackage.cs +++ b/Assets/Editor/BuildPackage.cs @@ -12,11 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Collections.Generic; using System.IO; using System.Linq; using UnityEditor; using UnityEngine; +using PolyToolkit; +using PolyToolkitInternal; // NO_POLY_TOOLKIT_INTERNAL_CHECK // PolyToolkitDev namespace is for classes that exist only for developing Poly Toolkit itself, // and don't ship out to users in the build. @@ -85,17 +88,19 @@ static string GetGitVersion() { /// Creates a .unitypackage file named after the current git version. /// Writes to the root of the git repo. - [MenuItem("Poly/Build .unitypackage")] + [MenuItem("Poly/Dev/Build .unitypackage")] static void DoBuild() { string version = GetGitVersion(); string name = string.Format("../poly-toolkit-{0}.unitypackage", version); using (var tmp = new TempBuildStamp(version)) { - AssetDatabase.ExportPackage( - GetFilesToExport(), - name, - ExportPackageOptions.Recurse); - Debug.LogFormat("Done building {0}", name); + using (var prepareSettings = new TempPrepareSettingsForExport()) { + AssetDatabase.ExportPackage( + GetFilesToExport(), + name, + ExportPackageOptions.Recurse); + Debug.LogFormat("Done building {0}", name); + } } } @@ -109,6 +114,39 @@ static string[] GetFilesToExport() { // Correct the path so it is relative to the package. return files.Select(x => x.Replace(Application.dataPath, "Assets")).ToArray(); } + + /// + /// This object temporarily configures the project (to allow unitypackage export), + /// and reverts the configuration back after it is disposed. + /// Use this in a using{} block while exporting. + /// + private class TempPrepareSettingsForExport : IDisposable { + private PolyAuthConfig oldAuthConfig; + + public TempPrepareSettingsForExport() { + oldAuthConfig = ResetToPlaceholderCredentials(); + } + + public void Dispose() { + // Restore old auth config. + PtSettings.Instance.authConfig = oldAuthConfig; + EditorUtility.SetDirty(PtSettings.Instance); + } + } + + /// + /// Resets the API credentials to placeholder ones. + /// + /// The previous auth credentials. + public static PolyAuthConfig ResetToPlaceholderCredentials() { + PolyAuthConfig oldAuthConfig = PtSettings.Instance.authConfig; + // Replace by a placeholder auth config during export. + PtSettings.Instance.authConfig = new PolyAuthConfig( + apiKey: "** INSERT YOUR API KEY HERE **", clientId: "", clientSecret: ""); + EditorUtility.SetDirty(PtSettings.Instance); + AssetDatabase.SaveAssets(); + return oldAuthConfig; + } } } \ No newline at end of file diff --git a/Assets/Editor/PrepForUASExport.cs b/Assets/Editor/PrepForUASExport.cs new file mode 100644 index 0000000..2033620 --- /dev/null +++ b/Assets/Editor/PrepForUASExport.cs @@ -0,0 +1,38 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.IO; +using UnityEditor; +using UnityEngine; + +// PolyToolkitDev namespace is for classes that exist only for developing Poly Toolkit itself, +// and don't ship out to users in the build. +namespace PolyToolkitDev { + +static class PrepForUASExport { + [MenuItem("Poly/Dev/Prep for UAS Export")] + public static void DoPrepForUASExport() { + // The exported package should have the placeholder credentials, not our credentials. + BuildPackage.ResetToPlaceholderCredentials(); + + // We used to create upgrade.dat in the editor, so there might be left over copies of it in people's + // working copies. To ensure that it's not exported, let's delete it. + File.Delete(Application.dataPath + "/Editor/upgrade.dat"); + File.Delete(Application.dataPath + "/Editor/upgrade.dat.meta"); + + EditorUtility.DisplayDialog("Ready", "Ready for Unity Asset Store export.", "OK"); + } +} + +} \ No newline at end of file diff --git a/Assets/Editor/PrepForUASExport.cs.meta b/Assets/Editor/PrepForUASExport.cs.meta new file mode 100644 index 0000000..af22cd0 --- /dev/null +++ b/Assets/Editor/PrepForUASExport.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0af39852857bc054d90e606b809745db +timeCreated: 1502212896 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Tests/TestImportGltf.cs b/Assets/Editor/Tests/TestImportGltf.cs index 7a4f845..bca9d35 100644 --- a/Assets/Editor/Tests/TestImportGltf.cs +++ b/Assets/Editor/Tests/TestImportGltf.cs @@ -158,7 +158,7 @@ static void SaveAsSinglePrefab( } [Test] - [MenuItem("Poly/Test/Save as Separate")] + [MenuItem("Poly/Dev/Test/Save as Separate")] public static void TestSaveAsSeparateWithMeshesInAsset() { IUriLoader binLoader = new BufferedStreamLoader(Path.GetDirectoryName(Path.Combine(RepoRoot, kAllBrush10))); ImportGltf.GltfImportResult result = null; @@ -172,7 +172,7 @@ public static void TestSaveAsSeparateWithMeshesInAsset() { } [Test] - [MenuItem("Poly/Test/Save as Single")] + [MenuItem("Poly/Dev/Test/Save as Single")] public static void TestSaveAsSinglePrefab() { IUriLoader binLoader = new BufferedStreamLoader(Path.GetDirectoryName(Path.Combine(RepoRoot, kMoto))); ImportGltf.GltfImportResult result = null; @@ -208,7 +208,7 @@ private static GameObject DoImport(string gltfPath, PolyImportOptions options, b } } - [MenuItem("Poly/Test/Import+save selected .gltf assets")] + [MenuItem("Poly/Dev/Test/Import+save selected .gltf assets")] public static void TestImportSelection() { var gltfAssets = Selection.objects .Select(o => AssetDatabase.GetAssetPath(o)) @@ -225,19 +225,19 @@ public static void TestImportSelection() { } [Test] - [MenuItem("Poly/Test/Import only/glTF1")] + [MenuItem("Poly/Dev/Test/Import only/glTF1")] public static void TestImportGltf1() { DoImport(Path.Combine(RepoRoot, kAllBrush14), PolyImportOptions.Default()); } [Test] - [MenuItem("Poly/Test/Import only/glTF2, defaults")] + [MenuItem("Poly/Dev/Test/Import only/glTF2, defaults")] public static void TestImportGltf2() { DoImport(Path.Combine(RepoRoot, kComputer), PolyImportOptions.Default()); } [Test] - [MenuItem("Poly/Test/Import only/glTF2, scale x2")] + [MenuItem("Poly/Dev/Test/Import only/glTF2, scale x2")] public static void TestImportGltf2Scale() { PolyImportOptions options = new PolyImportOptions(); options.rescalingMode = PolyImportOptions.RescalingMode.CONVERT; @@ -246,7 +246,7 @@ public static void TestImportGltf2Scale() { } [Test] - [MenuItem("Poly/Test/Import only/glTF2, target size=50")] + [MenuItem("Poly/Dev/Test/Import only/glTF2, target size=50")] public static void TestImportGltf2TargetSize() { PolyImportOptions options = new PolyImportOptions(); options.rescalingMode = PolyImportOptions.RescalingMode.FIT; @@ -255,7 +255,7 @@ public static void TestImportGltf2TargetSize() { } [Test] - [MenuItem("Poly/Test/Import only/glTF2, target size=50, recenter")] + [MenuItem("Poly/Dev/Test/Import only/glTF2, target size=50, recenter")] public static void TestImportGltf2TargetSizeRecenter() { PolyImportOptions options = new PolyImportOptions(); options.rescalingMode = PolyImportOptions.RescalingMode.FIT; @@ -265,7 +265,7 @@ public static void TestImportGltf2TargetSizeRecenter() { } [Test] - [MenuItem("Poly/Test/Import only (GLTF2, transparent)")] + [MenuItem("Poly/Dev/Test/Import only (GLTF2, transparent)")] public static void TestImportGltf2Transparent() { DoImport(Path.Combine(RepoRoot, kGoblets), PolyImportOptions.Default()); } diff --git a/Assets/PolyToolkit/Editor/Importer/PolyImporter.cs b/Assets/PolyToolkit/Editor/Importer/PolyImporter.cs index e59ba05..bba3cca 100644 --- a/Assets/PolyToolkit/Editor/Importer/PolyImporter.cs +++ b/Assets/PolyToolkit/Editor/Importer/PolyImporter.cs @@ -61,6 +61,8 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse } catch (Exception ex) { Debug.LogErrorFormat("Import error: {0}", ex); PtAnalytics.SendException(ex, isFatal: false); + EditorUtility.DisplayDialog("Error", + "There was an error importing the asset. Please check the logs for more information.", "OK"); } importRequests.Remove(localAssetPath); } @@ -95,16 +97,19 @@ private static void ExecuteImportRequest(ImportRequest request) { // First, import the GLTF and build a GameObject from it. EditorUtility.DisplayProgressBar(PROGRESS_BAR_TITLE, PROGRESS_BAR_TEXT, 0.5f); - // Use a SanitizedPath stream loader because any format file we have downloaded and saved to disk we - // have replaced the original relative path string with the MD5 string hash. This custom stream loader - // will always convert uris passed to it to this hash value, and read them from there. - IUriLoader binLoader = new HashedPathBufferedStreamLoader(Path.GetDirectoryName(gltfFullPath)); ImportGltf.GltfImportResult result = null; - using (TextReader reader = new StreamReader(gltfFullPath)) { - result = ImportGltf.Import(isGltf2 ? GltfSchemaVersion.GLTF2 : GltfSchemaVersion.GLTF1, - reader, binLoader, request.options.baseOptions); + try { + // Use a SanitizedPath stream loader because any format file we have downloaded and saved to disk we + // have replaced the original relative path string with the MD5 string hash. This custom stream loader + // will always convert uris passed to it to this hash value, and read them from there. + IUriLoader binLoader = new HashedPathBufferedStreamLoader(Path.GetDirectoryName(gltfFullPath)); + using (TextReader reader = new StreamReader(gltfFullPath)) { + result = ImportGltf.Import(isGltf2 ? GltfSchemaVersion.GLTF2 : GltfSchemaVersion.GLTF1, + reader, binLoader, request.options.baseOptions); + } + } finally { + EditorUtility.ClearProgressBar(); } - EditorUtility.ClearProgressBar(); string baseName = PtUtils.GetPtAssetBaseName(request.polyAsset); result.root.name = baseName; diff --git a/Assets/PolyToolkit/Editor/PostInstallHandler.cs b/Assets/PolyToolkit/Editor/PostInstallHandler.cs index 25d8111..7c8c490 100644 --- a/Assets/PolyToolkit/Editor/PostInstallHandler.cs +++ b/Assets/PolyToolkit/Editor/PostInstallHandler.cs @@ -17,8 +17,6 @@ using UnityEditor; using System; using PolyToolkitInternal; -using System.Collections.Generic; -using System.Linq; namespace PolyToolkitEditor { @@ -27,6 +25,10 @@ public class PostInstallHandler { static PostInstallHandler() { if (Application.isPlaying) return; + // Don't run the upgrade logic in the Poly Toolkit source project. We only want it to run + // when users have installed it. + if (Application.companyName == "Google" && Application.productName == "PolyToolkitUnity") return; + // Add HandlePostInstall method to the Editor update loop so it runs after the rest of // PolyToolkit has been initialized. EditorApplication.update += HandlePostInstall; @@ -44,17 +46,17 @@ public static void HandlePostInstall() { try { currentVersion = File.ReadAllText(upgradeFilePath).Trim(); } catch (Exception) {} - if (currentVersion != PtSettings.Version.ToString()) { - isUpgrade = !string.IsNullOrEmpty(currentVersion); - // Show the welcome window. - WelcomeWindow.ShowWelcomeWindow(); - AssetBrowserWindow.BrowsePolyAssets(); - File.WriteAllText(upgradeFilePath, PtSettings.Version.ToString()); - } - + + if (currentVersion == PtSettings.Version.ToString()) return; + isUpgrade = !string.IsNullOrEmpty(currentVersion); + // Show the welcome window. + WelcomeWindow.ShowWelcomeWindow(); + AssetBrowserWindow.BrowsePolyAssets(); + File.WriteAllText(upgradeFilePath, PtSettings.Version.ToString()); + // In the future, if we need to do any post-upgrade maintenance, we can add it here. PtAnalytics.SendEvent(isUpgrade ? PtAnalytics.Action.INSTALL_UPGRADE - : PtAnalytics.Action.INSTALL_NEW, PtSettings.Version.ToString()); + : PtAnalytics.Action.INSTALL_NEW_2, PtSettings.Version.ToString()); } } } \ No newline at end of file diff --git a/Assets/PolyToolkit/Editor/PtAnalytics.cs b/Assets/PolyToolkit/Editor/PtAnalytics.cs index cc6f553..46ef5bd 100644 --- a/Assets/PolyToolkit/Editor/PtAnalytics.cs +++ b/Assets/PolyToolkit/Editor/PtAnalytics.cs @@ -58,7 +58,8 @@ public enum Action { IMPORT_STARTED, IMPORT_STARTED_FROM_SEARCH, IMPORT_SUCCESSFUL, - INSTALL_NEW, + // Due to a bug in how INSTALL_NEW was collected, this was renamed to INSTALL_NEW_2. + INSTALL_NEW_2, INSTALL_UPGRADE, } diff --git a/Assets/PolyToolkit/Internal/ImportGltf.cs b/Assets/PolyToolkit/Internal/ImportGltf.cs index 0c6ca2a..469574e 100644 --- a/Assets/PolyToolkit/Internal/ImportGltf.cs +++ b/Assets/PolyToolkit/Internal/ImportGltf.cs @@ -123,14 +123,22 @@ public static GltfImportResult Import( private static GltfRootBase DeserializeGltfRoot(GltfSchemaVersion gltfVersion, JsonTextReader reader) { switch (gltfVersion) { case GltfSchemaVersion.GLTF1: { - var ret = kSerializer.Deserialize(reader); + var gltf1Root = kSerializer.Deserialize(reader); + if (gltf1Root == null || gltf1Root.nodes == null) { + throw new Exception("Failed to parse GLTF1. File is empty or in the wrong format."); + } + // Some historical Tilt Brush assets use multiple meshes per node, but the importer // assumes single-mesh-per-node. - PostProcessRemoveMultipleMeshes(ret); - return ret; + PostProcessRemoveMultipleMeshes(gltf1Root); + return gltf1Root; } case GltfSchemaVersion.GLTF2: - return kSerializer.Deserialize(reader); + var gltf2Root= kSerializer.Deserialize(reader); + if (gltf2Root == null || gltf2Root.nodes == null) { + throw new Exception("Failed to parse GLTF2. File is empty or in the wrong format."); + } + return gltf2Root; default: throw new ArgumentException("Invalid gltfVersion" + gltfVersion); } diff --git a/Assets/PolyToolkit/Internal/entitlement/OAuth2Identity.cs b/Assets/PolyToolkit/Internal/entitlement/OAuth2Identity.cs index 99ac1e7..de341da 100644 --- a/Assets/PolyToolkit/Internal/entitlement/OAuth2Identity.cs +++ b/Assets/PolyToolkit/Internal/entitlement/OAuth2Identity.cs @@ -50,7 +50,7 @@ public class UserInfo { private const string m_UserInfoUri = "https://people.googleapis.com/v1/people/me?requestMask.includeField=person.addresses,person.email_addresses,person.names,person.photos,person.residences"; private string m_OAuthScope = "profile email " + "https://www.googleapis.com/auth/vrassetdata.readonly " + - "https://www.googleapis.com/auth/peopleapi.readonly"; + "https://www.googleapis.com/auth/vrassetdata.readwrite "; private const string m_CallbackPath = "/callback"; private const string m_ReplaceHeadset = "ReplaceHeadset"; private string m_CallbackFailedMessage = "Sorry!"; diff --git a/Assets/PolyToolkit/Resources/PtSettings.asset b/Assets/PolyToolkit/Resources/PtSettings.asset index ad3e76c..d3c49fc 100644 --- a/Assets/PolyToolkit/Resources/PtSettings.asset +++ b/Assets/PolyToolkit/Resources/PtSettings.asset @@ -34,14 +34,15 @@ MonoBehaviour: scaleFactor: 1 desiredSize: 1 recenter: 1 - throttled: 0 + clientThrottledMainThread: 0 alsoInstantiate: 1 brushManifest: {fileID: 11400000, guid: 2b3e59298bb8cfc47bddd1e1ea01be06, type: 2} - basePbrMaterial: {fileID: 2100000, guid: a24c5cab5717b124889fe758761686b4, type: 2} - basePbrTransparentMaterial: {fileID: 2100000, guid: b2b07ce943390e34993803beeb1e8548, + basePbrOpaqueDoubleSidedMaterial: {fileID: 2100000, guid: a24c5cab5717b124889fe758761686b4, + type: 2} + basePbrBlendDoubleSidedMaterial: {fileID: 2100000, guid: b2b07ce943390e34993803beeb1e8548, type: 2} authConfig: - apiKey: '**INSERT YOUR API KEY HERE**' + apiKey: '** INSERT YOUR API KEY HERE **' clientId: clientSecret: additionalScopes: [] diff --git a/Assets/PolyToolkit/Scripts/PolyApi.cs b/Assets/PolyToolkit/Scripts/PolyApi.cs index 3fb99a2..0eaea4c 100644 --- a/Assets/PolyToolkit/Scripts/PolyApi.cs +++ b/Assets/PolyToolkit/Scripts/PolyApi.cs @@ -302,12 +302,18 @@ public static void ClearCache() { public static string GenerateAttributions(bool includeStatic = true, List runtimeAssets = null) { StringBuilder sb = new StringBuilder(); + bool hasHeader = false; if (includeStatic) { // Append static file first, because it includes the header. TextAsset staticAttributionFile = Resources.Load( Path.GetFileNameWithoutExtension(AttributionGeneration.ATTRIB_FILE_NAME)); - sb.Append(staticAttributionFile.text); - } else { + if (staticAttributionFile != null) { + sb.Append(staticAttributionFile.text); + hasHeader = true; + } + } + + if (!hasHeader) { sb.Append(AttributionGeneration.FILE_HEADER).AppendLine(); } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 843b571..4501dce 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -10,7 +10,7 @@ PlayerSettings: targetDevice: 2 useOnDemandResources: 0 accelerometerFrequency: 60 - companyName: DefaultCompany + companyName: Google productName: PolyToolkitUnity defaultCursor: {fileID: 0} cursorHotspot: {x: 0, y: 0} @@ -367,6 +367,9 @@ PlayerSettings: switchUdpSendBufferSize: 9 switchUdpReceiveBufferSize: 42 switchSocketBufferEfficiency: 4 + switchSocketInitializeEnabled: 1 + switchNetworkInterfaceManagerInitializeEnabled: 1 + switchPlayerConnectionEnabled: 1 ps4NPAgeRating: 12 ps4NPTitleSecret: ps4NPTrophyPackPath: diff --git a/README.txt b/README.txt deleted file mode 100644 index 8b617cd..0000000 --- a/README.txt +++ /dev/null @@ -1,22 +0,0 @@ -NOTE ON NAMESPACES - -namespace PolyToolkit: - Assets/PolyToolkit/Scripts - Public API classes, used at runtime and edit time. - -namespace PolyToolkitInternal: - Assets/PolyToolkit/Internal - Private classes used at runtime and edit time. - Should not be used or referenced by users of Poly Toolkit. - -namespace PolyToolkitEditor: - Assets/PolyToolkit/Editor - Classes that implement the PT editor UI logic. - Should not be used or referenced by users of Poly Toolkit. - -namespace PolyToolkitDev: - Assets/Editor - Classes only used for Poly Toolkit development. These are not included - in the builds that go out to users. - -