Esempio n. 1
0
        protected override void OnUpdate()
        {
            var triangleBuffer     = GetBufferFromEntity <MeshTriangleData>();
            var vertexBuffer       = GetBufferFromEntity <MeshVertexData>();
            var knotBuffer         = GetBufferFromEntity <LineKnotData>(true);
            var defaultLineProfile = LineProfile.Default();

            var lineEntities = lineQuery.ToEntityArrayAsync(Allocator.TempJob, out var jh1);
            var lines        = lineQuery.ToComponentDataArrayAsync <Line>(Allocator.TempJob, out var jh2);

            Dependency = JobHandle.CombineDependencies(Dependency, jh1, jh2);

            var joinEntities = lineJoinsQuery.ToEntityArrayAsync(Allocator.TempJob, out jh1);
            var joinPoints   =
                lineJoinsQuery.ToComponentDataArrayAsync <LineJoinPoint>(Allocator.TempJob, out jh2);

            Dependency = JobHandle.CombineDependencies(Dependency, jh1, jh2);

            var ecb = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent();

            Dependency = Entities
                         .WithDeallocateOnJobCompletion(lineEntities)
                         .WithDeallocateOnJobCompletion(lines)
                         .WithDeallocateOnJobCompletion(joinEntities)
                         .WithDeallocateOnJobCompletion(joinPoints)
                         .ForEach((Entity entity, int entityInQueryIndex, ref MeshBuildData data) =>
            {
                ecb.DestroyEntity(entityInQueryIndex, entity);
                if (!lineEntities.Contains(data.LineEntity))
                {
                    return;
                }

                var line       = lines[lineEntities.IndexOf <Entity>(data.LineEntity)];
                var joinPointA =
                    joinPoints[joinEntities.IndexOf <Entity>(line.JoinPointA)];
                var joinPointB =
                    joinPoints[joinEntities.IndexOf <Entity>(line.JoinPointB)];

                new LineMeshRebuildJob
                {
                    Knots      = knotBuffer[data.LineEntity],
                    Triangles  = triangleBuffer[data.LineEntity],
                    VertexData = vertexBuffer[data.LineEntity],
                    // TODO: Load line profile
                    Profile       = defaultLineProfile,
                    EndDirections = new float3x2(joinPointA.Direction, joinPointB.Direction)
                }.Execute();
                ecb.AddComponent <MeshUpdated>(entityInQueryIndex, data.LineEntity);
            }).Schedule(Dependency);
            LineEndSimBufferSystem.Instance.AddJobHandleForProducer(Dependency);
        }
Esempio n. 2
0
        protected override void OnUpdate()
        {
            var joinPoints   = GetComponentDataFromEntity <LineJoinPoint>(true);
            var lines        = GetComponentDataFromEntity <Line>(true);
            var knotBuffers  = GetBufferFromEntity <LineKnotData>(true);
            var linesToCheck = mergeCheckQuery.ToEntityArray(Allocator.TempJob);

            Dependency.Complete();
            LineEndSimBufferSystem.Instance
            .CreateCommandBuffer()
            .RemoveComponent <MergeCheck>(mergeCheckQuery);

            Dependency = new LineMergeJob
            {
                Lines          = lines,
                LineEntities   = linesToCheck,
                LineJoinPoints = joinPoints,
                LineProfiles   = GetComponentDataFromEntity <LineProfile>(),
                LineKnotData   = knotBuffers,
                Ecb            = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent(),
                DefaultProfile = LineProfile.Default()
            }.Schedule(linesToCheck.Length, 4, Dependency);

            // TODO only trigger this when lines are merged
            Dependency = new LineTriggerMeshRebuildJob
            {
                Ecb           = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent(),
                Lines         = GetComponentDataFromEntity <Line>(true),
                LineProfiles  = GetComponentDataFromEntity <LineProfile>(true),
                LineEntities  = linesToCheck,
                DefaultPrefab = LineDefaultMeshBuilderSystem.Prefab
            }.Schedule(linesToCheck.Length, 4, Dependency);

            Dependency = new LineSetDirtyJob
            {
                Ecb          = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent(),
                LineEntities = linesToCheck
            }.Schedule(linesToCheck.Length, 4, Dependency);

            Dependency = new DeallocateJob <Entity>
            {
                NativeArray1 = linesToCheck
            }.Schedule(Dependency);

            LineEndSimBufferSystem.Instance.AddJobHandleForProducer(Dependency);
        }
Esempio n. 3
0
        public void Execute(int index)
        {
            // If index is different, this means this line entity was already in the
            // array, there for this is a duplicate and we can skip it.
            if (LineEntities.IndexOf <Entity>(LineEntities[index]) != index)
            {
                return;
            }

            newKnotData = Ecb.SetBuffer <LineKnotData>(index, LineEntities[index]);

            line = Lines[LineEntities[index]];

            lineProfile = LineProfiles.Exists(line.Profile) ? LineProfiles[line.Profile] : LineProfile.Default();

            var b1 = BezierData[index].B1;
            var b2 = BezierData[index].B2;

            SetKnotsForBezier(b1);

            if (!b1.c2.IsCloseTo(b2.c2, lineProfile.KnotSpacing))
            {
                SetKnotsForBezier(new float3x3(b1.c2, math.lerp(b1.c2, b2.c2, 0.5f), b2.c2));
            }

            SetKnotsForBezier(b2, true);

            AdjustHeight(HeightBezierData[index]);

            var jpA = LineJoinPoints[index].A;
            var jpB = LineJoinPoints[index].B;

            if (newKnotData.Length > 0)
            {
                jpA.Pivot = newKnotData[0].Position;
                jpB.Pivot = newKnotData[newKnotData.Length - 1].Position;
            }

            LineJoinPoints[index] = new JoinPointPair {
                A = jpA, B = jpB
            };
        }
