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

[SDK-622] Feature/unity gltfast #155

Merged
merged 4 commits into from
Nov 20, 2023
Merged
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
32 changes: 8 additions & 24 deletions Editor/Module Management/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public static class ModuleInstaller

private const int THREAD_SLEEP_TIME = 100;
private const string PROGRESS_BAR_TITLE = "Ready Player Me";
private const string GLTFAST_NAME = "com.atteneder.gltfast";
private const string WEBVIEW_NAME = "webview";

private const string MODULE_INSTALLATION_SUCCESS_MESSAGE =
"All the modules are installed successfully. Ready Player Me avatar system is ready to use.";
Expand All @@ -37,26 +35,17 @@ public static class ModuleInstaller

static ModuleInstaller()
{

Events.registeringPackages -= OnRegisteringPackages;
Events.registeringPackages += OnRegisteringPackages;
# if RPM_DEVELOPMENT
modulesInstalled = true;
#endif
if (!modulesInstalled)
{
InstallModules();
EditorApplication.delayCall += DelayCreateCoreSettings;
}

#if !GLTFAST
if (IsModuleInstalled(GLTFAST_NAME))
{
DefineSymbolHelper.AddSymbols();
}
#endif

#if !READY_PLAYER_ME
InstallModules();
EditorApplication.delayCall += DelayCreateCoreSettings;
DefineSymbolHelper.AddSymbols();
#endif
}

/// <summary>
/// Called when a package is about to be added, removed or changed.
/// </summary>
Expand All @@ -75,6 +64,7 @@ private static void DelayCreateCoreSettings()
{
EditorApplication.delayCall -= DelayCreateCoreSettings;
CoreSettingsLoader.EnsureSettingsExist();

}

/// <summary>
Expand All @@ -86,7 +76,6 @@ private static void InstallModules()
Thread.Sleep(THREAD_SLEEP_TIME);

ModuleInfo[] missingModules = GetMissingModuleNames();

