From 164c152216f75a3d9c1e9b4f367118e9a9343180 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 25 Jun 2015 20:24:24 +0900 Subject: [PATCH] Initialized a material. Add warning message to `err` when material file not found. --- tiny_obj_loader.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tiny_obj_loader.cc b/tiny_obj_loader.cc index 93218e9..3c31b02 100644 --- a/tiny_obj_loader.cc +++ b/tiny_obj_loader.cc @@ -414,7 +414,9 @@ std::string LoadMtl(std::map &material_map, std::istream &inStream) { std::stringstream err; + // Create a default material anyway. material_t material; + InitMaterial(material); int maxchars = 8192; // Alloc enough size. std::vector buf(maxchars); // Alloc enough size. @@ -623,7 +625,13 @@ std::string MaterialFileReader::operator()(const std::string &matId, } std::ifstream matIStream(filepath.c_str()); - return LoadMtl(matMap, materials, matIStream); + std::string err = LoadMtl(matMap, materials, matIStream); + if (!matIStream) { + std::stringstream ss; + ss << "WARN: Material file [ " << filepath << " ] not found. Created a default material."; + err += ss.str(); + } + return err; } std::string LoadObj(std::vector &shapes,