Esempio n. 4
0
        protected override void OnUpdate()
        {
            var eventCount = eventQuery.CalculateEntityCount();

            var lineJoinPoints =
                new NativeArray <JoinPointPair>(eventCount, Allocator.TempJob);

            var eventData =
                eventQuery.ToComponentDataArrayAsync <NewLineUpdateEvent>(
                    Allocator.TempJob, out var jh1);

            var joinPoints = GetComponentDataFromEntity <LineJoinPoint>();


            var lineEntities = new NativeArray <Entity>(eventCount, Allocator.TempJob);

            Dependency = new GatherLineWithJoinPointData
            {
                EventData      = eventData,
                JoinPoints     = joinPoints,
                LineJoinPoints = lineJoinPoints,
                LineEntities   = lineEntities,
                Lines          = GetComponentDataFromEntity <Line>()
            }.Schedule(eventCount, 4, JobHandle.CombineDependencies(Dependency, jh1));

            // This job only runs if UpdateJoinPoints is set in event data
            Dependency = new NewLineGetUpdatedJoinPoints
            {
                Ecb            = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent(),
                EventData      = eventData,
                LineJoinPoints = lineJoinPoints,
                JoinPoints     = joinPoints,
                Lines          = GetComponentDataFromEntity <Line>()
            }.Schedule(eventCount, 4, Dependency);

            var updatedNewLines = new NativeArray <NewLine>(eventCount, Allocator.TempJob);

            Dependency = new NewLineUpdateModifiersJob
            {
                Ecb             = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent(),
                NewLines        = GetComponentDataFromEntity <NewLine>(),
                LineEntities    = lineEntities,
                LineJoinPoints  = lineJoinPoints,
                UpdateEvents    = eventData,
                UpdatedNewLines = updatedNewLines
            }.Schedule(eventCount, 4, Dependency);

            var heightBeziers = new NativeArray <float2x4>(eventCount, Allocator.TempJob);

            Dependency = new NewLineCreateHeightBezierJob
            {
                UpdatedNewLines = updatedNewLines,
                LineJoinPoints  = lineJoinPoints,
                HeightBeziers   = heightBeziers
            }.Schedule(eventCount, 4, Dependency);

            var bezierData = new NativeArray <BezierData>(eventCount, Allocator.TempJob);

            Dependency = new NewLineGetBezierJob
            {
                BezierData     = bezierData,
                JoinPoints     = GetComponentDataFromEntity <LineJoinPoint>(),
                LineTool       = GetSingleton <LineTool>(),
                LineJoinPoints = lineJoinPoints
            }.Schedule(eventCount, 4, Dependency);

            var boundsArray = new NativeArray <float3x2>(eventCount, Allocator.TempJob);

            Dependency = new NewLineGetBoundsFromBezierJob
            {
                BezierData  = bezierData,
                BoundsArray = boundsArray
            }.Schedule(eventCount, 4, Dependency);

            Dependency = new NewLineUpdateLineEntityJob
            {
                LineEntities   = lineEntities,
                BoundsArray    = boundsArray,
                Lines          = GetComponentDataFromEntity <Line>(true),
                LineProfiles   = GetComponentDataFromEntity <LineProfile>(),
                Ecb            = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent(),
                DefaultProfile = LineProfile.Default()
            }.Schedule(eventCount, 4, Dependency);

            Dependency = new NewLineGenerateKnotsJob
            {
                Ecb              = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent(),
                BezierData       = bezierData,
                HeightBezierData = heightBeziers,
                KnotData         = GetBufferFromEntity <LineKnotData>(),
                LineEntities     = lineEntities,
                LineProfiles     = GetComponentDataFromEntity <LineProfile>(),
                LineJoinPoints   = lineJoinPoints,
                Lines            = GetComponentDataFromEntity <Line>()
            }.Schedule(eventCount, 4, Dependency);

            Dependency = new NewLineUpdateJoinPointsJob
            {
                Ecb            = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent(),
                LineEntities   = lineEntities,
                Lines          = GetComponentDataFromEntity <Line>(),
                LineJoinPoints = lineJoinPoints
            }.Schedule(eventCount, 4, Dependency);

            Dependency = new LineSetDirtyJob
            {
                LineEntities = lineEntities,
                Ecb          = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent()
            }.Schedule(eventCount, 4, Dependency);

            Dependency = new LineTriggerMeshRebuildJob
            {
                Ecb           = LineEndSimBufferSystem.Instance.CreateCommandBuffer().ToConcurrent(),
                LineEntities  = lineEntities,
                LineProfiles  = GetComponentDataFromEntity <LineProfile>(),
                Lines         = GetComponentDataFromEntity <Line>(true),
                DefaultPrefab = LineDefaultMeshBuilderSystem.Prefab
            }.Schedule(eventCount, 4, Dependency);

            new DeallocateJob <Entity, JoinPointPair, NewLineUpdateEvent, float3x2>
            {
                NativeArray1 = lineEntities,
                NativeArray2 = lineJoinPoints,
                NativeArray3 = eventData,
                NativeArray4 = boundsArray
            }.Schedule(Dependency);

            new DeallocateJob <NewLine, float2x4, BezierData>
            {
                NativeArray1 = updatedNewLines,
                NativeArray2 = heightBeziers,
                NativeArray3 = bezierData
            }.Schedule(Dependency);

            LineEndSimBufferSystem.Instance.CreateCommandBuffer().DestroyEntity(eventQuery);

            LineEndSimBufferSystem.Instance.AddJobHandleForProducer(Dependency);
        }