Struct Anchor

Source
#[repr(C)]
pub struct Anchor(pub NonNull<_AnchorT>);
Expand description

An Anchor in StereoKit is a completely virtual pose that is pinned to a real-world location. They are creatable via code, generally can persist across sessions, may provide additional stability beyond the system’s 6dof tracking, and are not physical objects!

This functionality is backed by extensions like the Microsoft Spatial Anchor, or the Facebook Spatial Entity. If a proper anchoring system isn’t present on the device, StereoKit will fall back to a stage- relative anchor. Stage-relative anchors may be a good solution for devices with a consistent stage, but may be troublesome if the user adjusts their stage frequently.

A conceptual guide to Anchors:

  • A cloud anchor is an Anchor
  • A QR code is not an Anchor (it’s physical)
  • That spot around where your coffee usually sits can be an Anchor
  • A semantically labeled floor plane is not an Anchor (it’s physical)

https://stereokit.net/Pages/StereoKit/Anchor.html

§Examples

use stereokit_rust::{anchor::{Anchor, AnchorCaps}, maths::Pose};

let storable = !(Anchor::get_capabilities() & AnchorCaps::Storable).is_empty();
let stability = !(Anchor::get_capabilities() & AnchorCaps::Stability).is_empty();
if storable || stability {
    // create an anchor in center of the world
    let anchor = Anchor::from_pose(Pose::default()).expect("What?!!!?");
    anchor.try_set_persistent(true);
}

Tuple Fields§

§0: NonNull<_AnchorT>

Implementations§

Source§

impl Anchor

Source

pub fn find<S: AsRef<str>>(id: S) -> Result<Anchor, StereoKitError>

Searches the asset list for an anchor with the given Id. https://stereokit.net/Pages/StereoKit/Anchor/Find.html

  • id - The Id to search for.

see also anchor_find

§Examples
use stereokit_rust::anchor::Anchor;

let my_anchor = Anchor::find("the_anchor that doesn't exist");
assert!(my_anchor.is_err());
Source

pub fn clone_ref(&self) -> Anchor

Creates a clone of the same reference. Basically, the new variable is the same asset. This is what you get by calling find() method. https://stereokit.net/Pages/StereoKit/Anchor/Find.html

see also anchor_find()

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose};

// create an anchor in center of the world
if let Ok(anchor) = Anchor::from_pose(Pose::default()){;
    let same = anchor.clone_ref();
    assert_eq!(same.get_id(), anchor.get_id());
}
Source

pub fn from_pose(pose: impl Into<Pose>) -> Result<Anchor, StereoKitError>

This creates a new Anchor from a world space pose. https://stereokit.net/Pages/StereoKit/Anchor/FromPose.html

  • pose - A world space pose for the new Anchor

see also anchor_create

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose};

// create an anchor in center of the world
if let Ok(anchor) = Anchor::from_pose(Pose::default()){;
    anchor.try_set_persistent(true);
}
Source

pub fn id<S: AsRef<str>>(&mut self, id: S) -> &mut Self

Gets or sets the unique identifier of this asset resource! This can be helpful for debugging, managing your assets, or finding them later on! This is StereoKit’s asset ID, and not the system’s unique Name for the anchor. https://stereokit.net/Pages/StereoKit/Anchor/Id.html

  • id - The new id for this Anchor.

see also anchor_set_id

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose};

// create an anchor in center of the world
if let Ok(mut anchor) = Anchor::from_pose(Pose::default()){;
    anchor.id("my_anchor");
    assert_eq!(anchor.get_id(), "my_anchor");
}
Source

pub fn clear_store()

This will remove persistence from all Anchors the app knows about, even if they aren’t tracked. https://stereokit.net/Pages/StereoKit/Anchor/ClearStored.html

see also anchor_clear_stored

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose};

Anchor::clear_store();
assert_eq!(Anchor::anchors().get_count(), 0);
assert_eq!(Anchor::new_anchors().get_count(), 0);
Source

pub fn anchors() -> AnchorIter

Get an iterator of all Anchors that exist in StereoKit at the current moment. https://stereokit.net/Pages/StereoKit/Anchor/Anchors.html

see also anchor_get_count anchor_get_index

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose};

assert_eq!(Anchor::anchors().get_count(), 0);
Source

pub fn new_anchors() -> AnchorIter

Get an iterator of all Anchors that are new to StereoKit this frame. https://stereokit.net/Pages/StereoKit/Anchor/Anchors.html

see also anchor_get_new_count anchor_get_new_index

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose};

assert_eq!(Anchor::new_anchors().get_count(), 0);
Source

pub fn try_set_persistent(&self, persistent: bool) -> bool

This will attempt to make or prevent this Anchor from persisting across app sessions. You may want to check if the system is capable of persisting anchors via Anchors.Capabilities, but it’s possible for this to fail on the OpenXR runtime’s side as well. https://stereokit.net/Pages/StereoKit/Anchor/TrySetPersistent.html

