Skip to main content

Assets

An Asset represents a resource that can be used in a Scene. Examples of such resources include images, text, audio, fonts etc.

There are two basic categories of assets:

  • Web Assets: These are assets which are loaded directly from the web (i.e. via a url)
    • e.g. Image, Audio, Font assets
  • Text Assets: These are self-contained assets which simply hold some text.
    • e.g. JavaScript, JSON, HTML assets

Every Asset has the following properties

  • id: A unique identifier for the asset.
  • name: A user-defined name (can be empty).
  • type: The mime type of the asset.
  • subtype: The mime subtype of the asset (optional).

Additionally, a WebAsset has a url property while a TextAsset has a text property.

Assets can be referenced by nodes when applicable. This referencing is done using the id property of the Asset.

To illustrate this, consider the following example:

Consider a Scene which contains the following asset in its Assets Library:

{
"id": "ufvjMqG5NMIh",
"name": "Wall Texture",
"type": "image",
"url": "https://test.com/test.png"
}

Say now that we want to use this image asset as the fillTexture of a RectangleNode. We could do this as shown below:

var rectangleNode = new physion.RectangleNode();
rectangleNode.fillTexture = "ufvjMqG5NMIh";

Asset references (e.g. the fillTexture in the example above) can only be resolved if

  • The Node that is referencing them is part of a Scene
  • The Assets Library (of the Scene) contains an asset with the given id.

Note that a single Asset can be referenced by multiple nodes. Also an Asset might be defined but not used by any node of the Scene.

If an Asset is used by at least one Node in the Scene then it cannot be removed (you first need to remove all references of the Asset before it can be removed)

Assets Library

Every Scene has an Assets Library where all of its assets are stored. Initially (when a new Scene is created) the AssetsLibrary will be empty (or it might contain some assets depending on user settings). The user can add, remove or edit the assets of the AssetsLibrary via the UI. To open the edit dialog click the Assets Library option from the Edit Menu

Keep in mind that asset modifications (i.e. adding, removing or editing assets) is not part of the undo/redo mechanism.

Adding assets

To add a new asset, click on the + button at the top-left of the dialog.

From the drop-down menu that appears, select the type of asset you would like to add. The currently supported asset types are images and text.

When adding a WebAsset (i.e. an image), the user can either manually set the url of the asset or select an asset from the set of predefined assets provided by Physion. In either case, the mime type of the asset will be automatically detected and if supported then the asset will be added.

When adding a TextAsset the user needs to further specify the subtype of the asset (e.g. plain, javascript, html, etc). Again, Physion offers a set of predefined text assets that can be selected.

Removing assets

As mentioned above, an asset can only be removed from the assets library only if it is not used.

Editing assets

The user can choose any asset from the library (by clicking on it) and then modify it. Examples of editing an asset include: updating its name, changing its url (for web assets) or changing its text (for text assets).