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@nvidia.com>2022-01-15 04:21:04 +0300
committerMichael Kowalski <makowalski@nvidia.com>2022-01-15 04:21:04 +0300
commit56722236770631bc1d892fffb38b24397df3ee01 (patch)
tree48427be31937b328ce22ff336e0af65caba8abd3
parentdd9dc5946ce1454c620d9caa46ddd9c7ebaf91fa (diff)
parentaf8e8e2ae5ca28c4e03ce4e14fb15990f720684a (diff)
Merge branch 'temp-usd-preview-surf-export' into temp-usd-prev-export2temp-usd-prev-export2
-rw-r--r--source/blender/io/usd/intern/usd_writer_material.cc42
1 files changed, 22 insertions, 20 deletions
diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc
index 4d3cad08842..da60783cd59 100644
--- a/source/blender/io/usd/intern/usd_writer_material.cc
+++ b/source/blender/io/usd/intern/usd_writer_material.cc
@@ -122,6 +122,9 @@ static std::string get_tex_image_asset_path(bNode *node,
static InputSpecMap &preview_surface_input_map();
static bNode *traverse_channel(bNodeSocket *input, short target_type);
+template<typename T1, typename T2>
+void create_input(pxr::UsdShadeShader &shader, const InputSpec &spec, const void *value);
+
void create_usd_preview_surface_material(const USDExporterContext &usd_export_context,
Material *material,
pxr::UsdShadeMaterial &usd_material,
@@ -179,24 +182,16 @@ void create_usd_preview_surface_material(const USDExporterContext &usd_export_co
/* Set hardcoded value. */
switch (sock->type) {
case SOCK_FLOAT: {
- bNodeSocketValueFloat *float_value = static_cast<bNodeSocketValueFloat *>(
- sock->default_value);
- preview_surface.CreateInput(input_spec.input_name, input_spec.input_type)
- .Set(pxr::VtValue(float_value->value));
+ create_input<bNodeSocketValueFloat, float>(
+ preview_surface, input_spec, sock->default_value);
} break;
case SOCK_VECTOR: {
- bNodeSocketValueVector *vec_data = static_cast<bNodeSocketValueVector *>(
- sock->default_value);
- preview_surface.CreateInput(input_spec.input_name, input_spec.input_type)
- .Set(pxr::VtValue(
- pxr::GfVec3f(vec_data->value[0], vec_data->value[1], vec_data->value[2])));
+ create_input<bNodeSocketValueVector, pxr::GfVec3f>(
+ preview_surface, input_spec, sock->default_value);
} break;
case SOCK_RGBA: {
- bNodeSocketValueRGBA *rgba_data = static_cast<bNodeSocketValueRGBA *>(
- sock->default_value);
- preview_surface.CreateInput(input_spec.input_name, input_spec.input_type)
- .Set(pxr::VtValue(
- pxr::GfVec3f(rgba_data->value[0], rgba_data->value[1], rgba_data->value[2])));
+ create_input<bNodeSocketValueRGBA, pxr::GfVec3f>(
+ preview_surface, input_spec, sock->default_value);
} break;
default:
break;
@@ -260,6 +255,17 @@ static InputSpecMap &preview_surface_input_map()
return input_map;
}
+/* Create an input on the given shader with name and type
+ * provided by the InputSpec and assign the given value to the
+ * input. Parameters T1 and T2 indicate the Blender and USD
+ * value types, respectively. */
+template<typename T1, typename T2>
+void create_input(pxr::UsdShadeShader &shader, const InputSpec &spec, const void *value)
+{
+ const T1 *cast_value = static_cast<const T1 *>(value);
+ shader.CreateInput(spec.input_name, spec.input_type).Set(T2(cast_value->value));
+}
+
/* Find the UVMAP node input to the given texture image node and convert it
* to a USD primvar reader shader. If no UVMAP node is found, create a primvar
* reader for the given default uv set. The primvar reader will be attached to
@@ -413,7 +419,6 @@ static void get_absolute_path(Image *ima, char *r_path)
BLI_path_normalize(nullptr, r_path);
}
-
static pxr::TfToken get_node_tex_image_color_space(bNode *node)
{
if (!node->id) {
@@ -537,10 +542,6 @@ static pxr::UsdShadeShader create_usd_preview_shader(const USDExporterContext &u
static std::string get_tex_image_asset_path(Image *ima)
{
- if (strlen(ima->filepath) == 0) {
- return "";
- }
-
char filepath[FILE_MAX];
get_absolute_path(ima, filepath);
@@ -552,7 +553,8 @@ static std::string get_tex_image_asset_path(Image *ima)
* in the same directory as the USD file, depending on the export parameters.
* The filename is typically the image filepath but might also be automatically
* generated based on the image name for in-memory textures when exporting textures.
- * This function may return an empty string if no asset path could be determined. */
+ * This function may return an empty string if the image does not have a filepath
+ * assigned and no asset path could be determined. */
static std::string get_tex_image_asset_path(bNode *node,
const pxr::UsdStageRefPtr stage,
const USDExportParams &export_params)