Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/dracoenc/src/draco/io/obj_decoder.cc
| Context not available. | |||||
| #include <cmath> | #include <cmath> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include "draco/io/file_utils.h" | |||||
| #include "draco/io/parser_utils.h" | #include "draco/io/parser_utils.h" | ||||
| #include "draco/metadata/geometry_metadata.h" | #include "draco/metadata/geometry_metadata.h" | ||||
| Context not available. | |||||
| // Ensure the number of all entries is same for all attributes. | // Ensure the number of all entries is same for all attributes. | ||||
| if (num_positions_ == 0) | if (num_positions_ == 0) | ||||
| return Status(Status::ERROR, "No position attribute"); | return Status(Status::DRACO_ERROR, "No position attribute"); | ||||
| if (num_tex_coords_ > 0 && num_tex_coords_ != num_positions_) | if (num_tex_coords_ > 0 && num_tex_coords_ != num_positions_) | ||||
| return Status(Status::ERROR, | return Status(Status::DRACO_ERROR, | ||||
| "Invalid number of texture coordinates for a point cloud"); | "Invalid number of texture coordinates for a point cloud"); | ||||
| if (num_normals_ > 0 && num_normals_ != num_positions_) | if (num_normals_ > 0 && num_normals_ != num_positions_) | ||||
| return Status(Status::ERROR, | return Status(Status::DRACO_ERROR, | ||||
| "Invalid number of normals for a point cloud"); | "Invalid number of normals for a point cloud"); | ||||
| out_mesh_ = nullptr; // Treat the output geometry as a point cloud. | out_mesh_ = nullptr; // Treat the output geometry as a point cloud. | ||||
| Context not available. | |||||
| } | } | ||||
| if (num_materials_ > 0 && num_obj_faces_ > 0) { | if (num_materials_ > 0 && num_obj_faces_ > 0) { | ||||
| GeometryAttribute va; | GeometryAttribute va; | ||||
| const auto geometry_attribute_type = GeometryAttribute::GENERIC; | |||||
| if (num_materials_ < 256) { | if (num_materials_ < 256) { | ||||
| va.Init(GeometryAttribute::GENERIC, nullptr, 1, DT_UINT8, false, 1, 0); | va.Init(geometry_attribute_type, nullptr, 1, DT_UINT8, false, 1, 0); | ||||
| } else if (num_materials_ < (1 << 16)) { | } else if (num_materials_ < (1 << 16)) { | ||||
| va.Init(GeometryAttribute::GENERIC, nullptr, 1, DT_UINT16, false, 2, 0); | va.Init(geometry_attribute_type, nullptr, 1, DT_UINT16, false, 2, 0); | ||||
| } else { | } else { | ||||
| va.Init(GeometryAttribute::GENERIC, nullptr, 1, DT_UINT32, false, 4, 0); | va.Init(geometry_attribute_type, nullptr, 1, DT_UINT32, false, 4, 0); | ||||
| } | } | ||||
| material_att_id_ = | material_att_id_ = | ||||
| out_point_cloud_->AddAttribute(va, false, num_materials_); | out_point_cloud_->AddAttribute(va, false, num_materials_); | ||||
| Context not available. | |||||
| out_mesh_->SetFace(i, face); | out_mesh_->SetFace(i, face); | ||||
| } | } | ||||
| } | } | ||||
| #ifdef DRACO_ATTRIBUTE_DEDUPLICATION_SUPPORTED | |||||
| #ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED | |||||
| if (deduplicate_input_values_) { | if (deduplicate_input_values_) { | ||||
| out_point_cloud_->DeduplicateAttributeValues(); | out_point_cloud_->DeduplicateAttributeValues(); | ||||
| } | } | ||||
| #endif | |||||
| #ifdef DRACO_ATTRIBUTE_INDICES_DEDUPLICATION_SUPPORTED | |||||
| out_point_cloud_->DeduplicatePointIds(); | out_point_cloud_->DeduplicatePointIds(); | ||||
| #endif | #endif | ||||
| return status; | return status; | ||||
| Context not available. | |||||
| for (int i = 0; i < 3; ++i) { | for (int i = 0; i < 3; ++i) { | ||||
| parser::SkipWhitespace(buffer()); | parser::SkipWhitespace(buffer()); | ||||
| if (!parser::ParseFloat(buffer(), val + i)) { | if (!parser::ParseFloat(buffer(), val + i)) { | ||||
| *status = Status(Status::ERROR, "Failed to parse a float number"); | *status = Status(Status::DRACO_ERROR, "Failed to parse a float number"); | ||||
| // The definition is processed so return true. | // The definition is processed so return true. | ||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||
| for (int i = 0; i < 3; ++i) { | for (int i = 0; i < 3; ++i) { | ||||
| parser::SkipWhitespace(buffer()); | parser::SkipWhitespace(buffer()); | ||||
| if (!parser::ParseFloat(buffer(), val + i)) { | if (!parser::ParseFloat(buffer(), val + i)) { | ||||
| *status = Status(Status::ERROR, "Failed to parse a float number"); | *status = Status(Status::DRACO_ERROR, "Failed to parse a float number"); | ||||
| // The definition is processed so return true. | // The definition is processed so return true. | ||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||
| for (int i = 0; i < 2; ++i) { | for (int i = 0; i < 2; ++i) { | ||||
| parser::SkipWhitespace(buffer()); | parser::SkipWhitespace(buffer()); | ||||
| if (!parser::ParseFloat(buffer(), val + i)) { | if (!parser::ParseFloat(buffer(), val + i)) { | ||||
| *status = Status(Status::ERROR, "Failed to parse a float number"); | *status = Status(Status::DRACO_ERROR, "Failed to parse a float number"); | ||||
| // The definition is processed so return true. | // The definition is processed so return true. | ||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||
| if (i == 3) { | if (i == 3) { | ||||
| break; // It's OK if there is no fourth vertex index. | break; // It's OK if there is no fourth vertex index. | ||||
| } | } | ||||
| *status = Status(Status::ERROR, "Failed to parse vertex indices"); | *status = Status(Status::DRACO_ERROR, "Failed to parse vertex indices"); | ||||
| return true; | return true; | ||||
| } | } | ||||
| ++num_valid_indices; | ++num_valid_indices; | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| if (num_indices < 3 || num_indices > 4) { | if (num_indices < 3 || num_indices > 4) { | ||||
| *status = Status(Status::ERROR, "Invalid number of indices on a face"); | *status = | ||||
| Status(Status::DRACO_ERROR, "Invalid number of indices on a face"); | |||||
| return false; | return false; | ||||
| } | } | ||||
| // Either one or two new triangles. | // Either one or two new triangles. | ||||
| Context not available. | |||||
| parser::SkipWhitespace(&line_buffer); | parser::SkipWhitespace(&line_buffer); | ||||
| material_file_name_.clear(); | material_file_name_.clear(); | ||||
| if (!parser::ParseString(&line_buffer, &material_file_name_)) { | if (!parser::ParseString(&line_buffer, &material_file_name_)) { | ||||
| *status = Status(Status::ERROR, "Failed to parse material file name"); | *status = Status(Status::DRACO_ERROR, "Failed to parse material file name"); | ||||
| return true; | return true; | ||||
| } | } | ||||
| parser::SkipLine(&line_buffer); | parser::SkipLine(&line_buffer); | ||||
| Context not available. | |||||
| // will be added to the list. | // will be added to the list. | ||||
| last_material_id_ = num_materials_; | last_material_id_ = num_materials_; | ||||
| material_name_to_id_[mat_name] = num_materials_++; | material_name_to_id_[mat_name] = num_materials_++; | ||||
| return true; | return true; | ||||
| } | } | ||||
| last_material_id_ = it->second; | last_material_id_ = it->second; | ||||
| Context not available. | |||||
| bool ObjDecoder::ParseMaterialFile(const std::string &file_name, | bool ObjDecoder::ParseMaterialFile(const std::string &file_name, | ||||
| Status *status) { | Status *status) { | ||||
| // Get the correct path to the |file_name| using the folder from | const std::string full_path = GetFullPath(file_name, input_file_name_); | ||||
| // |input_file_name_| as the root folder. | |||||
| const auto pos = input_file_name_.find_last_of("/\\"); | |||||
| std::string full_path; | |||||
| if (pos != std::string::npos) { | |||||
| full_path = input_file_name_.substr(0, pos + 1); | |||||
| } | |||||
| full_path += file_name; | |||||
| std::ifstream file(full_path, std::ios::binary); | std::ifstream file(full_path, std::ios::binary); | ||||
| if (!file) | if (!file) | ||||
| return false; | return false; | ||||
| Context not available. | |||||
| std::string str; | std::string str; | ||||
| if (!parser::ParseString(buffer(), &str)) | if (!parser::ParseString(buffer(), &str)) | ||||
| return false; | return false; | ||||
| if (str.compare("newmtl") == 0) { | if (str == "newmtl") { | ||||
| parser::SkipWhitespace(buffer()); | parser::SkipWhitespace(buffer()); | ||||
| parser::ParseLine(buffer(), &str); | parser::ParseLine(buffer(), &str); | ||||
| if (str.length() == 0) | if (str.empty()) | ||||
| return false; | return false; | ||||
| // Add new material to our map. | // Add new material to our map. | ||||
| material_name_to_id_[str] = num_materials_++; | material_name_to_id_[str] = num_materials_++; | ||||
| } | } | ||||
| parser::SkipLine(buffer()); | |||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||