Anchor Wall

I have created a portal and attached it to a wall using the AnchorEntity. However, I am seeking guidance on how to determine the size of the wall so that the portal can fully occupy it. Initially, I attempted to locate relevant information within the demo code, but I encountered difficulties in comprehending certain sections. I would appreciate it if someone could provide a step-by-step explanation or a reference to the appropriate code. Thank you for your assistance.

Answered by Vision Pro Engineer in 809284022

Hello @lijiaxu

You should be able to use the extent property of the anchor for the wall plane.

A small change to that sample code that demonstrates the basics:

@MainActor
func updatePlane(_ anchor: PlaneAnchor) {
    if planeAnchors[anchor.id] == nil {
        let width = anchor.geomerty.extent.width
        let height = anchor.geomerty.extent.height
         // use these two values to know the extent of the plane that has been detected
        // Keep in mind that this anchor might be updated over time as 
        // more of the wall is discovered so it would make sense to have 
        // an update algorithm in addition to the creation algorithm 
        // demonstrated in the rest of this code.

        // Add a new entity to represent this plane.
        let entity = ModelEntity(mesh: .generateText(anchor.classification.description))
        entityMap[anchor.id] = entity
        rootEntity.addChild(entity)
    }
    
    entityMap[anchor.id]?.transform = Transform(matrix: anchor.originFromAnchorTransform)
}

Please let me know if this doesn't answer the question.

I am seeking guidance on how to determine the size of the wall so that the portal can fully occupy it.

Are you looking on how to compute (in terms of geometry) the sizes of elements ? If so, could you explain what is the issue to calculate the size of the wall.

Or to find the size of the wall in an image ?

Or on how to implement in code ?

Accepted Answer

Hello @lijiaxu

You should be able to use the extent property of the anchor for the wall plane.

A small change to that sample code that demonstrates the basics:

@MainActor
func updatePlane(_ anchor: PlaneAnchor) {
    if planeAnchors[anchor.id] == nil {
        let width = anchor.geomerty.extent.width
        let height = anchor.geomerty.extent.height
         // use these two values to know the extent of the plane that has been detected
        // Keep in mind that this anchor might be updated over time as 
        // more of the wall is discovered so it would make sense to have 
        // an update algorithm in addition to the creation algorithm 
        // demonstrated in the rest of this code.

        // Add a new entity to represent this plane.
        let entity = ModelEntity(mesh: .generateText(anchor.classification.description))
        entityMap[anchor.id] = entity
        rootEntity.addChild(entity)
    }
    
    entityMap[anchor.id]?.transform = Transform(matrix: anchor.originFromAnchorTransform)
}

Please let me know if this doesn't answer the question.

Given: Width/height ratio of portal. PlaneAnchors of wall, floor and ceiling.

Goal: Attaching the portal to the wall.

Methods:

  1. Taking the ray (6DoF pose) of DeviceAnchor, HandAnchor, or eye tracking by Spatial Tap.
  2. Ray-casting the ray onto the PlaneAnchor of wall.
  3. The initial position of portal is the ray-casting point.
  4. The normal vector of portal is the normal vector of wall.
  5. Moving the center position of portal to the middle point on the wall between the floor and ceiling.
  6. Adjustment of the height of portal to the vertical distance between the floor and ceiling.

Hope this is helpful.

Anchor Wall
 
 
Q