Tutorial 2: Core Components

In this tutorial, we will provide more detail behind the code that we wrote in Tutorial 1: Getting Started.

This tutorial explains the core components of Argo: HvrView, HvrPlayer, HvrRenderer and HvrActor. To understand how these components fit together, you will need a basic understanding of a render loop.

1. Understanding the Render Loop

Argo renders images of realistic humans and draws these images onto a screen. You can imagine that Argo works like this:

initialise(); // set up state
while(true){
    render(); // do some rendering
}
destroy(); // clean up state

The code above won’t work, but the idea is pretty simple. This is called a “render loop”. The render loop runs on the “rendering thread”. A single iteration of the render loop is called a “frame”.

2. Argo Components

In Tutorial 1: Getting Started, we perform the following actions to render an HvrActor:

  1. Get an HvrView
  2. Create an HvrPlayer
  3. Use HvrView.setPlayer to attach the HvrPlayer to the HvrView
  4. Post an event to the HvrPlayer
  5. Use HvrPlayer.getRenderer to get an HvrRenderer
  6. Create an HvrActor
  7. Use HvrRenderer.addActor to add the actor to the HvrRenderer
  8. Now the HvrActor will draw to the screen inside of the HvrView

Looking at the steps above and the rendering loop, we can begin to understand the responsibility of all the different Hvr* classes.

  • HvrView - the container that holds the rendering loop. The HvrView configures the render loop, starts it running on the rendering thread, and provides the canvas the HvrPlayer will render onto. The HvrView owns an HvrPlayer.
  • HvrPlayer - provides the rendering loop. The HvrPlayer owns an HvrRenderer. The most simple HvrPlayer implementation (BasicPlayer) calls HvrRenderer.render during the “render” part of the render loop.
  • HvrRenderer - renders attached HvrActors onto the screen.
  • HvrActor - represents an HVRS file that can be rendered. HvrActors are created by calling HvrRenderer.addActor on an instance of HvrRenderer.

3. HvrPlayer’s Render Thread

In Tutorial 1: Getting Started, we used HvrPlayer.post to add an HvrActor to the HvrPlayer’s HvrRenderer. HvrPlayer runs in its own rendering thread; actions interacting with anything owned by an HvrPlayer or related to the HvrPlayer should be performed on the rendering thread.

Warning: In some cases, you will be able to perform these actions on a different thread without immediately crashing the application, but this is simply a silent failure that is likely to cause issues in the future.

Next Steps

Using HvrPlayer.post is a good way to run one-off actions on an HvrPlayer’s rendering thread, but it is not a good solution for adding more complicated functionality to an HvrPlayer. To solve this problem, Argo has the HvrBehaviour class. In the next tutorial we will be looking at how to use HvrBehaviour to add functionality to an HvrPlayer.

Tutorial 3: HvrBehaviours