scale RealityView to fit parent in .windowStyle(.automatic)

Hi,

unable to have Reality View to scale when the window is resized.

Am I missing something or there is a doable way to achieve this?

I think I was able to do something similar to what you're trying to do. I am using a portal to not have to resize the actual Mesh though

In my View I'm setting up states in Entities

    @State var world = Entity()
    @State var portal = Entity()
    @State var boxEntity = ModelEntity(
        mesh: .generateBox(width: 0, height: 0, depth: 0),
        materials: []
    )
    @State var ready = 0

Then in the body of the view, within some other stuff I'm rendering this

                  GeometryReader3D { proxy in
                        ZStack {
                            Color.red // Only have this here to check the bounding box
                            RealityView { content in
                                world.components.set(WorldComponent())
                                world.addChild(boxEntity)
                                 
                                // this is the part that converts from the GeometryReader size to the portal size
                                let proxySize3d = proxy.frame(in: .local)
                                let portalDims = content.convert(proxySize3d, from: .local, to: world)

                                // create portal with converted sizes
                                portal.components.set(ModelComponent(
                                    mesh: .generatePlane(
                                        width: portalDims.extents.x,
                                        height: portalDims.extents.y
                                    ),
                                    materials: [
                                        PortalMaterial(),
                                        OcclusionMaterial()
                                    ]
                                ))
                                
                                portal.components.set(PortalComponent(target: world))
                                
                                content.add(world)
                                content.add(portal)
                            } update: { content in
                                          
                                let proxySize3d = proxy.frame(in: .local)
                                let portalDims = content.convert(proxySize3d, from: .local, to: world)
                                portal.components.set(ModelComponent(
                                    mesh: .generatePlane(
                                        width: portalDims.extents.x,
                                        height: portalDims.extents.y
                                    ),
                                    materials: [
                                        PortalMaterial(),
                                        OcclusionMaterial()
                                    ]
                                ))
                                
                                if let material = boxMaterial {
                                    boxEntity.components.set(ModelComponent(
                                        mesh: MeshResource.generateBox(
                                            width: boxtype.inMeters.width,
                                            height: boxtype.inMeters.height,
                                            depth: boxtype.inMeters.length
                                        ),
                                        materials: [SimpleMaterial(...color and things)]
                                    ))
                                    boxEntity.transform.rotation = simd_quatf(angle: 45, axis: SIMD3(.y))
                                } else {
                                    self.ready = self.ready + 1
                                }
                            }

Now when I resize my window, the portal also gets resized to match the ZStack.. The portal still shows up a little ahead of the 2D window though, not sure why :/

scale RealityView to fit parent in .windowStyle(.automatic)
 
 
Q