fixes in rendering
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "../../OpenGLWindow/GLInstancingRenderer.h"
|
||||
#include "../../OpenGLWindow/GLInstanceGraphicsShape.h"
|
||||
|
||||
GLInstanceGraphicsShape* btgCreateGraphicsShapeFromWavefrontObj(std::vector<tinyobj::shape_t>& shapes)
|
||||
GLInstanceGraphicsShape* btgCreateGraphicsShapeFromWavefrontObj(std::vector<tinyobj::shape_t>& shapes, bool flatShading)
|
||||
{
|
||||
|
||||
b3AlignedObjectArray<GLInstanceVertex>* vertices = new b3AlignedObjectArray<GLInstanceVertex>;
|
||||
@@ -82,29 +82,59 @@ GLInstanceGraphicsShape* btgCreateGraphicsShapeFromWavefrontObj(std::vector<tiny
|
||||
}
|
||||
|
||||
|
||||
|
||||
btVector3 v0(vtx0.xyzw[0],vtx0.xyzw[1],vtx0.xyzw[2]);
|
||||
btVector3 v1(vtx1.xyzw[0],vtx1.xyzw[1],vtx1.xyzw[2]);
|
||||
btVector3 v2(vtx2.xyzw[0],vtx2.xyzw[1],vtx2.xyzw[2]);
|
||||
|
||||
normal = (v1-v0).cross(v2-v0);
|
||||
btScalar len2 = normal.length2();
|
||||
//skip degenerate triangles
|
||||
if (len2 > SIMD_EPSILON)
|
||||
unsigned int maxIndex = 0;
|
||||
maxIndex = b3Max(maxIndex,shape.mesh.indices[f]*3+0);
|
||||
maxIndex = b3Max(maxIndex,shape.mesh.indices[f]*3+1);
|
||||
maxIndex = b3Max(maxIndex,shape.mesh.indices[f]*3+2);
|
||||
maxIndex = b3Max(maxIndex,shape.mesh.indices[f+1]*3+0);
|
||||
maxIndex = b3Max(maxIndex,shape.mesh.indices[f+1]*3+1);
|
||||
maxIndex = b3Max(maxIndex,shape.mesh.indices[f+1]*3+2);
|
||||
maxIndex = b3Max(maxIndex,shape.mesh.indices[f+2]*3+0);
|
||||
maxIndex = b3Max(maxIndex,shape.mesh.indices[f+2]*3+1);
|
||||
maxIndex = b3Max(maxIndex,shape.mesh.indices[f+2]*3+2);
|
||||
bool hasNormals = (shape.mesh.normals.size() && maxIndex<shape.mesh.normals.size() );
|
||||
|
||||
if (flatShading || !hasNormals)
|
||||
{
|
||||
normal.normalize();
|
||||
normal = (v1-v0).cross(v2-v0);
|
||||
btScalar len2 = normal.length2();
|
||||
//skip degenerate triangles
|
||||
if (len2 > SIMD_EPSILON)
|
||||
{
|
||||
normal.normalize();
|
||||
} else
|
||||
{
|
||||
normal.setValue(0,0,0);
|
||||
}
|
||||
vtx0.normal[0] = normal[0];
|
||||
vtx0.normal[1] = normal[1];
|
||||
vtx0.normal[2] = normal[2];
|
||||
vtx1.normal[0] = normal[0];
|
||||
vtx1.normal[1] = normal[1];
|
||||
vtx1.normal[2] = normal[2];
|
||||
vtx2.normal[0] = normal[0];
|
||||
vtx2.normal[1] = normal[1];
|
||||
vtx2.normal[2] = normal[2];
|
||||
} else
|
||||
{
|
||||
normal.setValue(0,0,0);
|
||||
|
||||
vtx0.normal[0] = shape.mesh.normals[shape.mesh.indices[f]*3+0];
|
||||
vtx0.normal[1] = shape.mesh.normals[shape.mesh.indices[f]*3+1];
|
||||
vtx0.normal[2] = shape.mesh.normals[shape.mesh.indices[f]*3+2]; //shape.mesh.indices[f+1]*3+0
|
||||
vtx1.normal[0] = shape.mesh.normals[shape.mesh.indices[f+1]*3+0];
|
||||
vtx1.normal[1] = shape.mesh.normals[shape.mesh.indices[f+1]*3+1];
|
||||
vtx1.normal[2] = shape.mesh.normals[shape.mesh.indices[f+1]*3+2];
|
||||
vtx2.normal[0] = shape.mesh.normals[shape.mesh.indices[f+2]*3+0];
|
||||
vtx2.normal[1] = shape.mesh.normals[shape.mesh.indices[f+2]*3+1];
|
||||
vtx2.normal[2] = shape.mesh.normals[shape.mesh.indices[f+2]*3+2];
|
||||
|
||||
|
||||
}
|
||||
vtx0.normal[0] = normal[0];
|
||||
vtx0.normal[1] = normal[1];
|
||||
vtx0.normal[2] = normal[2];
|
||||
vtx1.normal[0] = normal[0];
|
||||
vtx1.normal[1] = normal[1];
|
||||
vtx1.normal[2] = normal[2];
|
||||
vtx2.normal[0] = normal[0];
|
||||
vtx2.normal[1] = normal[1];
|
||||
vtx2.normal[2] = normal[2];
|
||||
vertices->push_back(vtx0);
|
||||
vertices->push_back(vtx1);
|
||||
vertices->push_back(vtx2);
|
||||
|
||||
Reference in New Issue
Block a user