Ejemplo n.º 1
0
        protected virtual async Task LoadGeometryAsync(IAwaitCaller awaitCaller, Func <string, IDisposable> MeasureTime)
        {
            var inverter = InvertAxis.Create();

            var meshImporter = new MeshImporter();

            for (int i = 0; i < GLTF.meshes.Count; ++i)
            {
                var index = i;
                using (MeasureTime("ReadMesh"))
                {
                    var x = meshImporter.ReadMesh(GLTF, index, inverter);
                    var y = await BuildMeshAsync(awaitCaller, MeasureTime, x, index);

                    Meshes.Add(y);
                }
            }

            using (MeasureTime("LoadNodes"))
            {
                for (int i = 0; i < GLTF.nodes.Count; i++)
                {
                    Nodes.Add(NodeImporter.ImportNode(GLTF.nodes[i], i).transform);
                }
            }
            await awaitCaller.NextFrame();

            using (MeasureTime("BuildHierarchy"))
            {
                var nodes = new List <NodeImporter.TransformWithSkin>();
                for (int i = 0; i < Nodes.Count; ++i)
                {
                    nodes.Add(NodeImporter.BuildHierarchy(GLTF, i, Nodes, Meshes));
                }

                NodeImporter.FixCoordinate(GLTF, nodes, inverter);

                // skinning
                for (int i = 0; i < nodes.Count; ++i)
                {
                    NodeImporter.SetupSkinning(GLTF, nodes, i, inverter);
                }

                if (Root == null)
                {
                    Root = new GameObject("GLTF");
                }
                if (GLTF.rootnodes != null)
                {
                    // connect root
                    foreach (var x in GLTF.rootnodes)
                    {
                        var t = nodes[x].Transform;
                        t.SetParent(Root.transform, false);
                    }
                }
            }
            await awaitCaller.NextFrame();
        }
Ejemplo n.º 2
0
        IEnumerator LoadNodes()
        {
            foreach (var x in GLTF.nodes)
            {
                Nodes.Add(NodeImporter.ImportNode(x).transform);
            }

            yield return(null);
        }
        IEnumerator LoadNodes()
        {
            using (MeasureTime("LoadNodes"))
            {
                foreach (var x in GLTF.nodes)
                {
                    Nodes.Add(NodeImporter.ImportNode(x).transform);
                }
            }

            yield return(null);
        }
Ejemplo n.º 4
0
        IEnumerator LoadNodes()
        {
            using (MeasureTime("LoadNodes"))
            {
                for (int i = 0; i < GLTF.nodes.Count; i++)
                {
                    Nodes.Add(NodeImporter.ImportNode(GLTF.nodes[i], i).transform);
                }
            }

            yield return(null);
        }
