protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            SimulationCallbacks.Callback verifyContactsIteratorJobCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyContactsIteratorJob
                {
                    CurrentManifoldNumContacts = CurrentManifoldNumContacts,
                    Bodies = world.Bodies,
                    VerificationData = GetComponentDataFromEntity <VerifyContactsIteratorData>(true)
                }.Schedule(simulation, ref world, inDeps));
            };

            SimulationCallbacks.Callback verifyNumContactsJobCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyNumContactsJob
                {
                    CurrentManifoldNumContacts = CurrentManifoldNumContacts,
                    VerificationData = GetComponentDataFromEntity <VerifyContactsIteratorData>(true)
                }.Schedule(inDeps));
            };

            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, verifyContactsIteratorJobCallback, inputDeps);
            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContactJacobians, verifyNumContactsJobCallback, inputDeps);

            return(inputDeps);
        }
        protected override void OnUpdate()
        {
            SimulationCallbacks.Callback testTriggerEventsCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyTriggerEventsJob
                {
                    NumEvents = NumEvents,
                    VerificationData = GetComponentDataFromEntity <VerifyTriggerEventsData>(true)
                }.Schedule(simulation, ref world, inDeps));
            };

            SimulationCallbacks.Callback testTriggerEventsPostCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyTriggerEventsPostJob
                {
                    NumEvents = NumEvents,
                    SimulationType = simulation.Type,
                    VerificationData = GetComponentDataFromEntity <VerifyTriggerEventsData>(true),
                    Entities = m_VerificationGroup.ToEntityArray(Allocator.TempJob)
                }.Schedule(inDeps));
            };

            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventsCallback, Dependency);
            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventsPostCallback, Dependency);
        }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (m_PairModifierGroup.CalculateLength() == 0)
        {
            return(inputDeps);
        }

        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return(inputDeps);
        }

        // Add a custom callback to the simulation, which will inject our custom job after the body pairs have been created
        SimulationCallbacks.Callback callback = (ref ISimulation simulation, JobHandle inDeps) =>
        {
            inDeps.Complete(); //<todo Needed to initialize our modifier

            return(new DisablePairsJob
            {
                Bodies = m_PhysicsWorld.PhysicsWorld.Bodies,
                Motions = m_PhysicsWorld.PhysicsWorld.MotionVelocities,
                Iterator = simulation.BodyPairs.GetIterator()
            }.Schedule(inDeps));
        };
        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, callback);

        return(inputDeps);
    }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            SimulationCallbacks.Callback testTriggerEventsCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyTriggerEventsJob
                {
                    NumEvents = NumEvents,
                    VerificationData = GetComponentDataFromEntity <VerifyTriggerEventsData>(true)
                }.Schedule(simulation, ref world, inDeps));
            };

            SimulationCallbacks.Callback testTriggerEventsPostCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyTriggerEventsPostJob
                {
                    NumEvents = NumEvents,
                    SimulationType = simulation.Type,
                    VerificationData = GetComponentDataFromEntity <VerifyTriggerEventsData>(true)
                }.Schedule(inDeps));
            };

            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventsCallback, inputDeps);
            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventsPostCallback, inputDeps);

            return(inputDeps);
        }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (m_ContactAdderGroup.CalculateLength() == 0)
        {
            return(inputDeps);
        }

        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return(inputDeps);
        }

        // Enqueue a callback which will inject a job into the simulation step
        SimulationCallbacks.Callback callback = (ref ISimulation simulation, JobHandle inDeps) =>
        {
            inDeps.Complete();  // TODO: shouldn't be needed?

            JobHandle handle = new AddContactsJob
            {
                Bodies   = m_BuildPhysicsWorldSystem.PhysicsWorld.Bodies,
                Motions  = m_BuildPhysicsWorldSystem.PhysicsWorld.MotionDatas,
                Contacts = simulation.Contacts
            }.Schedule(inDeps);

            handle.Complete(); //<todo.eoin.usermod Remove. Difficult, due to deallocation of schedulerInfo.

            return(handle);
        };
        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, callback);

        return(inputDeps);
    }
    protected override void OnUpdate()
    {
        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return;
        }

        SimulationCallbacks.Callback preparationCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            return(new SetContactFlagsJob
            {
                modificationData = GetComponentDataFromEntity <ModifyContactJacobians>(true)
            }.Schedule(simulation, ref world, inDeps));
        };

        SimulationCallbacks.Callback jacobianModificationCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            return(new ModifyJacobiansJob
            {
                modificationData = GetComponentDataFromEntity <ModifyContactJacobians>(true)
            }.Schedule(simulation, ref world, inDeps));
        };

        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, preparationCallback, Dependency);
        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContactJacobians, jacobianModificationCallback, Dependency);
    }
