5#include "testing/testing.h"
8#include <pxr/base/tf/stringUtils.h>
9#include <pxr/base/vt/types.h>
10#include <pxr/base/vt/value.h>
11#include <pxr/usd/sdf/types.h>
12#include <pxr/usd/usd/common.h>
13#include <pxr/usd/usd/prim.h>
14#include <pxr/usd/usd/stage.h>
15#include <pxr/usd/usdGeom/mesh.h>
73 BlendfileLoadingBaseTest::SetUp();
89 for (
auto child : prim.GetChildren()) {
90 if (child.IsA<pxr::UsdGeomMesh>()) {
94 return pxr::UsdPrim();
103 ASSERT_NE(bsdf_node,
nullptr);
104 ASSERT_TRUE(
bool(bsdf_prim));
106 for (
const auto *socket : bsdf_node->input_sockets()) {
108 if (attribute_token.IsEmpty()) {
113 const pxr::UsdAttribute bsdf_attribute = bsdf_prim.GetAttribute(attribute_token);
114 pxr::SdfPathVector paths;
115 bsdf_attribute.GetConnections(&paths);
116 if (!paths.empty() || !bsdf_attribute.IsValid()) {
121 const float socket_value_f = *socket->default_value_typed<
float>();
122 const float3 socket_value_3f = *socket->default_value_typed<
float3>();
123 float attribute_value_f;
124 pxr::GfVec3f attribute_value_3f;
126 switch (socket->type) {
128 bsdf_attribute.Get(&attribute_value_f, 0.0);
129 EXPECT_FLOAT_EQ(socket_value_f, attribute_value_f);
133 bsdf_attribute.Get(&attribute_value_3f, 0.0);
134 EXPECT_FLOAT_EQ(socket_value_3f[0], attribute_value_3f[0]);
135 EXPECT_FLOAT_EQ(socket_value_3f[1], attribute_value_3f[1]);
136 EXPECT_FLOAT_EQ(socket_value_3f[2], attribute_value_3f[2]);
140 bsdf_attribute.Get(&attribute_value_3f, 0.0);
141 EXPECT_FLOAT_EQ(socket_value_3f[0], attribute_value_3f[0]);
142 EXPECT_FLOAT_EQ(socket_value_3f[1], attribute_value_3f[1]);
143 EXPECT_FLOAT_EQ(socket_value_3f[2], attribute_value_3f[2]);
147 FAIL() <<
"Socket " << socket->name <<
" has unsupported type " << socket->type;
154 const pxr::UsdPrim &image_prim)
158 const pxr::UsdShadeShader image_shader(image_prim);
159 const pxr::UsdShadeInput file_input = image_shader.GetInput(pxr::TfToken(
"file"));
162 pxr::VtValue file_val;
164 EXPECT_TRUE(file_val.IsHolding<pxr::SdfAssetPath>());
166 pxr::SdfAssetPath image_prim_asset = file_val.Get<pxr::SdfAssetPath>();
181 pxr::VtIntArray face_indices;
182 pxr::VtIntArray face_counts;
183 pxr::VtVec3fArray positions;
184 pxr::VtVec3fArray normals;
188 mesh_prim.GetFaceVertexIndicesAttr().Get(&face_indices, 0.0);
189 mesh_prim.GetFaceVertexCountsAttr().Get(&face_counts, 0.0);
190 mesh_prim.GetPointsAttr().Get(&positions, 0.0);
191 mesh_prim.GetNormalsAttr().Get(&normals, 0.0);
196 switch (
mesh->normals_domain()) {
198 EXPECT_EQ(mesh_prim.GetNormalsInterpolation(), pxr::UsdGeomTokens->vertex);
203 EXPECT_EQ(mesh_prim.GetNormalsInterpolation(), pxr::UsdGeomTokens->uniform);
208 EXPECT_EQ(mesh_prim.GetNormalsInterpolation(), pxr::UsdGeomTokens->faceVarying);
224 EXPECT_EQ(bfile->main->objects.count(), 3);
235 ASSERT_TRUE(
bool(stage)) <<
"Unable to load Stage from " <<
output_filename;
240 for (
Object &
object : bfile->main->objects) {
244 const pxr::SdfPath sdf_path(
"/" + pxr::TfMakeValidIdentifier(object_name.
c_str()));
245 pxr::UsdPrim prim = stage->GetPrimAtPath(sdf_path);
248 const pxr::UsdGeomMesh mesh_prim(get_first_child_mesh(prim));
251 compare_blender_mesh_to_usd_prim(
mesh, mesh_prim);
258 auto found_nodes = nodetree->nodes_by_type(type_idname);
259 if (found_nodes.size() == 1) {
260 return found_nodes[0];
280 EXPECT_EQ(bfile->main->objects.count(), 6);
282 EXPECT_EQ(bfile->main->materials.count(), 7);
303 ASSERT_NE(stage,
nullptr) <<
"Unable to open exported stage: " <<
output_filename;
305 material->nodetree->ensure_topology_cache();
307 "ShaderNodeBsdfPrincipled"_ustr);
309 const std::string prim_name = pxr::TfMakeValidIdentifier(bsdf_node->
name);
310 const pxr::UsdPrim bsdf_prim = stage->GetPrimAtPath(
311 pxr::SdfPath(
"/_materials/Material/" + prim_name));
313 compare_blender_node_to_usd_prim(bsdf_node, bsdf_prim);
316 "ShaderNodeTexImage"_ustr);
317 ASSERT_NE(image_node,
nullptr);
318 ASSERT_NE(image_node->
storage,
nullptr);
320 const std::string image_prim_name = pxr::TfMakeValidIdentifier(image_node->
name);
322 const pxr::UsdPrim image_prim = stage->GetPrimAtPath(
323 pxr::SdfPath(
"/_materials/Material/" + image_prim_name));
325 ASSERT_TRUE(
bool(image_prim)) <<
"Unable to find Material prim from exported stage "
328 compare_blender_image_to_usd_image_shader(image_node, image_prim);
342 ASSERT_EQ(
make_safe_name(
"test:test",
false), std::string(
"test_test"));
345 ASSERT_EQ(
make_safe_name(
"Test|$bézier @ world",
false), std::string(
"Test__b_zier___world"));
346 ASSERT_EQ(
make_safe_name(
"Test|ハローワールド",
false), std::string(
"Test________"));
347 ASSERT_EQ(
make_safe_name(
"Test|Γεια σου κόσμε",
false), std::string(
"Test_______________"));
348 ASSERT_EQ(
make_safe_name(
"Test|∧hello ○ wórld",
false), std::string(
"Test__hello___w_rld"));
359 ASSERT_EQ(
make_safe_name(
"test:test",
true), std::string(
"test_test"));
362 ASSERT_EQ(
make_safe_name(
"Test|$bézier @ world",
true), std::string(
"Test__bézier___world"));
363 ASSERT_EQ(
make_safe_name(
"Test|ハローワールド",
true), std::string(
"Test_ハローワールド"));
364 ASSERT_EQ(
make_safe_name(
"Test|Γεια σου κόσμε",
true), std::string(
"Test_Γεια_σου_κόσμε"));
365 ASSERT_EQ(
make_safe_name(
"Test|∧hello ○ wórld",
true), std::string(
"Test__hello___wórld"));
File and directory operations.
external readfile function prototypes.
struct BlendFileData * bfile
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
bool blendfile_load(const char *filepath)
constexpr const char * c_str() const
pxr::UsdPrim get_first_child_mesh(const pxr::UsdPrim prim)
void compare_blender_image_to_usd_image_shader(const bNode *image_node, const pxr::UsdPrim &image_prim)
void compare_blender_node_to_usd_prim(const bNode *bsdf_node, const pxr::UsdPrim &bsdf_prim)
void compare_blender_mesh_to_usd_prim(const Mesh *mesh, const pxr::UsdGeomMesh &mesh_prim)
bool load_file_and_depsgraph(const StringRefNull &filepath, const eEvaluationMode eval_mode=DAG_EVAL_VIEWPORT)
#define EXPECT_TRUE(result)
static const bNode * find_node_for_type_in_graph(const bNodeTree *nodetree, const UString type_idname)
pxr::TfToken token_for_input(const StringRef input_name)
TEST_F(UsdExportTest, usd_export_rain_mesh)
TEST(utilities, make_safe_name)
std::string make_safe_name(const StringRef name, bool allow_unicode)
const StringRefNull simple_scene_filename
const StringRefNull materials_filename
bool USD_export(const bContext *C, const char *filepath, const USDExportParams *params, bool as_background_job, ReportList *reports)
const StringRefNull output_filename
std::string make_safe_primvar_name(const StringRef name, bool allow_unicode)
ID * BKE_libblock_find_name(Main *bmain, short type, const char *name, const std::optional< Library * > lib=std::nullopt) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BMesh const char void * data
int BLI_path_cmp_normalized(const char *p1, const char *p2) ATTR_NONNULL(1
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
void CTX_free(bContext *C)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void CTX_data_main_set(bContext *C, Main *bmain)
VecBase< float, 3 > float3
void CTX_data_scene_set(bContext *C, Scene *scene)
bool generate_preview_surface
bool generate_materialx_network
bool convert_world_material