I’m working with Apple’s RoomPlan and I’m struggling to load all the nodes from the CapturedStructure
into SCNNode.
I was able to browse through the floors, doors, windows, walls and object and render them in the view, but I’m struggling to add whole in the wall for the windows or the whole in the wall for the openings
, for example.
I have tried several solutions and I was able to render the usdz
file into the SCNView, and I noticed that usually the window and the wall are in a group and that was the last thing I tried.
This is the code that I’m using to merge the wall and the opening together, but I had no success, even the window isn’t working as expected.
func createWallWithOpenings(wall: CapturedRoom.Surface, openings: [CapturedRoom.Surface]) -> SCNNode {
let wallNode = SCNNode()
// Define the wall geometry
let wallWidth = CGFloat(wall.dimensions.x)
let wallHeight = CGFloat(wall.dimensions.y)
let wallThickness: CGFloat = 0.01
let wallGeometry = SCNBox(width: wallWidth, height: wallHeight, length: wallThickness, chamferRadius: 0)
// Create the wall node
let wall2 = SCNNode(geometry: wallGeometry)
wall2.simdTransform = wall.transform
// wall2.position = SCNVector3(wall.transform.position.x, wall.transform.position.y, wall.transform.position.z)
// Create materials
let wallMaterial = SCNMaterial()
wallMaterial.diffuse.contents = UIColor.gray // Your wall texture or color
wallMaterial.blendMode = .alpha
wall2.geometry?.materials = [wallMaterial]
// Add wall node to wallNode
wallNode.addChildNode(wall2)
// Subtract openings
for opening in openings {
if opening.parentIdentifier == wall.identifier {
let openingWidth = CGFloat(opening.dimensions.x)
let openingHeight = CGFloat(opening.dimensions.y)
let openingThickness: CGFloat = 0.4
let openingGeometry = SCNBox(width: openingWidth, height: openingHeight, length: openingThickness, chamferRadius: 0)
let openingNode = SCNNode(geometry: openingGeometry)
openingNode.simdTransform = opening.transform
// openingNode.position = SCNVector3(opening.transform.columns.3.x, opening.transform.columns.3.y, opening.transform.columns.3.z)
// Create material for the opening (transparent)
let openingMaterial = SCNMaterial()
openingMaterial.diffuse.contents = UIImage(named: "window-texture.png")
openingMaterial.emission.contents = UIColor.clear
openingMaterial.isDoubleSided = true
openingMaterial.blendMode = .alpha
openingNode.geometry?.materials = [openingMaterial]
// Subtract the opening from the wall
wallNode.addChildNode(openingNode)
}
}
return wallNode
}
As you can see in the image below, you can notice that the wall neither the wall nor the opening is transparent, even though I positioned them correctly in the Scene.
I would appreciate any help here, because I’m running out of ideas and it should be possible to be done, because when I render the usdz
file, I can see all the nodes and the window and the openings are there and the only reason I don’t use the object rendered by the usdz
is that I lose some information like:
- Node width, node height, material and so on