The RealityAPI provides functionalities for controlling an XRSession together with all XR capable members.
Example
// Start by connecting to the XR Session constxrSessionState = awaitwebvis.getContext().connectXRSession();
// Get a list of all available XR members constxrMembers = webvis.getContext().getXRMembers();
// The local XR member is always the first one in the list constlocalXRMember = xrMembers[0];
// To kick-off modeltracking, let the XRMember enter the INIT mode webvis.getContext().enterXRMemberInitMode(localXRMember);
// You can also hardreset the modeltracker by specifying the `resetHard` option webvis.getContext().enterXRMemberInitMode(localXRMember, {resetHard:true});
// By default, enterXRMemberInitMode will fit the current model to the viewport // If you want to disable this behavior, you can set the `fitView` option to false webvis.getContext().enterXRMemberInitMode(localXRMember, {fitView:false});
// The modeltracker will try to align the virtual model and its real world counterpart. // If this process is successful, this will automatically anchor the 3D model to the SLAM pose (provided e.g. by the ARKit) // You can also manually fixate the model by calling the `exitXRMemberInitMode` method webvis.getContext().exitXRMemberInitMode(localXRMember);
Enters the initialization phase for modeltracking. This is also used to reset
the current modeltracking. It will also trigger a
XRMemberStateChangedEvent event with FIXATED set to false.
By default the modeltracking will be softreset. If you choose to reset different data
on the modeltracker you can do so by specifying the XRInitOptions.
Parameters
memberId: number
The XRMember that the operation should be applied on.
Specify initialization options. E.g. reset behavior of modeltracker. Default is softreset.
Returns Promise<boolean>
Returns a Promise which reports whether the operation
was successful or not.
exitXRMemberInitMode
exitXRMemberInitMode(memberId): Promise<boolean>
Experimental
Exits the initialization phase for modeltracking, this will also anchor the model
at the current position.
Parameters
memberId: number
The XRMember that the operation should be applied on.
Returns Promise<boolean>
Returns a Promise which reports whether the operation
was successful or not.
exportXRInitTemplate
exportXRInitTemplate(memberId): Promise<string>
Experimental
Exports init template for modeltracking.
Usage: After a successful tracking session, the learned init template data
can be exported with this function and stored for later.
Only supported if the XRMember has the MODELTRACKER capability.
Imports init template for modeltracking.
When using Model tracking, Init templates are captured
during the tracking process. This initialization data
is linked to previously visited view-points along the traveled camera path.
Once the tracking is lost the templates are used to quickly
reinitialize from similar view-points without the user having to align the
line model with the real object.
Once the init template data is imported. It will stay until enterInitMode
with resetInitTemplate set to true is called.
Only supported if the XRMember has the MODELTRACKER capability.
The quality threshold for the modeltracker must be between 0 and 1
Returns Promise<boolean>
Returns a Promise which reports whether the operation
was successful or not.
showExpertDialog
showExpertDialog(): Promise<boolean>
Returns Promise<boolean>
returns true if the operation was successfull or false if not
Deprecated
Show expert dialog for developers or advanced users
startAR
startAR(): Promise<boolean>
Returns Promise<boolean>
returns true if starting was successfull or false if it could not start AR
Deprecated
Start AR. Projects the camera stream in the background and starts searching for the given reference.
The reference is defined by setting the realproperty on the particular node via the webvis API.
E.g. webvis.setProperty(0, pluginAPI.realProperty, pluginAPI.realState.Enabled)
startXRMemberSpectate
startXRMemberSpectate(memberId): Promise<boolean>
Experimental
Puts the image stream in the background of the renderer. It will also trigger a
XRMemberStateChangedEvent event with FOLLOWING set to true.
Parameters
memberId: number
The XRMember that the operation should be applied on.
Returns Promise<boolean>
Returns a Promise which reports whether the operation
was successful or not.
stopAR
stopAR(): Promise<boolean>
Returns Promise<boolean>
returns true if stopping was successfull or false if it could not stop AR
Deprecated
Stop AR. Stop projecting the camera stream in the background and reset background to default color.
stopXRMemberSpectate
stopXRMemberSpectate(memberId): Promise<boolean>
Experimental
Stops the image stream in the background of the renderer. It will also trigger a
XRMemberStateChangedEvent event with FOLLOWING set to false.
Parameters
memberId: number
The XRMember that the operation should be applied on.
Returns Promise<boolean>
Returns a Promise which reports whether the operation
was successful or not.
unfixateXRMember
unfixateXRMember(memberId): Promise<boolean>
Experimental
Unfixates the model. The model will move with the device. It will also trigger a
XRMemberStateChangedEvent event with FIXATED set to false.
Parameters
memberId: number
The XRMember that the operation should be applied on.
Returns Promise<boolean>
Returns a Promise which reports whether the operation
was successful or not.
Did you find this page useful? Please give it a rating:
The RealityAPI provides functionalities for controlling an XRSession together with all XR capable members.
Example