Created
February 5, 2018 21:18
-
-
Save manbod/efbced7034c1253bfa44d495c061c988 to your computer and use it in GitHub Desktop.
A TrackedPlanesController (ARScene.Listener interface implementation) that tracks planes and renders a surface on them. onAnchorFound is an interface method implemented by TrackedPlanesController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onAnchorFound(ARAnchor arAnchor, ARNode arNode) { | |
// Spawn a visual plane if a PlaneAnchor was found | |
if (arAnchor.getType() == ARAnchor.Type.PLANE){ | |
ARPlaneAnchor planeAnchor = (ARPlaneAnchor)arAnchor; | |
// Create the visual geometry representing this plane | |
Vector dimensions = planeAnchor.getExtent(); | |
Surface plane = new Surface(1,1); | |
plane.setWidth(dimensions.x); | |
plane.setHeight(dimensions.z); | |
// Set a default material for this plane. | |
Material material = new Material(); | |
material.setDiffuseColor(Color.parseColor("#BF000000")); | |
plane.setMaterials(Arrays.asList(material)); | |
// Attach it to the node | |
Node planeNode = new Node(); | |
planeNode.setGeometry(plane); | |
planeNode.setRotation(new Vector(-Math.toRadians(90.0), 0, 0)); | |
planeNode.setPosition(planeAnchor.getCenter()); | |
// Attach this planeNode to the anchor's arNode | |
arNode.addChildNode(planeNode); | |
surfaces.put(arAnchor.getAnchorId(), planeNode); | |
// Attach click listeners to be notified upon a plane onClick. | |
planeNode.setClickListener(new ClickListener() { | |
@Override | |
public void onClick(int i, Node node, Vector vector) { | |
for (ClickListener listener : mPlaneClickListeners){ | |
listener.onClick(i, node, vector); | |
} | |
} | |
@Override | |
public void onClickState(int i, Node node, ClickState clickState, Vector vector) { | |
//No-op | |
} | |
}); | |
// Finally, hide isTracking UI if we haven't done so already. | |
hideIsTrackingLayoutUI(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment