Spinning Topp Logo BlackTopp Studios
inc
extruder.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 /*
41  -----------------------------------------------------------------------------
42  This source file is part of ogre-procedural
43 
44  For the latest info, see http://code.google.com/p/ogre-procedural/
45 
46  Copyright (c) 2010-2013 Michael Broutin
47 
48  Permission is hereby granted, free of charge, to any person obtaining a copy
49  of this software and associated documentation files (the "Software"), to deal
50  in the Software without restriction, including without limitation the rights
51  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52  copies of the Software, and to permit persons to whom the Software is
53  furnished to do so, subject to the following conditions:
54 
55  The above copyright notice and this permission notice shall be included in
56  all copies or substantial portions of the Software.
57 
58  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64  THE SOFTWARE.
65  -----------------------------------------------------------------------------
66  */
67 #ifndef _graphicsproceduralextruder_cpp
68 #define _graphicsproceduralextruder_cpp
69 
70 #include "Graphics/Procedural/Mesh/extruder.h"
71 #include "Graphics/Procedural/Mesh/vertextransformmodifier.h"
72 #include "Graphics/Procedural/Mesh/vertexuvmodifier.h"
73 
74 #include "Graphics/Procedural/path.h"
75 #include "Graphics/Procedural/shape.h"
76 #include "Graphics/Procedural/triangulator.h"
77 
78 #include "MathTools/mathtools.h"
79 
80 namespace Mezzanine
81 {
82  namespace Graphics
83  {
84  namespace Procedural
85  {
87  Capped(true)
88  { }
89 
91  { }
92 
93  Vector2 Extruder::GenerateUVs(const Whole PathIndex, const Whole ShapeIndex, const Real PathCoord, const Real ShapeCoord) const
94  {
95  Vector2 Ret(PathCoord,ShapeCoord);
96  ConstTrackMapIterator PathUIt = this->PathUTextureTracks.find(PathIndex);
97  if( PathUIt != this->PathUTextureTracks.end() ) {
98  Ret.X = (*PathUIt).second->GetInterpolated(PathCoord);
99  }
100  ConstTrackMapIterator ShapeVIt = this->ShapeVTextureTracks.find(ShapeIndex);
101  if( ShapeVIt != this->ShapeVTextureTracks.end() ) {
102  Ret.Y = (*ShapeVIt).second->GetInterpolated(ShapeCoord);
103  }
104  return Ret;
105  }
106 
107  void Extruder::GenerateExtrusionShape(TriangleBuffer& Buffer, const Whole PathIndex, const Whole ShapeIndex, const Real PathCoord, const Vector3& Position, const Quaternion& LeftOri,
108  const Quaternion& RightOri, const Real Scale, const Real ScaleLeftCorrect, const Real ScaleRightCorrect, const Boole JoinWithNextShape) const
109  {
110  const Shape& ExtrudedShape = this->ShapesToExtrude.GetShape(ShapeIndex);
111  Real LineicShapePosition = 0.0;
112  Real TotalShapeLength = ExtrudedShape.GetTotalLength();
113  Whole NumShapeSegments = ExtrudedShape.GetSegCount();
114  // Insert new points
115  for( Whole PointIndex = 0 ; PointIndex <= NumShapeSegments ; ++PointIndex )
116  {
117  Vector2 Point2D = ExtrudedShape.GetPoint(PointIndex);
118  Vector2 Point2DNorm = ExtrudedShape.GetAvgNormal(PointIndex);
119  Quaternion Orientation = ( Point2D.X > 0 ) ? RightOri : LeftOri;
120  Vector3 Point3D = ( Point2D.X > 0 ) ? Vector3(ScaleRightCorrect * Point2D.X, Point2D.Y, 0) : Vector3(ScaleLeftCorrect * Point2D.X, Point2D.Y, 0);
121  Vector3 Normal(Point2DNorm.X, Point2DNorm.Y, 0);
122  Buffer.RebaseOffset();
123  Vector3 NewPoint = Position + ( Orientation * ( Point3D * Scale ) );
124  if( PointIndex > 0 ) {
125  LineicShapePosition += ( Point2D - ExtrudedShape.GetPoint( PointIndex - 1 ) ).Length();
126  }
127 
128  Buffer.AddVertex(NewPoint, Orientation * Normal, this->GenerateUVs(PathIndex,ShapeIndex,PathCoord,LineicShapePosition / TotalShapeLength));
129 
130  if( PointIndex < NumShapeSegments && JoinWithNextShape ) {
131  if( ExtrudedShape.GetOutSide() == Procedural::SS_Left ) {
132  Buffer.AddTriangle(NumShapeSegments + 1, NumShapeSegments + 2, 0);
133  Buffer.AddTriangle(0, NumShapeSegments + 2, 1);
134  }else{
135  Buffer.AddTriangle(NumShapeSegments + 2, NumShapeSegments + 1, 0);
136  Buffer.AddTriangle(NumShapeSegments + 2, 0, 1);
137  }
138  }
139  }
140  }
141 
143  {
144  IndexContainer CapIndexes;
145  Point2DContainer CapPoints;
146 
147  Triangulator CapTri;
149  CapTri.Triangulate(CapIndexes,CapPoints);
150 
151  for( Whole PathIndex = 0 ; PathIndex < this->PathsToExtrude.GetNumPaths() ; ++PathIndex )
152  {
153  const Path& CurrPath = this->PathsToExtrude.GetPath(PathIndex);
154  const ParameterTrack* CurrScaleTrack = NULL;
155  ConstTrackMapIterator ScaleIt = this->ScaleTracks.find(PathIndex);
156  if( ScaleIt != this->ScaleTracks.end() ) {
157  CurrScaleTrack = (*ScaleIt).second;
158  }
159  const ParameterTrack* CurrRotationTrack = NULL;
160  ConstTrackMapIterator RotationIt = this->RotationTracks.find(PathIndex);
161  if( RotationIt != this->RotationTracks.end() ) {
162  CurrRotationTrack = (*RotationIt).second;
163  }
164 
165  const MultiPath::IntersectionMap& PathIntersections = this->PathsToExtrude.GetIntersectionsMap();
166  // Begin Cap
167  if( PathIntersections.find( PathCoordinate(PathIndex,0) ) == PathIntersections.end() ) {
168  Buffer.RebaseOffset();
169  Buffer.EstimateIndexCount(CapIndexes.size());
170  Buffer.EstimateVertexCount(CapPoints.size());
171 
172  Quaternion QuatEnd(CurrPath.GetDirectionAfter(0),Vector3::Unit_Y());
173  if( CurrRotationTrack ) {
174  Real Angle = CurrRotationTrack->GetInterpolated(0.0);
175  QuatEnd = QuatEnd * Quaternion(Angle,Vector3::Unit_Z());
176  }
177 
178  Real ScaleBegin = 1.0;
179  if( CurrScaleTrack ) {
180  ScaleBegin = CurrScaleTrack->GetInterpolated(0.0);
181  }
182 
183  for( Whole CurrPoint = 0 ; CurrPoint < CapPoints.size() ; ++CurrPoint )
184  {
185  Vector2 Point2D = CapPoints[CurrPoint];
186  Vector3 Location( Point2D.X, Point2D.Y, 0 );
187  Vector3 Normal = Vector3::Neg_Unit_Z();
188 
189  Vector3 VertLoc = CurrPath.GetPoint(0) + ( QuatEnd * ( Location * ScaleBegin ) );
190  Buffer.AddVertex( VertLoc, QuatEnd * Normal, Point2D );
191  }
192 
193  for( Whole CurrIndex = 0 ; CurrIndex < ( CapIndexes.size() / 3 ) ; ++CurrIndex )
194  {
195  Buffer.AddIndex( CapIndexes[ CurrIndex * 9 ] );
196  Buffer.AddIndex( CapIndexes[ CurrIndex * 9 + 2 ] );
197  Buffer.AddIndex( CapIndexes[ CurrIndex * 9 + 1 ] );
198  }
199  }
200  // End Cap
201  if( PathIntersections.find( PathCoordinate(PathIndex,CurrPath.GetSegCount()) ) == PathIntersections.end() ) {
202  Buffer.RebaseOffset();
203  Buffer.EstimateIndexCount(CapIndexes.size());
204  Buffer.EstimateVertexCount(CapPoints.size());
205 
206  Quaternion QuatEnd(CurrPath.GetDirectionBefore(CurrPath.GetSegCount()),Vector3::Unit_Y());
207  if( CurrRotationTrack ) {
208  Real Angle = CurrRotationTrack->GetInterpolated(1.0);
209  QuatEnd = QuatEnd * Quaternion(Angle,Vector3::Unit_Z());
210  }
211 
212  Real ScaleEnd = 1.0;
213  if( CurrScaleTrack ) {
214  ScaleEnd = CurrScaleTrack->GetInterpolated(1.0);
215  }
216 
217  for( Whole CurrPoint = 0 ; CurrPoint < CapPoints.size() ; ++CurrPoint )
218  {
219  Vector2 Point2D = CapPoints[CurrPoint];
220  Vector3 Location( Point2D.X, Point2D.Y, 0 );
221  Vector3 Normal = Vector3::Unit_Z();
222 
223  Vector3 VertLoc = CurrPath.GetPoint(0) + ( QuatEnd * ( Location * ScaleEnd ) );
224  Buffer.AddVertex( VertLoc, QuatEnd * Normal, Point2D );
225  }
226 
227  for( Whole CurrIndex = 0 ; CurrIndex < ( CapIndexes.size() / 3 ) ; ++CurrIndex )
228  {
229  Buffer.AddIndex( CapIndexes[ CurrIndex * 9 ] );
230  Buffer.AddIndex( CapIndexes[ CurrIndex * 9 + 1 ] );
231  Buffer.AddIndex( CapIndexes[ CurrIndex * 9 + 2 ] );
232  }
233  }
234  }
235  }
236 
237  void Extruder::GenerateExtrusionSegment(TriangleBuffer& Buffer, const Whole ShapeIndex, const Whole PathIndex, const Whole PathSegBegin, const Whole PathSegEnd) const
238  {
239  const Path& CurrPath = this->PathsToExtrude.GetPath(PathIndex);
240  const Shape& CurrShape = this->ShapesToExtrude.GetShape(ShapeIndex);
241 
242  Whole NumSegmentsToExtrude = PathSegEnd - PathSegBegin;
243  Whole NumSegmentsInShape = CurrShape.GetSegCount();
244 
245  if( NumSegmentsToExtrude == 0 || NumSegmentsInShape == 0 ) {
246  MEZZ_EXCEPTION(ExceptionBase::INVALID_STATE_EXCEPTION,"The shape and path provided must contain at least 2 points to extrude.");
247  }
248 
249  // Lineic Position variables
250  Real TotalPathLength = CurrPath.GetTotalLength();
251  //Real TotalShapeLength = CurrShape.GetTotalLength();
252  Real LineicPosition = CurrPath.GetLengthAtPoint(PathSegBegin);
253 
254  // Iterators for later
255  ConstTrackMapIterator RotationTrackResult = this->RotationTracks.find(PathIndex);
256  ConstTrackMapIterator ScaleTrackResult = this->ScaleTracks.find(PathIndex);
257 
258  // Prepare the buffer
259  Buffer.RebaseOffset();
260  Buffer.EstimateVertexCount( ( NumSegmentsInShape + 1 ) * ( NumSegmentsToExtrude + 1 ) );
261  Buffer.EstimateIndexCount( NumSegmentsInShape * NumSegmentsToExtrude * 6 );
262 
263  // Should this initialize to the Y axis instead of zero?
264  Vector3 OldUp;
265  for( Whole PointIndex = PathSegBegin ; PointIndex <= PathSegEnd ; ++PointIndex )
266  {
267  Vector3 CurrPoint = CurrPath.GetPoint(PointIndex);
268  Vector3 Direction = CurrPath.GetAvgDirection(PointIndex);
269 
270  // Lineic Position
271  if( PointIndex > PathSegBegin ) {
272  LineicPosition += ( CurrPoint - CurrPath.GetPoint( PointIndex - 1 ) ).Length();
273  }
274  Real RelativeLineicPosition = LineicPosition / TotalPathLength;
275 
276  // Rotation Prep
277  Quaternion PointRotation(Direction,Vector3::Unit_Y());
278  Real Angle = ( PointRotation * Vector3::Unit_Y() ).AngleBetween(OldUp);
279  if( PointIndex > PathSegBegin && Angle > ( MathTools::GetHalfPi() * 0.5 ) ) {
280  PointRotation.SetFromAxisToZ(Direction,OldUp);
281  }
282  OldUp = PointRotation * Vector3::Unit_Y();
283 
284  // Rotation
285  if( RotationTrackResult != this->RotationTracks.end() ) {
286  Real TempAngle = (*RotationTrackResult).second->GetInterpolated(RelativeLineicPosition);
287  PointRotation = PointRotation * Quaternion(TempAngle,Vector3::Unit_Z());
288  }
289 
290  // Scale
291  Real PointScale = 1.0;
292  if( ScaleTrackResult != this->ScaleTracks.end() ) {
293  PointScale = (*ScaleTrackResult).second->GetInterpolated(RelativeLineicPosition);
294  }
295 
296  // Generate Points
297  this->GenerateExtrusionShape(Buffer,PathIndex,ShapeIndex,RelativeLineicPosition,CurrPoint,PointRotation,PointRotation,PointScale,1.0,1.0,PointIndex < PathSegEnd);
298  }
299  }
300 
301  void Extruder::GenerateExtrusionIntersection(TriangleBuffer& Buffer, const MultiPath::PathIntersection& Intersection, const Whole ShapeIndex) const
302  {
303  Quaternion FirstOrientation(this->PathsToExtrude.GetPath(Intersection[0].PathIndex).GetDirectionBefore(Intersection[0].PointIndex),Vector3::Unit_Y());
304  Vector3 RefX = FirstOrientation * Vector3::Unit_X();
305  Vector3 RefZ = FirstOrientation * Vector3::Unit_Z();
306 
307  Point2DContainer Points2D;
309  std::vector<Real> Directions;
310 
311  for( Whole CoordIndex = 0 ; CoordIndex < Intersection.size() ; ++CoordIndex )
312  {
313  const Path& IntersectionPath = this->PathsToExtrude.GetPath(Intersection[CoordIndex].PathIndex);
314  Whole PointIndex = Intersection[CoordIndex].PointIndex;
315  if( PointIndex > 0 || IntersectionPath.IsClosed() ) {
316  Vector3 VecB = IntersectionPath.GetDirectionBefore(PointIndex);
317  Vector2 VecB2D = Vector2(VecB.DotProduct(RefX), VecB.DotProduct(RefZ));
318  Points2D.push_back(VecB2D);
319  Coords.push_back(Intersection[CoordIndex]);
320  Directions.push_back(1);
321  }
322  if( PointIndex < static_cast<Whole>( IntersectionPath.GetSegCount() ) || IntersectionPath.IsClosed() ) {
323  Vector3 VecA = -IntersectionPath.GetDirectionAfter(PointIndex);
324  Vector2 VecA2D = Vector2(VecA.DotProduct(RefX), VecA.DotProduct(RefZ));
325  Points2D.push_back(VecA2D);
326  Coords.push_back(Intersection[CoordIndex]);
327  Directions.push_back(-1);
328  }
329  }
330 
331  std::map<Real,Whole> Angles;
332  for( Whole Point2DIndex = 1 ; Point2DIndex < Points2D.size() ; ++Point2DIndex )
333  {
334  Angles[ Points2D[0].AngleTo( Points2D[Point2DIndex] ) ] = Point2DIndex;
335  }
336 
337  std::vector<size_t> OrderedIndices;
338  OrderedIndices.push_back(0);
339  for( std::map<Real,Whole>::iterator IndiciesIt = Angles.begin() ; IndiciesIt != Angles.end() ; ++IndiciesIt )
340  {
341  OrderedIndices.push_back(IndiciesIt->second);
342  }
343 
344  for( size_t OrderedIndex = 0 ; OrderedIndex < OrderedIndices.size() ; ++OrderedIndex )
345  {
346  size_t CoordIndex = OrderedIndices[OrderedIndex];
347  size_t CoordIndexBefore = OrderedIndices[ MathTools::WrappedModulo( OrderedIndex - 1, OrderedIndices.size() ) ];
348  size_t CoordIndexAfter = OrderedIndices[ MathTools::WrappedModulo( OrderedIndex + 1, OrderedIndices.size() ) ];
349  Real AngleBefore = ( Points2D[CoordIndex].AngleBetween( Points2D[CoordIndexBefore] ) - MathTools::GetPi() ) / 2;
350  Real AngleAfter = ( MathTools::GetPi() - ( Points2D[CoordIndex].AngleBetween( Points2D[CoordIndexAfter] ) ) ) / 2;
351 
352  Integer PointIndex = Coords[CoordIndex].PointIndex - Directions[CoordIndex];
353  const Path& CurrPath = this->PathsToExtrude.GetPath(Coords[CoordIndex].PathIndex);
354 
355  Quaternion PointRotation(CurrPath.GetAvgDirection(PointIndex) * Directions[CoordIndex],Vector3::Unit_Y());
356  Real RelPathPos = CurrPath.GetLengthAtPoint(PointIndex) / CurrPath.GetTotalLength();
357 
358  // Shape making the joint with "standard extrusion"
359  this->GenerateExtrusionShape(Buffer,Coords[CoordIndex].PathIndex,ShapeIndex,RelPathPos,CurrPath.GetPoint(PointIndex),PointRotation,PointRotation,1.0,1.0,1.0,true);
360 
361  // Modified shape at the intersection
362  PointRotation = ( Directions[CoordIndex] > 0 ? Quaternion(CurrPath.GetDirectionBefore(Coords[CoordIndex].PointIndex),Vector3::Unit_Y()) : Quaternion(-CurrPath.GetDirectionAfter(Coords[CoordIndex].PointIndex),Vector3::Unit_Y()) );
363  Quaternion RotationLeft = PointRotation * Quaternion(AngleBefore,Vector3::Unit_Y());
364  Quaternion RotationRight = PointRotation * Quaternion(AngleAfter,Vector3::Unit_Y());
365  Real ScaleLeft = 1.0 / MathTools::Abs( MathTools::Cos(AngleBefore) );
366  Real ScaleRight = 1.0 / MathTools::Abs( MathTools::Cos(AngleAfter) );
367 
368  RelPathPos = CurrPath.GetLengthAtPoint(Coords[CoordIndex].PointIndex) / CurrPath.GetTotalLength();
369  this->GenerateExtrusionShape(Buffer,Coords[CoordIndex].PathIndex,ShapeIndex,RelPathPos,CurrPath.GetPoint(Coords[CoordIndex].PointIndex),RotationLeft,RotationRight,1.0,ScaleLeft,ScaleRight,false);
370  }
371  }
372 
373  ///////////////////////////////////////////////////////////////////////////////
374  // Utility
375 
377  {
378  if( this->ShapesToExtrude.GetNumShapes() == 0 ) {
379  MEZZ_EXCEPTION(ExceptionBase::INVALID_STATE_EXCEPTION,"At least one shape must be defined to perform an Extrude.");
380  }
381 
382  TriangleBuffer ExtrudeBuffer;
383 
384  if( this->Capped && this->ShapesToExtrude.IsClosed() ) {
385  this->GenerateExtrusionCaps(ExtrudeBuffer);
386  }
387 
388  for( Whole PathIndex = 0 ; PathIndex < this->ShapesToExtrude.GetNumShapes() ; ++PathIndex )
389  {
391  for( MultiPath::PathSegmentContainer::iterator SegIt = Segments.begin() ; SegIt != Segments.end() ; ++SegIt )
392  {
393  for( Whole ShapeIndex = 0 ; ShapeIndex < this->ShapesToExtrude.GetNumShapes() ; ++ShapeIndex )
394  {
395  this->GenerateExtrusionSegment(ExtrudeBuffer,ShapeIndex,PathIndex,(*SegIt).first,(*SegIt).second);
396  }
397  }
398 
399  const MultiPath::IntersectionVector& Intersections = this->PathsToExtrude.GetIntersections();
400  for( MultiPath::IntersectionVector::const_iterator IntersectIt = Intersections.begin() ; IntersectIt != Intersections.end() ; ++IntersectIt )
401  {
402  for( Whole ShapeIndex = 0 ; ShapeIndex < this->ShapesToExtrude.GetNumShapes() ; ++ShapeIndex )
403  {
404  this->GenerateExtrusionIntersection(ExtrudeBuffer,(*IntersectIt),ShapeIndex);
405  }
406  }
407  }
408 
411  Buffer.AppendBuffer(ExtrudeBuffer);
412  }
413 
414  ///////////////////////////////////////////////////////////////////////////////
415  // Configuration
416 
418  {
420  this->PathsToExtrude.AddPath(ToExtrude);
422  return *this;
423  }
424 
426  {
428  this->PathsToExtrude.AddMultiPath(ToExtrude);
430  return *this;
431  }
432 
434  {
436  this->ShapesToExtrude.AddShape(ToExtrude);
437  return *this;
438  }
439 
441  {
443  this->ShapesToExtrude.AddMultiShape(ToExtrude);
444  return *this;
445  }
446 
448  {
449  if( Scale != NULL ) {
450  this->ScaleTracks[PathIndex] = Scale;
451  }
452  return *this;
453  }
454 
456  {
457  if( Rotation != NULL ) {
458  this->RotationTracks[PathIndex] = Rotation;
459  }
460  return *this;
461  }
462 
464  {
465  if( PathU != NULL ) {
466  this->PathUTextureTracks[PathIndex] = PathU;
467  }
468  return *this;
469  }
470 
472  {
473 
474  if( ShapeV != NULL ) {
475  this->ShapeVTextureTracks[ShapeIndex] = ShapeV;
476  }
477  return *this;
478  }
479 
481  {
482  this->Capped = Cap;
483  return *this;
484  }
485  }//Procedural
486  }//Graphics
487 }//Mezzanine
488 
489 #endif
490 
VertexTransformModifier & SetTranslation(const Vector3 &Trans)
Sets the linear movement to apply.
MultiPath & AddMultiPath(const MultiPath &Other)
Append every path of another MultiShape to this MultiPath.
Definition: multipath.cpp:190
void GenerateExtrusionCaps(TriangleBuffer &Buffer) const
Creates the caps at the end of each shape extruded along a given Path.
Definition: extruder.cpp:142
Path & GetPath(const Whole Index)
Gets a path by index.
Definition: multipath.cpp:199
const IntersectionMap & GetIntersectionsMap() const
Gets the container storing all calculated intersections based on their path coordinate.
Definition: multipath.cpp:229
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Real GetTotalLength() const
Gets the total length of all segments in this path.
Definition: path.cpp:226
const Vector2 & GetPoint(const Integer Index) const
Gets a point by index which can be out of bounds and will wrap.
Definition: shape.cpp:694
A modifier that will transform the UV coordinates of a mesh.
VertexUVModifier & SetUVTile(const Vector2 &Tile)
Sets the scaling to apply to each vertex UV.
Extruder & SetMultiPathToExtrude(const MultiPath &ToExtrude)
Sets a MultiPath to be extruded along.
Definition: extruder.cpp:425
MultiPath & CalculateIntersections()
Generates all the known intersections between the paths in this MultiPath.
Definition: multipath.cpp:122
A generator that will create a 3D model by moving a 2D shape along a 3D Path.
Definition: extruder.h:84
A convenience buffer that stores vertices and indices of a mesh to be generated.
const IntersectionVector & GetIntersections() const
Gets the container storing all calculated intersections.
Definition: multipath.cpp:224
Procedural::ShapeSide GetOutSide() const
Gets which side is the OutSide of this shape.
Definition: shape.cpp:833
A convenience class for tracking points in a MultiPath.
Definition: multipath.h:83
MultiShape & AddShape(const Shape &ToAdd)
Adds a shape to this MultiShape.
Definition: multishape.cpp:298
TrackMap RotationTracks
A map of optional Tracks that store how the shapes on a given Path are to be rotated.
Definition: extruder.h:107
VertexUVModifier & SetUVTranslate(const Vector2 &Trans)
Sets the translation to apply to each vertex UV.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
void EstimateIndexCount(const Whole IndexCount)
Gives an estimation of the number of indices needed for this triangle buffer.
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
void GenerateExtrusionSegment(TriangleBuffer &Buffer, const Whole ShapeIndex, const Whole PathIndex, const Whole PathSegBegin, const Whole PathSegEnd) const
Creates a sequence of non-intersecting segments.
Definition: extruder.cpp:237
std::vector< PathCoordinate > PathIntersection
Convenience type used to represent the intersection of two or more paths.
Definition: multipath.h:128
Vector3 GetAvgDirection(const Whole Index) const
Gets the averaged direction from the specified point to both the next and previous points in the sequ...
Definition: path.cpp:375
void AppendBuffer(const TriangleBuffer &Other)
Appends the contents of another buffer to this buffer.
Real GetLengthAtPoint(const Whole PointIndex) const
Gets the total length to the point in this path at an index.
Definition: path.cpp:237
void GenerateExtrusionIntersection(TriangleBuffer &Buffer, const MultiPath::PathIntersection &Intersection, const Whole ShapeIndex) const
Creates an intersection of segments.
Definition: extruder.cpp:301
MultiShape ShapesToExtrude
A MultiShape storing all of the 2D shapes that will be extruded along the specified Paths...
Definition: extruder.h:101
Extruder & SetPathUTextureTrack(const Whole PathIndex, ParameterTrack *PathU)
Sets how the "U" component texture coordinates are to be generated for extruded shapes.
Definition: extruder.cpp:463
MultiPath & AddPath(const Path &ToAdd)
Adds a path to this MultiPath.
Definition: multipath.cpp:184
TrackMap ShapeVTextureTracks
A map of optional Tracks that store how texture coordinates are to be assigned along the Shapes being...
Definition: extruder.h:113
Boole IsClosed() const
Gets whether or not every Shape in this MultiShape is closed.
Definition: multishape.cpp:285
Boole Capped
Whether or not the ends of each Path will be capped.
Definition: extruder.h:116
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
PathSegmentContainer GetNoIntersectionParts(const Whole PathIndex) const
Gets segments from a specific sub-path that do not intersect other Paths of this MultiPath.
Definition: multipath.cpp:155
std::map< PathCoordinate, PathIntersection > IntersectionMap
Container type for the storage of unique intersections.
Definition: multipath.h:132
std::vector< Integer > IndexContainer
A container of Integers used to represent the indicies of a shape.
std::vector< PathSegment > PathSegmentContainer
Container type for segments in a Path.
Definition: multipath.h:136
std::vector< Vector2 > Point2DContainer
Basic container type for the storage of 2D points.
VertexTransformModifier & SetRotation(const Quaternion &Rot)
Sets how to rotate the mesh.
Whether or not to swap the UV compontents when generating a mesh.
Definition: meshgenerator.h:94
Extruder & SetScaleTrack(const Whole PathIndex, ParameterTrack *Scale)
Sets how shapes are to be scaled on a specific Path.
Definition: extruder.cpp:447
Real Y
Coordinate on the Y vector.
Definition: vector2.h:69
A modifier that will update the transform of every vertex in a mesh.
Vector3 Position
Position to apply to the mesh.
void SetFromAxisToZ(const Vector3 &DirectionAxis, const Vector3 &UpAxis)
Generates and sets the values of this quaternion to describe a rotation from the direction axis to th...
Definition: quaternion.cpp:175
Real X
Coordinate on the X vector.
Definition: vector2.h:67
Boole IsClosed() const
Gets whether or not the final point in this path connects to the first point.
Definition: path.cpp:267
virtual InterpolatableType GetInterpolated(Real Percentage) const
Get a value from somewhere on the track with 0.0 being the beginning and 1.0 being the end...
Definition: track.h:179
void EstimateVertexCount(const Whole VertexCount)
Gives an estimation of the number of vertices need for this triangle buffer.
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
static Vector3 Unit_Y()
Gets a vector representing the Y unit of a Vector3.
Definition: vector3.cpp:134
TrackMap ScaleTracks
A map of optional Tracks that store how the shapes on a given Path are to be scaled.
Definition: extruder.h:104
Whole GetSegCount() const
Gets the number of segments in this shape.
Definition: shape.cpp:472
TriangleBuffer & AddTriangle(const Integer Index1, const Integer Index2, const Integer Index3)
Adds a triangle to the index buffer.
VertexUVModifier & SetSwitchUV(const Boole Switch)
Sets if UV's will swap components.
Extruder & SetRotationTrack(const Whole PathIndex, ParameterTrack *Rotation)
Sets how shapes are to be rotated on a specific Path.
Definition: extruder.cpp:455
std::vector< PathIntersection > IntersectionVector
Container type for the storage of intersections.
Definition: multipath.h:130
A generator class that implements the Delaunay Triangulation algorithm.
Definition: triangulator.h:252
Extruder & SetPathToExtrude(const Path &ToExtrude)
Sets a single Path to be extruded along.
Definition: extruder.cpp:417
Real GetTotalLength() const
Gets the total length of all segments in this shape.
Definition: shape.cpp:475
Thrown when the available information should have worked but failed for unknown reasons.
Definition: exception.h:113
const Vector3 & GetPoint(const Integer Index) const
Safely gets a point in this path.
Definition: path.cpp:299
Real VTile
V tile for texture coords generation.
Vector3 GetDirectionBefore(const Whole Index) const
Gets the direction from a point to the previous point in the sequence.
Definition: path.cpp:364
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
Definition: vector3.cpp:131
virtual void AddToTriangleBuffer(TriangleBuffer &Buffer) const
Adds the vertices and indices as configured in this generator to a triangle buffer.
Definition: extruder.cpp:376
void RemoveAllShapes()
Removes all shapes from this MultiShape.
Definition: multishape.cpp:320
Real DotProduct(const Vector3 &Vec) const
This is used to calculate the dotproduct of this and another vector.
Definition: vector3.cpp:347
void GenerateExtrusionShape(TriangleBuffer &Buffer, const Whole PathIndex, const Whole ShapeIndex, const Real PathCoord, const Vector3 &Position, const Quaternion &LeftOri, const Quaternion &RightOri, const Real Scale, const Real ScaleLeftCorrect, const Real ScaleRightCorrect, const Boole JoinWithNextShape) const
Creates a single part of a segment being extruded.
Definition: extruder.cpp:107
void Triangulate(IndexContainer &Indexes, Point2DContainer &Vertices) const
Executes the Constrained Delaunay Triangulation algorithm. INVALID_STATE_EXCEPTION will be thrown if ...
Whole GetNumShapes() const
Gets the number of shapes in this MultiShape.
Definition: multishape.cpp:317
TrackMap PathUTextureTracks
A map of optional Tracks that store how texture coordinates are to be assigned along the Paths being ...
Definition: extruder.h:110
static Vector3 Unit_Z()
Gets a vector representing the Z unit of a Vector3.
Definition: vector3.cpp:137
TriangleBuffer & AddIndex(const Integer Index)
Adds an index to the index buffer.
Extruder & SetShapeVTextureTrack(const Whole ShapeIndex, ParameterTrack *ShapeV)
Sets how the "V" component texture coordinates are to be generated for extruded shapes.
Definition: extruder.cpp:471
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
MultiPath PathsToExtrude
A MultiPath storing all of the Paths the 2D shapes will be extruded along.
Definition: extruder.h:98
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
Extruder & SetShapeToExtrude(const Shape &ToExtrude)
Sets a single Shape to be extruded.
Definition: extruder.cpp:433
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
VertexTransformModifier & SetScaling(const Vector3 &Scale)
Sets the scaling to apply.
Triangulator & SetMultiShapeToTriangulate(const MultiShape *TriMultiShape)
Sets multi shape to triangulate.
A grouping of individual 3D curves used to express complicated structures.
Definition: multipath.h:118
Integer GetSegCount() const
Gets the number of segments in this path.
Definition: path.cpp:221
Extruder & SetCapped(const Boole Cap)
Sets whether or not the ends of each Path extruded are to be enclosed.
Definition: extruder.cpp:480
Extruder & SetMultiShapeToExtrude(const MultiShape &ToExtrude)
Sets a Multishape to be extruded.
Definition: extruder.cpp:440
UInt8 GeneratorOpts
Storage for the boolean options to be used by this generator.
Real UTile
U tile for texture coords generation.
Vector2 GetAvgNormal(const Whole Index) const
Gets the averaged normal of the segments before and after the specified point.
Definition: shape.cpp:816
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68
MultiShape & AddMultiShape(const MultiShape &Other)
Append every shape of another MultiShape to this MultiShape.
Definition: multishape.cpp:304
A collection of interconnected 2D points used to express an arbitrary 2D shape.
Definition: shape.h:95
Shape & GetShape(const Whole Index)
Gets a shape by index.
Definition: multishape.cpp:311
A grouping of individual 2D shapes used to express more elaborate shapes.
Definition: multishape.h:87
virtual void Modify(TriangleBuffer &Buffer)
Alters the generated pixels in a TriangleBuffer.
Whole GetNumPaths() const
Gets the number of shapes in this MultiPath.
Definition: multipath.cpp:209
static Vector3 Neg_Unit_Z()
Gets a vector representing the negative Z unit of a Vector3.
Definition: vector3.cpp:146
void RemoveAllPaths()
Removes all shapes from this MultiPath.
Definition: multipath.cpp:214
Vector2 GenerateUVs(const Whole PathIndex, const Whole ShapeIndex, const Real PathCoord, const Real ShapeCoord) const
Creates appropriate UV coordinates for a given Vertex.
Definition: extruder.cpp:93
virtual ~Extruder()
Class destructor.
Definition: extruder.cpp:90
A collection of interconnected 3D points used to express path through 3D space.
Definition: path.h:93
TrackMap::const_iterator ConstTrackMapIterator
Const Iterator type for ParameterTracks.
Definition: extruder.h:94
Quaternion Orientation
Orientation to apply the mesh.
A base type that provides container features for different tracks.
Definition: track.h:65
virtual void Modify(TriangleBuffer &Buffer)
Alters the generated pixels in a TriangleBuffer.
Vector3 GetDirectionAfter(const Whole Index) const
Gets the direction of a point to the next point in the sequence.
Definition: path.cpp:353
TriangleBuffer & AddVertex(const Vertex &Vert)
Adds a premade Vertex to the buffer.
Vector2 UVOrigin
Rectangle in which the texture coordinates will be placed.