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

SLRectangle creates a rectangular mesh with a certain resolution. More...

#include <SLRectangle.h>

Inheritance diagram for SLRectangle:
[legend]

Public Member Functions

 SLRectangle (SLAssetManager *assetMgr, const SLVec2f &min, const SLVec2f &max, SLuint resX, SLuint resY, const SLstring &name="rectangle mesh", SLMaterial *mat=nullptr)
 ctor for rectangle w. min & max corner More...
 
 SLRectangle (SLAssetManager *assetMgr, const SLVec2f &min, const SLVec2f &max, const SLVec2f &uv_min, const SLVec2f &uv_max, SLuint resX, SLuint resY, const SLstring &name="rectangle mesh", SLMaterial *mat=nullptr)
 ctor for rectangle w. min & max corner & tex. coord. More...
 
void buildMesh (SLMaterial *mat)
 SLRectangle::buildMesh fills in the underlying arrays from the SLMesh object. More...
 
- 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

SLVec3f _min
 min corner More...
 
SLVec3f _max
 max corner More...
 
SLVec2f _uv_min
 min corner tex.coord. More...
 
SLVec2f _uv_max
 max corner tex.coord. More...
 
SLuint _resX
 resolution in x direction More...
 
SLuint _resY
 resolution in y direction 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

SLRectangle creates a rectangular mesh with a certain resolution.

The SLRectangle node draws a rectangle with a minimal and a maximal corner in the x-y-plane. The normal is [0,0,1].

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 28 of file SLRectangle.h.

Constructor & Destructor Documentation

◆ SLRectangle() [1/2]

SLRectangle::SLRectangle ( SLAssetManager assetMgr,
const SLVec2f min,
const SLVec2f max,
SLuint  resX,
SLuint  resY,
const SLstring name = "rectangle mesh",
SLMaterial mat = nullptr 
)

ctor for rectangle w. min & max corner

SLRectangle ctor with min & max corners and its resolutions.

Definition at line 16 of file SLRectangle.cpp.

22  : SLMesh(assetMgr, name)
23 {
24  assert(min != max);
25  assert(resX > 0);
26  assert(resY > 0);
27  assert(!name.empty());
28  _min = min;
29  _max = max;
30  _uv_min.set(0, 0);
31  _uv_max.set(1, 1);
32  _resX = resX;
33  _resY = resY;
34  _isVolume = true;
35  buildMesh(mat);
36 }
SLMesh(SLAssetManager *assetMgr, const SLstring &name="Mesh")
Construct a new SLMesh::SLMesh object.
Definition: SLMesh.cpp:51
SLbool _isVolume
Flag for RT if mesh is a closed volume.
Definition: SLMesh.h:253
SLMaterial * mat() const
Definition: SLMesh.h:177
const SLstring & name() const
Definition: SLObject.h:38
SLuint _resX
resolution in x direction
Definition: SLRectangle.h:58
SLVec3f _max
max corner
Definition: SLRectangle.h:55
SLVec3f _min
min corner
Definition: SLRectangle.h:54
void buildMesh(SLMaterial *mat)
SLRectangle::buildMesh fills in the underlying arrays from the SLMesh object.
Definition: SLRectangle.cpp:65
SLuint _resY
resolution in y direction
Definition: SLRectangle.h:59
SLVec2f _uv_min
min corner tex.coord.
Definition: SLRectangle.h:56
SLVec2f _uv_max
max corner tex.coord.
Definition: SLRectangle.h:57
void set(const T X, const T Y)
Definition: SLVec2.h:40

◆ SLRectangle() [2/2]

SLRectangle::SLRectangle ( SLAssetManager assetMgr,
const SLVec2f min,
const SLVec2f max,
const SLVec2f uv_min,
const SLVec2f uv_max,
SLuint  resX,
SLuint  resY,
const SLstring name = "rectangle mesh",
SLMaterial mat = nullptr 
)

ctor for rectangle w. min & max corner & tex. coord.

SLRectangle ctor with min & max corners and its resolutions.

Definition at line 39 of file SLRectangle.cpp.

47  : SLMesh(assetMgr, name)
48 {
49  assert(min != max);
50  assert(uv_min != uv_max);
51  assert(resX > 0);
52  assert(resY > 0);
53  assert(!name.empty());
54  _min = min;
55  _max = max;
56  _uv_min = uv_min;
57  _uv_max = uv_max;
58  _resX = resX;
59  _resY = resY;
60  _isVolume = true;
61  buildMesh(mat);
62 }

Member Function Documentation

◆ buildMesh()

void SLRectangle::buildMesh ( SLMaterial mat)

SLRectangle::buildMesh fills in the underlying arrays from the SLMesh object.

Definition at line 65 of file SLRectangle.cpp.

