interiorInstance.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 _INTERIORINSTANCE_H_
  23. #define _INTERIORINSTANCE_H_
  24. #ifndef _SCENEZONESPACE_H_
  25. #include "scene/zones/sceneZoneSpace.h"
  26. #endif
  27. #ifndef _INTERIORRES_H_
  28. #include "interior/interiorRes.h"
  29. #endif
  30. #ifndef _INTERIORLMMANAGER_H_
  31. #include "interior/interiorLMManager.h"
  32. #endif
  33. #ifndef _BITVECTOR_H_
  34. #include "core/bitVector.h"
  35. #endif
  36. #ifndef _COLOR_H_
  37. #include "core/color.h"
  38. #endif
  39. #ifndef _INTERIOR_H_
  40. #include "interior.h"
  41. #endif
  42. #ifndef _REFLECTOR_H_
  43. #include "scene/reflector.h"
  44. #endif
  45. #ifndef __RESOURCE_H__
  46. #include "core/resource.h"
  47. #endif
  48. class AbstractPolyList;
  49. class InteriorSubObject;
  50. class InteriorResTrigger;
  51. class MaterialList;
  52. class TextureObject;
  53. class Convex;
  54. class SFXProfile;
  55. class SFXEnvironment;
  56. class PhysicsBody;
  57. /// Instance of a DIF interior.
  58. class InteriorInstance : public SceneZoneSpace
  59. {
  60. public:
  61. friend class Interior;
  62. typedef SceneZoneSpace Parent;
  63. static bool smDontRestrictOutside;
  64. static F32 smDetailModification;
  65. protected:
  66. enum UpdateMaskBits
  67. {
  68. InitMask = Parent::NextFreeMask << 0,
  69. AlarmMask = Parent::NextFreeMask << 1,
  70. // Reserved for light updates (8 bits for now)
  71. _lightupdate0 = Parent::NextFreeMask << 2,
  72. _lightupdate1 = Parent::NextFreeMask << 3,
  73. _lightupdate2 = Parent::NextFreeMask << 4,
  74. _lightupdate3 = Parent::NextFreeMask << 5,
  75. _lightupdate4 = Parent::NextFreeMask << 6,
  76. _lightupdate5 = Parent::NextFreeMask << 7,
  77. _lightupdate6 = Parent::NextFreeMask << 8,
  78. _lightupdate7 = Parent::NextFreeMask << 9,
  79. SkinBaseMask = Parent::NextFreeMask << 10,
  80. NextFreeMask = Parent::NextFreeMask << 11,
  81. };
  82. enum
  83. {
  84. LightUpdateBitStart = 3,
  85. LightUpdateBitEnd = 10
  86. };
  87. enum AlarmState {
  88. Normal = 0,
  89. Alarm = 1
  90. };
  91. /// Alarm state of the interior
  92. bool mAlarmState;
  93. /// File name of the interior this instance encapuslates
  94. StringTableEntry mInteriorFileName;
  95. /// Hash for interior file name, used for sorting
  96. U32 mInteriorFileHash;
  97. /// Interior managed by resource manager
  98. Resource<InteriorResource> mInteriorRes;
  99. /// Forced LOD, if -1 auto LOD
  100. S32 mForcedDetailLevel;
  101. /// CRC for the interior
  102. U32 mCRC;
  103. /// Handle to the light manager
  104. LM_HANDLE mLMHandle;
  105. Convex* mConvexList;
  106. PhysicsBody* mPhysicsRep;
  107. Vector< PlaneReflector > mPlaneReflectors;
  108. ReflectorDesc mReflectorDesc;
  109. U32 _calcDetailLevel( SceneRenderState* state, const Point3F& wsPoint );
  110. bool _loadInterior();
  111. void _unloadInterior();
  112. void _renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance* );
  113. bool _getOverlappingZones( const Box3F& aabb, const MatrixF& transform, const Point3F& scale, U32* outZones, U32& outNumZones );
  114. /// Creates a transform based on an trigger area
  115. /// @param trigger Trigger to create a transform for
  116. /// @param transform Transform generated (out)
  117. void _createTriggerTransform(const InteriorResTrigger *trigger, MatrixF *transform);
  118. // SceneObject.
  119. virtual bool onSceneAdd();
  120. virtual void onSceneRemove();
  121. public:
  122. InteriorInstance();
  123. virtual ~InteriorInstance();
  124. StringTableEntry getInteriorFileName() { return mInteriorFileName; }
  125. S32 getSurfaceZone(U32 surfaceindex, Interior *detail);
  126. /// Exports the interior to a Collada file
  127. /// @param bakeTransform Bakes the InteriorInstance's transform into the vertex positions
  128. void exportToCollada(bool bakeTransform = false);
  129. /// Returns the Light Manager handle
  130. LM_HANDLE getLMHandle() { return(mLMHandle); }
  131. /// Reads the lightmaps of the interior into the provided pointer
  132. /// @param lightmaps Lightmaps in the interior (out)
  133. bool readLightmaps(GBitmap ****lightmaps);
  134. /// This is used to determine just how 'inside' a point is in an interior.
  135. /// This is used by the environmental audio code for audio properties and the
  136. /// function always returns true.
  137. /// @param pos Point to test
  138. /// @param pScale How inside is the point 0 = totally outside, 1 = totally inside (out)
  139. bool getPointInsideScale(const Point3F & pos, F32 * pScale); // ~0: outside -> 1: inside
  140. /// Returns the interior resource
  141. Resource<InteriorResource> & getResource() {return(mInteriorRes);} // SceneLighting::InteriorProxy interface
  142. /// Returns the CRC for validation
  143. U32 getCRC() { return(mCRC); }
  144. /// @name Alarm States
  145. /// @{
  146. /// This returns true if the interior is in an alarm state. Alarm state
  147. /// will put different lighting into the interior and also possibly
  148. /// have an audio element also.
  149. bool inAlarmState() {return(mAlarmState);}
  150. /// This sets the alarm mode of the interior.
  151. /// @param alarm If true the interior will be in an alarm state next frame
  152. void setAlarmMode(const bool alarm);
  153. /// @}
  154. /// @name Subobject access interface
  155. /// @{
  156. /// Returns the number of detail levels for an object
  157. U32 getNumDetailLevels();
  158. /// Gets the interior associated with a particular detail level
  159. /// @param level Detail level
  160. Interior* getDetailLevel(const U32 level);
  161. /// Sets the detail level to render manually
  162. /// @param level Detail level to force
  163. void setDetailLevel(S32 level = -1) { mForcedDetailLevel = level; }
  164. /// @}
  165. // SimObject.
  166. DECLARE_CONOBJECT( InteriorInstance );
  167. virtual bool onAdd();
  168. virtual void onRemove();
  169. virtual void inspectPostApply();
  170. static void initPersistFields();
  171. static void consoleInit();
  172. // NetObject.
  173. virtual U32 packUpdate( NetConnection* conn, U32 mask, BitStream* stream );
  174. virtual void unpackUpdate( NetConnection* conn, BitStream* stream );
  175. // SceneObject.
  176. virtual bool buildPolyList(PolyListContext context, AbstractPolyList *polyList, const Box3F &box, const SphereF &sphere);
  177. virtual bool castRay(const Point3F &start, const Point3F &end, RayInfo *info);
  178. virtual void buildConvex(const Box3F& box,Convex* convex);
  179. virtual void prepRenderImage( SceneRenderState *state );
  180. // SceneZoneSpace.
  181. virtual void traverseZones( SceneTraversalState* state );
  182. virtual void traverseZones( SceneTraversalState* state, U32 startZoneId );
  183. virtual U32 getPointZone( const Point3F& p );
  184. virtual bool getOverlappingZones( const Box3F& aabb, U32* outZones, U32& outNumZones );
  185. virtual bool getOverlappingZones( SceneObject* obj, U32* outZones, U32& outNumZones );
  186. private:
  187. // Protected field accessors
  188. static bool _setInteriorFile( void *object, const char *, const char *data );
  189. };
  190. #endif //_INTERIORBLOCK_H_