Ejemplo n.º 5
0
        protected virtual async Task LoadGeometryAsync(IAwaitCaller awaitCaller, Func <string, IDisposable> MeasureTime)
        {
            var inverter = InvertAxis.Create();

            if (GLTF.meshes.Count > 0)
            {
                var maxVertexCapacity = 0;
                var maxIndexCapacity  = 0;
                foreach (var gltfMesh in GLTF.meshes)
                {
                    var(vertexCapacity, indexCapacity) = MeshData.GetCapacity(Data, gltfMesh);
                    maxVertexCapacity = Math.Max(maxVertexCapacity, vertexCapacity);
                    maxIndexCapacity  = Math.Max(maxIndexCapacity, indexCapacity);
                }

                // 一番長い VertexBuffer, IndexBuffer の長さでNativeArray を確保し、
                // 最後に Dispose する
                using (var meshData = new MeshData(maxVertexCapacity, maxIndexCapacity))
                {
                    for (var i = 0; i < GLTF.meshes.Count; ++i)
                    {
                        var index    = i;
                        var gltfMesh = Data.GLTF.meshes[index];

                        using (MeasureTime("ReadMesh"))
                            await awaitCaller.Run(() => meshData.LoadFromGltf(Data, index, inverter));
                        var meshWithMaterials = await BuildMeshAsync(awaitCaller, MeasureTime, meshData, index);

                        Meshes.Add(meshWithMaterials);
                    }
                }
                await awaitCaller.NextFrame();
            }

            if (GLTF.nodes.Count > 0)
            {
                using (MeasureTime("LoadNodes"))
                {
                    Profiler.BeginSample("ImporterContext.LoadNodes");
                    for (var i = 0; i < GLTF.nodes.Count; i++)
                    {
                        Nodes.Add(NodeImporter.ImportNode(GLTF.nodes[i], i).transform);
                    }
                    Profiler.EndSample();
                }

                await awaitCaller.NextFrame();
            }

            using (MeasureTime("BuildHierarchy"))
            {
                var nodes = new List <NodeImporter.TransformWithSkin>();
                if (Nodes.Count > 0)
                {
                    Profiler.BeginSample("NodeImporter.BuildHierarchy");
                    for (var i = 0; i < Nodes.Count; ++i)
                    {
                        nodes.Add(NodeImporter.BuildHierarchy(GLTF, i, Nodes, Meshes));
                    }
                    Profiler.EndSample();

                    await awaitCaller.NextFrame();
                }

                NodeImporter.FixCoordinate(GLTF, nodes, inverter);

                // skinning
                if (nodes.Count > 0)
                {
                    Profiler.BeginSample("NodeImporter.SetupSkinning");
                    for (var i = 0; i < nodes.Count; ++i)
                    {
                        NodeImporter.SetupSkinning(Data, nodes, i, inverter);
                    }
                    Profiler.EndSample();

                    await awaitCaller.NextFrame();
                }

                if (Root == null)
                {
                    Root = new GameObject("GLTF");
                }
                if (GLTF.rootnodes != null)
                {
                    // connect root
                    foreach (var x in GLTF.rootnodes)
                    {
                        var t = nodes[x].Transform;
                        t.SetParent(Root.transform, false);
                    }
                }
            }
            await awaitCaller.NextFrame();
        }
Ejemplo n.º 6
0
        protected virtual async Task LoadGeometryAsync(IAwaitCaller awaitCaller, Func <string, IDisposable> MeasureTime)
        {
            var inverter = InvertAxis.Create();

            var meshImporter = new MeshImporter();

            if (GLTF.meshes.Count > 0)
            {
                for (var i = 0; i < GLTF.meshes.Count; ++i)
                {
                    var index = i;
                    using (MeasureTime("ReadMesh"))
                    {
                        var meshContext = await awaitCaller.Run(() => meshImporter.ReadMesh(Data, index, inverter));

                        var meshWithMaterials = await BuildMeshAsync(awaitCaller, MeasureTime, meshContext, index);

                        Meshes.Add(meshWithMaterials);
                    }
                }

                await awaitCaller.NextFrame();
            }

            if (GLTF.nodes.Count > 0)
            {
                using (MeasureTime("LoadNodes"))
                {
                    Profiler.BeginSample("ImporterContext.LoadNodes");
                    for (var i = 0; i < GLTF.nodes.Count; i++)
                    {
                        Nodes.Add(NodeImporter.ImportNode(GLTF.nodes[i], i).transform);
                    }
                    Profiler.EndSample();
                }

                await awaitCaller.NextFrame();
            }

            using (MeasureTime("BuildHierarchy"))
            {
                var nodes = new List <NodeImporter.TransformWithSkin>();
                if (Nodes.Count > 0)
                {
                    Profiler.BeginSample("NodeImporter.BuildHierarchy");
                    for (var i = 0; i < Nodes.Count; ++i)
                    {
                        nodes.Add(NodeImporter.BuildHierarchy(GLTF, i, Nodes, Meshes));
                    }
                    Profiler.EndSample();

                    await awaitCaller.NextFrame();
                }

                NodeImporter.FixCoordinate(GLTF, nodes, inverter);

                // skinning
                if (nodes.Count > 0)
                {
                    Profiler.BeginSample("NodeImporter.SetupSkinning");
                    for (var i = 0; i < nodes.Count; ++i)
                    {
                        NodeImporter.SetupSkinning(Data, nodes, i, inverter);
                    }
                    Profiler.EndSample();

                    await awaitCaller.NextFrame();
                }

                if (Root == null)
                {
                    Root = new GameObject("GLTF");
                }
                if (GLTF.rootnodes != null)
                {
                    // connect root
                    foreach (var x in GLTF.rootnodes)
                    {
                        var t = nodes[x].Transform;
                        t.SetParent(Root.transform, false);
                    }
                }
            }
            await awaitCaller.NextFrame();
        }