0

Using Apple's RoomPlan API, I managed to create a series of nodes representing the walls of a room. However, after applying their transform, the yaw (eulerAngles.y) ends up being a random number which makes aligning other nodes not generated as part of the room tricky.

My thought was to add all the walls as children to a parent node, then rotate the parent until the largest wall had a eulerAngle.y of 90. However, I am having trouble getting it to work right.

Code for generating the walls from a RoomPlan CapturedRoom

for scannedWall in roomScan.walls {
                
  //Generate new wall geometry
                
  let length = 0.01
  let width = scannedWall.dimensions.x
  let height = scannedWall.dimensions.y
                
   //Generate new SCNNode
   let newWallGeometry = SCNBox(
     width: CGFloat(width),
     height: CGFloat(height),
     length: CGFloat(length),
     chamferRadius: 0
   )
            
  newWallGeometry.firstMaterial?.transparency = 0.6
                
  let newWall = SCNNode(geometry: newWallGeometry)
  newWall.simdTransform = scannedWall.transform
  
  parentNode.addChildNode(newWall)
            
}
        

My initial thought was just to rotate the parent node by the difference between the longest wall's rotation and 90 degrees, but that does not seem to be correct:

parentNode.eulerAngles.y = (.pi/2 - longestWall.eulerAngles.y)

Any help would be greatly appreciated, I'm fairly new to swift/scenekit and am banging my head against a wall

nnaiman
  • 53
  • 5

0 Answers0