Skip to content

Commit

Permalink
Updated UnityPhysicsSamples
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv-unity committed Dec 4, 2019
1 parent b11e889 commit c1744f4
Show file tree
Hide file tree
Showing 111 changed files with 33,169 additions and 7,933 deletions.
12 changes: 10 additions & 2 deletions UnityPhysicsSamples/Assets/Common/LWRP_Asset.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: bf2edee5c58d82540a51f03df9d42094, type: 3}
m_Name: LWRP_Asset
m_EditorClassIdentifier:
k_AssetVersion: 4
k_AssetVersion: 5
k_AssetPreviousVersion: 5
m_RendererType: 1
m_RendererData: {fileID: 0}
m_RendererDataList:
- {fileID: 11400000, guid: b2a8e3eb6ed8c42dfa125cd7d9683a49, type: 2}
m_DefaultRendererIndex: 0
m_RequireDepthTexture: 0
m_RequireOpaqueTexture: 0
m_OpaqueDownsampling: 1
Expand All @@ -36,10 +42,12 @@ MonoBehaviour:
m_UseSRPBatcher: 0
m_SupportsDynamicBatching: 1
m_MixedLightingSupported: 1
m_DebugLevel: 0
m_ColorGradingMode: 0
m_ColorGradingLutSize: 32
m_ShadowType: 1
m_LocalShadowsSupported: 1
m_LocalShadowsAtlasResolution: 512
m_MaxPixelLights: 4
m_ShadowAtlasResolution: 2048
m_ResourcesAsset: {fileID: 11400000, guid: aac5a08c32552a14c89394b703f1978a, type: 2}
m_ShaderVariantLogLevel: 0
4 changes: 2 additions & 2 deletions UnityPhysicsSamples/Assets/Common/Materials/Colorful.mat
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Material:
m_PrefabAsset: {fileID: 0}
m_Name: Colorful
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_ShaderKeywords:
m_ShaderKeywords: _SPECULARHIGHLIGHTS_OFF
m_LightmapFlags: 4
m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0
Expand Down Expand Up @@ -84,7 +84,7 @@ Material:
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SpecularHighlights: 0
- _SrcBlend: 1
- _Surface: 0
- _UVSec: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: DebugMaterial
m_Shader: {fileID: 4800000, guid: 284c017caead21c4185658d8d466797c, type: 3}
m_ShaderKeywords:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-1337605801007312193
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 1
--- !u!21 &2100000
Material:
serializedVersion: 6
Expand All @@ -8,17 +21,22 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PhysicsDynamicMaterial
m_Shader: {fileID: 4800000, guid: 72f25d9b45958174bbd2076cbff11af1, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_ShaderKeywords: _EMISSION _SPECULARHIGHLIGHTS_OFF
m_LightmapFlags: 2
m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
m_CustomRenderQueue: 2050
stringTagMap:
RenderType: Opaque
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BaseTexture:
m_Texture: {fileID: 2800000, guid: 24228c76bdb8f9f4d87f468ba127e71d, type: 3}
m_Scale: {x: 1, y: 1}
Expand Down Expand Up @@ -89,16 +107,24 @@ Material:
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossinessSource: 0
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Scale: 1
- _Shininess: 0
- _Smoothness: 0
- _SmoothnessSource: 1
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SpecSource: 0
- _SpecularHighlights: 0
- _Spread: 0.8
- _SrcBlend: 1
- _Surface: 0
Expand All @@ -110,12 +136,12 @@ Material:
- Color_4F18FDD0: {r: 0, g: 0, b: 0, a: 0}
- Color_AC52ADAA: {r: 0.5943396, g: 0.5376669, b: 0.08130119, a: 0}
- _BandColor: {r: 0.9921569, g: 0.7215686, b: 0.07450981, a: 0}
- _BaseColor: {r: 0.084905684, g: 0.081480905, b: 0.07329123, a: 0}
- _BaseColor: {r: 0.92156863, g: 0.7137255, b: 0.19215667, a: 0}
- _BaseColour: {r: 1, g: 1, b: 1, a: 1}
- _CellColorA: {r: 1, g: 1, b: 1, a: 1}
- _CellColorB: {r: 0.8, g: 0.8, b: 0.8, a: 1}
- _Color: {r: 0.92156863, g: 0.7137255, b: 0.19215687, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Color: {r: 0.92156863, g: 0.7137255, b: 0.19215682, a: 1}
- _EmissionColor: {r: 0.23529412, g: 0.003921569, b: 0, a: 1}
- _MainLineColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
- _SubLineColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-1300450000288821443
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 1
--- !u!21 &2100000
Material:
serializedVersion: 6
Expand All @@ -8,17 +21,22 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PhysicsKinematicMaterial
m_Shader: {fileID: 4800000, guid: 72f25d9b45958174bbd2076cbff11af1, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_ShaderKeywords: _EMISSION _SPECULARHIGHLIGHTS_OFF
m_LightmapFlags: 2
m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
m_CustomRenderQueue: 2050
stringTagMap:
RenderType: Opaque
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
Expand Down Expand Up @@ -73,14 +91,18 @@ Material:
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SpecularHighlights: 0
- _Spread: 0.8
- _SrcBlend: 1
- _Surface: 0
Expand All @@ -91,7 +113,7 @@ Material:
- Color_4F18FDD0: {r: 0.6627451, g: 0.05882353, b: 0.56078434, a: 0}
- Color_AC52ADAA: {r: 0.39626288, g: 0.12482201, b: 0.4811321, a: 0}
- _BandColor: {r: 0.65882355, g: 0.058823533, b: 0.56078434, a: 0}
- _BaseColor: {r: 0.13725491, g: 0.13333334, b: 0.12941177, a: 0}
- _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0.005882353, b: 0.34509805, a: 1}
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PhysicsStaticMaterial
m_Shader: {fileID: 4800000, guid: 284c017caead21c4185658d8d466797c, type: 3}
m_Shader: {fileID: -6465566751694194690, guid: 284c017caead21c4185658d8d466797c,
type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PhysicsStaticTerrainMaterial
m_Shader: {fileID: 4800000, guid: 284c017caead21c4185658d8d466797c, type: 3}
m_Shader: {fileID: -6465566751694194690, guid: 284c017caead21c4185658d8d466797c,
type: 3}
m_ShaderKeywords: _TOPDOWN_ON
m_LightmapFlags: 4
m_EnableInstancingVariants: 1
Expand Down
55 changes: 28 additions & 27 deletions UnityPhysicsSamples/Assets/Common/Scripts/BasePhysicsDemo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Physics;
using Unity.Physics.Extensions;
using System.Reflection;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Physics.Extensions;
using Unity.Rendering;
using Unity.Transforms;
using UnityEngine;
Expand All @@ -16,17 +18,7 @@
/// </summary>
public class BasePhysicsDemo : MonoBehaviour
{
public static World DefaultWorld
{
get
{
#if UNITY_ENTITIES_0_2_0_OR_NEWER
return World.DefaultGameObjectInjectionWorld;
#else
return World.Active;
#endif
}
}
public static World DefaultWorld => World.DefaultGameObjectInjectionWorld;

protected Entity stepper;

Expand Down Expand Up @@ -78,7 +70,19 @@ protected virtual void Start()
// Object creation
//

private Entity CreateBody(float3 position, quaternion orientation, BlobAssetReference<Collider> collider,
// TODO: add proper utility APIs for converting Collider into buffers usable for UnityEngine.Mesh and for drawing lines
static readonly Type k_DrawComponent = typeof(Unity.Physics.Authoring.DisplayBodyColliders)
.GetNestedType("DrawComponent", BindingFlags.NonPublic);

static readonly MethodInfo k_DrawComponent_BuildDebugDisplayMesh = k_DrawComponent
.GetMethod("BuildDebugDisplayMesh", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { typeof(BlobAssetReference<Collider>) }, null);

static readonly Type k_DisplayResult = k_DrawComponent.GetNestedType("DisplayResult");

static readonly FieldInfo k_DisplayResultsMesh = k_DisplayResult.GetField("Mesh");
static readonly PropertyInfo k_DisplayResultsTransform = k_DisplayResult.GetProperty("Transform");

Entity CreateBody(float3 position, quaternion orientation, BlobAssetReference<Collider> collider,
float3 linearVelocity, float3 angularVelocity, float mass, bool isDynamic)
{
var entityManager = DefaultWorld.EntityManager;
Expand All @@ -92,24 +96,21 @@ private Entity CreateBody(float3 position, quaternion orientation, BlobAssetRefe
var colliderComponent = new PhysicsCollider { Value = collider };
entityManager.AddComponentData(entity, colliderComponent);

Mesh mesh = new Mesh();
#pragma warning disable 618
List<Unity.Physics.Authoring.DisplayBodyColliders.DrawComponent.DisplayResult> meshes;
unsafe { meshes = Unity.Physics.Authoring.DisplayBodyColliders.DrawComponent.BuildDebugDisplayMesh(colliderComponent.ColliderPtr); }
#pragma warning restore 618
CombineInstance[] instances = new CombineInstance[meshes.Count];
int numVertices = 0;
for (int i = 0; i < meshes.Count; i++)
var mesh = new Mesh();
var instances = new List<CombineInstance>(8);
var numVertices = 0;
foreach (var displayResult in (IEnumerable)k_DrawComponent_BuildDebugDisplayMesh.Invoke(null, new object[] { collider }))
{
instances[i] = new CombineInstance
var instance = new CombineInstance
{
mesh = meshes[i].Mesh,
transform = Matrix4x4.TRS(meshes[i].Position, meshes[i].Orientation, meshes[i].Scale)
mesh = k_DisplayResultsMesh.GetValue(displayResult) as Mesh,
transform = (float4x4)k_DisplayResultsTransform.GetValue(displayResult)
};
numVertices += meshes[i].Mesh.vertexCount;
instances.Add(instance);
numVertices += mesh.vertexCount;
}
mesh.indexFormat = numVertices > UInt16.MaxValue ? UnityEngine.Rendering.IndexFormat.UInt32 : UnityEngine.Rendering.IndexFormat.UInt16;
mesh.CombineMeshes(instances);
mesh.CombineMeshes(instances.ToArray());

entityManager.AddSharedComponentData(entity, new RenderMesh
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ protected override JobHandle OnUpdate(JobHandle inputDeps)

const float elasticity = 0.1f;
const float damping = 0.5f;
deltaVelocity = -pointDiff * (elasticity / Time.fixedDeltaTime) - damping * relativeVelocityInWorld;
deltaVelocity = -pointDiff * (elasticity / UnityEngine.Time.fixedDeltaTime) - damping * relativeVelocityInWorld;
}

// Build effective mass matrix in world space
Expand Down Expand Up @@ -374,7 +374,7 @@ protected override JobHandle OnUpdate(JobHandle inputDeps)

// Clip the impulse
const float maxAcceleration = 250.0f;
float maxImpulse = math.rcp(massComponent.InverseMass) * Time.fixedDeltaTime * maxAcceleration;
float maxImpulse = math.rcp(massComponent.InverseMass) * UnityEngine.Time.fixedDeltaTime * maxAcceleration;
impulse *= math.min(1.0f, math.sqrt((maxImpulse * maxImpulse) / math.lengthsq(impulse)));

// Apply the impulse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Burst;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
Expand Down Expand Up @@ -94,11 +92,11 @@ protected override JobHandle OnUpdate(JobHandle inputDeps)

var physicsStep = m_PhysicsGroup.GetSingleton<PhysicsStep>();

var job = new RandomMotionJob()
var job = new RandomMotionJob
{
gravity = physicsStep.Gravity,
deltaTime = Time.fixedDeltaTime,
random = random,
deltaTime = UnityEngine.Time.fixedDeltaTime,
random = random
};
var jobHandle = job.Schedule(this, inputDeps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void Update()

if (ExpectingResults)
{
BlockStream.Reader reader = lastResults.PixelData;
NativeStream.Reader reader = lastResults.PixelData.AsReader();
for (int i = 0; i < lastResults.PixelData.ForEachCount; i++)
{
reader.BeginForEachIndex(i);
Expand Down
Loading

0 comments on commit c1744f4

Please sign in to comment.