internal static CapsuleGeometry BakeToBodySpace(
     this CapsuleGeometry capsule, float4x4 localToWorld, float4x4 shapeToWorld,
     out float3 center, out float height, ref EulerAngles orientation
     )
 {
     using (var geometry = new NativeArray <CapsuleGeometry>(1, Allocator.TempJob)
     {
         [0] = capsule
     })
         using (var outCenter = new NativeArray <float3>(1, Allocator.TempJob))
             using (var outHeight = new NativeArray <float>(1, Allocator.TempJob))
                 using (var outOrientation = new NativeArray <EulerAngles>(1, Allocator.TempJob)
                 {
                     [0] = orientation
                 })
                 {
                     var job = new BakeCapsuleJob
                     {
                         Capsule      = geometry,
                         Center       = outCenter,
                         Height       = outHeight,
                         Orientation  = outOrientation,
                         localToWorld = localToWorld,
                         shapeToWorld = shapeToWorld
                     };
                     job.Run();
                     center      = outCenter[0];
                     height      = outHeight[0];
                     orientation = outOrientation[0];
                     return(geometry[0]);
                 }
 }
示例#2
0
 internal static CapsuleGeometryAuthoring BakeToBodySpace(
     this CapsuleGeometryAuthoring capsule, float4x4 localToWorld, float4x4 shapeToWorld
     )
 {
     using (var geometry = new NativeArray <CapsuleGeometryAuthoring>(1, Allocator.TempJob)
     {
         [0] = capsule
     })
     {
         var job = new BakeCapsuleJob
         {
             Capsule      = geometry,
             localToWorld = localToWorld,
             shapeToWorld = shapeToWorld
         };
         job.Run();
         return(geometry[0]);
     }
 }
示例#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);
        }