66 {
67  deleteData();
68 
69  // Check max. allowed no. of vertices
70  SLuint uIntNumV64 = (_resX + 1) * (_resY + 1);
71  if (uIntNumV64 > UINT_MAX)
72  SL_EXIT_MSG("SLMesh supports max. 2^32 vertices.");
73 
74  // allocate vectors of SLMesh
75  P.clear();
76  P.resize((_resX + 1) * (_resY + 1));
77  N.clear();
78  N.resize(P.size());
79  UV[0].clear();
80  UV[0].resize(P.size());
81  UV[1].clear();
82 
83  if (uIntNumV64 < 65535)
84  {
85  I16.clear();
86  I16.resize(_resX * _resY * 2 * 3);
87  }
88  else
89  {
90  I32.clear();
91  I32.resize(_resX * _resY * 2 * 3);
92  }
93 
94  // Calculate normal from the first 3 corners
95  SLVec3f maxmin(_max.x, _min.y, 0);
96  SLVec3f minmax(_min.x, _max.y, 0);
97  SLVec3f e1(maxmin - _min);
98  SLVec3f e2(minmax - _min);
99  SLVec3f curN(e1 ^ e2);
100  curN.normalize();
101 
102  // Set one default material index
103  mat(material);
104 
105  // define delta vectors dX & dY and deltas for tex. coord. dU,dV
106  SLVec3f dX = e1 / (SLfloat)_resX;
107  SLVec3f dY = e2 / (SLfloat)_resY;
108  SLfloat dU = (_uv_max.x - _uv_min.x) / (SLfloat)_resX;
109  SLfloat dV = (_uv_max.y - _uv_min.y) / (SLfloat)_resY;
110 
111  // Build vertex data
112  SLuint i = 0;
113  for (SLuint y = 0; y <= _resY; ++y)
114  {
115  SLVec3f curV = _min;
116  SLVec2f curT = _uv_min;
117  curV += (SLfloat)y * dY;
118  curT.y += (SLfloat)y * dV;
119 
120  for (SLuint x = 0; x <= _resX; ++x, ++i)
121  {
122  P[i] = curV;
123  UV[0][i] = curT;
124  N[i] = curN;
125  curV += dX;
126  curT.x += dU;
127  }
128  }
129 
130  // Build face vertex indices
131  if (!I16.empty())
132  {
133  SLushort v = 0, i = 0; // index for vertices and indices
134  for (SLuint y = 0; y < _resY; ++y)
135  {
136  for (SLuint x = 0; x < _resX; ++x, ++v)
137  { // triangle 1
138  I16[i++] = v;
139  I16[i++] = v + (SLushort)_resX + 2;
140  I16[i++] = v + (SLushort)_resX + 1;
141 
142  // triangle 2
143  I16[i++] = v;
144  I16[i++] = v + 1;
145  I16[i++] = v + (SLushort)_resX + 2;
146  }
147  v++;
148  }
149  }
150  else
151  {
152  SLuint v = 0, i = 0; // index for vertices and indices
153  for (SLuint y = 0; y < _resY; ++y)
154  {
155  for (SLuint x = 0; x < _resX; ++x, ++v)
156  { // triangle 1
157  I32[i++] = v;
158  I32[i++] = v + _resX + 2;
159  I32[i++] = v + _resX + 1;
160 
161  // triangle 2
162  I32[i++] = v;
163  I32[i++] = v + 1;
164  I32[i++] = v + _resX + 2;
165  }
166  v++;
167  }
168  }
169 }
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
unsigned short SLushort
Definition: SL.h:169
#define SL_EXIT_MSG(message)
Definition: SL.h:240
SLVuint I32
Vector of vertex indices 32 bit.
Definition: SLMesh.h:215
SLVushort I16
Vector of vertex indices 16 bit.
Definition: SLMesh.h:214
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
T y
Definition: SLVec2.h:30
T x
Definition: SLVec2.h:30
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43

Member Data Documentation

◆ _max

SLVec3f SLRectangle::_max
protected

max corner

Definition at line 55 of file SLRectangle.h.

◆ _min

SLVec3f SLRectangle::_min
protected

min corner

Definition at line 54 of file SLRectangle.h.

◆ _resX

SLuint SLRectangle::_resX
protected

resolution in x direction

Definition at line 58 of file SLRectangle.h.

◆ _resY

SLuint SLRectangle::_resY
protected

resolution in y direction

Definition at line 59 of file SLRectangle.h.

◆ _uv_max

SLVec2f SLRectangle::_uv_max
protected

max corner tex.coord.

Definition at line 57 of file SLRectangle.h.

◆ _uv_min

SLVec2f SLRectangle::_uv_min
protected

min corner tex.coord.

Definition at line 56 of file SLRectangle.h.


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