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

SLPolygon creates a convex polyon mesh. More...

#include <SLPolygon.h>

Inheritance diagram for SLPolygon:
[legend]

Public Member Functions

 SLPolygon (SLAssetManager *assetMgr, const SLVVec3f &corner, const SLstring &name="polygon mesh", SLMaterial *mat=nullptr)
 ctor for generic convex polygon More...
 
 SLPolygon (SLAssetManager *assetMgr, const SLVVec3f &corners, const SLVVec2f &texcoords, const SLstring &name="polygon mesh", SLMaterial *mat=nullptr)
 ctor for generic convex polygon with texCoords More...
 
 SLPolygon (SLAssetManager *assetMgr, SLfloat width, SLfloat height, const SLstring &name, SLMaterial *mat=nullptr)
 ctor for centered rectangle in x-y-plane (N=-z) More...
 
void buildMesh (SLMaterial *mat)
 SLPolygon::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

SLVVec3f _corners
 corners in ccw order More...
 
SLVVec2f _uv1
 texture coords for corners 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

SLPolygon creates a convex polyon mesh.

The SLPolygon node draws a convex polygon with. The normale vector is calculated from the first 3 vertices.

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 SLPolygon.h.

Constructor & Destructor Documentation

◆ SLPolygon() [1/3]

SLPolygon::SLPolygon ( SLAssetManager assetMgr,
const SLVVec3f corner,
const SLstring name = "polygon mesh",
SLMaterial mat = nullptr 
)

ctor for generic convex polygon

SLPolygon ctor with corner points vector.

Definition at line 14 of file SLPolygon.cpp.

18  : SLMesh(assetMgr, name)
19 {
20  assert(corners.size() > 2);
21  _corners = corners;
22  buildMesh(mat);
23 }
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
void buildMesh(SLMaterial *mat)
SLPolygon::buildMesh fills in the underlying arrays from the SLMesh object.
Definition: SLPolygon.cpp:56
SLVVec3f _corners
corners in ccw order
Definition: SLPolygon.h:54

◆ SLPolygon() [2/3]

SLPolygon::SLPolygon ( SLAssetManager assetMgr,
const SLVVec3f corners,
const SLVVec2f texcoords,
const SLstring name = "polygon mesh",
SLMaterial mat = nullptr 
)

ctor for generic convex polygon with texCoords

SLPolygon ctor with corner points and its texture coords vector.

Definition at line 26 of file SLPolygon.cpp.

30  : SLMesh(assetMgr, name)
31 {
32  assert(corners.size() > 2 && texCoords.size() == corners.size());
33  _corners = corners;
34  _uv1 = texCoords;
35  buildMesh(mat);
36 }
SLVVec2f _uv1
texture coords for corners
Definition: SLPolygon.h:55

◆ SLPolygon() [3/3]

SLPolygon::SLPolygon ( SLAssetManager assetMgr,
SLfloat  width,
SLfloat  height,
const SLstring name,
SLMaterial mat = nullptr 
)

ctor for centered rectangle in x-y-plane (N=-z)

SLPolygon ctor for centered light rectangle in x/y-plane w. N=-z.

Definition at line 39 of file SLPolygon.cpp.

43  : SLMesh(assetMgr, name)
44 {
45  assert(width > 0 && height > 0);
46  SLfloat hw = width * 0.5f;
47  SLfloat hh = height * 0.5f;
48  _corners.push_back(SLVec3f(hw, hh));
49  _corners.push_back(SLVec3f(hw, -hh));
50  _corners.push_back(SLVec3f(-hw, -hh));
51  _corners.push_back(SLVec3f(-hw, hh));
52  buildMesh(mat);
53 }
float SLfloat
Definition: SL.h:173
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318

Member Function Documentation

◆ buildMesh()

void SLPolygon::buildMesh ( SLMaterial mat)

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

Definition at line 56 of file SLPolygon.cpp.

57 {
58  _isVolume = false;
59 
60  deleteData();
61 
62  // Check max. allowed no. of verts
63  if (_corners.size() >= 65535)
64  SL_EXIT_MSG("SLPolygon::buildMesh: NO. of vertices exceeds the maximum (65535) allowed.");
65 
66  // allocate vectors of SLMesh
67  P.clear();
68  P.resize(_corners.size());
69  N.clear();
70  N.resize(P.size());
71  if (!_uv1.empty())
72  {
73  UV[0].clear();
74  UV[0].resize(P.size());
75  }
76  UV[1].clear();
77  I16.clear();
78  I16.resize((P.size() - 2) * 3);
79 
80  // Calculate normal from the first 3 corners
81  SLVec3f v1(_corners[0] - _corners[1]);
82  SLVec3f v2(_corners[0] - _corners[2]);
83  SLVec3f n(v1 ^ v2);
84  n.normalize();
85 
86  // Set one default material index
87  mat(material);
88 
89  // Copy vertices and normals
90  for (SLushort i = 0; i < (SLushort)P.size(); ++i)
91  {
92  P[i] = _corners[i];
93  N[i] = n;
94  if (!UV[0].empty()) UV[0][i] = _uv1[i];
95  }
96 
97  // Build face vertex indices
98  for (SLushort f = 0; f < (SLushort)_corners.size() - 2; ++f)
99  {
100  SLuint i = f * 3;
101  I16[i] = 0;
102  I16[i + 1] = f + 1;
103  I16[i + 2] = f + 2;
104  }
105 }
unsigned int SLuint
Definition: SL.h:171
unsigned short SLushort
Definition: SL.h:169
#define SL_EXIT_MSG(message)
Definition: SL.h:240
SLVushort I16
Vector of vertex indices 16 bit.
Definition: SLMesh.h:214
SLbool _isVolume
Flag for RT if mesh is a closed volume.
Definition: SLMesh.h:253
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

Member Data Documentation

◆ _corners

SLVVec3f SLPolygon::_corners
protected

corners in ccw order

Definition at line 54 of file SLPolygon.h.

◆ _uv1

SLVVec2f SLPolygon::_uv1
protected

texture coords for corners

Definition at line 55 of file SLPolygon.h.


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