: SubComponent| _collidersDirty = value; }
[NonSerialized] private Mesh _transformedColliderMesh;
- [NonSerialized] private Mesh _transformedKinematicColliderMesh;
[NonSerialized] private Mesh _untransformedColliderMesh;
- [NonSerialized] private Mesh _untransformedKinematicColliderMesh;
[NonSerialized] private Aabb[] _aabbs;
[NonSerialized] private readonly List _nonMeshColliders = new List();
@@ -85,12 +83,11 @@ public virtual float4x4 GetLocalToPlayfieldMatrixInVpx(float4x4 worldToPlayfield
public float4x4 GetUnmodifiedLocalToPlayfieldMatrixInVpx(float4x4 worldToPlayfield)
=> Physics.GetLocalToPlayfieldMatrixInVpx(MainComponent.transform.localToWorldMatrix, worldToPlayfield);
- private bool HasCachedColliders => false;// _colliderMesh != null && !_collidersDirty;
+ private bool HasCachedColliders => !_collidersDirty && (_transformedColliderMesh != null ||_untransformedColliderMesh != null);
private void Start()
{
_transformedColliderMesh = null;
- _transformedKinematicColliderMesh = null;
_untransformedColliderMesh = null;
_collidersDirty = true;
// make enable checkbox visible
@@ -173,9 +170,9 @@ public virtual void OnTransformationChanged(float4x4 currTransformationMatrix)
#if UNITY_EDITOR
private Player _player;
- private NativeOctree _octree = default;
+ private NativeOctree _octree;
- private void OnDrawGizmos()
+ private void OnDrawGizmosSelected()
{
if (!_player) {
_player = GetComponentInParent();
@@ -183,6 +180,10 @@ private void OnDrawGizmos()
return;
}
}
+ var playfieldComponent = GetComponentInParent();
+ if (!playfieldComponent) {
+ return;
+ }
Profiler.BeginSample("ItemColliderComponent.OnDrawGizmosSelected");
@@ -202,18 +203,18 @@ private void OnDrawGizmos()
return;
}
- var playfieldToWorld = GetComponentInParent().transform.localToWorldMatrix;
- var worldToPlayfield = GetComponentInParent().transform.worldToLocalMatrix;
+ var playfieldToWorld = playfieldComponent.transform.localToWorldMatrix;
+ var worldToPlayfield = playfieldComponent.transform.worldToLocalMatrix;
var localToPlayfieldMatrixInVpx = GetLocalToPlayfieldMatrixInVpx(worldToPlayfield);
var unmodifiedLocalToPlayfieldMatrixInVpx = GetUnmodifiedLocalToPlayfieldMatrixInVpx(worldToPlayfield);
var nonTransformableColliderTransforms = new NativeParallelHashMap(0, Allocator.Temp);
- var generateColliders = ShowAabbs || showColliders && !HasCachedColliders || ShowColliderOctree;
+ var generateColliders = !HasCachedColliders && (ShowAabbs || showColliders || ShowColliderOctree);
if (generateColliders) {
if (Application.isPlaying) {
InstantiateRuntimeColliders(showColliders);
} else {
- InstantiateEditorColliders(showColliders, ref nonTransformableColliderTransforms, localToPlayfieldMatrixInVpx);
+ InstantiateEditorColliders(showColliders, ref nonTransformableColliderTransforms);
}
}
@@ -225,36 +226,43 @@ private void OnDrawGizmos()
var colliderEnabled = !Application.isPlaying || PhysicsEngine.IsColliderEnabled(MainComponent.gameObject.GetInstanceID());
- if (_untransformedColliderMesh || _untransformedKinematicColliderMesh) {
+ if (_untransformedColliderMesh) {
Gizmos.matrix = playfieldToWorld * (Matrix4x4)Physics.VpxToWorld * (Matrix4x4)unmodifiedLocalToPlayfieldMatrixInVpx;
if (_untransformedColliderMesh) {
- Gizmos.color = colliderEnabled ? ColliderColor.UntransformedColliderSelected : ColliderColor.DisabledColliderSelected;
+ if (IsKinematic) {
+ Gizmos.color = colliderEnabled ? ColliderColor.UntransformedKineticColliderSelected : ColliderColor.DisabledColliderSelected;
+ } else {
+ Gizmos.color = colliderEnabled ? ColliderColor.UntransformedColliderSelected : ColliderColor.DisabledColliderSelected;
+ }
Gizmos.DrawMesh(_untransformedColliderMesh);
- Gizmos.color = Application.isPlaying ? ColliderColor.UntransformedCollider : white;
+ if (IsKinematic) {
+ Gizmos.color = Application.isPlaying ? ColliderColor.UntransformedKineticCollider : white;
+ } else {
+ Gizmos.color = Application.isPlaying ? ColliderColor.UntransformedCollider : white;
+ }
Gizmos.DrawWireMesh(_untransformedColliderMesh);
}
- if (_untransformedKinematicColliderMesh) {
- Gizmos.color = colliderEnabled ? ColliderColor.UntransformedKineticColliderSelected : ColliderColor.DisabledColliderSelected;
- Gizmos.DrawMesh(_untransformedKinematicColliderMesh);
- Gizmos.color = Application.isPlaying ? ColliderColor.UntransformedKineticCollider : white;
- Gizmos.DrawWireMesh(_untransformedKinematicColliderMesh);
- }
}
- if (_transformedColliderMesh || _transformedKinematicColliderMesh) {
- Gizmos.matrix = playfieldToWorld * (Matrix4x4)Physics.VpxToWorld;
+ if (_transformedColliderMesh) {
+ Gizmos.matrix = Application.isPlaying
+ ? playfieldToWorld * (Matrix4x4)Physics.VpxToWorld
+ : playfieldToWorld * (Matrix4x4)Physics.VpxToWorld * (Matrix4x4)localToPlayfieldMatrixInVpx;
+ //Gizmos.matrix = MainComponent.transform.localToWorldMatrix * playfieldToWorld * (Matrix4x4)Physics.VpxToWorld;
if (_transformedColliderMesh) {
- Gizmos.color = colliderEnabled ? ColliderColor.TransformedColliderSelected : ColliderColor.DisabledColliderSelected;
+ if (IsKinematic) {
+ Gizmos.color = colliderEnabled ? ColliderColor.TransformedKineticColliderSelected : ColliderColor.DisabledColliderSelected;
+ } else {
+ Gizmos.color = colliderEnabled ? ColliderColor.TransformedColliderSelected : ColliderColor.DisabledColliderSelected;
+ }
Gizmos.DrawMesh(_transformedColliderMesh);
- Gizmos.color = Application.isPlaying ? ColliderColor.TransformedCollider : white;
+ if (IsKinematic) {
+ Gizmos.color = Application.isPlaying ? ColliderColor.TransformedKineticCollider : white;
+ } else {
+ Gizmos.color = Application.isPlaying ? ColliderColor.TransformedCollider : white;
+ }
Gizmos.DrawWireMesh(_transformedColliderMesh);
}
- if (_transformedKinematicColliderMesh) {
- Gizmos.color = colliderEnabled ? ColliderColor.TransformedKineticColliderSelected : ColliderColor.DisabledColliderSelected;
- Gizmos.DrawMesh(_transformedKinematicColliderMesh);
- Gizmos.color = Application.isPlaying ? ColliderColor.TransformedKineticCollider : white;
- Gizmos.DrawWireMesh(_transformedKinematicColliderMesh);
- }
}
DrawNonMeshColliders();
}
@@ -292,19 +300,8 @@ private void InstantiateRuntimeColliders(bool showColliders)
? PhysicsEngine.GetKinematicColliders(MainComponent.gameObject.GetInstanceID())
: PhysicsEngine.GetColliders(MainComponent.gameObject.GetInstanceID());
- if (IsKinematic) {
- _transformedColliderMesh = null;
- _untransformedColliderMesh = null;
- if (showColliders) {
- GenerateColliderMesh(colliders, out _transformedKinematicColliderMesh, out _untransformedKinematicColliderMesh);
- }
-
- } else {
- _transformedKinematicColliderMesh = null;
- _untransformedKinematicColliderMesh = null;
- if (showColliders) {
- GenerateColliderMesh(colliders, out _transformedColliderMesh, out _untransformedColliderMesh);
- }
+ if (showColliders) {
+ GenerateColliderMesh(colliders, out _transformedColliderMesh, out _untransformedColliderMesh);
}
if (ShowAabbs) {
@@ -319,23 +316,15 @@ private void InstantiateRuntimeColliders(bool showColliders)
}
}
- private void InstantiateEditorColliders(bool showColliders, ref NativeParallelHashMap nonTransformableColliderTransforms, float4x4 localToPlayfieldMatrixInVpx)
+ private void InstantiateEditorColliders(bool showColliders, ref NativeParallelHashMap nonTransformableColliderTransforms)
{
var api = InstantiateColliderApi(_player, PhysicsEngine);
var colliders = new ColliderReference(ref nonTransformableColliderTransforms, Allocator.Temp, IsKinematic);
try {
- api.CreateColliders(ref colliders, localToPlayfieldMatrixInVpx, 0.1f);
+ api.CreateColliders(ref colliders, float4x4.identity, 0.1f);
if (showColliders) {
- if (IsKinematic) {
- _transformedColliderMesh = null;
- _untransformedColliderMesh = null;
- GenerateColliderMesh(ref colliders, out _transformedKinematicColliderMesh, out _untransformedKinematicColliderMesh);
- } else {
- _transformedKinematicColliderMesh = null;
- _untransformedKinematicColliderMesh = null;
- GenerateColliderMesh(ref colliders, out _transformedColliderMesh, out _untransformedColliderMesh);
- }
+ GenerateColliderMesh(ref colliders, out _transformedColliderMesh, out _untransformedColliderMesh);
_collidersDirty = false;
}
@@ -385,7 +374,7 @@ private void GenerateColliderMesh(ref ColliderReference colliders, out Mesh tran
}
foreach (var col in colliders.FlipperColliders) {
if (col.Header.IsTransformed) {
- AddFlipperCollider(vertices, normals, indices, Origin.Global);
+ AddFlipperCollider(vertices, normals, indices, Origin.Original);
} else {
AddFlipperCollider(verticesNonTransformable, normalsNonTransformable, indicesNonTransformable, Origin.Original);
}
@@ -593,6 +582,13 @@ private void GenerateColliderMesh(IEnumerable colliders, out Mesh tra
private void DrawNonMeshColliders()
{
+ var playfieldComponent = GetComponentInParent();
+ var playfieldToWorld = playfieldComponent.transform.localToWorldMatrix;
+ var worldToPlayfield = playfieldComponent.transform.worldToLocalMatrix;
+ var localToPlayfieldMatrixInVpx = GetLocalToPlayfieldMatrixInVpx(worldToPlayfield);
+ Handles.matrix = Application.isPlaying
+ ? playfieldToWorld * (Matrix4x4)Physics.VpxToWorld
+ : playfieldToWorld * (Matrix4x4)Physics.VpxToWorld * (Matrix4x4)localToPlayfieldMatrixInVpx;
foreach (var col in _nonMeshColliders) {
switch (col) {
case LineZCollider lineZCol: {
@@ -775,10 +771,8 @@ private static void DrawAabb(Aabb aabb, bool isSelected)
#endregion
- void ICollidableComponent.GetColliders(Player player, PhysicsEngine physicsEngine, ref ColliderReference colliders,
- float4x4 translateWithinPlayfieldMatrix, float margin)
- => InstantiateColliderApi(player, physicsEngine)
- .CreateColliders(ref colliders, translateWithinPlayfieldMatrix, margin);
+ void ICollidableComponent.GetColliders(Player player, PhysicsEngine physicsEngine, ref ColliderReference colliders, float4x4 translateWithinPlayfieldMatrix, float margin)
+ => InstantiateColliderApi(player, physicsEngine).CreateColliders(ref colliders, translateWithinPlayfieldMatrix, margin);
int ICollidableComponent.ItemId => MainComponent.gameObject.GetInstanceID();
bool ICollidableComponent.IsCollidable => isActiveAndEnabled;
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperApi.cs
index cacd5d335..3330f9f98 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperApi.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperApi.cs
@@ -241,6 +241,11 @@ protected override void CreateColliders(ref ColliderReference colliders, float4x
),
translateWithinPlayfieldMatrix
);
+ if (ColliderComponent.FlipperCorrection != null && PhysicsEngine != null) {
+ ref var correctionTriggerState = ref PhysicsEngine.TriggerState(ColliderComponent.TriggerItemId);
+ correctionTriggerState.FlipperCorrection.FlipperColliderId = ColliderId;
+ }
+
}
#endregion
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperColliderComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperColliderComponent.cs
index 7e72c518b..5c0d71a96 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperColliderComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperColliderComponent.cs
@@ -75,6 +75,8 @@ public class FlipperColliderComponent : ColliderComponent();
var triggerCollider = go.AddComponent();
+ colliderComponent.TriggerItemId = go.GetInstanceID();
triggerCollider.ForFlipper = this;
triggerCollider.TimeThresholdMs = fc.TimeThresholdMs;
@@ -657,12 +658,16 @@ private void SetupFlipperCorrection(FlipperColliderComponent colliderComponent)
// but I couldn't get this transformation correctly from our current transforms.
// using Matrix4x4.Rotate(quaternion.Euler(new float3(0, 0, -StartAngle))) and transforming
// to localPos was close, but not close enough.
- var flipperToPlayfield = new Matrix4x4(
- new Vector4(-0.50754f, 0.86163f, 0, 0),
- new Vector4(-0.86163f, -0.50754f, 0, 0),
- new Vector4(0, 0, 1f, 0),
- new Vector4(278.21380f, 1803.27200f, 0, 1f)
- );
+ //
+ // var flipperToPlayfield = new Matrix4x4(
+ // new Vector4(-0.50754f, 0.86163f, 0, 0),
+ // new Vector4(-0.86163f, -0.50754f, 0, 0),
+ // new Vector4(0, 0, 1f, 0),
+ // new Vector4(278.21380f, 1803.27200f, 0, 1f)
+ // );
+
+ // UPDATE: just rotating the points by the start angle seems to work fine.
+ var flipperToPlayfield = Matrix4x4.Rotate(Quaternion.Euler(0, 0, StartAngle));
for (var i = 0; i < poly.Count; i++) {
// Poly points are expressed in flipper's frame: rotate to get it to the correct position.
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperCorrectionState.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperCorrectionState.cs
index 83cefa31f..0682b9f16 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperCorrectionState.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Flipper/FlipperCorrectionState.cs
@@ -23,8 +23,8 @@ namespace VisualPinball.Unity
{
public unsafe struct FlipperCorrectionState : IDisposable
{
+ public int FlipperColliderId;
public readonly bool IsEnabled;
- public readonly int FlipperColliderId;
public readonly int FlipperItemId;
public readonly uint TimeDelayMs;
@@ -34,11 +34,11 @@ public unsafe struct FlipperCorrectionState : IDisposable
private readonly int _numPolarities;
private readonly int _numVelocities;
- public FlipperCorrectionState(bool isEnabled, int flipperItemId, int flipperColliderId, uint timeDelayMs, float2[] polarities, float2[] velocities, Allocator allocator)
+ public FlipperCorrectionState(bool isEnabled, int flipperItemId, uint timeDelayMs, float2[] polarities, float2[] velocities, Allocator allocator)
{
IsEnabled = isEnabled;
FlipperItemId = flipperItemId;
- FlipperColliderId = flipperColliderId;
+ FlipperColliderId = 0;
TimeDelayMs = timeDelayMs;
_polarities = Allocate(polarities, allocator);
_velocities = Allocate(velocities, allocator);
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/HitTargetColliderComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/HitTargetColliderComponent.cs
index 9a78f3a5d..32b3f5824 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/HitTargetColliderComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/HitTargetColliderComponent.cs
@@ -102,9 +102,6 @@ public override bool PhysicsOverwrite {
protected override IApiColliderGenerator InstantiateColliderApi(Player player, PhysicsEngine physicsEngine)
=> (MainComponent as HitTargetComponent)?.HitTargetApi ?? new HitTargetApi(gameObject, player, physicsEngine);
- public override float4x4 GetLocalToPlayfieldMatrixInVpx(float4x4 worldToPlayfield)
- => base.GetLocalToPlayfieldMatrixInVpx(worldToPlayfield).TransformToVpx();
-
public int NumColliderMeshes => 1;
public Mesh GetColliderMesh(int index) => FrontColliderMesh; // there's only one
}
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/MeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/MeshComponent.cs
index 8b6b7cbe8..c1496fe41 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/MeshComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/MeshComponent.cs
@@ -55,6 +55,10 @@ private void OnDisable()
#endregion
+#if UNITY_EDITOR
+ [SerializeField] private Vector2 _playfieldDimensions = Vector2.zero;
+#endif
+
public virtual void RebuildMeshes()
{
UpdateMesh();
@@ -78,6 +82,27 @@ public void ClearMeshVertices()
protected abstract PbrMaterial GetMaterial(TData data, Table table);
+
+ protected Vector2 GetPlayfieldDimensions()
+ {
+ var playfieldComponent = GetComponentInParent();
+ // ReSharper disable once RedundantAssignment
+ var playfieldDimensions = Vector2.zero;
+
+#if UNITY_EDITOR
+ if (playfieldComponent) {
+ _playfieldDimensions = new Vector2(playfieldComponent.Width, playfieldComponent.Height);
+ }
+ playfieldDimensions = _playfieldDimensions;
+#endif
+
+ if (playfieldComponent) {
+ playfieldDimensions = new Vector2(playfieldComponent.Width, playfieldComponent.Height);
+ }
+
+ return playfieldDimensions;
+ }
+
public void CreateMesh(TData data, Table table, ITextureProvider texProvider, IMaterialProvider matProvider)
{
CreateMesh(gameObject, GetMesh(data), GetMaterial(data, table), data.GetName(), texProvider, matProvider);
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldColliderComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldColliderComponent.cs
index cfe39cc19..6c4f2c68d 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldColliderComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Playfield/PlayfieldColliderComponent.cs
@@ -17,7 +17,6 @@
// ReSharper disable InconsistentNaming
using System;
-using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using VisualPinball.Engine.VPT.Table;
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceApi.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceApi.cs
index 8afa97e2a..ca46d79c9 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceApi.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceApi.cs
@@ -53,7 +53,7 @@ protected override void CreateColliders(ref ColliderReference colliders, float4x
if (MainComponent.DragPoints.Length == 0) {
return;
}
- var colliderGenerator = new SurfaceColliderGenerator(this, MainComponent, translateWithinPlayfieldMatrix);
+ var colliderGenerator = new SurfaceColliderGenerator(this, MainComponent, ColliderComponent, translateWithinPlayfieldMatrix);
colliderGenerator.GenerateColliders(ref colliders);
}
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceColliderGenerator.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceColliderGenerator.cs
index 96fc61360..41f2edcdd 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceColliderGenerator.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceColliderGenerator.cs
@@ -25,13 +25,17 @@ namespace VisualPinball.Unity
public class SurfaceColliderGenerator
{
private readonly IApiColliderGenerator _api;
+ private readonly SurfaceComponent _component;
+ private readonly SurfaceColliderComponent _colliderComponent;
private readonly float4x4 _matrix;
private readonly SurfaceMeshGenerator _meshGen;
- public SurfaceColliderGenerator(SurfaceApi surfaceApi, SurfaceComponent component, float4x4 matrix)
+ public SurfaceColliderGenerator(SurfaceApi surfaceApi, SurfaceComponent component, SurfaceColliderComponent colliderComponent, float4x4 matrix)
{
_api = surfaceApi;
_matrix = matrix;
+ _component = component;
+ _colliderComponent = colliderComponent;
var data = new SurfaceData();
component.CopyDataTo(data, null, null, false);
@@ -42,10 +46,70 @@ public SurfaceColliderGenerator(SurfaceApi surfaceApi, SurfaceComponent componen
internal void GenerateColliders(ref ColliderReference colliders)
{
var topMesh = _meshGen.GetMesh(SurfaceMeshGenerator.Top, 0, 0, 0, false);
- var sideMesh = _meshGen.GetMesh(SurfaceMeshGenerator.Side, 0, 0, 0, false);
+ //var sideMesh = _meshGen.GetMesh(SurfaceMeshGenerator.Side, 0, 0, 0, false);
ColliderUtils.GenerateCollidersFromMesh(topMesh, _api.GetColliderInfo(), ref colliders, _matrix);
- ColliderUtils.GenerateCollidersFromMesh(sideMesh, _api.GetColliderInfo(), ref colliders, _matrix);
+ GenerateSideColliders(ref colliders);
+ // ColliderUtils.GenerateCollidersFromMesh(sideMesh, _api.GetColliderInfo(), ref colliders, _matrix);
+ }
+
+ private void GenerateSideColliders(ref ColliderReference colliders, float margin = 0f)
+ {
+ var vVertex = DragPoint.GetRgVertex(_component.DragPoints);
+
+ var count = vVertex.Length;
+ var rgv3Dt = new float3[count];
+ var rgv3Db = _colliderComponent.IsBottomSolid ? new float3[count] : null;
+
+ var bottom = _component.HeightBottom - margin;
+ var top = _component.HeightTop + margin;
+
+ for (var i = 0; i < count; ++i) {
+ var pv1 = vVertex[i];
+ rgv3Dt[i] = new float3(pv1.X, pv1.Y, top);
+
+ if (rgv3Db != null) {
+ rgv3Db[count - 1 - i] = new float3(pv1.X, pv1.Y, bottom);
+ }
+
+ var pv2 = vVertex[(i + 1) % count];
+ var pv3 = vVertex[(i + 2) % count];
+ GenerateLinePolys(pv2, pv3, ref colliders);
+ }
+ }
+
+ ///
+ /// Returns the hit line polygons for the surface.
+ ///
+ private void GenerateLinePolys(RenderVertex2D pv1, Vertex2D pv2, ref ColliderReference colliders)
+ {
+ var bottom = _component.HeightBottom;
+ var top = _component.HeightTop;
+
+ if (!pv1.IsSlingshot) {
+ colliders.Add(new LineCollider(pv1.ToUnityFloat2(), pv2.ToUnityFloat2(), bottom, top, _api.GetColliderInfo()), _matrix);
+
+ } else {
+ colliders.Add(new LineSlingshotCollider(_colliderComponent.SlingshotForce, pv1.ToUnityFloat2(), pv2.ToUnityFloat2(), bottom, top, _api.GetColliderInfo()), _matrix);
+ }
+
+ if (_component.HeightBottom != 0) {
+ // add lower edge as a line
+ colliders.Add(new Line3DCollider(new float3(pv1.X, pv1.Y, bottom), new float3(pv2.X, pv2.Y, bottom), _api.GetColliderInfo()), _matrix);
+ }
+
+ // add upper edge as a line
+ colliders.Add(new Line3DCollider(new float3(pv1.X, pv1.Y, top), new float3(pv2.X, pv2.Y, top), _api.GetColliderInfo()), _matrix);
+
+ // create vertical joint between the two line segments
+ colliders.Add(new LineZCollider(pv1.ToUnityFloat2(), bottom, top, _api.GetColliderInfo()), _matrix);
+
+ // add upper and lower end points of line
+ if (_component.HeightBottom != 0) {
+ colliders.Add(new PointCollider(new float3(pv1.X, pv1.Y, bottom), _api.GetColliderInfo()), _matrix);
+ }
+
+ colliders.Add(new PointCollider(new float3(pv1.X, pv1.Y, top), _api.GetColliderInfo()), _matrix);
}
}
}
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs
index ae6dcbb45..88ec6d2a2 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceSideMeshComponent.cs
@@ -30,9 +30,13 @@ public class SurfaceSideMeshComponent : MeshComponent();
+ var playfieldDimensions = GetPlayfieldDimensions();
+ if (playfieldDimensions == Vector2.zero) {
+ Debug.LogError($"SurfaceTopMeshComponent of {transform.parent.name} must be a child of a PlayfieldComponent.");
+ return null;
+ }
return new SurfaceMeshGenerator(data, Vertex3D.Zero)
- .GetMesh(SurfaceMeshGenerator.Side, playfieldComponent.Width, playfieldComponent.Height, 0, false)
+ .GetMesh(SurfaceMeshGenerator.Side, playfieldDimensions.x, playfieldDimensions.y, 0, false)
.TransformToWorld();
}
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceTopMeshComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceTopMeshComponent.cs
index 2deddc08f..efbfd2b3b 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceTopMeshComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Surface/SurfaceTopMeshComponent.cs
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
+// ReSharper disable InconsistentNaming
+
using UnityEngine;
using VisualPinball.Engine.Math;
using VisualPinball.Engine.VPT;
@@ -28,11 +30,16 @@ namespace VisualPinball.Unity
[AddComponentMenu("Pinball/Mesh/Surface Top Mesh")]
public class SurfaceTopMeshComponent : MeshComponent, IPackable
{
+
protected override Mesh GetMesh(SurfaceData data)
{
- var playfieldComponent = GetComponentInParent();
+ var playfieldDimensions = GetPlayfieldDimensions();
+ if (playfieldDimensions == Vector2.zero) {
+ Debug.LogError($"SurfaceTopMeshComponent of {transform.parent.name} must be a child of a PlayfieldComponent.");
+ return null;
+ }
return new SurfaceMeshGenerator(data, MainComponent.uvOffset.ToVertex3D())
- .GetMesh(SurfaceMeshGenerator.Top, playfieldComponent.Width, playfieldComponent.Height, 0, false)
+ .GetMesh(SurfaceMeshGenerator.Top, playfieldDimensions.x, playfieldDimensions.y, 0, false)
.TransformToWorld();
}
diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs
index 834b22ff8..2696d2e6a 100644
--- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs
+++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerComponent.cs
@@ -252,39 +252,39 @@ internal TriggerState CreateState()
var animComponent = GetComponentInChildren();
var meshComponent = GetComponentInChildren();
- if (collComponent.ForFlipper == null) {
+ if (collComponent.ForFlipper != null) {
return new TriggerState(
- animComponent ? animComponent.gameObject.GetInstanceID() : 0,
new TriggerStaticState {
- AnimSpeed = animComponent ? animComponent.AnimSpeed : 0,
+ AnimSpeed = 0,
Radius = collComponent.HitCircleRadius,
- Shape = meshComponent ? meshComponent.Shape : 0,
+ Shape = TriggerShape.TriggerNone,
TableScaleZ = 1f,
- InitialPosition = transform.localPosition
+ InitialPosition = transform.position
},
- new TriggerMovementState(),
- new TriggerAnimationState()
+ new FlipperCorrectionState(
+ true,
+ collComponent.ForFlipper.gameObject.GetInstanceID(),
+ collComponent.TimeThresholdMs,
+ collComponent.FlipperPolarities,
+ collComponent.FlipperVelocities,
+ Allocator.Persistent
+ )
);
}
return new TriggerState(
+ animComponent ? animComponent.gameObject.GetInstanceID() : 0,
new TriggerStaticState {
- AnimSpeed = 0,
+ AnimSpeed = animComponent ? animComponent.AnimSpeed : 0,
Radius = collComponent.HitCircleRadius,
- Shape = TriggerShape.TriggerNone,
+ Shape = meshComponent ? meshComponent.Shape : 0,
TableScaleZ = 1f,
- InitialPosition = transform.position
+ InitialPosition = transform.localPosition
},
- new FlipperCorrectionState(
- true,
- collComponent.ForFlipper.gameObject.GetInstanceID(),
- collComponent.ForFlipper.FlipperApi.ColliderId, // todo fixme this is not yet set
- collComponent.TimeThresholdMs,
- collComponent.FlipperPolarities,
- collComponent.FlipperVelocities,
- Allocator.Persistent
- )
+ new TriggerMovementState(),
+ new TriggerAnimationState()
);
+
}
#endregion
|