Stream tracks
Stream Tracks are animations or other kinds of tracks on a timeline which exist on an asset before it is used inside Mattercraft.
Examples of stream tracks include embedded animations in a 3D model, video tracks or audio tracks.
Adding a Stream Track to a Timeline
You may play a stream track using Behavior Actions, though you will have more control over that track by adding it to a Timeline. This allows you to create interactive moments, such as automatically pausing a track or animation at a specific time, or creating a volume slider.
To learn more about creating a timeline, check out our dedicated Timeline article.
To add a stream track to a timeline, you can use the following steps:
- Click on the Animations panel to open it up
- Click on Layers if your Timeline is inside a layer or Clips if it is independent
- Find and click on the Timeline you wish to add the Stream Track to
- Go to the Timeline Clip editor and find the + (plus) icon
- Find Streams and then click on the Stream Track you wish to add to the Timeline
- Mattercraft will automatically add the Stream Track to the Timeline
Giving the timelines your stream tracks are assigned to brief but descriptive names will make them easier to manage; particularly when activating them with Behavior Actions or script.
Customizing Stream Tracks
Mattercraft will automatically add a stream track to a timeline according to how that track has been exported, however, you are able to modify the playback options for stream tracks to customize how they are played in your Mattercraft project.
To customize the playback for a stream track, you can use the following instructions:
- Find and click on the Timeline you wish to add the Stream Track to
- When the Timeline Clip editor is open, right click on the stream instance and left click on Modify stream playback…
- Adjust the values of the Stream Track’s properties and click on Done when you have finished
Playing a Stream Track with Behavior Actions
You may play a stream track from within the Mattercraft visual editor, or with custom scripts.
For more information about adding interactivity to your Mattercraft projects, consider reading our Adding interactivity article.
You can play a stream track by using the following instructions:
- Find the Node you wish to play the Stream Track with inside the Hierarchy Panel and select it
- Head to the Behavior Actions Panel and click on the + (plus) icon
- Find the Animation Actions category or the Stream Actions category and use any of the following Behavior Actions to activate the stream tracks:
Animation Action | Description |
---|---|
Set Layer Off | Resets the chosen layer to whatever values are specified for the Off state. |
Play Layer Clip | Plays the stream track's timeline. |
Pause Layer Clips | Pauses the stream track's timeline. Unless reset or played from the start, the stream track will play from this point. |
Stream Action | Description |
---|---|
Stop Stream | Stops the stream track from playing and sets the timeline Time to 0 (the start of the stream track). |
Seek Stream | Sets the Time along the timeline where the stream track should play from. Useful if you want to replay a particular section of a stream track. |
Play Stream | Plays the stream track along its timeline. Will play from whatever Time is currently set to, unless From Start is checked. |
Pause Stream | Pauses the stream track. Unless reset or played from the start, the stream track will play from this point. |
Playing a Stream Track with Script
To activate stream tracks with a script, you can use similar functions as you might with States or Timelines.
Function | Description |
---|---|
.play() |
Plays the stream track along its timeline. Will play from whatever Time is currently set to. |
.pause() |
Pauses the stream track. Unless reset or played from the start, the stream track will play from this point. |
.seek() |
Sets the Time along the timeline where stream track should play from. Useful if you want to replay a particular section of a stream track. |
.stop() |
Stops the stream track from playing and sets the timeline Time to 0 (the start of the stream track). |
An example custom behavior for playing and restarting a video component along a stream track might look like this:
// Register that this node should be listening to an event,
// in this case onPointerDown (on click or tap)
this.register(this.instance.onPointerDown, evt => {
// Play the stream track by finding the layer containing the
// stream track's timeline; and then the stream track's timeline itself
this.zcomponent.animation.layers.StreamTrackLayer.clips.StreamTrackTimeline.play();
});
// Register that the video component should be listening to the onEnded event,
// which fires when the video has finished playing
this.register(this.zcomponent.nodes.myVideo.onEnded, evt => {
// Stop the stream track (and set the Time to 0) by finding the
// layer containing the stream track timeline; and then the
// stream track timeline itself
this.zcomponent.animation.layers.StreamTrackLayer.clips.StreamTrackTimeline.stop();
// Play the stream track by finding the layer containing the
// stream track timeline; and then the stream track timeline itself
this.zcomponent.animation.layers.StreamTrackLayer.clips.StreamTrackTimeline.play();
});