28 #include <pxr/base/tf/stringUtils.h>
30 #include <pxr/usd/usdGeom/scope.h>
37 static const pxr::TfToken
clearcoat(
"clearcoat", pxr::TfToken::Immortal);
39 static const pxr::TfToken
diffuse_color(
"diffuseColor", pxr::TfToken::Immortal);
40 static const pxr::TfToken
metallic(
"metallic", pxr::TfToken::Immortal);
41 static const pxr::TfToken
preview_shader(
"previewShader", pxr::TfToken::Immortal);
42 static const pxr::TfToken
preview_surface(
"UsdPreviewSurface", pxr::TfToken::Immortal);
43 static const pxr::TfToken
uv_texture(
"UsdUVTexture", pxr::TfToken::Immortal);
44 static const pxr::TfToken
primvar_float2(
"UsdPrimvarReader_float2", pxr::TfToken::Immortal);
45 static const pxr::TfToken
roughness(
"roughness", pxr::TfToken::Immortal);
46 static const pxr::TfToken
specular(
"specular", pxr::TfToken::Immortal);
47 static const pxr::TfToken
opacity(
"opacity", pxr::TfToken::Immortal);
48 static const pxr::TfToken
surface(
"surface", pxr::TfToken::Immortal);
49 static const pxr::TfToken
perspective(
"perspective", pxr::TfToken::Immortal);
50 static const pxr::TfToken
orthographic(
"orthographic", pxr::TfToken::Immortal);
51 static const pxr::TfToken
rgb(
"rgb", pxr::TfToken::Immortal);
52 static const pxr::TfToken
r(
"r", pxr::TfToken::Immortal);
53 static const pxr::TfToken
g(
"g", pxr::TfToken::Immortal);
54 static const pxr::TfToken
b(
"b", pxr::TfToken::Immortal);
55 static const pxr::TfToken
st(
"st", pxr::TfToken::Immortal);
56 static const pxr::TfToken
result(
"result", pxr::TfToken::Immortal);
57 static const pxr::TfToken
varname(
"varname", pxr::TfToken::Immortal);
58 static const pxr::TfToken
out(
"out", pxr::TfToken::Immortal);
59 static const pxr::TfToken
normal(
"normal", pxr::TfToken::Immortal);
60 static const pxr::TfToken
ior(
"ior", pxr::TfToken::Immortal);
61 static const pxr::TfToken
file(
"file", pxr::TfToken::Immortal);
62 static const pxr::TfToken
preview(
"preview", pxr::TfToken::Immortal);
63 static const pxr::TfToken
raw(
"raw", pxr::TfToken::Immortal);
64 static const pxr::TfToken
sRGB(
"sRGB", pxr::TfToken::Immortal);
65 static const pxr::TfToken
sourceColorSpace(
"sourceColorSpace", pxr::TfToken::Immortal);
66 static const pxr::TfToken
Shader(
"Shader", pxr::TfToken::Immortal);
71 static const pxr::TfToken
UVMap(
"UVMap", pxr::TfToken::Immortal);
100 pxr::UsdShadeMaterial &usd_material,
101 pxr::UsdShadeShader &usd_tex_shader,
102 const pxr::TfToken &default_uv);
104 const pxr::UsdStageRefPtr
stage,
105 const bool allow_overwrite =
false);
109 const pxr::UsdStageRefPtr
stage,
114 template<
typename T1,
typename T2>
119 pxr::UsdShadeMaterial &usd_material,
120 const std::string &default_uv)
127 pxr::UsdGeomScope::Define(usd_export_context.
stage,
132 pxr::TfToken(default_uv);
143 usd_export_context, usd_material,
node);
151 const InputSpecMap::const_iterator it = input_map.find(sock->name);
153 if (it == input_map.end()) {
157 pxr::UsdShadeShader created_shader;
161 const InputSpec &input_spec = it->second;
168 .ConnectToSource(created_shader.ConnectableAPI(), input_spec.
source_name);
172 switch (sock->type) {
174 create_input<bNodeSocketValueFloat, float>(
178 create_input<bNodeSocketValueVector, pxr::GfVec3f>(
182 create_input<bNodeSocketValueRGBA, pxr::GfVec3f>(
198 usd_export_context.
stage,
203 usd_export_context, input_node, usd_material, created_shader, default_uv_sampler);
209 pxr::UsdShadeMaterial &usd_material)
213 pxr::UsdShadeShader shader = pxr::UsdShadeShader::Define(usd_export_context.
stage, shader_path);
222 usd_material.CreateSurfaceOutput().ConnectToSource(shader.ConnectableAPI(),
usdtokens::surface);
240 {
"Clearcoat Roughness",
251 template<
typename T1,
typename T2>
254 const T1 *cast_value =
static_cast<const T1 *
>(value);
264 pxr::UsdShadeMaterial &usd_material,
265 pxr::UsdShadeShader &usd_tex_shader,
266 const pxr::TfToken &default_uv)
268 bool found_uv_node =
false;
273 if (!tex_node_sock->link || !
STREQ(tex_node_sock->name,
"Vector")) {
278 if (uv_node ==
nullptr) {
283 usd_export_context, usd_material, uv_node);
285 if (!uv_shader.GetPrim().IsValid()) {
289 found_uv_node =
true;
293 std::string uv_set = pxr::TfMakeValidIdentifier(shader_uv_map->uv_map);
296 .Set(pxr::TfToken(uv_set));
297 usd_tex_shader.CreateInput(
usdtokens::st, pxr::SdfValueTypeNames->Float2)
301 uv_shader.CreateInput(
usdtokens::varname, pxr::SdfValueTypeNames->Token).Set(default_uv);
302 usd_tex_shader.CreateInput(
usdtokens::st, pxr::SdfValueTypeNames->Float2)
307 if (!found_uv_node) {
315 if (uv_shader.GetPrim().IsValid()) {
316 uv_shader.CreateInput(
usdtokens::varname, pxr::SdfValueTypeNames->Token).Set(default_uv);
317 usd_tex_shader.CreateInput(
usdtokens::st, pxr::SdfValueTypeNames->Float2)
330 if (!(is_generated || is_dirty || is_packed)) {
345 strcpy(file_name, ima->
id.
name + 2);
353 const std::string &export_dir,
354 const bool allow_overwrite)
365 strcpy(file_name, ima->
id.
name + 2);
385 if (!allow_overwrite &&
BLI_exists(export_path)) {
394 std::cout <<
"Exporting in-memory texture to " << export_path << std::endl;
414 return pxr::TfToken();
426 return pxr::TfToken();
438 if (linked_node->
type == target_type) {
472 pxr::SdfPath shader_path =
material.GetPath()
474 .AppendChild(pxr::TfToken(pxr::TfMakeValidIdentifier(name)));
475 pxr::UsdShadeShader shader = pxr::UsdShadeShader::Define(usd_export_context.
stage, shader_path);
516 if (!imagePath.empty()) {
518 .Set(pxr::SdfAssetPath(imagePath));
522 if (!colorSpace.IsEmpty()) {
534 return std::string(filepath);
545 const pxr::UsdStageRefPtr
stage,
583 pxr::SdfLayerHandle layer =
stage->GetRootLayer();
584 std::string stage_path = layer->GetRealPath();
585 if (stage_path.empty()) {
599 pxr::SdfLayerHandle layer =
stage->GetRootLayer();
600 std::string stage_path = layer->GetRealPath();
601 if (stage_path.empty()) {
606 strcpy(rel_path, path.c_str());
622 const std::string &dest_dir,
623 const bool allow_overwrite)
633 std::cout <<
"WARNING: unsupported tile format for `" << src_path <<
"`" << std::endl;
642 src_tile_path, udim_pattern, tile_format,
tile->tile_number);
650 if (!allow_overwrite &&
BLI_exists(dest_tile_path)) {
659 std::cout <<
"Copying texture tile from " << src_tile_path <<
" to " << dest_tile_path
663 if (
BLI_copy(src_tile_path, dest_tile_path) != 0) {
665 "USD export: couldn't copy texture tile from %s to %s",
685 if (!allow_overwrite &&
BLI_exists(dest_path)) {
694 std::cout <<
"Copying texture from " << source_path <<
" to " << dest_path << std::endl;
697 if (
BLI_copy(source_path, dest_path) != 0) {
699 RPT_WARNING,
"USD export: couldn't copy texture from %s to %s", source_path, dest_path);
707 const pxr::UsdStageRefPtr
stage,
708 const bool allow_overwrite)
719 pxr::SdfLayerHandle layer =
stage->GetRootLayer();
720 std::string stage_path = layer->GetRealPath();
721 if (stage_path.empty()) {
737 std::string dest_dir(tex_dir_path);
739 if (is_generated || is_dirty || is_packed) {
int BKE_imbuf_write_as(struct ImBuf *ibuf, const char *name, const struct ImageFormatData *imf, bool save_copy)
void BKE_image_set_filepath_from_tile_number(char *filepath, const char *pattern, eUDIM_TILE_FORMAT tile_format, int tile_number)
struct ImBuf * BKE_image_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, void **r_lock)
bool BKE_image_has_packedfile(const struct Image *image)
bool BKE_image_is_dirty(struct Image *image)
char * BKE_image_get_tile_strformat(const char *filepath, eUDIM_TILE_FORMAT *r_tile_format)
#define SH_NODE_BSDF_PRINCIPLED
#define SH_NODE_TEX_ENVIRONMENT
#define SH_NODE_BSDF_DIFFUSE
File and directory operations.
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_dir_create_recursive(const char *dir) ATTR_NONNULL()
int BLI_copy(const char *file, const char *to) ATTR_NONNULL()
#define LISTBASE_FOREACH(type, var, list)
void BLI_split_dir_part(const char *string, char *dir, size_t dirlen)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void BLI_path_normalize(const char *relabase, char *path) ATTR_NONNULL(2)
size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path_first,...) ATTR_NONNULL(1
int BLI_path_cmp_normalized(const char *p1, const char *p2) ATTR_NONNULL(1
void BLI_path_rel(char *file, const char *relfile) ATTR_NONNULL()
void BLI_split_file_part(const char *string, char *file, size_t filelen)
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
bool IMB_colormanagement_space_name_is_srgb(const char *name)
bool IMB_colormanagement_space_name_is_data(const char *name)
Read Guarded memory(de)allocation.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks SH_NODE_TEX_COORD
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block SH_NODE_TEX_IMAGE
ColorManagedColorspaceSettings colorspace_settings
ccl_global const KernelWorkTile * tile
ccl_global KernelShaderEvalInput * input
static void export_in_memory_texture(Image *ima, const std::string &export_dir, const bool allow_overwrite)
static pxr::TfToken get_node_tex_image_color_space(bNode *node)
void create_usd_preview_surface_material(const USDExporterContext &usd_export_context, Material *material, pxr::UsdShadeMaterial &usd_material, const std::string &default_uv)
static void copy_single_file(Image *ima, const std::string &dest_dir, const bool allow_overwrite)
static bNode * traverse_channel(bNodeSocket *input, short target_type)
void create_input(pxr::UsdShadeShader &shader, const InputSpec &spec, const void *value)
static void copy_tiled_textures(Image *ima, const std::string &dest_dir, const bool allow_overwrite)
static std::string get_in_memory_texture_filename(Image *ima)
std::map< std::string, InputSpec > InputSpecMap
static InputSpecMap & preview_surface_input_map()
static void export_texture(bNode *node, const pxr::UsdStageRefPtr stage, const bool allow_overwrite=false)
static bNode * find_bsdf_node(Material *material)
void create_usd_viewport_material(const USDExporterContext &usd_export_context, Material *material, pxr::UsdShadeMaterial &usd_material)
static void create_uvmap_shader(const USDExporterContext &usd_export_context, bNode *tex_node, pxr::UsdShadeMaterial &usd_material, pxr::UsdShadeShader &usd_tex_shader, const pxr::TfToken &default_uv)
static pxr::UsdShadeShader create_usd_preview_shader(const USDExporterContext &usd_export_context, pxr::UsdShadeMaterial &material, const char *name, int type)
static std::string get_tex_image_asset_path(bNode *node, const pxr::UsdStageRefPtr stage, const USDExportParams &export_params)
static void get_absolute_path(Image *ima, char *r_path)
static const pxr::TfToken UVMap("UVMap", pxr::TfToken::Immortal)
static const pxr::TfToken sRGB("sRGB", pxr::TfToken::Immortal)
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
static const pxr::TfToken opacity("opacity", pxr::TfToken::Immortal)
static const pxr::TfToken preview_shader("previewShader", pxr::TfToken::Immortal)
static const pxr::TfToken sourceColorSpace("sourceColorSpace", pxr::TfToken::Immortal)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken clearcoat("clearcoat", pxr::TfToken::Immortal)
static const pxr::TfToken perspective("perspective", pxr::TfToken::Immortal)
static const pxr::TfToken varname("varname", pxr::TfToken::Immortal)
static const pxr::TfToken surface("surface", pxr::TfToken::Immortal)
static const pxr::TfToken r("r", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken ior("ior", pxr::TfToken::Immortal)
static const pxr::TfToken result("result", pxr::TfToken::Immortal)
static const pxr::TfToken raw("raw", pxr::TfToken::Immortal)
static const pxr::TfToken orthographic("orthographic", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
static const pxr::TfToken clearcoatRoughness("clearcoatRoughness", pxr::TfToken::Immortal)
static const pxr::TfToken file("file", pxr::TfToken::Immortal)
static const pxr::TfToken normal("normal", pxr::TfToken::Immortal)
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
static const pxr::TfToken metallic("metallic", pxr::TfToken::Immortal)
static const pxr::TfToken specular("specular", pxr::TfToken::Immortal)
static const pxr::TfToken preview("preview", pxr::TfToken::Immortal)
static const pxr::TfToken diffuse_color("diffuseColor", pxr::TfToken::Immortal)
static const pxr::TfToken primvar_float2("UsdPrimvarReader_float2", pxr::TfToken::Immortal)
static const pxr::TfToken uv_texture("UsdUVTexture", pxr::TfToken::Immortal)
static const pxr::TfToken rgb("rgb", pxr::TfToken::Immortal)
static const pxr::TfToken preview_surface("UsdPreviewSurface", pxr::TfToken::Immortal)
static const pxr::TfToken Shader("Shader", pxr::TfToken::Immortal)
struct bNodeTree * nodetree
const USDExportParams & export_params
const pxr::UsdStageRefPtr stage
void WM_reportf(eReportType type, const char *format,...)