public void Execute(int index) { SafetyChecks.IsTrue(BranchNodeOffsets[index] >= 0); var bvh = new BoundingVolumeHierarchy(Nodes, NodeFilters); var lastNode = bvh.BuildBranch(Points, Aabbs, Ranges[index], BranchNodeOffsets[index]); if (NodeFilters != null) { bvh.BuildCombinedCollisionFilter(BodyFilters, BranchNodeOffsets[index], lastNode); bvh.BuildCombinedCollisionFilter(Ranges[index].Root); } }
internal void CreateCollider(Entity rigidbodyEntity) { var colliderCount = RigidbodyToColliderMapping.CountValuesForKey(rigidbodyEntity); if (colliderCount == 0) { return; } // Single collider doesn't require a compound collider. if (colliderCount == 1) { var foundColliderBlob = RigidbodyToColliderMapping.TryGetFirstValue(rigidbodyEntity, out BlobAssetReference <Collider> colliderBlob, out NativeMultiHashMapIterator <Entity> ignore); SafetyChecks.IsTrue(foundColliderBlob); // Add the single collider to the rigidbody entity. DstEntityManager.AddComponentData(rigidbodyEntity, new PhysicsColliderBlob { Collider = colliderBlob }); return; } // Multiple colliders required a compound collider. var childrenArray = new NativeArray <PhysicsCompoundCollider.ColliderBlobInstance>(colliderCount, Allocator.Temp, NativeArrayOptions.UninitializedMemory); var childIndex = 0; foreach (var colliderBlob in RigidbodyToColliderMapping.GetValuesForKey(rigidbodyEntity)) { childrenArray[childIndex++] = new PhysicsCompoundCollider.ColliderBlobInstance { Collider = colliderBlob, // NOTE: Right now the relative pose of the collider with respect to the rigidbody is baked into the shape. // Later, we'll want to remove that and only have its offset (if any) baked into it and use this transform instead. CompoundFromChild = PhysicsTransform.Identity }; } // Create the compound collider. DstEntityManager.AddComponentData(rigidbodyEntity, new PhysicsColliderBlob { Collider = PhysicsCompoundCollider.Create(childrenArray) }); // We've finished with the children blobs and array. for (var i = 0; i < colliderCount; ++i) { childrenArray[i].Collider.Dispose(); } childrenArray.Dispose(); }
public unsafe void Polygon(ConvexHull.ConvexArray.Accessor vertices, int vertexCount, PhysicsTransform physicsTransform, Color color) { SafetyChecks.IsTrue(vertexCount <= PhysicsPolygonCollider.Constants.MaxVertexCount); Writer.Write(Type.Polygon); var polygon = new Polygon { Transform = physicsTransform, VertexCount = vertexCount, Color = color }; UnsafeUtility.MemCpy(polygon.Vertices, vertices.GetUnsafePtr(), sizeof(float2) * vertexCount); Writer.Write(polygon); }