Torque3D Documentation / _generateds / optimizedPolyList.h

optimizedPolyList.h

Engine/source/collision/optimizedPolyList.h

More...

Classes:

class

A concrete, renderable PolyList.

Public Defines

define
DEV() 0.01

Detailed Description

Public Defines

DEV() 0.01
  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 _OPTIMIZEDPOLYLIST_H_
 25#define _OPTIMIZEDPOLYLIST_H_
 26
 27#ifndef _ABSTRACTPOLYLIST_H_
 28#include "collision/abstractPolyList.h"
 29#endif
 30
 31#ifndef _MPOLYHEDRON_H_
 32#include "math/mPolyhedron.h"
 33#endif
 34
 35#define DEV 0.01
 36
 37/// A concrete, renderable PolyList
 38///
 39/// This class is used to store geometry from a PolyList query.
 40/// 
 41/// @see AbstractPolyList
 42class OptimizedPolyList : public AbstractPolyList
 43{
 44  public:
 45
 46   enum PolyType
 47   {
 48      TriangleFan,
 49      TriangleStrip,
 50      TriangleList
 51   };
 52
 53   struct VertIndex
 54   {
 55      S32 vertIdx;
 56      S32 normalIdx;
 57      S32 uv0Idx;
 58      S32 uv1Idx;
 59
 60      VertIndex()
 61         : vertIdx( -1 ),
 62           normalIdx ( -1 ),
 63           uv0Idx( -1 ),
 64           uv1Idx( -1 )
 65      {
 66      }
 67
 68      bool operator==(const VertIndex& _test) const
 69      {
 70         return ( vertIdx   == _test.vertIdx &&
 71                  normalIdx == _test.normalIdx &&
 72                  uv0Idx    == _test.uv0Idx &&
 73                  uv1Idx    == _test.uv1Idx );
 74      }
 75   };
 76
 77   struct Poly
 78   {
 79      S32 plane;
 80      S32 material;
 81      U32 vertexStart;
 82      U32 vertexCount;
 83      U32 surfaceKey;
 84
 85      SceneObject* object;
 86
 87      PolyType type;
 88
 89      Poly()
 90         : plane( -1 ),
 91           material( NULL ),
 92           vertexStart(0),
 93           vertexCount( 0 ),
 94           surfaceKey(0),
 95           object( NULL ),
 96           type( TriangleFan )
 97      {
 98      }
 99   };
100
101   // Vertex data
102   Vector<Point3F>   mPoints;
103   Vector<Point3F>   mNormals;
104   Vector<Point2F>   mUV0s;
105   Vector<Point2F>   mUV1s;
106
107   // List of the VertIndex structure that puts
108   // all of the vertex data together
109   Vector<VertIndex> mVertexList;
110
111   // Polygon data
112   Vector<U32>       mIndexList;
113   Vector<PlaneF>    mPlaneList;
114
115   Vector<BaseMatInstance*> mMaterialList;
116
117   // The Polygon structure puts the vertex data
118   // and the polygon together
119   Vector<Poly>      mPolyList;
120
121  public:
122   OptimizedPolyList();
123   ~OptimizedPolyList();
124   void clear();
125
126   // Virtual methods
127   U32  addPoint(const Point3F& p);
128   U32  addPlane(const PlaneF& plane);
129
130   void begin(BaseMatInstance* material, U32 surfaceKey);
131   void begin(BaseMatInstance* material, U32 surfaceKey, PolyType type);
132   void plane(U32 v1, U32 v2, U32 v3);
133   void plane(const PlaneF& p);
134   void plane(const U32 index);
135   void vertex(U32 vi);
136   void vertex(const Point3F& p);
137   void vertex(const Point3F& p,
138               const Point3F& normal,
139               const Point2F& uv0 = Point2F(0.0f, 0.0f),
140               const Point2F& uv1 = Point2F(0.0f, 0.0f));
141   void end();
142
143   U32 insertPoint(const Point3F& point);
144   U32 insertNormal(const Point3F& normal);
145   U32 insertUV0(const Point2F& uv);
146   U32 insertUV1(const Point2F& uv);
147   U32 insertPlane(const PlaneF& plane);
148   U32 insertMaterial(BaseMatInstance* baseMat);
149
150   U32 insertVertex(const Point3F& point,
151                    const Point3F& normal = Point3F(0.0f, 0.0f, 1.0f),
152                    const Point2F& uv0    = Point2F(0.0f, 0.0f),
153                    const Point2F& uv1    = Point2F(0.0f, 0.0f));
154
155   bool isEmpty() const;
156
157   Polyhedron toPolyhedron() const;
158
159  protected:
160   const PlaneF& getIndexedPlane(const U32 index);
161};
162
163#endif  // _OPTIMIZEDPOLYLIST_H_
164