Post

Replies

Boosts

Views

Activity

Attachment-like functionality in metal immersive space
I have an immersive space that is rendered using metal. Is there a way that I can position swiftUI views at coordinates relative to positions in my immersive space? I know that I can display a volume with RealityKit content simultaneously to my metal content. The volume's coordinate system specifically, it's bounds, does not, coincide with my entire metal scene. One approach I thought of would be to open two views in my immersive space. That way, I could simply add Attachment's to invisible RealityKit Entities in one view at positions where I have content in my metal scene. unfortunately it seems that, while I can declare an ImmersiveSpace be composed of multiple RealityViews ImmersiveSpace(){ RealityView { content in // load first view } update: { content in // update } } RealityView{ content in //load second view } } update: { content in //update } } That results in two coinciding realty kit views in the immersive space. I can not however do something like this: ImmersiveSpace(){ CompositorLayer(configuration: ContentStageConfiguration()){ layerRenderer in //set up my metal renderer and stuff } RealityView{ content in //set up a view where I could use attachments } update: { content in } }
2
0
505
Jun ’24
Act on @state changes only when that state has changed
I have a RealityKitView, and I want to update my scene when some @State value has changed, but I only want to take this action on the frame that the change happens. assuming I have something like @State private var someState = false in my update I want to take actions like this. RealityView { content in // Add the initial RealityKit content } update: { content in //I want to do something only when someState has changed. if(someState != lastValueForSomeState){ //do something to my content that Is expensive and //shouldn't happen every time state changes } lastValueForSomeState = someState } I am aware that I can use the .onChange(of:) modifier to do normal ui operations, but I don't know where or if I can declare it in a place where I have access to the RealityKitContent. I can also imagine ways I could do this with components and systems, but it seems like I should be able to do this without going there. is there some mechanism I'm missing for this?
3
0
681
Nov ’23