2 years ago
#60644
Jaysmito Mukherjee
OpenGL Mesh Mesh splitting up in triangles When trying to apply modification by addting normal*factor
I have a basic icosphere which i exported from blender with normals as obj.
Here is what i am doing
mesh->vert[i].position = mesh->vert[i].position + noise(mesh->vert[i].position) * mesh->vert[i].normal
for every vertex.
But the triangles are splitting up wierdly like:
The Exact Code:
for(int i=0;i<customModel->mesh->vertexCount;i++)
{
Vert tmp = customModelCopy->mesh->vert[i];
float x = tmp.position.x;
float y = tmp.position.y;
float z = tmp.position.z;
float elev = 0.0f;
if (noiseBased)
{
elev = noiseGen->Evaluate(x, y, z);
for (NoiseLayerModule* mod : moduleManager->nlModules)
{
if (mod->active)
{
elev += mod->Evaluate(x, y, z);
}
}
}
else {
float pos[3] = { x, y, z };
float texCoord[2] = { tmp.texCoord.x, tmp.texCoord.y };
float minPos[3] = {0, 0, 0};
float maxPos[3] = {-1, -1, -1};
elev = EvaluateMeshNodeEditor(NodeInputParam(pos, texCoord, minPos, maxPos)).value;
}
tmp.position -= elev * tmp.normal;
customModel->mesh->vert[i] = tmp;
}
customModel->mesh->RecalculateNormals();
And For Model : https://github.com/Jaysmito101/TerraForge3D/blob/master/TerraForge3D/src/Base/Mesh.cpp https://github.com/Jaysmito101/TerraForge3D/blob/master/TerraForge3D/src/Base/Model.cpp
c++
opengl
graphics
normals
0 Answers
Your Answer