SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLRevolver Class Reference

SLRevolver is an SLMesh object built out of revolving points. More...

#include <SLRevolver.h>

Inheritance diagram for SLRevolver:
[legend]

Public Member Functions

 SLRevolver (SLAssetManager *assetMgr, SLVVec3f revolvePoints, SLVec3f revolveAxis, SLuint slices=36, SLbool smoothFirst=false, SLbool smoothLast=false, SLstring name="revolver mesh", SLMaterial *mat=nullptr)
 ctor for generic revolver mesh More...
 
 SLRevolver (SLAssetManager *assetMgr, SLstring name)
 ctor for derived revolver shapes More...
 
void buildMesh (SLMaterial *mat=nullptr)
 
SLuint stacks ()
 
SLuint slices ()
 
- Public Member Functions inherited from SLMesh
 SLMesh (SLAssetManager *assetMgr, const SLstring &name="Mesh")
 Construct a new SLMesh::SLMesh object. More...
 
 ~SLMesh () override
 The destructor deletes everything by calling deleteData. More...
 
virtual void init (SLNode *node)
 SLMesh::shapeInit sets the transparency flag of the AABB. More...
 
virtual void draw (SLSceneView *sv, SLNode *node, SLuint intances=0)
 
void drawIntoDepthBuffer (SLSceneView *sv, SLNode *node, SLMaterial *depthMat)
 Simplified drawing method for shadow map creation. More...
 
void addStats (SLNodeStats &stats)
 
virtual void buildAABB (SLAABBox &aabb, const SLMat4f &wmNode)
 
void updateAccelStruct ()
 
SLbool hit (SLRay *ray, SLNode *node)
 
virtual void preShade (SLRay *ray)
 
virtual void deleteData ()
 SLMesh::deleteData deletes all mesh data and vbo's. More...
 
virtual void deleteDataGpu ()
 
void deleteSelected (SLNode *node)
 Deletes the rectangle selected vertices and the dependent triangles. More...
 
void deleteUnused ()
 Deletes unused vertices (= vertices that are not indexed in I16 or I32) More...
 
virtual void calcMinMax ()
 
virtual void calcNormals ()
 SLMesh::calcNormals recalculates vertex normals for triangle meshes. More...
 
void calcCenterRad (SLVec3f &center, SLfloat &radius)
 
SLbool hitTriangleOS (SLRay *ray, SLNode *node, SLuint iT)
 
virtual void generateVAO (SLGLVertexArray &vao)
 Generate the Vertex Array Object for a specific shader program. More...
 
void computeHardEdgesIndices (float angleRAD, float epsilon)
 computes the hard edges and stores the vertex indexes separately More...
 
void transformSkin (bool forceCPUSkinning, const std::function< void(SLMesh *)> &cbInformNodes)
 Transforms the vertex positions and normals with by joint weights. More...
 
void deselectPartialSelection ()
 
SLMaterialmat () const
 
SLMaterialmatOut () const
 
SLGLPrimitiveType primitive () const
 
const SLAnimSkeletonskeleton () const
 
SLuint numI () const
 
SLGLVertexArrayvao ()
 
SLbool isSelected () const
 
SLfloat edgeAngleDEG () const
 
SLfloat edgeWidth () const
 
SLCol4f edgeColor () const
 
SLVec3f finalP (SLuint i)
 
SLVec3f finalN (SLuint i)
 
SLbool accelStructIsOutOfDate ()
 
void mat (SLMaterial *m)
 
void matOut (SLMaterial *m)
 
void primitive (SLGLPrimitiveType pt)
 
void skeleton (SLAnimSkeleton *skel)
 
void isSelected (bool isSelected)
 
void edgeWidth (SLfloat ew)
 
void edgeAngleDEG (SLfloat ea)
 
void edgeColor (const SLCol4f &ec)
 
void vertexPosEpsilon (SLfloat eps)
 
- Public Member Functions inherited from SLObject
 SLObject (const SLstring &Name="", const SLstring &url="")
 
virtual ~SLObject ()
 
