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

Axis aligned box mesh. More...

#include <SLBox.h>

Inheritance diagram for SLBox:
[legend]

Public Member Functions

 SLBox (SLAssetManager *assetMgr, SLfloat minx=0, SLfloat miny=0, SLfloat minz=0, SLfloat maxx=1, SLfloat maxy=1, SLfloat maxz=1, const SLstring &name="box mesh", SLMaterial *mat=nullptr)
 SLBox::SLBox ctor with min. & max. coords. of the axis aligned box. More...
 
 SLBox (SLAssetManager *assetMgr, const SLVec3f &min, const SLVec3f &max, const SLstring &name="box mesh", SLMaterial *mat=nullptr)
 SLBox::SLBox ctor with min. & max. vectors of the axis aligned box. More...
 
void buildMesh (SLMaterial *mat)
 SLBox::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
 

Private Attributes

SLVec3f _min
 minimal corner More...
 
SLVec3f _max
 maximum corner 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...
 
- 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...
 

Detailed Description

Axis aligned box mesh.

The SLBox node draws an axis aligned box from a minimal corner to a maximal corner. If the minimal and maximal corner are swapped the normals will point inside.

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 SLMesh 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 30 of file SLBox.h.

Constructor & Destructor Documentation

◆ SLBox() [1/2]

SLBox::SLBox ( SLAssetManager assetMgr,
SLfloat  minx = 0,
SLfloat  miny = 0,
SLfloat  minz = 0,
SLfloat  maxx = 1,
SLfloat  maxy = 1,
SLfloat  maxz = 1,
const SLstring name = "box mesh",
SLMaterial mat = nullptr 
)

SLBox::SLBox ctor with min. & max. coords. of the axis aligned box.

Definition at line 15 of file SLBox.cpp.

23  : SLMesh(assetMgr, name)
24 {
25  _min.set(minx, miny, minz);
26  _max.set(maxx, maxy, maxz);
27  SLVec3f diag(_max - _min);
28  assert(diag.length() > FLT_EPSILON && "Box has no size!");
29  buildMesh(mat);
30 }
SLVec3f _max
maximum corner
Definition: SLBox.h:52
void buildMesh(SLMaterial *mat)
SLBox::buildMesh fills in the underlying arrays from the SLMesh object.
Definition: SLBox.cpp:47
SLVec3f _min
minimal corner
Definition: SLBox.h:51
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 set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59

◆ SLBox() [2/2]

SLBox::SLBox ( SLAssetManager assetMgr,
const SLVec3f min,
const SLVec3f max,
const SLstring name = "box mesh",
SLMaterial mat = nullptr 
)

SLBox::SLBox ctor with min. & max. vectors of the axis aligned box.

Definition at line 33 of file SLBox.cpp.

37  : SLMesh(assetMgr, name)
38 {
39  _min.set(min);
40  _max.set(max);
41  SLVec3f diag(_max - _min);
42  assert(diag.length() > FLT_EPSILON && "Box has no size!");
43  buildMesh(mat);
44 }

Member Function Documentation

◆ buildMesh()

void SLBox::buildMesh ( SLMaterial mat)

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

Definition at line 47 of file SLBox.cpp.