if (missingModules.Length > 0)
{
var installedModuleCount = 0f;
Expand Down Expand Up @@ -134,11 +123,6 @@ private static ModuleInfo[] GetMissingModuleNames()
{
PackageInfo[] installed = GetPackageList();
var missingModules = ModuleList.Modules.Where(m => installed.All(i => m.name != i.name)).ToList();

if(!missingModules.Any(module => module.name.Contains(GLTFAST_NAME)))
{
missingModules = missingModules.Where(module => !module.name.Contains(WEBVIEW_NAME)).ToList();
}
return missingModules.ToArray();
}

Expand Down
7 changes: 0 additions & 7 deletions Editor/Module Management/ModuleList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public static class ModuleList
/// </summary>
public static readonly ModuleInfo[] Modules =
{
new ModuleInfo
{
name = "com.atteneder.gltfast",
gitUrl = "https://github.com/atteneder/glTFast.git",
branch = "v5.0.0",
version = "5.0.0"
},
new ModuleInfo
{
name = "com.readyplayerme.webview",
Expand Down
4 changes: 0 additions & 4 deletions Editor/ShaderVariantHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ public static class ShaderVariantHelper
[InitializeOnLoadMethod]
private static void InitializeOnLoad()
{
#if GLTFAST
if (SessionState.GetBool(SHADER_SESSION_CHECK, false)) return;
SessionState.SetBool(SHADER_SESSION_CHECK, true);

EditorApplication.update += CheckAndUpdatePreloadShaders;
#endif
}

private static void CheckAndUpdatePreloadShaders()
Expand Down Expand Up @@ -70,7 +68,6 @@ public static void AddPreloadShaderVariants(bool checkForMissingVariants = false
if (!shadersMissing) return;
}


shaderPreloadArray.InsertArrayElementAtIndex(newArrayIndex);
SerializedProperty shaderInArray = shaderPreloadArray.GetArrayElementAtIndex(newArrayIndex);
shaderInArray.objectReferenceValue = shaderVariants;
Expand All @@ -79,7 +76,6 @@ public static void AddPreloadShaderVariants(bool checkForMissingVariants = false
AssetDatabase.SaveAssets();
}


public static bool IsMissingVariants()
{
var graphicsSettings = AssetDatabase.LoadAssetAtPath<GraphicsSettings>(GRAPHICS_SETTING_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public class AvatarLoaderEditor : EditorWindow
[MenuItem("Ready Player Me/Avatar Loader", priority = 1)]
public static void ShowWindow()
{
#if !GLTFAST
DefineSymbolHelper.AddSymbols();
#endif
var window = GetWindow<AvatarLoaderEditor>();
window.titleContent = new GUIContent(AVATAR_LOADER);
window.minSize = new Vector2(500, 300);
Expand Down
11 changes: 4 additions & 7 deletions Editor/Utils/DefineSymbolHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ namespace ReadyPlayerMe.Core.Editor
{
public static class DefineSymbolHelper
{
private const string GLTFAST_SYMBOL = "GLTFAST";
HarrisonHough marked this conversation as resolved.
Show resolved Hide resolved
private const string READY_PLAYER_ME_SYMBOL = "READY_PLAYER_ME";

private static void ModifyScriptingDefineSymbolInAllBuildTargetGroups(string defineSymbol, bool addSymbol)
{
foreach (BuildTarget target in Enum.GetValues(typeof(BuildTarget)))
Expand Down Expand Up @@ -54,19 +53,17 @@ private static void ModifyScriptingDefineSymbolInAllBuildTargetGroups(string def
CompilationPipeline.RequestScriptCompilation();
}
}

public static void AddSymbols()
{
ModifyScriptingDefineSymbolInAllBuildTargetGroups(GLTFAST_SYMBOL, true);
ModifyScriptingDefineSymbolInAllBuildTargetGroups(READY_PLAYER_ME_SYMBOL, true);
CompilationPipeline.RequestScriptCompilation();
}

public static void RemoveSymbols()
{
ModifyScriptingDefineSymbolInAllBuildTargetGroups(GLTFAST_SYMBOL, false);
ModifyScriptingDefineSymbolInAllBuildTargetGroups(READY_PLAYER_ME_SYMBOL, false);
}

}
}
4 changes: 0 additions & 4 deletions Runtime/GLTF/GLTFDeferAgent.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#if GLTFAST
using GLTFast;
#endif
using UnityEngine;

namespace ReadyPlayerMe.Core
{
public class GLTFDeferAgent : MonoBehaviour
{
#if GLTFAST
public IDeferAgent GetGLTFastDeferAgent()
{
return GetComponent<IDeferAgent>();
}
#endif
}
}
4 changes: 1 addition & 3 deletions Runtime/GLTF/GltFastGameObjectInstantiator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if GLTFAST
using GLTFast;
using GLTFast;
using GLTFast.Logging;
using UnityEngine;

Expand Down Expand Up @@ -103,4 +102,3 @@ public override void AddPrimitive(
}
}
}
#endif
6 changes: 0 additions & 6 deletions Runtime/GLTF/GltfImporter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
#if GLTFAST
using GLTFast;
using System;
using System.IO;
#endif

namespace ReadyPlayerMe.Core
{
Expand All @@ -21,7 +19,6 @@ public GltfImporter(CancellationToken token)
public async Task<GameObject> Import(string path)
{
GameObject avatar = null;
#if GLTFAST
var data = File.ReadAllBytes(path);
var gltf = new GltfImport(deferAgent: new UninterruptedDeferAgent());

Expand All @@ -39,14 +36,12 @@ public async Task<GameObject> Import(string path)

await gltf.InstantiateMainSceneAsync(customInstantiator, token);
}
#endif
return avatar;
}

public async Task<GameObject> Import(byte[] bytes, GLTFDeferAgent gltfDeferAgent = null)
{
GameObject avatar = null;
#if GLTFAST
IDeferAgent agent = gltfDeferAgent == null ? new UninterruptedDeferAgent() : gltfDeferAgent.GetGLTFastDeferAgent();

var gltf = new GltfImport(deferAgent: agent);
Expand All @@ -59,7 +54,6 @@ public async Task<GameObject> Import(byte[] bytes, GLTFDeferAgent gltfDeferAgent

await gltf.InstantiateMainSceneAsync(customInstantiator, token);
}
#endif
return avatar;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"changelogUrl": "https://github.com/readyplayerme/rpm-unity-sdk-core/blob/main/CHANGELOG.md",
"licensesUrl": "https://github.com/readyplayerme/rpm-unity-sdk-core/blob/main/LICENSE.md",
"dependencies": {
"com.unity.cloud.gltfast": "5.0.4",
HarrisonHough marked this conversation as resolved.
Show resolved Hide resolved
"com.unity.nuget.newtonsoft-json": "3.0.2"
},
"keywords": [
Expand Down