internal static CapsuleGeometry GetBakedCapsuleProperties(
            this PhysicsShapeAuthoring shape, out float3 center, out float height, out EulerAngles orientation
            )
        {
            var capsule = shape.GetCapsuleProperties(out orientation);

            return(capsule.BakeToBodySpace(shape.transform.localToWorldMatrix, shape.GetShapeToWorldMatrix(), out center, out height, ref orientation));
        }
Пример #2
0
        internal static CapsuleGeometry GetBakedCapsuleProperties(
            this PhysicsShapeAuthoring shape,
            out float3 center, out float height, out EulerAngles orientation
            )
        {
            var capsule = shape.GetCapsuleProperties(out orientation);
            var radius  = capsule.Radius;

            center = capsule.GetCenter();
            height = capsule.GetHeight();

            var s             = new float3(radius * 2f, radius * 2f, height);
            var localToWorld  = (float4x4)shape.transform.localToWorldMatrix;
            var basisToWorld  = GetBasisToWorldMatrix(localToWorld, center, orientation, s);
            var basisPriority = k_DefaultAxisPriority;
            var sheared       = localToWorld.HasShear();

            if (localToWorld.HasNonUniformScale() || sheared)
            {
                if (sheared)
                {
                    basisPriority = GetBasisAxisPriority(basisToWorld);
                }
                MakeZAxisPrimaryBasis(ref basisPriority);
            }
            var bakeToShape = GetPrimitiveBakeToShapeMatrix(shape, ref center, ref orientation, 1f, basisPriority);

            height *= math.length(bakeToShape.c2);
            radius *= math.max(math.length(bakeToShape.c0), math.length(bakeToShape.c1));

            var axis = math.mul(orientation, new float3 {
                z = 1f
            });
            var endPoint = axis * math.max(0f, 0.5f * height - radius);

            return(new CapsuleGeometry
            {
                Vertex0 = center + endPoint,
                Vertex1 = center - endPoint,
                Radius = radius
            });
        }
Пример #3
0
        internal static void SetBakedCapsuleSize(this PhysicsShapeAuthoring shape, float height, float radius)
        {
            var capsule = shape.GetCapsuleProperties();
            var center  = capsule.Center;

            var bakeToShape = BakeCapsuleJob.GetBakeToShape(shape, center, capsule.OrientationEuler);
            var scale       = bakeToShape.DecomposeScale();

            var newRadius = radius / math.cmax(scale.xy);

            if (math.abs(capsule.Radius - newRadius) > kMinimumChange)
            {
                capsule.Radius = newRadius;
            }

            height /= scale.z;

            if (math.abs(math.length(capsule.Height - height)) > kMinimumChange)
            {
                capsule.Height = height;
            }

            shape.SetCapsule(capsule);
        }
Пример #4
0
        internal static CapsuleGeometryAuthoring GetBakedCapsuleProperties(this PhysicsShapeAuthoring shape)
        {
            var capsule = shape.GetCapsuleProperties();

            return(capsule.BakeToBodySpace(shape.transform.localToWorldMatrix, shape.GetShapeToWorldMatrix()));
        }