48 {
49  deleteData();
50 
51  // allocate new vectors of SLMesh
52  P.resize(24); // 6 sides with 4 vertices
53  I16.resize(12 * 3); // 6 sides with 2 triangles * 3 indices
54  N.resize(P.size());
55 
56  // Set one default material index
57  mat(material);
58 
59  SLuint p = 0, i = 0;
60 
61  // predefined normals
62  SLVec3f NX = SLVec3f(1, 0, 0);
63  SLVec3f NY = SLVec3f(0, 1, 0);
64  SLVec3f NZ = SLVec3f(0, 0, 1);
65 
66  // clang-format off
67  // towards +x
68  P[p].x=_max.x; P[p].y=_max.y; P[p].z=_min.z; N[p]= NX; p++; // 0
69  P[p].x=_max.x; P[p].y=_max.y; P[p].z=_max.z; N[p]= NX; p++; // 1
70  P[p].x=_max.x; P[p].y=_min.y; P[p].z=_max.z; N[p]= NX; p++; // 2
71  P[p].x=_max.x; P[p].y=_min.y; P[p].z=_min.z; N[p]= NX; p++; // 3
72  I16[i++] = 0; I16[i++] = 1; I16[i++] = 2;
73  I16[i++] = 0; I16[i++] = 2; I16[i++] = 3;
74 
75  // towards -z
76  P[p].x=_min.x; P[p].y=_max.y; P[p].z=_min.z; N[p]=-NZ; p++; // 4
77  P[p].x=_max.x; P[p].y=_max.y; P[p].z=_min.z; N[p]=-NZ; p++; // 5
78  P[p].x=_max.x; P[p].y=_min.y; P[p].z=_min.z; N[p]=-NZ; p++; // 6
79  P[p].x=_min.x; P[p].y=_min.y; P[p].z=_min.z; N[p]=-NZ; p++; // 7
80  I16[i++] = 4; I16[i++] = 5; I16[i++] = 6;
81  I16[i++] = 4; I16[i++] = 6; I16[i++] = 7;
82 
83  // towards -x
84  P[p].x=_min.x; P[p].y=_max.y; P[p].z=_max.z; N[p]=-NX; p++; // 8
85  P[p].x=_min.x; P[p].y=_max.y; P[p].z=_min.z; N[p]=-NX; p++; // 9
86  P[p].x=_min.x; P[p].y=_min.y; P[p].z=_min.z; N[p]=-NX; p++; // 10
87  P[p].x=_min.x; P[p].y=_min.y; P[p].z=_max.z; N[p]=-NX; p++; // 11
88  I16[i++] = 8; I16[i++] = 9; I16[i++] = 10;
89  I16[i++] = 8; I16[i++] = 10; I16[i++] = 11;
90 
91  // towards +z
92  P[p].x=_max.x; P[p].y=_max.y; P[p].z=_max.z; N[p]= NZ; p++; // 12
93  P[p].x=_min.x; P[p].y=_max.y; P[p].z=_max.z; N[p]= NZ; p++; // 13
94  P[p].x=_min.x; P[p].y=_min.y; P[p].z=_max.z; N[p]= NZ; p++; // 14
95  P[p].x=_max.x; P[p].y=_min.y; P[p].z=_max.z; N[p]= NZ; p++; // 15
96  I16[i++] = 12; I16[i++] = 13; I16[i++] = 14;
97  I16[i++] = 12; I16[i++] = 14; I16[i++] = 15;
98 
99  // towards +y
100  P[p].x=_max.x; P[p].y=_max.y; P[p].z=_max.z; N[p]= NY; p++; // 16
101  P[p].x=_max.x; P[p].y=_max.y; P[p].z=_min.z; N[p]= NY; p++; // 17
102  P[p].x=_min.x; P[p].y=_max.y; P[p].z=_min.z; N[p]= NY; p++; // 18
103  P[p].x=_min.x; P[p].y=_max.y; P[p].z=_max.z; N[p]= NY; p++; // 19
104  I16[i++] = 16; I16[i++] = 17; I16[i++] = 18;
105  I16[i++] = 16; I16[i++] = 18; I16[i++] = 19;
106 
107  // towards -y
108  P[p].x=_min.x; P[p].y=_min.y; P[p].z=_max.z; N[p]=-NY; p++; // 20
109  P[p].x=_min.x; P[p].y=_min.y; P[p].z=_min.z; N[p]=-NY; p++; // 21
110  P[p].x=_max.x; P[p].y=_min.y; P[p].z=_min.z; N[p]=-NY; p++; // 22
111  P[p].x=_max.x; P[p].y=_min.y; P[p].z=_max.z; N[p]=-NY; // 23
112  I16[i++] = 20; I16[i++] = 21; I16[i++] = 22;
113  I16[i++] = 20; I16[i++] = 22; I16[i] = 23;
114 
115  UV[0].resize(6ull * 4ull);
116  for (SLint i = 0; i < 6; i++)
117  {
118  UV[0][4 * i + 0] = SLVec2f(1, 1);
119  UV[0][4 * i + 1] = SLVec2f(0, 1);
120  UV[0][4 * i + 2] = SLVec2f(0, 0);
121  UV[0][4 * i + 3] = SLVec2f(1, 0);
122  }
123 }
unsigned int SLuint
Definition: SL.h:171
int SLint
Definition: SL.h:170
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
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: SLVec3.h:43
T x
Definition: SLVec3.h:43
T z
Definition: SLVec3.h:43

Member Data Documentation

◆ _max

SLVec3f SLBox::_max
private

maximum corner

Definition at line 52 of file SLBox.h.

◆ _min

SLVec3f SLBox::_min
private

minimal corner

Definition at line 51 of file SLBox.h.


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