Пример #1
0
            public JobHandle ScheduleDeferredJobs(MeshData sourceMeshData, List <System.IDisposable> tempList, JobHandle dependOn)
            {
                uint meshFlags = sourceMeshData.BufferFlags;

                deferredCombinedMesh = new DeferredMeshData(meshFlags, Allocator.TempJob);
                tempList.Add(deferredCombinedMesh);

                JobHandle combined = default;

                if (deferredCombinedMesh.HasVertices)
                {
                    var h = CombineTransformedBufferJob.ScheduleDeferred(BufferType.Vertex, sourceMeshData.Vertices, deferredCombinedMesh.Vertices, instanceList, dependOn);
                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (deferredCombinedMesh.HasTriangles)
                {
                    var h = CombineTriangleBufferJob.ScheduleDeferred(sourceMeshData.Triangles, deferredCombinedMesh.Triangles, meshFlags, instanceList, dependOn);
                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (deferredCombinedMesh.HasNormals)
                {
                    var h = CombineTransformedBufferJob.ScheduleDeferred(BufferType.Normal, sourceMeshData.Normals, deferredCombinedMesh.Normals, instanceList, dependOn);
                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (deferredCombinedMesh.HasColors)
                {
                    var h = CombineBufferJob <Color> .ScheduleDeferred(sourceMeshData.Colors, deferredCombinedMesh.Colors, instanceList, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (deferredCombinedMesh.HasTangents)
                {
                    var h = CombineBufferJob <float4> .ScheduleDeferred(sourceMeshData.Tangents, deferredCombinedMesh.Tangents, instanceList, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (deferredCombinedMesh.HasUVs)
                {
                    var h = CombineBufferJob <float2> .ScheduleDeferred(sourceMeshData.UVs, deferredCombinedMesh.UVs, instanceList, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (deferredCombinedMesh.HasUVs2)
                {
                    var h = CombineBufferJob <float2> .ScheduleDeferred(sourceMeshData.UVs2, deferredCombinedMesh.UVs2, instanceList, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (deferredCombinedMesh.HasUVs3)
                {
                    var h = CombineBufferJob <float2> .ScheduleDeferred(sourceMeshData.UVs3, deferredCombinedMesh.UVs3, instanceList, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (deferredCombinedMesh.HasUVs4)
                {
                    var h = CombineBufferJob <float2> .ScheduleDeferred(sourceMeshData.UVs4, deferredCombinedMesh.UVs4, instanceList, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                return(combined);
            }
Пример #2
0
        protected override void EndGeneration(Mesh mesh)
        {
            var(doesGenerateUvs, doesGenerateNormals) = CheckAllInfoForMiscData();

            NativeList <float3> vertices  = new NativeList <float3>(Allocator.Temp);
            NativeList <int>    triangles = new NativeList <int>(Allocator.Temp);
            NativeList <float3> normals   = doesGenerateNormals ? new NativeList <float3>(Allocator.Temp) : default;
            NativeList <float2> uvs       = doesGenerateUvs ? new NativeList <float2>(Allocator.Temp) : default;

            List <Offset> submeshOffsets = new List <Offset>();
            int           submeshStart   = 0;
            int           vertexOffset   = 0;

            foreach (var handlerArray in submeshInfos)
            {
                int submeshLength = 0;
                foreach (var handler in handlerArray)
                {
                    var(addedVerts, addedTris) = handler.CompleteAppendData(vertices, triangles, normals, uvs);

                    OffsetTriangles(triangles, submeshStart + submeshLength, addedTris, vertexOffset);

                    submeshLength += addedTris;
                    vertexOffset  += addedVerts;

                    if (normals.IsCreated && !handler.DoesGenerateNormals)
                    {
                        FillList(normals, vertices.Length - normals.Length, DefaultNormal);
                    }
                    if (uvs.IsCreated && !handler.DoesGenerateUvs)
                    {
                        FillList(uvs, vertices.Length - uvs.Length, DefaultUV);
                    }
                }
                submeshOffsets.Add(new Offset()
                {
                    index = submeshStart, length = submeshLength
                });
                submeshStart += submeshLength;
            }

            uint flags = MeshDataBufferFlags;

            if (uvs.IsCreated)
            {
                flags |= (uint)MeshBuffer.UV;
            }

            using (MeshData data = new MeshData(vertices.Length, triangles.Length, submeshOffsets.ToArray(), Allocator.Temp, flags))
            {
                NativeArray <float3> .Copy(vertices, data.Vertices);

                NativeArray <int> .Copy(triangles, data.Triangles);

                if (normals.IsCreated)
                {
                    NativeArray <float3> .Copy(normals, data.Normals);
                }
                if (uvs.IsCreated)
                {
                    NativeArray <float2> .Copy(uvs, data.UVs);
                }

                data.UpdateMesh(mesh, MeshData.UpdateMode.Clear);
            }

            SafeDispose(ref vertices);
            SafeDispose(ref triangles);
            SafeDispose(ref normals);
            SafeDispose(ref uvs);
        }
Пример #3
0
            public JobHandle ScheduleImmediateJobs(MeshData sourceMeshData, List <System.IDisposable> tempList, JobHandle dependOn)
            {
                var combinedInfo = CalcCombinedMeshInfo(instanceArray, sourceMeshData.BufferFlags);

                combinedMesh = combinedInfo.CreateMeshData(Allocator.TempJob);
                tempList.Add(combinedMesh);

                var submeshOffsets = new NativeArray <Offset>(combinedInfo.submeshTriangleOffsets, Allocator.TempJob);

                tempList.Add(submeshOffsets);

                JobHandle combined = default;

                if (combinedMesh.HasVertices)
                {
                    var h = CombineTransformedBufferJob.Schedule(BufferType.Vertex, sourceMeshData.Vertices, combinedMesh.Vertices, instanceArray, dependOn);
                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (combinedMesh.HasTriangles)
                {
                    var h = CombineTriangleBufferJob.Schedule(sourceMeshData.Triangles, combinedMesh.Triangles, submeshOffsets, instanceArray, dependOn);
                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (combinedMesh.HasNormals)
                {
                    var h = CombineTransformedBufferJob.Schedule(BufferType.Normal, sourceMeshData.Normals, combinedMesh.Normals, instanceArray, dependOn);
                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (combinedMesh.HasColors)
                {
                    var h = CombineBufferJob <Color> .Schedule(sourceMeshData.Colors, combinedMesh.Colors, instanceArray, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (combinedMesh.HasTangents)
                {
                    var h = CombineBufferJob <float4> .Schedule(sourceMeshData.Tangents, combinedMesh.Tangents, instanceArray, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (combinedMesh.HasUVs)
                {
                    var h = CombineBufferJob <float2> .Schedule(sourceMeshData.UVs, combinedMesh.UVs, instanceArray, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (combinedMesh.HasUVs2)
                {
                    var h = CombineBufferJob <float2> .Schedule(sourceMeshData.UVs2, combinedMesh.UVs2, instanceArray, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (combinedMesh.HasUVs3)
                {
                    var h = CombineBufferJob <float2> .Schedule(sourceMeshData.UVs3, combinedMesh.UVs3, instanceArray, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                if (combinedMesh.HasUVs4)
                {
                    var h = CombineBufferJob <float2> .Schedule(sourceMeshData.UVs4, combinedMesh.UVs4, instanceArray, dependOn);

                    combined = JobHandle.CombineDependencies(combined, h);
                }

                return(combined);
            }