예제 #1
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);
        }
예제 #2
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);
        }