World tracking + User position

Hi, the World tracking option is a fantastic addition! I was wondering, if it is possible to get the user position, relatively to the world or 3D object, once it is placed? For example, to trigger events when the user is close from specific points? Anyways, great job! Cheers.

2 Likes

Absolutely! The ā€œuserā€ in Zappar is just Z.camera so you can stick a TriggerRegion relative to the world anchor, and a simple visible false, enabled true plane object relative to Z.camera with a tag set to the triggerTag of the trigger region.

You can then get callbacks with the local position of the trigger in the world every frame.

Using trigger regions or raycasters between tracked nodes (such as world anchors) and other nodes like the camera used to introduce a frame delay when the local positions are reported to javascript (they are calculated using the previously rendered positions, but the tracking data is already updated for the current frame).

The latest Zappar app includes a way of removing this frame delay, just set the updatePhase property of the trigger region to Z.FramePhase.after_early_updates, which will calculate the trigger positions after early updates for the new frame (including things like gyro and tracking updates).

This is a bit hidden right now (itā€™s not exposed in Studioā€™s property list yet and not documented). You can just set it in a script node, only needs to be done once:
triggerRegion.updatePhase(Z.FramePhase.after_early_updates);

4 Likes

Thanks Simon! Itā€™s working fine :grin:
But regarding the frame delay, the ā€˜zapparā€™ keyword is not found and fires a script error.

Oops, sorry. You can just use Z. now itā€™s in the typescript definitions in Studio. I copied and pasted from an earlier test scene I was working on. Iā€™ve edited the post above now for anyone new to the thread.

3 Likes

Perfect! Thanks again!:grin:

1 Like

Iā€™m sorry to ask, but would it be possible to elaborate a little on this procedure? I have been trying to do this for a while without success. I placed a plane in the area where I want action to trigger (in my case, display a plane with text materiel on root) when user enters plane. I used ACTION in properties ā€œON TRIGGER REGION ENTERā€ and sert a state that will make a plane on root visible, but this does not seem to work. Iā€™m not clear on how to set-up a trigger region. Where could I find this info?

Thank you for your help :slight_smile:

OK! I figured it out! Didnā€™t understand that I had to first define a trigger region from NEW menu! Duh. Sorry for misunderstanding :slight_smile:

And I have just see this thread: Sipsmith Portal - Inspiration Project
With everything insideā€¦ :smile:

But I still have a question: how can we get the coordinates of the Z.camera relatively to the world? Z.Camera.position() returns always (0,0,0)ā€¦ Triggers are great, but I would like also be able to control element with their distance from specific points.

Thanks.

1 Like

In Zappar we donā€™t have a single coordinate system shared by everything in the scene. There are instead different ā€œspacesā€ - so we refer to Z.camera as ā€œcamera spaceā€, and target finders and world anchors define their own spaces. Z.camera.position() is always [0,0,0] as it is the origin of the camera space.

The Javascript side of scenes doesnā€™t have full access to all the information - for example tracked targets have their transforms set on the native side and are not directly passed on to the Javascript, so there is no API to query them.

This is where TriggerRegion comes in. You can use them in the same space if you want, so you can have a TriggerRegion relativeTo Z.camera and an object node defined as a trigger also relative to Z.camera. However their real utility is when the TriggerRegion and trigger objects are in different ā€œspacesā€, as this allows you to map coordinates of the object from the space where it is defined to the space where you want it.

In the case of user position, you want your trigger object relativeTo Z.camera and your TriggerRegion relativeTo a group in the world tracking space. If you have the shape of the TriggerRegion set to none then the trigger will always be inside the active volume of the TriggerRegion. That means every frame you can retrieve the position of the user in world space with an event handler.

Iā€™ve put together a quick demo scene to show how this works:
WorldTrackingTriggerRegionDemo.zpp (4.6 KB)

Hold down on the screen to make a trail of planes in world space. Itā€™s pretty fun :smiley:

3 Likes

So the example above shows how to get the exact position of trigger objects in the TriggerRegionā€™s coordinates. However if all you want to do is have something happen when the user enters a certain part of the world, that can be done without any code at all, just using actions ā€œon trigger enterā€ and ā€œon trigger leaveā€.

Hereā€™s a minimal example using the standard ground placement subsymbol:
WorldTrackingTriggerRegionActions.zpp (1.1 MB)

You need an object relativeTo Z.camera, with a tag set (something like ā€˜cameraTriggerā€™ is sensible). Then add a TriggerRegion anywhere you want to take an action when the user enters or leaves, and set the triggerTag property to the same tag you added to the object that you want to use as the trigger.

1 Like

Thank you so much Simon, for these precisions! Your demo is very useful and opens a lot of opportunities for cool apps! - Too bad Little Thumb didnā€™t get Zappar! :grin::+1:

1 Like

This is SO COOL!!
Thanks
Simon!!

1 Like

:eyes: I can tell youā€™ve been getting involved with this, @jvouillon ā€¦!

Hi James! :smile:
So, here it is a very basic prototype, based on Simonā€™s code. [Updated: sliders for the color and the sizeā€¦]

ARDraw-mini

4 Likes

This is great! Love the undo functionality!

This same content will also run in the new version of the ZapBox app (submitted to Apple now, so hopefully live early next week). With the ZapBox app you could update it to use a ZapBox controller to draw the lines, and perhaps link the analog trigger value to radiusā€¦

2 Likes

So we can finally get the drawing in the air picture from the kickstarter campaign that was promised!?

Steve

1 Like