コード例 #1
0
        private void GenerateCurvedHitObjects(ICollection <ICollider> colliders)
        {
            var height  = _component.PositionZ;
            var vVertex = DragPoint.GetRgVertex <RenderVertex2D, CatmullCurve2DCatmullCurveFactory>(_component.DragPoints);

            var count = vVertex.Length;
            var rgv   = new RenderVertex2D[count];
            var rgv3D = new float3[count];

            for (var i = 0; i < count; i++)
            {
                rgv[i]   = vVertex[i];
                rgv3D[i] = new float3(rgv[i].X, rgv[i].Y, height + (float)(PhysicsConstants.PhysSkin * 2.0));
            }
            ColliderUtils.Generate3DPolyColliders(rgv3D, _api.GetColliderInfo(), colliders);

            for (var i = 0; i < count; i++)
            {
                var pv2 = rgv[i < count - 1 ? i + 1 : 0];
                var pv3 = rgv[i < count - 2 ? i + 2 : i + 2 - count];
                AddLineSeg(pv2.ToUnityFloat2(), pv3.ToUnityFloat2(), height, colliders);
            }
        }
コード例 #2
0
        internal void GenerateColliders(float collisionReductionFactor, List <ICollider> colliders)
        {
            var mesh = _meshGenerator.GetMesh();

            if (mesh == null)
            {
                Logger.Warn($"Primitive {_meshGenerator.name} did not return a mesh for collider generation.");
                return;
            }
            mesh = mesh.Transform(_meshGenerator.GetTransformationMatrix());

            var reducedVertices = math.max(
                (uint)MathF.Pow(mesh.Vertices.Length,
                                MathF.Clamp(1f - collisionReductionFactor, 0f, 1f) * 0.25f + 0.75f),
                420u                 //!! 420 = magic
                );

            if (reducedVertices < mesh.Vertices.Length)
            {
                mesh = ComputeReducedMesh(mesh, reducedVertices);
            }

            ColliderUtils.GenerateCollidersFromMesh(mesh, _api.GetColliderInfo(), colliders);
        }
コード例 #3
0
        protected override void CreateColliders(List <ICollider> colliders, float margin)
        {
            var info = ((IApiColliderGenerator)this).GetColliderInfo();

            var meshComp = GameObject.GetComponent <PlayfieldMeshComponent>();

            if (meshComp && !meshComp.AutoGenerate)
            {
                var mf = GameObject.GetComponent <MeshFilter>();
                if (mf && mf.sharedMesh)
                {
                    ColliderUtils.GenerateCollidersFromMesh(mf.sharedMesh.ToVpMesh(), info, colliders);
                }
            }

            if (ColliderComponent.CollideWithBounds)
            {
                // simple outer borders:
                colliders.Add(new LineCollider(
                                  new float2(MainComponent.Right, MainComponent.Top),
                                  new float2(MainComponent.Right, MainComponent.Bottom),
                                  MainComponent.TableHeight,
                                  MainComponent.GlassHeight,
                                  info
                                  ));

                colliders.Add(new LineCollider(
                                  new float2(MainComponent.Left, MainComponent.Bottom),
                                  new float2(MainComponent.Left, MainComponent.Top),
                                  MainComponent.TableHeight,
                                  MainComponent.GlassHeight,
                                  info
                                  ));

                colliders.Add(new LineCollider(
                                  new float2(MainComponent.Right, MainComponent.Bottom),
                                  new float2(MainComponent.Left, MainComponent.Bottom),
                                  MainComponent.TableHeight,
                                  MainComponent.GlassHeight,
                                  info
                                  ));

                colliders.Add(new LineCollider(
                                  new float2(MainComponent.Left, MainComponent.Top),
                                  new float2(MainComponent.Right, MainComponent.Top),
                                  MainComponent.TableHeight,
                                  MainComponent.GlassHeight,
                                  info
                                  ));
            }

            // glass:
            var rgv3D = new[] {
                new float3(MainComponent.Left, MainComponent.Top, MainComponent.GlassHeight),
                new float3(MainComponent.Right, MainComponent.Top, MainComponent.GlassHeight),
                new float3(MainComponent.Right, MainComponent.Bottom, MainComponent.GlassHeight),
                new float3(MainComponent.Left, MainComponent.Bottom, MainComponent.GlassHeight)
            };

            ColliderUtils.Generate3DPolyColliders(rgv3D, info, colliders);
        }