Esempio n. 1
0
        private static GameObject LoadInternal(this GLTFObject gltfObject, string filepath, ImportSettings importSettings, out GLTFAnimation.ImportResult[] animations)
        {
            // directory root is sometimes used for loading buffers from containing file, or local images
            string directoryRoot = Directory.GetParent(filepath).ToString() + "/";

            // Import tasks synchronously
            GLTFBuffer.ImportTask bufferTask = new GLTFBuffer.ImportTask(gltfObject.buffers, filepath);
            bufferTask.RunSynchronously();
            GLTFBufferView.ImportTask bufferViewTask = new GLTFBufferView.ImportTask(gltfObject.bufferViews, bufferTask);
            bufferViewTask.RunSynchronously();
            GLTFAccessor.ImportTask accessorTask = new GLTFAccessor.ImportTask(gltfObject.accessors, bufferViewTask);
            accessorTask.RunSynchronously();
            GLTFImage.ImportTask imageTask = new GLTFImage.ImportTask(gltfObject.images, directoryRoot, bufferViewTask);
            imageTask.RunSynchronously();
            GLTFTexture.ImportTask textureTask = new GLTFTexture.ImportTask(gltfObject.textures, imageTask);
            textureTask.RunSynchronously();
            GLTFMaterial.ImportTask materialTask = new GLTFMaterial.ImportTask(gltfObject.materials, textureTask, importSettings);
            materialTask.RunSynchronously();
            GLTFMesh.ImportTask meshTask = new GLTFMesh.ImportTask(gltfObject.meshes, accessorTask, materialTask, importSettings);
            meshTask.RunSynchronously();
            GLTFSkin.ImportTask skinTask = new GLTFSkin.ImportTask(gltfObject.skins, accessorTask);
            skinTask.RunSynchronously();
            GLTFNode.ImportTask nodeTask = new GLTFNode.ImportTask(gltfObject.nodes, meshTask, skinTask);
            nodeTask.RunSynchronously();
            animations = gltfObject.animations.Import(accessorTask.Result, nodeTask.Result);

            return(nodeTask.Result.GetRoot());
        }
Esempio n. 2
0
        private static GameObject LoadInternal(this GLTFObject gltfObject, string filepath, byte[] bytefile, long binChunkStart, ImportSettings importSettings, out GLTFAnimation.ImportResult[] animations)
        {
            // directory root is sometimes used for loading buffers from containing file, or local images
            string directoryRoot = filepath != null?Directory.GetParent(filepath).ToString() + "/" : null;

            importSettings.shaderOverrides.CacheDefaultShaders();

            // Import tasks synchronously
            GLTFBuffer.ImportTask bufferTask = new GLTFBuffer.ImportTask(gltfObject.buffers, filepath, bytefile, binChunkStart);
            bufferTask.RunSynchronously();
            GLTFBufferView.ImportTask bufferViewTask = new GLTFBufferView.ImportTask(gltfObject.bufferViews, bufferTask);
            bufferViewTask.RunSynchronously();
            GLTFAccessor.ImportTask accessorTask = new GLTFAccessor.ImportTask(gltfObject.accessors, bufferViewTask);
            accessorTask.RunSynchronously();
            GLTFImage.ImportTask imageTask = new GLTFImage.ImportTask(gltfObject.images, directoryRoot, bufferViewTask);
            imageTask.RunSynchronously();
            GLTFTexture.ImportTask textureTask = new GLTFTexture.ImportTask(gltfObject.textures, imageTask);
            textureTask.RunSynchronously();
            GLTFMaterial.ImportTask materialTask = new GLTFMaterial.ImportTask(gltfObject.materials, textureTask, importSettings);
            materialTask.RunSynchronously();
            GLTFMesh.ImportTask meshTask = new GLTFMesh.ImportTask(gltfObject.meshes, accessorTask, materialTask, importSettings);
            meshTask.RunSynchronously();
            GLTFSkin.ImportTask skinTask = new GLTFSkin.ImportTask(gltfObject.skins, accessorTask);
            skinTask.RunSynchronously();
            GLTFNode.ImportTask nodeTask = new GLTFNode.ImportTask(gltfObject.nodes, meshTask, skinTask, gltfObject.cameras);
            nodeTask.RunSynchronously();
            animations = gltfObject.animations.Import(accessorTask.Result, nodeTask.Result, importSettings);

            foreach (var item in bufferTask.Result)
            {
                item.Dispose();
            }

            return(nodeTask.Result.GetRoot());
        }
