Hey @gchiste thanks for your answer.
So, I made the test that you asked, and the answer is NO, the name that I add on the function that instantiate the entities is not the same as the name of the entity that the gesture get.
I made another test already, that was instead of add the entities on my func, I return an array of entities with all the elements.
And when I do it:
if let pinsGroup = erzbergSceneEntity.findEntity(named: PointOfInterestSystem.pinsGroupID) {
x.forEach{ e in
print(e.components.has(PointOfInterestComponent.self))
print(e.name)
pinsGroup.children.append(e)
}
}
It shown the name that I added and the component on it, but still seeing a different name when I interact with the entity on scene by TAP Gesture.
I don't know if because I am adding the elements inside of my reality view if. I need to refresh something. Did you have any tip?
Full Reality View code:
var body: some View {
@Bindable var modelData = modelData
RealityView { content in
// Add the initial RealityKit content
if let sceneEntity = try? await Entity(named: "EScene", in: realityKitContentBundle) {
// Add an ImageBasedLight for the immersive content
guard let resource = try? await EnvironmentResource(named: "ImageBasedLight") else { return }
let iblComponent = ImageBasedLightComponent(source: .single(resource), intensityExponent: 0.25)
sceneEntity.components.set(iblComponent)
sceneEntity.components.set(ImageBasedLightReceiverComponent(imageBasedLight: sceneEntity))
print("Adding Points Of Interest...")
let x = await MM_InitializePointsOfInterest(sceneEntity: sceneEntity, data: modelData)
if let pinsGroup = sceneEntity.findEntity(named: PointOfInterestSystem.pinsGroupID) {
x.forEach{ e in
print("Has POI Component? \(e.components.has(PointOfInterestComponent.self)) - with name: \(e.name)")
pinsGroup.children.append(e)
}
}
content.add(sceneEntity)
}
}
.gesture(tap)
}
var tap: some Gesture {
SpatialTapGesture()
.targetedToAnyEntity()
.onEnded { value in
print("Tap Gesture detected on: \(value.entity.name).")
if let poiComp = value.entity.components[PointOfInterestComponent.self] {
print("Point of Interest Component Id: \(poiComp.id)")
//let p : PointOfInterest = modelData.pointsOfInterest.pointsList.first(where: {$0.id == poiComp.id})!
//print(p.name)
} else {
print("Point Of Interest Component NOT FOUND!")
}
let curScale = value.entity.transform.scale.x
value.entity.transform.scale = curScale > 1 ? SIMD3(1,1,1) : SIMD3(1.4, 1.4, 1.4)
}
}
Post
Replies
Boosts
Views
Activity
I discovered WHY my Gesture tap wasn't get the component.
For some reason, when I clone the Entity that I want to instantiate and add my custom component, It's creating a ROOT element over the cloned entity.
To be more clear:
This print:
print("Tap Gesture detected on: \(value.entity.name) parent with name: \(value.entity.parent?.name)")
Generates this output:
Tap Gesture detected on: PointOfInterest parent with name: Optional("21BB3CB1-8EAC-4645-B154-C8D15ACB8858")
WHERE the name of my cloned component was set to it's UUID string v alue.
So It's visible that the gesture was got on the original root element (where the collider and input components was added) but my component was added one level above.
Someone could explain to me why when I cloned:
let pin = await pinObject.clone(recursive: true)
pin.name = poiData.id
the structure of my entity changed to have a new ROOT element?
Hey, You can use the WorldProvider to do it:
public struct WorldDataProvider {
private let arkitSession = ARKitSession()
private let worldTrackingProvider = WorldTrackingProvider()
func setUpSession() {
Task {
do {
try await arkitSession.run([worldTrackingProvider])
} catch {
print("Error: \(error)")
}
}
}
func getDeviceTransform() -> Transform? {
guard let deviceAnchor =
worldTrackingProvider.queryDeviceAnchor(atTimestamp: CACurrentMediaTime())
else { return nil }
return Transform(matrix: deviceAnchor.originFromAnchorTransform)
}
With that you can get the DeviceAnchor and obtain orientation, position....
You need to start the session before try to get the device position.
More info:
https://developer.apple.com/documentation/arkit/worldtrackingprovider
@kandao-xr I Believe that you are seeing this increase of brightness, because on your shader, you are adding the left image for both, LEFT camera index and MONO, that could be drawing two times (duplicating the brigthness of the image) when rendering the left Eye. Could you test just remove the Connection between left-image -> [mono]CameraIndex, to see if will solve?