42 Log::error(
"Extrusion::extrude(): no silhouette defined.\n" );
47 Log::error(
"Extrusion::extrude() needs at least a non empty positionPath().\n" );
52 Log::error(
"Extrusion::extrude(): scalingPath() must have the same number of control points as positionPath().\n" );
57 Log::error(
"Extrusion::extrude(): rotationPath() must have the same number of control points as positionPath().\n" );
62 Log::error(
"Extrusion::extrude(): colorPath() must have the same number of control points as positionPath().\n" );
70 std::vector<fvec3> verts;
71 verts.resize(
silhouette().size() * segments );
76 std::vector<vl::fvec3> projected_sil;
78 for (
unsigned i = 0; i <
silhouette().size(); ++i )
84 std::vector<fvec3> plane_normals;
86 for (
unsigned i = 1; i < plane_normals.size() - 1; ++i )
92 plane_normals[ i ] = ( p1 - p0 ).
normalize();
95 for (
unsigned i = 1; i <
positionPath().size() - 1; ++i )
97 for (
int j = 0; j < (int)
silhouette().size(); ++j )
100 const fvec3& P = projected_sil[ j ];
102 const fvec3& N = plane_normals[ i ];
103 float d =
dot( N, orig );
104 float t =
dot( V, N ) ? ( d -
dot( P, N ) ) /
dot( V, N ) : 0 ;
106 verts.at( j +
silhouette().size() * ( i - 1 ) ) = projected_sil[ j ] = P + V * t;
113 for (
unsigned i = 1; i <
positionPath().size() - 1; ++i )
118 for (
int j = 0; j < (int)
silhouette().size(); ++j )
119 c += verts.at( j +
silhouette().size() * ( i - 1 ) );
121 for (
int j = 0; j < (int)
silhouette().size(); ++j )
122 verts.at( j +
silhouette().size() * ( i - 1 ) ) = ( mat * ( verts.at( j +
silhouette().size() * ( i - 1 ) ) - c ) ) + c;
129 for (
unsigned i = 1; i <
positionPath().size() - 1; ++i )
133 for (
int j = 0; j < (int)
silhouette().size(); ++j )
134 c += verts.at( j +
silhouette().size() * ( i - 1 ) );
136 for (
int j = 0; j < (int)
silhouette().size(); ++j )
137 verts.at( j +
silhouette().size() * ( i - 1 ) ) = ( s * ( verts.at( j +
silhouette().size() * ( i - 1 ) ) - c ) ) + c;
141 for (
unsigned int i = 0; i <
silhouettes().size(); ++i )
143 int previousSilhouetteSize = ( i == 0 ) ? 0 :
silhouettes().at( i - 1 );
148 for (
int iseg = 0; iseg < segments - 1; ++iseg )
150 for (
int iquad = 0; iquad < prof_count; ++iquad )
152 de->
indexBuffer()->
at( ( iquad ) * 4 + iseg * 4 * prof_count + 3 ) = ( iseg + 0 ) * (GLuint)
silhouette().size() + iquad + previousSilhouetteSize;
153 de->
indexBuffer()->
at( ( iquad ) * 4 + iseg * 4 * prof_count + 2 ) = ( iseg + 0 ) * (GLuint)
silhouette().size() + ( iquad + 1 ) %
silhouettes().at( i ) + previousSilhouetteSize;
154 de->
indexBuffer()->
at( ( iquad ) * 4 + iseg * 4 * prof_count + 1 ) = ( iseg + 1 ) * (GLuint)
silhouette().size() + ( iquad + 1 ) %
silhouettes().at( i ) + previousSilhouetteSize;
155 de->
indexBuffer()->
at( ( iquad ) * 4 + iseg * 4 * prof_count + 0 ) = ( iseg + 1 ) * (GLuint)
silhouette().size() + iquad + previousSilhouetteSize;
162 size_t tess_bottom_count = 0;
163 size_t tess_top_count = 0;
167 int start = int( verts.size() );
169 for (
unsigned i = 0; i <
silhouettes().size(); ++i )
171 for (
unsigned i = 0; i <
silhouette().size(); ++i )
172 tessellator.contourVerts().push_back( (
dvec3)verts[ i ] );
174 tessellator.tessellate();
175 for (
unsigned i = 0; i < tessellator.tessellatedTris().size(); ++i )
176 verts.push_back( tessellator.tessellatedTris()[ i ] );
177 if ( tessellator.tessellatedTris().size() )
179 tess_bottom_count = tessellator.tessellatedTris().size();
183 int start = int( verts.size() );
185 for (
size_t i =
silhouettes().size() - 1; i >= 0; --i )
187 for (
unsigned i = 0; i <
silhouette().size(); ++i )
188 tessellator.contourVerts().push_back( (
dvec3)verts[ verts.size() - i - 1 - tess_bottom_count ] );
190 tessellator.tessellate();
191 for (
unsigned i = 0; i < tessellator.tessellatedTris().size(); ++i )
192 verts.push_back( tessellator.tessellatedTris()[ i ] );
193 if ( tessellator.tessellatedTris().size() )
195 tess_top_count = tessellator.tessellatedTris().size();
199 if ( compatibilityProfile )
208 if ( compatibilityProfile )
214 for (
int iseg = 0; iseg < segments; ++iseg )
216 for (
unsigned j = 0; j <
silhouette().size(); ++j, ++offs )
221 for (
unsigned j = 0; j < tess_bottom_count; ++j, ++offs )
226 for (
unsigned j = 0; j < tess_top_count; ++j, ++offs )
const std::vector< vl::fvec3 > & positionPath() const
The path along which the silhouette is extruded.
const std::vector< float > & scalingPath() const
The scaling to be applied along the extrusion.
Tessellates a complex polygon defined by a set of outlines into a set of triangles that can be render...
const Vector3 & normalize(T_Scalar *len=NULL)
Vector3< float > fvec3
A 3 components vector with float precision.
bool fillBottom() const
Whether a set of triangles should be generated to fill the beginning of the extrusion (default is tru...
bool smooth() const
If true the normals of the geometry are smoothed.
const ArrayAbstract * vertexArray() const
Conventional vertex array.
const std::vector< vl::fvec4 > & colorPath() const
The color to be applied to the extrusion.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
void setVertexArray(ArrayAbstract *data)
Conventional vertex array.
void setColorArray(const fvec4 &color)
Fills the color array with the given color.
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Visualization Library main namespace.
float dot(float a, float b)
const std::vector< vl::fvec2 > & silhouette() const
Returns the silhouette to be extruded.
void initFrom(const std::vector< T_VectorType > &vector)
vl::ref< vl::Geometry > extrude(bool compatibilityProfile=true)
Performs the actual extrusion.
ESilhouetteMode silhouetteMode() const
Wether the silhouette is considered closed, i.e. a line-loop, or open.
Implements the OpenGL Shading Language convenience functions for scalar and vector operations...
const std::vector< int > & contours() const
The contours that specify the complex polygon to be tessellated.
void convertDrawCallToDrawArrays()
Converts all the DrawCall objects bound to a Geometry into DrawArrays.
void computeNormals(bool verbose=false)
Computes the normals in a "smooth" way, i.e.
arr_type * indexBuffer()
The BufferObject containing the indices used to render.
const std::vector< unsigned int > & silhouettes() const
Return the number of points in each silhouette.
static Matrix4 & getRotation(Matrix4 &out, float degrees, float x, float y, float z)
T_VectorType & at(size_t i)
virtual size_t size() const =0
Returns the number of elements of an array.
The ref<> class is used to reference-count an Object.
bool fillTop() const
Whether a set of triangles should be generated to fill the ending of the extrusion (default is true)...
Wraps the OpenGL function glDrawArrays().
const std::vector< float > & rotationPath() const
The rotation to be applied along the extrusion.
Collection< DrawCall > & drawCalls()
Returns the list of DrawCall objects bound to a Geometry.
void setVertexAttribArray(int attrib_location, const ArrayAbstract *info)
Binds a generic vertex attribute.