Пример #7
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (!(HasSingleton <PhysicsDebugDisplayData>() && GetSingleton <PhysicsDebugDisplayData>().DrawContacts != 0))
            {
                return(inputDeps);
            }

            SimulationCallbacks.Callback callback = (ref ISimulation simulation, JobHandle inDeps) =>
            {
                inDeps.Complete(); //<todo Necessary to initialize the modifier

                SimulationData.Contacts contacts = simulation.Contacts;
                int numWorkItems = contacts.NumWorkItems;
                if (numWorkItems > 0)
                {
                    return(new DisplayContactsJob
                    {
                        ManifoldIterator = contacts.GetIterator(),
                        OutputStream = m_DebugStreamSystem.GetContext(numWorkItems)
                    }.Schedule(numWorkItems, 1, inDeps));
                }
                return(inDeps);
            };

            m_StepWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, callback);


            return(inputDeps);
        }
Пример #8
0
    protected override void OnCreate()
    {
        m_StepPhysicsWorld = World.GetOrCreateSystem <StepPhysicsWorld>();

        m_PreparationCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            var job = new SetConveyorBeltFlagJob
            {
                ConveyorBelts = GetComponentDataFromEntity <ConveyorBelt>(true)
            }.Schedule(simulation, ref world, inDeps);
            return(job);
        };

        m_JacobianModificationCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            var job = new SetConveyorBeltSpeedJob
            {
                ConveyorBelts = GetComponentDataFromEntity <ConveyorBelt>(true),
                Bodies        = world.Bodies,
            }.Schedule(simulation, ref world, inDeps);
            return(job);
        };

        RequireForUpdate(GetEntityQuery(new EntityQueryDesc
        {
            All = new ComponentType[] { typeof(ConveyorBelt) }
        }));
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (m_ContactModifierGroup.CalculateLength() == 0)
        {
            return(inputDeps);
        }

        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return(inputDeps);
        }

        var modifiers     = m_ContactModifierGroup.ToComponentDataArray <ModifyNarrowphaseContacts>(Allocator.TempJob);
        var surfaceNormal = modifiers[0].surfaceNormal;
        var surfaceRBIdx  = m_BuildPhysicsWorld.PhysicsWorld.GetRigidBodyIndex(modifiers[0].surfaceEntity);

        SimulationCallbacks.Callback callback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            inDeps.Complete();  // TODO: shouldn't be needed (jobify the below)

            return(new ModifyNormalsJob
            {
                m_SurfaceRBIdx = surfaceRBIdx,
                m_SurfaceNormal = surfaceNormal
            }.Schedule(simulation, ref world, inDeps));
        };

        modifiers.Dispose();

        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, callback);

        return(inputDeps);
    }
    protected override void OnUpdate()
    {
        if (m_PairModifierGroup.CalculateEntityCount() == 0)
        {
            return;
        }

        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return;
        }

        // Add a custom callback to the simulation, which will inject our custom job after the body pairs have been created
        SimulationCallbacks.Callback callback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            inDeps.Complete(); //<todo Needed to initialize our modifier

            return(new DisablePairsJob
            {
                Bodies = m_PhysicsWorld.PhysicsWorld.Bodies,
                Motions = m_PhysicsWorld.PhysicsWorld.MotionVelocities
            }.Schedule(simulation, ref world, Dependency));
        };
        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, callback);
    }
