public static 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 builder = new SpookyHashBuilder(Allocator.Temp); builder.Append(ref uniqueIdentifier); builder.Append(ref hullGenerationParameters); builder.Append(ref material); builder.Append(ref filter); builder.Append(ref scaleShear); builder.Append(inputs); builder.Append(allIncludedIndices); builder.Append(allBlendShapeWeights); return(builder.Finish()); }
public void Execute(int index) { var shapeData = ComputationData[index]; var material = shapeData.Material; var collisionFilter = shapeData.CollisionFilter; var shapeType = shapeData.ShapeType; var builder = new SpookyHashBuilder(Allocator.Temp); builder.Append(ref shapeType); builder.Append(ref shapeData.ForceUniqueIdentifier); builder.Append(ref collisionFilter); builder.Append(ref material); switch (shapeType) { case ShapeType.Box: { var p = shapeData.BoxProperties; builder.Append(ref p); var aabb = RotatedBoxAabb(p.Center, p.Size, shapeData.BoxProperties.Orientation); HashableShapeInputs.GetQuantizedTransformations(shapeData.BodyFromShape, aabb, out var transformations); builder.Append(ref transformations); break; } case ShapeType.Capsule: { var p = shapeData.CapsuleProperties; builder.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); builder.Append(ref transformations); break; } case ShapeType.Cylinder: { var p = shapeData.CylinderProperties; builder.Append(ref p); var aabb = RotatedCylinderAabb(p.Center, p.Height, p.Radius, shapeData.CylinderProperties.Orientation); HashableShapeInputs.GetQuantizedTransformations(shapeData.BodyFromShape, aabb, out var transformations); builder.Append(ref transformations); break; } case ShapeType.Plane: { var v = shapeData.PlaneVertices; builder.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); builder.Append(ref transformations); break; } case ShapeType.Sphere: { var p = shapeData.SphereProperties; builder.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); builder.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] = builder.Finish(); }