Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Extract glTF utility to its own project. (#801)
Browse files Browse the repository at this point in the history
* PR to extract the glTF utilities in to their own project.

Resolves #800

* Version bump

* Added string extensions for analysing file names from URI paths for glTF web loading

* Addressed feedback

* Updated Examples branch

* Updated Submodules/Examples and Submodules/WindowsMixedReality to paired glTF updates

* Reverted Examples PR and switched it to use the new glTF package
Uplifted Core version dependency for Submodules

Co-authored-by: Stephen Hodgson <hodgson.designs@gmail.com>
  • Loading branch information
SimonDarksideJ and StephenHodgson authored Apr 11, 2021
1 parent 330a066 commit f78f18d
Show file tree
Hide file tree
Showing 121 changed files with 25 additions and 4,271 deletions.
12 changes: 0 additions & 12 deletions Editor/BuildAndDeploy/BuildDeployWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using UnityEngine;
using XRTK.Editor.Utilities;
using XRTK.Editor.Utilities.USB;
using XRTK.Utilities.Gltf;
using XRTK.Utilities.WebRequestRest;
using XRTK.Utilities.WindowsDevicePortal;
using XRTK.Utilities.WindowsDevicePortal.DataStructures;
Expand Down Expand Up @@ -525,17 +524,6 @@ private void AppxBuildGUI()

var prevFieldWidth = EditorGUIUtility.fieldWidth;

EditorGUIUtility.fieldWidth = 120;
var appIconAssetObject = AssetDatabase.LoadAssetAtPath<GltfAsset>(UwpBuildDeployPreferences.MixedRealityAppIconPath);

EditorGUI.BeginChangeCheck();
appIconAssetObject = EditorGUILayout.ObjectField(appIconLabel, appIconAssetObject, typeof(GltfAsset), false) as GltfAsset;

if (EditorGUI.EndChangeCheck())
{
UwpBuildDeployPreferences.MixedRealityAppIconPath = AssetDatabase.GetAssetPath(appIconAssetObject);
}

EditorGUIUtility.fieldWidth = prevFieldWidth;
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
Expand Down
18 changes: 18 additions & 0 deletions Runtime/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,23 @@ public static string ToForwardSlashes(this string value)
{
return value.Replace(BackSlash, ForwardSlash);
}

/// <summary>
/// Returns the URI path, excluding the filename
/// </summary>
/// <param name="value"></param>
public static string PathFromURI(this string value)
{
return value.Substring(0, value.LastIndexOf("/") + 1);
}

/// <summary>
/// Returns the filename from a URI path
/// </summary>
/// <param name="value"></param>
public static string FilenameFromURI(this string value)
{
return value.Substring(value.LastIndexOf("/") + 1, value.Length - value.LastIndexOf("/") - 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,9 @@ public interface IMixedRealityController
/// Attempts to load the controller model render settings from the <see cref="Definitions.Controllers.MixedRealityControllerVisualizationProfile"/>
/// to render the controllers in the scene.
/// </summary>
/// <param name="glbData">The raw binary glb data of the controller model, typically loaded from the driver.</param>
/// <param name="useAlternatePoseAction">Should the rendered controller use the alternate pose action?</param>
/// <returns>True, if controller model is being properly rendered.</returns>
void TryRenderControllerModel(byte[] glbData = null, bool useAlternatePoseAction = false);

/// <summary>
/// Attempts to load the controller model render settings from the <see cref="Definitions.Controllers.MixedRealityControllerVisualizationProfile"/>
/// to render the controllers in the scene.
/// </summary>
/// <param name="glbData">The raw binary glb data of the controller model, typically loaded from the driver.</param>
/// <param name="useAlternatePoseAction">Should the rendered controller use the alternate pose action?</param>
/// <returns>True, if controller model is being properly rendered.</returns>
Task TryRenderControllerModelAsync(byte[] glbData = null, bool useAlternatePoseAction = false);
void TryRenderControllerModel(bool useAlternatePoseAction = false);

/// <summary>
/// Updates the controller's state.
Expand Down
44 changes: 6 additions & 38 deletions Runtime/Providers/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
using XRTK.Interfaces.Providers.Controllers;
using XRTK.Services;
using XRTK.Utilities;
using XRTK.Utilities.Gltf.Schema;
using XRTK.Utilities.Gltf.Serialization;
using Object = UnityEngine.Object;

namespace XRTK.Providers.Controllers
Expand Down Expand Up @@ -203,33 +201,16 @@ private IMixedRealityPointer[] AssignControllerMappings(MixedRealityInteractionM
}

/// <inheritdoc />
public async void TryRenderControllerModel(byte[] glbData = null, bool useAlternatePoseAction = false) => await TryRenderControllerModelAsync(glbData, useAlternatePoseAction);

/// <summary>
/// Attempts to load the controller model render settings from the <see cref="MixedRealityControllerVisualizationProfile"/>
/// to render the controllers in the scene.
/// </summary>
/// <param name="glbData">The raw binary glb data of the controller model, typically loaded from the driver.</param>
/// <param name="useAlternatePoseAction">Should the visualizer be assigned the alternate pose actions?</param>
public async Task TryRenderControllerModelAsync(byte[] glbData = null, bool useAlternatePoseAction = false)
public void TryRenderControllerModel(bool useAlternatePoseAction = false)
{
if (visualizationProfile.IsNull())
{
Debug.LogWarning($"Missing {nameof(visualizationProfile)} for {GetType().Name}");
return;
}

GltfObject gltfObject = null;
GameObject controllerModel = null;

// if we have model data from the platform and the controller has been configured to use the default model, attempt to load the controller model from glbData.
if (glbData != null)
{
gltfObject = GltfUtility.GetGltfObjectFromGlb(glbData);
await gltfObject.ConstructAsync();
controllerModel = gltfObject.GameObjectReference;
}

// If we didn't get an override model, and we didn't load the driver model,
// then get the global controller model for each hand.
if (controllerModel.IsNull())
Expand All @@ -244,31 +225,18 @@ public async Task TryRenderControllerModelAsync(byte[] glbData = null, bool useA
break;
}
}

// If we've got a controller model, then place it in the scene and get/attach the visualizer.
if (!controllerModel.IsNull())
{
var playspaceTransform = MixedRealityToolkit.TryGetSystem<IMixedRealityCameraSystem>(out var cameraSystem)
? cameraSystem.MainCameraRig.PlayspaceTransform
: CameraCache.Main.transform.parent;

// If the model was loaded from a system template
if (gltfObject != null)
{
controllerModel.name = $"{GetType().Name}_Visualization";
controllerModel.transform.SetParent(playspaceTransform);
var visualizationType = visualizationProfile.ControllerVisualizationType;
controllerModel.AddComponent(visualizationType.Type);
Visualizer = controllerModel.GetComponent<IMixedRealityControllerVisualizer>();
}
// If the model was a prefab
else
{
var controllerObject = Object.Instantiate(controllerModel, playspaceTransform);
Debug.Assert(controllerObject != null);
controllerObject.name = $"{GetType().Name}_Visualization";
Visualizer = controllerObject.GetComponent<IMixedRealityControllerVisualizer>();
}
var controllerObject = Object.Instantiate(controllerModel, playspaceTransform);
Debug.Assert(controllerObject != null);
controllerObject.name = $"{GetType().Name}_Visualization";
Visualizer = controllerObject.GetComponent<IMixedRealityControllerVisualizer>();

// If a visualizer exists, set it up and bind it to the controller
if (Visualizer != null)
Expand Down
8 changes: 0 additions & 8 deletions Runtime/Utilities/Gltf.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Runtime/Utilities/Gltf/Schema.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Runtime/Utilities/Gltf/Schema/Extensions.meta

This file was deleted.

10 changes: 0 additions & 10 deletions Runtime/Utilities/Gltf/Schema/Extensions/GltfExtension.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Runtime/Utilities/Gltf/Schema/Extensions/GltfExtension.cs.meta

This file was deleted.

This file was deleted.

This file was deleted.

129 changes: 0 additions & 129 deletions Runtime/Utilities/Gltf/Schema/GltfAccessor.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Runtime/Utilities/Gltf/Schema/GltfAccessor.cs.meta

This file was deleted.

20 changes: 0 additions & 20 deletions Runtime/Utilities/Gltf/Schema/GltfAccessorAttributeType.cs

This file was deleted.

Loading

0 comments on commit f78f18d

Please sign in to comment.