internal void GenerateColliders(float playfieldHeight, float hitHeight, int detailLevel, List <ICollider> colliders, float margin) { var mesh = _meshGenerator.GetTransformedMesh(playfieldHeight, hitHeight, detailLevel, 6, true, margin); //!! adapt hacky code in the function if changing the "6" here var addedEdges = EdgeSet.Get(); // add collision triangles and edges for (var i = 0; i < mesh.Indices.Length; i += 3) { // NB: HitTriangle wants CCW vertices, but for rendering we have them in CW order var rg0 = mesh.Vertices[mesh.Indices[i]].ToUnityFloat3(); var rg1 = mesh.Vertices[mesh.Indices[i + 2]].ToUnityFloat3(); var rg2 = mesh.Vertices[mesh.Indices[i + 1]].ToUnityFloat3(); colliders.Add(new TriangleCollider(rg0, rg1, rg2, _api.GetColliderInfo())); GenerateHitEdge(mesh, addedEdges, mesh.Indices[i], mesh.Indices[i + 2], colliders); GenerateHitEdge(mesh, addedEdges, mesh.Indices[i + 2], mesh.Indices[i + 1], colliders); GenerateHitEdge(mesh, addedEdges, mesh.Indices[i + 1], mesh.Indices[i], colliders); } // add collision vertices foreach (var mv in mesh.Vertices) { colliders.Add(new PointCollider(mv.ToUnityFloat3(), _api.GetColliderInfo())); } }
private void GenerateHitEdge(Mesh mesh, EdgeSet addedEdges, int i, int j, ICollection <ICollider> colliders) { if (addedEdges.ShouldAddHitEdge(i, j)) { var v1 = mesh.Vertices[i].ToUnityFloat3(); var v2 = mesh.Vertices[j].ToUnityFloat3(); colliders.Add(new Line3DCollider(v1, v2, _api.GetColliderInfo())); } }
internal void GenerateColliders(List <ICollider> colliders) { var localToPlayfield = MeshGenerator.GetTransformationMatrix(); var hitMesh = MeshGenerator.GetMesh(); for (var i = 0; i < hitMesh.Vertices.Length; i++) { hitMesh.Vertices[i].MultiplyMatrix(localToPlayfield); } var addedEdges = EdgeSet.Get(); GenerateCollidables(hitMesh, addedEdges, true, colliders); }
private protected void GenerateCollidables(Mesh hitMesh, EdgeSet addedEdges, bool setHitObject, ICollection <ICollider> colliders) { // add the normal drop target as collidable but without hit event for (var i = 0; i < hitMesh.Indices.Length; i += 3) { var i0 = hitMesh.Indices[i]; var i1 = hitMesh.Indices[i + 1]; var i2 = hitMesh.Indices[i + 2]; // NB: HitTriangle wants CCW vertices, but for rendering we have them in CW order var rgv0 = hitMesh.Vertices[i0].ToUnityFloat3(); var rgv1 = hitMesh.Vertices[i1].ToUnityFloat3(); var rgv2 = hitMesh.Vertices[i2].ToUnityFloat3(); colliders.Add(new TriangleCollider(rgv0, rgv2, rgv1, GetColliderInfo(setHitObject))); if (addedEdges.ShouldAddHitEdge(i0, i1)) { colliders.Add(new Line3DCollider(rgv0, rgv2, GetColliderInfo(setHitObject))); } if (addedEdges.ShouldAddHitEdge(i1, i2)) { colliders.Add(new Line3DCollider(rgv2, rgv1, GetColliderInfo(setHitObject))); } if (addedEdges.ShouldAddHitEdge(i2, i0)) { colliders.Add(new Line3DCollider(rgv1, rgv0, GetColliderInfo(setHitObject))); } } // add collision vertices foreach (var vertex in hitMesh.Vertices) { colliders.Add(new PointCollider(vertex.ToUnityFloat3(), GetColliderInfo(setHitObject))); } }
internal void GenerateColliders(float playfieldHeight, ICollection <ICollider> colliders) { var localToPlayfield = MeshGenerator.GetTransformationMatrix(); // QUICK FIX and TODO for Cupiii /* hitmesh should not be generated by the Mesh generator. Drop Targets need special Hitshapes, that shoujld be very simple and cannot be activated from behind. * var hitMesh = MeshGenerator.GetMesh(); * for (var i = 0; i < hitMesh.Vertices.Length; i++) { * hitMesh.Vertices[i].MultiplyMatrix(localToPlayfield); * } * * var addedEdges = EdgeSet.Get(); * * GenerateCollidables(hitMesh, addedEdges, Data.IsLegacy, colliders); */ var addedEdges = EdgeSet.Get(); var tempMatrix = new Matrix3D().RotateZMatrix(MathF.DegToRad(Data.RotZ)); var fullMatrix = new Matrix3D().Multiply(tempMatrix); //if (!Data.IsLegacy) // Always generate special hitshapes (QUICKFIX) { var rgv3D = new Vertex3D[DropTargetHitPlaneVertices.Length]; var hitShapeOffset = 0.18f; if (Data.TargetType == TargetType.DropTargetBeveled) { hitShapeOffset = 0.25f; } if (Data.TargetType == TargetType.DropTargetFlatSimple) { hitShapeOffset = 0.13f; } // now create a special hit shape with hit event enabled to prevent a hit event when hit from behind for (var i = 0; i < DropTargetHitPlaneVertices.Length; i++) { var dropTargetHitPlaneVertex = DropTargetHitPlaneVertices[i]; var vert = new Vertex3D( dropTargetHitPlaneVertex.x, dropTargetHitPlaneVertex.y + hitShapeOffset, dropTargetHitPlaneVertex.z ); vert.X *= Data.ScaleX; vert.Y *= Data.ScaleY; vert.Z *= Data.ScaleZ; vert = vert.MultiplyMatrix(fullMatrix); rgv3D[i] = new Vertex3D( vert.X + Data.PositionX, vert.Y + Data.PositionY, vert.Z + Data.PositionZ + playfieldHeight ); } for (var i = 0; i < DropTargetHitPlaneIndices.Length; i += 3) { var i0 = DropTargetHitPlaneIndices[i]; var i1 = DropTargetHitPlaneIndices[i + 1]; var i2 = DropTargetHitPlaneIndices[i + 2]; // NB: HitTriangle wants CCW vertices, but for rendering we have them in CW order var rgv0 = rgv3D[i0].ToUnityFloat3(); var rgv1 = rgv3D[i1].ToUnityFloat3(); var rgv2 = rgv3D[i2].ToUnityFloat3(); colliders.Add(new TriangleCollider(rgv0, rgv2, rgv1, GetColliderInfo(true))); if (addedEdges.ShouldAddHitEdge(i0, i1)) { colliders.Add(new Line3DCollider(rgv0, rgv2, GetColliderInfo(true))); } if (addedEdges.ShouldAddHitEdge(i1, i2)) { colliders.Add(new Line3DCollider(rgv2, rgv1, GetColliderInfo(true))); } if (addedEdges.ShouldAddHitEdge(i2, i0)) { colliders.Add(new Line3DCollider(rgv1, rgv0, GetColliderInfo(true))); } } // add collision vertices for (var i = 0; i < DropTargetHitPlaneVertices.Length; ++i) { colliders.Add(new PointCollider(rgv3D[i].ToUnityFloat3(), GetColliderInfo(true))); } } }