Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImporterContextのうち、BuildHierarchyまわりのフレームを分散 #1220

Merged
merged 2 commits into from
Sep 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using UnityEngine.Profiling;
using VRMShaders;

namespace UniGLTF
Expand Down Expand Up @@ -169,40 +170,65 @@ protected virtual async Task LoadGeometryAsync(IAwaitCaller awaitCaller, Func<st
var inverter = InvertAxis.Create();

var meshImporter = new MeshImporter();
for (int i = 0; i < GLTF.meshes.Count; ++i)
if (GLTF.meshes.Count > 0)
{
var index = i;
using (MeasureTime("ReadMesh"))
for (var i = 0; i < GLTF.meshes.Count; ++i)
{
var x = await awaitCaller.Run(() => meshImporter.ReadMesh(GLTF, index, inverter));
var y = await BuildMeshAsync(awaitCaller, MeasureTime, x, index);
Meshes.Add(y);
var index = i;
using (MeasureTime("ReadMesh"))
{
var x = await awaitCaller.Run(() => meshImporter.ReadMesh(GLTF, index, inverter));
var y = await BuildMeshAsync(awaitCaller, MeasureTime, x, index);
Meshes.Add(y);
}
}

await awaitCaller.NextFrame();
}

using (MeasureTime("LoadNodes"))
if (GLTF.nodes.Count > 0)
{
for (int i = 0; i < GLTF.nodes.Count; i++)
using (MeasureTime("LoadNodes"))
{
Nodes.Add(NodeImporter.ImportNode(GLTF.nodes[i], i).transform);
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();
}
await awaitCaller.NextFrame();

using (MeasureTime("BuildHierarchy"))
{
var nodes = new List<NodeImporter.TransformWithSkin>();
for (int i = 0; i < Nodes.Count; ++i)
if (Nodes.Count > 0)
{
nodes.Add(NodeImporter.BuildHierarchy(GLTF, i, Nodes, Meshes));
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
for (int i = 0; i < nodes.Count; ++i)
if (nodes.Count > 0)
{
NodeImporter.SetupSkinning(GLTF, nodes, i, inverter);
Profiler.BeginSample("NodeImporter.SetupSkinning");
for (var i = 0; i < nodes.Count; ++i)
{
NodeImporter.SetupSkinning(GLTF, nodes, i, inverter);
}
Profiler.EndSample();

await awaitCaller.NextFrame();
}

if (Root == null)
Expand Down