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

2021/main #490

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.0.0-pre]
### Changed
- Converted a lot of unintentionally public classes, types and properties to internal ones

## [4.7.0] - 2022-04-25
### Added
- `RenderPipelineUtils` to detect current render pipeline
Expand Down Expand Up @@ -54,6 +58,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `GameObject -> Export glTF` for GameObjects (may also be accessed from hierarchy view context menu)
- (Documentation) Split up monolithic docs into multiple markdown files
- (Documentation) Changelog links to code are now `xref` (for DocFX)
### Removed
- Converted a lot of unintentionally public classes, types and properties to internal ones
- `StopWatch`, a class used for measuring load times in tests, was moved to a dedicated test repository
### Fixed
- Point meshes are rendered consistently on more platforms (iOS, Vulkan) due to explicitely setting `PSIZE` (thanks [Kim Wonkee][wonkee-kim] for #309)
- Removed Editor markup resources from builds
Expand Down
199 changes: 101 additions & 98 deletions Editor/Scripts/AsyncHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,128 +5,131 @@
using System.Threading.Tasks;
using System.Collections.Generic;

public static class AsyncHelpers
{
/// <summary>
/// Execute's an async Task<T> method which has a void return value synchronously
/// </summary>
/// <param name="task">Task<T> method to execute</param>
public static void RunSync(Func<Task> task)
namespace GLTFast.Utils {

static class AsyncHelpers
{
var oldContext = SynchronizationContext.Current;
var synch = new ExclusiveSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(synch);
synch.Post(async _ =>
/// <summary>
/// Executes an async Task&lt;T&gt; method which has a void return value synchronously
/// </summary>
/// <param name="task">Task&lt;T&gt; method to execute</param>
public static void RunSync(Func<Task> task)
{
try
{
await task();
}
catch (Exception e)
var oldContext = SynchronizationContext.Current;
var sync = new ExclusiveSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(sync);
sync.Post(async _ =>
{
synch.InnerException = e;
throw;
}
finally
{
synch.EndMessageLoop();
}
}, null);
synch.BeginMessageLoop();
try
{
await task();
}
catch (Exception e)
{
sync.InnerException = e;
throw;
}
finally
{
sync.EndMessageLoop();
}
}, null);
sync.BeginMessageLoop();

SynchronizationContext.SetSynchronizationContext(oldContext);
}
SynchronizationContext.SetSynchronizationContext(oldContext);
}

/// <summary>
/// Execute's an async Task<T> method which has a T return type synchronously
/// </summary>
/// <typeparam name="T">Return Type</typeparam>
/// <param name="task">Task<T> method to execute</param>
/// <returns></returns>
public static T RunSync<T>(Func<Task<T>> task)
{
var oldContext = SynchronizationContext.Current;
var synch = new ExclusiveSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(synch);
T ret = default(T);
synch.Post(async _ =>
/// <summary>
/// Executes an async Task&lt;T&gt; method which has a T return type synchronously
/// </summary>
/// <typeparam name="T">Return Type</typeparam>
/// <param name="task">Task&lt;T&gt; method to execute</param>
/// <returns></returns>
public static T RunSync<T>(Func<Task<T>> task)
{
try
var oldContext = SynchronizationContext.Current;
var sync = new ExclusiveSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(sync);
T ret = default(T);
sync.Post(async _ =>
{
ret = await task();
}
catch (Exception e)
try
{
ret = await task();
}
catch (Exception e)
{
sync.InnerException = e;
throw;
}
finally
{
sync.EndMessageLoop();
}
}, null);
sync.BeginMessageLoop();
SynchronizationContext.SetSynchronizationContext(oldContext);
return ret;
}

class ExclusiveSynchronizationContext : SynchronizationContext
{
bool done;
public Exception InnerException { get; set; }
readonly AutoResetEvent workItemsWaiting = new AutoResetEvent(false);
readonly Queue<Tuple<SendOrPostCallback, object>> items =
new Queue<Tuple<SendOrPostCallback, object>>();

public override void Send(SendOrPostCallback d, object state)
{
synch.InnerException = e;
throw;
throw new NotSupportedException("We cannot send to our same thread");
}
finally

public override void Post(SendOrPostCallback d, object state)
{
synch.EndMessageLoop();
lock (items)
{
items.Enqueue(Tuple.Create(d, state));
}
workItemsWaiting.Set();
}
}, null);
synch.BeginMessageLoop();
SynchronizationContext.SetSynchronizationContext(oldContext);
return ret;
}

