renderShapeExample.h 5.1 KB

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