Skip to content

Commit 7ac28f7

Browse files
committed
Undo formatting changes
1 parent 0d2e987 commit 7ac28f7

File tree

2 files changed

+33
-68
lines changed

2 files changed

+33
-68
lines changed

Assets/Scripts/Model.cs

Lines changed: 29 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929

3030
namespace TiltBrush
3131
{
32+
3233
public class Model
3334
{
35+
3436
public struct Location
3537
{
3638
public enum Type
@@ -59,7 +61,6 @@ public static Location File(string relativePath)
5961
path = relativePath.Substring(0, lastIndex);
6062
fragment = relativePath.Substring(lastIndex + 1);
6163
}
62-
6364
return new Location
6465
{
6566
type = Type.LocalFile,
@@ -87,15 +88,13 @@ public string AbsolutePath
8788
{
8889
return null;
8990
}
90-
9191
switch (type)
9292
{
9393
case Type.LocalFile:
9494
return Path.Combine(App.ModelLibraryPath(), path).Replace("\\", "/");
9595
case Type.IcosaAssetId:
9696
return path.Replace("\\", "/");
9797
}
98-
9998
return null;
10099
}
101100
}
@@ -104,11 +103,7 @@ public string RelativePath
104103
{
105104
get
106105
{
107-
if (type == Type.LocalFile)
108-
{
109-
return path;
110-
}
111-
106+
if (type == Type.LocalFile) { return path; }
112107
throw new Exception("Invalid relative path request");
113108
}
114109
}
@@ -119,19 +114,12 @@ public string AssetId
119114
{
120115
get
121116
{
122-
if (type == Type.IcosaAssetId)
123-
{
124-
return id;
125-
}
126-
117+
if (type == Type.IcosaAssetId) { return id; }
127118
throw new Exception("Invalid Icosa asset id request");
128119
}
129120
}
130121

131-
public Type GetLocationType()
132-
{
133-
return type;
134-
}
122+
public Type GetLocationType() { return type; }
135123

136124
public override int GetHashCode()
137125
{
@@ -149,7 +137,6 @@ public override string ToString()
149137
{
150138
str = $"{type}:{path}";
151139
}
152-
153140
return str;
154141
}
155142

@@ -159,7 +146,6 @@ public override bool Equals(object obj)
159146
{
160147
return false;
161148
}
162-
163149
return this == (Location)obj;
164150
}
165151

@@ -212,10 +198,8 @@ public LoadError(string message, string detail = null)
212198
this.message = message;
213199
this.detail = detail;
214200
}
215-
216201
public readonly string message; // Human-readable short message
217-
218-
public readonly string detail; // Maybe non-human-readable details
202+
public readonly string detail; // Maybe non-human-readable details
219203
// maybe? public bool transient; // true if we know for sure that this error is transient
220204
}
221205

@@ -225,7 +209,6 @@ public LoadError(string message, string detail = null)
225209

226210
/// m_LoadError != null implies m_Valid == false
227211
private LoadError? m_LoadError;
228-
229212
public LoadError? Error => m_LoadError;
230213

231214
// How many widgets are using this model?
@@ -267,11 +250,7 @@ public IExportableMaterial GetExportableMaterial(Material material)
267250
return m_ImportMaterialCollector.GetExportableMaterial(material);
268251
}
269252

270-
271-
public Model(Location location)
272-
{
273-
m_Location = location;
274-
}
253+
public Model(Location location) { m_Location = location; }
275254

276255
public Location GetLocation()
277256
{
@@ -309,7 +288,11 @@ abstract class ModelBuilder
309288
/// It's unclear if the intent is that the user should continue calling TryEndAsyncLoad
310289
/// until it returns true, or if they should stop calling TryEndAsyncLoad. etc. Probably
311290
/// we should remove this.
312-
public bool IsValid { get; protected set; }
291+
public bool IsValid
292+
{
293+
get;
294+
protected set;
295+
}
313296

314297
public ModelBuilder(string localPath)
315298
{
@@ -334,15 +317,13 @@ public void CancelAsyncLoad()
334317
if (m_root != null)
335318
{
336319
foreach (var mesh in m_root.GetComponentsInChildren<MeshFilter>()
337-
.Select(x => x.sharedMesh))
320+
.Select(x => x.sharedMesh))
338321
{
339322
UObject.Destroy(mesh);
340323
}
341-
342324
UObject.Destroy(m_root);
343325
m_root = null;
344326
}
345-
346327
m_stateReader.Close();
347328
}
348329

