//Todo: World settings? internal CollisionLayer(int bodyCount, CollisionLayerSettings settings, Allocator allocator) { worldMin = settings.worldAABB.min; worldAxisStride = (settings.worldAABB.max - worldMin) / settings.worldSubdivisionsPerAxis; worldSubdivisionsPerAxis = settings.worldSubdivisionsPerAxis; bucketStartsAndCounts = new NativeArray <int2>(settings.worldSubdivisionsPerAxis.x * settings.worldSubdivisionsPerAxis.y * settings.worldSubdivisionsPerAxis.z + 1, allocator, NativeArrayOptions.UninitializedMemory); xmins = new NativeArray <float>(bodyCount, allocator, NativeArrayOptions.UninitializedMemory); xmaxs = new NativeArray <float>(bodyCount, allocator, NativeArrayOptions.UninitializedMemory); yzminmaxs = new NativeArray <float4>(bodyCount, allocator, NativeArrayOptions.UninitializedMemory); bodies = new NativeArray <ColliderBody>(bodyCount, allocator, NativeArrayOptions.UninitializedMemory); }
public static JobHandle BuildCollisionLayer(EntityQuery query, LayerChunkTypeGroup typeGroup, CollisionLayerSettings settings, Allocator allocator, JobHandle inputDeps, out CollisionLayer collisionLayer) { int count = query.CalculateEntityCount(); collisionLayer = new CollisionLayer(count, settings, allocator); NativeArray <int> layerIndices = new NativeArray <int>(collisionLayer.Count, allocator, NativeArrayOptions.UninitializedMemory); NativeArray <AABB> aabbs = new NativeArray <AABB>(collisionLayer.Count, allocator, NativeArrayOptions.UninitializedMemory); NativeArray <RigidTransform> rigidTransforms = new NativeArray <RigidTransform>(collisionLayer.Count, allocator, NativeArrayOptions.UninitializedMemory); JobHandle jh = new BuildCollisionLayerPart1 { layer = collisionLayer, layerIndices = layerIndices, aabbs = aabbs, rigidTransforms = rigidTransforms, typeGroup = typeGroup }.Schedule(query, inputDeps); jh = new BuildCollisionLayerPart2 { layer = collisionLayer, layerIndices = layerIndices }.Schedule(jh); jh = new BuildCollisionLayerPart3 { layer = collisionLayer, layerIndices = layerIndices, aabbs = aabbs, rigidTranforms = rigidTransforms, typeGroup = typeGroup }.Schedule(query, jh); //layerIndices, aabbs, and rigidTransforms are deallocated in Part3 jh = new BuildCollisionLayerPart4 { layer = collisionLayer }.Schedule(collisionLayer.BucketCount, 1, jh); return(jh); }
public static BuildCollisionLayerConfig WithSettings(this BuildCollisionLayerConfig config, CollisionLayerSettings settings) { config.settings = settings; return(config); }