public async void LoadModel() { // create a root object to parent a loaded model to modelEntity = arrService.CurrentActiveSession.Actions.CreateEntity(); arrService.CurrentActiveSession.Actions.CreateComponent(ObjectType.HierarchicalStateOverrideComponent, modelEntity); // get the game object representation of this entity modelEntityGO = modelEntity.GetOrCreateGameObject(UnityCreationMode.DoNotCreateUnityComponents); // ensure the entity will sync translations with the server var sync = modelEntityGO.GetComponent <RemoteEntitySyncObject>(); sync.SyncEveryFrame = true; // set position to an arbitrary distance from the parent modelEntityGO.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2; modelEntityGO.transform.localScale = Vector3.one; #if UNITY_WSA // anchor the model in the world modelWorldAnchor = modelEntityGO.AddComponent <WorldAnchor>(); #endif // load a model that will be parented to the entity var loadModelParams = new LoadModelFromSASParams(ModelName, modelEntity); var async = arrService.CurrentActiveSession.Actions.LoadModelFromSASAsync(loadModelParams); async.ProgressUpdated += (float progress) => { Debug.Log($"Loading: {progress * 100.0f}%"); }; await async.AsTask(); }
public ModelProgressStatus Load(LoadModelFromSASParams loadModelParams) { var machine = AppServices.RemoteRendering?.PrimaryMachine; if (machine == null) { var msg = $"Unable to load model: this is no remote rendering session. (url = {loadModelParams.ModelUrl})"; Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, msg); AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error); return(null); } if (machine.Session.Connection.ConnectionStatus != ConnectionStatus.Connected) { var msg = $"Unable to load model: manager is not connected. (url = {loadModelParams.ModelUrl})"; Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, msg); AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error); return(null); } ModelProgressStatus progressTask = new ModelProgressStatus(); ScaleLoad(loadModelParams, progressTask); return(progressTask); }
private async Task LoadModel() { // create a root object to parent a loaded model to Entity modelEntity = arrService.CurrentActiveSession.Actions.CreateEntity(); // get the game object representation of this entity modelEntityGO = modelEntity.GetOrCreateGameObject(UnityCreationMode.DoNotCreateUnityComponents); // ensure the entity will sync translations with the server var sync = modelEntityGO.GetComponent <RemoteEntitySyncObject>(); sync.SyncEveryFrame = true; // set position to an arbitrary distance from the parent PlaceModel(); modelEntityGO.transform.localScale = Vector3.one; // load a model that will be parented to the entity var loadModelParams = new LoadModelFromSASParams(ModelName, modelEntity); var async = arrService.CurrentActiveSession.Actions.LoadModelFromSASAsync(loadModelParams); async.ProgressUpdated += (float progress) => { LogMessage($"Loading Model: {progress.ToString("P2", CultureInfo.InvariantCulture)}"); }; await async.AsTask(); }
private async void ScaleLoad(LoadModelFromSASParams loadModelParams, ModelProgressStatus progressTask) { var machine = AppServices.RemoteRendering?.PrimaryMachine; // Remember the current connection, so we can cancel the load on a new connection uint connectionId = _connectionId; LoadModelAsync loadOperation = null; _progress.Add(progressTask); while (true) { if (machine == null) { var msg = $"Unable to load model: there is no remote rendering session. (url = {loadModelParams.ModelUrl})"; Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, msg); AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error); break; } lock (_loadingTasks) { if (_loadingTasks.Count == 0 || _loadingTasks.Count < _remoteObjectFactoryServiceProfile.ConcurrentModelLoads) { loadOperation = machine.Actions.LoadModelAsyncAsOperation(loadModelParams); break; } } await Task.WhenAll(_loadingTasks); lock (_loadingTasks) { _loadingTasks.Clear(); } } if (loadOperation != null) { if (_connectionId != connectionId) { progressTask.Start(null); } else { progressTask.Start(loadOperation); _loadingTasks.Add(IgnoreFailure(progressTask.Result)); } } }