Skip to content
MaverickAl edited this page May 15, 2018 · 4 revisions

The code in Scene is the higher level code associated with rendering the game world.

RenderNode

A render node is a single drawable item with two virtual functions, Draw and VisibilityUpdate. Anything that you wish to render as part of the game scene should inherit from RenderNode and implement atleast Draw. VisibilityUpdate is for updating buffers that aren't required if not visible.

You control the order render nodes are drawn by using the following functions:

void SetLayer(Layer eLayer);
void SetPriority(uint8 uPriority);

Using SetRenderMask you can set flags to determine which scene contexts will draw this RenderNode.

void SetRenderMask(uint32 uMask);

These can be through of as major and minor values. The lower value layers will be rendered first. Render nodes in the same layer will be sorted such that those with the lowest priority will be rendered first.

RenderGroup

RenderGroups are used for batching RenderNodes which should use the same bounds for visibility checking (such as multiple draw calls on a single model or multiple emitters on a single particle effect). Where level of details are available it will also control which to use based on the view.

Scene

The Scene class is responsible for tracking all of RenderNodes in the world. In theory it should be possible to have multiple scenes. Scenes can be used to ViewContexts and ShadowContexts, both of which inherit from SceneContext.

SceneContext

A scene context is essentially a view into that scene, such as a frustum for a spot light, or the players view. When the scene is updated for each active scene context the scene will add all of the RenderNodes visible to that scene context. Apart from the visiblity check all SceneContexts also have a render mask.
Shadow contexts default to having the mask RENDER_MASK_SHADOW_CAST, so that only things tagged as shadow casters will be drawn by a shadow context.
View contexts default to RENDER_MASK_ALL (which is every bit except RENDER_MASK_SHADOW_CAST). As it is a bitfield your render node can be set to RENDER_MASK_ALL|RENDER_MASK_SHADOW_CAST if it should cast shadows but does not have optimized shadow geometry.

Model

The scene library also includes all of the model code. The best way to use these in game is using the ModelComponent. So long as your entity has a TransformComponent, MatrixComponent and ModelComponent it should operate correctly. To move the model you should update the base entities TransformComponent rather than attempting to access the model runtime data.

When using a model component every bone in a model will become its own entity, for details on how to add components to this automatically generated entities see Component entity system coding.

You can override model material variables at runtime by calling OverrideVariable (see the OverrideColorEvent in ModelEvents for an example). For details on how to specify model shaders and associate material variables see Ayataka Model Loader (note the FBX importer currently does not support multiple materials).

If you want animations you should add a ModelAnimComponent. By default all FBX files when converted output their animations as .vskla files.

ModelComponent:
  name: test/test.vmdf
ModelAnimComponent:
 name: "VPB/Animations/Test.vpb"

The name in ModelAnimComponent is not a name of an animation you want to play, rather it is the name of a yml file Data\VPB\Animations. This yml file should contain a single Usg::SkeletalAnim::AnimChain, e.g.

VPB/Animations/Test.yml:

<% include Usg::SkeletalAnim %>

AnimChain:
  entryState: "State1"
  conditions:
    - name: "DoSomething"
      value: false    
  events:
    - name: "DoSomethingEvent"
  states:
    - stateName: "State1"
      bHidden: true
      anim:
        animName:  "test/Take 001"
        playbackSpeed: 1.0
      transitions:
        - targetState: "State2"
          conditions:
            - name: "DoSomething"
              value: true
    - stateName: "State2"
      anim:
        animName:  "test/Take 001"
        playbackSpeed: 1.0
      transitions:
        - targetState: "State1"
          blendInTime: 0.2
          conditions:
            - name: "DoSomething"
              value: false

There is currently no editor for the animation states, although the above may still look familiar. At any given time a model animation is in a named state, from this state it can transition to other states based on a combination of boolean values.
These boolean values are set by sending a ModifyAnimationConditionEvent to the entity with the ModelAnimComponent.

There is currently no support for material animations either, however you can use the UVTranslation and UVRotation systems to update texture UVs manually.