decalRoad.h
Engine/source/environment/decalRoad.h
Classes:
class
class
class
class
class
class
Public Defines
define
MIN_METERS_PER_SEGMENT() 1.0f
define
StepSize_Normal() 10.0f
Public Typedefs
Detailed Description
Public Defines
MIN_METERS_PER_SEGMENT() 1.0f
StepSize_Normal() 10.0f
Public Typedefs
typedef Vector< RoadBatch > RoadBatchVector
typedef Vector< RoadEdge > RoadEdgeVector
typedef Vector< RoadNode > RoadNodeVector
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 _DECALROAD_H_ 25#define _DECALROAD_H_ 26 27#ifndef _SCENEOBJECT_H_ 28#include "scene/sceneObject.h" 29#endif 30#ifndef _GFXVERTEXBUFFER_H_ 31#include "gfx/gfxVertexBuffer.h" 32#endif 33#ifndef _GFXPRIMITIVEBUFFER_H_ 34#include "gfx/gfxPrimitiveBuffer.h" 35#endif 36#ifndef _CLIPPEDPOLYLIST_H_ 37#include "collision/clippedPolyList.h" 38#endif 39 40#include "T3D/assets/MaterialAsset.h" 41 42class Path; 43class TerrainBlock; 44struct ObjectRenderInst; 45class Material; 46struct DecalRoadNodeList; 47 48 49class DecalRoadUpdateEvent : public SimEvent 50{ 51 typedef SimEvent Parent; 52public: 53 54 DecalRoadUpdateEvent( U32 mask, U32 ms ) { mMask = mask; mMs = ms; } 55 virtual void process( SimObject *object ); 56 57 U32 mMask; 58 U32 mMs; 59}; 60 61 62struct RoadNode 63{ 64 /// The 3D position of the node. 65 Point3F point; 66 67 /// The width of the road at this node. 68 F32 width; 69 70 /// Alpha of the road at this node. 71 //F32 alpha; 72}; 73typedef Vector<RoadNode> RoadNodeVector; 74 75struct RoadEdge 76{ 77 RoadEdge() 78 { 79 p0.zero(); 80 p1.zero(); 81 p2.zero(); 82 83 uvec.zero(); 84 fvec.zero(); 85 rvec.zero(); 86 87 width = 0.0f; 88 89 parentNodeIdx = -1; 90 }; 91 92 Point3F p0; 93 Point3F p1; 94 Point3F p2; 95 96 VectorF uvec; 97 VectorF fvec; 98 VectorF rvec; 99 100 F32 width; 101 102 U32 parentNodeIdx; 103}; 104typedef Vector<RoadEdge> RoadEdgeVector; 105 106struct RoadBatch 107{ 108 U32 startVert; 109 U32 endVert; 110 111 U32 startIndex; 112 U32 endIndex; 113 114 Box3F bounds; 115}; 116typedef Vector<RoadBatch> RoadBatchVector; 117 118 119//------------------------------------------------------------------------------ 120// DecalRoad Class 121//------------------------------------------------------------------------------ 122class DecalRoad : public SceneObject 123{ 124private: 125 126 friend class DecalRoadUpdateEvent; 127 friend class GuiRoadEditorCtrl; 128 friend class GuiRoadEditorUndoAction; 129 typedef SceneObject Parent; 130 131protected: 132 // Internal defines, enums, structs, classes 133 134 struct Triangle 135 { 136 GFXVertexPT v0, v1, v2; 137 }; 138 139 enum 140 { 141 DecalRoadMask = Parent::NextFreeMask, 142 NodeMask = Parent::NextFreeMask << 1, 143 GenEdgesMask = Parent::NextFreeMask << 2, 144 ReClipMask = Parent::NextFreeMask << 3, 145 TerrainChangedMask = Parent::NextFreeMask << 4, 146 NextFreeMask = Parent::NextFreeMask << 5, 147 }; 148 149 #define StepSize_Normal 10.0f 150 #define MIN_METERS_PER_SEGMENT 1.0f 151 152public: 153 154 DecalRoad(); 155 ~DecalRoad(); 156 157 DECLARE_CONOBJECT(DecalRoad); 158 159 // ConsoleObject 160 static void initPersistFields(); 161 static void consoleInit(); 162 163 // SimObject 164 bool onAdd(); 165 void onRemove(); 166 void onEditorEnable(); 167 void onEditorDisable(); 168 void inspectPostApply(); 169 void onStaticModified(const char* slotName, const char*newValue = NULL); 170 void writeFields(Stream &stream, U32 tabStop); 171 bool writeField( StringTableEntry fieldname, const char *value ); 172 173 // NetObject 174 U32 packUpdate(NetConnection *, U32, BitStream *); 175 void unpackUpdate(NetConnection *, BitStream *); 176 177 // SceneObject 178 virtual void prepRenderImage( SceneRenderState* state ); 179 virtual void setTransform( const MatrixF &mat ); 180 virtual void setScale( const VectorF &scale ); 181 virtual bool containsPoint( const Point3F& point ) const { return containsPoint( point, NULL ); } 182 183 // fxRoad Public Methods 184 void scheduleUpdate( U32 updateMask ); 185 void scheduleUpdate( U32 updateMask, U32 delayMs, bool restartTimer ); 186 void regenerate(); 187 void setTextureLength( F32 meters ); 188 void setBreakAngle( F32 degrees ); 189 190 /// Insert a node anywhere in the road. 191 /// Pass idx zero to add to the front and idx U32_MAX to add to the end 192 U32 insertNode( const Point3F &pos, const F32 &width, const U32 &idx ); 193 194 U32 addNode( const Point3F &pos, F32 width = 10.0f ); 195 void deleteNode( U32 idx ); 196 197 void buildNodesFromList( DecalRoadNodeList* list ); 198 199 bool getClosestNode( const Point3F &pos, U32 &idx ); 200 201 bool containsPoint( const Point3F &worldPos, U32 *nodeIdx ) const; 202 bool castray( const Point3F &start, const Point3F &end ) const; 203 204 Point3F getNodePosition( U32 idx ); 205 void setNodePosition( U32 idx, const Point3F &pos ); 206 207 F32 getNodeWidth( U32 idx ); 208 void setNodeWidth( U32 idx, F32 width ); 209 210 /// Protected 'Node' Field setter that will add a node to the list. 211 static bool addNodeFromField( void *object, const char *index, const char *data ); 212 213 static SimSet* getServerSet(); 214 215protected: 216 217 // Internal Helper Methods 218 219 void _initMaterial(); 220 void _debugRender( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *matInst ); 221 222 U32 _insertNode( const Point3F &pos, const F32 &width, const U32 &idx ); 223 U32 _addNode( const Point3F &pos, F32 width ); 224 void _generateEdges(); 225 void _captureVerts(); 226 227 bool _getTerrainHeight( Point3F &pos ); 228 bool _getTerrainHeight( const Point2F &pos, F32 &height ); 229 bool _getTerrainHeight( const F32 &x, const F32 &y, F32 &height ); 230 231 void _onTerrainChanged( U32 type, TerrainBlock* tblock, const Point2I &min, const Point2I &max ); 232 233 // static protected field set methods 234 static bool ptSetBreakAngle( void *object, const char *index, const char *data ); 235 static bool ptSetTextureLength( void *object, const char *index, const char *data ); 236 237protected: 238 239 // Field Vars 240 F32 mBreakAngle; 241 U32 mSegmentsPerBatch; 242 F32 mTextureLength; 243 244 DECLARE_NET_MATERIALASSET(DecalRoad, Material, DecalRoadMask); 245 U32 mRenderPriority; 246 247 // Static ConsoleVars for editor 248 static bool smEditorOpen; 249 static bool smWireframe; 250 static bool smShowBatches; 251 static bool smDiscardAll; 252 static bool smShowSpline; 253 static bool smShowRoad; 254 static S32 smUpdateDelay; 255 256 static SimObjectPtr<SimSet> smServerDecalRoadSet; 257 258 // Other Internal Vars 259 260 RoadEdgeVector mEdges; 261 RoadNodeVector mNodes; 262 RoadBatchVector mBatches; 263 264 bool mLoadRenderData; 265 266 SimObjectPtr<Material> mMaterial; 267 BaseMatInstance *mMatInst; 268 269 GFXVertexBufferHandle<GFXVertexPNTBT> mVB; 270 GFXPrimitiveBufferHandle mPB; 271 272 U32 mTriangleCount; 273 U32 mVertCount; 274 275 S32 mUpdateEventId; 276 DecalRoadUpdateEvent *mLastEvent; 277 278 Box3F mTerrainUpdateRect; 279}; 280 281 282#endif // _DECALROAD_H_ 283