USD IO format fixes.
This commit is contained in:
parent
f71ad78dc1
commit
da766dd71c
|
@ -151,11 +151,7 @@ const EnumPropertyItem rna_enum_usd_mtl_name_collision_mode_items[] = {
|
|||
};
|
||||
|
||||
const EnumPropertyItem rna_enum_usd_attr_import_mode_items[] = {
|
||||
{USD_ATTR_IMPORT_NONE,
|
||||
"NONE",
|
||||
0,
|
||||
"None",
|
||||
"Do not import attributes"},
|
||||
{USD_ATTR_IMPORT_NONE, "NONE", 0, "None", "Do not import attributes"},
|
||||
{USD_ATTR_IMPORT_USER,
|
||||
"USER",
|
||||
0,
|
||||
|
@ -756,11 +752,12 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
|
|||
true,
|
||||
"Export Custom Properties",
|
||||
"When checked, custom properties will be exported as USD User Properties");
|
||||
RNA_def_boolean(ot->srna,
|
||||
"add_properties_namespace",
|
||||
true,
|
||||
"Add Properties Namespace",
|
||||
"Add exported custom properties to the 'userProperties' USD attribute namespace");
|
||||
RNA_def_boolean(
|
||||
ot->srna,
|
||||
"add_properties_namespace",
|
||||
true,
|
||||
"Add Properties Namespace",
|
||||
"Add exported custom properties to the 'userProperties' USD attribute namespace");
|
||||
RNA_def_boolean(ot->srna,
|
||||
"export_identity_transforms",
|
||||
false,
|
||||
|
@ -971,8 +968,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
|
|||
const eUSDMtlNameCollisionMode mtl_name_collision_mode = RNA_enum_get(op->ptr,
|
||||
"mtl_name_collision_mode");
|
||||
|
||||
const eUSDAttrImportMode attr_import_mode = RNA_enum_get(op->ptr,
|
||||
"attr_import_mode");
|
||||
const eUSDAttrImportMode attr_import_mode = RNA_enum_get(op->ptr, "attr_import_mode");
|
||||
|
||||
/* TODO(makowalski): Add support for sequences. */
|
||||
const bool is_sequence = false;
|
||||
|
@ -1249,13 +1245,12 @@ void WM_OT_usd_import(struct wmOperatorType *ot)
|
|||
"Material Name Collision",
|
||||
"Behavior when the name of an imported material conflicts with an existing material");
|
||||
|
||||
RNA_def_enum(
|
||||
ot->srna,
|
||||
"attr_import_mode",
|
||||
rna_enum_usd_attr_import_mode_items,
|
||||
USD_ATTR_IMPORT_NONE,
|
||||
"Import Attributes",
|
||||
"Behavior when importing USD attributes as Blender custom properties");
|
||||
RNA_def_enum(ot->srna,
|
||||
"attr_import_mode",
|
||||
rna_enum_usd_attr_import_mode_items,
|
||||
USD_ATTR_IMPORT_NONE,
|
||||
"Import Attributes",
|
||||
"Behavior when importing USD attributes as Blender custom properties");
|
||||
}
|
||||
|
||||
#endif /* WITH_USD */
|
||||
|
|
|
@ -84,19 +84,23 @@ static bool validate_params(const USDExportParams ¶ms)
|
|||
|
||||
if (params.export_materials && !pxr::SdfPath::IsValidPathString(params.material_prim_path)) {
|
||||
WM_reportf(RPT_ERROR,
|
||||
"USD Export: invalid material prim path parameter '%s'", params.material_prim_path);
|
||||
"USD Export: invalid material prim path parameter '%s'",
|
||||
params.material_prim_path);
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (strlen(params.root_prim_path) != 0 && !pxr::SdfPath::IsValidPathString(params.root_prim_path)) {
|
||||
WM_reportf(RPT_ERROR,
|
||||
"USD Export: invalid root prim path parameter '%s'", params.root_prim_path);
|
||||
if (strlen(params.root_prim_path) != 0 &&
|
||||
!pxr::SdfPath::IsValidPathString(params.root_prim_path)) {
|
||||
WM_reportf(
|
||||
RPT_ERROR, "USD Export: invalid root prim path parameter '%s'", params.root_prim_path);
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (strlen(params.default_prim_path) != 0 && !pxr::SdfPath::IsValidPathString(params.default_prim_path)) {
|
||||
if (strlen(params.default_prim_path) != 0 &&
|
||||
!pxr::SdfPath::IsValidPathString(params.default_prim_path)) {
|
||||
WM_reportf(RPT_ERROR,
|
||||
"USD Export: invalid default prim path parameter '%s'", params.default_prim_path);
|
||||
"USD Export: invalid default prim path parameter '%s'",
|
||||
params.default_prim_path);
|
||||
valid = false;
|
||||
}
|
||||
|
||||
|
@ -219,7 +223,7 @@ static void export_startjob(void *customdata,
|
|||
pxr::SdfPath mtl_prim_path(data->params.material_prim_path);
|
||||
|
||||
blender::io::usd::usd_define_or_over<pxr::UsdGeomScope>(
|
||||
usd_stage, mtl_prim_path, data->params.export_as_overs);
|
||||
usd_stage, mtl_prim_path, data->params.export_as_overs);
|
||||
}
|
||||
|
||||
pxr::VtValue upAxis = pxr::VtValue(pxr::UsdGeomTokens->z);
|
||||
|
|
|
@ -354,8 +354,7 @@ Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_mater
|
|||
set_viewport_material_props(mtl, usd_preview);
|
||||
}
|
||||
|
||||
if (params_.import_shaders_mode == USD_IMPORT_USD_PREVIEW_SURFACE
|
||||
&& usd_preview) {
|
||||
if (params_.import_shaders_mode == USD_IMPORT_USD_PREVIEW_SURFACE && usd_preview) {
|
||||
/* Create shader nodes to represent a UsdPreviewSurface. */
|
||||
import_usd_preview(mtl, usd_preview);
|
||||
}
|
||||
|
@ -367,8 +366,8 @@ Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_mater
|
|||
#endif
|
||||
if (!imported_mdl && usd_preview) {
|
||||
/* We failed to import an MDL, so fall back on importing UsdPreviewSuface. */
|
||||
std::string message = "Couldn't import MDL shaders for material "
|
||||
+ mtl_name + ", importing USD Preview Surface shaders instead";
|
||||
std::string message = "Couldn't import MDL shaders for material " + mtl_name +
|
||||
", importing USD Preview Surface shaders instead";
|
||||
WM_reportf(RPT_INFO, message.c_str());
|
||||
import_usd_preview(mtl, usd_preview);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ void set_array_prop(IDProperty *idgroup,
|
|||
return;
|
||||
}
|
||||
|
||||
IDPropertyTemplate val = { 0 };
|
||||
IDPropertyTemplate val = {0};
|
||||
val.array.len = static_cast<int>(vec.dimension);
|
||||
|
||||
if (val.array.len <= 0) {
|
||||
|
@ -76,7 +76,8 @@ void set_array_prop(IDProperty *idgroup,
|
|||
return;
|
||||
}
|
||||
|
||||
typename VECT::ScalarType *prop_data = static_cast<typename VECT::ScalarType *>(prop->data.pointer);
|
||||
typename VECT::ScalarType *prop_data = static_cast<typename VECT::ScalarType *>(
|
||||
prop->data.pointer);
|
||||
|
||||
for (int i = 0; i < val.array.len; ++i) {
|
||||
prop_data[i] = vec[i];
|
||||
|
@ -85,24 +86,22 @@ void set_array_prop(IDProperty *idgroup,
|
|||
IDP_AddToGroup(idgroup, prop);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
} // anonymous namespace
|
||||
|
||||
namespace blender::io::usd {
|
||||
|
||||
/* TfToken objects are not cheap to construct, so we do it once. */
|
||||
namespace usdtokens {
|
||||
static const pxr::TfToken userProperties("userProperties", pxr::TfToken::Immortal);
|
||||
static const pxr::TfToken userProperties("userProperties", pxr::TfToken::Immortal);
|
||||
} // namespace usdtokens
|
||||
|
||||
static void set_string_prop(IDProperty *idgroup,
|
||||
const char *prop_name,
|
||||
const char *str_val)
|
||||
static void set_string_prop(IDProperty *idgroup, const char *prop_name, const char *str_val)
|
||||
{
|
||||
if (!idgroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
IDPropertyTemplate val = { 0 };
|
||||
IDPropertyTemplate val = {0};
|
||||
val.string.str = str_val;
|
||||
/* Note length includes null terminator. */
|
||||
val.string.len = strlen(str_val) + 1;
|
||||
|
@ -113,45 +112,39 @@ static void set_string_prop(IDProperty *idgroup,
|
|||
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 char *prop_name, const int ival)
|
||||
{
|
||||
if (!idgroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
IDPropertyTemplate val = { 0 };
|
||||
IDPropertyTemplate val = {0};
|
||||
val.i = ival;
|
||||
IDProperty *prop = IDP_New(IDP_INT, &val, prop_name);
|
||||
|
||||
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 char *prop_name, const float fval)
|
||||
{
|
||||
if (!idgroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
IDPropertyTemplate val = { 0 };
|
||||
IDPropertyTemplate val = {0};
|
||||
val.f = fval;
|
||||
IDProperty *prop = IDP_New(IDP_FLOAT, &val, prop_name);
|
||||
|
||||
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 char *prop_name, const double dval)
|
||||
{
|
||||
if (!idgroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
IDPropertyTemplate val = { 0 };
|
||||
IDPropertyTemplate val = {0};
|
||||
val.d = dval;
|
||||
IDProperty *prop = IDP_New(IDP_DOUBLE, &val, prop_name);
|
||||
|
||||
|
@ -195,7 +188,8 @@ void USDPrimReader::set_props(ID *id, const pxr::UsdPrim &prim, const double mot
|
|||
}
|
||||
|
||||
/* When importing user properties, strip the namespace. */
|
||||
pxr::TfToken attr_name = (attr_import_mode == USD_ATTR_IMPORT_USER) ? attr.GetBaseName() : attr.GetName();
|
||||
pxr::TfToken attr_name = (attr_import_mode == USD_ATTR_IMPORT_USER) ? attr.GetBaseName() :
|
||||
attr.GetName();
|
||||
|
||||
pxr::SdfValueTypeName type_name = attr.GetTypeName();
|
||||
|
||||
|
@ -259,7 +253,6 @@ void USDPrimReader::set_props(ID *id, const pxr::UsdPrim &prim, const double mot
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
USDPrimReader::USDPrimReader(const pxr::UsdPrim &prim,
|
||||
const USDImportParams &import_params,
|
||||
const ImportSettings &settings)
|
||||
|
@ -287,7 +280,7 @@ void USDPrimReader::read_object_data(Main * /* bmain */, const double motionSamp
|
|||
return;
|
||||
}
|
||||
|
||||
ID *id = object_->data ? static_cast<ID*>(object_->data) : &object_->id;
|
||||
ID *id = object_->data ? static_cast<ID *>(object_->data) : &object_->id;
|
||||
|
||||
set_props(id, prim_, motionSampleTime);
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ class USDPrimReader {
|
|||
virtual bool valid() const;
|
||||
|
||||
virtual void create_object(Main *bmain, double motionSampleTime) = 0;
|
||||
virtual void read_object_data(Main * bmain, double motionSampleTime);
|
||||
virtual void read_object_data(Main *bmain, double motionSampleTime);
|
||||
|
||||
virtual bool needs_cachefile()
|
||||
{
|
||||
|
@ -146,7 +146,6 @@ class USDPrimReader {
|
|||
|
||||
protected:
|
||||
void set_props(ID *id, const pxr::UsdPrim &prim, double motionSampleTime);
|
||||
|
||||
};
|
||||
|
||||
} // namespace blender::io::usd
|
||||
|
|
|
@ -51,7 +51,7 @@ void USDXformReader::create_object(Main *bmain, const double /* motionSampleTime
|
|||
object_->data = nullptr;
|
||||
}
|
||||
|
||||
void USDXformReader::read_object_data(Main * bmain, const double motionSampleTime)
|
||||
void USDXformReader::read_object_data(Main *bmain, const double motionSampleTime)
|
||||
{
|
||||
USDPrimReader::read_object_data(bmain, motionSampleTime);
|
||||
|
||||
|
|
|
@ -166,7 +166,6 @@ static bool report_notification(PyObject *dict)
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool is_none_value(PyObject *tup)
|
||||
{
|
||||
if (!(tup && PyTuple_Check(tup) && PyTuple_Size(tup) > 1)) {
|
||||
|
@ -738,7 +737,7 @@ bool umm_import_material(Material *mtl, const pxr::UsdShadeMaterial &usd_materia
|
|||
if (!surf_shader.GetSourceAssetSubIdentifier(&source_asset_sub_identifier, usdtokens::mdl)) {
|
||||
if (verbose) {
|
||||
std::cout << "No mdl source asset sub identifier for shader " << surf_shader.GetPath()
|
||||
<< std::endl;
|
||||
<< std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,9 @@ struct USDExporterContext;
|
|||
|
||||
bool umm_module_loaded();
|
||||
|
||||
bool umm_import_material(Material *mtl, const pxr::UsdShadeMaterial &usd_material, bool verbose = false);
|
||||
bool umm_import_material(Material *mtl,
|
||||
const pxr::UsdShadeMaterial &usd_material,
|
||||
bool verbose = false);
|
||||
|
||||
bool umm_export_material(const USDExporterContext &usd_export_context,
|
||||
const Material *mtl,
|
||||
|
|
|
@ -61,16 +61,17 @@ bool set_vec_attrib(const pxr::UsdPrim &prim,
|
|||
pxr::UsdAttribute vec_attr = prim.CreateAttribute(prop_token, type_name, true);
|
||||
|
||||
if (!vec_attr) {
|
||||
printf("WARNING: Couldn't USD attribute for array property %s.\n", prop_token.GetString().c_str());
|
||||
printf("WARNING: Couldn't USD attribute for array property %s.\n",
|
||||
prop_token.GetString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
VECT vec_value(static_cast<typename VECT::ScalarType*>(prop->data.pointer));
|
||||
VECT vec_value(static_cast<typename VECT::ScalarType *>(prop->data.pointer));
|
||||
|
||||
return vec_attr.Set(vec_value, timecode);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
} // anonymous namespace
|
||||
|
||||
namespace blender::io::usd {
|
||||
|
||||
|
@ -84,7 +85,10 @@ static void create_vector_attrib(const pxr::UsdPrim &prim,
|
|||
}
|
||||
|
||||
if (prop->type != IDP_ARRAY) {
|
||||
printf("WARNING: Property %s is not an array type and can't be converted to a vector attribute.\n", prop_token.GetString().c_str());
|
||||
printf(
|
||||
"WARNING: Property %s is not an array type and can't be converted to a vector "
|
||||
"attribute.\n",
|
||||
prop_token.GetString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -135,12 +139,14 @@ static void create_vector_attrib(const pxr::UsdPrim &prim,
|
|||
}
|
||||
|
||||
if (!type_name) {
|
||||
printf("WARNING: Couldn't determine USD type name for array property %s.\n", prop_token.GetString().c_str());
|
||||
printf("WARNING: Couldn't determine USD type name for array property %s.\n",
|
||||
prop_token.GetString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
printf("WARNING: Couldn't set USD attribute from array property %s.\n", prop_token.GetString().c_str());
|
||||
printf("WARNING: Couldn't set USD attribute from array property %s.\n",
|
||||
prop_token.GetString().c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -382,22 +388,26 @@ void USDAbstractWriter::write_user_properties(pxr::UsdPrim &prim,
|
|||
|
||||
switch (prop->type) {
|
||||
case IDP_INT:
|
||||
if (pxr::UsdAttribute int_attr = prim.CreateAttribute(prop_token, pxr::SdfValueTypeNames->Int, true)) {
|
||||
if (pxr::UsdAttribute int_attr = prim.CreateAttribute(
|
||||
prop_token, pxr::SdfValueTypeNames->Int, true)) {
|
||||
int_attr.Set<int>(prop->data.val, timecode);
|
||||
}
|
||||
break;
|
||||
case IDP_FLOAT:
|
||||
if (pxr::UsdAttribute float_attr = prim.CreateAttribute(prop_token, pxr::SdfValueTypeNames->Float, true)) {
|
||||
if (pxr::UsdAttribute float_attr = prim.CreateAttribute(
|
||||
prop_token, pxr::SdfValueTypeNames->Float, true)) {
|
||||
float_attr.Set<float>(*reinterpret_cast<float *>(&prop->data.val), timecode);
|
||||
}
|
||||
break;
|
||||
case IDP_DOUBLE:
|
||||
if (pxr::UsdAttribute double_attr = prim.CreateAttribute(prop_token, pxr::SdfValueTypeNames->Double, true)) {
|
||||
if (pxr::UsdAttribute double_attr = prim.CreateAttribute(
|
||||
prop_token, pxr::SdfValueTypeNames->Double, true)) {
|
||||
double_attr.Set<double>(*reinterpret_cast<double *>(&prop->data.val), timecode);
|
||||
}
|
||||
break;
|
||||
case IDP_STRING:
|
||||
if (pxr::UsdAttribute str_attr = prim.CreateAttribute(prop_token, pxr::SdfValueTypeNames->String, true)) {
|
||||
if (pxr::UsdAttribute str_attr = prim.CreateAttribute(
|
||||
prop_token, pxr::SdfValueTypeNames->String, true)) {
|
||||
str_attr.Set<std::string>(static_cast<const char *>(prop->data.pointer), timecode);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -52,16 +52,16 @@ pxr::UsdGeomXformable USDSkelRootWriter::create_xformable() const
|
|||
pxr::UsdGeomXformable root;
|
||||
|
||||
if (is_under_skel_root()) {
|
||||
root =
|
||||
(usd_export_context_.export_params.export_as_overs) ?
|
||||
pxr::UsdGeomXform(usd_export_context_.stage->OverridePrim(usd_export_context_.usd_path)) :
|
||||
pxr::UsdGeomXform::Define(usd_export_context_.stage, usd_export_context_.usd_path);
|
||||
root = (usd_export_context_.export_params.export_as_overs) ?
|
||||
pxr::UsdGeomXform(
|
||||
usd_export_context_.stage->OverridePrim(usd_export_context_.usd_path)) :
|
||||
pxr::UsdGeomXform::Define(usd_export_context_.stage, usd_export_context_.usd_path);
|
||||
}
|
||||
else {
|
||||
root =
|
||||
(usd_export_context_.export_params.export_as_overs) ?
|
||||
pxr::UsdSkelRoot(usd_export_context_.stage->OverridePrim(usd_export_context_.usd_path)) :
|
||||
pxr::UsdSkelRoot::Define(usd_export_context_.stage, usd_export_context_.usd_path);
|
||||
root = (usd_export_context_.export_params.export_as_overs) ?
|
||||
pxr::UsdSkelRoot(
|
||||
usd_export_context_.stage->OverridePrim(usd_export_context_.usd_path)) :
|
||||
pxr::UsdSkelRoot::Define(usd_export_context_.stage, usd_export_context_.usd_path);
|
||||
}
|
||||
|
||||
return root;
|
||||
|
|
|
@ -190,7 +190,8 @@ void USDSkinnedMeshWriter::write_weights(const Object *ob,
|
|||
|
||||
std::vector<int> group_to_bone_idx;
|
||||
|
||||
for (const bDeformGroup *def = (const bDeformGroup *)mesh->vertex_group_names.first; def; def = def->next) {
|
||||
for (const bDeformGroup *def = (const bDeformGroup *)mesh->vertex_group_names.first; def;
|
||||
def = def->next) {
|
||||
|
||||
int bone_idx = -1;
|
||||
/* For now, n-squared search is acceptable. */
|
||||
|
|
Loading…
Reference in New Issue