void name (const SLstring &Name)
 
void url (const SLstring &url)
 
const SLstringname () const
 
const SLstringurl () const
 

Protected Attributes

SLVVec3f _revPoints
 Array revolving points. More...
 
SLVec3f _revAxis
 axis of revolution More...
 
SLuint _stacks
 No. of stacks (mostly used) More...
 
SLuint _slices
 NO. of slices. More...
 
SLbool _smoothFirst
 flag if the normal of the first point is eqaual to -revAxis More...
 
SLbool _smoothLast
 flag if the normal of the last point is eqaual to revAxis More...
 
- Protected Attributes inherited from SLMesh
SLGLPrimitiveType _primitive
 Primitive type (default triangles) More...
 
SLMaterial_mat
 Pointer to the inside material. More...
 
SLMaterial_matOut
 Pointer to the outside material. More...
 
SLGLVertexArray _vao
 Main OpenGL Vertex Array Object for drawing. More...
 
SLGLVertexArrayExt _vaoN
 OpenGL VAO for optional normal drawing. More...
 
SLGLVertexArrayExt _vaoT
 OpenGL VAO for optional tangent drawing. More...
 
SLGLVertexArrayExt _vaoS
 OpenGL VAO for optional selection drawing. More...
 
SLbool _isSelected
 Flag if mesh is partially of fully selected. More...
 
SLfloat _edgeAngleDEG
 Edge crease angle in degrees between face normals (30 deg. default) More...
 
SLfloat _edgeWidth
 Line width for hard edge drawing. More...
 
SLCol4f _edgeColor
 Color for hard edge drawing. More...
 
SLfloat _vertexPosEpsilon
 Vertex position epsilon used in computeHardEdgesIndices. More...
 
SLbool _isVolume
 Flag for RT if mesh is a closed volume. More...
 
SLAccelStruct_accelStruct
 KD-tree or uniform grid. More...
 
SLbool _accelStructIsOutOfDate
 Flag if accel. struct needs update. More...
 
SLAnimSkeleton_skeleton
 The skeleton this mesh is bound to. More...
 
SLVMat4f _jointMatrices
 Joint matrix vector for this mesh. More...
 
SLbool _isCPUSkinned
 Flag if mesh has been skinned on CPU during update. More...
 
SLVVec3f_finalP
 Pointer to final vertex position vector. More...
 
SLVVec3f_finalN
 pointer to final vertex normal vector More...
 
- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 

Additional Inherited Members

- Static Public Member Functions inherited from SLMesh
static void calcTex3DMatrix (SLNode *node)
 
- Public Attributes inherited from SLMesh
SLVVec3f P
 Vector for vertex positions layout (location = 0) More...
 
SLVVec3f N
 Vector for vertex normals (opt.) layout (location = 1) More...
 
SLVVec2f UV [2]
 Array of 2 Vectors for tex. coords. (opt.) layout (location = 2) More...
 
SLVCol4f C
 Vector of vertex colors (opt.) layout (location = 4) More...
 
SLVVec4f T
 Vector of vertex tangents (opt.) layout (location = 5) More...
 
SLVVuchar Ji
 2D Vector of per vertex joint ids (opt.) layout (location = 6) More...
 
SLVVfloat Jw
 2D Vector of per vertex joint weights (opt.) layout (location = 7) More...
 
SLVVec3f skinnedP
 temp. vector for CPU skinned vertex positions More...
 
SLVVec3f skinnedN
 temp. vector for CPU skinned vertex normals More...
 
SLVushort I16
 Vector of vertex indices 16 bit. More...
 
SLVuint I32
 Vector of vertex indices 32 bit. More...
 
SLVuint IS32
 Vector of rectangle selected vertex indices 32 bit. More...
 
SLVushort IE16
 Vector of hard edges vertex indices 16 bit (see computeHardEdgesIndices) More...
 
SLVuint IE32
 Vector of hard edges vertex indices 32 bit (see computeHardEdgesIndices) More...
 
