I’ve been trying to displace the surface of a ofMesh::sphere instance by iterating over the vertexes and adding a noise function. Most things are working but somehow the iterating over the vertexes doesn’t seem normal. There’s a stitching error spiralling around the sphere, and the effect occurs symmetrical. Also one of the ends (the top i guess) has all vertexes connecting to the last vertex, but that last one doesn’t seem to move at all.
From the source code of the ofMesh I can’t figure out how the vertexes are generated, so I’ve been struggling to fix this.
I’ve included the displace function of the class that holds and construct geometries. geoRes is a variable that holds the resolution of the mesh (which is 12 as a default, 200 in my current code). originalVertexes[] is a vector that stores all the original positions.
Hope someone can help me out
void GeoHandler::displace() {
for (int y = 0; y<geoRes*2 + 1; y++){
for (int x = 0; x<geoRes*2 + 1; x++){
glm::vec3 tempVertex = geoMesh.getVertex(x+(y*geoRes));
glm::vec3 tempNormal = geoMesh.getNormal(x+(y*geoRes));
float noiseSpeed = ofGetFrameNum() * 0.01;
float xNoise = x * 0.01;
float yNoise = y * 0.01;
float noiseVal = ofNoise(noiseSpeed + xNoise,noiseSpeed + yNoise);
float noiseMap = ofMap(noiseVal,0,1,0,displaceSize);
glm::vec3 newVertex = originalVertexes[x+(y*geoRes)] + (tempNormal * noiseMap);
geoMesh.setVertex(x+(y*geoRes), newVertex);
}
}
}