Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/dracoenc/src/draco/io/mesh_io.cc
| Context not available. | |||||
| #include <fstream> | #include <fstream> | ||||
| #include "draco/io/file_utils.h" | |||||
| #include "draco/io/obj_decoder.h" | #include "draco/io/obj_decoder.h" | ||||
| #include "draco/io/parser_utils.h" | |||||
| #include "draco/io/ply_decoder.h" | #include "draco/io/ply_decoder.h" | ||||
| namespace draco { | namespace draco { | ||||
| namespace { | |||||
| // Returns the file extension in lowercase if present, else "" | |||||
| inline std::string LowercaseFileExtension(const std::string &filename) { | |||||
| size_t pos = filename.find_last_of('.'); | |||||
| if (pos == std::string::npos || pos >= filename.length() - 1) | |||||
| return ""; | |||||
| return parser::ToLower(filename.substr(pos + 1)); | |||||
| } | |||||
| } // namespace | |||||
| StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name) { | StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name) { | ||||
| return ReadMeshFromFile(file_name, false); | const Options options; | ||||
| return ReadMeshFromFile(file_name, options); | |||||
| } | } | ||||
| StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name, | StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name, | ||||
| bool use_metadata) { | bool use_metadata) { | ||||
| Options options; | |||||
| options.SetBool("use_metadata", use_metadata); | |||||
| return ReadMeshFromFile(file_name, options); | |||||
| } | |||||
| StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name, | |||||
| const Options &options) { | |||||
| std::unique_ptr<Mesh> mesh(new Mesh()); | std::unique_ptr<Mesh> mesh(new Mesh()); | ||||
| // Analyze file extension. | // Analyze file extension. | ||||
| const std::string extension = LowercaseFileExtension(file_name); | const std::string extension = LowercaseFileExtension(file_name); | ||||
| if (extension == "obj") { | if (extension == "obj") { | ||||
| // Wavefront OBJ file format. | // Wavefront OBJ file format. | ||||
| ObjDecoder obj_decoder; | ObjDecoder obj_decoder; | ||||
| obj_decoder.set_use_metadata(use_metadata); | obj_decoder.set_use_metadata(options.GetBool("use_metadata", false)); | ||||
| const Status obj_status = obj_decoder.DecodeFromFile(file_name, mesh.get()); | const Status obj_status = obj_decoder.DecodeFromFile(file_name, mesh.get()); | ||||
| if (!obj_status.ok()) | if (!obj_status.ok()) | ||||
| return obj_status; | return obj_status; | ||||
| Context not available. | |||||
| if (extension == "ply") { | if (extension == "ply") { | ||||
| // Wavefront PLY file format. | // Wavefront PLY file format. | ||||
| PlyDecoder ply_decoder; | PlyDecoder ply_decoder; | ||||
| if (!ply_decoder.DecodeFromFile(file_name, mesh.get())) | DRACO_RETURN_IF_ERROR(ply_decoder.DecodeFromFile(file_name, mesh.get())); | ||||
| return Status(Status::ERROR, "Unknown error."); | |||||
| return std::move(mesh); | return std::move(mesh); | ||||
| } | } | ||||
| Context not available. | |||||
| // draco encoding methods. | // draco encoding methods. | ||||
| std::ifstream is(file_name.c_str(), std::ios::binary); | std::ifstream is(file_name.c_str(), std::ios::binary); | ||||
| if (!is) | if (!is) | ||||
| return Status(Status::ERROR, "Invalid input stream."); | return Status(Status::DRACO_ERROR, "Invalid input stream."); | ||||
| if (!ReadMeshFromStream(&mesh, is).good()) | if (!ReadMeshFromStream(&mesh, is).good()) | ||||
| return Status(Status::ERROR, | return Status(Status::DRACO_ERROR, | ||||
| "Unknown error."); // Error reading the stream. | "Unknown error."); // Error reading the stream. | ||||
| return std::move(mesh); | return std::move(mesh); | ||||
| } | } | ||||
| Context not available. | |||||