internal static void GetBakeTransformation(
            this PhysicsShape shape, out float3 linearScalar, out float radiusScalar
            )
        {
            linearScalar = shape.transform.lossyScale;

            radiusScalar = 1f;
            var s = math.abs(linearScalar);

            switch (shape.ShapeType)
            {
            case ShapeType.Box:
                radiusScalar = math.cmin(s);
                break;

            case ShapeType.Sphere:
                radiusScalar = math.cmax(s);
                break;

            case ShapeType.Capsule:
                var cmax  = math.cmax(s);
                var cmin  = math.cmin(s);
                var cmaxI = cmax == s.z ? 2 : cmax == s.y ? 1 : 0;
                var cminI = cmin == s.z ? 2 : cmin == s.y ? 1 : 0;
                var cmidI = cmaxI == 2 ? (cminI == 1 ? 0 : 1) : (cminI == 1 ? 2 : 0);
                radiusScalar = s[cmidI];
                break;

            case ShapeType.Cylinder:
                radiusScalar = math.cmax(s);
                break;

            case ShapeType.ConvexHull:
                radiusScalar = math.cmax(s);
                break;

            case ShapeType.Plane:
            case ShapeType.Mesh:
                break;

            default:
                throw new UnimplementedShapeException(shape.ShapeType);
            }
        }
Esempio n. 2
0
 internal static GameObject GetPrimaryBody(this PhysicsShape shape) => GetPrimaryBody(shape.gameObject);