Exemplo n.º 1
0
 internal AssetLoader(MonoBehaviour owner, MixedRealityExtensionApp app)
 {
     _owner       = owner ?? throw new ArgumentException("Asset loader requires an owner MonoBehaviour script to be assigned to it.");
     _app         = app ?? throw new ArgumentException("Asset loader requires a MixedRealityExtensionApp to be associated with.");
     _asyncHelper = _owner.gameObject.GetComponent <AsyncCoroutineHelper>() ??
                    _owner.gameObject.AddComponent <AsyncCoroutineHelper>();
 }
Exemplo n.º 2
0
 /// <inheritdoc cref="CreateImporter(string, ILoader, AsyncCoroutineHelper)"/>
 public GLTFSceneImporter CreateImporter(
     string gltfFileName,
     ILoader externalDataLoader,
     AsyncCoroutineHelper asyncCoroutineHelper)
 {
     return(new GLTFSceneImporter(gltfFileName, externalDataLoader, asyncCoroutineHelper));
 }
Exemplo n.º 3
0
 public GLTFSceneImporter CreateImporter(GLTFRoot gltfRoot, ILoader loader, AsyncCoroutineHelper helper, Stream stream = null)
 {
     return(new VertexShadedGltfImporter(MixedRealityExtension.API.MREAPI.AppsAPI.DefaultMaterial, gltfRoot, stream, new ImportOptions()
     {
         ExternalDataLoader = loader,
         AsyncCoroutineHelper = helper
     }));
 }
Exemplo n.º 4
0
 public GLTFSceneImporter CreateImporter(string filename, ILoader loader, AsyncCoroutineHelper asyncCoroutineHelper)
 {
     return(new VertexShadedGltfImporter(MixedRealityExtension.API.MREAPI.AppsAPI.DefaultMaterial, filename, new ImportOptions()
     {
         ExternalDataLoader = loader,
         AsyncCoroutineHelper = asyncCoroutineHelper
     }));
 }
Exemplo n.º 5
0
 public GLTFSceneImporter CreateImporter(
     GLTFRoot rootNode,
     ILoader externalDataLoader,
     AsyncCoroutineHelper asyncCoroutineHelper,
     Stream gltfStream = null)
 {
     return(new GLTFSceneImporter(rootNode, externalDataLoader, asyncCoroutineHelper, gltfStream));
 }
Exemplo n.º 6
0
 /// <inheritdoc cref="CreateImporter(string, IDataLoader, AsyncCoroutineHelper)"/>
 public GLTFSceneImporter CreateImporter(
     string gltfFileName,
     IDataLoader dataLoader,
     AsyncCoroutineHelper asyncCoroutineHelper)
 {
     return(new GLTFSceneImporter(gltfFileName, new ImportOptions()
     {
         DataLoader = dataLoader,
         AsyncCoroutineHelper = asyncCoroutineHelper
     }));
 }
        void Start()
        {
            Debug.Log("Hit spacebar to change the scene.");
            _asyncCoroutineHelper = gameObject.AddComponent <AsyncCoroutineHelper>();
            Uri uri           = new Uri(Url);
            var directoryPath = URIHelper.AbsoluteUriPath(uri);

            _loader   = new WebRequestLoader(directoryPath);
            _fileName = URIHelper.GetFileFromUri(uri);

            LoadScene(SceneIndex);
        }
Exemplo n.º 8
0
 /// <inheritdoc cref="CreateImporter(GLTFRoot, IDataLoader, AsyncCoroutineHelper, Stream)"/>
 public GLTFSceneImporter CreateImporter(
     GLTFRoot rootNode,
     IDataLoader dataLoader,
     AsyncCoroutineHelper asyncCoroutineHelper,
     Stream gltfStream = null)
 {
     return(new GLTFSceneImporter(rootNode, gltfStream, new ImportOptions()
     {
         DataLoader = dataLoader,
         AsyncCoroutineHelper = asyncCoroutineHelper
     }));
 }
Exemplo n.º 9
0
        public async Task LoadGltfAsync(GameObject newObject, string fullPath, ModelImportOptions importOptions)
        {
            asyncCoroutineHelper = newObject.GetComponent <AsyncCoroutineHelper>() ?? gameObject.AddComponent <AsyncCoroutineHelper>();
            //GLTFSceneImporter sceneImporter = null;
            ILoader loader = null;

            try
            {
                // Path.Combine treats paths that start with the separator character
                // as absolute paths, ignoring the first path passed in. This removes
                // that character to properly handle a filename written with it.
                fullPath = fullPath.TrimStart(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
                string directoryPath = URIHelper.GetDirectoryName(fullPath);
                loader        = new FileLoader(directoryPath);
                sceneImporter = new GLTFSceneImporter(
                    Path.GetFileName(fullPath),
                    loader,
                    asyncCoroutineHelper
                    );
                sceneImporter.SceneParent = newObject.transform;
                sceneImporter.Collider    = Collider;
                if (importOptions != null)
                {
                    if (importOptions.buildColliders)
                    {
                        sceneImporter.Collider = GLTFSceneImporter.ColliderType.MeshConvex;
                        //if (importOptions.colliderConvex)
                        //{
                        //    sceneImporter.Collider = GLTFSceneImporter.ColliderType.MeshConvex;
                        //}
                        //else
                        //{
                        //    sceneImporter.Collider = GLTFSceneImporter.ColliderType.Mesh;
                        //}
                    }
                    else
                    {
                        sceneImporter.Collider = GLTFSceneImporter.ColliderType.None;
                    }
                }
                sceneImporter.MaximumLod       = MaximumLod;
                sceneImporter.Timeout          = Timeout;
                sceneImporter.isMultithreaded  = Multithreaded;
                sceneImporter.CustomShaderName = shaderOverride ? shaderOverride.name : null;
                await sceneImporter.LoadSceneAsync();

                // 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;
                    }
                }

                if (PlayAnimationOnLoad)
                {
                    Animation[] animations = sceneImporter.LastLoadedScene.GetComponents <Animation>();
                    foreach (Animation anim in animations)
                    {
                        anim.Play();
                    }
                }
            }
            finally
            {
                if (loader != null)
                {
                    sceneImporter?.Dispose();
                    sceneImporter = null;
                    loader        = null;
                }
            }
        }
Exemplo n.º 10
0
 public WebRequestLoader(string rootURI, AsyncCoroutineHelper asyncCoroutineHelper)
 {
     _rootURI = rootURI;
     _asyncCoroutineHelper = asyncCoroutineHelper;
     HasSyncLoadMethod     = false;
 }