Skip to content

Commit c354a2a

Browse files
committed
Make Samples more user-friendly: ExportMesh, ImportProcessor, UsdTimelinePlayable
1 parent fa6e626 commit c354a2a

File tree

13 files changed

+3930
-723
lines changed

13 files changed

+3930
-723
lines changed

package/com.unity.formats.usd/Samples/ExportMesh/ExportMesh.unity

Lines changed: 1803 additions & 719 deletions
Large diffs are not rendered by default.

package/com.unity.formats.usd/Samples/ExportMesh/ExportMeshExample.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// limitations under the License.
1414

1515
using System;
16+
using System.IO;
17+
using UnityEditor;
1618
using UnityEngine;
1719
using USD.NET;
1820

@@ -130,7 +132,7 @@ public void StartRecording()
130132
}
131133
else
132134
{
133-
m_usdScene = Scene.Create(m_usdFile);
135+
m_usdScene = Scene.Create(Path.Combine(Application.dataPath, m_usdFile));
134136
}
135137

136138
// USD operates on frames, so the frame rate is required for playback.
@@ -280,6 +282,11 @@ void LateUpdate()
280282
}
281283
}
282284

285+
void OnApplicationQuit()
286+
{
287+
AssetDatabase.Refresh();
288+
}
289+
283290
public static void Export(GameObject root,
284291
Scene scene,
285292
BasisTransformation basisTransform)

package/com.unity.formats.usd/Samples/ImportProcessor/CombineMeshes.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ public void PostProcessComponents(PrimMap primMap, SceneImportOptions sceneImpor
3939
}
4040
}
4141

42+
public void RefreshUSD()
43+
{
44+
this.GetComponent<UsdAsset>().Reload(true);
45+
}
46+
4247
void Reset()
4348
{
4449
matchExpression = "Geom";
4550
isNot = false;
46-
matchType = EMatchType.Wildcard;
51+
matchType = EMatchType.Regex;
4752
compareAgainst = ECompareAgainst.UsdName;
4853
}
4954

@@ -91,6 +96,8 @@ void DoCombineMeshes(Transform current)
9196
current.gameObject.SetActive(true);
9297
foreach (Transform child in current)
9398
{
99+
if (child.name == "Materials")
100+
continue;
94101
child.gameObject.SetActive(false);
95102
}
96103

@@ -111,7 +118,10 @@ void DoCombineMeshes(Transform current)
111118
MeshRenderer mr = sub.gameObject.GetComponent<MeshRenderer>();
112119
if (mr == null) mr = sub.gameObject.AddComponent<MeshRenderer>();
113120

114-
mf.mesh = new Mesh();
121+
var combinedMesh = new Mesh();
122+
combinedMesh.name = "CombinedMesh";
123+
124+
mf.mesh = combinedMesh;
115125
if (vertexCount > kVertexLimit)
116126
{
117127
mf.sharedMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
@@ -132,7 +142,7 @@ void DoCombineMeshes(Transform current)
132142
{
133143
if (materials.Count == 0)
134144
{
135-
Debug.LogError("No material to assign to combined mesh for " + current.name);
145+
Debug.Log("No material to assign to combined mesh for " + current.name);
136146
}
137147
else
138148
{

package/com.unity.formats.usd/Samples/ImportProcessor/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
using UnityEditor;
14+
using UnityEngine;
15+
16+
namespace Unity.Formats.USD.Examples
17+
{
18+
[CustomEditor(typeof(CombineMeshes))]
19+
public class CombineMeshesEditor : Editor
20+
{
21+
public override void OnInspectorGUI()
22+
{
23+
DrawDefaultInspector();
24+
25+
CombineMeshes combineMeshesScript = (CombineMeshes)target;
26+
if (GUILayout.Button("Click Me to Refresh USD Asset"))
27+
{
28+
combineMeshesScript.RefreshUSD();
29+
}
30+
}
31+
}
32+
}
33+

package/com.unity.formats.usd/Samples/ImportProcessor/Editor/CombineMeshesEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
using UnityEditor;
14+
using UnityEngine;
15+
16+
namespace Unity.Formats.USD.Examples
17+
{
18+
[CustomEditor(typeof(SetHideFlags))]
19+
public class SetHideFlagsEditor : Editor
20+
{
21+
public override void OnInspectorGUI()
22+
{
23+
DrawDefaultInspector();
24+
25+
SetHideFlags combineMeshesScript = (SetHideFlags)target;
26+
if (GUILayout.Button("Click Me to Refresh USD Asset"))
27+
{
28+
combineMeshesScript.RefreshUSD();
29+
}
30+
}
31+
}
32+
}
33+

package/com.unity.formats.usd/Samples/ImportProcessor/Editor/SetHideFlagsEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)