Is there a way to add gestures to an entire Reality Composer scene? I can add it to an individual entity, but it would be cool to let users place the entire scene (otherwise I lose all the Reality Composer behaviors when i just target the entity)

A way to get the entity gestures working on an entire scene is to use visualBounds(…) and create a CollisionComponent on the root entity. You can then use CollisionGroup to make sure it doesn’t interfere with any physics.

If you’re using ARView.installGestures(…) you’ll need the entity to conform to HasCollision, which may require you to create a new entity type for the root. Quick example:

// New Entity type which conforms for `HasCollision`
class CollisionAnchorEntity: Entity, HasAnchoring, HasCollision { }

// Transfer scene contents
let collisionAnchor = CollisionAnchorEntity()
    .children.append(contentsOf: originalAnchor.children)
collisionAnchor.anchoring = originalAnchor.anchoring

// Create CollisionComponent for bounds of scene
let sceneBounds = collisionAnchor
    .visualBounds(recursive: true, relativeTo: collisionAnchor)
let collisionShape = ShapeResource
    .generateBox(size: sceneBounds.extents)
collisionAnchor.collision = CollisionComponent(
                                shapes: [collisionShape]

// Install gesture on new anchor
arView.installGestures(for: collisionAnchor)
Tagged with: