Utility/OBJParser: Optimized loading
Former-commit-id: f84e73928d0596d5933cadea572465ded864192f [formerly 0621b0e5e8f674273190ed08e5d984c085d190a9] Former-commit-id: 7dae4cbeff3644cdb0246ac3d077ddcb5bc7b51f
This commit is contained in:
@@ -123,8 +123,8 @@ namespace Nz
|
||||
if (!parameters.custom.GetIntegerParameter("NativeOBJLoader_VertexCount", &reservedVertexCount))
|
||||
reservedVertexCount = 100;
|
||||
|
||||
OBJParser parser(stream);
|
||||
if (!parser.Parse(reservedVertexCount))
|
||||
OBJParser parser;
|
||||
if (!parser.Parse(stream, reservedVertexCount))
|
||||
{
|
||||
NazaraError("OBJ parser failed");
|
||||
return false;
|
||||
@@ -177,23 +177,24 @@ namespace Nz
|
||||
{
|
||||
bool operator()(const OBJParser::FaceVertex& lhs, const OBJParser::FaceVertex& rhs) const
|
||||
{
|
||||
return lhs.normal == rhs.normal &&
|
||||
return lhs.normal == rhs.normal &&
|
||||
lhs.position == rhs.position &&
|
||||
lhs.texCoord == rhs.texCoord;
|
||||
}
|
||||
};
|
||||
|
||||
std::unordered_map<OBJParser::FaceVertex, unsigned int, FaceVertexHasher, FaceVertexComparator> vertices;
|
||||
vertices.reserve(meshes[i].vertices.size());
|
||||
|
||||
unsigned int vertexCount = 0;
|
||||
for (unsigned int j = 0; j < faceCount; ++j)
|
||||
{
|
||||
unsigned int faceVertexCount = meshes[i].faces[j].vertices.size();
|
||||
unsigned int faceVertexCount = meshes[i].faces[j].vertexCount;
|
||||
faceIndices.resize(faceVertexCount);
|
||||
|
||||
for (unsigned int k = 0; k < faceVertexCount; ++k)
|
||||
{
|
||||
const OBJParser::FaceVertex& vertex = meshes[i].faces[j].vertices[k];
|
||||
const OBJParser::FaceVertex& vertex = meshes[i].vertices[meshes[i].faces[j].firstVertex + k];
|
||||
|
||||
auto it = vertices.find(vertex);
|
||||
if (it == vertices.end())
|
||||
@@ -202,6 +203,7 @@ namespace Nz
|
||||
faceIndices[k] = it->second;
|
||||
}
|
||||
|
||||
// Triangulation
|
||||
for (unsigned int k = 1; k < faceVertexCount-1; ++k)
|
||||
{
|
||||
indices.push_back(faceIndices[0]);
|
||||
@@ -233,17 +235,17 @@ namespace Nz
|
||||
|
||||
MeshVertex& vertex = meshVertices[index];
|
||||
|
||||
const Vector4f& vec = positions[vertexIndices.position];
|
||||
const Vector4f& vec = positions[vertexIndices.position-1];
|
||||
vertex.position = Vector3f(parameters.matrix * vec);
|
||||
|
||||
if (vertexIndices.normal >= 0)
|
||||
vertex.normal = normals[vertexIndices.normal];
|
||||
if (vertexIndices.normal > 0)
|
||||
vertex.normal = normals[vertexIndices.normal-1];
|
||||
else
|
||||
hasNormals = false;
|
||||
|
||||
if (vertexIndices.texCoord >= 0)
|
||||
if (vertexIndices.texCoord > 0)
|
||||
{
|
||||
const Vector3f& uvw = texCoords[vertexIndices.texCoord];
|
||||
const Vector3f& uvw = texCoords[vertexIndices.texCoord-1];
|
||||
vertex.uv.Set(uvw.x, (parameters.flipUVs) ? 1.f - uvw.y : uvw.y); // Inversion des UVs si demandé
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user