![]() TGE Version 1.5.2 | |
| |
3D RenderingOverviewTorque has a modular, extensible 3D world rendering 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 OpenGL drawing commands respectively. 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.SceneGraphThe 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 one or more SceneRenderImage objects (in SceneObject::prepRenderImage()) that are then inserted into the current SceneState via SceneState::insertRenderImage(). Render images are sorted based on translucency and rendered from SceneObject::renderObject(). 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. TerrainThe terrain library (engine/terrain) is the home for objects that render the outside world, including instances of the Sky, TerrainBlock and WaterBlock classes. 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.TerrainBlock manages a single 256x256 infinitely repeating block of heightfield terrain. 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 TerrainRender static class is used by TerrainBlock instances for rendering. The TerrainRender::renderBlock() function renders the current repeating block of terrain.
The WaterBlock class manages a single block of water, which may or may not be infinitely repeating. Water is dynamically detailed based on distance, so nearby water is more highly tessellated. Though the surface of a water block is rectangular, the actual coverage of the water area can be set to seed fill from a point on the surface, allowing the water to fill a mountain crater, for example, without leaking outside the corner edges. InteriorThe 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). 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. |