interior.h 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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 _INTERIOR_H_
  23. #define _INTERIOR_H_
  24. #ifndef _COLOR_H_
  25. #include "core/color.h"
  26. #endif
  27. #ifndef _COLLISION_H_
  28. #include "collision/collision.h"
  29. #endif
  30. #ifndef _TVECTOR_H_
  31. #include "core/util/tVector.h"
  32. #endif
  33. #ifndef _MPOINT3_H_
  34. #include "math/mPoint3.h"
  35. #endif
  36. #ifndef _MPLANE_H_
  37. #include "math/mPlane.h"
  38. #endif
  39. #ifndef _MBOX_H_
  40. #include "math/mBox.h"
  41. #endif
  42. #ifndef _MSPHERE_H_
  43. #include "math/mSphere.h"
  44. #endif
  45. #ifndef _CONVEX_H_
  46. #include "collision/convex.h"
  47. #endif
  48. #ifndef _INTERIORLMMANAGER_H_
  49. #include "interior/interiorLMManager.h"
  50. #endif
  51. #ifndef _INTERIORSIMPLEMESH_H_
  52. #include "interior/interiorSimpleMesh.h"
  53. #endif
  54. #ifndef _OPTIMIZEDPOLYLIST_H_
  55. #include "collision/optimizedPolyList.h"
  56. #endif
  57. #ifndef _SCENEDATA_H_
  58. #include "materials/sceneData.h"
  59. #endif
  60. //-------------------------------------- Forward declarations
  61. class MatInstance;
  62. class Stream;
  63. class EditGeometry;
  64. class InteriorInstance;
  65. class GBitmap;
  66. class RectD;
  67. class SphereF;
  68. class MatrixF;
  69. class SceneRenderState;
  70. class MaterialList;
  71. class AbstractPolyList;
  72. class InteriorSubObject;
  73. class TranslucentSubObject;
  74. class BitVector;
  75. struct RayInfo;
  76. struct EdgeList;
  77. class SurfaceHash;
  78. class InteriorPolytope;
  79. class LightInfo;
  80. class PlaneRange;
  81. class EditInteriorResource;
  82. class GFXVertexBuffer;
  83. class GFXPrimitiveBuffer;
  84. struct RenderInst;
  85. struct GFXVertexPNTTB;
  86. struct GFXPrimitiveInfo;
  87. struct MaterialFeatureData;
  88. //--------------------------------------------------------------------------
  89. class InteriorConvex : public Convex
  90. {
  91. typedef Convex Parent;
  92. friend class Interior;
  93. friend class InteriorInstance;
  94. protected:
  95. Interior* pInterior;
  96. public:
  97. S32 hullId;
  98. Box3F box;
  99. public:
  100. InteriorConvex() { mType = InteriorConvexType; }
  101. InteriorConvex(const InteriorConvex& cv)
  102. {
  103. mObject = cv.mObject;
  104. pInterior = cv.pInterior;
  105. hullId = cv.hullId;
  106. box = box;
  107. }
  108. Box3F getBoundingBox() const;
  109. Box3F getBoundingBox(const MatrixF& mat, const Point3F& scale) const;
  110. Point3F support(const VectorF& v) const;
  111. void getFeatures(const MatrixF& mat,const VectorF& n, ConvexFeature* cf);
  112. void getPolyList(AbstractPolyList* list);
  113. };
  114. class ZoneVisDeterminer
  115. {
  116. enum Mode
  117. {
  118. FromState,
  119. FromRects
  120. };
  121. Mode mMode;
  122. SceneRenderState* mState;
  123. U32 mZoneRangeOffset;
  124. U32 mParentZone;
  125. public:
  126. ZoneVisDeterminer() : mMode(FromRects), mState(NULL) { }
  127. void runFromState(SceneRenderState*, U32, U32);
  128. void runFromRects(SceneRenderState*, U32, U32);
  129. bool isZoneVisible(const U32) const;
  130. };
  131. struct ItrPaddedPoint
  132. {
  133. Point3F point;
  134. union
  135. {
  136. F32 fogCoord;
  137. U8 fogColor[4];
  138. };
  139. };
  140. //------------------------------------------------------------------------------
  141. //-------------------------------------- CLASS NOTES
  142. // Interior: Base for all interior geometries. Contains all lighting, poly,
  143. // portal zone, bsp info, etc. to render an interior.
  144. //
  145. // Internal Structure Notes:
  146. // IBSPNode:
  147. // planeIndex: Obv.
  148. // frontIndex/backIndex: Top bit indicates if children are leaves.
  149. // Next bit indicates if leaf children are solid.
  150. //
  151. // IBSPLeafSolid:
  152. // planeIndex: obv.
  153. // surfaceIndex/surfaceCount: Polys that are on the faces of this leaf. Only
  154. // used for collision/surface info detection.
  155. //
  156. //------------------------------------------------------------------------------
  157. //------------------------------------------------------------------------------
  158. class Interior
  159. {
  160. friend class EditGeometry;
  161. friend class InteriorInstance;
  162. friend class InteriorProxy;
  163. friend class blInteriorProxy;
  164. friend class TranslucentSubObject;
  165. friend class MirrorSubObject;
  166. friend class InteriorConvex;
  167. friend class EditInteriorResource;
  168. friend class InteriorLMManager;
  169. friend class TSShape;
  170. friend class SceneLighting;
  171. //-------------------------------------- Public interfaces
  172. public:
  173. Interior();
  174. ~Interior();
  175. private:
  176. U32 mLightMapBorderSize;
  177. public:
  178. Vector<S32> surfaceZones;
  179. U32 getLightMapBorderSize() const {return mLightMapBorderSize;}
  180. void setLightMapBorderSize(U32 value) {mLightMapBorderSize = value;}
  181. void buildSurfaceZones();
  182. //void sgSetupLighting(InteriorInstance *intInst, SceneData &sgData);
  183. //bool sgRenderLights(InteriorInstance *intInst, SceneData &sgData);
  184. // Interior Render StateBlock
  185. GFXStateBlockRef mInteriorSB;
  186. MaterialList* mMaterialList;
  187. // Misc
  188. U32 getDetailLevel() const;
  189. U32 getMinPixels() const;
  190. const Box3F& getBoundingBox() const;
  191. S32 getNumZones() const;
  192. // Rendering
  193. bool prepForRendering(const char* path);
  194. bool traverseZones( SceneCullingState* state,
  195. const Frustum& frustum,
  196. S32 containingZone,
  197. S32 baseZone,
  198. U32 zoneOffset,
  199. const MatrixF& OSToWS,
  200. const Point3F& objScale,
  201. const bool dontRestrictOutside,
  202. const bool flipClipPlanes,
  203. Frustum& outFrustum );
  204. void prepBatchRender( InteriorInstance *intInst, SceneRenderState *state );
  205. void setupRenderStates();
  206. bool scopeZones(const S32 baseZone,
  207. const Point3F& interiorRoot,
  208. bool* interiorScopingState);
  209. ZoneVisDeterminer setupZoneVis( InteriorInstance *intInst, SceneRenderState *state );
  210. SceneData setupSceneGraphInfo( InteriorInstance *intInst,
  211. SceneRenderState *state );
  212. void setupRender( InteriorInstance *intInst,
  213. SceneRenderState *state,
  214. MeshRenderInst *coreRi,
  215. const MatrixF* worldToCamera);
  216. //-------------------------------------- Collision Interface and zone scans
  217. public:
  218. bool scanZones(const Box3F&, const MatrixF&, U16* zones, U32* numZones);
  219. bool castRay(const Point3F&, const Point3F&, RayInfo*);
  220. bool buildPolyList(AbstractPolyList*, const Box3F&, const MatrixF&, const Point3F&);
  221. bool getIntersectingHulls(const Box3F&, U16* hulls, U32* numHulls);
  222. bool getIntersectingVehicleHulls(const Box3F&, U16* hulls, U32* numHulls);
  223. protected:
  224. bool castRay_r(const U32, const U16, const Point3F&, const Point3F&, RayInfo*);
  225. void buildPolyList_r(InteriorPolytope& polytope,
  226. SurfaceHash& hash);
  227. void scanZone_r(const U32 node,
  228. const Point3F& center,
  229. const Point3F& axisx,
  230. const Point3F& axisy,
  231. const Point3F& axisz,
  232. U16* zones,
  233. U32* numZones);
  234. void scanZoneNew(InteriorPolytope& polytope,
  235. U16* zones,
  236. U32* numZones);
  237. /// @name Lightmap Support
  238. /// @{
  239. static void _enableLightMapFeature( ProcessedMaterial *mat,
  240. U32 stageNum,
  241. MaterialFeatureData &fd,
  242. const FeatureSet &features );
  243. /// @}
  244. //-------------------------------------- Global rendering control
  245. public:
  246. enum RenderModes
  247. {
  248. NormalRender = 0,
  249. NormalRenderLines = 1,
  250. ShowDetail = 2,
  251. ShowAmbiguous = 3,
  252. ShowOrphan = 4,
  253. ShowLightmaps = 5,
  254. ShowTexturesOnly = 6,
  255. ShowPortalZones = 7,
  256. ShowOutsideVisible = 8,
  257. ShowCollisionFans = 9,
  258. ShowStrips = 10,
  259. ShowNullSurfaces = 11,
  260. ShowLargeTextures = 12,
  261. ShowHullSurfaces = 13,
  262. ShowVehicleHullSurfaces = 14,
  263. ShowVertexColors = 15,
  264. ShowDetailLevel = 16
  265. };
  266. enum Constants
  267. {
  268. NumCoordBins = 16,
  269. BinsXY = 0,
  270. BinsXZ = 1,
  271. BinsYZ = 2
  272. };
  273. static U32 smRenderMode;
  274. static bool smFocusedDebug;
  275. static bool smUseVertexLighting;
  276. static U32 smFileVersion;
  277. static bool smLightingCastRays;
  278. static bool smLightingBuildPolyList;
  279. //-------------------------------------- Persistence interface
  280. public:
  281. bool read(Stream& stream);
  282. bool write(Stream& stream) const;
  283. bool readVehicleCollision(Stream& stream);
  284. bool writeVehicleCollision(Stream& stream) const;
  285. private:
  286. bool writePlaneVector(Stream&) const;
  287. bool readPlaneVector(Stream&);
  288. bool readLMapTexGen(Stream&, PlaneF&, PlaneF&);
  289. bool writeLMapTexGen(Stream&, const PlaneF&, const PlaneF&) const;
  290. void setupTexCoords();
  291. void setupZonePlanes();
  292. //-------------------------------------- For morian only...
  293. public:
  294. void processHullPolyLists();
  295. void processVehicleHullPolyLists();
  296. //-------------------------------------- BSP Structures
  297. private:
  298. struct IBSPNode
  299. {
  300. U16 planeIndex;
  301. U32 frontIndex;
  302. U32 backIndex;
  303. U16 terminalZone; // if high bit set, then the lower 15 bits are the zone
  304. // of any of the subsidiary nodes. Note that this is
  305. // going to overestimate some, since an object could be
  306. // completely contained in solid, but it's probably
  307. // going to turn out alright.
  308. };
  309. struct IBSPLeafSolid
  310. {
  311. U32 surfaceIndex;
  312. U16 surfaceCount;
  313. };
  314. bool isBSPLeafIndex(U32 index) const;
  315. bool isBSPSolidLeaf(U32 index) const;
  316. bool isBSPEmptyLeaf(U32 index) const;
  317. U16 getBSPSolidLeafIndex(U32 index) const;
  318. U16 getBSPEmptyLeafZone(U32 index) const;
  319. void setupAveTexGenLength();
  320. void truncateZoneTree();
  321. void truncateZoneNode(const U32);
  322. bool getUnifiedZone(const U32, S32*);
  323. public:
  324. static U16 getPlaneIndex(U16 index);
  325. static bool planeIsFlipped(U16 index);
  326. const PlaneF& getPlane(U16 index) const;
  327. PlaneF getFlippedPlane(const U16 index) const;
  328. const Point3F getPointNormal(const U32 surfaceIndex, const U32 pointOffset) const;
  329. private:
  330. bool areEqualPlanes(U16, U16) const;
  331. bool isNullSurfaceIndex(const U32 index) const;
  332. bool isVehicleNullSurfaceIndex(const U32 index) const;
  333. U32 getNullSurfaceIndex(const U32 index) const;
  334. U32 getVehicleNullSurfaceIndex(const U32 index) const;
  335. //-------------------------------------- Portals and Zone structures
  336. private:
  337. struct Zone
  338. {
  339. U16 portalStart;
  340. U16 portalCount;
  341. U32 surfaceStart;
  342. U32 planeStart;
  343. U16 surfaceCount;
  344. U16 planeCount;
  345. U32 staticMeshStart;
  346. U32 staticMeshCount;
  347. U16 flags;
  348. U16 zoneId; // This is ephemeral, not persisted out.
  349. };
  350. struct Portal
  351. {
  352. U16 planeIndex;
  353. U16 triFanCount;
  354. U32 triFanStart; // portals can have multiple windings
  355. U16 zoneFront;
  356. U16 zoneBack;
  357. };
  358. //-------------------------------------- Poly/Surface structures
  359. public:
  360. enum SurfaceFlags
  361. {
  362. SurfaceDetail = BIT(0),
  363. SurfaceAmbiguous = BIT(1),
  364. SurfaceOrphan = BIT(2),
  365. SurfaceSharedLMaps = BIT(3), // Indicates that the alarm and normal states share a lightmap (for mission lighter)
  366. SurfaceOutsideVisible = BIT(4),
  367. SurfaceStaticMesh = BIT(5), // This surface belongs to a static mesh collision hull
  368. SurfaceFlagMask = (SurfaceDetail |
  369. SurfaceAmbiguous |
  370. SurfaceOrphan |
  371. SurfaceSharedLMaps |
  372. SurfaceOutsideVisible |
  373. SurfaceStaticMesh)
  374. };
  375. enum ZoneFlags
  376. {
  377. ZoneInside = BIT(0)
  378. };
  379. const bool isSurfaceOutsideVisible(U32 surface) const;
  380. public:
  381. struct TexMatrix
  382. {
  383. S32 T;
  384. S32 N;
  385. S32 B;
  386. TexMatrix()
  387. : T( -1 ),
  388. N( -1 ),
  389. B( -1 )
  390. {};
  391. };
  392. struct Edge
  393. {
  394. S32 vertexes[2];
  395. S32 faces[2];
  396. };
  397. struct TexGenPlanes
  398. {
  399. PlaneF planeX;
  400. PlaneF planeY;
  401. };
  402. struct TriFan
  403. {
  404. U32 windingStart;
  405. U32 windingCount;
  406. };
  407. struct Surface
  408. {
  409. U32 windingStart; // 1
  410. U16 planeIndex; // 2
  411. U16 textureIndex;
  412. U32 texGenIndex; // 3
  413. U16 lightCount; // 4
  414. U8 surfaceFlags;
  415. U32 windingCount;
  416. U32 fanMask; // 5
  417. U32 lightStateInfoStart; // 6
  418. U32 mapOffsetX; // 7
  419. U32 mapOffsetY;
  420. U32 mapSizeX;
  421. U32 mapSizeY;
  422. Point3F T,B,N;
  423. Point3F normal;
  424. //U32 VBIndexStart;
  425. //U32 primIndex;
  426. GFXPrimitive surfaceInfo;
  427. bool unused;
  428. };
  429. struct NullSurface
  430. {
  431. U32 windingStart;
  432. U16 planeIndex;
  433. U8 surfaceFlags;
  434. U32 windingCount;
  435. };
  436. //-------------------------------------- Animated lighting structures
  437. enum LightFlags
  438. {
  439. AnimationAmbient = BIT(0),
  440. AnimationLoop = BIT(1),
  441. AnimationFlicker = BIT(2),
  442. AnimationTypeMask = BIT(3) - 1,
  443. AlarmLight = BIT(3)
  444. };
  445. enum LightType
  446. {
  447. AmbientLooping = AnimationAmbient | AnimationLoop,
  448. AmbientFlicker = AnimationAmbient | AnimationFlicker,
  449. TriggerableLoop = AnimationLoop,
  450. TriggerableFlicker = AnimationFlicker,
  451. TriggerableRamp = 0
  452. };
  453. private:
  454. bool readSurface(Stream&, Surface&, TexGenPlanes&, const bool);
  455. public:
  456. // this is public because tools/Morian needs this defination
  457. struct AnimatedLight {
  458. U32 nameIndex; // Light's name
  459. U32 stateIndex; // start point in the state list
  460. U16 stateCount; // number of states in this light
  461. U16 flags; // flags (Apply AnimationTypeMask to get type)
  462. U32 duration; // total duration of animation (ms)
  463. };
  464. private:
  465. struct LightState {
  466. U8 red; // state's color
  467. U8 green;
  468. U8 blue;
  469. U8 _color_padding_;
  470. U32 activeTime; // Time (ms) at which this state becomes active
  471. U32 dataIndex; // StateData count and index for this state
  472. U16 dataCount;
  473. U16 __32bit_padding__;
  474. };
  475. struct LightStateData {
  476. U32 surfaceIndex; // Surface affected by this data
  477. U32 mapIndex; // Index into StateDataBuffer (0xFFFFFFFF indicates none)
  478. U16 lightStateIndex; // Entry to modify in InteriorInstance
  479. U16 __32bit_padding__;
  480. };
  481. // convex hull collision structures...
  482. protected:
  483. struct ConvexHull
  484. {
  485. F32 minX;
  486. F32 maxX;
  487. F32 minY;
  488. F32 maxY;
  489. F32 minZ;
  490. F32 maxZ;
  491. U32 hullStart;
  492. U32 surfaceStart;
  493. U32 planeStart;
  494. U16 hullCount;
  495. U16 surfaceCount;
  496. U32 polyListPlaneStart;
  497. U32 polyListPointStart;
  498. U32 polyListStringStart;
  499. U16 searchTag;
  500. bool staticMesh;
  501. };
  502. struct CoordBin
  503. {
  504. U32 binStart;
  505. U32 binCount;
  506. };
  507. struct RenderNode
  508. {
  509. bool exterior;
  510. U16 baseTexIndex;
  511. U8 lightMapIndex;
  512. S32 primInfoIndex;
  513. BaseMatInstance *matInst;
  514. RenderNode()
  515. {
  516. exterior = true;
  517. baseTexIndex = 0;
  518. lightMapIndex = U8(-1);
  519. primInfoIndex = -1;
  520. matInst = NULL;
  521. }
  522. };
  523. // public because InteriorInstance needs access
  524. public:
  525. Vector< PlaneF > mReflectPlanes;
  526. protected:
  527. struct ReflectRenderNode
  528. {
  529. bool exterior;
  530. S32 reflectPlaneIndex;
  531. S32 primInfoIndex;
  532. U8 lightMapIndex;
  533. BaseMatInstance *matInst;
  534. ReflectRenderNode()
  535. {
  536. exterior = true;
  537. reflectPlaneIndex = -1;
  538. lightMapIndex = U8(-1);
  539. primInfoIndex = -1;
  540. matInst = NULL;
  541. }
  542. };
  543. struct ZoneRNList
  544. {
  545. Vector<RenderNode> renderNodeList;
  546. };
  547. struct ZoneReflectRNList
  548. {
  549. Vector<ReflectRenderNode> reflectList;
  550. };
  551. // needs to be exposed in order for on the fly changes
  552. public:
  553. Vector<ZoneRNList> mZoneRNList;
  554. private:
  555. // reflective plane data
  556. GFXVertexBufferHandle<GFXVertexPNTTB> mReflectVertBuff;
  557. GFXPrimitiveBufferHandle mReflectPrimBuff;
  558. Vector<ZoneReflectRNList> mZoneReflectRNList;
  559. // standard interior data
  560. GFXVertexBufferHandle<GFXVertexPNTTB> mVertBuff;
  561. GFXPrimitiveBufferHandle mPrimBuff;
  562. private:
  563. LM_HANDLE mLMHandle;
  564. public:
  565. LM_HANDLE getLMHandle() {return(mLMHandle);}
  566. public:
  567. // SceneLighting::InteriorProxy interface
  568. const Surface & getSurface(const U32 surface) const;
  569. const U32 getSurfaceCount() const;
  570. const U32 getNormalLMapIndex(const U32 surface) const;
  571. const U32 getAlarmLMapIndex(const U32 surface) const;
  572. const U32 getStaticMeshCount() const;
  573. const InteriorSimpleMesh *getStaticMesh(const U32 index) const;
  574. const U32 getWinding(const U32 index) const;
  575. const Point3F & getPoint(const U32 index) const;
  576. const TexGenPlanes & getLMTexGenEQ(const U32 index) const;
  577. const TexGenPlanes & getTexGenEQ(const U32 index) const;
  578. bool hasAlarmState() const;
  579. const U32 getWindingCount() const;
  580. S32 getTargetCount() const;
  581. const String& getTargetName( S32 mapToNameIndex ) const;
  582. //-------------------------------------- Instance Data Members
  583. private:
  584. U32 mFileVersion;
  585. U32 mDetailLevel;
  586. U32 mMinPixels;
  587. F32 mAveTexGenLength; // Set in Interior::read after loading the texgen planes.
  588. Box3F mBoundingBox;
  589. SphereF mBoundingSphere;
  590. Vector<PlaneF> mPlanes;
  591. Vector<ItrPaddedPoint> mPoints;
  592. Vector<U8> mPointVisibility;
  593. Vector<Point3F> mNormals;
  594. Vector<TexMatrix> mTexMatrices;
  595. Vector<U32> mTexMatIndices;
  596. ColorF mBaseAmbient;
  597. ColorF mAlarmAmbient;
  598. Vector<IBSPNode> mBSPNodes;
  599. Vector<IBSPLeafSolid> mBSPSolidLeaves;
  600. bool mPreppedForRender;
  601. bool mHasTranslucentMaterials;
  602. Vector<U32> mWindings;
  603. Vector<TexGenPlanes> mTexGenEQs;
  604. Vector<TexGenPlanes> mLMTexGenEQs;
  605. Vector<TriFan> mWindingIndices;
  606. Vector<Surface> mSurfaces;
  607. Vector<NullSurface> mNullSurfaces;
  608. Vector<U32> mSolidLeafSurfaces;
  609. Vector<Edge> mEdges;
  610. // Portals and zones
  611. Vector<Zone> mZones;
  612. Vector<U16> mZonePlanes;
  613. Vector<U16> mZoneSurfaces;
  614. Vector<U16> mZonePortalList;
  615. Vector<Portal> mPortals;
  616. Vector<U32> mZoneStaticMeshes;
  617. // Subobjects: Doors, translucencies, mirrors, etc.
  618. Vector<InteriorSubObject*> mSubObjects;
  619. // Lighting info
  620. bool mHasAlarmState;
  621. U32 mNumLightStateEntries;
  622. Vector<GBitmap*> mLightmaps;
  623. Vector<bool> mLightmapKeep;
  624. Vector<U32> mNormalLMapIndices;
  625. Vector<U32> mAlarmLMapIndices;
  626. U32 mNumTriggerableLights; // Note: not persisted
  627. // Persistent animated light structures
  628. Vector<AnimatedLight> mAnimatedLights;
  629. Vector<LightState> mLightStates;
  630. Vector<LightStateData> mStateData;
  631. Vector<U8> mStateDataBuffer;
  632. Vector<char> mNameBuffer;
  633. Vector<ConvexHull> mConvexHulls;
  634. Vector<U8> mConvexHullEmitStrings;
  635. Vector<U32> mHullIndices;
  636. Vector<U32> mHullEmitStringIndices;
  637. Vector<U32> mHullSurfaceIndices;
  638. Vector<U16> mHullPlaneIndices;
  639. Vector<U16> mPolyListPlanes;
  640. Vector<U32> mPolyListPoints;
  641. Vector<U8> mPolyListStrings;
  642. CoordBin mCoordBins[NumCoordBins * NumCoordBins];
  643. Vector<U16> mCoordBinIndices;
  644. U32 mCoordBinMode;
  645. Vector<ConvexHull> mVehicleConvexHulls;
  646. Vector<U8> mVehicleConvexHullEmitStrings;
  647. Vector<U32> mVehicleHullIndices;
  648. Vector<U32> mVehicleHullEmitStringIndices;
  649. Vector<U32> mVehicleHullSurfaceIndices;
  650. Vector<U16> mVehicleHullPlaneIndices;
  651. Vector<U16> mVehiclePolyListPlanes;
  652. Vector<U32> mVehiclePolyListPoints;
  653. Vector<U8> mVehiclePolyListStrings;
  654. Vector<ItrPaddedPoint> mVehiclePoints;
  655. Vector<NullSurface> mVehicleNullSurfaces;
  656. Vector<PlaneF> mVehiclePlanes;
  657. Vector<U32> mVehicleWindings;
  658. Vector<TriFan> mVehicleWindingIndices;
  659. VectorPtr<InteriorSimpleMesh*> mStaticMeshes;
  660. U16 mSearchTag;
  661. Vector<BaseMatInstance*> mMatInstCleanupList;
  662. //-------------------------------------- Private interface
  663. private:
  664. #ifndef TORQUE_SHIPPING
  665. GFXShaderRef mDebugShader;
  666. GFXTexHandle mDebugTexture;
  667. GFXStateBlockRef mInteriorDebugNoneSB;
  668. GFXStateBlockRef mInteriorDebugPortalSB;
  669. GFXStateBlockRef mInteriorDebugTextureSB;
  670. GFXStateBlockRef mInteriorDebugTwoTextureSB;
  671. // Debug Render ConstantBuffers
  672. GFXShaderConstBufferRef mDebugShaderConsts;
  673. GFXShaderConstHandle* mDebugShaderModelViewSC;
  674. GFXShaderConstHandle* mDebugShaderShadeColorSC;
  675. #endif
  676. const char* getName(const U32 nameIndex) const;
  677. static const char* getLightTypeString(const LightType);
  678. S32 getZoneForPoint(const Point3F&) const;
  679. #ifndef TORQUE_SHIPPING
  680. void debugRender(const ZoneVisDeterminer& zoneVis, SceneData &sgData, InteriorInstance *intInst, MatrixF& modelview);
  681. // render debug utility functions
  682. void preDebugRender();
  683. void debugDefaultRender(const ZoneVisDeterminer& zoneVis, SceneData &sgData, InteriorInstance *intInst);
  684. // show all surfaces with flag set as color c
  685. void debugShowSurfaceFlag(const ZoneVisDeterminer& zoneVis, const U32 flag, const ColorF& c);
  686. // render brushes
  687. void debugNormalRenderLines(const ZoneVisDeterminer& zoneVis);
  688. // next 4 use debugShowSurfaceFlag to show surface info
  689. void debugShowDetail(const ZoneVisDeterminer& zoneVis);
  690. void debugShowAmbiguous(const ZoneVisDeterminer& zoneVis);
  691. void debugShowOrphan(const ZoneVisDeterminer& zoneVis);
  692. void debugShowOutsideVisible(const ZoneVisDeterminer& zoneVis);
  693. void debugShowPortalZones(const ZoneVisDeterminer& zoneVis);
  694. void debugRenderPortals();
  695. void debugShowCollisionFans(const ZoneVisDeterminer& zoneVis);
  696. void debugShowStrips(const ZoneVisDeterminer& zoneVis);
  697. void debugShowDetailLevel(const ZoneVisDeterminer& zoneVis);
  698. void debugShowHullSurfaces();
  699. void debugShowNullSurfaces(const ZoneVisDeterminer& zoneVis, SceneData &sgData, InteriorInstance *intInst);
  700. void debugShowVehicleHullSurfaces(const ZoneVisDeterminer& zoneVis, SceneData &sgData, InteriorInstance *intInst);
  701. void debugShowTexturesOnly(const ZoneVisDeterminer& zoneVis, SceneData &sgData, InteriorInstance *intInst);
  702. void debugShowLightmaps(const ZoneVisDeterminer& zoneVis, SceneData &sgData, InteriorInstance *intInst);
  703. void debugShowLargeTextures(const ZoneVisDeterminer& zoneVis, SceneData &sgData, InteriorInstance *intInst);
  704. // void debugShowVertexColors(MaterialList* pMaterials);
  705. #endif
  706. public:
  707. void collisionFanFromSurface(const Surface&, U32* fan, U32* numIndices) const;
  708. void fillSurfaceTexMats();
  709. void createZoneVBs();
  710. void cloneMatInstances();
  711. void initMatInstances();
  712. void createReflectPlanes();
  713. private:
  714. void fullWindingFromSurface(const Surface&, U32* fan, U32* numIndices) const;
  715. bool projectClipAndBoundFan(U32 fanIndex, F64* pResult);
  716. void zoneTraversal(S32 baseZone, const bool flipClipPlanes);
  717. void createZoneRectVectors();
  718. void destroyZoneRectVectors();
  719. void traverseZone(const RectD* inRects, const U32 numInputRects, U32 currZone, Vector<U32>& zoneStack);
  720. void fillVertex( GFXVertexPNTTB &vert, Surface &surface, U32 surfaceIndex );
  721. void getTexMat(U32 surfaceIndex, U32 pointOffset, Point3F& T, Point3F& N, Point3F& B);
  722. void storeRenderNode( RenderNode &node,
  723. ZoneRNList &RNList,
  724. Vector<GFXPrimitive> &primInfoList,
  725. Vector<U16> &indexList,
  726. Vector<GFXVertexPNTTB> &verts,
  727. U32 &startIndex,
  728. U32 &startVert );
  729. void renderZoneNode( SceneRenderState *state,
  730. RenderNode &node,
  731. InteriorInstance *intInst,
  732. SceneData &sgData,
  733. MeshRenderInst *coreRi );
  734. void renderReflectNode( SceneRenderState *state,
  735. ReflectRenderNode &node,
  736. InteriorInstance *intInst,
  737. SceneData &sgData,
  738. MeshRenderInst *coreRi );
  739. void renderLights(SceneRenderState* state, InteriorInstance *intInst, SceneData &sgData, MeshRenderInst *coreRi, const ZoneVisDeterminer &zonevis);
  740. /// Used to maintain point and normal relationship (which use
  741. /// dissimilar index lookups) for verts when building vertex buffer.
  742. struct VertexBufferTempIndex
  743. {
  744. U16 index;
  745. Point3F normal;
  746. VertexBufferTempIndex()
  747. {
  748. index = 0;
  749. normal.set(0.0f, 0.0f, 0.0f);
  750. }
  751. VertexBufferTempIndex(const U16 ind, const Point3F &norm)
  752. {
  753. index = ind;
  754. normal = norm;
  755. }
  756. };
  757. void storeSurfVerts( Vector<U16> &masterIndexList,
  758. Vector<VertexBufferTempIndex> &tempIndexList,
  759. Vector<GFXVertexPNTTB> &verts,
  760. U32 numIndices,
  761. Surface &surface,
  762. U32 surfaceIndex );
  763. public:
  764. void purgeLODData();
  765. void buildExportPolyList(OptimizedPolyList& polys, MatrixF* mat = NULL, Point3F* scale = NULL);
  766. };
  767. //------------------------------------------------------------------------------
  768. inline bool Interior::isBSPLeafIndex(U32 index) const
  769. {
  770. if (mFileVersion >= 14)
  771. return (index & 0x80000) != 0;
  772. else
  773. return (index & 0x8000) != 0;
  774. }
  775. inline bool Interior::isBSPSolidLeaf(U32 index) const
  776. {
  777. AssertFatal(isBSPLeafIndex(index) == true, "Error, only call for leaves!");
  778. if (mFileVersion >= 14)
  779. return (index & 0x40000) != 0;
  780. else
  781. return (index & 0x4000) != 0;
  782. }
  783. inline bool Interior::isBSPEmptyLeaf(U32 index) const
  784. {
  785. AssertFatal(isBSPLeafIndex(index) == true, "Error, only call for leaves!");
  786. if (mFileVersion >= 14)
  787. return (index & 0x40000) == 0;
  788. else
  789. return (index & 0x4000) == 0;
  790. }
  791. inline U16 Interior::getBSPSolidLeafIndex(U32 index) const
  792. {
  793. AssertFatal(isBSPSolidLeaf(index) == true, "Error, only call for leaves!");
  794. if (mFileVersion >= 14)
  795. return U16(index & ~0xC0000);
  796. else
  797. return U16(index & ~0xC000);
  798. }
  799. inline U16 Interior::getBSPEmptyLeafZone(U32 index) const
  800. {
  801. AssertFatal(isBSPEmptyLeaf(index) == true, "Error, only call for leaves!");
  802. if (mFileVersion >= 14)
  803. return U16(index & ~0xC0000);
  804. else
  805. return U16(index & ~0xC000);
  806. }
  807. inline const PlaneF& Interior::getPlane(U16 index) const
  808. {
  809. AssertFatal(U32(index & ~0x8000) < mPlanes.size(),
  810. "Interior::getPlane: planeIndex out of range");
  811. return mPlanes[index & ~0x8000];
  812. }
  813. inline PlaneF Interior::getFlippedPlane(const U16 index) const
  814. {
  815. PlaneF plane = getPlane(index);
  816. if(Interior::planeIsFlipped(index))
  817. plane.neg();
  818. return plane;
  819. }
  820. inline U16 Interior::getPlaneIndex(U16 index)
  821. {
  822. return U16(index & ~0x8000);
  823. }
  824. inline bool Interior::planeIsFlipped(U16 index)
  825. {
  826. return (index >> 15)!=0;
  827. }
  828. inline bool Interior::areEqualPlanes(U16 o, U16 t) const
  829. {
  830. return (o & ~0x8000) == (t & ~0x8000);
  831. }
  832. inline const Point3F Interior::getPointNormal(const U32 surfaceIndex, const U32 pointOffset) const
  833. {
  834. Surface rSurface = mSurfaces[surfaceIndex];
  835. Point3F normal(0.0f, 0.0f, 0.0f);
  836. if (mFileVersion >= 11)
  837. {
  838. U32 texMatIndex = mTexMatIndices[rSurface.windingStart + pointOffset];
  839. TexMatrix texMat = mTexMatrices[texMatIndex];
  840. if (texMat.N > -1)
  841. normal = mNormals[texMat.N];
  842. }
  843. else
  844. normal = getFlippedPlane(rSurface.planeIndex);
  845. return normal;
  846. }
  847. inline U32 Interior::getDetailLevel() const
  848. {
  849. return mDetailLevel;
  850. }
  851. inline U32 Interior::getMinPixels() const
  852. {
  853. return mMinPixels;
  854. }
  855. inline const Box3F& Interior::getBoundingBox() const
  856. {
  857. return mBoundingBox;
  858. }
  859. inline S32 Interior::getNumZones() const
  860. {
  861. return mZones.size();
  862. }
  863. inline bool Interior::isNullSurfaceIndex(const U32 index) const
  864. {
  865. return (index & 0x80000000) != 0;
  866. }
  867. inline bool Interior::isVehicleNullSurfaceIndex(const U32 index) const
  868. {
  869. return (index & 0x40000000) != 0;
  870. }
  871. inline U32 Interior::getNullSurfaceIndex(const U32 index) const
  872. {
  873. AssertFatal(isNullSurfaceIndex(index), "Not a proper index!");
  874. AssertFatal(!isVehicleNullSurfaceIndex(index), "Not a proper index");
  875. return (index & ~0x80000000);
  876. }
  877. inline U32 Interior::getVehicleNullSurfaceIndex(const U32 index) const
  878. {
  879. AssertFatal(isVehicleNullSurfaceIndex(index), "Not a proper index!");
  880. return (index & ~(0x80000000 | 0x40000000));
  881. }
  882. inline const char* Interior::getLightTypeString(const LightType type)
  883. {
  884. switch (type) {
  885. case AmbientLooping:
  886. return "AmbientLooping";
  887. case AmbientFlicker:
  888. return "AmbientFlicker";
  889. case TriggerableLoop:
  890. return "TriggerableLoop";
  891. case TriggerableFlicker:
  892. return "TriggerableFlicker";
  893. case TriggerableRamp:
  894. return "TriggerableRamp";
  895. default:
  896. return "<UNKNOWN>";
  897. }
  898. }
  899. inline const char* Interior::getName(const U32 nameIndex) const
  900. {
  901. return &mNameBuffer[nameIndex];
  902. }
  903. inline const U32 Interior::getSurfaceCount() const
  904. {
  905. return(mSurfaces.size());
  906. }
  907. inline const Interior::Surface & Interior::getSurface(const U32 surface) const
  908. {
  909. AssertFatal(surface < mSurfaces.size(), "invalid index");
  910. return(mSurfaces[surface]);
  911. }
  912. inline const U32 Interior::getStaticMeshCount() const
  913. {
  914. return mStaticMeshes.size();
  915. }
  916. inline const InteriorSimpleMesh *Interior::getStaticMesh(const U32 index) const
  917. {
  918. AssertFatal(index < mStaticMeshes.size(), "invalid index");
  919. return mStaticMeshes[index];
  920. }
  921. inline const U32 Interior::getNormalLMapIndex(const U32 surface) const
  922. {
  923. AssertFatal(surface < mNormalLMapIndices.size(), "invalid index");
  924. return(mNormalLMapIndices[surface]);
  925. }
  926. inline const U32 Interior::getAlarmLMapIndex(const U32 surface) const
  927. {
  928. AssertFatal(surface < mAlarmLMapIndices.size(), "invalid index");
  929. return(mAlarmLMapIndices[surface]);
  930. }
  931. inline const U32 Interior::getWinding(const U32 index) const
  932. {
  933. AssertFatal(index < mWindings.size(), "invalid index");
  934. return(mWindings[index]);
  935. }
  936. inline const Point3F & Interior::getPoint(const U32 index) const
  937. {
  938. AssertFatal(index < mPoints.size(), "invalid index");
  939. return(mPoints[index].point);
  940. }
  941. inline const Interior::TexGenPlanes & Interior::getLMTexGenEQ(const U32 index) const
  942. {
  943. AssertFatal(index < mLMTexGenEQs.size(), "invalid index");
  944. return(mLMTexGenEQs[index]);
  945. }
  946. inline const Interior::TexGenPlanes & Interior::getTexGenEQ(const U32 index) const
  947. {
  948. AssertFatal(index < mTexGenEQs.size(), "invalid index");
  949. return(mTexGenEQs[index]);
  950. }
  951. inline bool Interior::hasAlarmState() const
  952. {
  953. return(mHasAlarmState);
  954. }
  955. inline const bool Interior::isSurfaceOutsideVisible(U32 surface) const
  956. {
  957. AssertFatal(surface < mSurfaces.size(), "Interior::isSurfaceOutsideVisible: Invalid surface index");
  958. return ((mSurfaces[surface].surfaceFlags & SurfaceOutsideVisible)!=0);
  959. }
  960. inline const U32 Interior::getWindingCount() const
  961. {
  962. return(mWindings.size());
  963. }
  964. #endif //_INTERIOR_H_