I cant read OBJ file without normal properly


#1

I read OBJ file without normal in Cinder.

However, OBJ that is read is displayed in Black and can’t change color.

What should I do?

The text below is OBJ that I read.

WaveFront *.obj file (generated by xismo)

mtllib Cut.mtl

g cube
v 1 1 -1
v 1 -1 -1
v -1 1 -1
v -1 -1 -1
v -1 1 1
v -1 -1 1
v 1 1 1
v 1 -1 1

vt 1 0
vt 0 0
vt 0 1
vt 1 1

usemtl Default
f 3/1 4/4 6/3 5/2
f 5/1 6/4 8/3 7/2
f 2/1 8/4 6/3 4/2
f 5/2 7/2 3/2
f 3/2 2/2 4/2
f 2/2 7/2 8/2
f 3/2 7/2 2/2

This is Source Code

ObjLoader loader(loadFile("myModel.obj"));

mTriMesh = TriMesh::create(geom::Cube().subdivisions(6));
auto lambertShader = gl::getStockShader(gl::ShaderDef().color().lambert());

mObjectBounds = mTriMesh->calcBoundingBox();
mMesh = gl::Batch::create(loader, lambertShader);
mTransform = mat4(1.0f);

#2

The lambertian shader requires normals to calculate the shading. You can either use a different shader, or regenerate the normals before creating your gl::Batch

TriMesh loader = ObjLoader ( loadFile(“myModel.obj”) );
loader.recalculateNormals( /* true for smooth normals */ );

auto lambertShader = gl::getStockShader(gl::ShaderDef().color().lambert());
mObjectBounds = loader.calcBoundingBox();
mMesh = gl::Batch::create(loader, lambertShader);
mTransform = mat4(1.0f);

#3

I can display because I tried this way.
Thank you very much!