Пример #1
0
        private void GenerateMeshAsync()
        {
            if (inflateJobWaiter != null && inflateJobWaiter.IsRunning)
            {
                inflateJobWaiter.ForceCancel();
            }

            var vertices         = new NativeArray <Vector3>(generatedVertices.ToArray(), Allocator.Persistent);
            var normals          = new NativeArray <Vector3>(generatedNormals.ToArray(), Allocator.Persistent);
            var modifiedVertices = new NativeArray <Vector3>(generatedVertices.Count, Allocator.Persistent);

            InflateMeshJobMulti inflateJob = new InflateMeshJobMulti()
            {
                vertices         = vertices,
                normals          = normals,
                modifiedVertices = modifiedVertices,
                inflateAmount    = mossDistance
            };

            JobHandle inflatingJobHandle = inflateJob.Schedule(generatedVertices.Count, 64);

            JobHandle.ScheduleBatchedJobs();

            Action <bool> onComplete = (success) =>
            {
                if (success)
                {
                    Vector3[] modVertices = new Vector3[generatedVertices.Count];
                    inflateJob.modifiedVertices.CopyTo(modVertices);

                    Vector3[] modNormals = generatedNormals.ToArray();

                    GenerateMesh(modVertices, modNormals);
                }

                inflateJob.vertices.Dispose();
                inflateJob.normals.Dispose();
                inflateJob.modifiedVertices.Dispose();
            };

            inflateJobWaiter = new EditorJobWaiter(inflatingJobHandle, onComplete);
            inflateJobWaiter.Start();
        }
Пример #2
0
        private void FindDuplicateMeshData(List <Vector3> addVertices, Action <int[]> onComplete)
        {
            if (findDuplicatesJobWaiter != null && findDuplicatesJobWaiter.IsRunning)
            {
                findDuplicatesJobWaiter.ForceCancel();
            }

            var newVertices       = new NativeArray <Vector3>(addVertices.ToArray(), Allocator.Persistent);
            var oldVertices       = new NativeArray <Vector3>(generatedVertices.ToArray(), Allocator.Persistent);
            var duplicateVertices = new NativeArray <int>(addVertices.Count, Allocator.Persistent);

            FindDuplicateMeshJob job = new FindDuplicateMeshJob()
            {
                newVertices       = newVertices,
                oldVertices       = oldVertices,
                duplicateVertices = duplicateVertices
            };

            JobHandle duplicateJobHandle = job.Schedule(addVertices.Count, 64);

            JobHandle.ScheduleBatchedJobs();

            Action <bool> onJobComplete = (success) =>
            {
                if (success)
                {
                    int[] duplicates = new int[addVertices.Count];
                    job.duplicateVertices.CopyTo(duplicates);
                    onComplete?.Invoke(duplicates);
                }

                job.duplicateVertices.Dispose();
                job.newVertices.Dispose();
                job.oldVertices.Dispose();
            };

            findDuplicatesJobWaiter = new EditorJobWaiter(duplicateJobHandle, onJobComplete);
            findDuplicatesJobWaiter.Start();
        }