see also anchor_try_set_persistent

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose};

// create an anchor in center of the world
if let Ok(mut anchor) = Anchor::from_pose(Pose::default()){;
    assert_eq!(anchor.get_persistent(), false);
    anchor.try_set_persistent(true);
    assert_eq!(anchor.get_persistent(), true);
}
Source

pub fn get_capabilities() -> AnchorCaps

This describes the anchoring capabilities of the current XR anchoring backend. Some systems like a HoloLens can create Anchors that provide stability, and can persist across multiple sessions. Some like SteamVR might be able to make a persistent Anchor that’s relative to the stage, but doesn’t provide any stability benefits. https://stereokit.net/Pages/StereoKit/Anchor/Capabilities.html

see also anchor_get_capabilities

§Examples
use stereokit_rust::{anchor::{Anchor, AnchorCaps}, maths::Pose};

let storable = !(Anchor::get_capabilities() & AnchorCaps::Storable).is_empty();
let stability = !(Anchor::get_capabilities() & AnchorCaps::Stability).is_empty();
if storable || stability {
    // create an anchor in center of the world
    let anchor = Anchor::from_pose(Pose::default()).expect("What?!!!?");
    anchor.try_set_persistent(true);
}
Source

pub fn get_id(&self) -> &str

The id of this anchor. This is StereoKit’s asset ID, and not the system’s unique Name for the anchor. https://stereokit.net/Pages/StereoKit/Anchor/Id.html

see also anchor_get_id see example in Anchor::id

Source

pub fn get_pose(&self) -> Pose

The most recently identified Pose of the Anchor. While an Anchor will generally be in the same position once discovered, it may shift slightly to compensate for drift in the device’s 6dof tracking. Anchor Poses when tracked are more accurate than world-space positions. https://stereokit.net/Pages/StereoKit/Anchor/Pose.html

see also anchor_get_pose

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose};

// create an anchor in center of the world
if let Ok(mut anchor) = Anchor::from_pose(Pose::default()){;
    assert_eq!(anchor.get_pose(), Pose::default());
}
Source

pub fn get_tracked(&self) -> BtnState

Does the device consider this Anchor to be tracked? This doesn’t require the Anchor to be visible, just that the device knows where this Anchor is located. https://stereokit.net/Pages/StereoKit/Anchor/Tracked.html

see also anchor_get_tracked

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose, system::BtnState};

// create an anchor in center of the world
if let Ok(mut anchor) = Anchor::from_pose(Pose::default()){;
    assert_eq!(anchor.get_tracked(), BtnState::Active);
}
Source

pub fn get_persistent(&self) -> bool

Will this Anchor persist across multiple app sessions? You can use TrySetPersistent to change this value. https://stereokit.net/Pages/StereoKit/Anchor/Persistent.html

see also anchor_get_persistent see example in Anchor::try_set_persistent

Source

pub fn get_name(&self) -> &str

A unique system provided name identifying this anchor. This will be the same across sessions for persistent Anchors. https://stereokit.net/Pages/StereoKit/Anchor/Name.html

see also anchor_get_name

§Examples
use stereokit_rust::{anchor::Anchor, maths::Pose, system::BtnState};

// create an anchor in center of the world
if let Ok(mut anchor) = Anchor::from_pose(Pose::default()){;
    assert_eq!(anchor.get_name().is_empty(), false);
}
Source

pub fn try_get_perception_anchor<T>(&self) -> Option<*mut T>

Tries to get the underlying perception spatial anchor for platforms using Microsoft spatial anchors. https://stereokit.net/Pages/StereoKit/Anchor/TryGetPerceptionAnchor.html

  • 'T' - The type of the spatial anchor. Must corresponds to the the Windows API type of Windows.Perception.Spatial.SpatialAnchor.
  • spatial_anchor - The spatial anchor.

returns Some(anchor) if the perception spatial anchor was successfully obtained, false otherwise.

see also anchor_get_name

Trait Implementations§

Source§

impl AsRef<Anchor> for Anchor

Source§

fn as_ref(&self) -> &Anchor

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for Anchor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Anchor

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl IAsset for Anchor

Source§

fn get_id(&self) -> &str

gets the unique identifier of this asset resource! This can be helpful for debugging, managing your assets, or finding them later on! https://stereokit.net/Pages/StereoKit/IAsset/Id.html
Source§

impl PartialEq for Anchor

Source§

fn eq(&self, other: &Anchor) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Anchor

Auto Trait Implementations§

§

impl Freeze for Anchor

§

impl RefUnwindSafe for Anchor

§

impl !Send for Anchor

§

impl !Sync for Anchor

§

impl Unpin for Anchor

§

impl UnwindSafe for Anchor

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more