5

I am relatively new to swift, and trying to use Apple's RoomPlan API to create a rendering of a room without any objects inside. To do this I'm taking the list of walls given by CapturedRoom.walls and creating a series of SCNNodes using the information given. This way I can modify the room at-will in the app. However, the walls are showing up in random places? Not sure where I am going wrong:

//roomScan is a CapturedRoom object, scene is an SCNScene
for i in 0...(roomScan.walls.endIndex-1) {
 
   //Generate new wall geometry
   let scannedWall = roomScan.walls[i]
            
   let length = scannedWall.dimensions.x
   let width = 0.2
   let height = scannedWall.dimensions.y
   let newWall = SCNBox(
      width: CGFloat(width),
      height: CGFloat(height),
      length: CGFloat(length),
      chamferRadius: 0
   )
            
   newWall.firstMaterial?.diffuse.contents = UIColor.white
   newWall.firstMaterial?.transparency = 0.5
            
   //Generate new SCNNode
   let newNode = SCNNode(geometry: newWall)
   newNode.simdTransform = scannedWall.transform

   scene.rootNode.addChildNode(newNode)
}

This is what the CapturedRoom looks like

But this what my code is outputting

nnaiman
  • 53
  • 5

1 Answers1

3

Should it be the following?

let length = 0.2
let width = scannedWall.dimensions.x
let height = scannedWall.dimensions.y
mnuages
  • 13,049
  • 2
  • 23
  • 40