Esempio n. 3
0
        private static IEnumerator LoadInternal(this GLTFObject gltfObject, string filepath, byte[] bytefile, long binChunkStart, ImportSettings importSettings, Action <GameObject, AnimationClip[]> onFinished)
        {
            CheckExtensions(gltfObject);

            // directory root is sometimes used for loading buffers from containing file, or local images
            string directoryRoot = filepath != null?Directory.GetParent(filepath).ToString() + "/" : null;

            importSettings.shaderOverrides.CacheDefaultShaders();

            // Import tasks synchronously
            GLTFBuffer.ImportTask bufferTask = new GLTFBuffer.ImportTask(gltfObject.buffers, filepath, bytefile, binChunkStart);
            yield return(StaticCoroutine.Start(bufferTask.RunSynchronously()));

            GLTFBufferView.ImportTask bufferViewTask = new GLTFBufferView.ImportTask(gltfObject.bufferViews, bufferTask);
            yield return(StaticCoroutine.Start(bufferViewTask.RunSynchronously()));

            GLTFAccessor.ImportTask accessorTask = new GLTFAccessor.ImportTask(gltfObject.accessors, bufferViewTask);
            yield return(StaticCoroutine.Start(accessorTask.RunSynchronously()));

            GLTFImage.ImportTask imageTask = new GLTFImage.ImportTask(gltfObject.images, directoryRoot, bufferViewTask);
            yield return(StaticCoroutine.Start(imageTask.RunSynchronously()));

            GLTFTexture.ImportTask textureTask = new GLTFTexture.ImportTask(gltfObject.textures, imageTask);
            yield return(StaticCoroutine.Start(textureTask.RunSynchronously()));

            GLTFMaterial.ImportTask materialTask = new GLTFMaterial.ImportTask(gltfObject.materials, textureTask, importSettings);
            yield return(StaticCoroutine.Start(materialTask.RunSynchronously()));

            GLTFMesh.ImportTask meshTask = new GLTFMesh.ImportTask(gltfObject.meshes, accessorTask, bufferViewTask, materialTask, importSettings);
            yield return(StaticCoroutine.Start(meshTask.RunSynchronously()));

            GLTFSkin.ImportTask skinTask = new GLTFSkin.ImportTask(gltfObject.skins, accessorTask);
            yield return(StaticCoroutine.Start(skinTask.RunSynchronously()));

            GLTFNode.ImportTask nodeTask = new GLTFNode.ImportTask(gltfObject.nodes, meshTask, skinTask, gltfObject.cameras);
            yield return(StaticCoroutine.Start(nodeTask.RunSynchronously()));

            GLTFAnimation.ImportResult[] animationResult = gltfObject.animations.Import(accessorTask.Result, nodeTask.Result, importSettings);
            AnimationClip[] animations = null;
            if (animationResult != null)
            {
                animations = animationResult.Select(x => x.clip).ToArray();
            }
            else
            {
                animations = new AnimationClip[0];
            }

            foreach (var item in bufferTask.Result)
            {
                item.Dispose();
            }

            onFinished?.Invoke(nodeTask.Result.GetRoot(), animations);
        }
