Skip to main content
Version: 21 Aug 2024

MagicLeapPixelSensorFeature

NameSpace: PixelSensors

Enables the Magic Leap OpenXR Loader for Android, and modifies the AndroidManifest to be compatible with ML2.

Inherits from:
MagicLeapOpenXRFeatureWithInterception< MagicLeapPixelSensorFeature >,
MagicLeapOpenXRFeatureBase,
OpenXRFeature

Public Fields

RequiredCapabilities


public HashSet< PixelSensorCapabilityType > RequiredCapabilities { get; set; }

TypeDescription
HashSet< PixelSensorCapabilityType >The configurable capability types of a pixel sensor

Public Methods

void ApplySensorConfig

Apply a configuration to a sensor

public void ApplySensorConfig(
PixelSensorId sensorType,
PixelSensorConfigData configData
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
PixelSensorConfigDataconfigDataThe config data to apply

Details*

To configure a sensor, capabilities have to be configured iteratively

Each applied configuration can impact other capabilities.

So, when applying a sensor config, query for the other capabilities that have not been applied to get the updated range and to check if this applied config can configure the sensor

Note: Every subsequent application of the same capability for the same stream will overwrite the previous value


void ApplySensorConfig

An overloaded ApplySensorConfig that applies a float value for a capability

public void ApplySensorConfig(
PixelSensorId sensorType,
PixelSensorCapabilityType capabilityType,
float value,
uint streamIndex
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
PixelSensorCapabilityTypecapabilityTypeThe capability type
floatvalueThe float value to be applied
uintstreamIndexThe stream index

void ApplySensorConfig

An overloaded ApplySensorConfig that applies a bool value for a capability

public void ApplySensorConfig(
PixelSensorId sensorType,
PixelSensorCapabilityType capabilityType,
bool value,
uint streamIndex
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
PixelSensorCapabilityTypecapabilityTypeThe capability type
boolvalueThe bool value to be applied
uintstreamIndexThe stream index

void ApplySensorConfig

An overloaded ApplySensorConfig that applies a unsigned int value for a capability

public void ApplySensorConfig(
PixelSensorId sensorType,
PixelSensorCapabilityType capabilityType,
uint value,
uint streamIndex
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
PixelSensorCapabilityTypecapabilityTypeThe capability type
uintvalueThe unsigned int value to be applied
uintstreamIndexThe stream index

void ApplySensorConfig

An overloaded ApplySensorConfig that applies a Vector2Int value for a capability

public void ApplySensorConfig(
PixelSensorId sensorType,
PixelSensorCapabilityType capabilityType,
Vector2Int value,
uint streamIndex
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
PixelSensorCapabilityTypecapabilityTypeThe capability type
Vector2IntvalueThe Vector2Int value to be applied
uintstreamIndexThe stream index

void ClearAllAppliedConfigs

Clears all the applied configs for a sensor

public void ClearAllAppliedConfigs(
PixelSensorId sensorType
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor

void ClearSensorConfig

Clears an applied config for a capability

public void ClearSensorConfig(
PixelSensorId sensorType,
PixelSensorCapabilityType capabilityType,
uint streamIndex
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
PixelSensorCapabilityTypecapabilityTypeThe capability type
uintstreamIndexThe stream index of the capability

PixelSensorAsyncOperationResult ConfigureSensor

Configure a given sensor for the passed streams

public PixelSensorAsyncOperationResult ConfigureSensor(
PixelSensorId sensorType,
IEnumerable< uint > streams
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor to configure
IEnumerable< uint >streamsThe streams to configure

Returns: An awaitable operation result to indicate the progress of this operation. (See PixelSensorAsyncOperationResult)


PixelSensorAsyncOperationResult ConfigureSensorWithDefaultCapabilities

Configures a sensor with default capabilities

public PixelSensorAsyncOperationResult ConfigureSensorWithDefaultCapabilities(
PixelSensorId sensorType,
params uint [] streams
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
params uint []streamsThe streams to configure

Returns: An async operation object for this operation (See: PixelSensorAsyncOperationResult)


bool CreatePixelSensor

Create a pixel sensor of the given type

public bool CreatePixelSensor(
PixelSensorId sensorType
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor to create

Returns: True if the sensor was created


bool DestroyPixelSensor

Destroys a created pixel sensor

public bool DestroyPixelSensor(
PixelSensorId sensorType
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor to create

Returns: True if the sensor was destroyed


bool EnumeratePixelSensorMetaDataTypes

Gets the available metadata types for a sensor's stream.

public bool EnumeratePixelSensorMetaDataTypes(
PixelSensorId sensorType,
uint streamIndex,
out PixelSensorMetaDataType [] metaDataTypes
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
uintstreamIndexThe stream to get the metadata for
out PixelSensorMetaDataType []metaDataTypesThe types of the metadata that are supported

Details*

Note: A sensor has to be configured in order to be able to get its supported metadata types

Returns: True if the supported metadata types were fetched


bool GetConfiguredValueForSensor

Get a configured value for a sensor.

public bool GetConfiguredValueForSensor(
PixelSensorId sensorType,
uint streamIndex,
PixelSensorCapabilityType capabilityType,
out PixelSensorConfigData result
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
uintstreamIndexThe stream index to get the configured value for
PixelSensorCapabilityTypecapabilityTypeThe type of the capability
out PixelSensorConfigDataresultThe configured value

Details*

A configured value is the value that is applied to the sensor by calling ApplySensorConfig(MagicLeap.OpenXR.Features.PixelSensors.MagicLeapPixelSensorFeature.PixelSensorId,MagicLeap.OpenXR.Features.PixelSensors.MagicLeapPixelSensorFeature.PixelSensorConfigData)

Returns: True if a valid configuration was found


bool GetPixelSensorCapabilities

Get all the capabilities that a pixel sensor supports

public bool GetPixelSensorCapabilities(
PixelSensorId sensorType,
uint streamIndex,
out PixelSensorCapability [] capabilities
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the pixel sensor
uintstreamIndexThe stream index for which to get the supported capabilities for
out PixelSensorCapability []capabilitiesThe array of capabilities supported

Returns: True if the capabilities were fetched


bool GetPixelSensorFromXrPath

Get a Pixel Sensor given an XrPath String

public bool GetPixelSensorFromXrPath(
string path,
out PixelSensorId sensorId
)

Parameters

TypeNameDescription
stringpathThe XrPath string of the sensor. /pixelsensor/world/left for example
out PixelSensorIdsensorIdThe PixelSensorId associated with the sensor

Returns: True if a sensor was found, false otherwise


bool GetSensorData

Get the sensor data of a started sensor

public bool GetSensorData(
PixelSensorId sensorType,
uint streamIndex,
out PixelSensorFrame frame,
out PixelSensorMetaData [] metaData,
Allocator allocator,
long timeOut =10,
bool shouldFlipTexture =true
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor to get the data for
uintstreamIndexThe stream to get the data for
out PixelSensorFrameframeThe current frame data of the sensor
out PixelSensorMetaData []metaDataThe metadata for this frame
AllocatorallocatorAn allocator handle that will be used to allocate the memory for the underlying raw data
longtimeOutThe expected timeout for the data fetch
boolshouldFlipTextureWhether to fip the obtained texture. The data stored in the sensor could be flipped. Pass in false if the raw data is needed

Returns: True if a frame was obtained


Quaternion GetSensorFrameRotation

The sensor data stored can have differing orientations.

public Quaternion GetSensorFrameRotation(
PixelSensorId sensorType
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor to get the rotation for

Returns: The rotation of the frame data


Pose GetSensorPose

Get the sensor pose

public Pose GetSensorPose(
PixelSensorId sensorType,
Pose offset =default
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor
PoseoffsetThe offset that should be considered for the pose calculation

Returns: The pose of the sensor


PixelSensorStatus GetSensorStatus

Get the status of the sensor

public PixelSensorStatus GetSensorStatus(
PixelSensorId sensorType
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor

Returns: The status of the sensor


uint GetStreamCount

Gets the number of streams supported by a sensor

public uint GetStreamCount(
PixelSensorId sensorType
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor

Returns: The number of streams supported by the sensor


List< PixelSensorId > GetSupportedSensors

Get all the supported sensors on the device.

public List< PixelSensorId > GetSupportedSensors()

Details*

Note: This will return all the sensors the device supports, not sensors that are currently available

Returns: List of the supported sensors on the platform


bool IsCapabilityRequired

Returns if a given capability is required to configure a sensor

public bool IsCapabilityRequired(
PixelSensorCapabilityType capabilityType
)

Parameters

TypeNameDescription
PixelSensorCapabilityTypecapabilityTypeThe type of capability to check

Returns: True if the capability is required for a successful configuration of the sensor


bool QueryPixelSensorCapability

Query a particular capability of a sensor to get its valid range

public bool QueryPixelSensorCapability(
PixelSensorId sensorType,
PixelSensorCapabilityType capabilityType,
uint streamIndex,
out PixelSensorCapabilityRange capabilityRange
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor to query the capability for
PixelSensorCapabilityTypecapabilityTypeThe type of the capability to query
uintstreamIndexThe stream for which to query the capability
out PixelSensorCapabilityRangecapabilityRangeThe range of the capability. Use the return value to determine if this value is accurate or not

Returns: True if the query was successful


PixelSensorAsyncOperationResult StartSensor

Start a configured sensor

public PixelSensorAsyncOperationResult StartSensor(
PixelSensorId sensorType,
IEnumerable< uint > streams,
Dictionary< uint, PixelSensorMetaDataType[]> metaDataTypes =null
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor to start
IEnumerable< uint >streamsThe streams to start for the sensor
Dictionary< uint, PixelSensorMetaDataType[]>metaDataTypesThe types of the metadata for each stream

Returns: An awaitable operation result to indicate the progress of this operation. (See PixelSensorAsyncOperationResult)


PixelSensorAsyncOperationResult StopSensor

Stops a given sensor for the passed streams

public PixelSensorAsyncOperationResult StopSensor(
PixelSensorId sensorType,
IEnumerable< uint > streams
)

Parameters

TypeNameDescription
PixelSensorIdsensorTypeThe type of the sensor to stop
IEnumerable< uint >streamsThe streams to stop

Returns: An awaitable operation result to indicate the progress of this operation. (See PixelSensorAsyncOperationResult)


Protected Methods

MarkFunctionsToIntercept

protected virtual override void MarkFunctionsToIntercept()

Reimplements: MarkFunctionsToIntercept


OnInstanceCreate

protected override bool OnInstanceCreate(
ulong xrInstance
)

Parameters

TypeNameDescription
ulongxrInstance

OnInstanceDestroy

protected override void OnInstanceDestroy(
ulong xrInstance
)

Parameters

TypeNameDescription
ulongxrInstance

Public Attributes

FeatureId


public const string FeatureId = "com.magicleap.openxr.feature.ml2_pixel_sensor";


PixelSensorCapabilityRangeType

Gets the capability range type and the capability data type for a sensor's capability


public PixelSensorCapabilityRangeType;

Parameters

TypeNameDescription
sensorTypeThe type of the sensor
streamIndexThe stream index to query the capability for
capabilityTypeThe capability type

Returns: The range type and the data type for the capability


Protected Attributes

UsesExperimentalExtensions


protected override bool UsesExperimentalExtensions => true;


Public Events

OnSensorAvailabilityChanged

public Action< PixelSensorId, bool > OnSensorAvailabilityChanged()