[Bf-blender-cvs] [03c0bb75c58] temp-usd-prev-export2: USD Export: shared code to get active uv name.
Michael Kowalski
noreply at git.blender.org
Tue Dec 28 06:13:51 CET 2021
Commit: 03c0bb75c58b9cfc1c65445c460d66e4986da28a
Author: Michael Kowalski
Date: Sun Dec 26 19:12:33 2021 -0500
Branches: temp-usd-prev-export2
https://developer.blender.org/rB03c0bb75c58b9cfc1c65445c460d66e4986da28a
USD Export: shared code to get active uv name.
Added CustomData_get_active_layer_name() function to
BKE_customdata.h to return the name of the active
layer of a given type, as this functionality can
be used in both the USD export and Collada IO
utility functions when retrieving the name of a
mesh's active UV layer. Refactored the USD Preview
Surface code to use this function.
===================================================================
M source/blender/blenkernel/BKE_customdata.h
M source/blender/blenkernel/intern/customdata.c
M source/blender/io/usd/intern/usd_writer_abstract.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 68d29235469..35c5db57d84 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -441,6 +441,12 @@ int CustomData_get_render_layer(const struct CustomData *data, int type);
int CustomData_get_clone_layer(const struct CustomData *data, int type);
int CustomData_get_stencil_layer(const struct CustomData *data, int type);
+/**
+ * Returns name of the active layer of the given type or NULL
+ * if no such active layer is defined.
+ */
+const char *CustomData_get_active_layer_name(const struct CustomData *data, int type);
+
/**
* Copies the data from source to the data element at index in the first layer of type
* no effect if there is no layer of type.
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 090de26c230..bf2760d3db3 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -2405,6 +2405,13 @@ int CustomData_get_stencil_layer(const CustomData *data, int type)
return (layer_index != -1) ? data->layers[layer_index].active_mask : -1;
}
+const char *CustomData_get_active_layer_name(const struct CustomData *data, int type)
+{
+ /* Get the layer index of the active layer of this type. */
+ int layer_index = CustomData_get_active_layer_index(data, type);
+ return layer_index < 0 ? NULL : data->layers[layer_index].name;
+}
+
void CustomData_set_layer_active(CustomData *data, int type, int n)
{
for (int i = 0; i < data->totlayer; i++) {
diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc
index 470718b49c8..b254739c5bf 100644
--- a/source/blender/io/usd/intern/usd_writer_abstract.cc
+++ b/source/blender/io/usd/intern/usd_writer_abstract.cc
@@ -38,49 +38,21 @@ static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal);
static const pxr::TfToken surface("surface", pxr::TfToken::Immortal);
} // namespace usdtokens
-namespace blender::io::usd {
-
-/* The following three utility function for getting active layers
- * were coppied from the collada utils. */
-
-/* Returns name of the active layer of the given type or null
- * if no such active layer is defined. */
-static const char *customData_get_active_layer_name(const CustomData *data, int type)
+static std::string get_mesh_active_uvlayer_name(const Object *ob)
{
- /* get the layer index of the active layer of type */
- int layer_index = CustomData_get_active_layer_index(data, type);
- if (layer_index < 0) {
- return nullptr;
+ if (!ob || ob->type != OB_MESH || !ob->data) {
+ return "";
}
- return data->layers[layer_index].name;
-}
+ const Mesh *me =static_cast<Mesh *>(ob->data);
-/* Returns name of the active UV layer or the empty string if no active
- * UV Layer defined. */
-static std::string get_active_uvlayer_name(Mesh *me)
-{
- int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
- if (num_layers) {
- const char *layer_name = customData_get_active_layer_name(&me->ldata, CD_MLOOPUV);
- if (layer_name) {
- return std::string(layer_name);
- }
- }
- return "";
-}
+ const char *name = CustomData_get_active_layer_name(&me->ldata, CD_MLOOPUV);
-/* Returns name of the acive Layer or empty String if no active UV Layer defined,
- * assuming the Object is of type MESH. */
-static std::string get_active_uvlayer_name(Object *ob)
-{
- if (!ob || ob->type != OB_MESH) {
- return "";
- }
- Mesh *me = static_cast<Mesh *>(ob->data);
- return get_active_uvlayer_name(me);
+ return name ? name : "";
}
+namespace blender::io::usd {
+
USDAbstractWriter::USDAbstractWriter(const USDExporterContext &usd_export_context)
: usd_export_context_(usd_export_context), frame_has_been_written_(false), is_animated_(false)
{
@@ -139,9 +111,9 @@ pxr::UsdShadeMaterial USDAbstractWriter::ensure_usd_material(const HierarchyCont
usd_material = pxr::UsdShadeMaterial::Define(stage, usd_path);
if (material->use_nodes && this->usd_export_context_.export_params.generate_preview_surface) {
- std::string active_uv_name = get_active_uvlayer_name(context.object);
+ std::string active_uv = get_mesh_active_uvlayer_name(context.object);
create_usd_preview_surface_material(
- this->usd_export_context_, material, usd_material, active_uv_name);
+ this->usd_export_context_, material, usd_material, active_uv);
}
else {
create_usd_viewport_material(this->usd_export_context_, material, usd_material);
More information about the Bf-blender-cvs
mailing list