Esempio n. 4
0
        private static GameObject LoadInternal(this GLTFObject gltfObject, string filepath, byte[] bytefile, long binChunkStart, ImportSettings importSettings, out AnimationClip[] animations)
        {
            CheckExtensions(gltfObject);

            // directory root is sometimes used for loading buffers from containing file, or local images
            string directoryRoot = filepath != null?Directory.GetParent(filepath).ToString() + "/" : null;

            importSettings.shaderOverrides.CacheDefaultShaders();

            // Import tasks synchronously
            GLTFBuffer.ImportTask bufferTask = new GLTFBuffer.ImportTask(gltfObject.buffers, filepath, bytefile, binChunkStart);
            bufferTask.RunSynchronously();
            GLTFBufferView.ImportTask bufferViewTask = new GLTFBufferView.ImportTask(gltfObject.bufferViews, bufferTask);
            bufferViewTask.RunSynchronously();
            GLTFAccessor.ImportTask accessorTask = new GLTFAccessor.ImportTask(gltfObject.accessors, bufferViewTask);
            accessorTask.RunSynchronously();
            GLTFImage.ImportTask imageTask = new GLTFImage.ImportTask(gltfObject.images, directoryRoot, bufferViewTask);
            imageTask.RunSynchronously();
            GLTFTexture.ImportTask textureTask = new GLTFTexture.ImportTask(gltfObject.textures, imageTask);
            textureTask.RunSynchronously();
            GLTFMaterial.ImportTask materialTask = new GLTFMaterial.ImportTask(gltfObject.materials, textureTask, importSettings);
            materialTask.RunSynchronously();
            GLTFMesh.ImportTask meshTask = new GLTFMesh.ImportTask(gltfObject.meshes, accessorTask, bufferViewTask, materialTask, importSettings);
            meshTask.RunSynchronously();
            GLTFSkin.ImportTask skinTask = new GLTFSkin.ImportTask(gltfObject.skins, accessorTask);
            skinTask.RunSynchronously();
            GLTFNode.ImportTask nodeTask = new GLTFNode.ImportTask(gltfObject.nodes, meshTask, skinTask, gltfObject.cameras);
            nodeTask.RunSynchronously();
            GLTFAnimation.ImportResult[] animationResult = gltfObject.animations.Import(accessorTask.Result, nodeTask.Result, importSettings);
            if (animationResult != null)
            {
                animations = animationResult.Select(x => x.clip).ToArray();
            }
            else
            {
                animations = new AnimationClip[0];
            }

            foreach (var item in bufferTask.Result)
            {
                item.Dispose();
            }

            GameObject gameObject = nodeTask.Result.GetRoot();

            if (importSettings.extrasProcessor != null)
            {
                if (gltfObject.extras == null)
                {
                    gltfObject.extras = new JObject();
                }

                if (gltfObject.materials != null)
                {
                    JArray materialExtras       = new JArray();
                    bool   hasMaterialExtraData = false;
                    foreach (GLTFMaterial material in gltfObject.materials)
                    {
                        if (material.extras != null)
                        {
                            materialExtras.Add(material.extras);
                            hasMaterialExtraData = true;
                        }
                        else
                        {
                            materialExtras.Add(new JObject());
                        }
                    }
                    if (hasMaterialExtraData)
                    {
                        gltfObject.extras.Add("material", materialExtras);
                    }
                }

                if (gltfObject.animations != null)
                {
                    JArray animationExtras       = new JArray();
                    bool   hasAnimationExtraData = false;
                    foreach (GLTFAnimation animation in gltfObject.animations)
                    {
                        if (animation.extras != null)
                        {
                            hasAnimationExtraData = true;
                            animationExtras.Add(animation.extras);
                        }
                        else
                        {
                            animationExtras.Add(new JObject());
                        }
                    }
                    if (hasAnimationExtraData)
                    {
                        gltfObject.extras.Add("animation", animationExtras);
                    }
                }

                importSettings.extrasProcessor.ProcessExtras(gameObject, animations, gltfObject.extras);
            }
            return(gameObject);
        }
