Cleanup: IO: Use CLOG and fmtlib for tracing OBJ/PLY/STL messages
OBJ, PLY, and STL used a mix of fprintf, std::cout, and std::cerr to trace warnings, errors, and general messages to the console. Now, we instead use CLOG which provides real facilities for warnings and errors and generally removes the need to pull in and use the heavy `<iostream>` machinery. For traces that should always be printed, `fmt::print` is used since CLOG currently doesn't provide that particular level of trace. Tests were only minimally changed to drop usage of streams while keeping their prior usage of older stdio APIs. We can change to using fmtlib there too if desired. Pull Request: https://projects.blender.org/blender/blender/pulls/130107
This commit is contained in:
committed by
Jesse Yurkovich
parent
de187f7877
commit
c9c2fbc52d
@@ -54,6 +54,7 @@ set(LIB
|
||||
PRIVATE bf::blenlib
|
||||
PRIVATE bf::depsgraph
|
||||
PRIVATE bf::dna
|
||||
PRIVATE bf::intern::clog
|
||||
PRIVATE bf::intern::guardedalloc
|
||||
bf_io_common
|
||||
PRIVATE bf::extern::fmtlib
|
||||
|
||||
@@ -6,10 +6,9 @@
|
||||
* \ingroup ply
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include "BLI_timeit.hh"
|
||||
|
||||
#include "DNA_windowmanager_types.h"
|
||||
#include "IO_ply.hh"
|
||||
#include "ply_export.hh"
|
||||
@@ -20,9 +19,9 @@ using namespace blender::timeit;
|
||||
static void report_duration(const char *job, const TimePoint &start_time, const char *path)
|
||||
{
|
||||
Nanoseconds duration = Clock::now() - start_time;
|
||||
std::cout << "PLY " << job << " of '" << BLI_path_basename(path) << "' took ";
|
||||
fmt::print("PLY {} of '{}' took ", job, BLI_path_basename(path));
|
||||
print_duration(duration);
|
||||
std::cout << '\n';
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
void PLY_export(bContext *C, const PLYExportParams *export_params)
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
* \ingroup ply
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "BKE_context.hh"
|
||||
#include "BKE_lib_id.hh"
|
||||
#include "BKE_report.hh"
|
||||
@@ -25,6 +23,9 @@
|
||||
#include "ply_file_buffer_ascii.hh"
|
||||
#include "ply_file_buffer_binary.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.ply"};
|
||||
|
||||
namespace blender::io::ply {
|
||||
|
||||
void exporter_main(bContext *C, const PLYExportParams &export_params)
|
||||
@@ -75,7 +76,7 @@ void exporter_main(bContext *C, const PLYExportParams &export_params)
|
||||
}
|
||||
}
|
||||
catch (const std::system_error &ex) {
|
||||
fprintf(stderr, "%s\n", ex.what());
|
||||
CLOG_ERROR(&LOG, "[%s] %s", ex.code().category().name(), ex.what());
|
||||
BKE_reportf(export_params.reports,
|
||||
RPT_ERROR,
|
||||
"PLY Export: Cannot open file '%s'",
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
|
||||
#include "BLI_fileops.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <system_error>
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.ply"};
|
||||
|
||||
namespace blender::io::ply {
|
||||
|
||||
FileBuffer::FileBuffer(const char *filepath, size_t buffer_chunk_size)
|
||||
@@ -40,8 +42,7 @@ void FileBuffer::close_file()
|
||||
return;
|
||||
}
|
||||
if (outfile_ && close_status) {
|
||||
std::cerr << "Error: could not close the file '" << this->filepath_
|
||||
<< "' properly, it may be corrupted." << std::endl;
|
||||
CLOG_ERROR(&LOG, "Error: could not close file '%s' properly, it may be corrupted.", filepath_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include "ply_import_data.hh"
|
||||
#include "ply_import_mesh.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.ply"};
|
||||
|
||||
namespace blender::io::ply {
|
||||
|
||||
/* If line starts with keyword, returns true and drops it from the line. */
|
||||
@@ -169,7 +172,7 @@ static Mesh *read_ply_to_mesh(const PLYImportParams &import_params, const char *
|
||||
PlyHeader header;
|
||||
const char *err = read_header(file, header);
|
||||
if (err != nullptr) {
|
||||
fprintf(stderr, "PLY Importer: %s: %s\n", ob_name, err);
|
||||
CLOG_ERROR(&LOG, "PLY Importer: %s: %s", ob_name, err);
|
||||
BKE_reportf(import_params.reports, RPT_ERROR, "PLY Importer: %s: %s", ob_name, err);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -177,17 +180,17 @@ static Mesh *read_ply_to_mesh(const PLYImportParams &import_params, const char *
|
||||
/* Parse actual file data. */
|
||||
std::unique_ptr<PlyData> data = import_ply_data(file, header);
|
||||
if (data == nullptr) {
|
||||
fprintf(stderr, "PLY Importer: failed importing %s, unknown error\n", ob_name);
|
||||
CLOG_ERROR(&LOG, "PLY Importer: failed importing %s, unknown error", ob_name);
|
||||
BKE_report(import_params.reports, RPT_ERROR, "PLY Importer: failed importing, unknown error");
|
||||
return nullptr;
|
||||
}
|
||||
if (!data->error.empty()) {
|
||||
fprintf(stderr, "PLY Importer: failed importing %s: %s\n", ob_name, data->error.c_str());
|
||||
CLOG_ERROR(&LOG, "PLY Importer: failed importing %s: %s", ob_name, data->error.c_str());
|
||||
BKE_report(import_params.reports, RPT_ERROR, "PLY Importer: failed importing, unknown error");
|
||||
return nullptr;
|
||||
}
|
||||
if (data->vertices.is_empty()) {
|
||||
fprintf(stderr, "PLY Importer: file %s contains no vertices\n", ob_name);
|
||||
CLOG_ERROR(&LOG, "PLY Importer: file %s contains no vertices", ob_name);
|
||||
BKE_report(import_params.reports, RPT_ERROR, "PLY Importer: failed importing, no vertices");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
#include <charconv>
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.ply"};
|
||||
|
||||
static bool is_whitespace(char c)
|
||||
{
|
||||
return c <= ' ';
|
||||
@@ -440,7 +443,7 @@ static const char *load_face_element(PlyReadBuffer &file,
|
||||
/* Previous python based importer was accepting faces with fewer
|
||||
* than 3 vertices, and silently dropping them. */
|
||||
if (count < 3) {
|
||||
fprintf(stderr, "PLY Importer: ignoring face %i (%i vertices)\n", i, count);
|
||||
CLOG_WARN(&LOG, "PLY Importer: ignoring face %i (%i vertices)", i, count);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -476,7 +479,7 @@ static const char *load_face_element(PlyReadBuffer &file,
|
||||
/* Previous python based importer was accepting faces with fewer
|
||||
* than 3 vertices, and silently dropping them. */
|
||||
if (count < 3) {
|
||||
fprintf(stderr, "PLY Importer: ignoring face %i (%i vertices)\n", i, int(count));
|
||||
CLOG_WARN(&LOG, "PLY Importer: ignoring face %i (%i vertices)", i, count);
|
||||
}
|
||||
else {
|
||||
ptr = scratch.data();
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
#include "ply_import_mesh.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.ply"};
|
||||
|
||||
namespace blender::io::ply {
|
||||
Mesh *convert_ply_to_mesh(PlyData &data, const PLYImportParams ¶ms)
|
||||
{
|
||||
@@ -35,11 +38,11 @@ Mesh *convert_ply_to_mesh(PlyData &data, const PLYImportParams ¶ms)
|
||||
int32_t v1 = data.edges[i].first;
|
||||
int32_t v2 = data.edges[i].second;
|
||||
if (v1 >= mesh->verts_num) {
|
||||
fprintf(stderr, "Invalid PLY vertex index in edge %i/1: %d\n", i, v1);
|
||||
CLOG_WARN(&LOG, "Invalid PLY vertex index in edge %i/1: %d", i, v1);
|
||||
v1 = 0;
|
||||
}
|
||||
if (v2 >= mesh->verts_num) {
|
||||
fprintf(stderr, "Invalid PLY vertex index in edge %i/2: %d\n", i, v2);
|
||||
CLOG_WARN(&LOG, "Invalid PLY vertex index in edge %i/2: %d", i, v2);
|
||||
v2 = 0;
|
||||
}
|
||||
edges[i] = {v1, v2};
|
||||
@@ -59,7 +62,7 @@ Mesh *convert_ply_to_mesh(PlyData &data, const PLYImportParams ¶ms)
|
||||
for (int j = 0; j < size; j++) {
|
||||
uint32_t v = data.face_vertices[offset + j];
|
||||
if (v >= mesh->verts_num) {
|
||||
fprintf(stderr, "Invalid PLY vertex index in face %i loop %i: %u\n", i, j, v);
|
||||
CLOG_WARN(&LOG, "Invalid PLY vertex index in face %i loop %i: %u", i, j, v);
|
||||
v = 0;
|
||||
}
|
||||
corner_verts[offset + j] = data.face_vertices[offset + j];
|
||||
|
||||
@@ -44,6 +44,7 @@ set(LIB
|
||||
PRIVATE bf::blenlib
|
||||
PRIVATE bf::depsgraph
|
||||
PRIVATE bf::dna
|
||||
PRIVATE bf::intern::clog
|
||||
PRIVATE bf::intern::guardedalloc
|
||||
bf_io_common
|
||||
PRIVATE bf::extern::fmtlib
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* \ingroup stl
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
||||
#include "BKE_context.hh"
|
||||
@@ -35,6 +34,9 @@
|
||||
#include "stl_export.hh"
|
||||
#include "stl_export_writer.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.stl"};
|
||||
|
||||
namespace blender::io::stl {
|
||||
|
||||
void export_frame(Depsgraph *depsgraph,
|
||||
@@ -49,7 +51,7 @@ void export_frame(Depsgraph *depsgraph,
|
||||
writer = std::make_unique<FileWriter>(export_params.filepath, export_params.ascii_format);
|
||||
}
|
||||
catch (const std::runtime_error &ex) {
|
||||
fprintf(stderr, "%s\n", ex.what());
|
||||
CLOG_ERROR(&LOG, "Error: %s", ex.what());
|
||||
BKE_reportf(export_params.reports,
|
||||
RPT_ERROR,
|
||||
"STL Export: Cannot open file '%s'",
|
||||
@@ -103,7 +105,7 @@ void export_frame(Depsgraph *depsgraph,
|
||||
writer = std::make_unique<FileWriter>(filepath, export_params.ascii_format);
|
||||
}
|
||||
catch (const std::runtime_error &ex) {
|
||||
fprintf(stderr, "%s\n", ex.what());
|
||||
CLOG_ERROR(&LOG, "Error: %s", ex.what());
|
||||
BKE_reportf(
|
||||
export_params.reports, RPT_ERROR, "STL Export: Cannot open file '%s'", filepath);
|
||||
return;
|
||||
|
||||
@@ -34,13 +34,16 @@
|
||||
#include "stl_import_ascii_reader.hh"
|
||||
#include "stl_import_binary_reader.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.stl"};
|
||||
|
||||
namespace blender::io::stl {
|
||||
|
||||
void stl_import_report_error(FILE *file)
|
||||
{
|
||||
fprintf(stderr, "STL Importer: failed to read file");
|
||||
CLOG_ERROR(&LOG, "STL Importer: failed to read file");
|
||||
if (feof(file)) {
|
||||
fprintf(stderr, ", end of file reached.\n");
|
||||
CLOG_ERROR(&LOG, "End of file reached");
|
||||
}
|
||||
else if (ferror(file)) {
|
||||
perror("Error");
|
||||
@@ -51,7 +54,7 @@ Mesh *read_stl_file(const STLImportParams &import_params)
|
||||
{
|
||||
FILE *file = BLI_fopen(import_params.filepath, "rb");
|
||||
if (!file) {
|
||||
fprintf(stderr, "Failed to open STL file:'%s'.\n", import_params.filepath);
|
||||
CLOG_ERROR(&LOG, "Failed to open STL file:'%s'.\n", import_params.filepath);
|
||||
BKE_reportf(import_params.reports,
|
||||
RPT_ERROR,
|
||||
"STL Import: Cannot open file '%s'",
|
||||
@@ -82,7 +85,7 @@ Mesh *read_stl_file(const STLImportParams &import_params)
|
||||
read_stl_binary(file, import_params.use_facet_normal);
|
||||
|
||||
if (mesh == nullptr) {
|
||||
fprintf(stderr, "STL Importer: Failed to import mesh '%s'\n", import_params.filepath);
|
||||
CLOG_ERROR(&LOG, "STL Importer: Failed to import mesh '%s'", import_params.filepath);
|
||||
BKE_reportf(import_params.reports,
|
||||
RPT_ERROR,
|
||||
"STL Import: Failed to import mesh from file '%s'",
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* \ingroup stl
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <system_error>
|
||||
|
||||
#include "BLI_fileops.hh"
|
||||
@@ -27,6 +26,9 @@
|
||||
#include "stl_import_ascii_reader.hh"
|
||||
#include "stl_import_mesh.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.stl"};
|
||||
|
||||
namespace blender::io::stl {
|
||||
|
||||
class StringBuffer {
|
||||
@@ -116,7 +118,7 @@ Mesh *read_stl_ascii(const char *filepath, const bool use_custom_normals)
|
||||
size_t buffer_len;
|
||||
void *buffer = BLI_file_read_text_as_mem(filepath, 0, &buffer_len);
|
||||
if (buffer == nullptr) {
|
||||
fprintf(stderr, "STL Importer: cannot read from ASCII STL file: '%s'\n", filepath);
|
||||
CLOG_ERROR(&LOG, "STL Importer: cannot read from ASCII STL file: '%s'", filepath);
|
||||
return nullptr;
|
||||
}
|
||||
BLI_SCOPED_DEFER([&]() { MEM_freeN(buffer); });
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
* \ingroup stl
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "BKE_mesh.hh"
|
||||
|
||||
#include "BLI_array_utils.hh"
|
||||
@@ -18,6 +16,9 @@
|
||||
#include "stl_data.hh"
|
||||
#include "stl_import_mesh.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.stl"};
|
||||
|
||||
namespace blender::io::stl {
|
||||
|
||||
STLMeshHelper::STLMeshHelper(int tris_num, bool use_custom_normals)
|
||||
@@ -56,12 +57,10 @@ bool STLMeshHelper::add_triangle(const PackedTriangle &data)
|
||||
Mesh *STLMeshHelper::to_mesh()
|
||||
{
|
||||
if (degenerate_tris_num_ > 0) {
|
||||
std::cout << "STL Importer: " << degenerate_tris_num_ << " degenerate triangles were removed"
|
||||
<< std::endl;
|
||||
CLOG_WARN(&LOG, "Removed %d degenerate triangles during import", degenerate_tris_num_);
|
||||
}
|
||||
if (duplicate_tris_num_ > 0) {
|
||||
std::cout << "STL Importer: " << duplicate_tris_num_ << " duplicate triangles were removed"
|
||||
<< std::endl;
|
||||
CLOG_WARN(&LOG, "Removed %d duplicate triangles during import", duplicate_tris_num_);
|
||||
}
|
||||
|
||||
Mesh *mesh = BKE_mesh_new_nomain(verts_.size(), 0, tris_.size(), tris_.size() * 3);
|
||||
|
||||
@@ -57,6 +57,7 @@ set(LIB
|
||||
PRIVATE bf::blenlib
|
||||
PRIVATE bf::depsgraph
|
||||
PRIVATE bf::dna
|
||||
PRIVATE bf::intern::clog
|
||||
PRIVATE bf::intern::guardedalloc
|
||||
bf_io_common
|
||||
PRIVATE bf::extern::fmtlib
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
* \ingroup obj
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "BLI_path_utils.hh"
|
||||
#include "BLI_timeit.hh"
|
||||
|
||||
@@ -16,14 +14,16 @@
|
||||
#include "obj_exporter.hh"
|
||||
#include "obj_importer.hh"
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
using namespace blender::timeit;
|
||||
|
||||
static void report_duration(const char *job, const TimePoint &start_time, const char *path)
|
||||
{
|
||||
Nanoseconds duration = Clock::now() - start_time;
|
||||
std::cout << "OBJ " << job << " of '" << BLI_path_basename(path) << "' took ";
|
||||
fmt::print("OBJ {} of '{}' took ", job, BLI_path_basename(path));
|
||||
print_duration(duration);
|
||||
std::cout << '\n';
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
void OBJ_export(bContext *C, const OBJExportParams *export_params)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <system_error>
|
||||
|
||||
#include "BKE_attribute.hh"
|
||||
#include "BKE_blender_version.h"
|
||||
@@ -28,6 +28,9 @@
|
||||
|
||||
#include "obj_export_file_writer.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.obj"};
|
||||
|
||||
namespace blender::io::obj {
|
||||
/**
|
||||
* Per reference http://www.martinreddy.net/gfx/3d/OBJ.spec:
|
||||
@@ -49,6 +52,23 @@ static const char *DEFORM_GROUP_DISABLED = "off";
|
||||
* So an empty material name is written. */
|
||||
static const char *MATERIAL_GROUP_DISABLED = "";
|
||||
|
||||
OBJWriter::OBJWriter(const char *filepath, const OBJExportParams &export_params) noexcept(false)
|
||||
: export_params_(export_params), outfile_path_(filepath), outfile_(nullptr)
|
||||
{
|
||||
outfile_ = BLI_fopen(filepath, "wb");
|
||||
if (!outfile_) {
|
||||
throw std::system_error(errno, std::system_category(), "Cannot open file " + outfile_path_);
|
||||
}
|
||||
}
|
||||
OBJWriter::~OBJWriter()
|
||||
{
|
||||
if (outfile_ && std::fclose(outfile_)) {
|
||||
CLOG_ERROR(&LOG,
|
||||
"Error: could not close file '%s' properly, it may be corrupted.",
|
||||
outfile_path_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void OBJWriter::write_vert_uv_normal_indices(FormatHandler &fh,
|
||||
const IndexOffsets &offsets,
|
||||
Span<int> vert_indices,
|
||||
@@ -527,10 +547,8 @@ BLI_STATIC_ASSERT(ARRAY_SIZE(tex_map_type_to_string) == int(MTLTexMapType::Count
|
||||
*/
|
||||
static std::string float3_to_string(const float3 &numbers)
|
||||
{
|
||||
std::ostringstream r_string;
|
||||
r_string << numbers[0] << " " << numbers[1] << " " << numbers[2];
|
||||
return r_string.str();
|
||||
};
|
||||
return fmt::format("{} {} {}", numbers[0], numbers[1], numbers[2]);
|
||||
}
|
||||
|
||||
MTLWriter::MTLWriter(const char *obj_filepath, bool write_file) noexcept(false)
|
||||
{
|
||||
@@ -556,8 +574,9 @@ MTLWriter::~MTLWriter()
|
||||
if (outfile_) {
|
||||
fmt_handler_.write_to_file(outfile_);
|
||||
if (std::fclose(outfile_)) {
|
||||
std::cerr << "Error: could not close the file '" << mtl_filepath_
|
||||
<< "' properly, it may be corrupted." << std::endl;
|
||||
CLOG_ERROR(&LOG,
|
||||
"Error: could not close file '%s' properly, it may be corrupted.",
|
||||
mtl_filepath_.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
#include "obj_export_io.hh"
|
||||
#include "obj_export_mtl.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace blender::io::obj {
|
||||
|
||||
class OBJCurve;
|
||||
@@ -42,21 +40,8 @@ class OBJWriter : NonMovable, NonCopyable {
|
||||
FILE *outfile_;
|
||||
|
||||
public:
|
||||
OBJWriter(const char *filepath, const OBJExportParams &export_params) noexcept(false)
|
||||
: export_params_(export_params), outfile_path_(filepath), outfile_(nullptr)
|
||||
{
|
||||
outfile_ = BLI_fopen(filepath, "wb");
|
||||
if (!outfile_) {
|
||||
throw std::system_error(errno, std::system_category(), "Cannot open file " + outfile_path_);
|
||||
}
|
||||
}
|
||||
~OBJWriter()
|
||||
{
|
||||
if (outfile_ && std::fclose(outfile_)) {
|
||||
std::cerr << "Error: could not close the file '" << outfile_path_
|
||||
<< "' properly, it may be corrupted." << std::endl;
|
||||
}
|
||||
}
|
||||
OBJWriter(const char *filepath, const OBJExportParams &export_params) noexcept(false);
|
||||
~OBJWriter();
|
||||
|
||||
FILE *get_outfile() const
|
||||
{
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "BKE_node.hh"
|
||||
#include "BKE_node_runtime.hh"
|
||||
|
||||
#include "BLI_map.hh"
|
||||
#include "BLI_math_vector.h"
|
||||
#include "BLI_math_vector.hh"
|
||||
#include "BLI_path_utils.hh"
|
||||
@@ -22,6 +21,9 @@
|
||||
#include "obj_export_mesh.hh"
|
||||
#include "obj_export_mtl.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.obj"};
|
||||
|
||||
namespace blender::io::obj {
|
||||
|
||||
const char *tex_map_type_to_socket_id[] = {
|
||||
@@ -145,10 +147,11 @@ static std::string get_image_filepath(const bNode *tex_node)
|
||||
if (BKE_image_has_packedfile(tex_image)) {
|
||||
/* Put image in the same directory as the `.MTL` file. */
|
||||
const char *filename = BLI_path_basename(tex_image->filepath);
|
||||
fprintf(stderr,
|
||||
"Packed image found:'%s'. Unpack and place the image in the same "
|
||||
"directory as the .MTL file.\n",
|
||||
filename);
|
||||
CLOG_INFO(&LOG,
|
||||
1,
|
||||
"Packed image found:'%s'. Unpack and place the image in the same "
|
||||
"directory as the .MTL file.",
|
||||
filename);
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
|
||||
#include "obj_export_file_writer.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.obj"};
|
||||
|
||||
namespace blender::io::obj {
|
||||
|
||||
OBJDepsgraph::OBJDepsgraph(const bContext *C,
|
||||
@@ -81,8 +84,7 @@ void OBJDepsgraph::update_for_newframe()
|
||||
|
||||
static void print_exception_error(const std::system_error &ex)
|
||||
{
|
||||
std::cerr << ex.code().category().name() << ": " << ex.what() << ": " << ex.code().message()
|
||||
<< std::endl;
|
||||
CLOG_ERROR(&LOG, "[%s] %s", ex.code().category().name(), ex.what());
|
||||
}
|
||||
|
||||
static bool is_curve_nurbs_compatible(const Nurb *nurb)
|
||||
@@ -355,7 +357,7 @@ void exporter_main(bContext *C, const OBJExportParams &export_params)
|
||||
|
||||
/* Single frame export, i.e. no animation. */
|
||||
if (!export_params.export_animation) {
|
||||
fprintf(stderr, "Writing to %s\n", filepath);
|
||||
fmt::println("Writing to {}", filepath);
|
||||
export_frame(obj_depsgraph.get(), export_params, filepath);
|
||||
return;
|
||||
}
|
||||
@@ -367,13 +369,13 @@ void exporter_main(bContext *C, const OBJExportParams &export_params)
|
||||
for (int frame = export_params.start_frame; frame <= export_params.end_frame; frame++) {
|
||||
const bool filepath_ok = append_frame_to_filename(filepath, frame, filepath_with_frames);
|
||||
if (!filepath_ok) {
|
||||
fprintf(stderr, "Error: File Path too long.\n%s\n", filepath_with_frames);
|
||||
CLOG_ERROR(&LOG, "File Path too long: %s", filepath_with_frames);
|
||||
return;
|
||||
}
|
||||
|
||||
scene->r.cfra = frame;
|
||||
obj_depsgraph.update_for_newframe();
|
||||
fprintf(stderr, "Writing to %s\n", filepath_with_frames);
|
||||
fmt::println("Writing to {}", filepath_with_frames);
|
||||
export_frame(obj_depsgraph.get(), export_params, filepath_with_frames);
|
||||
}
|
||||
scene->r.cfra = original_frame;
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
#include <iostream>
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.obj"};
|
||||
|
||||
namespace blender::io::obj {
|
||||
|
||||
@@ -152,7 +154,7 @@ static const char *parse_vertex_index(const char *p, const char *end, size_t n_e
|
||||
if (r_index != INT32_MAX) {
|
||||
r_index += r_index < 0 ? n_elems : -1;
|
||||
if (r_index < 0 || r_index >= n_elems) {
|
||||
fprintf(stderr, "Invalid vertex index %i (valid range [0, %zu))\n", r_index, n_elems);
|
||||
CLOG_WARN(&LOG, "Invalid vertex index %i (valid range [0, %zu))", r_index, n_elems);
|
||||
r_index = INT32_MAX;
|
||||
}
|
||||
}
|
||||
@@ -178,7 +180,7 @@ static void geom_add_polyline(Geometry *geom,
|
||||
p = parse_vertex_index(p, end, r_global_vertices.vertices.size(), last_vertex_index);
|
||||
|
||||
if (last_vertex_index == INT32_MAX) {
|
||||
fprintf(stderr, "Skipping invalid OBJ polyline.\n");
|
||||
CLOG_WARN(&LOG, "Skipping invalid OBJ polyline.");
|
||||
return;
|
||||
}
|
||||
geom->track_vertex_index(last_vertex_index);
|
||||
@@ -252,10 +254,10 @@ static void geom_add_polygon(Geometry *geom,
|
||||
/* Always keep stored indices non-negative and zero-based. */
|
||||
corner.vert_index += corner.vert_index < 0 ? global_vertices.vertices.size() : -1;
|
||||
if (corner.vert_index < 0 || corner.vert_index >= global_vertices.vertices.size()) {
|
||||
fprintf(stderr,
|
||||
"Invalid vertex index %i (valid range [0, %zu)), ignoring face\n",
|
||||
corner.vert_index,
|
||||
size_t(global_vertices.vertices.size()));
|
||||
CLOG_WARN(&LOG,
|
||||
"Invalid vertex index %i (valid range [0, %zu)), ignoring face",
|
||||
corner.vert_index,
|
||||
size_t(global_vertices.vertices.size()));
|
||||
face_valid = false;
|
||||
}
|
||||
else {
|
||||
@@ -265,10 +267,10 @@ static void geom_add_polygon(Geometry *geom,
|
||||
if (got_uv && !global_vertices.uv_vertices.is_empty()) {
|
||||
corner.uv_vert_index += corner.uv_vert_index < 0 ? global_vertices.uv_vertices.size() : -1;
|
||||
if (corner.uv_vert_index < 0 || corner.uv_vert_index >= global_vertices.uv_vertices.size()) {
|
||||
fprintf(stderr,
|
||||
"Invalid UV index %i (valid range [0, %zu)), ignoring face\n",
|
||||
corner.uv_vert_index,
|
||||
size_t(global_vertices.uv_vertices.size()));
|
||||
CLOG_WARN(&LOG,
|
||||
"Invalid UV index %i (valid range [0, %zu)), ignoring face",
|
||||
corner.uv_vert_index,
|
||||
size_t(global_vertices.uv_vertices.size()));
|
||||
face_valid = false;
|
||||
}
|
||||
}
|
||||
@@ -282,10 +284,10 @@ static void geom_add_polygon(Geometry *geom,
|
||||
if (corner.vertex_normal_index < 0 ||
|
||||
corner.vertex_normal_index >= global_vertices.vert_normals.size())
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Invalid normal index %i (valid range [0, %zu)), ignoring face\n",
|
||||
corner.vertex_normal_index,
|
||||
size_t(global_vertices.vert_normals.size()));
|
||||
CLOG_WARN(&LOG,
|
||||
"Invalid normal index %i (valid range [0, %zu)), ignoring face",
|
||||
corner.vertex_normal_index,
|
||||
size_t(global_vertices.vert_normals.size()));
|
||||
face_valid = false;
|
||||
}
|
||||
}
|
||||
@@ -317,7 +319,7 @@ static Geometry *geom_set_curve_type(Geometry *geom,
|
||||
{
|
||||
p = drop_whitespace(p, end);
|
||||
if (!StringRef(p, end).startswith("bspline")) {
|
||||
std::cerr << "Curve type not supported: '" << std::string(p, end) << "'" << std::endl;
|
||||
CLOG_WARN(&LOG, "Curve type not supported: '%s'", std::string(p, end).c_str());
|
||||
return geom;
|
||||
}
|
||||
geom = create_geometry(geom, GEOM_CURVE, group_name, r_all_geometries);
|
||||
@@ -354,11 +356,11 @@ static void geom_add_curve_parameters(Geometry *geom, const char *p, const char
|
||||
{
|
||||
p = drop_whitespace(p, end);
|
||||
if (p == end) {
|
||||
std::cerr << "Invalid OBJ curve parm line" << std::endl;
|
||||
CLOG_ERROR(&LOG, "Invalid OBJ curve parm line");
|
||||
return;
|
||||
}
|
||||
if (*p != 'u') {
|
||||
std::cerr << "OBJ curve surfaces are not supported: '" << *p << "'" << std::endl;
|
||||
CLOG_WARN(&LOG, "OBJ curve surfaces are not supported, found '%c'", *p);
|
||||
return;
|
||||
}
|
||||
++p;
|
||||
@@ -370,7 +372,7 @@ static void geom_add_curve_parameters(Geometry *geom, const char *p, const char
|
||||
geom->nurbs_element_.parm.append(val);
|
||||
}
|
||||
else {
|
||||
std::cerr << "OBJ curve parm line has invalid number" << std::endl;
|
||||
CLOG_ERROR(&LOG, "OBJ curve parm line has invalid number");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -426,7 +428,7 @@ OBJParser::OBJParser(const OBJImportParams &import_params, size_t read_buffer_si
|
||||
{
|
||||
obj_file_ = BLI_fopen(import_params_.filepath, "rb");
|
||||
if (!obj_file_) {
|
||||
fprintf(stderr, "Cannot read from OBJ file:'%s'.\n", import_params_.filepath);
|
||||
CLOG_ERROR(&LOG, "Cannot read from OBJ file:'%s'.\n", import_params_.filepath);
|
||||
BKE_reportf(import_params_.reports,
|
||||
RPT_ERROR,
|
||||
"OBJ Import: Cannot open file '%s'",
|
||||
@@ -540,10 +542,10 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
|
||||
}
|
||||
if (buffer[last_nl] != '\n') {
|
||||
/* Whole line did not fit into our read buffer. Warn and exit. */
|
||||
fprintf(stderr,
|
||||
"OBJ file contains a line #%zu that is too long (max. length %zu)\n",
|
||||
line_number,
|
||||
read_buffer_size_);
|
||||
CLOG_ERROR(&LOG,
|
||||
"OBJ file contains a line #%zu that is too long (max. length %zu)",
|
||||
line_number,
|
||||
read_buffer_size_);
|
||||
break;
|
||||
}
|
||||
++last_nl;
|
||||
@@ -668,7 +670,7 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
|
||||
/* End of curve definition, nothing else to do. */
|
||||
}
|
||||
else {
|
||||
std::cout << "OBJ element not recognized: '" << std::string(p, end) << "'" << std::endl;
|
||||
CLOG_WARN(&LOG, "OBJ element not recognized: '%s'", std::string(p, end).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -757,8 +759,9 @@ static bool parse_texture_option(const char *&p,
|
||||
tex_map.projection_type = SHD_PROJ_SPHERE;
|
||||
const StringRef line = StringRef(p, end);
|
||||
if (!line.startswith("sphere")) {
|
||||
std::cerr << "OBJ import: only sphere MTL projection type is supported: '" << line << "'"
|
||||
<< std::endl;
|
||||
CLOG_WARN(&LOG,
|
||||
"Only the 'sphere' MTL projection type is supported, found: '%s'",
|
||||
std::string(line).c_str());
|
||||
}
|
||||
p = drop_non_whitespace(p, end);
|
||||
return true;
|
||||
@@ -793,7 +796,7 @@ static void parse_texture_map(const char *p,
|
||||
MTLTexMapType key = mtl_line_start_to_texture_type(p, end);
|
||||
if (key == MTLTexMapType::Count) {
|
||||
/* No supported texture map found. */
|
||||
std::cerr << "OBJ import: MTL texture map type not supported: '" << line << "'" << std::endl;
|
||||
CLOG_WARN(&LOG, "MTL texture map type not supported: '%s'", std::string(line).c_str());
|
||||
return;
|
||||
}
|
||||
MTLTexMap &tex_map = material->tex_map_of_type(key);
|
||||
@@ -854,7 +857,7 @@ void MTLParser::parse_and_store(Map<string, std::unique_ptr<MTLMaterial>> &r_mat
|
||||
size_t buffer_len;
|
||||
void *buffer = BLI_file_read_text_as_mem(mtl_file_path_, 0, &buffer_len);
|
||||
if (buffer == nullptr) {
|
||||
fprintf(stderr, "OBJ import: cannot read from MTL file: '%s'\n", mtl_file_path_);
|
||||
CLOG_ERROR(&LOG, "OBJ import: cannot read from MTL file: '%s'", mtl_file_path_);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
* \ingroup obj
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "DNA_customdata_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
@@ -29,6 +27,9 @@
|
||||
#include "obj_export_mtl.hh"
|
||||
#include "obj_import_mesh.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.obj"};
|
||||
|
||||
namespace blender::io::obj {
|
||||
|
||||
Mesh *MeshFromGeometry::create_mesh(const OBJImportParams &import_params)
|
||||
@@ -223,7 +224,7 @@ void MeshFromGeometry::create_faces(Mesh *mesh, bool use_vertex_groups)
|
||||
const FaceElem &curr_face = mesh_geometry_.face_elements_[face_idx];
|
||||
if (curr_face.corner_count_ < 3) {
|
||||
/* Don't add single vertex face, or edges. */
|
||||
std::cerr << "Face with less than 3 vertices found, skipping." << std::endl;
|
||||
CLOG_WARN(&LOG, "Face with less than 3 vertices found, skipping.");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
#include "obj_export_mtl.hh"
|
||||
#include "obj_import_mtl.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include "CLG_log.h"
|
||||
static CLG_LogRef LOG = {"io.obj"};
|
||||
|
||||
namespace blender::io::obj {
|
||||
|
||||
@@ -68,10 +69,10 @@ static Image *load_image_at_path(Main *bmain, const std::string &path, bool rela
|
||||
{
|
||||
Image *image = BKE_image_load_exists(bmain, path.c_str());
|
||||
if (!image) {
|
||||
fprintf(stderr, "Cannot load image file: '%s'\n", path.c_str());
|
||||
CLOG_WARN(&LOG, "Cannot load image file: '%s'", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
fprintf(stderr, "Loaded image from: '%s'\n", path.c_str());
|
||||
CLOG_INFO(&LOG, 1, "Loaded image from: '%s'", path.c_str());
|
||||
if (relative_paths) {
|
||||
BLI_path_rel(image->filepath, BKE_main_blendfile_path(bmain));
|
||||
}
|
||||
@@ -233,8 +234,9 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
std::cerr << "Warning! illum value = " << illum
|
||||
<< "is not supported by the Principled-BSDF shader." << std::endl;
|
||||
CLOG_WARN(&LOG,
|
||||
"Material illum value '%d' is not supported by the Principled BSDF shader.",
|
||||
illum);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 */
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ios>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
@@ -16,9 +15,7 @@
|
||||
#include "BKE_main.hh"
|
||||
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_index_range.hh"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_string_utf8.h"
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include "BLO_readfile.hh"
|
||||
@@ -168,8 +165,7 @@ class ObjExporterWriterTest : public testing::Test {
|
||||
return writer;
|
||||
}
|
||||
catch (const std::system_error &ex) {
|
||||
std::cerr << ex.code().category().name() << ": " << ex.what() << ": " << ex.code().message()
|
||||
<< std::endl;
|
||||
fprintf(stderr, "[%s] %s\n", ex.code().category().name(), ex.what());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -251,15 +247,15 @@ static bool strings_equal_after_first_lines(const std::string &a, const std::str
|
||||
const size_t a_next = a.find_first_of('\n');
|
||||
const size_t b_next = b.find_first_of('\n');
|
||||
if (a_next == std::string::npos || b_next == std::string::npos) {
|
||||
std::cout << "Couldn't find newline in one of args\n";
|
||||
printf("Couldn't find newline in one of args\n");
|
||||
return false;
|
||||
}
|
||||
if (a.compare(a_next, a_len - a_next, b, b_next, b_len - b_next) != 0) {
|
||||
for (int i = 0; i < a_len - a_next && i < b_len - b_next; ++i) {
|
||||
if (a[a_next + i] != b[b_next + i]) {
|
||||
std::cout << "Difference found at pos " << a_next + i << " of a\n";
|
||||
std::cout << "a: " << a.substr(a_next + i, 100) << " ...\n";
|
||||
std::cout << "b: " << b.substr(b_next + i, 100) << " ... \n";
|
||||
printf("Difference found at pos %zu of a\n", a_next + i);
|
||||
printf("a: %s ...\n", a.substr(a_next + i, 100).c_str());
|
||||
printf("b: %s ...\n", b.substr(b_next + i, 100).c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "BKE_appdir.hh"
|
||||
|
||||
#include "CLG_log.h"
|
||||
|
||||
#include "testing/testing.h"
|
||||
|
||||
#include "obj_export_mtl.hh"
|
||||
@@ -17,6 +19,14 @@ namespace blender::io::obj {
|
||||
|
||||
class OBJMTLParserTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
CLG_init();
|
||||
}
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
CLG_exit();
|
||||
}
|
||||
void check_string(const char *text, const MTLMaterial *expect, size_t expect_count)
|
||||
{
|
||||
BKE_tempdir_init(nullptr);
|
||||
|
||||
Reference in New Issue
Block a user