Creates a box shape with the specified extent.
- Parameters:
- size: The box extent in meters along the local axes.
- Note: Collision shape extents that fall below 2mm are forced to be 2mm in size - this includes,
entities with negative scale values.
- Returns: The new box centered at the local origin and aligned with the
local axes.
Creates a box shape with the specified dimensions.
- Parameters:
- width: The extent of the box along the x-axis in meters.
- height: The extent of the box along the y-axis in meters.
- depth: The extent of the box along the z-axis in meters.
- Note: Collision shape extents that fall below 2mm are forced to be 2mm in size - this includes,
entities with negative scale values.
- Returns: The new box centered at the local origin and aligned with the
local axes.
Creates a convex shape from the given points asynchronously.
- Parameters:
- points: An array of 3D points that define the convex polyhedron. Keep the number of points small to
avoid hurting performance.
- Returns: A new ShapeResource object defined by the convex hull of `points`.
- Throws: Will throw an error if `points` do not define a nonempty convex volume. For example, will fail if
all of the points in `points` are coplanar.
Creates a convex shape from the given mesh.
- Parameters:
- mesh: A mesh with the shape of the convex polyhedron. Use meshes with a small number of vertices to
avoid hurting performance.
- Returns: The new shape, defined by the convex hull of the vertices in `mesh`.
- Throws: Will throw an error if `mesh` does not define a nonempty convex volume. For example, will fail if
all the vertices in `mesh` are coplanar.
Creates a sphere shape with the specified radius.
- Parameters:
- radius: The radius of the sphere in meters.
- Note: Collision shape extents that fall below 2mm are forced to be 2mm in size - this includes,
entities with negative scale values.
- Returns: The new sphere centered at the local origin.
Creates a capsule shape with the specified height and radius.
- Parameters:
- height: The height of the capsule including the spherical caps in meters, measured along the local y-axis.
- radius: The radius of the capsule in meters.
- Note: Collision shape extents that fall below 2mm are forced to be 2mm in size - this includes,
entities with negative scale values.
- Returns: The new capsule.
Creates a static collision mesh from a mesh resource.
You can use only the physics body mode ``PhysicsBodyMode/static`` and the
collision component mode ``CollisionComponent/Mode-swift.enum/default`` with this shape.
The code example below assumes calling this method from a synchronous block:
```swift
// Use a low-priority task because generating collision meshes can take a while.
let myShapeTask = Task(priority: .low) {
let meshResource = await MeshResource(
shape: .generateBox(size: [5, 5, 5])
)
guard let shape = try? await ShapeResource.generateStaticMesh(
from: meshResource
) else { return }
// You can use the `ShapeResource` to make a
// `CollisionComponent`, and add that to an entity.
// Run this from the main thread.
await MainActor.run {
let entity = Entity()
let collision = CollisionComponent(shapes: [shape])
entity.components.set(collision)
// Note that you can't set `mode` to `.dynamic`.
// This only supports `.static`.
let physicsBody = PhysicsBodyComponent(
massProperties: .default,
material: nil,
mode: .static
)
entity.components.set(physicsBody)
// ...
}
}
```
- Parameters:
- mesh: The mesh resource for generating the collision shape.
Creates a static collision mesh from an array of vertex positions and face indices.
The triangle mesh is pre-processed into an optimized format before being used by the physics engine.
The pre-processing step can take significant time if the position counts are large.
To minimize this cost, the position count should be as small as possible.
The returned `ShapeResource` can only be used under the following circumstances:
- You can only use this shape with ``PhysicsBodyMode/static``
and not `.dynamic` or `.kinematic`.
- You can't use this shape with ``CollisionComponent/Mode-swift.enum/trigger``.
- Parameters:
- positions: An array of vertex positions containing discrete points on the mesh.
- faceIndices: An array of integers used to index into the position array.
Each three indices define a polygon in the mesh.
Creates a new shape resource by applying a translation.
- Parameters:
- translation: The translation to apply to the existing shape resource.
- Returns: The transformed resource.
Creates a new shape resource by applying a rotation and a translation.
- Parameters:
- rotation: The rotation to apply to the existing shape resource.
- translation: The translation to apply to the existing shape resource.
- Returns: The transformed resource.
Creates a new shape resource by applying a rotation.
- Parameters:
- rotation: The rotation to apply to the existing shape resource.
- Returns: The transformed resource.
Skipped declarations
2 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
ShapeResource.generateConvex(from:)
The iOS SDK compiler rejected this binding: call can throw but is not marked with 'try'
ShapeResource.generateConvex(from:)
The iOS SDK compiler rejected this binding: call can throw but is not marked with 'try'