Exemplo n.º 1
0
        private void SetPlanes()
        {
            BlobArray.Accessor <float3> hullVertices = ConvexHull.Vertices;
            float3 cross = math.cross(
                hullVertices[1] - hullVertices[0],
                hullVertices[2] - hullVertices[0]);
            float dot            = math.dot(cross, hullVertices[0]);
            float invLengthCross = math.rsqrt(math.lengthsq(cross));
            Plane plane          = new Plane(cross * invLengthCross, -dot * invLengthCross);

            ConvexHull.Planes[0] = plane;
            ConvexHull.Planes[1] = plane.Flipped;
        }
Exemplo n.º 2
0
        // Build mass properties representing a union of all the child collider mass properties.
        // This assumes a uniform density for all children, and returns a mass properties for a compound of unit mass.
        private unsafe MassProperties BuildMassProperties()
        {
            BlobArray.Accessor <Child> children = Children;

            // Calculate combined center of mass
            float3 combinedCenterOfMass = float3.zero;
            float  combinedVolume       = 0.0f;

            for (int i = 0; i < NumChildren; ++i)
            {
                ref Child child = ref children[i];
                var       mp    = child.Collider->MassProperties;

                // weight this contribution by its volume (=mass)
                combinedCenterOfMass += math.transform(child.CompoundFromChild, mp.MassDistribution.Transform.pos) * mp.Volume;
                combinedVolume       += mp.Volume;
            }
Exemplo n.º 3
0
        // Build mass properties representing a union of all the child collider mass properties.
        // This assumes a uniform density for all children, and returns a mass properties for a compound of unit mass.
        private unsafe MassProperties BuildMassProperties()
        {
            BlobArray.Accessor <Child> children = Children;

            // Check if all children are triggers or have collisions disabled.
            // If so, we'll include them in mass properties of the compound collider.
            // This is mostly targeted for single collider compounds, as they should behave
            // the same as when there is no compound.
            bool skipTriggersAndDisabledColliders = false;
            {
                for (int i = 0; i < NumChildren; ++i)
                {
                    ref Child child = ref children[i];
                    var       convexChildCollider = (ConvexCollider *)child.Collider;
                    if (child.Collider->CollisionType == CollisionType.Convex &&
                        (convexChildCollider->Material.CollisionResponse != CollisionResponsePolicy.RaiseTriggerEvents &&
                         convexChildCollider->Material.CollisionResponse != CollisionResponsePolicy.None))
                    {
                        // If there are children with regular collisions, all triggers and disabled colliders should be skipped
                        skipTriggersAndDisabledColliders = true;
                        break;
                    }
                }
            }