SLVec3f minP
 min. vertex in OS More...
 
SLVec3f maxP
 max. vertex in OS More...
 

Detailed Description

SLRevolver is an SLMesh object built out of revolving points.

SLRevolver is an SLMesh object that is built out of points that are revolved in slices around and axis. The surface will be outwards if the points in the array _revPoints increase towards the axis direction. If all points in the array _revPoints are different the normals will be smoothed. If two consecutive points are identical the normals will define a hard edge. Texture coords. are cylindrically mapped. See the online example Revolving Meshes with various revolver objects.

Remarks
It is important that during instantiation NO OpenGL functions (gl*) get called because this constructor will be most probably called in a parallel thread from within an SLScene::registerAssetsToLoad or SLScene::assemble function. All objects that get rendered have to do their OpenGL initialization when they are used the first time during rendering in the main thread. For this mesh it means that the objects for OpenGL drawing (_vao, _vaoP, _vaoN, _vaoT and _vaoS) remain unused until the first frame is rendered.

Definition at line 37 of file SLRevolver.h.

Constructor & Destructor Documentation

◆ SLRevolver() [1/2]

SLRevolver::SLRevolver ( SLAssetManager assetMgr,
SLVVec3f  revolvePoints,
SLVec3f  revolveAxis,
SLuint  slices = 36,
SLbool  smoothFirst = false,
SLbool  smoothLast = false,
SLstring  name = "revolver mesh",
SLMaterial mat = nullptr 
)

ctor for generic revolver mesh

SLRevolver::SLRevolver ctor for generic revolution object.

Definition at line 16 of file SLRevolver.cpp.

23  : SLMesh(assetMgr, name)
24 {
25  assert(revolvePoints.size() >= 2 && "Error: Not enough revolve points.");
26  assert(revolveAxis != SLVec3f::ZERO && "Error axis is a zero vector.");
27  assert(slices >= 3 && "Error: Not enough slices.");
28 
29  _revPoints = revolvePoints;
30  _revAxis = revolveAxis;
31  _slices = slices;
32  _smoothFirst = smoothFirst;
33  _smoothLast = smoothLast;
34 
36 
37  buildMesh(mat);
38 }
SLMesh(SLAssetManager *assetMgr, const SLstring &name="Mesh")
Construct a new SLMesh::SLMesh object.
Definition: SLMesh.cpp:51
SLMaterial * mat() const
Definition: SLMesh.h:177
const SLstring & name() const
Definition: SLObject.h:38
SLbool _smoothLast
flag if the normal of the last point is eqaual to revAxis
Definition: SLRevolver.h:67
SLVec3f _revAxis
axis of revolution
Definition: SLRevolver.h:59
SLuint slices()
Definition: SLRevolver.h:55
SLbool _smoothFirst
flag if the normal of the first point is eqaual to -revAxis
Definition: SLRevolver.h:64
SLuint _slices
NO. of slices.
Definition: SLRevolver.h:61
void buildMesh(SLMaterial *mat=nullptr)
Definition: SLRevolver.cpp:43
SLVVec3f _revPoints
Array revolving points.
Definition: SLRevolver.h:58
SLVec3 & normalize()
Definition: SLVec3.h:124
static SLVec3 ZERO
Definition: SLVec3.h:285

◆ SLRevolver() [2/2]

SLRevolver::SLRevolver ( SLAssetManager assetMgr,
SLstring  name 
)
inline

ctor for derived revolver shapes

Definition at line 51 of file SLRevolver.h.

51 : SLMesh(assetMgr, std::move(name)) { ; }

Member Function Documentation

◆ buildMesh()

void SLRevolver::buildMesh ( SLMaterial material = nullptr)

SLRevolver::buildMesh builds the underlying mesh data structure

Definition at line 43 of file SLRevolver.cpp.

