admin管理员组文章数量:1279021
I want to create virtual objects on tap.
I know that I can use the gesture
call to react to gestures, but I don't see how I can access the RealityViewContent from there in order to add it to the scene or subscribe to collision events.
RealityView { content in
...
}.gesture(TapGesture().targetedToAnyEntity().onEnded{ event in
let o = create_a_square()
// I want to do this:
content.add(o);
content.subscribe(to: CollisionEvents.Began.self, on: o) ..
}
I want to create virtual objects on tap.
I know that I can use the gesture
call to react to gestures, but I don't see how I can access the RealityViewContent from there in order to add it to the scene or subscribe to collision events.
RealityView { content in
...
}.gesture(TapGesture().targetedToAnyEntity().onEnded{ event in
let o = create_a_square()
// I want to do this:
content.add(o);
content.subscribe(to: CollisionEvents.Began.self, on: o) ..
}
Share
Improve this question
edited Feb 25 at 10:16
jonrsharpe
122k30 gold badges267 silver badges474 bronze badges
asked Feb 25 at 10:15
DarkTrickDarkTrick
3,5293 gold badges30 silver badges54 bronze badges
1
- The cube sample code from apple has a really good example. I don't remember which one it is but it is the ones were you do a spatial tap gesture and a cube gets added to the scene – lorem ipsum Commented Feb 26 at 12:15
1 Answer
Reset to default 0For adding / removing entities in gestures (or other locations):
Apple's sample code adds an entity** to content
, stores it in an environment variable add uses rootEntity.addChild
and rootEntity.removeChild
later for accessing.
** In the SceneReconstruction example by Apple it's called model
. Other common names might be rootEntity.
For accessing content
to subscribe to events:
You can go with the same logic
本文标签: visionosHow to access RealityViewContent from gesture handlersStack Overflow
版权声明:本文标题:visionos - How to access RealityViewContent from gesture handlers? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741212614a2359424.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论