Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #52 from hiroj/import_speed_up
Browse files Browse the repository at this point in the history
Import speed up
  • Loading branch information
ousttrue authored Oct 12, 2018
2 parents 975f06f + 0a24f80 commit 8918a4f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 69 deletions.
122 changes: 55 additions & 67 deletions Core/Scripts/IO/ImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,27 +466,9 @@ protected virtual Schedulable<Unit> LoadAsync()
//
}
})
.ContinueWithCoroutine(Scheduler.ThreadPool, () =>
{
using (MeasureTime("TexturesProcessOnAnyThread"))
{
return TexturesProcessOnAnyThread();
}
})
.ContinueWithCoroutine(Scheduler.MainThread, () =>
{
using (MeasureTime("TexturesProcessOnMainThread"))
{
return TexturesProcessOnMainThread();
}
})
.ContinueWithCoroutine(Scheduler.MainThread, () =>
{
using (MeasureTime("LoadMaterials"))
{
return LoadMaterials();
}
})
.ContinueWithCoroutine(Scheduler.ThreadPool, TexturesProcessOnAnyThread)
.ContinueWithCoroutine(Scheduler.MainThread, TexturesProcessOnMainThread)
.ContinueWithCoroutine(Scheduler.MainThread, LoadMaterials)
.OnExecute(Scheduler.ThreadPool, parent =>
{
if (GLTF.meshes
Expand Down Expand Up @@ -535,24 +517,15 @@ protected virtual Schedulable<Unit> LoadAsync()
;
}
})
.ContinueWithCoroutine(Scheduler.MainThread, () =>
{
using (MeasureTime("LoadNodes"))
{
return LoadNodes();
}
})
.ContinueWithCoroutine(Scheduler.MainThread, () =>
.ContinueWithCoroutine(Scheduler.MainThread, LoadNodes)
.ContinueWithCoroutine(Scheduler.MainThread, BuildHierarchy)
.ContinueWith(Scheduler.MainThread, _ =>
{
using (MeasureTime("BuildHierarchy"))
using (MeasureTime("AnimationImporter"))
{
return BuildHierarchy();
AnimationImporter.ImportAnimation(this);
}
})
.ContinueWith(Scheduler.MainThread, _ =>
{
AnimationImporter.ImportAnimation(this);
})
.ContinueWith(Scheduler.CurrentThread,
_ =>
{
Expand All @@ -569,36 +542,45 @@ protected virtual void OnLoadModel()

IEnumerator TexturesProcessOnAnyThread()
{
foreach (var x in GetTextures())
using (MeasureTime("TexturesProcessOnAnyThread"))
{
x.ProcessOnAnyThread(GLTF, Storage);
yield return null;
foreach (var x in GetTextures())
{
x.ProcessOnAnyThread(GLTF, Storage);
yield return null;
}
}
}

IEnumerator TexturesProcessOnMainThread()
{
foreach (var x in GetTextures())
using (MeasureTime("TexturesProcessOnMainThread"))
{
x.ProcessOnMainThread(GLTF);
yield return null;
foreach (var x in GetTextures())
{
x.ProcessOnMainThread(GLTF);
yield return null;
}
}
}

IEnumerator LoadMaterials()
{
if (GLTF.materials == null || !GLTF.materials.Any())
using (MeasureTime("LoadMaterials"))
{
AddMaterial(MaterialImporter.CreateMaterial(0, null));
}
else
{
for (int i = 0; i < GLTF.materials.Count; ++i)
if (GLTF.materials == null || !GLTF.materials.Any())
{
AddMaterial(MaterialImporter.CreateMaterial(i, GLTF.materials[i]));
yield return null;
AddMaterial(MaterialImporter.CreateMaterial(0, null));
}
else
{
for (int i = 0; i < GLTF.materials.Count; ++i)
{
AddMaterial(MaterialImporter.CreateMaterial(i, GLTF.materials[i]));
}
}
}
yield return null;
}

IEnumerator LoadMeshes()
Expand All @@ -621,36 +603,42 @@ IEnumerator LoadMeshes()

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

yield return null;
}

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

NodeImporter.FixCoordinate(this, nodes);
NodeImporter.FixCoordinate(this, nodes);

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

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

yield return null;
Expand Down
2 changes: 1 addition & 1 deletion Core/Scripts/IO/MeshImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public static MeshWithMaterials BuildMesh(ImporterContext ctx, MeshImporter.Mesh
{
emptyVertices = new Vector3[mesh.vertexCount];
}
Debug.LogFormat("empty blendshape: {0}.{1}", mesh.name, blendShape.Name);
// Debug.LogFormat("empty blendshape: {0}.{1}", mesh.name, blendShape.Name);
// add empty blend shape for keep blend shape index
mesh.AddBlendShapeFrame(blendShape.Name, FRAME_WEIGHT,
emptyVertices,
Expand Down
4 changes: 3 additions & 1 deletion Core/Scripts/IO/TextureItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ static Byte[] ToArray(ArraySegment<byte> bytes)
}
else
{
return bytes.Array.Skip(bytes.Offset).Take(bytes.Count).ToArray();
Byte[] result = new byte[bytes.Count];
Buffer.BlockCopy(bytes.Array, bytes.Offset, result, 0, result.Length);
return result;
}
}

Expand Down

0 comments on commit 8918a4f

Please sign in to comment.