Skip to content

Commit

Permalink
UnityPhysicsExamples
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikPoulsen committed Apr 11, 2019
1 parent 7010542 commit fc601f9
Show file tree
Hide file tree
Showing 40 changed files with 435 additions and 718 deletions.
102 changes: 0 additions & 102 deletions HACKING.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,31 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b275e5f92732148048d7b77e264ac30e, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ShapeType: 30
m_ShapeType: 3
m_PrimitiveCenter:
x: 0.000000059604645
y: 0
z: -0.00000008940697
m_PrimitiveSize:
x: 2
y: 0
z: 1.0000002
x: 1.0000002
y: 1.0000002
z: 2
m_PrimitiveOrientation:
Value:
x: 0
x: 90
y: 0
z: 0
RotationOrder: 4
m_Capsule:
Height: 2
Radius: 0.5000001
Axis: 0
Axis: 2
m_Cylinder:
Height: 0
Radius: 1
Axis: 1
Height: 2
Radius: 0.5000001
Axis: 2
m_SphereRadius: 1
m_ConvexRadius: 0
m_ConvexRadius: 0.05
m_CustomMesh: {fileID: 0}
m_Material:
m_SupportsTemplate: 1
Expand Down Expand Up @@ -179,11 +179,11 @@ MonoBehaviour:
y: 0
z: 0
m_Orientation:
value:
Value:
x: 0
y: 0
z: 0
w: 1
RotationOrder: 4
m_InertiaTensor:
x: 0.4
y: 0.4
Expand Down
4 changes: 2 additions & 2 deletions UnityPhysicsExamples/Assets/Common/Scripts/BasePhysicsDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// </summary>
public class BasePhysicsDemo : MonoBehaviour
{
public static EntityManager EntityManager => World.Active.GetOrCreateManager<EntityManager>();
public static EntityManager EntityManager => World.Active.EntityManager;
protected Entity stepper;

public Material dynamicMaterial;
Expand Down Expand Up @@ -131,7 +131,7 @@ protected Entity CreateDynamicBody(float3 position, quaternion orientation, Blob

protected unsafe Entity CreateJoint(BlobAssetReference<JointData> jointData, Entity entityA, Entity entityB, bool enableCollision = false)
{
EntityManager entityManager = World.Active.GetOrCreateManager<EntityManager>();
EntityManager entityManager = World.Active.EntityManager;
ComponentType[] componentTypes = new ComponentType[1];
componentTypes[0] = typeof(PhysicsJoint);
Entity jointEntity = entityManager.CreateEntity(componentTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void LateUpdate()
newPositionTo = LookTo.transform.position;
}

PhysicsWorld world = World.Active.GetExistingManager<BuildPhysicsWorld>().PhysicsWorld;
PhysicsWorld world = World.Active.GetExistingSystem<BuildPhysicsWorld>().PhysicsWorld;
// check barrier
{
var rayInput = new RaycastInput
Expand All @@ -66,7 +66,7 @@ void LateUpdate()
if (Target != null)
{
// add velocity
var em = World.Active.GetOrCreateManager<EntityManager>();
var em = World.Active.EntityManager;
var e = Target.GetComponent<GameObjectEntity>();
if ((em != null) && (e != null) && (e.Entity != Entity.Null))
{
Expand All @@ -83,7 +83,7 @@ void LateUpdate()
Vector3 newForward = newPositionTo - newPositionFrom;
newForward.Normalize();
Quaternion newRotation = Quaternion.LookRotation(newForward, Vector3.up);

gameObject.transform.SetPositionAndRotation(newPositionFrom, newRotation);
oldPositionTo = newPositionTo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MousePickSystem : JobComponentSystem
{
const float k_MaxDistance = 100.0f;

ComponentGroup m_MouseGroup;
EntityQuery m_MouseGroup;
BuildPhysicsWorld m_BuildPhysicsWorldSystem;

public NativeArray<SpringData> SpringDatas;
Expand Down Expand Up @@ -96,10 +96,10 @@ public MousePickSystem()
SpringDatas[0] = new SpringData();
}

protected override void OnCreateManager()
protected override void OnCreate()
{
m_BuildPhysicsWorldSystem = World.GetOrCreateManager<BuildPhysicsWorld>();
m_MouseGroup = GetComponentGroup(new EntityArchetypeQuery
m_BuildPhysicsWorldSystem = World.GetOrCreateSystem<BuildPhysicsWorld>();
m_MouseGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[] { typeof(MousePick) }
});
Expand Down Expand Up @@ -155,13 +155,13 @@ protected override JobHandle OnUpdate(JobHandle inputDeps)
[UpdateBefore(typeof(BuildPhysicsWorld))]
public class MouseSpringSystem : JobComponentSystem
{
ComponentGroup m_MouseGroup;
EntityQuery m_MouseGroup;
MousePickSystem m_PickSystem;

protected override void OnCreateManager()
protected override void OnCreate()
{
m_PickSystem = World.GetOrCreateManager<MousePickSystem>();
m_MouseGroup = GetComponentGroup(new EntityArchetypeQuery
m_PickSystem = World.GetOrCreateSystem<MousePickSystem>();
m_MouseGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[] { typeof(MousePick) }
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void Update()
return;
}

RayTracerSystem rbs = Entities.World.Active.GetExistingManager<RayTracerSystem>();
RayTracerSystem rbs = Entities.World.Active.GetExistingSystem<RayTracerSystem>();
if (rbs == null || !rbs.IsEnabled)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public unsafe void Execute(int index)

float3 targetImagePlane = Request.ImageCenter + Request.Up * Request.PlaneHalfExtents * yFrac + Request.Right * Request.PlaneHalfExtents * xFrac;
float3 rayDir = Request.RayLength * (Request.PinHole - targetImagePlane);

RaycastHit hit;
bool hasHit;
if (Request.CastSphere)
Expand Down Expand Up @@ -182,13 +182,13 @@ public unsafe void Execute(int index)
}
}

protected override void OnCreateManager()
protected override void OnCreate()
{
m_BuildPhysicsWorldSystem = World.GetOrCreateManager<BuildPhysicsWorld>();
m_BuildPhysicsWorldSystem = World.GetOrCreateSystem<BuildPhysicsWorld>();
m_Requests = new List<RayRequest>();
m_Results = new List<RayResult>();
}

protected override JobHandle OnUpdate(JobHandle inputDeps)
{
if (m_Requests == null || m_Requests.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Unity.Physics.Systems;
using System;
using Unity.Physics.Systems;
using Unity.Collections;
using Unity.Mathematics;
using Unity.Entities;
Expand Down Expand Up @@ -84,6 +85,9 @@ private BlobAssetReference<Collider> CreateCollider(UnityEngine.Mesh mesh, Colli
float3 vertex1 = bounds.center; vertex1[z] = (max - radius);
return CapsuleCollider.Create(vertex0, vertex1, radius);
}
case ColliderType.Cylinder:
// TODO: need someone to add
throw new NotImplementedException();
case ColliderType.Convex:
{
NativeArray<float3> points = new NativeArray<float3>(mesh.vertices.Length, Allocator.Temp);
Expand Down Expand Up @@ -130,7 +134,7 @@ void OnDestroy()

void RunQueries()
{
ref PhysicsWorld world = ref Entities.World.Active.GetExistingManager<BuildPhysicsWorld>().PhysicsWorld;
ref PhysicsWorld world = ref Entities.World.Active.GetExistingSystem<BuildPhysicsWorld>().PhysicsWorld;

float3 origin = transform.position;
float3 direction = (transform.rotation * Direction) * Distance;
Expand Down Expand Up @@ -243,7 +247,7 @@ void OnDrawGizmos()
{
RunQueries();

ref PhysicsWorld world = ref Entities.World.Active.GetExistingManager<BuildPhysicsWorld>().PhysicsWorld;
ref PhysicsWorld world = ref Entities.World.Active.GetExistingSystem<BuildPhysicsWorld>().PhysicsWorld;

// Draw the query
Gizmos.color = new Color(0.94f, 0.35f, 0.15f, 0.75f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ void IConvertGameObjectToEntity.Convert(Entity entity, EntityManager dstManager,
[UpdateBefore(typeof(StepPhysicsWorld))]
public class AddContactsSystem : JobComponentSystem
{
ComponentGroup m_ContactAdderGroup;
EntityQuery m_ContactAdderGroup;

BuildPhysicsWorld m_BuildPhysicsWorldSystem;
StepPhysicsWorld m_StepPhysicsWorld;

protected override void OnCreateManager()
protected override void OnCreate()
{
m_BuildPhysicsWorldSystem = World.GetOrCreateManager<BuildPhysicsWorld>();
m_StepPhysicsWorld = World.GetOrCreateManager<StepPhysicsWorld>();
m_BuildPhysicsWorldSystem = World.GetOrCreateSystem<BuildPhysicsWorld>();
m_StepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();

m_ContactAdderGroup = GetComponentGroup(new EntityArchetypeQuery
m_ContactAdderGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[] { typeof(AddNarrowphaseContacts) }
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class LinearDashpotBehaviour : MonoBehaviour, IConvertGameObjectToEntity
{
public PhysicsBody parentBody;
public float3 parentOffset;
public float3 localOffset;
public float3 localOffset;

public bool dontApplyImpulseToParent = false;
public float strength;
Expand Down Expand Up @@ -76,9 +76,9 @@ public class LinearDashpotSystem : ComponentSystem
{
BuildPhysicsWorld m_BuildPhysicsWorldSystem;

protected override void OnCreateManager()
protected override void OnCreate()
{
m_BuildPhysicsWorldSystem = World.GetOrCreateManager<BuildPhysicsWorld>();
m_BuildPhysicsWorldSystem = World.GetOrCreateSystem<BuildPhysicsWorld>();
}

protected override void OnUpdate()
Expand All @@ -98,7 +98,7 @@ protected override void OnUpdate()
// Find the rigid bodies in the physics world
int rbAIdx = world.GetRigidBodyIndex(eA);
int rbBIdx = world.GetRigidBodyIndex(eB);
int rbBIdx = world.GetRigidBodyIndex(eB);
// Calculate and apply the impulses
RigidBody rbA = rbAIdx >= 0 ? world.Bodies[rbAIdx] : RigidBody.Zero;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ void IConvertGameObjectToEntity.Convert(Entity entity, EntityManager dstManager,
[UpdateBefore(typeof(StepPhysicsWorld))]
public class ModifyBroadphasePairsSystem : JobComponentSystem
{
ComponentGroup m_PairModifierGroup;
EntityQuery m_PairModifierGroup;

BuildPhysicsWorld m_PhysicsWorld;
StepPhysicsWorld m_StepPhysicsWorld;

protected override void OnCreateManager()
protected override void OnCreate()
{
m_PhysicsWorld = World.GetOrCreateManager<BuildPhysicsWorld>();
m_StepPhysicsWorld = World.GetOrCreateManager<StepPhysicsWorld>();
m_PhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
m_StepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();

m_PairModifierGroup = GetComponentGroup(new EntityArchetypeQuery
m_PairModifierGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[] { typeof(ModifyBroadphasePairs) }
});
Expand Down
Loading

0 comments on commit fc601f9

Please sign in to comment.