Spinning Topp Logo BlackTopp Studios
inc
extruder.h
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_h
68 #define _graphicsproceduralextruder_h
69 
70 #include "Graphics/Procedural/Mesh/meshgenerator.h"
71 #include "Graphics/Procedural/multipath.h"
72 #include "Graphics/Procedural/multishape.h"
73 
74 namespace Mezzanine
75 {
76  namespace Graphics
77  {
78  namespace Procedural
79  {
80  ///////////////////////////////////////////////////////////////////////////////
81  /// @brief A generator that will create a 3D model by moving a 2D shape along a 3D Path.
82  /// @details
83  ///////////////////////////////////////
84  class MEZZ_LIB Extruder : public MeshGenerator<Extruder>
85  {
86  public:
87  /// @brief Convenience type for a Track that stores additional optional data.
89  /// @brief Container type for storing ParameterTracks.
90  typedef std::map< Whole, ParameterTrack* > TrackMap;
91  /// @brief Iterator type for ParameterTracks.
92  typedef TrackMap::iterator TrackMapIterator;
93  /// @brief Const Iterator type for ParameterTracks.
94  typedef TrackMap::const_iterator ConstTrackMapIterator;
95  protected:
96  /// @internal
97  /// @brief A MultiPath storing all of the Paths the 2D shapes will be extruded along.
99  /// @internal
100  /// @brief A MultiShape storing all of the 2D shapes that will be extruded along the specified Paths.
102  /// @internal
103  /// @brief A map of optional Tracks that store how the shapes on a given Path are to be scaled.
104  TrackMap ScaleTracks;
105  /// @internal
106  /// @brief A map of optional Tracks that store how the shapes on a given Path are to be rotated.
107  TrackMap RotationTracks;
108  /// @internal
109  /// @brief A map of optional Tracks that store how texture coordinates are to be assigned along the Paths being extruded along.
111  /// @internal
112  /// @brief A map of optional Tracks that store how texture coordinates are to be assigned along the Shapes being extruded.
114  /// @internal
115  /// @brief Whether or not the ends of each Path will be capped.
117 
118  /// @internal
119  /// @brief Creates appropriate UV coordinates for a given Vertex.
120  /// @param PathIndex The index of the Path being extruded.
121  /// @param ShapeIndex The index of the Shape being extruded.
122  /// @param PathCoord The coordinate position on the current Path being extruded.
123  /// @param ShapeCoord The coordinate position on the current Shape being extruded.
124  /// @return Returns a Vector2 with Path and Shape appropriate UV coordinates.
125  Vector2 GenerateUVs(const Whole PathIndex, const Whole ShapeIndex, const Real PathCoord, const Real ShapeCoord) const;
126  /// @internal
127  /// @brief Creates the caps at the end of each shape extruded along a given Path.
128  /// @param Buffer The buffer to be modified.
129  void GenerateExtrusionCaps(TriangleBuffer& Buffer) const;
130  /// @internal
131  /// @brief Creates a single part of a segment being extruded.
132  /// @param Buffer The buffer to be modified.
133  /// @param PathIndex The index of the Path being extruded.
134  /// @param ShapeIndex The index of the Shape being extruded.
135  /// @param PathCoord The coordinate position on the current Path being extruded.
136  /// @param Position The position on the Path the Shape will be extruded at.
137  /// @param LeftOri The rotation to be applied to Negative-X positioned points in the Shape being extruded.
138  /// @param RightOri The rotation to be applied to Positive-X positioned points in the Shape being extruded.
139  /// @param Scale The scaling to be applied to the Shape being extruded at this segment.
140  /// @param ScaleLeftCorrect The scaling adjustment to apply on the Negative-X positioned points in the Shape being extruded.
141  /// @param ScaleRightCorrect The scaling adjustment to apply on the Positive-X positioned points in the Shape being extruded.
142  /// @param JoinWithNextShape Whether or not to set up the indicies to
143  void GenerateExtrusionShape(TriangleBuffer& Buffer, const Whole PathIndex, const Whole ShapeIndex, const Real PathCoord, const Vector3& Position, const Quaternion& LeftOri,
144  const Quaternion& RightOri, const Real Scale, const Real ScaleLeftCorrect, const Real ScaleRightCorrect, const Boole JoinWithNextShape) const;
145  /// @internal
146  /// @brief Creates a sequence of non-intersecting segments.
147  /// @param Buffer The buffer to be modified.
148  /// @param ShapeIndex The index of the Shape to be extruded.
149  /// @param PathIndex The index of the Path to be extruded along.
150  /// @param PathSegBegin The index of the start of the segment on the specified Path.
151  /// @param PathSegEnd The index of the end of the segment on the specified Path.
152  void GenerateExtrusionSegment(TriangleBuffer& Buffer, const Whole ShapeIndex, const Whole PathIndex, const Whole PathSegBegin, const Whole PathSegEnd) const;
153  /// @internal
154  /// @brief Creates an intersection of segments.
155  /// @param Buffer The buffer to be modified.
156  /// @param Intersection A single intersection of multiple segments in the MultiPath.
157  /// @param ShapeIndex The index of the Shape to be extruded.
158  void GenerateExtrusionIntersection(TriangleBuffer& Buffer, const MultiPath::PathIntersection& Intersection, const Whole ShapeIndex) const;
159  public:
160  /// @brief Class constructor.
161  Extruder();
162  /// @brief Class destructor.
163  virtual ~Extruder();
164 
165  ///////////////////////////////////////////////////////////////////////////////
166  // Utility
167 
168  /// @copydoc MeshGenerator::AddToTriangleBuffer(TriangleBuffer&) const
169  /// @exception If neither the shape or multishape are defined an INVALID_STATE_EXCEPTION will be thrown.
170  virtual void AddToTriangleBuffer(TriangleBuffer& Buffer) const;
171 
172  ///////////////////////////////////////////////////////////////////////////////
173  // Configuration
174 
175  /// @brief Sets a single Path to be extruded along.
176  /// @param ToExtrude A Path to be extruded along.
177  /// @return Returns a reference to this.
178  Extruder& SetPathToExtrude(const Path& ToExtrude);
179  /// @brief Sets a MultiPath to be extruded along.
180  /// @param ToExtrude A MultiPath storing all of the Paths the 2D shapes will be extruded along.
181  /// @return Returns a reference to this.
182  Extruder& SetMultiPathToExtrude(const MultiPath& ToExtrude);
183  /// @brief Sets a single Shape to be extruded.
184  /// @param ToExtrude A Shape to be extruded.
185  /// @return Returns a reference to this.
186  Extruder& SetShapeToExtrude(const Shape& ToExtrude);
187  /// @brief Sets a Multishape to be extruded.
188  /// @param ToExtrude A MultiShape storing all of the 2D shapes that will be extruded along the specified Paths.
189  /// @return Returns a reference to this.
190  Extruder& SetMultiShapeToExtrude(const MultiShape& ToExtrude);
191 
192  /// @brief Sets how shapes are to be scaled on a specific Path.
193  /// @param PathIndex The index of the Path this Track is to be applied to.
194  /// @param Scale A pointer to an optional Track that stores how the shapes on a given Path are to be scaled. Initial Value: NULL.
195  /// @return Returns a reference to this.
196  Extruder& SetScaleTrack(const Whole PathIndex, ParameterTrack* Scale);
197  /// @brief Sets how shapes are to be rotated on a specific Path.
198  /// @param PathIndex The index of the Path this Track is to be applied to.
199  /// @param Rotation A pointer to an optional Track that stores how the shapes on a given Path are to be rotated. Initial Value: NULL.
200  /// @return Returns a reference to this.
201  Extruder& SetRotationTrack(const Whole PathIndex, ParameterTrack* Rotation);
202  /// @brief Sets how the "U" component texture coordinates are to be generated for extruded shapes.
203  /// @param PathIndex The index of the Path this Track is to be applied to.
204  /// @param PathU A pointer to an optional Track that stores how texture coordinates are to be assigned along the Path being extruded along. Initial Value: NULL.
205  /// @return Returns a reference to this.
206  Extruder& SetPathUTextureTrack(const Whole PathIndex, ParameterTrack* PathU);
207  /// @brief Sets how the "V" component texture coordinates are to be generated for extruded shapes.
208  /// @param ShapeIndex The index of the Shape this Track is to be applied to.
209  /// @param ShapeV A pointer to an optional Track that stores how texture coordinates are to be assigned along the shape being extruded. Initial Value: NULL.
210  /// @return Returns a reference to this.
211  Extruder& SetShapeVTextureTrack(const Whole ShapeIndex, ParameterTrack* ShapeV);
212 
213  /// @brief Sets whether or not the ends of each Path extruded are to be enclosed.
214  /// @param Cap True to enclose the Mesh at the ends of each Path, false otherwise.
215  /// @return Returns a reference to this.
216  Extruder& SetCapped(const Boole Cap);
217  };//Extruder
218  }//Procedural
219  }//Graphics
220 }//Mezzanine
221 
222 #endif
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
TrackMap::iterator TrackMapIterator
Iterator type for ParameterTracks.
Definition: extruder.h:92
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.
TrackMap RotationTracks
A map of optional Tracks that store how the shapes on a given Path are to be rotated.
Definition: extruder.h:107
std::vector< PathCoordinate > PathIntersection
Convenience type used to represent the intersection of two or more paths.
Definition: multipath.h:128
MultiShape ShapesToExtrude
A MultiShape storing all of the 2D shapes that will be extruded along the specified Paths...
Definition: extruder.h:101
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 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
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
TrackMap ScaleTracks
A map of optional Tracks that store how the shapes on a given Path are to be scaled.
Definition: extruder.h:104
A base class containing all of the utilities needed for a mesh generator.
Definition: meshgenerator.h:87
TrackMap PathUTextureTracks
A map of optional Tracks that store how texture coordinates are to be assigned along the Paths being ...
Definition: extruder.h:110
Track< LinearInterpolator< Real > > ParameterTrack
Convenience type for a Track that stores additional optional data.
Definition: extruder.h:88
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
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
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
A grouping of individual 3D curves used to express complicated structures.
Definition: multipath.h:118
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68
A collection of interconnected 2D points used to express an arbitrary 2D shape.
Definition: shape.h:95
A grouping of individual 2D shapes used to express more elaborate shapes.
Definition: multishape.h:87
A collection of interconnected 3D points used to express path through 3D space.
Definition: path.h:93
std::map< Whole, ParameterTrack * > TrackMap
Container type for storing ParameterTracks.
Definition: extruder.h:90
TrackMap::const_iterator ConstTrackMapIterator
Const Iterator type for ParameterTracks.
Definition: extruder.h:94
A base type that provides container features for different tracks.
Definition: track.h:65