Skip to content
This repository has been archived by the owner on Jun 24, 2019. It is now read-only.

Commit

Permalink
Patch release (1.0.3) of Poly Toolkit.
Browse files Browse the repository at this point in the history
  • Loading branch information
btco committed Dec 7, 2017
1 parent 8c72ede commit 89454b9
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 69 deletions.
50 changes: 44 additions & 6 deletions Assets/Editor/BuildPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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();
}

/// <summary>
/// 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.
/// </summary>
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);
}
}

/// <summary>
/// Resets the API credentials to placeholder ones.
/// </summary>
/// <returns>The previous auth credentials.</returns>
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;
}
}

}
38 changes: 38 additions & 0 deletions Assets/Editor/PrepForUASExport.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}

}
12 changes: 12 additions & 0 deletions Assets/Editor/PrepForUASExport.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Assets/Editor/Tests/TestImportGltf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}
Expand Down
21 changes: 13 additions & 8 deletions Assets/PolyToolkit/Editor/Importer/PolyImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down
24 changes: 13 additions & 11 deletions Assets/PolyToolkit/Editor/PostInstallHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
using UnityEditor;
using System;
using PolyToolkitInternal;
using System.Collections.Generic;
using System.Linq;

namespace PolyToolkitEditor {

Expand All @@ -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;
Expand All @@ -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());
}
}
}
3 changes: 2 additions & 1 deletion Assets/PolyToolkit/Editor/PtAnalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
16 changes: 12 additions & 4 deletions Assets/PolyToolkit/Internal/ImportGltf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Gltf1Root>(reader);
var gltf1Root = kSerializer.Deserialize<Gltf1Root>(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<Gltf2Root>(reader);
var gltf2Root= kSerializer.Deserialize<Gltf2Root>(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);
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/PolyToolkit/Internal/entitlement/OAuth2Identity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
9 changes: 5 additions & 4 deletions Assets/PolyToolkit/Resources/PtSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down
10 changes: 8 additions & 2 deletions Assets/PolyToolkit/Scripts/PolyApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,18 @@ public static void ClearCache() {
public static string GenerateAttributions(bool includeStatic = true, List<PolyAsset> runtimeAssets = null) {
StringBuilder sb = new StringBuilder();

bool hasHeader = false;
if (includeStatic) {
// Append static file first, because it includes the header.
TextAsset staticAttributionFile = Resources.Load<TextAsset>(
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();
}

Expand Down
Loading

4 comments on commit 89454b9

@andybak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be lots of separate commits squashed together plus a not very descriptive commit message. Seems a bit of a shame as this negates half the benefit of having a public Git repo. I assume you've got more granular commits internally?

@btco
Copy link
Contributor Author

@btco btco commented on 89454b9 Dec 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this is a series of internal commits squashed together, and we do have more granular commits internally. We do this mainly because we want to always have a stable snapshot of the source code in Github so that developers don't have to worry about the code being in an inconsistent state in between commits. Sometimes we fix one thing and break something else temporarily, then fix the other thing and break a third thing, then fix that... and so on and so forth :) So to minimize pain to external devs, we prefer to push "known good snapshots" reflecting good states of the code, as individual commits might or might not be good patches.

But maybe I'm fundamentally misunderstanding something! What's a use case in which individual commits would be vastly more useful than snapshots?

@andybak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to use commit history for two main things:

  1. In lieu of a decent changelog. If you provided a detailed changelog that would be a fine substitute.
  2. As a way of understanding the code. It's helpful to track down bugs, understand when, how and even why a feature was added.

And to give a more fuzzy reason - I guess I'm just used to seeing proper commits as it's how the majority of open source projects operate. I use the Github network view a lot to keep my eye on how a project is progressing: https://github.com/thestonefox/VRTK/network

@btco
Copy link
Contributor Author

@btco btco commented on 89454b9 Dec 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! Making a more detailed changelog is feasible, I'll look into improving this process. Thanks for the feedback!

Please sign in to comment.