3D Scene Management

Overview

Torque has a modular, extensible 3D world system. Subclasses of the GuiTSCtrl override the GuiTSCtrl::processCameraQuery() and GuiTSCtrl::renderWorld() methods to define the camera orientation/FOV, and draw the 3D scene using the GFX system. GuiTSCtrl manages setting up the viewport, modelview matrix and projection matrix. The Torque example code GameTSCtrl class calls the global functions GameProcessCameraQuery() and GameRenderWorld(). GameProcessCameraQuery() returns the viewing camera of the current control object (the object in the simulation that the player is currently controlling), then GameRenderWorld makes the client scene graph object render the world.

SceneGraph

The scene graph library (engine/sceneGraph) is, on the client, responsible for traversing the world scene and determining which objects in the world should be rendered given the current camera position, and on the server, determines what objects should be sent to each client based on that client's position in the world.

The world in the SceneGraph is divided into zones - volumes of space bounded by solid areas and portals. The outside world is a single zone, while interior objects can have multiple interior zones. SceneGraph::findZone() finds the zone of a given 3D point and reports which SceneObject owns that zone. SceneGraph::rezoneObject() determines which zone or zones contain a SceneObject instance. At render time, the scene is traversed starting from the zone that contains the camera, clipping each zone's objects to the visible portal set from the zones before it. Scoping of network objects is performed in SceneGraph::scopeScene().

The scene graph traversal is complicated by transform portals. Transform portals are objects like mirrors or teleporters through which the world can be viewed using a different transform than the normal camera transform. When SceneGraph::buildSceneTree() encounters an object with a transform portal, it constructs a new SceneState object for rendering that portal's contents.

Every renderable world object in the scene derives from the SceneObject base class. As the world is traversed, visible objects are asked to prepare for rendering in accordance with the GFX system, and if it should render, prepare a RenderInstance which is returned to the GFX system. Render Instances are sorted based on both scene and batching criteria, and then delivered to the video card. This system allows, for example, an interior object with multiple translucent windows to render the building first, followed by other objects, followed by the building's windows. Objects can insert any number of images for rendering.

Environment

The environmental systems are the home for objects that render the outside world, including instances of the Sky, TerrainBlock and WaterBlock classes.

Sky

The Sky object renders the outside sky and cloud layers and maintains the visible distance and fog distance settings for the world. The sky also tracks vertical fog layers and installs them into the SceneGraph for rendering.

MegaTerrains

TerrainBlock manages multiple 512x512 blocks of heightfield terrain, and stitches them together when appropriate. Terrain heightfield data is stored and loaded using the TerrainFile resource class (Resource<TerrainFile>) so that a single terrain data file can be shared between server and client, when both are on the same execution instance.

The terrain is textured by blending base material textures into a series of clipmap based render textures, and then transferred to the video card by the clipmap texturing system for optimized performance.

Waterblocks

The WaterBlock class manages multiple blocks of water, using shaders to dynamically alter the texture in accordance with user defined material properties.

Shape Replication

Torque provides for a network optimized method of placing large amounts of shapes in your game world called Shape Replicators, which allow you to define properties to control the frequency, coverage, type, and variations of shapes throughout your game world. Instead of having to manually place each object (and then network each object individually when playing), you define coverage areas and the rest is done randomly (with determinism, so once you get a random coverage you like, you can keep it!)

Ground Cover

TGE-A 1.7 introduces a brand new way to decorate your scene--Ground Cover! Ground Cover can be considered "advanced foilage replication", and acts in a similar manner to Shape Replication, but focused on objects and foilage near the control object's location.

Interior

The interior library (engine/interior) manages the rendering, collision and IO for interior objects. The InteriorInstance SceneObject class manages a single interior. The InteriorResource class manages the data associated with one definition of an interior, multiple instances of which may exist at any one time. Interiors manage zones for the scene graph, and may have subobjects that, for example, render a mirrored view (MirrorSubObject). The InteriorLMManager class manages lightmaps for all currently loaded interiors - sharing lightmaps among instances where possible.

Interiors are converted to DIF by the tool Map2DIF (formerly known as Morian), or by utilizing the GarageGames Torque Constructor CSG modeling application. The source files are just Quake-style .map files - lists of convex physical "brushes" that define the solid areas of the interior. Special brushes are used to define zone portal boundaries and objects such as doors and platforms.

3Space (TS)

The 3Space library (engine/ts) manages the display and animation of shape models in the world. The 3Space shape resource class TSShape can be shared between multiple TSShapeInstance instances. The TSShape class manages all the static data for a shape - mesh data, animation keyframes, material lists, decal information, triggers and detail levels (for dynamically detailed shapes).

The TSShapeInstance class manages animation, rendering and detail selection for an instance of a shape. The TSShapeInstance class uses the TSThread class to manage one of the concurrently running animations on an instance. TSShapeInstance::addThread() initializes a new thread on a shape instance, and TSShapeInstance::setSequence() sets an animation sequence for a given thread. Each thread can be individually advanced in time, or can be set on a time scale that is used when all threads are advanced in TSShapeInstance::advanceTime(). A thread can also manage transitions between sequences with TSShapeInstance::transitionToSequence().

TSShape animation sequences can be composed of node/bone animation (for example, joints in an explosion), material animation (a texture animation on an explosion) and mesh animation (a morphing blob - note most mesh animations can be accomplished with node scale and rotation animations). Animations can also contain visibility tracks so that some meshes in the shape are not visible until an animation is played.

Container Database

Container maintains a database on both client and server for objects positioned in the simulation. It supports a set of functions for quickly inserting, removing and moving objects in the world (Container::addObject, Container::removeObject, Container::checkBins), as well as query functions for line, box and polyhedron intersection tests (Container::castRay, Container::collideBox, Container::findObjects).