I'm running into a confusing difference in the way SpatialTapGesture locations are handled when the targeted entities are children of AnchorEntities.
Context: I'm wanting to create entities at points on interactable entities where the user taps.
The following code snippet works fine with non-anchored entities, but produces incorrect coordinates.
func convertLocation(_ value: EntityTargetValue<SpatialTapGesture.Value>) -> SIMD3<Float> {
return value.convert(value.location3D, from: .local, to: .scene)
}
func handleTap(_ value: EntityTargetValue<SpatialTapGesture.Value>, material: SimpleMaterial) {
let location3D = convertLocation(value)
let tap = createSphereEntity(0.01, material: material, interactable: false)
tap.position = location3D
value.entity.addChild(tap, preservingWorldTransform: true)
}
and, for reference, this is the gesture modifier attached to my RealityView:
.gesture(SpatialTapGesture().targetedToAnyEntity().onEnded({ value in
let material = SimpleMaterial(color: .systemPink, roughness: 0.1, isMetallic: true)
handleTap(value, material: material)
}))
I've tried numerous combinations... .local, .global, .named for CoordinateSpace, .scene, anchor name, entity name etc for SceneRealityCoordinateSpace... preserving world transform and not, adding the new entity to the tapped entity, directly to the anchor, etc.
anyone have any ideas?
also, i noticed that in the docs for NamedCoordinateSpace it mentions
static var immersiveSpace: NamedCoordinateSpace
but no such static property exists for me?
cheers,
Mike
The simulation part of the quote above isn't really relevant to your problem, to put it more concisely, "AnchorEntities exist in an independent coordinate space". This means there is no way for you to take the value from a tap on something in an AnchorEntities hierarchy and convert it to another coordinate space, because you don't have access to the relationship between those coordinate spaces.