I'm doing an experiment integrating SwiftUI views as Materials for a SceneKit scene SCNPanel node.
It is working perfectly in iOS using UIHostingController with the following code:
Yet, when I tried to apply the same to macOS, I don't seem to be able to make the view created by NSHostingController transparent.
Invoking <infoPanelHost.view.isOpaque = false> returns an error, saying isOpaque is read-only and can't be set.
I tried subclassing NSHostingController and overriding viewWillAppear to try and make the view transparent / non-opaque, to no avail.
Tried setting everything I could think of to non-opaque as you can see, and still, the panels are opaque, show no info, and obscure the 3D entity they should overlay...
Can someone please advise?
It is working perfectly in iOS using UIHostingController with the following code:
Code Block Swift func createInfoPanel() { let panel = SCNPlane(width: 6.0, height: 6.0) let panelNode = SCNNode(geometry: panel) let infoPanelHost = SCNHostingController(rootView: helloWorld) infoPanelHost.view.isOpaque = false infoPanelHost.view.backgroundColor = SCNColor.clear infoPanelHost.view.frame = CGRect(x: 0, y: 0, width: 256, height: 256) panel.materials.first?.diffuse.contents = infoPanelHost.view panel.materials.first?.emission.contents = infoPanelHost.view panel.materials.first?.emission.intensity = 3.0 [... BillBoardConstraint etc here ...] addNodeToScene(panelNode) }
Yet, when I tried to apply the same to macOS, I don't seem to be able to make the view created by NSHostingController transparent.
Invoking <infoPanelHost.view.isOpaque = false> returns an error, saying isOpaque is read-only and can't be set.
I tried subclassing NSHostingController and overriding viewWillAppear to try and make the view transparent / non-opaque, to no avail.
Code Block Swift override func viewWillAppear() { super.viewWillAppear() self.view.wantsLayer = true self.view.layer?.backgroundColor = NSColor.clear.cgColor self.view.layer?.isOpaque = false self.view.opaqueAncestor?.layer?.backgroundColor = NSColor.clear.cgColor self.view.opaqueAncestor?.layer?.isOpaque = false self.view.opaqueAncestor?.alphaValue = 0.0 self.view.alphaValue = 0.0 self.view.window?.isOpaque = false self.view.window?.backgroundColor = NSColor.clear }
Tried setting everything I could think of to non-opaque as you can see, and still, the panels are opaque, show no info, and obscure the 3D entity they should overlay...
Can someone please advise?