Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Draft][USDU-331] Make package samples more user friendly #367

Draft
wants to merge 36 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c4b7a8b
Ignores two unstable test cases until a fix has been found
lee-aandrew Mar 21, 2023
464ea5b
Merge branch 'dev' of https://github.com/Unity-Technologies/usd-unity…
lee-aandrew Mar 29, 2023
7af60ed
Merge branch 'dev' of https://github.com/Unity-Technologies/usd-unity…
lee-aandrew Mar 31, 2023
20dc1c7
Merge branch 'dev' of https://github.com/Unity-Technologies/usd-unity…
lee-aandrew Apr 12, 2023
4236bd0
Merge branch 'dev' of https://github.com/Unity-Technologies/usd-unity…
lee-aandrew Apr 14, 2023
2d14b87
Merge branch 'dev' of https://github.com/Unity-Technologies/usd-unity…
lee-aandrew Apr 18, 2023
bb60d3e
Merge branch 'dev' of https://github.com/Unity-Technologies/usd-unity…
lee-aandrew Apr 19, 2023
fa6e626
HelloUSD to be a bit more user-friendly
lee-aandrew Apr 4, 2023
c354a2a
Make Samples more user-friendly: ExportMesh, ImportProcessor, UsdTime…
lee-aandrew Apr 4, 2023
8ec4518
fix formatting issue
lee-aandrew Apr 4, 2023
8f76aee
Set up Samples properly according to Unity documentation
lee-aandrew Apr 13, 2023
24392f2
add removal of Samples.meta file
lee-aandrew Apr 13, 2023
8399af7
Revert "add removal of Samples.meta file"
lee-aandrew Apr 20, 2023
bbd2308
Revert "Set up Samples properly according to Unity documentation"
lee-aandrew Apr 20, 2023
9656bc2
Update HelloUSD and Separated out + updated ExportMeshWithAnimation s…
lee-aandrew Apr 21, 2023
5bc6608
Adds Export Mesh Example
lee-aandrew Apr 25, 2023
7eff80c
Applies code review comments & fixes formatting issue
lee-aandrew Apr 25, 2023
786ea4b
fixes variable naming miss
lee-aandrew Apr 25, 2023
9891944
Quick clean up of non-used using references and Additional comments
lee-aandrew Apr 25, 2023
e02a734
Adds ExportMeshTransformOverride Sample
lee-aandrew Apr 25, 2023
9588f2c
Removes hard coded color codes & adds more comments where needed
lee-aandrew Apr 25, 2023
92da6e3
Removed tree object from Export Mesh example as the tree object was a…
lee-aandrew Apr 26, 2023
33e3782
Quick Scene update for ExportMeshTransformOverride
lee-aandrew Apr 26, 2023
be78943
Fix naming issues
lee-aandrew Apr 26, 2023
721337d
Changes ExportMeshExample and ExportMeshWithAnimationExample back to …
lee-aandrew Apr 28, 2023
5d5827b
Redo HelloUSD to be more informative
lee-aandrew Apr 28, 2023
fcba3e5
Applies Vicky's PR Review suggestions
lee-aandrew Apr 28, 2023
e9f8a52
Apply formatting fix
lee-aandrew Apr 28, 2023
fba3a79
Adds Import Materials Sample Sample changes
lee-aandrew May 2, 2023
b446bff
Update Copyright comments
lee-aandrew May 2, 2023
94483f0
Changes Import Mesh Sample to only be Import Mesh
lee-aandrew May 2, 2023
04d33ab
Changes Import Processort Samples
lee-aandrew May 2, 2023
eddf389
Adds ExportAnimationWithRecorder sample
lee-aandrew May 3, 2023
149d34f
Change UsdTimelinePlayable Sample
lee-aandrew May 4, 2023
8891a7b
Apply review suggestions
lee-aandrew May 5, 2023
5f6ce5a
Apply review suggestion for ExportAnimationWithRecorderExample
lee-aandrew May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions package/com.unity.formats.usd/Editor/Utils/SampleUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEngine;

