/// <summary> /// Method <c>LoadHologram</c> is used to load hologram from Storage server /// It requires thehologram ID as the parameter /// </summary> /// <param name="hologramID">ID of Hologram</param> public static async void LoadHologram(string hologramID, HologramInstantiationSettings setting = null) { if (setting == null) { setting = new HologramInstantiationSettings(); } string getHologramUri = $"{BaseUri}/holograms/{hologramID}/download"; Response response = new Response(); try { response = await Rest.GetAsync(getHologramUri); } catch (Exception e) { Debug.LogError(e.Message); } if (!response.Successful) { Debug.LogError($"Failed to get glb model from {getHologramUri}"); return; } var gltfObject = GltfUtility.GetGltfObjectFromGlb(response.ResponseData); try { GameObject loadedObject = await gltfObject.ConstructAsync(); HologramInstantiationSettings.Initialize(loadedObject, setting); } catch (Exception e) { Debug.LogError($"{e.Message}\n{e.StackTrace}"); return; } }
/// <summary> /// Initialize transform settings of the gameobject /// </summary> /// <param name="gameobject">The loaded GameObject</param> public static void Initialize(GameObject gameobject, HologramInstantiationSettings setting) { gameobject.name = setting.Name; Mesh mesh = gameobject.GetComponentsInChildren <MeshFilter>()[0].sharedMesh; float max = Math.Max(Math.Max(mesh.bounds.size.x, mesh.bounds.size.y), mesh.bounds.size.z); float scaleSize = setting.Size / max; gameobject.transform.localScale = new Vector3(scaleSize, scaleSize, scaleSize); Vector3 initialPosition = new Vector3(mesh.bounds.center.x, -mesh.bounds.center.y, mesh.bounds.center.z) * scaleSize; gameobject.transform.position = initialPosition + setting.Position; gameobject.transform.eulerAngles = setting.Rotation; if (setting.Manipulable) { gameobject.AddComponent <BoundingBox>(); gameobject.AddComponent <ManipulationHandler>(); } if (setting.SceneName != null) { try { Scene HologramDisplayScene = SceneManager.GetSceneByName(setting.SceneName); SceneManager.MoveGameObjectToScene(gameobject, HologramDisplayScene); } catch (Exception e) { Debug.LogError("Failed to move the object to specific scene! \n[Error message]: " + e.Message); } } }