Esempio n. 5
0
        // hkyoo
        public static GameObject LoadInternal(this GLTFObject gltfObject, string filepath, int index, byte[] bytefile, long binChunkStart, ImportSettings importSettings, out AnimationClip[] animations)
        {
            // directory root is sometimes used for loading buffers from containing file, or local images
            string directoryRoot = filepath != null?Directory.GetParent(filepath).ToString() + "/" : null;

            importSettings.shaderOverrides.CacheDefaultShaders();

            //// for debug
            //Debug.Log(gltfObject.nodes.ToString() + " " + gltfObject.nodes.Count); // 151
            //Debug.Log(gltfObject.meshes.ToString() + " " + gltfObject.meshes.Count); // 151
            ////Debug.Log(gltfObject.animations.ToString() + " " + gltfObject.animations.Count); // null
            //Debug.Log(gltfObject.buffers.ToString() + " " + gltfObject.buffers.Count); // 1
            //Debug.Log(gltfObject.bufferViews.ToString() + " " + gltfObject.bufferViews.Count); // 755
            //Debug.Log(gltfObject.accessors.ToString() + " " + gltfObject.accessors.Count); // 604
            ////Debug.Log(gltfObject.skins.ToString() + " " + gltfObject.skins.Count); // null
            //Debug.Log(gltfObject.textures.ToString() + " " + gltfObject.textures.Count); // 151
            //Debug.Log(gltfObject.images.ToString() + " " + gltfObject.images.Count); // 151
            //Debug.Log(gltfObject.materials.ToString() + " " + gltfObject.materials.Count); // 151
            ////Debug.Log(gltfObject.cameras.ToString() + " " + gltfObject.cameras.Count); // null
            ///

            Stopwatch sw = new Stopwatch();


            // image/material/mesh

            sw.Start();
            // Import tasks synchronously
            GLTFBuffer.ImportTask bufferTask = new GLTFBuffer.ImportTask(gltfObject.buffers, filepath, bytefile, binChunkStart);
            bufferTask.RunSynchronously();
            sw.Stop();
            UnityEngine.Debug.Log("bufferTask : " + sw.ElapsedMilliseconds.ToString() + "ms");
            sw.Reset();

            sw.Start();

            // TODO?
            GLTFBufferView.ImportTask bufferViewTask = new GLTFBufferView.ImportTask(gltfObject.bufferViews, bufferTask);
            bufferViewTask.RunSynchronously();

            sw.Stop();
            UnityEngine.Debug.Log("bufferViewTask : " + sw.ElapsedMilliseconds.ToString() + "ms");
            sw.Reset();

            sw.Start();


            GLTFAccessor.ImportTask accessorTask = new GLTFAccessor.ImportTask(gltfObject.accessors, bufferViewTask);
            accessorTask.RunSynchronously();

            sw.Stop();
            UnityEngine.Debug.Log("accessorTask : " + sw.ElapsedMilliseconds.ToString() + "ms");
            sw.Reset();

            sw.Start();

            GLTFImage.ImportTask imageTask = new GLTFImage.ImportTask(gltfObject.images[index], directoryRoot, bufferViewTask);
            //GLTFImage.ImportTask imageTask = new GLTFImage.ImportTask(gltfObject.images, directoryRoot, bufferViewTask);
            imageTask.RunSynchronously();

            sw.Stop();
            UnityEngine.Debug.Log("imageTask : " + sw.ElapsedMilliseconds.ToString() + "ms");
            sw.Reset();

            sw.Start();

            GLTFTexture.ImportTask textureTask = new GLTFTexture.ImportTask(gltfObject.textures[index], imageTask);
            //GLTFTexture.ImportTask textureTask = new GLTFTexture.ImportTask(gltfObject.textures, imageTask);
            textureTask.RunSynchronously();

            UnityEngine.Debug.Log("textureTask.Result[0] " + textureTask.Result.Length + " " + textureTask.Result[0]);

            sw.Stop();
            UnityEngine.Debug.Log("textureTask : " + sw.ElapsedMilliseconds.ToString() + "ms");
            sw.Reset();

            sw.Start();

            // TODO : shader setting
            GLTFMaterial.ImportTask materialTask = new GLTFMaterial.ImportTask(gltfObject.materials[index], textureTask, importSettings);
            //GLTFMaterial.ImportTask materialTask = new GLTFMaterial.ImportTask(gltfObject.materials, textureTask, importSettings);

            materialTask.RunSynchronously();

            sw.Stop();
            UnityEngine.Debug.Log("materialTask : " + sw.ElapsedMilliseconds.ToString() + "ms");
            sw.Reset();

            sw.Start();

            // TODO :
            GLTFMesh.ImportTask meshTask = new GLTFMesh.ImportTask(gltfObject.meshes[index], accessorTask, bufferViewTask, materialTask, importSettings);
            //GLTFMesh.ImportTask meshTask = new GLTFMesh.ImportTask(gltfObject.meshes, accessorTask, bufferViewTask, materialTask, importSettings);

            meshTask.RunSynchronously();

            sw.Stop();
            UnityEngine.Debug.Log("meshTask : " + sw.ElapsedMilliseconds.ToString() + "ms");
            sw.Reset();

            sw.Start();

            GLTFSkin.ImportTask skinTask = new GLTFSkin.ImportTask(gltfObject.skins, accessorTask);
            skinTask.RunSynchronously();

            sw.Stop();
            UnityEngine.Debug.Log("skinTask : " + sw.ElapsedMilliseconds.ToString() + "ms");
            sw.Reset();

            sw.Start();


            GLTFNode.ImportTask nodeTask = new GLTFNode.ImportTask(gltfObject.nodes[index], meshTask, skinTask, gltfObject.cameras);
            //GLTFNode.ImportTask nodeTask = new GLTFNode.ImportTask(gltfObject.nodes, meshTask, skinTask, gltfObject.cameras);
            nodeTask.RunSynchronously();

            sw.Stop();
            UnityEngine.Debug.Log("nodeTask : " + sw.ElapsedMilliseconds.ToString() + "ms");
            sw.Reset();



            GLTFAnimation.ImportResult[] animationResult = gltfObject.animations.Import(accessorTask.Result, nodeTask.Result, importSettings);
            if (animationResult != null)
            {
                animations = animationResult.Select(x => x.clip).ToArray();
            }
            else
            {
                animations = new AnimationClip[0];
            }

            foreach (var item in bufferTask.Result)
            {
                item.Dispose();
            }

            return(nodeTask.Result.GetRoot());
        }