Torque3D Documentation / _generateds / renderShapeExample.h

renderShapeExample.h

Engine/source/T3D/examples/renderShapeExample.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _RENDERSHAPEEXAMPLE_H_
 25#define _RENDERSHAPEEXAMPLE_H_
 26
 27#ifndef _SCENEOBJECT_H_
 28#include "scene/sceneObject.h"
 29#endif
 30#ifndef _TSSHAPEINSTANCE_H_
 31#include "ts/tsShapeInstance.h"
 32#endif
 33
 34//-----------------------------------------------------------------------------
 35// This class implements a basic SceneObject that can exist in the world at a
 36// 3D position and render itself. There are several valid ways to render an
 37// object in Torque. This class makes use of the "TS" (three space) shape
 38// system. TS manages loading the various mesh formats supported by Torque as
 39// well was rendering those meshes (including LOD and animation...though this
 40// example doesn't include any animation over time).
 41//-----------------------------------------------------------------------------
 42
 43class RenderShapeExample : public SceneObject
 44{
 45   typedef SceneObject Parent;
 46
 47   // Networking masks
 48   // We need to implement a mask specifically to handle
 49   // updating our transform from the server object to its
 50   // client-side "ghost". We also need to implement a
 51   // maks for handling editor updates to our properties
 52   // (like material).
 53   enum MaskBits 
 54   {
 55      TransformMask = Parent::NextFreeMask << 0,
 56      UpdateMask    = Parent::NextFreeMask << 1,
 57      NextFreeMask  = Parent::NextFreeMask << 2
 58   };
 59
 60   //--------------------------------------------------------------------------
 61   // Rendering variables
 62   //--------------------------------------------------------------------------
 63   // The name of the shape file we will use for rendering
 64   String            mShapeFile;
 65   // The actual shape instance
 66   TSShapeInstance*  mShapeInstance;
 67   // Store the resource so we can access the filename later
 68   Resource<TSShape> mShape;
 69
 70public:
 71   RenderShapeExample();
 72   virtual ~RenderShapeExample();
 73
 74   // Declare this object as a ConsoleObject so that we can
 75   // instantiate it into the world and network it
 76   DECLARE_CONOBJECT(RenderShapeExample);
 77
 78   //--------------------------------------------------------------------------
 79   // Object Editing
 80   // Since there is always a server and a client object in Torque and we
 81   // actually edit the server object we need to implement some basic
 82   // networking functions
 83   //--------------------------------------------------------------------------
 84   // Set up any fields that we want to be editable (like position)
 85   static void initPersistFields();
 86
 87   // Allows the object to update its editable settings
 88   // from the server object to the client
 89   virtual void inspectPostApply();
 90
 91   // Handle when we are added to the scene and removed from the scene
 92   bool onAdd();
 93   void onRemove();
 94
 95   // Override this so that we can dirty the network flag when it is called
 96   void setTransform( const MatrixF &mat );
 97
 98   // This function handles sending the relevant data from the server
 99   // object to the client object
100   U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
101   // This function handles receiving relevant data from the server
102   // object and applying it to the client object
103   void unpackUpdate( NetConnection *conn, BitStream *stream );
104
105   //--------------------------------------------------------------------------
106   // Object Rendering
107   // Torque utilizes a "batch" rendering system. This means that it builds a
108   // list of objects that need to render (via RenderInst's) and then renders
109   // them all in one batch. This allows it to optimized on things like
110   // minimizing texture, state, and shader switching by grouping objects that
111   // use the same Materials.
112   //--------------------------------------------------------------------------
113   // Create the geometry for rendering
114   void createShape();
115
116   // This is the function that allows this object to submit itself for rendering
117   void prepRenderImage( SceneRenderState *state );
118};
119
120#endif // _RENDERSHAPEEXAMPLE_H_
121