USD Export: filtering option for types to export

Added option for filtering types of objects to export.  Meshes,
materials, lights, cameras, volumes, and curves are all equally
supported.

This is useful for many situations in which a user might want a
subset of objects from a Collection without wanting to build a
sub-collection or otherwise reorganize their scene.  Exporting
Armatures and their animation as UsdSkel objects and UsdSkelAnim
clips, but without meshes, is a good example.

Co-authored-by: Charles Wardlaw <cwardlaw@nvidia.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/121325
This commit is contained in:
Charles Wardlaw
2024-05-24 22:16:43 +02:00
committed by Michael Kowalski
parent 62ebc5f351
commit a6a5fd053a
3 changed files with 91 additions and 7 deletions

View File

@@ -210,6 +210,13 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
const bool export_materials = RNA_boolean_get(op->ptr, "export_materials");
const eSubdivExportMode export_subdiv = eSubdivExportMode(
RNA_enum_get(op->ptr, "export_subdivision"));
const bool export_meshes = RNA_boolean_get(op->ptr, "export_meshes");
const bool export_lights = RNA_boolean_get(op->ptr, "export_lights");
const bool export_cameras = RNA_boolean_get(op->ptr, "export_cameras");
const bool export_curves = RNA_boolean_get(op->ptr, "export_curves");
const bool export_volumes = RNA_boolean_get(op->ptr, "export_volumes");
const bool use_instancing = RNA_boolean_get(op->ptr, "use_instancing");
const bool evaluation_mode = RNA_enum_get(op->ptr, "evaluation_mode");
@@ -261,6 +268,11 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
eIOAxis(global_forward),
eIOAxis(global_up),
xform_op_mode,
export_meshes,
export_lights,
export_cameras,
export_curves,
export_volumes,
};
STRNCPY(params.root_prim_path, root_prim_path);
@@ -292,7 +304,6 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op)
col = uiLayoutColumn(box, true);
uiItemR(col, ptr, "export_animation", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "export_hair", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "export_uvmaps", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "export_normals", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "export_materials", UI_ITEM_NONE, nullptr, ICON_NONE);
@@ -344,6 +355,15 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op)
box = uiLayoutBox(layout);
col = uiLayoutColumnWithHeading(box, true, IFACE_("Experimental"));
uiItemR(col, ptr, "use_instancing", UI_ITEM_NONE, nullptr, ICON_NONE);
box = uiLayoutBox(layout);
col = uiLayoutColumnWithHeading(box, true, IFACE_("Object Types"));
uiItemR(col, ptr, "export_meshes", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "export_lights", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "export_cameras", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "export_volumes", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "export_curves", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "export_hair", UI_ITEM_NONE, nullptr, ICON_NONE);
}
static void free_operator_customdata(wmOperator *op)
@@ -571,6 +591,16 @@ void WM_OT_usd_export(wmOperatorType *ot)
"Blender Names",
"Author USD custom attributes containing the original Blender object and "
"object data names");
RNA_def_boolean(ot->srna, "export_meshes", true, "Meshes", "Export all meshes");
RNA_def_boolean(ot->srna, "export_lights", true, "Lights", "Export all lights");
RNA_def_boolean(ot->srna, "export_cameras", true, "Cameras", "Export all cameras");
RNA_def_boolean(ot->srna, "export_curves", true, "Curves", "Export all curves");
RNA_def_boolean(ot->srna, "export_volumes", true, "Volumes", "Export all volumes");
}
/* ====== USD Import ====== */

View File

@@ -45,7 +45,30 @@ bool USDHierarchyIterator::mark_as_weak_export(const Object *object) const
if (params_.selected_objects_only && (object->base_flag & BASE_SELECTED) == 0) {
return true;
}
return false;
switch (object->type) {
case OB_EMPTY:
/* Always assume empties are being exported intentionally. */
return false;
case OB_MESH:
case OB_MBALL:
return !params_.export_meshes;
case OB_CAMERA:
return !params_.export_cameras;
case OB_LAMP:
return !params_.export_lights;
case OB_CURVES_LEGACY:
case OB_CURVES:
return !params_.export_curves;
case OB_VOLUME:
return !params_.export_volumes;
case OB_ARMATURE:
return !params_.export_armatures;
default:
/* Assume weak for all other types. */
return true;
}
}
void USDHierarchyIterator::release_writer(AbstractHierarchyWriter *writer)
@@ -108,23 +131,48 @@ AbstractHierarchyWriter *USDHierarchyIterator::create_data_writer(const Hierarch
switch (context->object->type) {
case OB_MESH:
data_writer = new USDMeshWriter(usd_export_context);
if (usd_export_context.export_params.export_meshes) {
data_writer = new USDMeshWriter(usd_export_context);
}
else {
return nullptr;
}
break;
case OB_CAMERA:
data_writer = new USDCameraWriter(usd_export_context);
if (usd_export_context.export_params.export_cameras) {
data_writer = new USDCameraWriter(usd_export_context);
}
else {
return nullptr;
}
break;
case OB_LAMP:
data_writer = new USDLightWriter(usd_export_context);
if (usd_export_context.export_params.export_lights) {
data_writer = new USDLightWriter(usd_export_context);
}
else {
return nullptr;
}
break;
case OB_MBALL:
data_writer = new USDMetaballWriter(usd_export_context);
break;
case OB_CURVES_LEGACY:
case OB_CURVES:
data_writer = new USDCurvesWriter(usd_export_context);
if (usd_export_context.export_params.export_curves) {
data_writer = new USDCurvesWriter(usd_export_context);
}
else {
return nullptr;
}
break;
case OB_VOLUME:
data_writer = new USDVolumeWriter(usd_export_context);
if (usd_export_context.export_params.export_volumes) {
data_writer = new USDVolumeWriter(usd_export_context);
}
else {
return nullptr;
}
break;
case OB_ARMATURE:
if (usd_export_context.export_params.export_armatures) {

View File

@@ -109,6 +109,12 @@ struct USDExportParams {
enum eIOAxis forward_axis = eIOAxis::IO_AXIS_NEGATIVE_Z;
enum eIOAxis up_axis = eIOAxis::IO_AXIS_Y;
eUSDXformOpMode xform_op_mode = eUSDXformOpMode::USD_XFORM_OP_TRS;
bool export_meshes = true;
bool export_lights = true;
bool export_cameras = true;
bool export_curves = true;
bool export_volumes = true;
char root_prim_path[1024] = ""; /* FILE_MAX */
char collection[MAX_IDPROP_NAME] = "";