44 {
45  deleteData();
46 
47  ///////////////////////////////
48  // Vertices & Texture coords //
49  ///////////////////////////////
50 
51  // calculate no. of vertices & allocate vectors for P, UV1 & N.
52  // On one stack it has one vertex more at the end that is identical with the
53  // first vertex of the stack. This is for cylindrical texture mapping where
54  // we need 2 different texture s-coords (0 & 1) at the same point.
55  P.clear();
56  P.resize((_slices + 1) * _revPoints.size());
57  N.clear();
58  N.resize(P.size());
59  UV[0].clear();
60  UV[0].resize(P.size());
61  UV[1].clear();
62 
63  // calculate length of segments for texture coords
64  SLfloat totalLenght = 0;
65  SLVfloat segments;
66  segments.push_back(0);
67  for (SLuint r = 0; r < _revPoints.size() - 1; ++r)
68  {
69  SLVec3f s = _revPoints[r + 1] - _revPoints[r];
70  SLfloat len = s.length();
71  totalLenght += len;
72  segments.push_back(len);
73  }
74 
75  // Normalize segment lengths for texture coords
76  for (auto& segment : segments)
77  segment /= totalLenght;
78 
79  // Texture coordinate
80  SLVec2f uv1(0, 0); // y is increased by segment[r]
81  SLfloat deltaS = 1.0f / _slices; // increase value for s-tecCoord
82 
83  // define matrix & angles for rotation
84  SLMat4f m;
85  SLfloat dPhi = 360.0f / _slices;
86 
87  // calculate vertices & texture coords for all revolution points
88  SLuint iV = 0;
89  for (SLuint r = 0; r < _revPoints.size(); ++r)
90  {
91  m.identity();
92  uv1.x = 0;
93  uv1.y += segments[r];
94  for (SLuint s = 0; s <= _slices; ++s)
95  {
96  if (s == 0 || s == _slices)
97  P[iV] = _revPoints[r];
98  else
99  P[iV] = m.multVec(_revPoints[r]);
100 
101  UV[0][iV++] = uv1;
102  m.rotate(dPhi, _revAxis);
103  uv1.x += deltaS;
104  }
105  }
106 
107  /////////////////
108  // Faces //
109  /////////////////
110 
111  vector<SLVec3ui> faces;
112 
113  // set faces (triangles) for all revolution segments
114  SLVec3ui f;
115  SLuint iV1, iV2;
116  for (SLuint r = 0; r < _revPoints.size() - 1; ++r)
117  {
118  iV1 = r * (_slices + 1);
119  iV2 = (r + 1) * (_slices + 1);
120 
121  // only define faces if neighboring points are different
122  if (_revPoints[r] != _revPoints[r + 1])
123  {
124  for (SLuint s = 0; s < _slices; ++s)
125  {
126  // Add two triangles if real quad is visible
127  // Add upper triangle only iB (or iC) are not on rev. axis
128  if (_revAxis.distSquared(P[iV2 + s]) > FLT_EPSILON)
129  {
130  f.x = iV1 + s;
131  f.y = iV2 + s + 1;
132  f.z = iV2 + s;
133  faces.push_back(f);
134  }
135 
136  // Add lower triangle only iA (or iB) are not on rev. axis
137  if (_revAxis.distSquared(P[iV1 + s]) > FLT_EPSILON)
138  {
139  f.x = iV1 + s;
140  f.y = iV1 + s + 1;
141  f.z = iV2 + s + 1;
142  faces.push_back(f);
143  }
144  }
145  }
146  }
147 
148  assert(!faces.empty() && "SLRevolver::buildMesh: No faces defined!");
149 
150  // calculate no. of faces (triangles) & allocate arrays
151  SLuint i = 0;
152  if (P.size() < 65536)
153  {
154  I16.clear();
155  I16.resize(faces.size() * 3);
156  for (auto face : faces)
157  {
158  I16[i++] = (SLushort)face.x;
159  I16[i++] = (SLushort)face.y;
160  I16[i++] = (SLushort)face.z;
161  }
162  }
163  else
164  {
165  I32.clear();
166  I32.resize(faces.size() * 3);
167  for (auto face : faces)
168  {
169  I32[i++] = face.x;
170  I32[i++] = face.y;
171  I32[i++] = face.z;
172  }
173  }
174 
175  // Set one default material index
176  mat(material);
177 
178  /////////////////
179  // Normals //
180  /////////////////
181 
182  // Calculate normals with the SLMesh method
183  calcNormals();
184 
185  // correct normals at the first point
186  if (_smoothFirst)
187  {
188  for (SLuint s = 0; s < _slices; ++s)
189  {
190  N[s] = -_revAxis;
191  N[s + 1] = -_revAxis;
192  }
193  }
194 
195  // correct normals at the first point
196  if (_smoothLast)
197  {
198  for (SLuint s = 0; s < _slices; ++s)
199  {
200  N[P.size() - s - 1] = _revAxis;
201  N[P.size() - s - 2] = _revAxis;
202  }
203  }
204 
205  // correct (smooth) the start normal and the end normal of a stack
206  for (SLuint r = 0; r < _revPoints.size(); ++r)
207  {
208  iV1 = r * (_slices + 1);
209  iV2 = iV1 + _slices;
210  N[iV1] += N[iV2];
211  N[iV1].normalize();
212  N[iV2] = N[iV1];
213  }
214 }
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
unsigned short SLushort
Definition: SL.h:169
vector< SLfloat > SLVfloat
Definition: SL.h:200
SLScene * s
Definition: SLScene.h:31
void rotate(T degAng, T axisx, T axisy, T axisz)
Definition: SLMat4.h:656
SLVec3< T > multVec(SLVec3< T > v) const
Definition: SLMat4.h:576
void identity()
Sets the identity matrix.
Definition: SLMat4.h:1333
SLVuint I32
Vector of vertex indices 32 bit.
Definition: SLMesh.h:215
SLVushort I16
Vector of vertex indices 16 bit.
Definition: SLMesh.h:214
virtual void calcNormals()
SLMesh::calcNormals recalculates vertex normals for triangle meshes.
Definition: SLMesh.cpp:1165
SLVVec3f N
Vector for vertex normals (opt.) layout (location = 1)
Definition: SLMesh.h:204
virtual void deleteData()
SLMesh::deleteData deletes all mesh data and vbo's.
Definition: SLMesh.cpp:88
SLVVec2f UV[2]
Array of 2 Vectors for tex. coords. (opt.) layout (location = 2)
Definition: SLMesh.h:205
SLVVec3f P
Vector for vertex positions layout (location = 0)
Definition: SLMesh.h:203
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
T z
Definition: SLVec3.h:43
T distSquared(const SLVec3 &q)
Calculate the squared distance from the vector to point q.
Definition: SLVec3.h:172

