Issue with .estimatedVerticalPlane

I have this book, but I’m currently remixing the furniture app from the video tutorial that was free on AR/VR week.

I would like to have a 3D wall canvas aligned with the wall/vertical plane detected.

This is proving to be harder than I thought. Positioning isn’t a issue. Much like the furniture placement app you can just get the column3 of the hittest.worldtransform and provide the new geometry this vector3 for position.

But I do not know what I have to do to get my 3D object rotated to face forward on the aligned detected plane. As I have a canvas object, the photo is on one side of the canvas. on placement, the photo is ALWAYS facing away.

I thought about applying a arbitrary rotation to the canvas to face forward but that then was only correct if I was looking north and place a canvas on a wall to my right.

I’v tried quite a few solutions on line all but one always use .existingPlaneUsingExtent. for vertical plane detections. This allows for you to get the ARPlaneAnchor from the
hittest.anchor? as ARPlaneAnchor.
if you try this when using .estimatedVerticalPlane the .anchor? is nil

I also didn’t continue down this route as my horizontal 3D objects started getting placed in the air. This maybe down to a control flow logic but I am ignoring it until the vertical canvas placement is working.

My current train of thought is to get the front vector of the canvas and rotate it towards the front facing vector of the vertical plane detected UIImage or the hittest point.

How would I get a forward vector from a 3D point. OR get the front vector from the grid image, that is a UIImage that is placed as an overlay when ARKIT detects a vertical wall?

Here is an example. The canvas is showing the back of the canvas and is not parallel with the detected vertical plane that is the column. But there is a “Place Poster Here” grid which is what I want the canvas to align with and I’m able to see the photo.

canvasBack
Things I have tried.
using .estimatedverticalplane

I don’t know how to correctly apply this matrix and eular angle results from the SO answer.

my add picture function.

func addPicture(hitTestResult: ARHitTestResult) {
    // I would like to convert estimate hitTest to a anchorpoint
    // it is easier to rotate a node to a anchorpoint over calculating eularAngles
    // we have all detected anchors in the _Renderer SCNNode. however there are
    
    // Get the current furniture item, correct its position if necessary,
    // and add it to the scene.
    let picture = pictureSettings.currentPicturePiece()
    
    //look for the vertical node geometry in verticalAnchors
    if let hitPlaneAnchor = hitTestResult.anchor as? ARPlaneAnchor {
      if let anchoredNode = verticalAnchors[hitPlaneAnchor]{
        //code removed as a .estimatedVerticalPlane hittestResult doesn't get here
      }
    }else{
      // Transform hitresult to world coords
      let worldTransform = hitTestResult.worldTransform
      let anchoredNodeOrientation = worldTransform.eulerAngles
        picture.rotation.y =
          -.pi * anchoredNodeOrientation.y
        //set the transform matirs
        let positionMatris = worldTransform.columns.3
        let position = SCNVector3 (
          positionMatris.x,
          positionMatris.y,
          positionMatris.z
        )
        picture.position = position + pictureSettings.currentPictureOffset();
      
    }
    //parented to rootNode of the scene
    sceneView.scene.rootNode.addChildNode(picture)
  }

Thanks for any help available.

@ashstampede Do you still have issues with this?

Yeah, I managed to realign the model in blender. But can’t figure put how to place my object on the plan anchor that is estimated where the overlay image appears.

You might have better luck if you use raycasting instead of hitTesting. Raycasting will continue to update the position and orientation of the Anchor as more geometry is added by ARKit. Unfortunately raycasting isn’t in the latest Ray Wenderlich ARKit book, but you can find some sample code here Apple Developer Documentation