Instant World Tracking
Instant World Tracking lets you tracking 3D content to a point chosen by the user in the room or immediate environment around them. With this tracking type you could build a 3D model viewer that lets users walk around to view the model from different angles, or an experience that places an animated character in their room.
Before setting up instant tracking, you must first add or replace any existing camera you have in your scene. Find out more here.
To track content from a point on a surface in front of the user, use the zappar-instant
component:
<a-entity zappar-instant="placement-mode: true;" id="my-instant-tracker">
<!-- PLACE CONTENT TO APPEAR IN THE WORLD HERE -->
</a-entity>
With the placement-mode: true
parameter set, the instant tracker will let the user choose a location for the content by pointing their camera around the room. When the user indicates that they're happy with the placement, e.g. by tapping a button on-screen, remove that parameter to fix the content in that location:
<a-entity zappar-instant="placement-mode: true;" id="my-instant-tracker">
<!-- PLACE CONTENT TO APPEAR IN THE WORLD HERE -->
</a-entity>
<script>
let myInstantTracker = document.getElementById("my-instant-tracker");
document.body.addEventListener("click", () => {
myInstantTracker.setAttribute("zappar-instant", "placement-mode: false;");
})
</script>
The group provides a coordinate system that has its origin at the point that's been set, with the positive Y coordinate pointing up out of the surface, and the X and Z coordinates in the plane of the surface.
To choose the point in the user's environment that the anchor tracks from, use the anchorPoseOffset
parameter, like this:
<a-entity zappar-instant="placement-mode: true; anchorPoseOffset: 0 0 -5" id="anchor">
<!-- ... -->
</a-entity>
The parameters passed in to this function correspond to the X, Y and Z coordinates (in camera space) of the point to track. Choosing a position with X and Y coordinates of zero, and a negative Z coordinate, will select a point on a surface directly in front of the center of the screen.
This parameter defaults to 0 0 -5
when not supplied.