Пример #11
0
    protected override void OnCreate()
    {
        m_StepPhysicsWorld = World.GetOrCreateSystem <StepPhysicsWorld>();

        m_PreparationCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            return(new SetContactFlagsJob
            {
                modificationData = GetComponentDataFromEntity <ModifyContactJacobians>(true)
            }.Schedule(simulation, ref world, inDeps));
        };

        m_JacobianModificationCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            return(new ModifyJacobiansJob
            {
                modificationData = GetComponentDataFromEntity <ModifyContactJacobians>(true)
            }.Schedule(simulation, ref world, inDeps));
        };

        RequireForUpdate(GetEntityQuery(new EntityQueryDesc
        {
            All = new ComponentType[] { typeof(ModifyContactJacobians) }
        }));
    }
Пример #12
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (m_PairModifierGroup.CalculateEntityCount() == 0)
        {
            return(inputDeps);
        }

        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return(inputDeps);
        }

        // Add a custom callback to the simulation, which will inject our custom job after the body pairs have been created
        SimulationCallbacks.Callback callback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            inDeps.Complete(); //<todo Needed to initialize our modifier

            return(new DisablePairsJob
            {
                Bodies = m_PhysicsWorld.PhysicsWorld.Bodies,
                DisableGroup = GetComponentDataFromEntity <DisableCollision>(true)
            }.Schedule(simulation, ref world, inputDeps));
        };
        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, callback);

        return(inputDeps);
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (m_ContactModifierGroup.CalculateLength() == 0)
        {
            return(inputDeps);
        }

        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return(inputDeps);
        }

        var modifiers     = m_ContactModifierGroup.ToComponentDataArray <ModifyNarrowphaseContacts>(Allocator.TempJob);
        var surfaceNormal = modifiers[0].surfaceNormal;
        var surfaceRBIdx  = m_BuildPhysicsWorld.PhysicsWorld.GetRigidBodyIndex(modifiers[0].surfaceEntity);

        SimulationCallbacks.Callback callback = (ref ISimulation simulation, JobHandle inDeps) =>
        {
            inDeps.Complete();  // TODO: shouldn't be needed (jobify the below)

            SimulationData.Contacts.Iterator iterator = simulation.Contacts.GetIterator();
            while (iterator.HasItemsLeft())
            {
                ContactHeader manifold      = iterator.GetNextContactHeader();
                bool          bUpdateNormal = (manifold.BodyPair.BodyAIndex == surfaceRBIdx) || (manifold.BodyPair.BodyBIndex == surfaceRBIdx);

                float distanceScale = 1;
                if (bUpdateNormal)
                {
                    var newNormal = surfaceNormal;
                    distanceScale = math.dot(newNormal, manifold.Normal);

                    //<todo.eoin.hpi Feels pretty weird.
                    //<todo.eoin.hp Need to make this work if user has read a contact
                    iterator.SetManifoldNormal(newNormal);
                }
                for (int i = 0; i < manifold.NumContacts; i++)
                {
                    ContactPoint cp = iterator.GetNextContact();

                    if (bUpdateNormal)
                    {
                        cp.Distance *= distanceScale;
                        iterator.UpdatePreviousContact(cp);
                    }
                }
            }

            return(inDeps);
        };

        modifiers.Dispose();

        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, callback);

        return(inputDeps);
    }
        protected override void OnUpdate()
        {
            SimulationCallbacks.Callback verifyBodyPairsIteratorJobCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyBodyPairsIteratorJob
                {
                    Bodies = world.Bodies,
                    VerificationData = GetComponentDataFromEntity <VerifyBodyPairsIteratorData>(true)
                }.Schedule(simulation, ref world, inDeps));
            };

            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, verifyBodyPairsIteratorJobCallback, Dependency);
        }
Пример #15
0
        protected override void OnUpdate()
        {
            SimulationCallbacks.Callback testTriggerEventCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyTriggerEventDataJob
                {
                    Bodies = world.Bodies,
                    VerificationData = GetComponentDataFromEntity <VerifyTriggerEventDataData>(true)
                }.Schedule(simulation, ref world, inDeps));
            };

            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventCallback, Dependency);
        }
Пример #16
0
        protected override void OnUpdate()
        {
            SimulationCallbacks.Callback verifyPhasedDispatchPairsJobCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyPhasedDispatchPairsJob
                {
                    VerificationData = GetComponentDataFromEntity <VerifyPhasedDispatchPairsData>(true),
                    LastStaticPairPerDynamicBody = new NativeArray <int>(world.NumDynamicBodies, Allocator.TempJob),
                    IsUnityPhysics = simulation.Type == SimulationType.UnityPhysics
                }.Schedule(simulation, ref world, inDeps));
            };

            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, verifyPhasedDispatchPairsJobCallback, Dependency);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            SimulationCallbacks.Callback testCollisionEventCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                return(new VerifyCollisionEventDataJob
                {
                    World = world,
                    Bodies = world.Bodies,
                    VerificationData = GetComponentDataFromEntity <VerifyCollisionEventDataData>(true)
                }.Schedule(simulation, ref world, inDeps));
            };

            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testCollisionEventCallback, inputDeps);

            return(inputDeps);
        }
Пример #18
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (!(HasSingleton <PhysicsDebugDisplayData>() && GetSingleton <PhysicsDebugDisplayData>().DrawContacts != 0))
            {
                return(inputDeps);
            }

            SimulationCallbacks.Callback callback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
            {
                unsafe
                {
                    // Allocate a block of memory to store our debug output, so it can be shared across the display/finish jobs
                    var sharedOutput = (DebugStream.Context *)UnsafeUtility.Malloc(sizeof(DebugStream.Context), 16, Allocator.TempJob);
                    *   sharedOutput = m_DebugStreamSystem.GetContext(1);
                    sharedOutput->Begin(0);

                    var gatherJob = new DisplayContactsJob
                    {
                        DisplayContactIndices = false,
                        OutputStreamContext   = sharedOutput
                    };

                    JobHandle gatherJobHandle = new DisplayContactsJob
                    {
                        DisplayContactIndices = false,
                        OutputStreamContext   = sharedOutput
                    }.Schedule(simulation, ref world, inDeps);

                    var finishJob = new FinishDisplayContactsJob
                    {
                        OutputStreamContext = sharedOutput
                    };

                    return(finishJob.Schedule(gatherJobHandle));
                }
            };

            m_StepWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, callback);

            return(inputDeps);
        }
Пример #19
0
        protected override void OnUpdate()
        {
            if (!(HasSingleton <PhysicsDebugDisplayData>() && GetSingleton <PhysicsDebugDisplayData>().DrawColliderAabbs != 0))
            {
                return;
            }

            if (m_BuildPhysicsWorldSystem.PhysicsWorld.NumBodies == 0)
            {
                return;
            }

            SimulationCallbacks.Callback callback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle deps) =>
            {
                return(new DisplayColliderAabbsJob
                {
                    OutputStream = m_DebugStreamSystem.GetContext(1),
                    Bodies = m_BuildPhysicsWorldSystem.PhysicsWorld.Bodies
                }.Schedule(deps));
            };
            m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, callback);
        }
    protected override void OnUpdate()
    {
        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return;
        }

        var modifier = GetSingleton <ModifyNarrowphaseContacts>();

        var surfaceNormal = modifier.surfaceNormal;
        var surfaceEntity = modifier.surfaceEntity;

        SimulationCallbacks.Callback callback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            return(new ModifyNormalsJob
            {
                SurfaceEntity = surfaceEntity,
                SurfaceNormal = surfaceNormal,
                CollisionWorld = world.CollisionWorld,
            }.Schedule(simulation, ref world, inDeps));
        };
        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, callback);
    }
