Cleanup: USD: Use StringRef in more places
Reduce the usage of raw `char *` and `std::string` in a variety of places where they weren't needed. General notes: - Anything used for output or reporting needs to be `StringRefNull` - No additional strlen calls should be incurred beyond what was already present - Memory lifetime is still valid according to ASAN Pull Request: https://projects.blender.org/blender/blender/pulls/137747
This commit is contained in:
committed by
Jesse Yurkovich
parent
f8c046f23d
commit
b6372b3af3
@@ -7,8 +7,11 @@
|
||||
|
||||
#include "BKE_armature.hh"
|
||||
#include "BKE_modifier.hh"
|
||||
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_string_ref.hh"
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include "DEG_depsgraph.hh"
|
||||
#include "DEG_depsgraph_query.hh"
|
||||
#include "DNA_action_types.h"
|
||||
@@ -77,7 +80,7 @@ void visit_bones(const Object *ob_arm, FunctionRef<void(const Bone *)> visitor)
|
||||
|
||||
void get_armature_bone_names(const Object *ob_arm,
|
||||
const bool use_deform,
|
||||
Vector<std::string> &r_names)
|
||||
Vector<StringRef> &r_names)
|
||||
{
|
||||
Map<StringRef, const Bone *> deform_map;
|
||||
if (use_deform) {
|
||||
@@ -85,11 +88,12 @@ void get_armature_bone_names(const Object *ob_arm,
|
||||
}
|
||||
|
||||
auto visitor = [&](const Bone *bone) {
|
||||
if (use_deform && !deform_map.contains(bone->name)) {
|
||||
const StringRef bone_name(bone->name);
|
||||
if (use_deform && !deform_map.contains(bone_name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
r_names.append(bone->name);
|
||||
r_names.append(bone_name);
|
||||
};
|
||||
|
||||
visit_bones(ob_arm, visitor);
|
||||
@@ -101,7 +105,7 @@ pxr::TfToken build_usd_joint_path(const Bone *bone, bool allow_unicode)
|
||||
|
||||
const Bone *parent = bone->parent;
|
||||
while (parent) {
|
||||
path = make_safe_name(parent->name, allow_unicode) + std::string("/") + path;
|
||||
path = make_safe_name(parent->name, allow_unicode) + '/' + path;
|
||||
parent = parent->parent;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ void visit_bones(const Object *ob_arm, FunctionRef<void(const Bone *)> visitor);
|
||||
* armature export joint indices
|
||||
* \param r_names: The returned list of bone names
|
||||
*/
|
||||
void get_armature_bone_names(const Object *ob_arm, bool use_deform, Vector<std::string> &r_names);
|
||||
void get_armature_bone_names(const Object *ob_arm, bool use_deform, Vector<StringRef> &r_names);
|
||||
|
||||
/**
|
||||
* Return the USD joint path corresponding to the given bone. For example, for the bone
|
||||
|
||||
@@ -503,7 +503,7 @@ void ensure_usd_source_path_prop(const std::string &path, ID *id)
|
||||
return;
|
||||
}
|
||||
|
||||
const char *prop_name = "usd_source_path";
|
||||
const StringRef prop_name = "usd_source_path";
|
||||
|
||||
if (IDP_GetPropertyFromGroup(idgroup, prop_name)) {
|
||||
return;
|
||||
@@ -531,7 +531,7 @@ std::string get_usd_source_path(ID *id)
|
||||
return "";
|
||||
}
|
||||
|
||||
const char *prop_name = "usd_source_path";
|
||||
const StringRef prop_name = "usd_source_path";
|
||||
const IDProperty *prop = IDP_GetPropertyFromGroup(idgroup, prop_name);
|
||||
if (!prop) {
|
||||
return "";
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_math_vector.h"
|
||||
#include "BLI_path_utils.hh"
|
||||
#include "BLI_string_ref.hh"
|
||||
|
||||
#include "DNA_image_types.h"
|
||||
#include "DNA_node_types.h"
|
||||
@@ -164,8 +165,8 @@ static Image *load_image(std::string tex_path, Main *bmain, const USDImportParam
|
||||
* as an upstream source to 'dst_node' with the given sockets. */
|
||||
static bNode *append_node(bNode *dst_node,
|
||||
int16_t new_node_type,
|
||||
const char *out_sock,
|
||||
const char *in_sock,
|
||||
const StringRef out_sock,
|
||||
const StringRef in_sock,
|
||||
bNodeTree *ntree,
|
||||
float offset)
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "BLI_math_vector.h"
|
||||
#include "BLI_path_utils.hh"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_string_ref.hh"
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include "DNA_material_types.h"
|
||||
@@ -100,10 +101,10 @@ using blender::io::usd::ShaderToNodeMap;
|
||||
* be specified in order to generate a unique key when more than one Blender
|
||||
* node is created for the USD shader.
|
||||
*/
|
||||
static std::string get_key(const pxr::UsdShadeShader &usd_shader, const char *tag)
|
||||
static std::string get_key(const pxr::UsdShadeShader &usd_shader, const blender::StringRefNull tag)
|
||||
{
|
||||
std::string key = usd_shader.GetPath().GetAsString();
|
||||
if (tag) {
|
||||
if (!tag.is_empty()) {
|
||||
key += ":";
|
||||
key += tag;
|
||||
}
|
||||
@@ -115,7 +116,7 @@ static std::string get_key(const pxr::UsdShadeShader &usd_shader, const char *ta
|
||||
* null if no cached shader was found. */
|
||||
static bNode *get_cached_node(const ShaderToNodeMap &node_cache,
|
||||
const pxr::UsdShadeShader &usd_shader,
|
||||
const char *tag = nullptr)
|
||||
const blender::StringRefNull tag = {})
|
||||
{
|
||||
return node_cache.lookup_default(get_key(usd_shader, tag), nullptr);
|
||||
}
|
||||
@@ -125,7 +126,7 @@ static bNode *get_cached_node(const ShaderToNodeMap &node_cache,
|
||||
static void cache_node(ShaderToNodeMap &node_cache,
|
||||
const pxr::UsdShadeShader &usd_shader,
|
||||
bNode *node,
|
||||
const char *tag = nullptr)
|
||||
const blender::StringRefNull tag = {})
|
||||
{
|
||||
node_cache.add(get_key(usd_shader, tag), node);
|
||||
}
|
||||
@@ -145,18 +146,21 @@ static bNode *add_node(
|
||||
}
|
||||
|
||||
/* Connect the output socket of node 'source' to the input socket of node 'dest'. */
|
||||
static void link_nodes(
|
||||
bNodeTree *ntree, bNode *source, const char *sock_out, bNode *dest, const char *sock_in)
|
||||
static void link_nodes(bNodeTree *ntree,
|
||||
bNode *source,
|
||||
const blender::StringRefNull sock_out,
|
||||
bNode *dest,
|
||||
const blender::StringRefNull sock_in)
|
||||
{
|
||||
bNodeSocket *source_socket = blender::bke::node_find_socket(*source, SOCK_OUT, sock_out);
|
||||
if (!source_socket) {
|
||||
CLOG_ERROR(&LOG, "Couldn't find output socket %s", sock_out);
|
||||
CLOG_ERROR(&LOG, "Couldn't find output socket %s", sock_out.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
bNodeSocket *dest_socket = blender::bke::node_find_socket(*dest, SOCK_IN, sock_in);
|
||||
if (!dest_socket) {
|
||||
CLOG_ERROR(&LOG, "Couldn't find input socket %s", sock_in);
|
||||
CLOG_ERROR(&LOG, "Couldn't find input socket %s", sock_in.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -408,7 +412,9 @@ static pxr::UsdShadeInput get_input(const pxr::UsdShadeShader &usd_shader,
|
||||
return input;
|
||||
}
|
||||
|
||||
static bNodeSocket *get_input_socket(bNode *node, const char *identifier, ReportList *reports)
|
||||
static bNodeSocket *get_input_socket(bNode *node,
|
||||
const blender::StringRefNull identifier,
|
||||
ReportList *reports)
|
||||
{
|
||||
bNodeSocket *sock = blender::bke::node_find_socket(*node, SOCK_IN, identifier);
|
||||
if (!sock) {
|
||||
@@ -416,7 +422,7 @@ static bNodeSocket *get_input_socket(bNode *node, const char *identifier, Report
|
||||
RPT_ERROR,
|
||||
"%s: Error: Couldn't get input socket %s for node %s",
|
||||
__func__,
|
||||
identifier,
|
||||
identifier.c_str(),
|
||||
node->idname);
|
||||
}
|
||||
|
||||
@@ -649,17 +655,17 @@ bool USDMaterialReader::set_displacement_node_inputs(bNodeTree *ntree,
|
||||
/* The column index, from right to left relative to the output node. */
|
||||
int column = 0;
|
||||
|
||||
const char *sock_name = "Height";
|
||||
const StringRefNull height = "Height";
|
||||
ExtraLinkInfo extra;
|
||||
extra.is_color_corrected = false;
|
||||
set_node_input(displacement_input, displacement_node, sock_name, ntree, column, &context, extra);
|
||||
set_node_input(displacement_input, displacement_node, height, ntree, column, &context, extra);
|
||||
|
||||
/* If the displacement input is not connected, then this is "constant" displacement.
|
||||
* We need to adjust the Height input by our default Midlevel value of 0.5. */
|
||||
if (!displacement_input.HasConnectedSource()) {
|
||||
bNodeSocket *sock = blender::bke::node_find_socket(*displacement_node, SOCK_IN, sock_name);
|
||||
bNodeSocket *sock = blender::bke::node_find_socket(*displacement_node, SOCK_IN, height);
|
||||
if (!sock) {
|
||||
CLOG_ERROR(&LOG, "Couldn't get destination node socket %s", sock_name);
|
||||
CLOG_ERROR(&LOG, "Couldn't get destination node socket %s", height.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -673,7 +679,7 @@ bool USDMaterialReader::set_displacement_node_inputs(bNodeTree *ntree,
|
||||
|
||||
bool USDMaterialReader::set_node_input(const pxr::UsdShadeInput &usd_input,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
const int column,
|
||||
NodePlacementContext *r_ctx,
|
||||
@@ -750,8 +756,8 @@ bool USDMaterialReader::set_node_input(const pxr::UsdShadeInput &usd_input,
|
||||
|
||||
struct IntermediateNode {
|
||||
bNode *node;
|
||||
const char *sock_input_name;
|
||||
const char *sock_output_name;
|
||||
StringRefNull sock_input_name;
|
||||
StringRefNull sock_output_name;
|
||||
};
|
||||
|
||||
static IntermediateNode add_normal_map(bNodeTree *ntree, int column, NodePlacementContext *r_ctx)
|
||||
@@ -812,7 +818,7 @@ static IntermediateNode add_scale_bias(const pxr::UsdShadeShader &usd_shader,
|
||||
|
||||
IntermediateNode scale_bias{};
|
||||
|
||||
const char *tag = "scale_bias";
|
||||
const StringRefNull tag = "scale_bias";
|
||||
bNode *node = get_cached_node(r_ctx->node_cache, usd_shader, tag);
|
||||
|
||||
if (!node) {
|
||||
@@ -867,7 +873,7 @@ static IntermediateNode add_separate_color(const pxr::UsdShadeShader &usd_shader
|
||||
if (usd_source_name == usdtokens::r || usd_source_name == usdtokens::g ||
|
||||
usd_source_name == usdtokens::b)
|
||||
{
|
||||
const char *tag = "separate_color";
|
||||
const StringRefNull tag = "separate_color";
|
||||
bNode *node = get_cached_node(r_ctx->node_cache, usd_shader, tag);
|
||||
|
||||
if (!node) {
|
||||
@@ -964,13 +970,13 @@ static void configure_displacement(const pxr::UsdShadeShader &usd_shader, bNode
|
||||
|
||||
bool USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
int column,
|
||||
NodePlacementContext *r_ctx,
|
||||
const ExtraLinkInfo &extra) const
|
||||
{
|
||||
if (!(usd_input && dest_node && dest_socket_name && ntree && r_ctx)) {
|
||||
if (!(usd_input && dest_node && !dest_socket_name.is_empty() && ntree && r_ctx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1004,7 +1010,7 @@ bool USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input,
|
||||
|
||||
/* Create a Normal Map node if the source is flowing into a 'Normal' socket. */
|
||||
IntermediateNode normal_map{};
|
||||
const bool is_normal_map = STREQ(dest_socket_name, "Normal");
|
||||
const bool is_normal_map = dest_socket_name == "Normal";
|
||||
if (is_normal_map) {
|
||||
normal_map = add_normal_map(ntree, column + shift, r_ctx);
|
||||
shift++;
|
||||
@@ -1019,7 +1025,7 @@ bool USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input,
|
||||
|
||||
/* Create a Scale-Bias adjustment node or fill in Displacement settings if necessary. */
|
||||
IntermediateNode scale_bias{};
|
||||
if (STREQ(dest_socket_name, "Height")) {
|
||||
if (dest_socket_name == "Height") {
|
||||
configure_displacement(source_shader, dest_node);
|
||||
}
|
||||
else {
|
||||
@@ -1029,7 +1035,7 @@ bool USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input,
|
||||
/* Wire up any intermediate nodes that are present. Keep track of the
|
||||
* final "target" destination for the Image link. */
|
||||
bNode *target_node = dest_node;
|
||||
const char *target_sock_name = dest_socket_name;
|
||||
StringRefNull target_sock_name = dest_socket_name;
|
||||
if (normal_map.node) {
|
||||
/* If a scale-bias node is required, we need to re-adjust the output
|
||||
* so it can be passed into the NormalMap node properly. */
|
||||
@@ -1079,7 +1085,7 @@ bool USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input,
|
||||
shift++;
|
||||
}
|
||||
else if (separate_color.node) {
|
||||
if (extra.opacity_threshold == 0.0f || !STREQ(dest_socket_name, "Alpha")) {
|
||||
if (extra.opacity_threshold == 0.0f || dest_socket_name != "Alpha") {
|
||||
link_nodes(ntree,
|
||||
separate_color.node,
|
||||
separate_color.sock_output_name,
|
||||
@@ -1135,13 +1141,13 @@ bool USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input,
|
||||
void USDMaterialReader::convert_usd_uv_texture(const pxr::UsdShadeShader &usd_shader,
|
||||
const pxr::TfToken &usd_source_name,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
const int column,
|
||||
NodePlacementContext *r_ctx,
|
||||
const ExtraLinkInfo &extra) const
|
||||
{
|
||||
if (!usd_shader || !dest_node || !ntree || !dest_socket_name || !bmain_ || !r_ctx) {
|
||||
if (!usd_shader || !dest_node || !ntree || dest_socket_name.is_empty() || !bmain_ || !r_ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1170,9 +1176,9 @@ void USDMaterialReader::convert_usd_uv_texture(const pxr::UsdShadeShader &usd_sh
|
||||
/* Connect to destination node input. */
|
||||
|
||||
/* Get the source socket name. */
|
||||
std::string source_socket_name = usd_source_name == usdtokens::a ? "Alpha" : "Color";
|
||||
const StringRefNull source_socket_name = usd_source_name == usdtokens::a ? "Alpha" : "Color";
|
||||
|
||||
link_nodes(ntree, tex_image, source_socket_name.c_str(), dest_node, dest_socket_name);
|
||||
link_nodes(ntree, tex_image, source_socket_name, dest_node, dest_socket_name);
|
||||
|
||||
/* Connect the texture image node "Vector" input. */
|
||||
if (pxr::UsdShadeInput st_input = usd_shader.GetInput(usdtokens::st)) {
|
||||
@@ -1182,12 +1188,12 @@ void USDMaterialReader::convert_usd_uv_texture(const pxr::UsdShadeShader &usd_sh
|
||||
|
||||
void USDMaterialReader::convert_usd_transform_2d(const pxr::UsdShadeShader &usd_shader,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
int column,
|
||||
NodePlacementContext *r_ctx) const
|
||||
{
|
||||
if (!usd_shader || !dest_node || !ntree || !dest_socket_name || !bmain_ || !r_ctx) {
|
||||
if (!usd_shader || !dest_node || !ntree || dest_socket_name.is_empty() || !bmain_ || !r_ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1206,7 +1212,7 @@ void USDMaterialReader::convert_usd_transform_2d(const pxr::UsdShadeShader &usd_
|
||||
RPT_WARNING,
|
||||
"%s: Couldn't create SH_NODE_MAPPING for node input %s",
|
||||
__func__,
|
||||
dest_socket_name);
|
||||
dest_socket_name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1423,12 +1429,12 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader &usd_shader,
|
||||
void USDMaterialReader::convert_usd_primvar_reader_float2(const pxr::UsdShadeShader &usd_shader,
|
||||
const pxr::TfToken & /*usd_source_name*/,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
const int column,
|
||||
NodePlacementContext *r_ctx) const
|
||||
{
|
||||
if (!usd_shader || !dest_node || !ntree || !dest_socket_name || !bmain_ || !r_ctx) {
|
||||
if (!usd_shader || !dest_node || !ntree || dest_socket_name.is_empty() || !bmain_ || !r_ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1443,7 +1449,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) {
|
||||
CLOG_ERROR(&LOG, "Couldn't create SH_NODE_UVMAP for node input %s", dest_socket_name);
|
||||
CLOG_ERROR(&LOG, "Couldn't create SH_NODE_UVMAP for socket %s", dest_socket_name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "WM_types.hh"
|
||||
|
||||
#include "BLI_map.hh"
|
||||
#include "BLI_string_ref.hh"
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include <pxr/usd/usdShade/material.h>
|
||||
@@ -123,7 +124,7 @@ class USDMaterialReader {
|
||||
/** Convert the given USD shader input to an input on the given Blender node. */
|
||||
bool set_node_input(const pxr::UsdShadeInput &usd_input,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
int column,
|
||||
NodePlacementContext *r_ctx,
|
||||
@@ -135,7 +136,7 @@ class USDMaterialReader {
|
||||
*/
|
||||
bool follow_connection(const pxr::UsdShadeInput &usd_input,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
int column,
|
||||
NodePlacementContext *r_ctx,
|
||||
@@ -144,7 +145,7 @@ class USDMaterialReader {
|
||||
void convert_usd_uv_texture(const pxr::UsdShadeShader &usd_shader,
|
||||
const pxr::TfToken &usd_source_name,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
int column,
|
||||
NodePlacementContext *r_ctx,
|
||||
@@ -152,7 +153,7 @@ class USDMaterialReader {
|
||||
|
||||
void convert_usd_transform_2d(const pxr::UsdShadeShader &usd_shader,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
int column,
|
||||
NodePlacementContext *r_ctx) const;
|
||||
@@ -174,7 +175,7 @@ class USDMaterialReader {
|
||||
void convert_usd_primvar_reader_float2(const pxr::UsdShadeShader &usd_shader,
|
||||
const pxr::TfToken &usd_source_name,
|
||||
bNode *dest_node,
|
||||
const char *dest_socket_name,
|
||||
const StringRefNull dest_socket_name,
|
||||
bNodeTree *ntree,
|
||||
int column,
|
||||
NodePlacementContext *r_ctx) const;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "usd_reader_utils.hh"
|
||||
|
||||
#include "BLI_string_ref.hh"
|
||||
|
||||
#include "BKE_idprop.hh"
|
||||
|
||||
#include <pxr/usd/usd/attribute.h>
|
||||
@@ -15,7 +17,7 @@ namespace {
|
||||
|
||||
template<typename VECT>
|
||||
void set_array_prop(IDProperty *idgroup,
|
||||
const char *prop_name,
|
||||
const blender::StringRefNull prop_name,
|
||||
const pxr::UsdAttribute &attr,
|
||||
const pxr::UsdTimeCode motionSampleTime)
|
||||
{
|
||||
@@ -32,7 +34,7 @@ void set_array_prop(IDProperty *idgroup,
|
||||
val.array.len = int(vec.dimension);
|
||||
|
||||
if (val.array.len <= 0) {
|
||||
CLOG_WARN(&LOG, "Invalid array length for prop %s", prop_name);
|
||||
CLOG_WARN(&LOG, "Invalid array length for prop %s", prop_name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -49,14 +51,14 @@ void set_array_prop(IDProperty *idgroup,
|
||||
val.array.type = IDP_INT;
|
||||
}
|
||||
else {
|
||||
CLOG_WARN(&LOG, "Couldn't determine array type for prop %s", prop_name);
|
||||
CLOG_WARN(&LOG, "Couldn't determine array type for prop %s", prop_name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
IDProperty *prop = IDP_New(IDP_ARRAY, &val, prop_name);
|
||||
|
||||
if (!prop) {
|
||||
CLOG_WARN(&LOG, "Couldn't create array prop %s", prop_name);
|
||||
CLOG_WARN(&LOG, "Couldn't create array prop %s", prop_name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,16 +84,18 @@ bool equivalent(const pxr::SdfValueTypeName &type_name1, const pxr::SdfValueType
|
||||
|
||||
namespace blender::io::usd {
|
||||
|
||||
static void set_string_prop(IDProperty *idgroup, const char *prop_name, const char *str_val)
|
||||
static void set_string_prop(IDProperty *idgroup,
|
||||
const StringRefNull prop_name,
|
||||
const StringRefNull str_val)
|
||||
{
|
||||
if (!idgroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
IDPropertyTemplate val = {0};
|
||||
val.string.str = str_val;
|
||||
val.string.str = str_val.data();
|
||||
/* Note length includes null terminator. */
|
||||
val.string.len = strlen(str_val) + 1;
|
||||
val.string.len = str_val.size() + 1;
|
||||
val.string.subtype = IDP_STRING_SUB_UTF8;
|
||||
|
||||
IDProperty *prop = IDP_New(IDP_STRING, &val, prop_name);
|
||||
@@ -99,7 +103,7 @@ static void set_string_prop(IDProperty *idgroup, const char *prop_name, const ch
|
||||
IDP_AddToGroup(idgroup, prop);
|
||||
}
|
||||
|
||||
static void set_int_prop(IDProperty *idgroup, const char *prop_name, const int ival)
|
||||
static void set_int_prop(IDProperty *idgroup, const StringRefNull prop_name, const int ival)
|
||||
{
|
||||
if (!idgroup) {
|
||||
return;
|
||||
@@ -112,7 +116,7 @@ static void set_int_prop(IDProperty *idgroup, const char *prop_name, const int i
|
||||
IDP_AddToGroup(idgroup, prop);
|
||||
}
|
||||
|
||||
static void set_bool_prop(IDProperty *idgroup, const char *prop_name, const bool bval)
|
||||
static void set_bool_prop(IDProperty *idgroup, const StringRefNull prop_name, const bool bval)
|
||||
{
|
||||
if (!idgroup) {
|
||||
return;
|
||||
@@ -125,7 +129,7 @@ static void set_bool_prop(IDProperty *idgroup, const char *prop_name, const bool
|
||||
IDP_AddToGroup(idgroup, prop);
|
||||
}
|
||||
|
||||
static void set_float_prop(IDProperty *idgroup, const char *prop_name, const float fval)
|
||||
static void set_float_prop(IDProperty *idgroup, const StringRefNull prop_name, const float fval)
|
||||
{
|
||||
if (!idgroup) {
|
||||
return;
|
||||
@@ -138,7 +142,7 @@ static void set_float_prop(IDProperty *idgroup, const char *prop_name, const flo
|
||||
IDP_AddToGroup(idgroup, prop);
|
||||
}
|
||||
|
||||
static void set_double_prop(IDProperty *idgroup, const char *prop_name, const double dval)
|
||||
static void set_double_prop(IDProperty *idgroup, const StringRefNull prop_name, const double dval)
|
||||
{
|
||||
if (!idgroup) {
|
||||
return;
|
||||
@@ -170,7 +174,7 @@ void set_id_props_from_prim(ID *id,
|
||||
|
||||
std::vector<std::string> attr_names = attr.SplitName();
|
||||
|
||||
bool is_user_prop = attr_names[0] == "userProperties";
|
||||
const bool is_user_prop = attr_names[0] == "userProperties";
|
||||
|
||||
if (attr_names.size() > 2 && is_user_prop && attr_names[1] == "blender") {
|
||||
continue;
|
||||
@@ -187,9 +191,9 @@ void set_id_props_from_prim(ID *id,
|
||||
if (is_user_prop) {
|
||||
/* We strip the userProperties namespace, but leave others in case
|
||||
* someone's custom attribute namespace is important in their pipeline. */
|
||||
const std::string token = "userProperties:";
|
||||
const std::string name = attr.GetName().GetString();
|
||||
attr_name = pxr::TfToken(name.substr(token.size(), name.size() - token.size()));
|
||||
const StringRefNull token = "userProperties:";
|
||||
const StringRefNull name = attr.GetName().GetString();
|
||||
attr_name = pxr::TfToken(name.substr(token.size()));
|
||||
}
|
||||
else {
|
||||
attr_name = attr.GetName();
|
||||
@@ -200,86 +204,86 @@ void set_id_props_from_prim(ID *id,
|
||||
if (type_name == pxr::SdfValueTypeNames->Int) {
|
||||
int ival = 0;
|
||||
if (attr.Get<int>(&ival, time_code)) {
|
||||
set_int_prop(idgroup, attr_name.GetString().c_str(), ival);
|
||||
set_int_prop(idgroup, attr_name.GetString(), ival);
|
||||
}
|
||||
}
|
||||
else if (type_name == pxr::SdfValueTypeNames->Float) {
|
||||
float fval = 0.0f;
|
||||
if (attr.Get<float>(&fval, time_code)) {
|
||||
set_float_prop(idgroup, attr_name.GetString().c_str(), fval);
|
||||
set_float_prop(idgroup, attr_name.GetString(), fval);
|
||||
}
|
||||
}
|
||||
else if (type_name == pxr::SdfValueTypeNames->Double) {
|
||||
double dval = 0.0;
|
||||
if (attr.Get<double>(&dval, time_code)) {
|
||||
set_double_prop(idgroup, attr_name.GetString().c_str(), dval);
|
||||
set_double_prop(idgroup, attr_name.GetString(), dval);
|
||||
}
|
||||
}
|
||||
else if (type_name == pxr::SdfValueTypeNames->Half) {
|
||||
pxr::GfHalf hval = 0.0f;
|
||||
if (attr.Get<pxr::GfHalf>(&hval, time_code)) {
|
||||
set_float_prop(idgroup, attr_name.GetString().c_str(), hval);
|
||||
set_float_prop(idgroup, attr_name.GetString(), hval);
|
||||
}
|
||||
}
|
||||
else if (type_name == pxr::SdfValueTypeNames->String) {
|
||||
std::string sval;
|
||||
if (attr.Get<std::string>(&sval, time_code)) {
|
||||
set_string_prop(idgroup, attr_name.GetString().c_str(), sval.c_str());
|
||||
set_string_prop(idgroup, attr_name.GetString(), sval);
|
||||
}
|
||||
}
|
||||
else if (type_name == pxr::SdfValueTypeNames->Token) {
|
||||
pxr::TfToken tval;
|
||||
if (attr.Get<pxr::TfToken>(&tval, time_code)) {
|
||||
set_string_prop(idgroup, attr_name.GetString().c_str(), tval.GetString().c_str());
|
||||
set_string_prop(idgroup, attr_name.GetString(), tval.GetString());
|
||||
}
|
||||
}
|
||||
else if (type_name == pxr::SdfValueTypeNames->Asset) {
|
||||
pxr::SdfAssetPath aval;
|
||||
if (attr.Get<pxr::SdfAssetPath>(&aval, time_code)) {
|
||||
set_string_prop(idgroup, attr_name.GetString().c_str(), aval.GetAssetPath().c_str());
|
||||
set_string_prop(idgroup, attr_name.GetString(), aval.GetAssetPath());
|
||||
}
|
||||
}
|
||||
else if (type_name == pxr::SdfValueTypeNames->Bool) {
|
||||
bool bval = false;
|
||||
if (attr.Get<bool>(&bval, time_code)) {
|
||||
set_bool_prop(idgroup, attr_name.GetString().c_str(), bval);
|
||||
set_bool_prop(idgroup, attr_name.GetString(), bval);
|
||||
}
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Float2)) {
|
||||
set_array_prop<pxr::GfVec2f>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec2f>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Float3)) {
|
||||
set_array_prop<pxr::GfVec3f>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec3f>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Float4)) {
|
||||
set_array_prop<pxr::GfVec4f>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec4f>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Double2)) {
|
||||
set_array_prop<pxr::GfVec2d>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec2d>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Double3)) {
|
||||
set_array_prop<pxr::GfVec3d>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec3d>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Double4)) {
|
||||
set_array_prop<pxr::GfVec4d>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec4d>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Int2)) {
|
||||
set_array_prop<pxr::GfVec2i>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec2i>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Int3)) {
|
||||
set_array_prop<pxr::GfVec3i>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec3i>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Int4)) {
|
||||
set_array_prop<pxr::GfVec4i>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec4i>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Half2)) {
|
||||
set_array_prop<pxr::GfVec2h>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec2h>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Half3)) {
|
||||
set_array_prop<pxr::GfVec3h>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec3h>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
else if (equivalent(type_name, pxr::SdfValueTypeNames->Half4)) {
|
||||
set_array_prop<pxr::GfVec4h>(idgroup, attr_name.GetString().c_str(), attr, time_code);
|
||||
set_array_prop<pxr::GfVec4h>(idgroup, attr_name.GetString(), attr, time_code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,6 @@ void import_skeleton_curves(Main *bmain,
|
||||
const pxr::UsdSkelSkeletonQuery &skel_query,
|
||||
const blender::Map<pxr::TfToken, std::string> &joint_to_bone_map,
|
||||
ReportList *reports)
|
||||
|
||||
{
|
||||
if (!(bmain && arm_obj && skel_query)) {
|
||||
return;
|
||||
@@ -762,8 +761,9 @@ void import_skeleton(Main *bmain,
|
||||
|
||||
/* Create the bones. */
|
||||
for (const pxr::TfToken &joint : joint_order) {
|
||||
std::string name = pxr::SdfPath(joint).GetName();
|
||||
EditBone *bone = ED_armature_ebone_add(arm, name.c_str());
|
||||
pxr::SdfPath bone_path(joint);
|
||||
const std::string &bone_name = bone_path.GetName();
|
||||
EditBone *bone = ED_armature_ebone_add(arm, bone_name.c_str());
|
||||
if (!bone) {
|
||||
BKE_reportf(reports,
|
||||
RPT_WARNING,
|
||||
@@ -1296,7 +1296,7 @@ void shape_key_export_chaser(pxr::UsdStageRefPtr stage,
|
||||
|
||||
void export_deform_verts(const Mesh *mesh,
|
||||
const pxr::UsdSkelBindingAPI &skel_api,
|
||||
const Span<std::string> bone_names)
|
||||
const Span<StringRef> bone_names)
|
||||
{
|
||||
BLI_assert(mesh);
|
||||
BLI_assert(skel_api);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "BLI_map.hh"
|
||||
#include "BLI_string_ref.hh"
|
||||
|
||||
#include <pxr/usd/usd/prim.h>
|
||||
#include <pxr/usd/usdGeom/xformCache.h>
|
||||
@@ -133,6 +134,6 @@ void shape_key_export_chaser(pxr::UsdStageRefPtr stage,
|
||||
*/
|
||||
void export_deform_verts(const Mesh *mesh,
|
||||
const pxr::UsdSkelBindingAPI &skel_api,
|
||||
Span<std::string> bone_names);
|
||||
Span<StringRef> bone_names);
|
||||
|
||||
} // namespace blender::io::usd
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "BLI_path_utils.hh"
|
||||
#include "BLI_set.hh"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_string_ref.hh"
|
||||
#include "BLI_string_utils.hh"
|
||||
|
||||
#include "DNA_material_types.h"
|
||||
@@ -107,12 +108,12 @@ struct InputSpec {
|
||||
};
|
||||
|
||||
/* Map Blender socket names to USD Preview Surface InputSpec structs. */
|
||||
using InputSpecMap = blender::Map<std::string, InputSpec>;
|
||||
using InputSpecMap = blender::Map<StringRef, InputSpec>;
|
||||
|
||||
/* Static function forward declarations. */
|
||||
static pxr::UsdShadeShader create_usd_preview_shader(const USDExporterContext &usd_export_context,
|
||||
const pxr::UsdShadeMaterial &material,
|
||||
const char *name,
|
||||
const StringRef name,
|
||||
int type);
|
||||
static pxr::UsdShadeShader create_usd_preview_shader(const USDExporterContext &usd_export_context,
|
||||
const pxr::UsdShadeMaterial &material,
|
||||
@@ -536,7 +537,7 @@ static void create_uvmap_shader(const USDExporterContext &usd_export_context,
|
||||
|
||||
BLI_assert(!uv_node || uv_node->type_legacy == SH_NODE_UVMAP);
|
||||
|
||||
const char *shader_name = uv_node ? uv_node->name : "uvmap";
|
||||
const StringRef shader_name = uv_node ? uv_node->name : "uvmap";
|
||||
|
||||
pxr::UsdShadeShader uv_shader = create_usd_preview_shader(
|
||||
usd_export_context, usd_material, shader_name, SH_NODE_UVMAP);
|
||||
@@ -1007,7 +1008,7 @@ static bNode *find_displacement_node(Material *material)
|
||||
/* Creates a USD Preview Surface shader based on the given cycles node name and type. */
|
||||
static pxr::UsdShadeShader create_usd_preview_shader(const USDExporterContext &usd_export_context,
|
||||
const pxr::UsdShadeMaterial &material,
|
||||
const char *name,
|
||||
const StringRef name,
|
||||
const int type)
|
||||
{
|
||||
pxr::SdfPath shader_path = material.GetPath().AppendChild(
|
||||
@@ -1345,7 +1346,7 @@ void export_texture(bNode *node,
|
||||
export_texture(ima, stage, allow_overwrite, reports);
|
||||
}
|
||||
|
||||
pxr::TfToken token_for_input(const char *input_name)
|
||||
pxr::TfToken token_for_input(const StringRef input_name)
|
||||
{
|
||||
const InputSpecMap &input_map = preview_surface_input_map();
|
||||
const InputSpec *spec = input_map.lookup_ptr(input_name);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "BLI_string_ref.hh"
|
||||
|
||||
#include <pxr/usd/usdShade/material.h>
|
||||
|
||||
#include <string>
|
||||
@@ -33,7 +35,7 @@ pxr::UsdShadeMaterial create_usd_material(const USDExporterContext &usd_export_c
|
||||
* Returns a USDPreviewSurface token name for a given Blender shader Socket name,
|
||||
* or an empty TfToken if the input name is not found in the map.
|
||||
*/
|
||||
pxr::TfToken token_for_input(const char *input_name);
|
||||
pxr::TfToken token_for_input(const StringRef input_name);
|
||||
|
||||
void export_texture(bNode *node,
|
||||
const pxr::UsdStageRefPtr stage,
|
||||
|
||||
@@ -756,7 +756,7 @@ void USDMeshWriter::init_skinned_mesh(const HierarchyContext &context)
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<std::string> bone_names;
|
||||
Vector<StringRef> bone_names;
|
||||
get_armature_bone_names(
|
||||
arm_obj, usd_export_context_.export_params.only_deform_bones, bone_names);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user