Exemple #1
0
        /// <summary>
        /// Create a glTF import task, which will be incrementally advanced
        /// in each call to Update().
        ///
        /// This version of StartImport is only used by the WebGL viewer.
        /// </summary>
        public void StartImport(byte[] data, string filename)
        {
            Uri            uri        = new Uri(filename, UriKind.Relative);
            GltfImportTask importTask = RuntimeGltfImporter.GetImportTask(data, ImportOptions);

            StartImport(importTask, uri);
        }
Exemple #2
0
        /// <summary>
        /// Create a glTF import task, which will be incrementally advanced
        /// in each call to Update().
        ///
        /// Note that the URI argument must be passed in as a string
        /// rather than a `Uri` object, so that this method
        /// can be invoked from javascript.
        /// </summary>
        /// <param name="uriStr">The URI of the input glTF file.</param>
        public void StartImport(string uriStr)
        {
            Uri            uri        = new Uri(uriStr);
            GltfImportTask importTask = RuntimeGltfImporter.GetImportTask(uri, ImportOptions);

            StartImport(importTask, uri);
        }
        /// <summary>
        /// Abort any running/queued glTF imports and start importing
        /// the given glTF file.
        ///
        /// This version of StartImport is only called by the
        /// WebGL version of the viewer.
        /// </summary>
        /// <param name="data">
        /// A byte[] containing the raw byte content of a .glb/.zip file.
        /// </param>
        /// <param name="filename">
        /// The name of the .glb/.zip file that `data` was read from.
        /// The purpose of this argument is just to provide a filename
        /// to show in the progress log. Note that parameter only
        /// provides the basename for the file, not the complete file path.
        /// (For security reasons, the WebGL build is not allowed to know
        /// the complete path of a user-selected input file.)
        /// </param>
        public void StartImport(byte[] data, string filename)
        {
            AbortImports();
            var importTask = RuntimeGltfImporter.GetImportTask(data, GetGltfImportOptions());

            QueueImport(importTask, filename);
        }
        /// <summary>
        /// Queue the given glTF file to be imported after any other
        /// running/queued glTF imports have completed.
        /// </summary>
        /// <param name="uriStr">
        /// The URI for the input glTF file, which may be either an
        /// absolute file path or HTTP URL.
        /// </param>
        public void QueueImport(string uriStr)
        {
            var uri        = UriUtil.GetAbsoluteUri(uriStr);
            var basename   = Path.GetFileName(uri.ToString());
            var importTask = RuntimeGltfImporter.GetImportTask(uri, GetGltfImportOptions());

            QueueImport(importTask, basename);
        }
Exemple #5
0
 /// <summary>
 /// Unity callback that is invoked before the first frame.
 /// Create the glTF import task and set up callbacks for
 /// progress messages and successful completion.
 /// </summary>
 public void Import(string path)
 {
     /*_task = RuntimeGltfImporter.GetImportTask(
      *  "https://awesomesaucelabs.github.io/piglet-webgl-demo/StreamingAssets/piggleston.glb");*/
     _task             = RuntimeGltfImporter.GetImportTask(path);
     _task.OnProgress  = OnProgress;
     _task.OnCompleted = OnComplete;
     importFlag        = true;
 }
 /// <summary>
 /// Unity callback that is invoked before the first frame.
 /// Create the glTF import task and set up callbacks for
 /// progress messages and successful completion.
 /// </summary>
 void Start()
 {
     // Note: To import a local .gltf/.glb/.zip file, you may
     // instead pass an absolute file path to GetImportTask
     // (e.g. "C:/Users/Joe/Desktop/piggleston.glb"), or a byte[]
     // array containing the raw byte content of the file.
     _task = RuntimeGltfImporter.GetImportTask(
         "https://awesomesaucelabs.github.io/piglet-webgl-demo/StreamingAssets/piggleston.glb");
     _task.OnProgress  = OnProgress;
     _task.OnCompleted = OnComplete;
 }
Exemple #7
0
    /// <summary>
    /// Unity callback that is invoked before the first frame.
    /// Create the glTF import task and set up callbacks for
    /// progress messages and successful completion.
    /// </summary>
    void Start()
    {
        // Uniformly scale the model such that the longest
        // dimension of its world-space axis-aligned bounding
        // box becomes 4.0 units.
        var importOptions = new GltfImportOptions();

        importOptions.AutoScale     = true;
        importOptions.AutoScaleSize = 4.0f;

        // Note: To import a local .gltf/.glb/.zip file, you may
        // instead pass an absolute file path to GetImportTask
        // (e.g. "C:/Users/Joe/Desktop/piggleston.glb"), or a byte[]
        // array containing the raw byte content of the file.
        _task = RuntimeGltfImporter.GetImportTask(
            "https://awesomesaucelabs.github.io/piglet-webgl-demo/StreamingAssets/cartoon_hartman.zip",
            importOptions);

        _task.OnCompleted = OnComplete;
    }
        /// <summary>
        /// Parse command line arguments and start initial model
        /// import (if any).
        /// </summary>
        private void ParseCommandLineArgs()
        {
            string[] args = Environment.GetCommandLineArgs();

            bool profile               = false;
            bool quitAfterLoad         = false;
            long delayLoadMilliseconds = 0;

            // default model to load at startup, unless
            // --load or --no-load is used

            var uri           = new Uri(Path.Combine(Application.streamingAssetsPath, "piggleston.glb"));
            var importOptions = GameManager.Instance.ImportOptions;
            var importTask    = RuntimeGltfImporter.GetImportTask(uri, importOptions);

            for (int i = 0; i < args.Length; ++i)
            {
                if (args[i] == "--delay-load")
                {
                    // Delay initial model import at startup.
                    // I added this option so that I could prevent
                    // Unity player loading/initialization from affecting
                    // my profiling results.
                    delayLoadMilliseconds = Int64.Parse(args[i + 1]);
                }
                else if (args[i] == "--load")
                {
                    // Specify a model to load at startup,
                    // in place of the default Piglet model.
                    uri        = new Uri(args[i + 1]);
                    importTask = RuntimeGltfImporter.GetImportTask(uri, importOptions);
                }
                else if (args[i] == "--no-load")
                {
                    // Don't load a model at startup.
                    importTask = null;
                }
                else if (args[i] == "--profile")
                {
                    // Record and log profiling results while
                    // importing the initial model. This option times
                    // IEnumerator.MoveNext() calls and identifies
                    // which import subtasks cause the longest
                    // interruptions the main Unity thread.
                    profile = true;
                }
                else if (args[i] == "--quit-after-load")
                {
                    // Exit the viewer immediately after loading
                    // the initial model. This option is usually
                    // used in conjunction with --profile to
                    // perform automated profiling from the command
                    // line.
                    quitAfterLoad = true;
                }
            }

            if (importTask == null)
            {
                return;
            }

            if (delayLoadMilliseconds > 0)
            {
                importTask.PushTask(SleepUtil.SleepEnum(
                                        delayLoadMilliseconds));
            }

            if (profile)
            {
                importTask.OnCompleted += _ => importTask.LogProfilingData();
            }

            if (quitAfterLoad)
            {
                importTask.OnCompleted += _ => Application.Quit(0);
            }

            GameManager.Instance.StartImport(importTask, uri);
        }