23 # pragma clang diagnostic push
24 # pragma clang diagnostic ignored "-Weverything"
27 #include <igl/remove_duplicate_vertices.h>
28 #include <igl/per_face_normals.h>
29 #include <igl/unique_edge_map.h>
32 # pragma clang diagnostic pop
58 minP.
set(FLT_MAX, FLT_MAX, FLT_MAX);
59 maxP.
set(-FLT_MAX, -FLT_MAX, -FLT_MAX);
73 assetMgr->
meshes().push_back(
this);
96 for (
auto i :
Ji) i.clear();
98 for (
auto i :
Jw) i.clear();
121 _vertexBuffer.free();
122 _normalBuffer.free();
123 _indexShortBuffer.free();
124 _indexIntBuffer.free();
135 _vertexBuffer.free();
136 _normalBuffer.free();
137 _indexShortBuffer.free();
138 _indexIntBuffer.free();
155 if (ixDel <
P.size())
P.erase(
P.begin() + ixDel);
156 if (ixDel <
N.size())
N.erase(
N.begin() + ixDel);
157 if (ixDel <
C.size())
C.erase(
C.begin() + ixDel);
158 if (ixDel <
T.size())
T.erase(
T.begin() + ixDel);
159 if (ixDel <
UV[0].size())
UV[0].erase(
UV[0].begin() + ixDel);
160 if (ixDel <
UV[1].size())
UV[1].erase(
UV[1].begin() + ixDel);
161 if (ixDel <
Ji.size())
Ji.erase(
Ji.begin() + ixDel);
162 if (ixDel <
Jw.size())
Jw.erase(
Jw.begin() + ixDel);
171 if (
I16[t] != ixDel &&
172 I16[t + 1] != ixDel &&
176 i16.push_back(
I16[t]);
178 i16.push_back(
I16[t] - 1);
179 if (
I16[t + 1] < ixDel)
180 i16.push_back(
I16[t + 1]);
182 i16.push_back(
I16[t + 1] - 1);
183 if (
I16[t + 2] < ixDel)
184 i16.push_back(
I16[t + 2]);
186 i16.push_back(
I16[t + 2] - 1);
199 if (
I32[t] != ixDel &&
200 I32[t + 1] != ixDel &&
204 i32.push_back(
I32[t]);
206 i32.push_back(
I32[t] - 1);
207 if (
I32[t + 1] < ixDel)
208 i32.push_back(
I32[t + 1]);
210 i32.push_back(
I32[t + 1] - 1);
211 if (
I32[t + 2] < ixDel)
212 i32.push_back(
I32[t + 2]);
214 i32.push_back(
I32[t + 2] - 1);
226 if (
mat()->needsTangents() && !
UV[0].empty() &&
T.empty())
247 if (
I16.empty() &&
I32.empty())
252 for (
auto&& u : used)
256 for (
unsigned short i :
I16)
259 for (
unsigned int i :
I32)
263 for (
SLulong u = 0; u < used.size(); ++u)
268 SLulong ixDel = u - (unused - 1);
270 if (ixDel <
P.size())
P.erase(
P.begin() + ixDel);
271 if (ixDel <
N.size())
N.erase(
N.begin() + ixDel);
272 if (ixDel <
C.size())
C.erase(
C.begin() + ixDel);
273 if (ixDel <
T.size())
T.erase(
T.begin() + ixDel);
274 if (ixDel <
UV[0].size())
UV[0].erase(
UV[0].begin() + ixDel);
275 if (ixDel <
UV[1].size())
UV[1].erase(
UV[1].begin() + ixDel);
276 if (ixDel <
Ji.size())
Ji.erase(
Ji.begin() + ixDel);
277 if (ixDel <
Jw.size())
Jw.erase(
Jw.begin() + ixDel);
280 for (
unsigned short& i :
I16)
286 for (
unsigned int& i :
I32)
301 msg =
"No vertex positions (P)\n";
303 msg +=
"No vertex indices (I16 or I32)\n";
304 if (msg.length() > 0)
321 if (
mat()->needsTangents() && !
UV[0].empty() &&
T.empty())
339 msg =
"No vertex positions (P)\n";
342 msg +=
"No vertex indices (I16 or I32)\n";
344 if (msg.length() > 0)
396 msg =
"No vertex positions (P)\n";
398 msg +=
"No vertex indices (I16 or I32)\n";
399 if (msg.length() > 0)
451 (!
Ji.empty() && !
Jw.empty()));
460 if (!
Ji.empty() && !
Jw.empty())
464 sp->
uniform1i(
"u_skinningEnabled", skinningEnabled);
516 if (blended) stateGL->
blend(
false);
524 V2.resize(
P.size() * 2);
525 for (
SLulong i = 0; i <
P.size(); ++i)
536 for (
SLulong i = 0; i <
P.size(); ++i)
554 stateGL->
blend(
false);
589 stateGL->
blend(
true);
630 set<SLuint> tempIselected;
635 set<SLuint> tempInRect;
636 for (
SLulong i = 0; i <
P.size(); ++i)
640 tempInRect.insert((
SLuint)i);
644 set<SLuint> IS32set(
IS32.begin(),
IS32.end());
645 std::set_union(IS32set.begin(),
649 inserter(tempIselected, tempIselected.begin()));
654 set<SLuint> tempIdeselected;
655 for (
SLulong i = 0; i <
P.size(); ++i)
659 tempIdeselected.insert((
SLuint)i);
663 tempIselected.clear();
664 set<SLuint> IS32set(
IS32.begin(),
IS32.end());
665 std::set_difference(IS32set.begin(),
667 tempIdeselected.begin(),
668 tempIdeselected.end(),
669 inserter(tempIselected, tempIselected.begin()));
686 if (!tempIselected.empty())
687 IS32.assign(tempIselected.begin(), tempIselected.end());
749 if (!
I16.empty() || !
I32.empty())
771 if (!
Ji.empty() && !
Jw.empty())
773 assert(
Ji.size() ==
P.size());
774 assert(
Jw.size() ==
P.size());
780 for (
unsigned i = 0; i <
P.size(); i++)
783 assert(!curIndices.empty());
785 jointIndicesData[i] =
SLVec4i(curIndices.size() >= 1 ? curIndices[0] : 0,
786 curIndices.size() >= 2 ? curIndices[1] : 0,
787 curIndices.size() >= 3 ? curIndices[2] : 0,
788 curIndices.size() >= 4 ? curIndices[3] : 0);
792 for (
unsigned i = 0; i <
P.size(); i++)
795 assert(curWeights.size() ==
Ji[i].size());
797 jointWeightsData[i] =
SLVec4f(curWeights.size() >= 1 ? curWeights[0] : 0.0f,
798 curWeights.size() >= 2 ? curWeights[1] : 0.0f,
799 curWeights.size() >= 3 ? curWeights[2] : 0.0f,
800 curWeights.size() >= 4 ? curWeights[3] : 0.0f);
830 Eigen::MatrixXf newV;
831 Eigen::MatrixXi newF;
832 Eigen::MatrixXi edges;
833 Eigen::MatrixXi edgeMap;
834 Eigen::MatrixXi uniqueEdges;
835 Eigen::MatrixXf faceN;
839 vector<vector<int>> uE2E;
842 V.resize((Eigen::Index)
_finalP->size(), 3);
843 for (
int i = 0; i <
_finalP->size(); i++)
848 F.resize((Eigen::Index)
I16.size() / 3, 3);
849 for (
int j = 0, i = 0; i <
I16.size(); j++, i += 3)
850 F.row(j) <<
I16[i],
I16[i + 1],
I16[i + 2];
854 F.resize((Eigen::Index)
I32.size() / 3, 3);
855 for (
int j = 0, i = 0; i <
I32.size(); j++, i += 3)
856 F.row(j) << (int)
I32[i], (
int)
I32[i + 1], (int)
I32[i + 2];
860 igl::remove_duplicate_vertices(V, F, epsilon, newV, SVI, SVJ, newF);
861 igl::per_face_normals(newV, newF, faceN);
862 igl::unique_edge_map(newF, edges, uniqueEdges, edgeMap, uE2E);
864 for (
int u = 0; u < uE2E.size(); u++)
867 if (uE2E[u].size() == 1)
871 for (
int i = 0; i < uE2E[u].size(); i++)
873 for (
int j = i + 1; j < uE2E[u].size(); j++)
878 const int ei = uE2E[u][i];
879 const int fi = ei % (int)newF.rows();
880 const int ej = uE2E[u][j];
881 const int fj = ej % (int)newF.rows();
882 Eigen::Matrix<float, 1, 3> ni = faceN.row(fi);
883 Eigen::Matrix<float, 1, 3> nj = faceN.row(fj);
884 Eigen::Matrix<float, 1, 3> ev = (newV.row(edges(ei, 1)) - newV.row(edges(ei, 0))).normalized();
885 float dij =
Utils::PI - atan2((ni.cross(nj)).dot(ev), ni.dot(nj));
894 IE16.push_back(SVI[uniqueEdges(u, 0)]);
895 IE16.push_back(SVI[uniqueEdges(u, 1)]);
897 else if (!
I32.empty())
899 IE32.push_back(SVI[uniqueEdges(u, 0)]);
900 IE32.push_back(SVI[uniqueEdges(u, 1)]);
981 minP.
set(FLT_MAX, FLT_MAX, FLT_MAX);
982 maxP.
set(-FLT_MAX, -FLT_MAX, -FLT_MAX);
985 for (
SLulong i = 0; i <
P.size(); ++i)
1004 SLfloat radius2, xspan, yspan, zspan, maxspan;
1005 SLfloat old_to_p, old_to_p_sq, old_to_new;
1006 SLVec3f xmin, xmax, ymin, ymax, zmin, zmax, dia1, dia2;
1009 xmin.
x = ymin.
y = zmin.
z = FLT_MAX;
1010 xmax.
x = ymax.
y = zmax.
z = -FLT_MAX;
1012 for (i = 0; i <
P.size(); ++i)
1014 if (
P[i].x < xmin.
x)
1016 else if (
P[i].x > xmax.
x)
1018 if (
P[i].y < ymin.
y)
1020 else if (
P[i].y > ymax.
y)
1022 if (
P[i].z < zmin.
z)
1024 else if (
P[i].z > zmax.
z)
1029 dx = xmax.
x - xmin.
x;
1030 dy = xmax.
y - xmin.
y;
1031 dz = xmax.
z - xmin.
z;
1032 xspan = dx * dx + dy * dy + dz * dz;
1035 dx = ymax.
x - ymin.
x;
1036 dy = ymax.
y - ymin.
y;
1037 dz = ymax.
z - ymin.
z;
1038 yspan = dx * dx + dy * dy + dz * dz;
1040 dx = zmax.
x - zmin.
x;
1041 dy = zmax.
y - zmin.
y;
1042 dz = zmax.
z - zmin.
z;
1043 zspan = dx * dx + dy * dy + dz * dz;
1049 if (yspan > maxspan)
1055 if (zspan > maxspan)
1063 center.
x = (dia1.
x + dia2.
x) * 0.5f;
1064 center.
y = (dia1.
y + dia2.
y) * 0.5f;
1065 center.
z = (dia1.
z + dia2.
z) * 0.5f;
1068 dx = dia2.
x - center.
x;
1069 dy = dia2.
y - center.
y;
1070 dz = dia2.
z - center.
z;
1071 radius2 = dx * dx + dy * dy + dz * dz;
1072 radius = sqrt(radius2);
1075 for (i = 0; i <
P.size(); ++i)
1077 dx =
P[i].x - center.
x;
1078 dy =
P[i].y - center.
y;
1079 dz =
P[i].z - center.
z;
1080 old_to_p_sq = dx * dx + dy * dy + dz * dz;
1082 if (old_to_p_sq > radius2)
1085 old_to_p = sqrt(old_to_p_sq);
1088 radius = (radius + old_to_p) * 0.5f;
1089 radius2 = radius * radius;
1090 old_to_new = old_to_p - radius;
1093 center.
x = (radius * center.
x + old_to_new *
P[i].x) / old_to_p;
1094 center.
y = (radius * center.
y + old_to_new *
P[i].y) / old_to_p;
1095 center.
z = (radius * center.
z + old_to_new *
P[i].z) / old_to_p;
1098 SL_LOG(
"\n New sphere: center,radius = %f %f %f %f",
1220 for (
SLulong i = 0; i <
P.size(); ++i)
1232 !
N.empty() && !
UV[0].empty() &&
1233 (!
I16.empty() || !
I32.empty()))
1246 T1.resize(
P.size());
1249 T2.resize(
P.size());
1255 for (
SLuint t = 0; t < numT; ++t)
1273 float x1 =
P[iVB].x -
P[iVA].x;
1274 float x2 =
P[iVC].x -
P[iVA].x;
1275 float y1 =
P[iVB].y -
P[iVA].y;
1276 float y2 =
P[iVC].y -
P[iVA].y;
1277 float z1 =
P[iVB].z -
P[iVA].z;
1278 float z2 =
P[iVC].z -
P[iVA].z;
1280 float s1 =
UV[0][iVB].x -
UV[0][iVA].x;
1281 float s2 =
UV[0][iVC].x -
UV[0][iVA].x;
1282 float t1 =
UV[0][iVB].y -
UV[0][iVA].y;
1283 float t2 =
UV[0][iVC].y -
UV[0][iVA].y;
1285 float r = 1.0F / (s1 * t2 - s2 * t1);
1286 SLVec3f sdir((t2 * x1 - t1 * x2) * r,
1287 (t2 * y1 - t1 * y2) * r,
1288 (t2 * z1 - t1 * z2) * r);
1289 SLVec3f tdir((s1 * x2 - s2 * x1) * r,
1290 (s1 * y2 - s2 * y1) * r,
1291 (s1 * z2 - s2 * z1) * r);
1302 for (
SLulong i = 0; i <
P.size(); ++i)
1305 T[i] = T1[i] -
N[i] *
N[i].dot(T1[i]);
1310 bitangent.
cross(
N[i], T1[i]);
1311 T[i].w = (bitangent.
dot(T2[i]) < 0.0f) ? -1.0f : 1.0f;
1328 SLfloat s = 1.0f / (2.0f * maxExt);
1347 assert(ray &&
"ray pointer is null");
1348 assert(node &&
"node pointer is null");
1349 assert(
_mat &&
"material pointer is null");
1360 SLVec3f cornerA, cornerB, cornerC;
1379 e1.
sub(cornerB, cornerA);
1380 e2.
sub(cornerC, cornerA);
1395 if (det < FLT_EPSILON)
return false;
1402 if (u < 0.0f || u > det)
return false;
1409 if (v < 0.0f || u + v > det)
return false;
1412 inv_det = 1.0f / det;
1413 t = e2.
dot(Q) * inv_det;
1416 if (t > ray->
length || t < 0.0f)
return false;
1421 ray->
hitU = u * inv_det;
1422 ray->
hitV = v * inv_det;
1427 if (det < FLT_EPSILON && det > -FLT_EPSILON)
return false;
1429 inv_det = 1.0f / det;
1435 u = AO.
dot(K) * inv_det;
1436 if (u < 0.0f || u > 1.0f)
return false;
1443 if (v < 0.0f || u + v > 1.0f)
return false;
1446 t = e2.
dot(Q) * inv_det;
1449 if (t > ray->
length || t < 0.0f)
return false;
1508 if (!diffuseTex.empty() &&
1509 !diffuseTex[0]->images().empty() &&
1519 if (!bumpTex.empty() && !bumpTex[0]->images().empty())
1530 SLVec2f d = bumpTex[0]->dudv(tc.
x, tc.
y);
1550 ray->
hitAO = aoTex[0]->getTexelf(tc2.
x, tc2.
y).r;
1574 const std::function<
void(
SLMesh*)>& cbInformNodes)
1577 forceCPUSkinning =
true;
1583 for (
SLulong i = 0; i <
P.size(); ++i)
1589 for (
SLulong i = 0; i <
P.size(); ++i)
1604 cbInformNodes(
this);
1614 if (forceCPUSkinning)
1620 for (
SLulong i = 0; i <
P.size(); ++i)
1626 for (
SLulong j = 0; j <
Ji[i].size(); ++j)
1661 unsigned int SLMesh::meshIndex = 0;
1663 void SLMesh::allocAndUploadData()
1665 _vertexBuffer.alloc_and_upload(
P);
1667 _normalBuffer.alloc_and_upload(
N);
1670 _textureBuffer.alloc_and_upload(
UV[0]);
1673 _textureBuffer.alloc_and_upload(
UV[1]);
1676 _indexShortBuffer.alloc_and_upload(
I16);
1678 _indexIntBuffer.alloc_and_upload(
I32);
1681 void SLMesh::uploadData()
1683 _vertexBuffer.upload(*
_finalP);
1684 _normalBuffer.upload(*
_finalN);
1687 void SLMesh::createMeshAccelerationStructure()
1689 if (!_vertexBuffer.isAllocated())
1691 allocAndUploadData();
1695 uint32_t _buildInput_flags[1] = {OPTIX_GEOMETRY_FLAG_NONE};
1697 _buildInput.type = OPTIX_BUILD_INPUT_TYPE_TRIANGLES;
1700 _buildInput.triangleArray.indexFormat = OPTIX_INDICES_FORMAT_UNSIGNED_SHORT3;
1701 _buildInput.triangleArray.numIndexTriplets = (
SLuint)(
I16.size() / 3);
1702 _buildInput.triangleArray.indexBuffer = _indexShortBuffer.devicePointer();
1706 _buildInput.triangleArray.indexFormat = OPTIX_INDICES_FORMAT_UNSIGNED_INT3;
1707 _buildInput.triangleArray.numIndexTriplets = (
SLuint)(
I32.size() / 3);
1708 _buildInput.triangleArray.indexBuffer = _indexIntBuffer.devicePointer();
1710 _buildInput.triangleArray.vertexFormat = OPTIX_VERTEX_FORMAT_FLOAT3;
1711 _buildInput.triangleArray.vertexBuffers = _vertexBuffer.devicePointerPointer();
1712 _buildInput.triangleArray.numVertices = (
SLuint)
P.size();
1713 _buildInput.triangleArray.flags = _buildInput_flags;
1714 _buildInput.triangleArray.numSbtRecords = 1;
1715 _buildInput.triangleArray.sbtIndexOffsetBuffer = 0;
1716 _buildInput.triangleArray.sbtIndexOffsetSizeInBytes = 0;
1717 _buildInput.triangleArray.sbtIndexOffsetStrideInBytes = 0;
1719 _sbtIndex = RAY_TYPE_COUNT * meshIndex++;
1721 buildAccelerationStructure();
1724 void SLMesh::updateMeshAccelerationStructure()
1732 uint32_t _buildInput_flags[1] = {OPTIX_GEOMETRY_FLAG_NONE};
1733 _buildInput.triangleArray.flags = _buildInput_flags;
1735 updateAccelerationStructure();
1738 ortHitData SLMesh::createHitData()
1740 ortHitData hitData = {};
1742 hitData.sbtIndex = 0;
1743 hitData.normals =
reinterpret_cast<float3*
>(_normalBuffer.devicePointer());
1744 hitData.indices =
reinterpret_cast<short3*
>(_indexShortBuffer.devicePointer());
1745 hitData.texCords =
reinterpret_cast<float2*
>(_textureBuffer.devicePointer());
1750 hitData.material.kn =
mat()->
kn();
1751 hitData.material.kt =
mat()->
kt();
1752 hitData.material.kr =
mat()->
kr();
1754 hitData.material.ambient_color = make_float4(
mat()->ambient());
1755 hitData.material.specular_color = make_float4(
mat()->specular());
1756 hitData.material.transmissiv_color = make_float4(
mat()->transmissive());
1757 hitData.material.diffuse_color = make_float4(
mat()->diffuse());
1758 hitData.material.emissive_color = make_float4(
mat()->emissive());
#define PROFILE_FUNCTION()
#define SL_WARN_MSG(message)
vector< SLuchar > SLVuchar
vector< SLfloat > SLVfloat
#define SL_EXIT_MSG(message)
vector< SLushort > SLVushort
SLuint SL_sizeOfVector(const T &vector)
#define SL_DB_ONLYEDGES
Draw only hard edges.
#define SL_DB_NORMALS
Draw the vertex normals.
#define SL_DB_WITHEDGES
Draw faces with hard edges.
#define SL_DB_NOTSELECTABLE
Flags an object as selected.
#define SL_DB_VOXELS
Draw the voxels of the uniform grid.
#define SL_DB_CULLOFF
Turn off face culling.
#define SL_DB_MESHWIRED
Draw polygons as wired mesh.
#define SL_DB_HIDDEN
Flags an object as hidden.
@ AT_jointWeight
Vertex joint weight for vertex skinning.
@ AT_jointIndex
Vertex joint id for vertex skinning.
@ AT_position
Vertex position as a 2, 3 or 4 component vectors.
@ AT_normal
Vertex normal as a 3 component vector.
@ AT_color
Vertex color as 3 or 4 component vector.
@ AT_uv1
Vertex 1st texture coordinate as 2 component vector.
@ AT_uv2
Vertex 2nd texture coordinate as 2 component vector.
@ AT_tangent
Vertex tangent as a 4 component vector (see SLMesh)
@ BU_stream
Buffer will be modified once and used at most a few times.
@ BU_static
Buffer will be modified once and used many times.
vector< SLGLTexture * > SLVGLTexture
STL vector of SLGLTexture pointers.
vector< SLVec3f > SLVVec3f
vector< SLVec4f > SLVVec4f
vector< SLVec4i > SLVVec4i
SLVec4< SLfloat > SLVec4f
Defines an axis aligned bounding box.
void fromOStoWS(const SLVec3f &minOS, const SLVec3f &maxOS, const SLMat4f &wm)
Recalculate min and max after transformation in world coords.
void maxOS(const SLVec3f &maxC)
virtual void updateStats(SLNodeStats &stats)=0
virtual void build(SLVec3f minV, SLVec3f maxV)=0
virtual void draw(SLSceneView *sv)=0
virtual SLbool intersect(SLRay *ray, SLNode *node)=0
virtual void disposeBuffers()=0
void getJointMatrices(SLVMat4f &jointWM)
Toplevel holder of the assets meshes, materials, textures and shaders.
Active or visible camera node class.
Class for compact uniform grid acceleration structure.
Encapsulation of an OpenGL shader program object.
SLint uniformMatrix4fv(const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const
Passes a 4x4 float matrix values py pointer to the uniform variable "name".
SLint getUniformLocation(const SLchar *name) const
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
Singleton class holding all OpenGL states.
SLMat4f textureMatrix
matrix for the texture transform
SLMat4f modelMatrix
Init all states.
void polygonOffsetPoint(SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f)
void depthMask(SLbool state)
static SLGLState * instance()
Public static instance getter for singleton pattern.
void polygonOffsetLine(SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f)
SLMat4f viewMatrix
matrix for the active cameras view transform
SLMat4f projectionMatrix
matrix for projection transform
void polygonLine(SLbool state)
void cullFace(SLbool state)
void depthTest(SLbool state)
void generateVertexPos(SLVVec2f *p)
Adds or updates & generates a position vertex attribute for colored line or point drawing.
void drawElementAsColored(SLGLPrimitiveType primitiveType, SLCol4f color, SLfloat pointSize, SLuint indexFirstVertex=0, SLuint countVertices=0)
Draws the VAO by element indices with the specified primitive with the color.
void drawArrayAsColored(SLGLPrimitiveType primitiveType, SLCol4f color, SLfloat lineOrPointSize=1.0f, SLuint indexFirstVertex=0, SLuint countVertices=0)
Draws the array as the specified primitive with the color.
SLGLVertexArray encapsulates the core OpenGL drawing.
void clearAttribs()
Clears the attribute definition.
void updateAttrib(SLGLAttributeType type, SLint elementSize, void *dataPointer)
Updates a specific vertex attribute in the VBO.
void drawElementsAs(SLGLPrimitiveType primitiveType, SLuint numIndexes=0, SLuint indexOffsetBytes=0)
Draws the VAO by element indices with a primitive type.
void setAttrib(SLGLAttributeType type, SLint elementSize, SLint location, void *dataPointer, SLGLBufferType dataType=BT_float)
Adds a vertex attribute with data pointer and an element size.
void drawArrayAs(SLGLPrimitiveType primitiveType, SLint firstVertex=0, SLsizei countVertices=0)
Draws the VAO as an array with a primitive type.
void drawElementsInstanced(SLGLPrimitiveType primitiveType, SLuint countInstance=0, SLuint numIndexes=0, SLuint indexOffset=0)
Draws the VAO as an array with instance primitive type.
SLuint vaoID() const
Returns either the VAO id or the VBO id.
void setIndices(SLuint numIndicesElements, SLGLBufferType indexDataType, void *indexDataElements, SLuint numIndicesEdges=0, void *indexDataEdges=nullptr)
Adds the index array for indexed element drawing.
void generate(SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true, SLuint divisor=0)
Generates the VA & VB objects for a NO. of vertices.
void drawEdges(SLCol4f color, SLfloat lineWidth=1.0f)
Draws the hard edges of the VAO with the edge indices.
void deleteGL()
Deletes all vertex array & vertex buffer objects.
void identity()
Sets the identity matrix.
void translate(T tx, T ty, T tz=0)
void viewport(T x, T y, T ww, T wh, T n=0.0f, T f=1.0f)
Defines the viewport matrix.
static SLMaterialDefaultColorAttribute * instance()
static SLMaterialDefaultGray * instance()
Defines a standard CG material with textures and a shader program.
SLbool has3DTexture()
Returns true if a material has a 3D texture.
void activate(SLCamera *cam, SLVLight *lights, SLbool supportGPUSkinning)
void shininess(SLfloat shin)
SLVGLTexture & textures(SLTextureType type)
SLVGLTexture & textures3d()
void program(SLGLProgram *sp)
An SLMesh object is a triangulated mesh, drawn with one draw call.
SLMesh(SLAssetManager *assetMgr, const SLstring &name="Mesh")
Construct a new SLMesh::SLMesh object.
SLVec3f maxP
max. vertex in OS
void handleRectangleSelection(SLSceneView *sv, SLGLState *stateGL, SLNode *node)
Handles the rectangle section of mesh vertices (partial selection)
SLVuint IS32
Vector of rectangle selected vertex indices 32 bit.
SLVuint I32
Vector of vertex indices 32 bit.
SLVushort I16
Vector of vertex indices 16 bit.
virtual void calcNormals()
SLMesh::calcNormals recalculates vertex normals for triangle meshes.
void deselectPartialSelection()
SLbool _isVolume
Flag for RT if mesh is a closed volume.
SLGLVertexArrayExt _vaoT
OpenGL VAO for optional tangent drawing.
SLVVec4f T
Vector of vertex tangents (opt.) layout (location = 5)
void transformSkin(bool forceCPUSkinning, const std::function< void(SLMesh *)> &cbInformNodes)
Transforms the vertex positions and normals with by joint weights.
virtual void calcMinMax()
SLVuint IE32
Vector of hard edges vertex indices 32 bit (see computeHardEdgesIndices)
SLfloat _edgeAngleDEG
Edge crease angle in degrees between face normals (30 deg. default)
virtual void init(SLNode *node)
SLMesh::shapeInit sets the transparency flag of the AABB.
virtual void draw(SLSceneView *sv, SLNode *node, SLuint intances=0)
void calcCenterRad(SLVec3f ¢er, SLfloat &radius)
SLbool hit(SLRay *ray, SLNode *node)
SLbool _isSelected
Flag if mesh is partially of fully selected.
SLfloat _vertexPosEpsilon
Vertex position epsilon used in computeHardEdgesIndices.
SLVCol4f C
Vector of vertex colors (opt.) layout (location = 4)
SLVVec3f skinnedN
temp. vector for CPU skinned vertex normals
void computeHardEdgesIndices(float angleRAD, float epsilon)
computes the hard edges and stores the vertex indexes separately
void deleteSelected(SLNode *node)
Deletes the rectangle selected vertices and the dependent triangles.
void drawSelectedVertices()
virtual void deleteDataGpu()
void addStats(SLNodeStats &stats)
SLVushort IE16
Vector of hard edges vertex indices 16 bit (see computeHardEdgesIndices)
SLGLPrimitiveType _primitive
Primitive type (default triangles)
virtual void generateVAO(SLGLVertexArray &vao)
Generate the Vertex Array Object for a specific shader program.
SLVVec3f * _finalN
pointer to final vertex normal vector
static void calcTex3DMatrix(SLNode *node)
SLfloat _edgeWidth
Line width for hard edge drawing.
SLGLVertexArrayExt _vaoN
OpenGL VAO for optional normal drawing.
SLAnimSkeleton * _skeleton
The skeleton this mesh is bound to.
SLVVec3f N
Vector for vertex normals (opt.) layout (location = 1)
SLVec3f minP
min. vertex in OS
virtual void deleteData()
SLMesh::deleteData deletes all mesh data and vbo's.
void calcTangents()
SLMesh::calcTangents computes the tangents per vertex for triangle meshes.
SLVVec2f UV[2]
Array of 2 Vectors for tex. coords. (opt.) layout (location = 2)
SLVMat4f _jointMatrices
Joint matrix vector for this mesh.
SLVVec3f * _finalP
Pointer to final vertex position vector.
SLbool hitTriangleOS(SLRay *ray, SLNode *node, SLuint iT)
void drawIntoDepthBuffer(SLSceneView *sv, SLNode *node, SLMaterial *depthMat)
Simplified drawing method for shadow map creation.
SLVVuchar Ji
2D Vector of per vertex joint ids (opt.) layout (location = 6)
SLCol4f _edgeColor
Color for hard edge drawing.
virtual void buildAABB(SLAABBox &aabb, const SLMat4f &wmNode)
void deleteUnused()
Deletes unused vertices (= vertices that are not indexed in I16 or I32)
SLGLVertexArrayExt _vaoS
OpenGL VAO for optional selection drawing.
SLbool _accelStructIsOutOfDate
Flag if accel. struct needs update.
SLGLVertexArray _vao
Main OpenGL Vertex Array Object for drawing.
~SLMesh() override
The destructor deletes everything by calling deleteData.
SLVVec3f skinnedP
temp. vector for CPU skinned vertex positions
SLVVfloat Jw
2D Vector of per vertex joint weights (opt.) layout (location = 7)
SLAccelStruct * _accelStruct
KD-tree or uniform grid.
SLVVec3f P
Vector for vertex positions layout (location = 0)
SLMaterial * _matOut
Pointer to the outside material.
virtual void preShade(SLRay *ray)
SLbool _isCPUSkinned
Flag if mesh has been skinned on CPU during update.
SLMaterial * _mat
Pointer to the inside material.
SLNode represents a node in a hierarchical scene graph.
SLbool drawBit(SLuint bit)
const SLMat4f & updateAndGetWM() const
void isSelected(bool isSelected)
void levelForSM(SLubyte lfsm)
Base class for all other classes.
SLstring _name
name of an object
Ray class with ray and intersection properties.
SLint hitTriangle
Points to the intersected triangle.
SLVec3f origin
Vector to the origin of ray in WS.
static SLuint intersections
NO. of intersection.
SLint srcTriangle
Points to the triangle at ray origin.
static SLuint tests
NO. of intersection tests.
SLMesh * hitMesh
Points to the intersected mesh.
SLbool isOutside
Flag if ray is inside of a material.
SLfloat hitAO
Ambient occlusion factor at intersection point.
SLVec3f dir
Direction vector of ray in WS.
SLMesh * srcMesh
Points to the mesh at ray origin.
SLfloat length
length from origin to an intersection
SLNode * hitNode
Points to the intersected node.
SLVec3f hitPoint
Point of intersection.
SLVec3f dirOS
Direction vector of ray in OS.
SLCol4f hitTexColor
Color at intersection for texture or color attributes.
SLVec3f originOS
Vector to the origin of ray in OS.
SLVec3f hitNormal
Surface normal at intersection point.
SLfloat hitV
barycentric coords in hit triangle
SLbool contains(T X, T Y)
The SLScene class represents the top level instance holding the scene structure.
SLVMesh & selectedMeshes()
SLVNode & selectedNodes()
SceneView class represents a dynamic real time 3D view onto the scene.
SLRecti viewportRect() const
void camera(SLCamera *camera)
SLbool drawBit(SLuint bit)
Skybox node class with a SLBox mesh.
void cross(const SLVec3 &a, const SLVec3 &b)
void set(const T X, const T Y, const T Z)
T dot(const SLVec3 &v) const
void sub(const SLVec3 &a, const SLVec3 &b)
void set(const T X, const T Y, const T Z, const T W=1)
void set(std::string path, const std::vector< char > &data)
static const float DEG2RAD
Struct for scene graph statistics.
SLuint numMeshes
NO. of meshes in node.
SLuint numTriangles
NO. of triangles in mesh.
SLuint numLines
NO. of lines in mesh.
SLuint numBytes
NO. of bytes allocated.