Пример #21
0
    protected override JobHandle OnUpdate(JobHandle handle)
    {
        // delegate for physics to add my jobs to its pipeline
        SimulationCallbacks.Callback callback = (ref ISimulation sim,
                                                 ref PhysicsWorld world, JobHandle deps) =>
        {
            // delete containers from previous frame
            DisposeContainers();

            JobHandle playerToBulletCollect = InitCollectBulletDataJob(ref sim,
                                                                       ref world, deps, ObjectType.Player, ObjectType.EnemyBullet);
            JobHandle enemyToBulletCollect = InitCollectBulletDataJob(ref sim,
                                                                      ref world, deps, ObjectType.Enemy, ObjectType.PlayerBullet);

            JobHandle processJob = InitProcessJobs(playerToBulletCollect, enemyToBulletCollect);
            job = processJob;
            return(processJob);
        };

        stepPhysWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts,
                                      callback);

        return(handle);
    }
    protected override void OnUpdate()
    {
        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return;
        }

        // Add a custom callback to the simulation, which will inject our custom job after the body pairs have been created
        SimulationCallbacks.Callback callback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
        {
            inDeps = new DisableDynamicDynamicPairsJob
            {
                NumDynamicBodies = world.NumDynamicBodies
            }.Schedule(m_StepPhysicsWorld.Simulation, ref world, inDeps);

            inDeps = new DisableDynamicStaticPairsJob
            {
                NumDynamicBodies = world.NumDynamicBodies
            }.Schedule(m_StepPhysicsWorld.Simulation, ref world, inDeps);

            return inDeps;
        };
        m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, callback);
    }
Пример #23
0
 // Enqueue a callback to run during scheduling of the next simulation step
 public void EnqueueCallback(SimulationCallbacks.Phase phase, SimulationCallbacks.Callback callback, JobHandle dependency = default(JobHandle))
 {
     m_Callbacks.Enqueue(phase, callback, dependency);
 }
