Skip to content

Commit

Permalink
feat: Incorporated IDeferAgent into MorphTargetContext. This way it's…
Browse files Browse the repository at this point in the history
… possible to add multple blend shapes per frame (if the IDeferAgent decides it's doable)
  • Loading branch information
atteneder committed Jan 13, 2022
1 parent f39caf2 commit 13f84f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Runtime/Scripts/GltfImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,7 @@ async Task<bool> LoadAccessorData( Root gltf ) {
}

MorphTargetsContext CreateMorphTargetsContext(MeshPrimitive primitive,string[] meshTargetNames) {
var morphTargetsContext = new MorphTargetsContext(primitive.targets.Length,meshTargetNames);
var morphTargetsContext = new MorphTargetsContext(primitive.targets.Length,meshTargetNames,deferAgent);
foreach (var morphTarget in primitive.targets) {
var success = morphTargetsContext.AddMorphTarget(
this,
Expand Down
13 changes: 6 additions & 7 deletions Runtime/Scripts/MorphTargetContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Profiling;
using Mesh = UnityEngine.Mesh;
using System.Threading.Tasks;
using System.Threading;

namespace GLTFast {

Expand All @@ -32,12 +30,14 @@ class MorphTargetsContext {
NativeArray<JobHandle> handles;
int currentIndex;
string[] meshTargetNames;
IDeferAgent deferAgent;

public MorphTargetsContext(int morphTargetCount, string[] meshTargetNames) {
public MorphTargetsContext(int morphTargetCount, string[] meshTargetNames, IDeferAgent deferAgent) {
contexts = new MorphTargetContext[morphTargetCount];
handles = new NativeArray<JobHandle>(morphTargetCount, VertexBufferConfigBase.defaultAllocator);
currentIndex = 0;
this.meshTargetNames = meshTargetNames;
this.deferAgent = deferAgent;
}

public bool AddMorphTarget(
Expand Down Expand Up @@ -76,8 +76,9 @@ public JobHandle GetJobHandle() {
public async Task ApplyOnMeshAndDispose(Mesh mesh) {
for (var index = 0; index < contexts.Length; index++) {
var context = contexts[index];
await context.AddToMesh(mesh, meshTargetNames?[index] ?? index.ToString());
context.AddToMesh(mesh, meshTargetNames?[index] ?? index.ToString());
context.Dispose();
await deferAgent.BreakPoint();
}
contexts = null;
}
Expand Down Expand Up @@ -298,12 +299,10 @@ ICodeLogger logger
return handle;
}

public async Task AddToMesh(Mesh mesh, string name) {
public void AddToMesh(Mesh mesh, string name) {
Profiler.BeginSample("AddBlendShapeFrame");
mesh.AddBlendShapeFrame(name,1f,positions,normals,tangents);
Profiler.EndSample();
// await Task.Delay(20, CancellationToken.None);
await Task.Yield();
}

public void Dispose() {
Expand Down

0 comments on commit 13f84f7

Please sign in to comment.