◆ slices()

SLuint SLRevolver::slices ( )
inline

Definition at line 55 of file SLRevolver.h.

55 { return _slices; }

◆ stacks()

SLuint SLRevolver::stacks ( )
inline

Definition at line 54 of file SLRevolver.h.

54 { return _stacks; }
SLuint _stacks
No. of stacks (mostly used)
Definition: SLRevolver.h:60

Member Data Documentation

◆ _revAxis

SLVec3f SLRevolver::_revAxis
protected

axis of revolution

Definition at line 59 of file SLRevolver.h.

◆ _revPoints

SLVVec3f SLRevolver::_revPoints
protected

Array revolving points.

Definition at line 58 of file SLRevolver.h.

◆ _slices

SLuint SLRevolver::_slices
protected

NO. of slices.

Definition at line 61 of file SLRevolver.h.

◆ _smoothFirst

SLbool SLRevolver::_smoothFirst
protected

flag if the normal of the first point is eqaual to -revAxis

Definition at line 64 of file SLRevolver.h.

◆ _smoothLast

SLbool SLRevolver::_smoothLast
protected

flag if the normal of the last point is eqaual to revAxis

Definition at line 67 of file SLRevolver.h.

◆ _stacks

SLuint SLRevolver::_stacks
protected

No. of stacks (mostly used)

Definition at line 60 of file SLRevolver.h.


The documentation for this class was generated from the following files: