67 #ifndef _graphicsproceduralextruder_cpp
68 #define _graphicsproceduralextruder_cpp
70 #include "Graphics/Procedural/Mesh/extruder.h"
71 #include "Graphics/Procedural/Mesh/vertextransformmodifier.h"
72 #include "Graphics/Procedural/Mesh/vertexuvmodifier.h"
74 #include "Graphics/Procedural/path.h"
75 #include "Graphics/Procedural/shape.h"
76 #include "Graphics/Procedural/triangulator.h"
78 #include "MathTools/mathtools.h"
95 Vector2 Ret(PathCoord,ShapeCoord);
98 Ret.
X = (*PathUIt).second->GetInterpolated(PathCoord);
102 Ret.
Y = (*ShapeVIt).second->GetInterpolated(ShapeCoord);
108 const Quaternion& RightOri,
const Real Scale,
const Real ScaleLeftCorrect,
const Real ScaleRightCorrect,
const Boole JoinWithNextShape)
const
111 Real LineicShapePosition = 0.0;
115 for(
Whole PointIndex = 0 ; PointIndex <= NumShapeSegments ; ++PointIndex )
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);
123 Vector3 NewPoint = Position + ( Orientation * ( Point3D *
Scale ) );
124 if( PointIndex > 0 ) {
125 LineicShapePosition += ( Point2D - ExtrudedShape.
GetPoint( PointIndex - 1 ) ).Length();
128 Buffer.
AddVertex(NewPoint, Orientation * Normal, this->
GenerateUVs(PathIndex,ShapeIndex,PathCoord,LineicShapePosition / TotalShapeLength));
130 if( PointIndex < NumShapeSegments && JoinWithNextShape ) {
132 Buffer.
AddTriangle(NumShapeSegments + 1, NumShapeSegments + 2, 0);
135 Buffer.
AddTriangle(NumShapeSegments + 2, NumShapeSegments + 1, 0);
157 CurrScaleTrack = (*ScaleIt).second;
162 CurrRotationTrack = (*RotationIt).second;
167 if( PathIntersections.find(
PathCoordinate(PathIndex,0) ) == PathIntersections.end() ) {
173 if( CurrRotationTrack ) {
178 Real ScaleBegin = 1.0;
179 if( CurrScaleTrack ) {
183 for(
Whole CurrPoint = 0 ; CurrPoint < CapPoints.size() ; ++CurrPoint )
185 Vector2 Point2D = CapPoints[CurrPoint];
186 Vector3 Location( Point2D.
X, Point2D.
Y, 0 );
189 Vector3 VertLoc = CurrPath.
GetPoint(0) + ( QuatEnd * ( Location * ScaleBegin ) );
190 Buffer.
AddVertex( VertLoc, QuatEnd * Normal, Point2D );
193 for(
Whole CurrIndex = 0 ; CurrIndex < ( CapIndexes.size() / 3 ) ; ++CurrIndex )
195 Buffer.
AddIndex( CapIndexes[ CurrIndex * 9 ] );
196 Buffer.
AddIndex( CapIndexes[ CurrIndex * 9 + 2 ] );
197 Buffer.
AddIndex( CapIndexes[ CurrIndex * 9 + 1 ] );
207 if( CurrRotationTrack ) {
213 if( CurrScaleTrack ) {
217 for(
Whole CurrPoint = 0 ; CurrPoint < CapPoints.size() ; ++CurrPoint )
219 Vector2 Point2D = CapPoints[CurrPoint];
220 Vector3 Location( Point2D.
X, Point2D.
Y, 0 );
223 Vector3 VertLoc = CurrPath.
GetPoint(0) + ( QuatEnd * ( Location * ScaleEnd ) );
224 Buffer.
AddVertex( VertLoc, QuatEnd * Normal, Point2D );
227 for(
Whole CurrIndex = 0 ; CurrIndex < ( CapIndexes.size() / 3 ) ; ++CurrIndex )
229 Buffer.
AddIndex( CapIndexes[ CurrIndex * 9 ] );
230 Buffer.
AddIndex( CapIndexes[ CurrIndex * 9 + 1 ] );
231 Buffer.
AddIndex( CapIndexes[ CurrIndex * 9 + 2 ] );
242 Whole NumSegmentsToExtrude = PathSegEnd - PathSegBegin;
245 if( NumSegmentsToExtrude == 0 || NumSegmentsInShape == 0 ) {
265 for(
Whole PointIndex = PathSegBegin ; PointIndex <= PathSegEnd ; ++PointIndex )
271 if( PointIndex > PathSegBegin ) {
272 LineicPosition += ( CurrPoint - CurrPath.
GetPoint( PointIndex - 1 ) ).Length();
274 Real RelativeLineicPosition = LineicPosition / TotalPathLength;
279 if( PointIndex > PathSegBegin && Angle > ( MathTools::GetHalfPi() * 0.5 ) ) {
286 Real TempAngle = (*RotationTrackResult).second->GetInterpolated(RelativeLineicPosition);
291 Real PointScale = 1.0;
292 if( ScaleTrackResult != this->
ScaleTracks.end() ) {
293 PointScale = (*ScaleTrackResult).second->GetInterpolated(RelativeLineicPosition);
297 this->
GenerateExtrusionShape(Buffer,PathIndex,ShapeIndex,RelativeLineicPosition,CurrPoint,PointRotation,PointRotation,PointScale,1.0,1.0,PointIndex < PathSegEnd);
309 std::vector<Real> Directions;
311 for(
Whole CoordIndex = 0 ; CoordIndex < Intersection.size() ; ++CoordIndex )
314 Whole PointIndex = Intersection[CoordIndex].PointIndex;
315 if( PointIndex > 0 || IntersectionPath.
IsClosed() ) {
318 Points2D.push_back(VecB2D);
319 Coords.push_back(Intersection[CoordIndex]);
320 Directions.push_back(1);
322 if( PointIndex < static_cast<Whole>( IntersectionPath.
GetSegCount() ) || IntersectionPath.
IsClosed() ) {
325 Points2D.push_back(VecA2D);
326 Coords.push_back(Intersection[CoordIndex]);
327 Directions.push_back(-1);
331 std::map<Real,Whole> Angles;
332 for(
Whole Point2DIndex = 1 ; Point2DIndex < Points2D.size() ; ++Point2DIndex )
334 Angles[ Points2D[0].AngleTo( Points2D[Point2DIndex] ) ] = Point2DIndex;
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 )
341 OrderedIndices.push_back(IndiciesIt->second);
344 for(
size_t OrderedIndex = 0 ; OrderedIndex < OrderedIndices.size() ; ++OrderedIndex )
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;
352 Integer PointIndex = Coords[CoordIndex].PointIndex - Directions[CoordIndex];
359 this->
GenerateExtrusionShape(Buffer,Coords[CoordIndex].PathIndex,ShapeIndex,RelPathPos,CurrPath.
GetPoint(PointIndex),PointRotation,PointRotation,1.0,1.0,1.0,
true);
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) );
369 this->
GenerateExtrusionShape(Buffer,Coords[CoordIndex].PathIndex,ShapeIndex,RelPathPos,CurrPath.
GetPoint(Coords[CoordIndex].PointIndex),RotationLeft,RotationRight,1.0,ScaleLeft,ScaleRight,
false);
391 for( MultiPath::PathSegmentContainer::iterator SegIt = Segments.begin() ; SegIt != Segments.end() ; ++SegIt )
400 for( MultiPath::IntersectionVector::const_iterator IntersectIt = Intersections.begin() ; IntersectIt != Intersections.end() ; ++IntersectIt )
449 if( Scale != NULL ) {
457 if( Rotation != NULL ) {
465 if( PathU != NULL ) {
474 if( ShapeV != NULL ) {
MultiPath & AddMultiPath(const MultiPath &Other)
Append every path of another MultiShape to this MultiPath.
void GenerateExtrusionCaps(TriangleBuffer &Buffer) const
Creates the caps at the end of each shape extruded along a given Path.
Path & GetPath(const Whole Index)
Gets a path by index.
const IntersectionMap & GetIntersectionsMap() const
Gets the container storing all calculated intersections based on their path coordinate.
bool Boole
Generally acts a single bit, true or false.
Real GetTotalLength() const
Gets the total length of all segments in this path.
const Vector2 & GetPoint(const Integer Index) const
Gets a point by index which can be out of bounds and will wrap.
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.
MultiPath & CalculateIntersections()
Generates all the known intersections between the paths in this MultiPath.
A generator that will create a 3D model by moving a 2D shape along a 3D Path.
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.
Procedural::ShapeSide GetOutSide() const
Gets which side is the OutSide of this shape.
A convenience class for tracking points in a MultiPath.
MultiShape & AddShape(const Shape &ToAdd)
Adds a shape to this MultiShape.
TrackMap RotationTracks
A map of optional Tracks that store how the shapes on a given Path are to be rotated.
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.
void EstimateIndexCount(const Whole IndexCount)
Gives an estimation of the number of indices needed for this triangle buffer.
void RebaseOffset()
Rebase index offset.
int Integer
A datatype used to represent any integer close to.
void GenerateExtrusionSegment(TriangleBuffer &Buffer, const Whole ShapeIndex, const Whole PathIndex, const Whole PathSegBegin, const Whole PathSegEnd) const
Creates a sequence of non-intersecting segments.
std::vector< PathCoordinate > PathIntersection
Convenience type used to represent the intersection of two or more paths.
Vector3 GetAvgDirection(const Whole Index) const
Gets the averaged direction from the specified point to both the next and previous points in the sequ...
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.
void GenerateExtrusionIntersection(TriangleBuffer &Buffer, const MultiPath::PathIntersection &Intersection, const Whole ShapeIndex) const
Creates an intersection of segments.
MultiShape ShapesToExtrude
A MultiShape storing all of the 2D shapes that will be extruded along the specified Paths...
Vector3 Scale
Scale to apply to the mesh.
Extruder & SetPathUTextureTrack(const Whole PathIndex, ParameterTrack *PathU)
Sets how the "U" component texture coordinates are to be generated for extruded shapes.
MultiPath & AddPath(const Path &ToAdd)
Adds a path to this MultiPath.
TrackMap ShapeVTextureTracks
A map of optional Tracks that store how texture coordinates are to be assigned along the Shapes being...
Boole IsClosed() const
Gets whether or not every Shape in this MultiShape is closed.
Boole Capped
Whether or not the ends of each Path will be capped.
float Real
A Datatype used to represent a real floating point number.
PathSegmentContainer GetNoIntersectionParts(const Whole PathIndex) const
Gets segments from a specific sub-path that do not intersect other Paths of this MultiPath.
std::map< PathCoordinate, PathIntersection > IntersectionMap
Container type for the storage of unique intersections.
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.
std::vector< Vector2 > Point2DContainer
Basic container type for the storage of 2D points.
Whether or not to swap the UV compontents when generating a mesh.
Extruder & SetScaleTrack(const Whole PathIndex, ParameterTrack *Scale)
Sets how shapes are to be scaled on a specific Path.
Extruder()
Class constructor.
Real Y
Coordinate on the Y vector.
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...
Real X
Coordinate on the X vector.
Boole IsClosed() const
Gets whether or not the final point in this path connects to the first point.
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...
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.
static Vector3 Unit_Y()
Gets a vector representing the Y unit of a Vector3.
TrackMap ScaleTracks
A map of optional Tracks that store how the shapes on a given Path are to be scaled.
Whole GetSegCount() const
Gets the number of segments in this shape.
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.
std::vector< PathIntersection > IntersectionVector
Container type for the storage of intersections.
A generator class that implements the Delaunay Triangulation algorithm.
Extruder & SetPathToExtrude(const Path &ToExtrude)
Sets a single Path to be extruded along.
Real GetTotalLength() const
Gets the total length of all segments in this shape.
Thrown when the available information should have worked but failed for unknown reasons.
const Vector3 & GetPoint(const Integer Index) const
Safely gets a point in this path.
Use the left side of the shape.
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.
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
virtual void AddToTriangleBuffer(TriangleBuffer &Buffer) const
Adds the vertices and indices as configured in this generator to a triangle buffer.
void RemoveAllShapes()
Removes all shapes from this MultiShape.
Real DotProduct(const Vector3 &Vec) const
This is used to calculate the dotproduct of this and another vector.
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.
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.
TrackMap PathUTextureTracks
A map of optional Tracks that store how texture coordinates are to be assigned along the Paths being ...
static Vector3 Unit_Z()
Gets a vector representing the Z unit of a Vector3.
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.
This is used to represent a point in space, or a vector through space.
MultiPath PathsToExtrude
A MultiPath storing all of the Paths the 2D shapes will be extruded along.
The bulk of the engine components go in this namspace.
Extruder & SetShapeToExtrude(const Shape &ToExtrude)
Sets a single Shape to be extruded.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Triangulator & SetMultiShapeToTriangulate(const MultiShape *TriMultiShape)
Sets multi shape to triangulate.
A grouping of individual 3D curves used to express complicated structures.
Integer GetSegCount() const
Gets the number of segments in this path.
Extruder & SetCapped(const Boole Cap)
Sets whether or not the ends of each Path extruded are to be enclosed.
Extruder & SetMultiShapeToExtrude(const MultiShape &ToExtrude)
Sets a Multishape to be extruded.
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.
This is used to store information about rotation in 3d space.
MultiShape & AddMultiShape(const MultiShape &Other)
Append every shape of another MultiShape to this MultiShape.
A collection of interconnected 2D points used to express an arbitrary 2D shape.
Shape & GetShape(const Whole Index)
Gets a shape by index.
A grouping of individual 2D shapes used to express more elaborate shapes.
virtual void Modify(TriangleBuffer &Buffer)
Alters the generated pixels in a TriangleBuffer.
Whole GetNumPaths() const
Gets the number of shapes in this MultiPath.
static Vector3 Neg_Unit_Z()
Gets a vector representing the negative Z unit of a Vector3.
void RemoveAllPaths()
Removes all shapes from this MultiPath.
Vector2 GenerateUVs(const Whole PathIndex, const Whole ShapeIndex, const Real PathCoord, const Real ShapeCoord) const
Creates appropriate UV coordinates for a given Vertex.
virtual ~Extruder()
Class destructor.
A collection of interconnected 3D points used to express path through 3D space.
TrackMap::const_iterator ConstTrackMapIterator
Const Iterator type for ParameterTracks.
Quaternion Orientation
Orientation to apply the mesh.
A base type that provides container features for different tracks.
Vector3 GetDirectionAfter(const Whole Index) const
Gets the direction of a point to the next point in the sequence.
TriangleBuffer & AddVertex(const Vertex &Vert)
Adds a premade Vertex to the buffer.
Vector2 UVOrigin
Rectangle in which the texture coordinates will be placed.