public void Execute()
            {
                var bytes = new NativeList <byte>(Allocator.Temp);

                bytes.Append(ChildHashes);
                bytes.Append(ChildOffsets);
                Output[0] = HashUtility.Hash128(bytes.GetUnsafeReadOnlyPtr(), bytes.Length);
            }
Beispiel #2
0
        public static unsafe Hash128 GetHash128(
            uint uniqueIdentifier,
            ConvexHullGenerationParameters hullGenerationParameters,
            Material material,
            CollisionFilter filter,
            float4x4 bakeFromShape,
            NativeArray <HashableShapeInputs> inputs,
            NativeArray <int> allIncludedIndices,
            NativeArray <float> allBlendShapeWeights,
            float linearPrecision = k_DefaultLinearPrecision
            )
        {
            var numInputs = inputs.IsCreated ? inputs.Length : 0;

            // quantize shape-level transforms
            var bounds = new Aabb {
                Min = float.MaxValue, Max = float.MinValue
            };

            for (int i = 0; i < numInputs; i++)
            {
                var d = inputs[i];
                bounds.Include(math.mul(d.BodyFromShape, new float4(d.Bounds.Min, 1f)).xyz);
                bounds.Include(math.mul(d.BodyFromShape, new float4(d.Bounds.Max, 1f)).xyz);
            }
            GetQuantizedTransformations(bakeFromShape, bounds, out var bakeMatrix, linearPrecision);

            // bakeFromShape only contains scale/shear information, so only the inner 3x3 needs to contribute to the hash
            var scaleShear = new float3x3(bakeMatrix.c0.xyz, bakeMatrix.c1.xyz, bakeMatrix.c2.xyz);

            var bytes = new NativeList <byte>(Allocator.Temp);

            bytes.Append(ref uniqueIdentifier);
            bytes.Append(ref hullGenerationParameters);
            bytes.Append(ref material);
            bytes.Append(ref filter);
            bytes.Append(ref scaleShear);
            bytes.Append(inputs);
            bytes.Append(allIncludedIndices);
            bytes.Append(allBlendShapeWeights);
            return(HashUtility.Hash128(bytes.GetUnsafeReadOnlyPtr(), bytes.Length));
        }
Beispiel #3
0
            public void Execute(int index)
            {
                var shapeData = ComputationData[index];

                var material        = shapeData.Material;
                var collisionFilter = shapeData.CollisionFilter;
                var shapeType       = shapeData.ShapeType;

                var bytes = new NativeList <byte>(Allocator.Temp);

                bytes.Append(ref shapeType);
                bytes.Append(ref shapeData.ForceUniqueIdentifier);
                bytes.Append(ref collisionFilter);
                bytes.Append(ref material);

                switch (shapeType)
                {
                case ShapeType.Box:
                {
                    var p = shapeData.BoxProperties;
                    bytes.Append(ref p);
                    var aabb = RotatedBoxAabb(p.Center, p.Size, shapeData.BoxProperties.Orientation);
                    HashableShapeInputs.GetQuantizedTransformations(shapeData.BodyFromShape, aabb, out var transformations);
                    bytes.Append(ref transformations);
                    break;
                }

                case ShapeType.Capsule:
                {
                    var p = shapeData.CapsuleProperties;
                    bytes.Append(ref p);
                    var v0   = p.Vertex0;
                    var v1   = p.Vertex1;
                    var r    = p.Radius;
                    var aabb = RotatedCylinderAabb(p.GetCenter(), p.GetHeight(), r, quaternion.LookRotationSafe(v0 - v1, math.up()));
                    HashableShapeInputs.GetQuantizedTransformations(shapeData.BodyFromShape, aabb, out var transformations);
                    bytes.Append(ref transformations);
                    break;
                }

                case ShapeType.Cylinder:
                {
                    var p = shapeData.CylinderProperties;
                    bytes.Append(ref p);
                    var aabb = RotatedCylinderAabb(p.Center, p.Height, p.Radius, shapeData.CylinderProperties.Orientation);
                    HashableShapeInputs.GetQuantizedTransformations(shapeData.BodyFromShape, aabb, out var transformations);
                    bytes.Append(ref transformations);
                    break;
                }

                case ShapeType.Plane:
                {
                    var v = shapeData.PlaneVertices;
                    bytes.Append(ref v);
                    var planeCenter = math.lerp(v.c0, v.c2, 0.5f);
                    var planeSize   = math.abs(v.c0 - v.c2);
                    var aabb        = RotatedBoxAabb(planeCenter, planeSize, quaternion.LookRotationSafe(v.c1 - v.c2, math.cross(v.c1 - v.c0, v.c2 - v.c1)));
                    HashableShapeInputs.GetQuantizedTransformations(shapeData.BodyFromShape, aabb, out var transformations);
                    bytes.Append(ref transformations);
                    break;
                }

                case ShapeType.Sphere:
                {
                    var p = shapeData.SphereProperties;
                    bytes.Append(ref p);
                    var aabb = new Aabb {
                        Min = p.Center - new float3(p.Radius), Max = p.Center + new float3(p.Radius)
                    };
                    HashableShapeInputs.GetQuantizedTransformations(shapeData.BodyFromShape, aabb, out var transformations);
                    bytes.Append(ref transformations);
                    break;
                }

                case ShapeType.ConvexHull:
                {
                    Hashes[index] = shapeData.Instance.Hash;     // precomputed when gathering inputs
                    return;
                }

                case ShapeType.Mesh:
                {
                    Hashes[index] = shapeData.Instance.Hash;     // precomputed when gathering inputs
                    return;
                }
                }

                Hashes[index] = HashUtility.Hash128(bytes.GetUnsafeReadOnlyPtr(), bytes.Length);
            }
Beispiel #4
0
 protected override void OnCreate()
 {
     base.OnCreate();
     HashUtility.Initialize();
 }