renderShapeExample.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_REFACTOR(RenderShapeExample, Shape)
  58. // The actual shape instance
  59. TSShapeInstance* mShapeInstance;
  60. public:
  61. RenderShapeExample();
  62. virtual ~RenderShapeExample();
  63. // Declare this object as a ConsoleObject so that we can
  64. // instantiate it into the world and network it
  65. DECLARE_CONOBJECT(RenderShapeExample);
  66. //--------------------------------------------------------------------------
  67. // Object Editing
  68. // Since there is always a server and a client object in Torque and we
  69. // actually edit the server object we need to implement some basic
  70. // networking functions
  71. //--------------------------------------------------------------------------
  72. // Set up any fields that we want to be editable (like position)
  73. static void initPersistFields();
  74. // Allows the object to update its editable settings
  75. // from the server object to the client
  76. void inspectPostApply() override;
  77. // Handle when we are added to the scene and removed from the scene
  78. bool onAdd() override;
  79. void onRemove() override;
  80. // Override this so that we can dirty the network flag when it is called
  81. void setTransform( const MatrixF &mat ) override;
  82. // This function handles sending the relevant data from the server
  83. // object to the client object
  84. U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ) override;
  85. // This function handles receiving relevant data from the server
  86. // object and applying it to the client object
  87. void unpackUpdate( NetConnection *conn, BitStream *stream ) override;
  88. //--------------------------------------------------------------------------
  89. // Object Rendering
  90. // Torque utilizes a "batch" rendering system. This means that it builds a
  91. // list of objects that need to render (via RenderInst's) and then renders
  92. // them all in one batch. This allows it to optimized on things like
  93. // minimizing texture, state, and shader switching by grouping objects that
  94. // use the same Materials.
  95. //--------------------------------------------------------------------------
  96. // Create the geometry for rendering
  97. void createShape();
  98. // This is the function that allows this object to submit itself for rendering
  99. void prepRenderImage( SceneRenderState *state ) override;
  100. };
  101. #endif // _RENDERSHAPEEXAMPLE_H_