Flat Shading on a 3D Model

Is it possible to get a flat shading like this in openFrameworks?

Screenshot of a collada model (.dae) in a Three.js scene with two moving lights.
Interactive version here

Same model as above, but exported from Blender as 3D Studio (.3ds) and imported into [openFrameworks]/examples/addons/3DModelLoaderExample.

How can I get the same flat shading as in the Three.js example?
I tried glShadeModel (GL_FLAT) but I know it is not that simple.

1 Like

Looks like the difference is that the three.js version is using face normals and your OF version is using smoothed normals. Not sure how to do it for .3ds models, but there is an option for Face smoothing the normals for some export options in Blender. There may be an option in Blender to convert to face normals before exporting.
You can also try splitting the faces in OF, so that the vertices do not share the same normal (causing it to render smooth). This technique is shown in the 3DPrimitives examples (hit z to split the faces). Some sample code:

vector<ofMeshFace> triangles = myMesh.getMesh().getUniqueFaces();
myMesh.getMesh().setFromTriangles( triangles, true );

Thank you @NickHardeman.

I couldn’t find an option like that in Blender. There was something about smoothing when exporting to other formats (.obj for example) but not for .3ds. And I think ofx3DModelLoader only supports .3ds, so I moved on to the second approach.

No luck there either, because there is no way (that I’m aware of) to get the mesh from an ofx3DModelLoader object. And every forum post out there about this suggests to use ofxAssimpModelLoader instead. On Windows with Code Blocks I try to avoid that as much as I can, but I found a solution that seems to work OK. I posted about it in another relevant thread in case anyone is interested: http://forum.openframeworks.cc/t/setting-up-assimploader-on-windows/6378

I haven’t used ofx3DModelLoader loader, but it looks like you can get into the meshes.
The model variable in ofx3DModelLoader is a model3DS. The model3DS class has a list of meshes; each mesh has the verts, normals, faces and faceSmoothing, etc. Maybe you can loop through the meshes and adjust the normals to be oriented with the face or try changing the faceSmoothing for each vert?

maybe it’s the provoking vertex (last or first) you’d like to check, also maybe check whether the correct shader extensions are activated. i wrote a post about flat shading in openFrameworks a while ago, maybe you’ll find something in there that helps: Flat Shading of meshes in OpenGL / openFrameworks using legacy GLSL