public static void StartBakingMesh(Mesh mesh) { var job = new BakeJob(mesh.GetInstanceID()); JobHandle currentJob = job.Schedule(); jobsByMesh.Add(mesh, currentJob); }
public static void BakeMeshImmediate(Mesh mesh) { var job = new BakeJob(mesh.GetInstanceID()); JobHandle currentJob = job.Schedule(); currentJob.Complete(); }
IEnumerator BakeUpdator() { int counter = 0; while (true) { if (meshes.Count == 0) { counter = 0; yield return(null); continue; } if (counter < 4 && meshes.Count < 5) { counter++; yield return(null); continue; } meshIds = new NativeArray <int>(meshes.Count, Allocator.TempJob); for (int i = 0; i < meshes.Count; ++i) { meshIds[i] = meshes[i].mesh.GetInstanceID(); } BakeJob bakeJob = new BakeJob { meshIds = meshIds }; jobHandle = bakeJob.Schedule(meshIds.Length, 32); JobHandle.ScheduleBatchedJobs(); int frameCount = 1; yield return(new WaitUntil(() => { frameCount++; return jobHandle.IsCompleted || frameCount >= 4; })); jobHandle.Complete(); meshIds.Dispose(); for (int i = 0; i < meshes.Count; i++) { meshes[i].chunk.SetSharedMesh(meshes[i].mesh); } meshes.Clear(); counter = 0; yield return(null); } }
public static BakeJob ConfigureBake(Curve[] curves, float frameRate, Curve[] outCurves, Allocator alloc, SampleRange sampleRange) { var job = new BakeJob(); job.curves = new NativeArray <CurveData>(curves.Length, alloc); job.frameRate = frameRate; job.outCurves = new NativeArray <CurveData>(curves.Length, alloc); job.sampleRange = sampleRange; for (int i = 0; i < curves.Length; i++) { job.curves[i] = new CurveData(curves[i], alloc); int frameCount = (int)math.ceil(frameRate * curves[i].Duration); //var outCurve = new Curve(frameCount, alloc); //outCurves[i] = outCurve; job.outCurves[i] = new CurveData(outCurves[i], alloc); } return(job); }