Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kowalski <makowalski>2022-01-27 17:43:14 +0300
committerSybren A. Stüvel <sybren@blender.org>2022-01-27 17:51:50 +0300
commitc85c52f2ce478ab0e30c5e93fd5a5cb812db232f (patch)
treecb4f2e120cbcfa9a9ff65244d209d40868a5865e /source/blender/editors
parentd518550c46d7811ea98fb549cc29961621d66b07 (diff)
USD Preview Surface material export.
Add `USD Preview Surface From Nodes` export option, to convert a Principled BSDF material node network to an approximate USD Preview Surface shader representation. If this option is disabled, the original material export behavior is maintained, where viewport setting are saved to the Preview Surface shader. Also added the following options for texture export. - `Export Textures`: If converting Preview Surface, export textures referenced by shader nodes to a 'textures' directory which is a sibling of the USD file. - `Overwrite Textures`: Allow overwriting existing texture files when exporting textures (this option is off by default). - `Relative Texture Paths`: Make texture asset paths relative to the USD. The entry point for the new functionality is `create_usd_preview_surface_material()`, called from `USDAbstractWriter::ensure_usd_material()`. The material conversion currently handles a small subset of Blender shading nodes, `BSDF_DIFFUSE`, `BSDF_PRINCIPLED`, `TEX_IMAGE` and `UVMAP`. Texture export is handled by copying texture files from their original location to a `textures` folder in the same directory as the USD. In-memory and packed textures are saved directly to the textures folder. This patch is based, in part, on code in Tangent Animation's USD exporter branch. Reviewed By: sybren, HooglyBoogly Differential Revision: https://developer.blender.org/D13647
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/io/io_usd.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 4e2ccea36ab..49d60ede277 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -131,6 +131,11 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
const bool use_instancing = RNA_boolean_get(op->ptr, "use_instancing");
const bool evaluation_mode = RNA_enum_get(op->ptr, "evaluation_mode");
+ const bool generate_preview_surface = RNA_boolean_get(op->ptr, "generate_preview_surface");
+ const bool export_textures = RNA_boolean_get(op->ptr, "export_textures");
+ const bool overwrite_textures = RNA_boolean_get(op->ptr, "overwrite_textures");
+ const bool relative_texture_paths = RNA_boolean_get(op->ptr, "relative_texture_paths");
+
struct USDExportParams params = {
export_animation,
export_hair,
@@ -141,6 +146,10 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
visible_objects_only,
use_instancing,
evaluation_mode,
+ generate_preview_surface,
+ export_textures,
+ overwrite_textures,
+ relative_texture_paths,
};
bool ok = USD_export(C, filename, &params, as_background_job);
@@ -173,6 +182,26 @@ static void wm_usd_export_draw(bContext *UNUSED(C), wmOperator *op)
uiItemR(col, ptr, "evaluation_mode", 0, NULL, ICON_NONE);
box = uiLayoutBox(layout);
+ col = uiLayoutColumnWithHeading(box, true, IFACE_("Materials"));
+ uiItemR(col, ptr, "generate_preview_surface", 0, NULL, ICON_NONE);
+ const bool export_mtl = RNA_boolean_get(ptr, "export_materials");
+ uiLayoutSetActive(col, export_mtl);
+
+ uiLayout *row = uiLayoutRow(col, true);
+ uiItemR(row, ptr, "export_textures", 0, NULL, ICON_NONE);
+ const bool preview = RNA_boolean_get(ptr, "generate_preview_surface");
+ uiLayoutSetActive(row, export_mtl && preview);
+
+ row = uiLayoutRow(col, true);
+ uiItemR(row, ptr, "overwrite_textures", 0, NULL, ICON_NONE);
+ const bool export_tex = RNA_boolean_get(ptr, "export_textures");
+ uiLayoutSetActive(row, export_mtl && preview && export_tex);
+
+ row = uiLayoutRow(col, true);
+ uiItemR(row, ptr, "relative_texture_paths", 0, NULL, ICON_NONE);
+ uiLayoutSetActive(row, export_mtl && preview);
+
+ box = uiLayoutBox(layout);
uiItemL(box, IFACE_("Experimental"), ICON_NONE);
uiItemR(box, ptr, "use_instancing", 0, NULL, ICON_NONE);
}
@@ -249,6 +278,32 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
"Use Settings for",
"Determines visibility of objects, modifier settings, and other areas where there "
"are different settings for viewport and rendering");
+
+ RNA_def_boolean(ot->srna,
+ "generate_preview_surface",
+ true,
+ "To USD Preview Surface",
+ "Generate an approximate USD Preview Surface shader "
+ "representation of a Principled BSDF node network");
+
+ RNA_def_boolean(ot->srna,
+ "export_textures",
+ true,
+ "Export Textures",
+ "If exporting materials, export textures referenced by material nodes "
+ "to a 'textures' directory in the same directory as the USD file");
+
+ RNA_def_boolean(ot->srna,
+ "overwrite_textures",
+ false,
+ "Overwrite Textures",
+ "Allow overwriting existing texture files when exporting textures");
+
+ RNA_def_boolean(ot->srna,
+ "relative_texture_paths",
+ true,
+ "Relative Texture Paths",
+ "Make texture asset paths relative to the USD file");
}
/* ====== USD Import ====== */