@@ -352,7 +333,7 @@ public void CancelAsyncLoad()
352333
/// ImportMaterialCollector - non-null upon successful completion.
353334
/// Raises an exception on unsuccessful completion.
354335
public bool TryEndAsyncLoad(out GameObject root,
355-
out ImportMaterialCollector importMaterialCollector)
336+
out ImportMaterialCollector importMaterialCollector)
356337
{
357338
// Three things happen in this function.
358339
// 1: It waits to try and get the result of reading the model on a background thread
@@ -364,10 +345,7 @@ public bool TryEndAsyncLoad(out GameObject root,
364345
if (m_meshEnumerator == null)
365346
{
366347
IDisposable state;
367-
if (!m_stateReader.TryGetResult(out state))
368-
{
369-
return false;
370-
}
348+
if (!m_stateReader.TryGetResult(out state)) { return false; }
371349

372350
IEnumerable<Null> enumerable;
373351
m_root = DoUnityThreadWork(state, out enumerable, out m_ImportMaterialCollector);
@@ -380,15 +358,13 @@ public bool TryEndAsyncLoad(out GameObject root,
380358
{
381359
return false;
382360
}
383-
384361
m_ImportMaterialCollector = new ImportMaterialCollector(
385362
Path.GetDirectoryName(m_localPath),
386363
uniqueSeed: m_localPath
387364
);
388365
m_meshEnumerator = enumerable.GetEnumerator();
389366
m_root.SetActive(false);
390367
}
391-
392368
// Yield until the limiter unblocks.
393369
// Multiple calls to TryGetResult above are harmless.
394370
if (sm_Limiter.IsBlocked())
@@ -410,7 +386,6 @@ public bool TryEndAsyncLoad(out GameObject root,
410386
stopwatch.Stop();
411387
return true;
412388
}
413-
414389
if (stopwatch.ElapsedTicks > numTicks)
415390
{
416391
stopwatch.Stop();
@@ -461,14 +436,13 @@ protected override IDisposable DoBackgroundThreadWork()
461436
{
462437
return ImportGltf.BeginImport(m_localPath, loader, options);
463438
}
464-
465439
return NewGltfImporter.BeginImport(m_localPath);
466440
}
467441

468442
protected override GameObject DoUnityThreadWork(IDisposable state__,
469-
out IEnumerable<Null> meshEnumerable,
470-
out ImportMaterialCollector
471-
importMaterialCollector)
443+
out IEnumerable<Null> meshEnumerable,
444+
out ImportMaterialCollector
445+
importMaterialCollector)
472446
{
473447
GameObject rootObject = null;
474448
if (m_fromIcosa)
@@ -492,7 +466,6 @@ out ImportMaterialCollector
492466
importMaterialCollector = (ImportMaterialCollector)result.materialCollector;
493467
}
494468
}
495-
496469
IsValid = rootObject != null;
497470
meshEnumerable = null;
498471
importMaterialCollector = null;
@@ -511,11 +484,9 @@ out ImportMaterialCollector
511484
// EndImport doesn't try to use the loadImages functionality of UriLoader anyway.
512485
// It knows it's on the main thread, so chooses to use Unity's fast loading.
513486
rootObject = state.root;
514-
importMaterialCollector =
515-
new ImportMaterialCollector(assetLocation, uniqueSeed: m_localPath);
487+
importMaterialCollector = new ImportMaterialCollector(assetLocation, uniqueSeed: m_localPath);
516488
}
517489
}
518-
519490
IsValid = rootObject != null;
520491
return rootObject;
521492
}
@@ -533,6 +504,7 @@ GameObject LoadUsd(List<string> warnings)
533504

534505
GameObject LoadPly(List<string> warningsOut)
535506
{
507+
536508
try
537509
{
538510
var reader = new PlyReader(m_Location.AbsolutePath);
@@ -549,6 +521,7 @@ GameObject LoadPly(List<string> warningsOut)
549521
Debug.LogException(ex);
550522
return null;
551523
}
524+
552525
}
553526

554527
GameObject LoadSvg(List<string> warningsOut, out SVGParser.SceneInfo sceneInfo)
@@ -689,7 +662,6 @@ public bool TryLoadModel()
689662
{
690663
return false;
691664
}
692-
693665
isValid = m_builder.IsValid;
694666
}
695667
catch (ObjectDisposedException ex)
@@ -732,11 +704,12 @@ public async Task LoadModelAsync()
732704
{
733705
Task t = StartCreatePrefab(null);
734706
await t;
735-
}
736707