namespace Unity.Formats.USD
{
public static class SampleUtils
{
/// <summary>
/// Utils functions for the package Samples
/// </summary>

public static string SampleArtifactDirectory => Path.Combine(Application.dataPath, "Samples");
public static string SampleArtifactRelativeDirectory => "Assets/Samples";

private static EditorWindow GetConsoleWindow()
{
var editorWindowTypes = TypeCache.GetTypesDerivedFrom<EditorWindow>();
foreach (var type in editorWindowTypes)
{
if (type.Name == "ConsoleWindow")
{
return EditorWindow.GetWindow(type);
}
}

throw new System.Exception("Error could not find ConsoleWindow type");
}

public static void FocusConsoleWindow()
{
#if UNITY_EDITOR
var consoleWindow = GetConsoleWindow();
consoleWindow.Focus();
#endif
}

public struct TextColor
{
public const string Red = "#FF2D2D";
public const string Green = "#00FF00";
public const string Blue = "#338DFF";
}
}
}
11 changes: 11 additions & 0 deletions package/com.unity.formats.usd/Editor/Utils/SampleUtils.cs.meta

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

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All rights reserved.
// Copyright 2023 Unity Technologies. 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.
Expand All @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using UnityEngine;
using UnityEditor;
using UnityEngine;

namespace Unity.Formats.USD.Examples
{
Expand All @@ -25,30 +25,80 @@ public override void OnInspectorGUI()
DrawDefaultInspector();

ExportMeshExample script = (ExportMeshExample)target;
if (script.IsRecording)

var labelStyle = new GUIStyle() { fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleLeft, wordWrap = true };
labelStyle.normal.textColor = Color.white;

GUILayout.Label($"\nFor Exporting as <.{script.FileExtension}>, follow these step(s):", labelStyle);

if (GUILayout.Button("1. Initialize USD Package"))
{
var oldBg = GUI.backgroundColor;
GUI.backgroundColor = Color.white;
if (GUILayout.Button("Stop"))
{
script.StopRecording();
EditorApplication.isPaused = true;
}

GUI.backgroundColor = oldBg;
script.InitUSD();
}
else

switch (script.FileExtension)
{
var oldBg = GUI.backgroundColor;
GUI.backgroundColor = Color.red;
if (GUILayout.Button("Record"))
{
EditorApplication.isPaused = false;
//EditorApplication.isPlaying = true;
script.StartRecording();
}

GUI.backgroundColor = oldBg;
case ExportMeshExample.UsdFileExtension.usd:
case ExportMeshExample.UsdFileExtension.usda:
case ExportMeshExample.UsdFileExtension.usdc:
{
if (GUILayout.Button("2. Create New USD Scene"))
{
SampleUtils.FocusConsoleWindow();

script.CreateNewUsdScene();
Debug.Log($"<color={SampleUtils.TextColor.Green}>Created USD file: <b><{script.m_newUsdFileName}.{script.FileExtension}></b> under project <b>'{SampleUtils.SampleArtifactRelativeDirectory}'</b> folder</color>");
lee-aandrew marked this conversation as resolved.
Show resolved Hide resolved
}

if (GUILayout.Button("3. Set up Export Context"))
{
SampleUtils.FocusConsoleWindow();

script.SetUpExportContext();
}

if (GUILayout.Button("3. Set up Export Context"))
lee-aandrew marked this conversation as resolved.
Show resolved Hide resolved
{
SampleUtils.FocusConsoleWindow();

script.SetUpExportContext();
}

if (GUILayout.Button("4. Export"))
{
SampleUtils.FocusConsoleWindow();

script.Export();
}

if (GUILayout.Button("5. Save Scene"))
{
SampleUtils.FocusConsoleWindow();

script.SaveScene();
AssetDatabase.Refresh();
Debug.Log($"<color={SampleUtils.TextColor.Green}>Exported details of <b><{script.m_exportRoot.name}></b> into <b><{script.m_newUsdFileName}.{script.FileExtension}></b></color>");
}

if (GUILayout.Button("6. Close Scene"))
{
script.CloseScene();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see a reason to do the Save and Close steps seperately- I think they should be combined into one step to reduce clicks.

}
break;
}

case ExportMeshExample.UsdFileExtension.usdz:
{
if (GUILayout.Button("2. Export GameObject as USDZ"))
{
SampleUtils.FocusConsoleWindow();
Debug.Log("For USDZ Export the sample will utilize the <b>UsdzExporter.cs</b> script");
script.ExportAsUsdz();
AssetDatabase.Refresh();
Debug.Log($"<color={SampleUtils.TextColor.Green}>Exported details of <b><{script.m_exportRoot.name}></b> into <b><{script.m_newUsdFileName}.usdz></b></color>");
}
break;
}
}
}
}
Expand Down

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

Loading