Пример #24
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (m_ContactModifierGroup.CalculateLength() == 0)
        {
            return(inputDeps);
        }

        if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics)
        {
            return(inputDeps);
        }

        SimulationCallbacks.Callback preparationCallback = (ref ISimulation simulation, JobHandle inDeps) =>
        {
            inDeps.Complete();  // shouldn't be needed (jobify the below)

            SimulationData.Contacts.Iterator iterator = simulation.Contacts.GetIterator();
            while (iterator.HasItemsLeft())
            {
                ContactHeader manifold = iterator.GetNextContactHeader();

                // JacobianModifierFlags format for this example
                // UserData 0 - soft contact
                // UserData 1 - surface velocity
                // UserData 2 - infinite inertia
                // UserData 3 - no torque
                // UserData 4 - clip impulse
                // UserData 5 - disabled contact

                if (0 != (manifold.BodyCustomDatas.CustomDataA & (byte)(1 << 0)) ||
                    0 != (manifold.BodyCustomDatas.CustomDataB & (byte)(1 << 0)))
                {
                    manifold.JacobianFlags |= JacobianFlags.UserFlag0; // Soft Contact
                }
                if (0 != (manifold.BodyCustomDatas.CustomDataA & (byte)(1 << 1)) ||
                    0 != (manifold.BodyCustomDatas.CustomDataB & (byte)(1 << 1)))
                {
                    manifold.JacobianFlags |= JacobianFlags.EnableSurfaceVelocity;
                }
                if (0 != (manifold.BodyCustomDatas.CustomDataA & (byte)(1 << 2)) ||
                    0 != (manifold.BodyCustomDatas.CustomDataB & (byte)(1 << 2)))
                {
                    manifold.JacobianFlags |= JacobianFlags.EnableMassFactors;
                }
                if (0 != (manifold.BodyCustomDatas.CustomDataA & (byte)(1 << 3)) ||
                    0 != (manifold.BodyCustomDatas.CustomDataB & (byte)(1 << 3)))
                {
                    manifold.JacobianFlags |= JacobianFlags.UserFlag1; // No Torque
                }
                if (0 != (manifold.BodyCustomDatas.CustomDataA & (byte)(1 << 4)) ||
                    0 != (manifold.BodyCustomDatas.CustomDataB & (byte)(1 << 4)))
                {
                    manifold.JacobianFlags |= JacobianFlags.EnableMaxImpulse; // No Torque
                }
                if (0 != (manifold.BodyCustomDatas.CustomDataA & (byte)(1 << 5)) ||
                    0 != (manifold.BodyCustomDatas.CustomDataB & (byte)(1 << 5)))
                {
                    manifold.JacobianFlags |= JacobianFlags.Disabled;
                }

                iterator.UpdatePreviousContactHeader(manifold);

                // Just read contacts
                for (int i = 0; i < manifold.NumContacts; i++)
                {
                    iterator.GetNextContact();
                }
            }

            return(inDeps);
        };

        SimulationCallbacks.Callback jacobianModificationCallback = (ref ISimulation simulation, JobHandle inDeps) =>
        {
            inDeps.Complete();  // shouldn't be needed (jobify the below)

            JacobianIterator iterator = simulation.Jacobians.Iterator;
            while (iterator.HasJacobiansLeft())
            {
                // JacobianModifierFlags format for this example
                // UserFlag0 - soft contact
                // UserFlag1 - no torque

                // Jacobian header
                ref JacobianHeader jacHeader = ref iterator.ReadJacobianHeader();

                // Triggers can only be disabled, other modifiers have no effect
                if (jacHeader.Type == JacobianType.Contact)
                {
                    // Contact jacobian modification
                    ref ContactJacobian contactJacobian = ref jacHeader.AccessBaseJacobian <ContactJacobian>();
                    {
                        // Check if NoTorque modifier
                        if ((jacHeader.Flags & JacobianFlags.UserFlag1) != 0)
                        {
                            // Disable all friction angular effects
                            contactJacobian.Friction0.AngularA       = 0.0f;
                            contactJacobian.Friction1.AngularA       = 0.0f;
                            contactJacobian.AngularFriction.AngularA = 0.0f;
                            contactJacobian.Friction0.AngularB       = 0.0f;
                            contactJacobian.Friction1.AngularB       = 0.0f;
                            contactJacobian.AngularFriction.AngularB = 0.0f;
                        }

                        // Check if SurfaceVelocity present
                        if (jacHeader.HasSurfaceVelocity)
                        {
                            // Since surface normal can change, make sure angular velocity is always relative to it, not independent
                            float3 angVel = contactJacobian.BaseJacobian.Normal * (new float3(0.0f, 1.0f, 0.0f));
                            float3 linVel = float3.zero;

                            Math.CalculatePerpendicularNormalized(contactJacobian.BaseJacobian.Normal, out float3 dir0, out float3 dir1);
                            float linVel0 = math.dot(linVel, dir0);
                            float linVel1 = math.dot(linVel, dir1);

                            float angVelProj = math.dot(angVel, contactJacobian.BaseJacobian.Normal);

                            jacHeader.SurfaceVelocity = new SurfaceVelocity {
                                ExtraFrictionDv = new float3(linVel0, linVel1, angVelProj)
                            };
                        }
 // Enqueue a callback to run during scheduling of the next simulation step
 public void EnqueueCallback(SimulationCallbacks.Phase phase, SimulationCallbacks.Callback callback, JobHandle dependency = default) => m_Stepper.EnqueueCallback(phase, callback, dependency);
Пример #26
0
 // Enqueue a callback to run during scheduling of the next simulation step
 public void EnqueueCallback(SimulationCallbacks.Phase phase, SimulationCallbacks.Callback callback)
 {
     m_Callbacks.Enqueue(phase, callback);
 }