Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ XR Studio

texturetobinary

  • Last UpdatedFeb 19, 2025
  • 3 minute read

The texturetobinary statement can be used inside Command or Coroutine to store the content of a Texture2D node instance inside an sbinary field.

The typical use case for this command is to successively use the content of the sbinary field to mirror the texture visual content inside another Texture2D instance or to share the content of the sbinary field with another XR application instance through the XR Real-time Message Bus using shares. In this way, the content of the original Texture2D can be mirrored and viewed inside a different XR application instance.

The texturetobinary statement applies a compression to the texture image. By default, the image is encoded as a PNG with quality = 80. Both the encoding and the quality can be specified with parameters. The supported encodings are PNG, JPEG, GIF, and BMP.

Note: The texturetobinary statement is an asynchronous statement. This means that the variable might not immediately contain the updated binary value after the statement is called. The suggested approach is to chain two commands together: one to update the sbinary variable and one triggered by the update of the same variable. See the code sample below for an example.

binarytotexture and texturetobinary

The opposite of this command, namely to read the content of an sbinary field and to load it into a Texture2D node, can be achieved by using the binarytotexture command.

Platform support

This command is supported on all platforms.

XR-WIN

XR-P-WIN

XR-P-IOS

XR-P-AND

XR-P-WASM

Full support

Full support

Full support

Full support

Full support

Full support

Full support

Full support

Full support

Full support

Code example

The following code example shows encoding the content of a Texture2D node (named myTexture2D) into a PNG with quality=90 image and storing it in the sbinary field named mySBinary.

Notice that by routing the myTexture2D.updated field to the cmd_runTextureToBinary command, the content of the myTexture2D node is automatically stored in the mySBinary field every time the Texture2D is graphically updated. This might be due to a user interaction for example.

When the texturetobinary asynch statement is complete, the log command is called.

<route from="myTexture2D.updated" to="cmd_runTextureToBinary.execute" />

<Command name="cmd_runTextureToBinary">

<texturetobinary name="mySBinary.value" texture="myTexture2D" encoding="png" quality="90" />

</Command>

<route from="mySBinary.value" to="cmd_log.execute" />

<Command name="cmd_log">

<log text="%0%" />

</Command>

Fields

These are the fields for the texturetobinary statement.

Fields

Type

Use

Default value

Description


name

sstring

Mandatory

No default value

The name of the SBinary value field that will be used to store the Texture2D image data.

texture

sstring

Mandatory

No default value

The name of the Texture2D node from which the image data will be taken.

encoding

sstring

Optional

png

The encoding format to use to compress the image data that will be stored in the SBinary field.

Supported values are:

  • png

  • jpeg

  • gif

  • bmp

quality

int

Optional

80

The encoding quality to use to compress the image data (with the selected encoding) that will be stored in the SBinary field.

The value should be an integer number between 0 and 100 where 0 means maximum compression (and lowest quality) and 100 means minimum compression (and highest quality).

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in