public static IEnumerator LoadScene(GLTFSceneImporter sceneImporter, bool Multithreaded, Action <GameObject> onLoad) { yield return(sceneImporter.LoadScene(-1, Multithreaded)); if (onLoad != null) { onLoad(sceneImporter.CreatedObject); } }
IEnumerator Start() { ILoader loader = new WebRequestLoader(URIHelper.GetDirectoryName(Url)); var sceneImporter = new GLTFSceneImporter( URIHelper.GetFileFromUri(new Uri(Url)), loader ); sceneImporter.SceneParent = gameObject.transform; yield return(sceneImporter.LoadScene(-1, Multithreaded)); IntegrationTest.Pass(); }
IEnumerator LoadScene(int SceneIndex) { foreach (Transform child in transform) { GameObject.Destroy(child.gameObject); } _importer = new GLTFSceneImporter( _fileName, _loader ); _importer.SceneParent = gameObject.transform; yield return(_importer.LoadScene(SceneIndex)); }
public async void OpenNewModelAsync(Action <GameObject> completionCallback) { // Get rid of the previous model regardless of whether the user chooses // a new one or not with a review to avoiding cluttering the screen. this.DisposeExistingGLTFModel(); // Note - this method will throw inside of the editor, only does something // on the UWP platform. var filePath = await FileDialogHelper.PickGLTFFileAsync(); if (!string.IsNullOrEmpty(filePath)) { this.ShowCursor(false); ProgressIndicator.Instance.Open( IndicatorStyleEnum.AnimatedOrbs, ProgressStyleEnum.None, ProgressMessageStyleEnum.Visible, "Loading..."); var loader = new FileLoader(Path.GetDirectoryName(filePath)); GLTFSceneImporter importer = new GLTFSceneImporter(Path.GetFileName(filePath), loader); importer.Collider = GLTFSceneImporter.ColliderType.Box; try { await base.RunCoroutineAsync( importer.LoadScene( -1, gameObject => this.LoadedCompletionHandler(gameObject, completionCallback) ) ); } catch (Exception ex) { this.LoadedCompletionHandler(null, completionCallback); } } else { completionCallback?.Invoke(null); } }
public IEnumerator Download(Promise <bool> loadComplete) { string directoryPath = URIHelper.GetDirectoryName(Url); string relativePath = Url.Replace(directoryPath, ""); var wrl = new B3DMLoader(new WebRequestLoader(directoryPath)); GLTFSceneImporter sceneImporter = new GLTFSceneImporter( relativePath, wrl ); sceneImporter.SceneParent = gameObject.transform; sceneImporter.CustomShaderName = ShaderOverride ? ShaderOverride.name : null; sceneImporter.MaximumLod = MaximumLod; if (addColliders) { sceneImporter.Collider = GLTFSceneImporter.ColliderType.Mesh; } yield return(sceneImporter.LoadScene(-1, Multithreaded, sceneObject => { if (sceneObject != null) { loadComplete.Resolve(true); } else { loadComplete.Resolve(false); } Destroy(this); })); // Override the shaders on all materials if a shader is provided if (ShaderOverride != null) { Renderer[] renderers = gameObject.GetComponentsInChildren <Renderer>(); foreach (Renderer renderer in renderers) { renderer.sharedMaterial.shader = ShaderOverride; } } }
async Task <ImportedModelInfo> ImportGLTFModelFromFileAsync(string filePath) { this.ShowBusy("Loading model..."); ImportedModelInfo modelDetails = null; try { modelDetails = new ImportedModelInfo( new RecordingFileLoader(Path.GetDirectoryName(filePath))); GLTFSceneImporter importer = new GLTFSceneImporter( Path.GetFileName(filePath), modelDetails.FileLoader); importer.Collider = GLTFSceneImporter.ColliderType.Box; await base.RunCoroutineAsync( importer.LoadScene( -1, gameObject => modelDetails.GameObject = gameObject) ); } catch { // TODO: figure out sensible exceptions here. } this.HideBusy(); if (modelDetails?.GameObject != null) { this.AudioManager?.PlayClipOnceOnly(AudioClipType.FirstModelOpened); } else { this.AudioManager?.PlayClip(AudioClipType.LoadError); } return(modelDetails); }
public IEnumerator Load() { GLTFSceneImporter sceneImporter = null; ILoader loader = new loadFromXML(preLoadScene.blobName, MeshNum); sceneImporter = new GLTFSceneImporter(preLoadScene.blobName, loader); sceneImporter.SceneParent = gameObject.transform; sceneImporter.Collider = Collider; sceneImporter.MaximumLod = MaximumLod; sceneImporter.CustomShaderName = shaderOverride ? shaderOverride.name : null; yield return(sceneImporter.LoadScene(-1, Multithreaded)); // Override the shaders on all materials if a shader is provided if (shaderOverride != null) { Renderer[] renderers = gameObject.GetComponentsInChildren <Renderer>(); foreach (Renderer renderer in renderers) { renderer.sharedMaterial.shader = shaderOverride; } } }
public IEnumerator Download(Promise <bool> loadComplete) { string url = UrlUtils.ReplaceDataProtocol(Url); string dir = UrlUtils.GetBaseUri(url); string file = UrlUtils.GetLastPathSegment(url); ILoader loader = AbstractWebRequestLoader.CreateDefaultRequestLoader(dir); //.glb, .gltf if (file.EndsWith(".b3dm", StringComparison.OrdinalIgnoreCase)) { loader = new B3DMLoader(loader); } var sceneImporter = new GLTFSceneImporter(file, loader); sceneImporter.SceneParent = gameObject.transform; sceneImporter.CustomShaderName = ShaderOverride ? ShaderOverride.name : null; sceneImporter.MaximumLod = MaximumLod; sceneImporter.Collider = AddColliders ? GLTFSceneImporter.ColliderType.Mesh : GLTFSceneImporter.ColliderType.None; loadComplete = loadComplete ?? new Promise <bool>(); yield return(sceneImporter.LoadScene(-1, Multithreaded, sceneObject => loadComplete.Resolve(sceneObject != null))); }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { _UpdateApplicationLifecycle(); if (startedDownloading && this.ARCaptLoader.WWWLoader != null && this.ARCaptLoader.WWWLoader.isDone) { startedDownloading = !this.ARCaptLoader.WWWLoader.isDone; if (this.ARCaptLoader.WWWLoader.progress < 1) { this.ARCaptLoader.StatusMsg = "Downloading 3D model.. " + (int)(this.ARCaptLoader.WWWLoader.progress * 100) + "%"; } } if (this.TextMessages.text != this.ARCaptLoader.StatusMsg) { this.TextMessages.text = this.ARCaptLoader.StatusMsg; } // Hide snackbar when currently tracking at least one plane. Session.GetTrackables <DetectedPlane>(m_AllPlanes); bool showSearchingUI = true; for (int i = 0; i < m_AllPlanes.Count; i++) { if (m_AllPlanes[i].TrackingState == TrackingState.Tracking) { showSearchingUI = false; break; } } SearchingForPlaneUI.SetActive(showSearchingUI); if (GroupModel3D != null) { if (Input.touchCount == 1) { if (Input.GetTouch(0).phase == TouchPhase.Began) { oldTouchPosition = Input.GetTouch(0).position.x; } else if (Input.GetTouch(0).phase == TouchPhase.Moved) { if (Math.Abs(oldTouchPosition - Input.GetTouch(0).position.x) < 50) { return; } if (oldTouchPosition > Input.GetTouch(0).position.x) { GroupModel3D.transform.Rotate(0, 5f, 0, Space.Self); } else { GroupModel3D.transform.Rotate(0, -5f, 0, Space.Self); } oldTouchPosition = Input.GetTouch(0).position.x; } } if (Input.touchCount == 2) { this.RotateModel(); } } else { // If the player has not touched the screen, we are done with this update. Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } // If the mode is still loading, we are done with this update again. if (this.isModelLoading) { return; } // Raycast against the location the player touched to search for planes. TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) { // Use hit pose and camera pose to check if hittest is from the // back of the plane, if it is, no need to create the anchor. if ((hit.Trackable is DetectedPlane) && Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position, hit.Pose.rotation * Vector3.up) < 0) { Debug.Log("Hit at back of the current DetectedPlane"); } else { this.Hit = hit; if (string.IsNullOrEmpty(this.ARCaptLoader.ModelPath)) { return; } this.isModelLoading = true; this.ARCaptLoader.StatusMsg = "Loading 3D model. Please wait..."; var loader = new FileLoader(Path.GetDirectoryName(this.ARCaptLoader.ModelPath)); var sceneImporter = new GLTFSceneImporter(this.ARCaptLoader.ModelPath, loader); StartCoroutine(sceneImporter.LoadScene(0, true, OnImportedModel)); } } } }