Cleanup: USD: various non-functional changes
- Pass large std::function by const ref - Shift the mesh material assignment helpers inside main namespace - Use MaterialFaceGroups type alias in more places - Remove unused bmain argument from import_mesh_skel_bindings Pull Request: https://projects.blender.org/blender/blender/pulls/132586
This commit is contained in:
committed by
Jesse Yurkovich
parent
e3f1a62a3f
commit
e5b3b9b9cb
@@ -9,7 +9,6 @@
|
||||
#include "usd.hh"
|
||||
#include "usd_attribute_utils.hh"
|
||||
#include "usd_hash_types.hh"
|
||||
#include "usd_hook.hh"
|
||||
#include "usd_mesh_utils.hh"
|
||||
#include "usd_reader_material.hh"
|
||||
#include "usd_skel_convert.hh"
|
||||
@@ -59,8 +58,10 @@ static const pxr::TfToken UVMap("UVMap", pxr::TfToken::Immortal);
|
||||
static const pxr::TfToken normalsPrimvar("normals", pxr::TfToken::Immortal);
|
||||
} // namespace usdtokens
|
||||
|
||||
namespace blender::io::usd {
|
||||
|
||||
namespace utils {
|
||||
using namespace blender::io::usd;
|
||||
|
||||
static pxr::UsdShadeMaterial compute_bound_material(const pxr::UsdPrim &prim,
|
||||
eUSDMtlPurpose mtl_purpose)
|
||||
{
|
||||
@@ -93,11 +94,10 @@ static pxr::UsdShadeMaterial compute_bound_material(const pxr::UsdPrim &prim,
|
||||
static void assign_materials(Main *bmain,
|
||||
Object *ob,
|
||||
const blender::Map<pxr::SdfPath, int> &mat_index_map,
|
||||
const blender::io::usd::USDImportParams ¶ms,
|
||||
const USDImportParams ¶ms,
|
||||
pxr::UsdStageRefPtr stage,
|
||||
const blender::io::usd::ImportSettings &settings)
|
||||
const ImportSettings &settings)
|
||||
{
|
||||
using namespace blender::io::usd;
|
||||
if (!(stage && bmain && ob)) {
|
||||
return;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ static void assign_materials(Main *bmain,
|
||||
USDMaterialReader mat_reader(params, bmain);
|
||||
|
||||
for (const auto item : mat_index_map.items()) {
|
||||
Material *assigned_mat = blender::io::usd::find_existing_material(
|
||||
Material *assigned_mat = find_existing_material(
|
||||
item.key, params, settings.mat_name_to_mat, settings.usd_path_to_mat_name);
|
||||
if (!assigned_mat) {
|
||||
/* Blender material doesn't exist, so create it now. */
|
||||
@@ -170,8 +170,6 @@ static void assign_materials(Main *bmain,
|
||||
|
||||
} // namespace utils
|
||||
|
||||
namespace blender::io::usd {
|
||||
|
||||
void USDMeshReader::create_object(Main *bmain, const double /*motionSampleTime*/)
|
||||
{
|
||||
Mesh *mesh = BKE_mesh_add(bmain, name_.c_str());
|
||||
@@ -222,7 +220,7 @@ void USDMeshReader::read_object_data(Main *bmain, const double motionSampleTime)
|
||||
}
|
||||
|
||||
if (import_params_.import_skeletons) {
|
||||
import_mesh_skel_bindings(bmain, object_, prim_, reports());
|
||||
import_mesh_skel_bindings(object_, prim_, reports());
|
||||
}
|
||||
|
||||
USDXformReader::read_object_data(bmain, motionSampleTime);
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "usd_reader_xform.hh"
|
||||
#include "usd_utils.hh"
|
||||
|
||||
#include <pxr/pxr.h>
|
||||
#include <pxr/usd/usd/primRange.h>
|
||||
#include <pxr/usd/usdGeom/camera.h>
|
||||
#include <pxr/usd/usdGeom/capsule.h>
|
||||
@@ -180,7 +179,7 @@ static void find_prefix_to_skip(pxr::UsdStageRefPtr stage, ImportSettings &setti
|
||||
|
||||
USDStageReader::USDStageReader(pxr::UsdStageRefPtr stage,
|
||||
const USDImportParams ¶ms,
|
||||
std::function<CacheFile *()> get_cache_file_fn)
|
||||
const std::function<CacheFile *()> &get_cache_file_fn)
|
||||
: stage_(stage), params_(params)
|
||||
{
|
||||
convert_to_z_up(stage_, settings_);
|
||||
|
||||
@@ -59,7 +59,7 @@ class USDStageReader {
|
||||
public:
|
||||
USDStageReader(pxr::UsdStageRefPtr stage,
|
||||
const USDImportParams ¶ms,
|
||||
std::function<CacheFile *()> get_cache_file_fn = {});
|
||||
const std::function<CacheFile *()> &get_cache_file_fn = {});
|
||||
|
||||
~USDStageReader();
|
||||
|
||||
|
||||
@@ -964,12 +964,9 @@ void import_skeleton(Main *bmain,
|
||||
}
|
||||
}
|
||||
|
||||
void import_mesh_skel_bindings(Main *bmain,
|
||||
Object *mesh_obj,
|
||||
const pxr::UsdPrim &prim,
|
||||
ReportList *reports)
|
||||
void import_mesh_skel_bindings(Object *mesh_obj, const pxr::UsdPrim &prim, ReportList *reports)
|
||||
{
|
||||
if (!(bmain && mesh_obj && mesh_obj->type == OB_MESH && prim)) {
|
||||
if (!(mesh_obj && mesh_obj->type == OB_MESH && prim)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "BLI_map.hh"
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include <pxr/usd/usd/prim.h>
|
||||
#include <pxr/usd/usdGeom/xformCache.h>
|
||||
@@ -70,16 +69,12 @@ void import_skeleton(Main *bmain,
|
||||
* modifier on the given mesh object. If the USD prim does not have a skeleton
|
||||
* binding defined, this function is a no-op.
|
||||
*
|
||||
* \param bmain: Main pointer
|
||||
* \param obj: Mesh object to which an armature modifier will be added
|
||||
* \param mesh_obj: Mesh object to which an armature modifier will be added
|
||||
* \param prim: The USD primitive from which skinning data will be imported
|
||||
* \param reports: the storage for potential warning or error reports (generated using BKE_report
|
||||
* API).
|
||||
*/
|
||||
void import_mesh_skel_bindings(Main *bmain,
|
||||
Object *mesh_obj,
|
||||
const pxr::UsdPrim &prim,
|
||||
ReportList *reports);
|
||||
void import_mesh_skel_bindings(Object *mesh_obj, const pxr::UsdPrim &prim, ReportList *reports);
|
||||
|
||||
/**
|
||||
* Map an object to its USD prim export path.
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "DEG_depsgraph.hh"
|
||||
|
||||
#include "DNA_key_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
|
||||
#include "CLG_log.h"
|
||||
@@ -286,7 +287,7 @@ struct USDMeshData {
|
||||
pxr::VtArray<pxr::GfVec3f> points;
|
||||
pxr::VtIntArray face_vertex_counts;
|
||||
pxr::VtIntArray face_indices;
|
||||
Map<short, pxr::VtIntArray> face_groups;
|
||||
MaterialFaceGroups face_groups;
|
||||
|
||||
/* The length of this array specifies the number of creases on the surface. Each element gives
|
||||
* the number of (must be adjacent) vertices in each crease, whose indices are linearly laid out
|
||||
@@ -664,7 +665,7 @@ void USDGenericMeshWriter::assign_materials(const HierarchyContext &context,
|
||||
auto subset_material_api = pxr::UsdShadeMaterialBindingAPI(subset_prim);
|
||||
subset_material_api.Bind(usd_material);
|
||||
/* Apply the #MaterialBindingAPI applied schema, as required by USD. */
|
||||
subset_material_api.Apply(subset_prim);
|
||||
pxr::UsdShadeMaterialBindingAPI::Apply(subset_prim);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ namespace blender::io::usd {
|
||||
|
||||
struct USDMeshData;
|
||||
|
||||
/* Mapping from material slot number to array of face indices with that material. */
|
||||
using MaterialFaceGroups = Map<short, pxr::VtArray<int>>;
|
||||
|
||||
/* Writer for USD geometry. Does not assume the object is a mesh object. */
|
||||
class USDGenericMeshWriter : public USDAbstractWriter {
|
||||
public:
|
||||
@@ -32,9 +35,6 @@ class USDGenericMeshWriter : public USDAbstractWriter {
|
||||
virtual void free_export_mesh(Mesh *mesh);
|
||||
|
||||
private:
|
||||
/* Mapping from material slot number to array of face indices with that material. */
|
||||
using MaterialFaceGroups = Map<short, pxr::VtIntArray>;
|
||||
|
||||
void write_mesh(HierarchyContext &context, Mesh *mesh, const SubsurfModifierData *subsurfData);
|
||||
pxr::TfToken get_subdiv_scheme(const SubsurfModifierData *subsurfData);
|
||||
void write_subdiv(const pxr::TfToken &subdiv_scheme,
|
||||
|
||||
Reference in New Issue
Block a user