One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

ShapeResource

class · iOS 13.0+ · SDK 27.1

@MainActor @preconcurrency class ShapeResource

A representation of a shape.

Members (12)

static · iOS 13.0+

generateBox

TypeScript
static generateBoxSize(size: SDKHandle): Promise<ShapeResource>
Swift declaration
@MainActor @preconcurrency static func generateBox(size: SIMD3<Float>) -> ShapeResource

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.

static · iOS 13.0+

generateBox

TypeScript
static generateBoxWidthHeightDepth(width: number, height: number, depth: number): Promise<ShapeResource>
Swift declaration
@MainActor @preconcurrency static func generateBox(width: Float, height: Float, depth: Float) -> ShapeResource

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.

static · iOS 13.0+

generateConvex

TypeScript
static generateConvexFrom(points: Array<SDKHandle>): Promise<ShapeResource>
Swift declaration
nonisolated static func generateConvex(from points: [SIMD3<Float>]) async throws -> ShapeResource

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.

static · iOS 13.0+

generateConvex

TypeScript
static generateConvexFrom11093(mesh: MeshResource): Promise<ShapeResource>
Swift declaration
nonisolated static func generateConvex(from mesh: MeshResource) async throws -> ShapeResource

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.

static · iOS 13.0+

generateSphere

TypeScript
static generateSphere(radius: number): Promise<ShapeResource>
Swift declaration
@MainActor @preconcurrency static func generateSphere(radius: Float) -> ShapeResource

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.

static · iOS 13.0+

generateCapsule

TypeScript
static generateCapsule(height: number, radius: number): Promise<ShapeResource>
Swift declaration
@MainActor @preconcurrency static func generateCapsule(height: Float, radius: Float) -> ShapeResource

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.

static · iOS 18.0+

generateStaticMesh

TypeScript
static generateStaticMeshFrom(mesh: MeshResource): Promise<ShapeResource>
Swift declaration
@MainActor @preconcurrency static func generateStaticMesh(from mesh: MeshResource) async throws -> ShapeResource

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.

static · iOS 18.0+

generateStaticMesh

TypeScript
static generateStaticMeshPositionsFaceIndices(positions: Array<SDKHandle>, faceIndices: Array<number>): Promise<ShapeResource>
Swift declaration
nonisolated static func generateStaticMesh(positions: [SIMD3<Float>], faceIndices: [UInt16]) async throws -> ShapeResource

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.

get · iOS 18.0+

bounds

TypeScript
get bounds(): Promise<BoundingBox>
Swift declaration
nonisolated var bounds: BoundingBox { get }

Axis aligned bounding box in world space.

method · iOS 13.0+

offsetBy

TypeScript
offsetByTranslation(translation: SDKHandle): Promise<ShapeResource>
Swift declaration
@MainActor @preconcurrency func offsetBy(translation: SIMD3<Float>) -> ShapeResource

Creates a new shape resource by applying a translation. - Parameters: - translation: The translation to apply to the existing shape resource. - Returns: The transformed resource.

method · iOS 13.0+

offsetBy

TypeScript
offsetByRotationTranslation(rotation?: SDKHandle, translation?: SDKHandle): Promise<ShapeResource>
Swift declaration
@MainActor @preconcurrency func offsetBy(rotation: simd_quatf = simd_quatf(ix: 0, iy: 0, iz: 0, r: 1), translation: SIMD3<Float> = SIMD3<Float>()) -> ShapeResource

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.

method · iOS 13.0+

offsetBy

TypeScript
offsetByRotation(rotation: SDKHandle): Promise<ShapeResource>
Swift declaration
@MainActor @preconcurrency func offsetBy(rotation: simd_quatf) -> ShapeResource

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'

All RealityFoundation types →