Exemple #1
0
bool CalculateVertexNormals(Grid& grid, APosition& aPos, ANormal& aNorm)
{
    if(!grid.has_attachment<Vertex>(aPos))
        return false;
    if(!grid.has_attachment<Vertex>(aNorm))
        grid.attach_to<Vertex>(aNorm);

    Grid::VertexAttachmentAccessor<APosition> aaPos(grid, aPos);
    Grid::VertexAttachmentAccessor<ANormal> aaNorm(grid, aNorm);

    return CalculateVertexNormals(grid, aaPos, aaNorm);
}
Exemple #2
0
	std::shared_ptr<MD5Mesh> MD5Mesh::Create(const FilePath& fname) {
		auto mesh = std::make_shared<MD5Mesh>();
		mesh->SetFileName(fname);
		mesh->SetName(fname.SubpathFrom("assets").toGenericString());

		if (mesh->Parse()) {
			mesh->CalculateVertexPositions();
			mesh->CalculateVertexNormals();
			mesh->UpdateIndexList();
			MeshMap::Set(mesh->GetName(), mesh);
			return mesh;
		}
		spdlog::get("console_log")->warn("[MD5Mesh] Error parsing file {}", fname.toString());

		return nullptr;
	}
Exemple #3
0
void Mesh::Finalize ()
{
	if (DBGERROR (finalized)) {
		return;
	}

	calculatedTriangleNormals.clear ();
	calculatedVertexNormals.clear ();

	bool needVertexNormals = false;
	for (UIndex i = 0; i < triangles.size (); i++) {
		Triangle& triangle = triangles[i];
		if (triangle.curveGroup != Mesh::NonCurved) {
			needVertexNormals = true;
		}
		if (triangle.texCoord0 == InvalidIndex) {
			texCoords.push_back (Vec2 (0.0, 0.0));
			triangle.texCoord0 = texCoords.size () - 1;
		}
		if (triangle.texCoord1 == InvalidIndex) {
			texCoords.push_back (Vec2 (0.0, 0.0));
			triangle.texCoord1 = texCoords.size () - 1;
		}
		if (triangle.texCoord2 == InvalidIndex) {
			texCoords.push_back (Vec2 (0.0, 0.0));
			triangle.texCoord2 = texCoords.size () - 1;
		}
		calculatedTriangleNormals.push_back (CalculateTriangleNormal (i));
	}

	if (needVertexNormals) {
		CalculateVertexNormals ();
	}

	CalculateBoundingShapes ();
	CalculateOctree ();

	finalized = true;
}
Exemple #4
0
void Mesh::CalculateNormals() {

	CalculateFaceNormals();
	CalculateVertexNormals();
}