5#include "testing/testing.h"
8#include <pxr/base/plug/registry.h>
9#include <pxr/base/tf/stringUtils.h>
10#include <pxr/base/vt/types.h>
11#include <pxr/base/vt/value.h>
12#include <pxr/usd/sdf/types.h>
13#include <pxr/usd/usd/prim.h>
14#include <pxr/usd/usd/stage.h>
15#include <pxr/usd/usdGeom/mesh.h>
16#include <pxr/usd/usdGeom/subset.h>
17#include <pxr/usd/usdGeom/tokens.h>
74 BlendfileLoadingBaseTest::SetUp();
90 for (
auto child : prim.GetChildren()) {
91 if (child.IsA<pxr::UsdGeomMesh>()) {
95 return pxr::UsdPrim();
103 const pxr::UsdPrim &bsdf_prim)
105 ASSERT_NE(bsdf_node,
nullptr);
106 ASSERT_TRUE(
bool(bsdf_prim));
108 for (
auto socket : bsdf_node->input_sockets()) {
110 if (attribute_token.IsEmpty()) {
115 const pxr::UsdAttribute bsdf_attribute = bsdf_prim.GetAttribute(attribute_token);
116 pxr::SdfPathVector paths;
117 bsdf_attribute.GetConnections(&paths);
118 if (!paths.empty() || !bsdf_attribute.IsValid()) {
123 const float socket_value_f = *socket->default_value_typed<
float>();
124 const float3 socket_value_3f = *socket->default_value_typed<
float3>();
125 float attribute_value_f;
126 pxr::GfVec3f attribute_value_3f;
128 switch (socket->type) {
130 bsdf_attribute.Get(&attribute_value_f, 0.0);
131 EXPECT_FLOAT_EQ(socket_value_f, attribute_value_f);
135 bsdf_attribute.Get(&attribute_value_3f, 0.0);
136 EXPECT_FLOAT_EQ(socket_value_3f[0], attribute_value_3f[0]);
137 EXPECT_FLOAT_EQ(socket_value_3f[1], attribute_value_3f[1]);
138 EXPECT_FLOAT_EQ(socket_value_3f[2], attribute_value_3f[2]);
142 bsdf_attribute.Get(&attribute_value_3f, 0.0);
143 EXPECT_FLOAT_EQ(socket_value_3f[0], attribute_value_3f[0]);
144 EXPECT_FLOAT_EQ(socket_value_3f[1], attribute_value_3f[1]);
145 EXPECT_FLOAT_EQ(socket_value_3f[2], attribute_value_3f[2]);
149 FAIL() <<
"Socket " << socket->name <<
" has unsupported type " << socket->type;
156 const pxr::UsdPrim &image_prim)
158 const Image *image =
reinterpret_cast<Image *
>(image_node->
id);
160 const pxr::UsdShadeShader image_shader(image_prim);
161 const pxr::UsdShadeInput file_input = image_shader.GetInput(pxr::TfToken(
"file"));
162 EXPECT_TRUE(
bool(file_input));
164 pxr::VtValue file_val;
165 EXPECT_TRUE(file_input.Get(&file_val));
166 EXPECT_TRUE(file_val.IsHolding<pxr::SdfAssetPath>());
168 pxr::SdfAssetPath image_prim_asset = file_val.Get<pxr::SdfAssetPath>();
183 pxr::VtIntArray face_indices;
184 pxr::VtIntArray face_counts;
185 pxr::VtVec3fArray positions;
190 mesh_prim.GetFaceVertexIndicesAttr().Get(&face_indices, 0.0);
191 mesh_prim.GetFaceVertexCountsAttr().Get(&face_counts, 0.0);
192 mesh_prim.GetPointsAttr().Get(&positions, 0.0);
193 mesh_prim.GetNormalsAttr().Get(&normals, 0.0);
195 EXPECT_EQ(mesh->verts_num, positions.size());
196 EXPECT_EQ(mesh->faces_num, face_counts.size());
197 EXPECT_EQ(mesh->corners_num, face_indices.size());
198 EXPECT_EQ(mesh->corners_num, normals.size());
213 params.export_materials =
false;
214 params.export_normals =
true;
215 params.export_uvmaps =
false;
216 params.visible_objects_only =
true;
228 const Mesh *mesh =
static_cast<Mesh *
>(
object->data);
231 const pxr::SdfPath sdf_path(
"/" + pxr::TfMakeValidIdentifier(object_name.
c_str()));
232 pxr::UsdPrim prim =
stage->GetPrimAtPath(sdf_path);
233 EXPECT_TRUE(
bool(prim));
235 const pxr::UsdGeomMesh mesh_prim(get_first_child_mesh(prim));
236 EXPECT_TRUE(
bool(mesh_prim));
238 compare_blender_mesh_to_usd_prim(mesh, mesh_prim);
245 auto found_nodes = nodetree->nodes_by_type(type_idname);
246 if (found_nodes.size() == 1) {
247 return found_nodes[0];
274 EXPECT_TRUE(
bool(material));
277 params.export_materials =
true;
278 params.export_normals =
true;
279 params.export_textures =
false;
280 params.export_uvmaps =
true;
281 params.generate_preview_surface =
true;
282 params.generate_materialx_network =
false;
283 params.convert_world_material =
false;
284 params.relative_paths =
false;
287 ASSERT_TRUE(result) <<
"Unable to export stage to " <<
output_filename;
292 material->nodetree->ensure_topology_cache();
294 "ShaderNodeBsdfPrincipled");
296 const std::string prim_name = pxr::TfMakeValidIdentifier(bsdf_node->
name);
297 const pxr::UsdPrim bsdf_prim =
stage->GetPrimAtPath(
298 pxr::SdfPath(
"/_materials/Material/" + prim_name));
300 compare_blender_node_to_usd_prim(bsdf_node, bsdf_prim);
303 ASSERT_NE(image_node,
nullptr);
304 ASSERT_NE(image_node->
storage,
nullptr);
306 const std::string image_prim_name = pxr::TfMakeValidIdentifier(image_node->
name);
308 const pxr::UsdPrim image_prim =
stage->GetPrimAtPath(
309 pxr::SdfPath(
"/_materials/Material/" + image_prim_name));
311 ASSERT_TRUE(
bool(image_prim)) <<
"Unable to find Material prim from exported stage "
314 compare_blender_image_to_usd_image_shader(image_node, image_prim);
324 ASSERT_EQ(
make_safe_name(
"Test|$bézier @ world",
false), std::string(
"Test__b__zier___world"));
326 std::string(
"Test______________________"));
328 std::string(
"Test___________________________"));
329 ASSERT_EQ(
make_safe_name(
"Test|∧hello ○ wórld",
false), std::string(
"Test____hello_____w__rld"));
331#if PXR_VERSION >= 2403
337 ASSERT_EQ(
make_safe_name(
"Test|$bézier @ world",
true), std::string(
"Test__bézier___world"));
338 ASSERT_EQ(
make_safe_name(
"Test|ハローワールド",
true), std::string(
"Test_ハローワールド"));
339 ASSERT_EQ(
make_safe_name(
"Test|Γεια σου κόσμε",
true), std::string(
"Test_Γεια_σου_κόσμε"));
340 ASSERT_EQ(
make_safe_name(
"Test|∧hello ○ wórld",
true), std::string(
"Test__hello___wórld"));
void CTX_data_main_set(bContext *C, Main *bmain)
void CTX_free(bContext *C)
void CTX_data_scene_set(bContext *C, Scene *scene)
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()
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
File and directory operations.
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
#define LISTBASE_FOREACH(type, var, list)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_path_cmp_normalized(const char *p1, const char *p2) ATTR_NONNULL(1
external readfile function prototypes.
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
bool blendfile_load(const char *filepath)
struct BlendFileData * bfile
constexpr const char * c_str() const
virtual void TearDown() override
const void compare_blender_mesh_to_usd_prim(const Mesh *mesh, const pxr::UsdGeomMesh &mesh_prim)
const void compare_blender_node_to_usd_prim(const bNode *bsdf_node, const pxr::UsdPrim &bsdf_prim)
const void compare_blender_image_to_usd_image_shader(const bNode *image_node, const pxr::UsdPrim &image_prim)
virtual void SetUp() override
const pxr::UsdPrim get_first_child_mesh(const pxr::UsdPrim prim)
bool load_file_and_depsgraph(const StringRefNull &filepath, const eEvaluationMode eval_mode=DAG_EVAL_VIEWPORT)
static float normals[][3]
pxr::TfToken token_for_input(const char *input_name)
static const bNode * find_node_for_type_in_graph(const bNodeTree *nodetree, const blender::StringRefNull type_idname)
std::string make_safe_name(const std::string &name, bool allow_unicode)
TEST(utilities, make_safe_name)
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
TEST_F(UsdCurvesTest, usd_export_curves)