private class ExclusiveSynchronizationContext : SynchronizationContext
{
private bool done;
public Exception InnerException { get; set; }
readonly AutoResetEvent workItemsWaiting = new AutoResetEvent(false);
readonly Queue<Tuple<SendOrPostCallback, object>> items =
new Queue<Tuple<SendOrPostCallback, object>>();

public override void Send(SendOrPostCallback d, object state)
{
throw new NotSupportedException("We cannot send to our same thread");
}

public override void Post(SendOrPostCallback d, object state)
{
lock (items)
public void EndMessageLoop()
{
items.Enqueue(Tuple.Create(d, state));
Post(_ => done = true, null);
}
workItemsWaiting.Set();
}

public void EndMessageLoop()
{
Post(_ => done = true, null);
}

public void BeginMessageLoop()
{
while (!done)
public void BeginMessageLoop()
{
Tuple<SendOrPostCallback, object> task = null;
lock (items)
while (!done)
{
if (items.Count > 0)
Tuple<SendOrPostCallback, object> task = null;
lock (items)
{
task = items.Dequeue();
if (items.Count > 0)
{
task = items.Dequeue();
}
}
}
if (task != null)
{
task.Item1(task.Item2);
if (InnerException != null) // the method threw an exeption
if (task != null)
{
throw new AggregateException("AsyncHelpers.Run method threw an exception.", InnerException);
task.Item1(task.Item2);
if (InnerException != null) // the method threw an exception
{
throw new AggregateException("AsyncHelpers.Run method threw an exception.", InnerException);
}
}
else
{
workItemsWaiting.WaitOne();
}
}
else
{
workItemsWaiting.WaitOne();
}
}
}

public override SynchronizationContext CreateCopy()
{
return this;
public override SynchronizationContext CreateCopy()
{
return this;
}
}
}
}
2 changes: 1 addition & 1 deletion Editor/Scripts/BuiltInShaderGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace GLTFast.Editor
{
using Materials;

public class BuiltInShaderGUI : ShaderGUIBase
class BuiltInShaderGUI : ShaderGUIBase
{

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Editor/Scripts/EditorDownloadProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace GLTFast.Editor {

using Loading;

public class EditorDownloadProvider : IDownloadProvider {
class EditorDownloadProvider : IDownloadProvider {

public List<GltfAssetDependency> assetDependencies = new List<GltfAssetDependency>();

Expand Down Expand Up @@ -55,7 +55,7 @@ Uri MakePathProjectRelative(Uri uri) {
}
}

public class SyncFileLoader : IDownload {
class SyncFileLoader : IDownload {
public SyncFileLoader(Uri url) {
var path = url.OriginalString;
if (File.Exists(path)) {
Expand Down Expand Up @@ -87,7 +87,7 @@ public bool? isBinary {
}
}

public class SyncTextureLoader : SyncFileLoader, ITextureDownload {
class SyncTextureLoader : SyncFileLoader, ITextureDownload {

public Texture2D texture { get; }

Expand Down
2 changes: 1 addition & 1 deletion Editor/Scripts/GltfAssetDependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace GLTFast {

[Serializable]
public struct GltfAssetDependency {
struct GltfAssetDependency {

public enum Type {
Unknown,
Expand Down
3 changes: 2 additions & 1 deletion Editor/Scripts/GltfImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GLTFast.Utils;
using UnityEditor;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
Expand All @@ -50,7 +51,7 @@ namespace GLTFast.Editor {
#else
[ScriptedImporter(1, null, overrideExts: new[] { "gltf","glb" })]
#endif
public class GltfImporter : ScriptedImporter {
class GltfImporter : ScriptedImporter {

[SerializeField]
EditorImportSettings editorImportSettings;
Expand Down
2 changes: 1 addition & 1 deletion Editor/Scripts/GltfImporterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace GLTFast {

[CustomEditor(typeof(GltfImporter))]
// [CanEditMultipleObjects]
public class GltfImporterEditor : ScriptedImporterEditor
class GltfImporterEditor : ScriptedImporterEditor
{

// To be assigned defaults from the inspector
Expand Down
3 changes: 2 additions & 1 deletion Editor/Scripts/MenuEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.IO;
using System.Linq;
using GLTFast.Export;
using GLTFast.Utils;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
Expand All @@ -26,7 +27,7 @@

namespace GLTFast.Editor {

public static class MenuEntries {
static class MenuEntries {

const string k_GltfExtension = "gltf";
const string k_GltfBinaryExtension = "glb";
Expand Down
2 changes: 1 addition & 1 deletion Editor/Scripts/OnScriptsReloadHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using UnityEditor.PackageManager.Requests;

namespace GLTFast {
public static class OnScriptsReloadHandler {
static class OnScriptsReloadHandler {

// Only run this check if glTFast is in Packages/manifest.json testables
// (which indicates you're developing it)
Expand Down
2 changes: 1 addition & 1 deletion Editor/Scripts/ShaderGUIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace GLTFast.Editor
{
public class ShaderGUIBase : ShaderGUI
class ShaderGUIBase : ShaderGUI
{
protected const float TOLERANCE = 0.001f;

Expand Down
2 changes: 1 addition & 1 deletion Editor/Scripts/ShaderGraphGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace GLTFast.Editor
{
public class ShaderGraphGUI : ShaderGUIBase
class ShaderGraphGUI : ShaderGUIBase
{

private UvTransform? uvTransform;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Export/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace GLTFast.Export {
static class Constants {
public const string version = "4.7.0";
public const string version = "7.0.0-exp.1";

internal const string mimeTypePNG = "image/png";
internal const string mimeTypeJPG = "image/jpeg";
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Export/ExportJobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace GLTFast.Export {

[BurstCompile]
public static class ExportJobs {
static class ExportJobs {

[BurstCompile]
public struct ConvertIndicesFlippedJob<T> : IJobParallelFor where T : struct {
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Export/StreamExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#endif

namespace GLTFast.Export {
public static class StreamExtension {
static class StreamExtension {

#if NET_STANDARD
public static unsafe void Write(this Stream stream, NativeArray<byte> array) {
Expand Down
Loading