convexShape.h
Engine/source/T3D/convexShape.h
Classes:
class
class
class
Public Typedefs
ConvexVert
VertexType
Public Functions
GFXDeclareVertexFormat(ConvexVert )
Detailed Description
Public Typedefs
typedef ConvexVert VertexType
Public Functions
GFXDeclareVertexFormat(ConvexVert )
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 _CONVEXSHAPE_H_ 25#define _CONVEXSHAPE_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 _CONVEX_H_ 37#include "collision/convex.h" 38#endif 39 40class ConvexShape; 41 42// Crap name, but whatcha gonna do. 43class ConvexShapeCollisionConvex : public Convex 44{ 45 typedef Convex Parent; 46 friend class ConvexShape; 47 48protected: 49 50 ConvexShape *pShape; 51 52public: 53 54 ConvexShapeCollisionConvex() { mType = ConvexShapeCollisionConvexType; } 55 56 ConvexShapeCollisionConvex( const ConvexShapeCollisionConvex& cv ) { 57 mType = ConvexShapeCollisionConvexType; 58 mObject = cv.mObject; 59 pShape = cv.pShape; 60 } 61 62 Point3F support(const VectorF& vec) const; 63 void getFeatures(const MatrixF& mat,const VectorF& n, ConvexFeature* cf); 64 void getPolyList(AbstractPolyList* list); 65}; 66 67 68GFXDeclareVertexFormat( ConvexVert ) 69{ 70 Point3F point; 71 GFXVertexColor color; 72 Point3F normal; 73 Point3F tangent; 74 Point2F texCoord; 75}; 76 77class PhysicsBody; 78 79// Define our vertex format here so we don't have to 80// change it in multiple spots later 81typedef ConvexVert VertexType; 82 83class ConvexShape : public SceneObject 84{ 85 typedef SceneObject Parent; 86 friend class GuiConvexEditorCtrl; 87 friend class GuiConvexEditorUndoAction; 88 friend class ConvexShapeCollisionConvex; 89 90public: 91 92 enum NetBits { 93 TransformMask = Parent::NextFreeMask, 94 UpdateMask = Parent::NextFreeMask << 1, 95 NextFreeMask = Parent::NextFreeMask << 2 96 }; 97 98 // Declaring these structs directly within ConvexShape to prevent 99 // the otherwise excessively deep scoping we had. 100 // eg. ConvexShape::Face::Triangle ... 101 102 struct Edge 103 { 104 U32 p0; 105 U32 p1; 106 }; 107 108 struct Triangle 109 { 110 U32 p0; 111 U32 p1; 112 U32 p2; 113 114 U32 operator []( U32 index ) const 115 { 116 AssertFatal( index >= 0 && index <= 2, "index out of range" ); 117 return *( (&p0) + index ); 118 } 119 }; 120 121 struct Face 122 { 123 Vector< Edge> edges; 124 Vector< U32> points; 125 Vector< U32> winding; 126 Vector< Point2F> texcoords; 127 Vector< Triangle> triangles; 128 Point3F tangent; 129 Point3F normal; 130 Point3F centroid; 131 F32 area; 132 S32 id; 133 }; 134 135 struct Geometry 136 { 137 void generate( const Vector< PlaneF> &planes, const Vector< Point3F> &tangents ); 138 139 Vector< Point3F> points; 140 Vector< Face> faces; 141 }; 142 143 static bool smRenderEdges; 144 145 // To prevent bitpack overflows. 146 // This is only indirectly enforced by trucation when serializing. 147 static const S32 smMaxSurfaces = 100; 148 149public: 150 151 ConvexShape(); 152 virtual ~ConvexShape(); 153 154 DECLARE_CONOBJECT( ConvexShape ); 155 156 // ConsoleObject 157 static void initPersistFields(); 158 159 // SimObject 160 virtual void inspectPostApply(); 161 virtual bool onAdd(); 162 virtual void onRemove(); 163 virtual void writeFields(Stream &stream, U32 tabStop); 164 virtual bool writeField( StringTableEntry fieldname, const char *value ); 165 166 // NetObject 167 virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ); 168 virtual void unpackUpdate( NetConnection *conn, BitStream *stream ); 169 170 // SceneObject 171 virtual void onScaleChanged(); 172 virtual void setTransform( const MatrixF &mat ); 173 virtual void prepRenderImage( SceneRenderState *state ); 174 virtual void buildConvex( const Box3F &box, Convex *convex ); 175 virtual bool buildPolyList( PolyListContext context, AbstractPolyList *polyList, const Box3F &box, const SphereF &sphere ); 176 virtual bool castRay( const Point3F &start, const Point3F &end, RayInfo *info ); 177 virtual bool collideBox( const Point3F &start, const Point3F &end, RayInfo *info ); 178 179 180 void updateBounds( bool recenter ); 181 void recenter(); 182 183 /// Geometry access. 184 /// @{ 185 186 MatrixF getSurfaceWorldMat( S32 faceid, bool scaled = false ) const; 187 void cullEmptyPlanes( Vector< U32> *removedPlanes ); 188 void exportToCollada(); 189 void resizePlanes( const Point3F &size ); 190 void getSurfaceLineList( S32 surfId, Vector< Point3F> &lineList ); 191 Geometry& getGeometry() { return mGeometry; } 192 Vector<MatrixF>& getSurfaces() { return mSurfaces; } 193 void getSurfaceTriangles( S32 surfId, Vector< Point3F> *outPoints, Vector< Point2F> *outCoords, bool worldSpace ); 194 195 /// @} 196 197 /// Geometry Visualization. 198 /// @{ 199 200 void renderFaceEdges( S32 faceid, const ColorI &color = ColorI::WHITE, F32 lineWidth = 1.0f ); 201 202 /// @} 203 204protected: 205 206 void _updateMaterial(); 207 void _updateGeometry( bool updateCollision = false ); 208 void _updateCollision(); 209 void _export( OptimizedPolyList *plist, const Box3F &box, const SphereF &sphere ); 210 211 void _renderDebug( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *mat ); 212 213 static S32 QSORT_CALLBACK _comparePlaneDist( const void *a, const void *b ); 214 215 static bool protectedSetSurface( void *object, const char *index, const char *data ); 216 217protected: 218 219 // The name of the Material we will use for rendering 220 String mMaterialName; 221 222 // The actual Material instance 223 BaseMatInstance* mMaterialInst; 224 225 // The GFX vertex and primitive buffers 226 GFXVertexBufferHandle< VertexType> mVertexBuffer; 227 GFXPrimitiveBufferHandle mPrimitiveBuffer; 228 229 U32 mVertCount; 230 U32 mPrimCount; 231 232 Geometry mGeometry; 233 234 Vector< PlaneF> mPlanes; 235 236 Vector< MatrixF> mSurfaces; 237 238 Vector< Point3F> mFaceCenters; 239 240 Convex *mConvexList; 241 242 PhysicsBody *mPhysicsRep; 243 244 /// Geometry visualization 245 /// @{ 246 247 F32 mNormalLength; 248 249 /// @} 250 251}; 252 253#endif // _CONVEXSHAPE_H_ 254
