Ejemplo n.º 1
0
        internal static void GetBakedMeshProperties(
            this PhysicsShapeAuthoring shape, NativeList <float3> pointCloud, NativeList <int3> triangles, out Hash128 hashedInputs
            )
        {
            using (var inputs = new NativeList <HashableShapeInputs>(8, Allocator.TempJob))
            {
                shape.GetMeshProperties(pointCloud, triangles, true, inputs);
                shape.BakePoints(pointCloud);

                using (var hash = new NativeArray <Hash128>(1, Allocator.TempJob))
                    using (var allSkinIndices = new NativeArray <int>(0, Allocator.TempJob))
                        using (var allBlendShapeWeights = new NativeArray <float>(0, Allocator.TempJob))
                        {
                            var job = new GetShapeInputsHashJob
                            {
                                Result = hash,
                                ForceUniqueIdentifier = (uint)(shape.ForceUnique ? shape.GetInstanceID() : 0),
                                Material             = shape.GetMaterial(),
                                CollisionFilter      = shape.GetFilter(),
                                BakeFromShape        = shape.GetLocalToShapeMatrix(),
                                Inputs               = inputs,
                                AllSkinIndices       = allSkinIndices,
                                AllBlendShapeWeights = allBlendShapeWeights
                            };
                            job.Run();
                            hashedInputs = hash[0];
                        }
            }
        }
Ejemplo n.º 2
0
        internal static void GetBakedConvexProperties(
            this PhysicsShapeAuthoring shape, NativeList <float3> pointCloud, out ConvexHullGenerationParameters generationParameters,
            out Hash128 hashedInputs
            )
        {
            using (var inputs = new NativeList <HashableShapeInputs>(8, Allocator.TempJob))
                using (var allSkinIndices = new NativeList <int>(4096, Allocator.TempJob))
                    using (var allBlendShapeWeights = new NativeList <float>(64, Allocator.TempJob))
                    {
                        shape.GetConvexHullProperties(pointCloud, true, inputs, allSkinIndices, allBlendShapeWeights);

                        shape.BakePoints(pointCloud);

                        // compute convex radius
                        var center       = float3.zero;
                        var orientation  = EulerAngles.Default;
                        var localToWorld = shape.transform.localToWorldMatrix;
                        var shapeToWorld = shape.GetShapeToWorldMatrix();
                        var bakeToShape  =
                            GetPrimitiveBakeToShapeMatrix(localToWorld, shapeToWorld, ref center, ref orientation, 1f, k_DefaultAxisPriority);
                        using (var aabb = new NativeArray <Aabb>(1, Allocator.TempJob))
                        {
                            new GetAabbJob {
                                Points = pointCloud, Aabb = aabb
                            }.Run();
                            HashableShapeInputs.GetQuantizedTransformations(bakeToShape, aabb[0], out bakeToShape);
                        }
                        var s = new float3(math.length(bakeToShape[0]), math.length(bakeToShape[1]), math.length(bakeToShape[2]));
                        generationParameters = shape.ConvexHullGenerationParameters;
                        generationParameters.SimplificationTolerance = math.max(
                            ConvexHullGenerationParametersExtensions.k_MinRecommendedSimplificationTolerance,
                            math.cmax(s) * generationParameters.SimplificationTolerance
                            );
                        generationParameters.BevelRadius *= math.cmin(s);

                        using (var hash = new NativeArray <Hash128>(1, Allocator.TempJob))
                        {
                            var job = new GetShapeInputsHashJob
                            {
                                Result = hash,
                                ForceUniqueIdentifier = (uint)(shape.ForceUnique ? shape.GetInstanceID() : 0),
                                GenerationParameters  = generationParameters,
                                Material             = shape.GetMaterial(),
                                CollisionFilter      = shape.GetFilter(),
                                BakeFromShape        = shape.GetLocalToShapeMatrix(),
                                Inputs               = inputs,
                                AllSkinIndices       = allSkinIndices,
                                AllBlendShapeWeights = allBlendShapeWeights
                            };
                            job.Run();
                            hashedInputs = hash[0];
                        }
                    }
        }