I’m just getting started with OF, was playing around with the 3d api, and just noticed some strange behavior. I’m getting the mesh from an ofBoxPrimitive and calling mergeDuplicateVertices() on it. Afterwards the normals are wrong and calling smoothNormals(0) on it screws it up further.
ofMesh fillMesh = ofBoxPrimitive(sz,sz,sz).getMesh();
cout << fillMesh.getVertices().size() << endl; //prints 24 as expected
fillMesh.mergeDuplicateVertices(); //after this normals are weird
cout << fillMesh.getVertices().size() << endl; //prints 36, without smoothNormals(0) prints 8
I’m guessing it has something to do with the state of the mesh before calling merge. Anyone know whats going on here?
The box primitive is composed of triangles, with shared vertices on the corners. So calling mergeDuplicate vertices will make the normals look strange, since there is only one vert and normal there and not four verts and normals. The mergeDuplicateVertices function is for meshes that might have incorrect vertices. Is there a reason you want to call it on the box primitive, that should be well constructed?
Not sure exactly why the number of verts increases when you call smoothNormals.
I thought about triangles after I posted. I guess there would be 36 verts if none of the triangles were sharing verts. I don’t really have any reason to merge, just experimenting. Is it possible to draw quads via ofMesh::draw()?
I’m putting a bunch of these cubes in a grid, appending them to a single mesh instance. If I use smoothNormals(0) as I previously posted on a single instance of the mesh and then construct a Vector with the mesh as the fill object (moving each one to its grid position) the faces don’t display correctly except the front one (positive z I think, the one that points toward the camera).
If I call smoothNormals(0) on each mesh after moving it or on the whole mesh I’m appending them to it looks fine, but takes a long time to get started. I don’t know if it makes sense to do any of this stuff really. I’ve worked with OpenGL a little via Processing, but never tried OF until now.
Anyway, thanks for the reply.
SmoothNormals is an expensive operation. Not sure about how it functions on rigid objects with 90 degree angles.
Currently, GL_QUADS is not supported in OF because it is not cross-platform compatible (ie. iOS) and you can make a quad from triangles. . You can render a quad using ofMesh::plane.