Cleanup: Use CLOG instead of iostream for USD logging

Straightforward change from usage of iostream to CLOG.

Using CLOG unifies info/warning/error logging under a common
infrastructure that provides facilities for standardized filtering,
categorization, and printing. It also removes direct dependencies on
`<iostream>` which can be detrimental to compile times.

Pull Request: https://projects.blender.org/blender/blender/pulls/117429
This commit is contained in:
Jesse Yurkovich
2024-01-24 21:27:59 +01:00
committed by Jesse Yurkovich
parent 03e0de14c5
commit 7bb78be256
11 changed files with 81 additions and 79 deletions

View File

@@ -46,7 +46,6 @@
#include "ED_keyframing.hh"
#include "ED_mesh.hh"
#include <iostream>
#include <string>
#include <vector>

View File

@@ -18,8 +18,6 @@
#include <pxr/usd/usdLux/shapingAPI.h>
#include <pxr/usd/usdLux/sphereLight.h>
#include <iostream>
namespace blender::io::usd {
void USDLightReader::create_object(Main *bmain, const double /*motionSampleTime*/)

View File

@@ -31,7 +31,8 @@
#include <pxr/usd/usdShade/material.h>
#include <pxr/usd/usdShade/shader.h>
#include <iostream>
#include "CLG_log.h"
static CLG_LogRef LOG = {"io.usd"};
namespace usdtokens {
@@ -145,14 +146,14 @@ static void link_nodes(
bNodeSocket *source_socket = nodeFindSocket(source, SOCK_OUT, sock_out);
if (!source_socket) {
std::cerr << "PROGRAMMER ERROR: Couldn't find output socket " << sock_out << std::endl;
CLOG_ERROR(&LOG, "Couldn't find output socket %s", sock_out);
return;
}
bNodeSocket *dest_socket = nodeFindSocket(dest, SOCK_IN, sock_in);
if (!dest_socket) {
std::cerr << "PROGRAMMER ERROR: Couldn't find input socket " << sock_in << std::endl;
CLOG_ERROR(&LOG, "Couldn't find input socket %s", sock_in);
return;
}
@@ -492,8 +493,9 @@ void USDMaterialReader::import_usd_preview(Material *mtl,
bNode *principled = add_node(nullptr, ntree, SH_NODE_BSDF_PRINCIPLED, 0.0f, 300.0f);
if (!principled) {
std::cerr << "ERROR: Couldn't create SH_NODE_BSDF_PRINCIPLED node for USD shader "
<< usd_shader.GetPath() << std::endl;
CLOG_ERROR(&LOG,
"Couldn't create SH_NODE_BSDF_PRINCIPLED node for USD shader %s",
usd_shader.GetPath().GetAsString().c_str());
return;
}
@@ -501,8 +503,9 @@ void USDMaterialReader::import_usd_preview(Material *mtl,
bNode *output = add_node(nullptr, ntree, SH_NODE_OUTPUT_MATERIAL, 300.0f, 300.0f);
if (!output) {
std::cerr << "ERROR: Couldn't create SH_NODE_OUTPUT_MATERIAL node for USD shader "
<< usd_shader.GetPath() << std::endl;
CLOG_ERROR(&LOG,
"Couldn't create SH_NODE_OUTPUT_MATERIAL node for USD shader %s",
usd_shader.GetPath().GetAsString().c_str());
return;
}
@@ -621,14 +624,15 @@ bool USDMaterialReader::set_node_input(const pxr::UsdShadeInput &usd_input,
bNodeSocket *sock = nodeFindSocket(dest_node, SOCK_IN, dest_socket_name);
if (!sock) {
std::cerr << "ERROR: couldn't get destination node socket " << dest_socket_name << std::endl;
CLOG_ERROR(&LOG, "Couldn't get destination node socket %s", dest_socket_name);
return false;
}
pxr::VtValue val;
if (!usd_input.Get(&val)) {
std::cerr << "ERROR: couldn't get value for usd shader input "
<< usd_input.GetPrim().GetPath() << std::endl;
CLOG_ERROR(&LOG,
"Couldn't get value for usd shader input %s",
usd_input.GetPrim().GetPath().GetAsString().c_str());
return false;
}
@@ -665,8 +669,10 @@ bool USDMaterialReader::set_node_input(const pxr::UsdShadeInput &usd_input,
}
break;
default:
std::cerr << "WARNING: unexpected type " << sock->idname << " for destination node socket "
<< dest_socket_name << std::endl;
CLOG_WARN(&LOG,
"Unexpected type %s for destination node socket %s",
sock->idname,
dest_socket_name);
break;
}
}
@@ -704,8 +710,9 @@ bool USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input,
pxr::TfToken shader_id;
if (!source_shader.GetShaderId(&shader_id)) {
std::cerr << "ERROR: couldn't get shader id for source shader "
<< source_shader.GetPrim().GetPath() << std::endl;
CLOG_ERROR(&LOG,
"Couldn't get shader id for source shader %s",
source_shader.GetPath().GetAsString().c_str());
return false;
}
@@ -781,8 +788,7 @@ void USDMaterialReader::convert_usd_uv_texture(const pxr::UsdShadeShader &usd_sh
tex_image = add_node(nullptr, ntree, SH_NODE_TEX_IMAGE, locx, locy);
if (!tex_image) {
std::cerr << "ERROR: Couldn't create SH_NODE_TEX_IMAGE for node input " << dest_socket_name
<< std::endl;
CLOG_ERROR(&LOG, "Couldn't create SH_NODE_TEX_IMAGE for node input %s", dest_socket_name);
return;
}
@@ -896,15 +902,17 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader &usd_shader,
pxr::UsdShadeInput file_input = usd_shader.GetInput(usdtokens::file);
if (!file_input) {
std::cerr << "WARNING: Couldn't get file input for USD shader " << usd_shader.GetPath()
<< std::endl;
CLOG_WARN(&LOG,
"Couldn't get file input for USD shader %s",
usd_shader.GetPath().GetAsString().c_str());
return;
}
pxr::VtValue file_val;
if (!file_input.Get(&file_val) || !file_val.IsHolding<pxr::SdfAssetPath>()) {
std::cerr << "WARNING: Couldn't get file input value for USD shader " << usd_shader.GetPath()
<< std::endl;
CLOG_WARN(&LOG,
"Couldn't get file input value for USD shader %s",
usd_shader.GetPath().GetAsString().c_str());
return;
}
@@ -923,8 +931,9 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader &usd_shader,
}
if (file_path.empty()) {
std::cerr << "WARNING: Couldn't resolve image asset '" << asset_path
<< "' for Texture Image node." << std::endl;
CLOG_WARN(&LOG,
" Couldn't resolve image asset '%s' for Texture Image node",
asset_path.GetAssetPath().c_str());
return;
}
@@ -959,8 +968,7 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader &usd_shader,
const char *im_file = file_path.c_str();
Image *image = BKE_image_load_exists(bmain_, im_file);
if (!image) {
std::cerr << "WARNING: Couldn't open image file '" << im_file << "' for Texture Image node."
<< std::endl;
CLOG_WARN(&LOG, "Couldn't open image file '%s' for Texture Image node", im_file);
return;
}
@@ -1041,8 +1049,7 @@ void USDMaterialReader::convert_usd_primvar_reader_float2(const pxr::UsdShadeSha
uv_map = add_node(nullptr, ntree, SH_NODE_UVMAP, locx, locy);
if (!uv_map) {
std::cerr << "ERROR: Couldn't create SH_NODE_UVMAP for node input " << dest_socket_name
<< std::endl;
CLOG_ERROR(&LOG, "Couldn't create SH_NODE_UVMAP for node input %s", dest_socket_name);
return;
}

View File

@@ -44,7 +44,8 @@
#include <pxr/usd/usdShade/materialBindingAPI.h>
#include <pxr/usd/usdSkel/bindingAPI.h>
#include <iostream>
#include "CLG_log.h"
static CLG_LogRef LOG = {"io.usd"};
namespace usdtokens {
/* Materials */
@@ -106,8 +107,8 @@ static void assign_materials(Main *bmain,
pxr::UsdShadeMaterial usd_mat(prim);
if (!usd_mat) {
std::cout << "WARNING: Couldn't construct USD material from prim " << item.key
<< std::endl;
CLOG_WARN(
&LOG, "Couldn't construct USD material from prim %s", item.key.GetAsString().c_str());
continue;
}
@@ -115,8 +116,9 @@ static void assign_materials(Main *bmain,
assigned_mat = mat_reader.add_material(usd_mat);
if (!assigned_mat) {
std::cout << "WARNING: Couldn't create Blender material from USD material " << item.key
<< std::endl;
CLOG_WARN(&LOG,
"Couldn't create Blender material from USD material %s",
item.key.GetAsString().c_str());
continue;
}
@@ -135,7 +137,7 @@ static void assign_materials(Main *bmain,
}
else {
/* This shouldn't happen. */
std::cout << "WARNING: Couldn't assign material " << item.key << std::endl;
CLOG_WARN(&LOG, "Couldn't assign material %s", item.key.GetAsString().c_str());
}
}
if (ob->totcol > 0) {
@@ -721,13 +723,13 @@ void USDMeshReader::read_vertex_creases(Mesh *mesh, const double motionSampleTim
/* It is fine to have fewer indices than vertices, but never the other way other. */
if (corner_indices.size() > mesh->verts_num) {
std::cerr << "WARNING: too many vertex crease for mesh " << prim_path_ << std::endl;
CLOG_WARN(&LOG, "Too many vertex creases for mesh %s", prim_path_.c_str());
return;
}
if (corner_indices.size() != corner_sharpnesses.size()) {
std::cerr << "WARNING: vertex crease indices and sharpnesses count mismatch for mesh "
<< prim_path_ << std::endl;
CLOG_WARN(
&LOG, "Vertex crease and sharpnesses count mismatch for mesh %s", prim_path_.c_str());
return;
}
@@ -752,8 +754,7 @@ void USDMeshReader::process_normals_vertex_varying(Mesh *mesh)
}
if (normals_.size() != mesh->verts_num) {
std::cerr << "WARNING: vertex varying normals count mismatch for mesh " << prim_path_
<< std::endl;
CLOG_WARN(&LOG, "Vertex varying normals count mismatch for mesh %s", prim_path_.c_str());
return;
}
@@ -770,7 +771,7 @@ void USDMeshReader::process_normals_face_varying(Mesh *mesh)
/* Check for normals count mismatches to prevent crashes. */
if (normals_.size() != mesh->corners_num) {
std::cerr << "WARNING: loop normal count mismatch for mesh " << mesh->id.name << std::endl;
CLOG_WARN(&LOG, "Loop normal count mismatch for mesh %s", mesh->id.name);
return;
}
@@ -811,7 +812,7 @@ void USDMeshReader::process_normals_uniform(Mesh *mesh)
/* Check for normals count mismatches to prevent crashes. */
if (normals_.size() != mesh->faces_num) {
std::cerr << "WARNING: uniform normal count mismatch for mesh " << mesh->id.name << std::endl;
CLOG_WARN(&LOG, "Uniform normal count mismatch for mesh %s", mesh->id.name);
return;
}

View File

@@ -16,8 +16,6 @@
#include "WM_api.hh"
#include <iostream>
namespace blender::io::usd {
bool USDSkeletonReader::valid() const

View File

@@ -15,8 +15,6 @@
#include <pxr/usd/usdVol/openVDBAsset.h>
#include <pxr/usd/usdVol/volume.h>
#include <iostream>
namespace usdtokens {
static const pxr::TfToken density("density", pxr::TfToken::Immortal);

View File

@@ -53,7 +53,6 @@
#include "ANIM_animdata.hh"
#include "ANIM_fcurve.hh"
#include <iostream>
#include <string>
#include <vector>
@@ -207,17 +206,17 @@ void import_skeleton_curves(Main *bmain,
/* Sanity checks: make sure we have a curve entry for each joint. */
if (loc_curves.size() != joint_order.size() * 3) {
std::cout << "PROGRAMMER ERROR: location curve count mismatch\n";
CLOG_ERROR(&LOG, "Location curve count mismatch");
return;
}
if (rot_curves.size() != joint_order.size() * 4) {
std::cout << "PROGRAMMER ERROR: rotation curve count mismatch\n";
CLOG_ERROR(&LOG, "Rotation curve count mismatch");
return;
}
if (scale_curves.size() != joint_order.size() * 3) {
std::cout << "PROGRAMMER ERROR: scale curve count mismatch\n";
CLOG_ERROR(&LOG, "Scale curve count mismatch");
return;
}
@@ -273,14 +272,16 @@ void import_skeleton_curves(Main *bmain,
for (const double frame : samples) {
pxr::VtMatrix4dArray joint_local_xforms;
if (!skel_query.ComputeJointLocalTransforms(&joint_local_xforms, frame)) {
std::cout << "WARNING: couldn't compute joint local transforms on frame " << frame
<< std::endl;
CLOG_WARN(&LOG, "Couldn't compute joint local transforms on frame %f", frame);
continue;
}
if (joint_local_xforms.size() != joint_order.size()) {
std::cout << "WARNING: number of joint local transform entries " << joint_local_xforms.size()
<< " doesn't match the number of joints " << joint_order.size() << std::endl;
CLOG_WARN(
&LOG,
"Number of joint local transform entries %zu doesn't match the number of joints %zu",
joint_local_xforms.size(),
joint_order.size());
continue;
}
@@ -292,7 +293,7 @@ void import_skeleton_curves(Main *bmain,
pxr::GfVec3h s;
if (!pxr::UsdSkelDecomposeTransform(bone_xform, &t, &qrot, &s)) {
std::cout << "WARNING: error decomposing matrix on frame " << frame << std::endl;
CLOG_WARN(&LOG, "Error decomposing matrix on frame %f", frame);
continue;
}
@@ -302,7 +303,7 @@ void import_skeleton_curves(Main *bmain,
for (int j = 0; j < 3; ++j) {
const int k = 3 * i + j;
if (k >= loc_curves.size()) {
std::cout << "PROGRAMMER ERROR: out of bounds translation curve index." << std::endl;
CLOG_ERROR(&LOG, "Out of bounds translation curve index %d", k);
break;
}
if (FCurve *fcu = loc_curves[k]) {
@@ -313,7 +314,7 @@ void import_skeleton_curves(Main *bmain,
for (int j = 0; j < 4; ++j) {
const int k = 4 * i + j;
if (k >= rot_curves.size()) {
std::cout << "PROGRAMMER ERROR: out of bounds rotation curve index." << std::endl;
CLOG_ERROR(&LOG, "Out of bounds rotation curve index %d", k);
break;
}
if (FCurve *fcu = rot_curves[k]) {
@@ -329,7 +330,7 @@ void import_skeleton_curves(Main *bmain,
for (int j = 0; j < 3; ++j) {
const int k = 3 * i + j;
if (k >= scale_curves.size()) {
std::cout << "PROGRAMMER ERROR: out of bounds scale curve index." << std::endl;
CLOG_ERROR(&LOG, "Out of bounds scale curve index %d", k);
break;
}
if (FCurve *fcu = scale_curves[k]) {
@@ -545,8 +546,10 @@ void import_blendshapes(Main *bmain,
int a = 0;
for (int i : point_indices) {
if (i < 0 || i > kb->totelem) {
std::cerr << "Out of bounds point index " << i << " for blendshape " << path
<< std::endl;
CLOG_WARN(&LOG,
"Out of bounds point index %d for blendshape %s",
i,
path.GetAsString().c_str());
++a;
continue;
}
@@ -654,14 +657,15 @@ void import_blendshapes(Main *bmain,
for (double frame : times) {
pxr::VtFloatArray weights;
if (!weights_attr.Get(&weights, frame)) {
std::cerr << "Couldn't get blendshape weights for time " << frame << std::endl;
CLOG_WARN(&LOG, "Couldn't get blendshape weights for time %f", frame);
continue;
}
if (weights.size() != curves.size()) {
std::cerr << "Programmer error: number of weight samples doesn't match number of shapekey "
"curve entries for frame "
<< frame << std::endl;
CLOG_WARN(
&LOG,
"Number of weight samples doesn't match number of shapekey curve entries for frame %f",
frame);
continue;
}
@@ -840,8 +844,10 @@ void import_skeleton(Main *bmain,
continue;
}
if (parent_idx >= edit_bones.size()) {
std::cout << "WARNING: out of bounds parent index for bone " << pxr::SdfPath(joint_order[i])
<< " for skeleton " << skel.GetPath() << std::endl;
CLOG_WARN(&LOG,
"Out of bounds parent index for bone %s on skeleton %s",
pxr::SdfPath(joint_order[i]).GetAsString().c_str(),
skel.GetPath().GetAsString().c_str());
continue;
}
@@ -1050,7 +1056,7 @@ void import_mesh_skel_bindings(Main *bmain,
if (std::find(used_indices.begin(), used_indices.end(), index) == used_indices.end()) {
/* We haven't accounted for this index yet. */
if (index < 0 || index >= joints.size()) {
std::cerr << "Out of bound joint index " << index << std::endl;
CLOG_WARN(&LOG, "Out of bound joint index %d", index);
continue;
}
used_indices.append(index);

View File

@@ -13,8 +13,6 @@
#include "WM_types.hh"
#include <iostream>
#include "CLG_log.h"
static CLG_LogRef LOG = {"io.usd"};
@@ -106,7 +104,7 @@ void create_skel_roots(pxr::UsdStageRefPtr stage, const USDExportParams &params)
if (pxr::UsdGeomXform xf = get_xform_ancestor(prim, skel.GetPrim())) {
/* We found a common Xform ancestor, so we set its type to UsdSkelRoot. */
CLOG_INFO(
&LOG, 4, "Converting Xform prim %s to a SkelRoot", prim.GetPath().GetAsString().c_str());
&LOG, 2, "Converting Xform prim %s to a SkelRoot", prim.GetPath().GetAsString().c_str());
pxr::UsdSkelRoot::Define(stage, xf.GetPath());
converted_to_usdskel = true;

View File

@@ -22,7 +22,6 @@
#include <pxr/usd/usdSkel/tokens.h>
#include <functional>
#include <iostream>
#include "CLG_log.h"
static CLG_LogRef LOG = {"io.usd"};

View File

@@ -36,7 +36,8 @@
#include <pxr/pxr.h>
#include <pxr/usd/usdGeom/scope.h>
#include <iostream>
#include "CLG_log.h"
static CLG_LogRef LOG = {"io.usd"};
/* `TfToken` objects are not cheap to construct, so we do it once. */
namespace usdtokens {
@@ -583,7 +584,7 @@ static void export_in_memory_texture(Image *ima,
return;
}
std::cout << "Exporting in-memory texture to " << export_path << std::endl;
CLOG_INFO(&LOG, 2, "Exporting in-memory texture to '%s'", export_path);
if (BKE_imbuf_write_as(imbuf, export_path, &imageFormat, true) == 0) {
BKE_reportf(
@@ -867,7 +868,7 @@ static void copy_tiled_textures(Image *ima,
/* Only <UDIM> tile formats are supported by USD right now. */
if (tile_format != UDIM_TILE_FORMAT_UDIM) {
std::cout << "WARNING: unsupported tile format for `" << src_path << "`" << std::endl;
CLOG_WARN(&LOG, "Unsupported tile format for '%s'", src_path);
MEM_SAFE_FREE(udim_pattern);
return;
}
@@ -893,8 +894,7 @@ static void copy_tiled_textures(Image *ima,
continue;
}
std::cout << "Copying texture tile from " << src_tile_path << " to " << dest_tile_path
<< std::endl;
CLOG_INFO(&LOG, 2, "Copying texture tile from '%s' to '%s'", src_tile_path, dest_tile_path);
/* Copy the file. */
if (BLI_copy(src_tile_path, dest_tile_path) != 0) {
@@ -932,7 +932,7 @@ static void copy_single_file(Image *ima,
return;
}
std::cout << "Copying texture from " << source_path << " to " << dest_path << std::endl;
CLOG_INFO(&LOG, 2, "Copying texture from '%s' to '%s'", source_path, dest_path);
/* Copy the file. */
if (BLI_copy(source_path, dest_path) != 0) {

View File

@@ -50,8 +50,6 @@
#include "WM_api.hh"
#include <iostream>
#include "CLG_log.h"
static CLG_LogRef LOG = {"io.usd"};