708+
}
737709
public void LoadModel()
738710
{
739711
StartCreatePrefab(null);
712+
740713
}
741714

742715
/// Either synchronously load a GameObject hierarchy and convert it to a "prefab"
@@ -776,7 +749,7 @@ private async Task StartCreatePrefab(GameObject go)
776749
EndCreatePrefab(go, warnings);
777750
}
778751
else if (m_Location.GetLocationType() == Location.Type.IcosaAssetId ||
779-
ext == ".gltf2" || ext == ".gltf" || ext == ".glb")
752+
ext == ".gltf2" || ext == ".gltf" || ext == ".glb")
780753
{
781754
// If we pulled this from Icosa, it's going to be a gltf file.
782755
Task t = LoadGltf(warnings);
@@ -806,6 +779,7 @@ private async Task StartCreatePrefab(GameObject go)
806779
m_LoadError = new LoadError("Unknown format", ext);
807780
}
808781
}
782+
809783
}
810784

811785
public void CalcBoundsGltf(GameObject go)
@@ -827,7 +801,6 @@ public void CalcBoundsGltf(GameObject go)
827801
b.Encapsulate(bounds);
828802
}
829803
}
830-
831804
m_MeshBounds = b;
832805
if (first)
833806
{
@@ -857,16 +830,15 @@ private void CalcBoundsNonGltf(GameObject go)
857830
{
858831
b.Encapsulate(bc.bounds);
859832
}
860-
861833
UnityEngine.Object.Destroy(bc);
862834
}
863-
864835
m_MeshBounds = b;
865836
if (first)
866837
{
867838
// There was no geometry
868839
Debug.LogErrorFormat("No usable geometry in model. LoadModel({0})", go.name);
869840
}
841+
870842
}
871843

872844
public void EndCreatePrefab(GameObject go, List<string> warnings)
@@ -885,7 +857,6 @@ public void EndCreatePrefab(GameObject go, List<string> warnings)
885857
{
886858
UnityEngine.Object.Destroy(m_ModelParent.gameObject);
887859
}
888-
889860
m_ModelParent = go.transform;
890861

891862
#if DEVELOPMENT_BUILD || UNITY_EDITOR
@@ -928,27 +899,24 @@ void SetUniqueNameForNode(Transform node)
928899
}
929900
}
930901

931-
932902
public void UnloadModel()
933903
{
934904
if (m_builder != null)
935905
{
936906
m_builder.CancelAsyncLoad();
937907
m_builder = null;
938908
}
939-
940909
m_Valid = false;
941910
m_LoadError = null;
942911
if (m_ModelParent != null)
943912
{
944913
// Procedurally created meshes need to be explicitly destroyed - you can't just destroy
945914
// the MeshFilter that references them.
946915
foreach (var mesh in m_ModelParent.GetComponentsInChildren<MeshFilter>()
947-
.Select(x => x.sharedMesh))
916+
.Select(x => x.sharedMesh))
948917
{
949918
UObject.Destroy(mesh);
950919
}
951-
952920
UObject.Destroy(m_ModelParent.gameObject);
953921
m_ModelParent = null;
954922
}
@@ -976,7 +944,6 @@ public IEnumerator LoadFullyCoroutine(string reason)
976944
{
977945
yield return null;
978946
}
979-
980947
break;
981948
default:
982949
m_LoadError = new LoadError($"Unknown load type {type}");
@@ -1001,7 +968,7 @@ private void DisplayWarnings(List<string> warnings)
1001968
public bool IsCached()
1002969
{
1003970
return m_Location.GetLocationType() == Location.Type.IcosaAssetId &&
1004-
Directory.Exists(m_Location.AbsolutePath);
971+
Directory.Exists(m_Location.AbsolutePath);
1005972
}
1006973

1007974
public void RefreshCache()
@@ -1019,7 +986,6 @@ public MeshFilter[] GetMeshes()
1019986
{
1020987
throw new InvalidOperationException();
1021988
}
1022-
1023989
return m_ModelParent.GetComponent<ObjModelScript>().m_MeshChildren;
1024990
}
1025991

@@ -1032,7 +998,6 @@ public string GetExportName()
1032998
case Model.Location.Type.IcosaAssetId:
1033999
return AssetId;
10341000
}
1035-
10361001
return "Unknown";
10371002
}
10381003

@@ -1061,4 +1026,4 @@ public void EnsureCollectorExists()
10611026
}
10621027
}
10631028
}
1064-
} // namespace TiltBrush;
1029+
} // namespace TiltBrush;

0 commit comments

Comments
 (0)