[Bf-blender-cvs] [fb1f756bd15] universal-scene-description: USD export to USDZ.
Michael Kowalski
noreply at git.blender.org
Tue Sep 27 00:21:14 CEST 2022
Commit: fb1f756bd1591d6033f6ef0bcf068f13681feb29
Author: Michael Kowalski
Date: Mon Sep 26 18:19:42 2022 -0400
Branches: universal-scene-description
https://developer.blender.org/rBfb1f756bd1591d6033f6ef0bcf068f13681feb29
USD export to USDZ.
USDZ export code developed by Sonny Campbell in
patch D15623, which is currently under review.
Charles added USDZ Texture downsample export functionality
and a switch for creating ARKit assets during USDZ export.
===================================================================
M release/scripts/startup/bl_ui/space_topbar.py
M source/blender/blenkernel/BKE_image.h
M source/blender/blenkernel/intern/cachefile.c
M source/blender/blenkernel/intern/image.cc
M source/blender/blenlib/BLI_fileops.h
M source/blender/blenlib/intern/fileops.c
M source/blender/blenlib/intern/storage.c
M source/blender/editors/io/io_usd.c
M source/blender/editors/space_file/filelist.c
M source/blender/io/usd/intern/usd_capi_export.cc
M source/blender/io/usd/usd.h
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index da089ea23b0..9583e54e7c3 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -453,7 +453,7 @@ class TOPBAR_MT_file_import(Menu):
self.layout.operator("wm.alembic_import", text="Alembic (.abc)")
if bpy.app.build_options.usd:
self.layout.operator(
- "wm.usd_import", text="Universal Scene Description (.usd, .usdc, .usda)")
+ "wm.usd_import", text="Universal Scene Description (.usd*)")
if bpy.app.build_options.io_gpencil:
self.layout.operator("wm.gpencil_import_svg", text="SVG as Grease Pencil")
@@ -476,7 +476,7 @@ class TOPBAR_MT_file_export(Menu):
self.layout.operator("wm.alembic_export", text="Alembic (.abc)")
if bpy.app.build_options.usd:
self.layout.operator(
- "wm.usd_export", text="Universal Scene Description (.usd, .usdc, .usda)")
+ "wm.usd_export", text="Universal Scene Description (.usd*)")
if bpy.app.build_options.io_gpencil:
# Pugixml lib dependency
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index eb43ce823ac..8d186e967f2 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -165,6 +165,7 @@ void BKE_image_alpha_mode_from_extension(struct Image *image);
/**
* Returns a new image or NULL if it can't load.
*/
+struct Image *BKE_image_load_ex(struct Main *bmain, const char *filepath, int flag);
struct Image *BKE_image_load(struct Main *bmain, const char *filepath);
/**
* Returns existing Image when filename/type is same.
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index fd83ac50cad..b8ee2a1d20b 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -366,7 +366,7 @@ void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file
}
#endif
#ifdef WITH_USD
- if (BLI_path_extension_check_glob(filepath, "*.usd;*.usda;*.usdc")) {
+ if (BLI_path_extension_check_glob(filepath, "*.usd;*.usda;*.usdc;*.usdz")) {
cache_file->type = CACHEFILE_TYPE_USD;
cache_file->handle = USD_create_handle(bmain, filepath, &cache_file->object_paths);
BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX);
diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc
index ae24383e5b9..d57ec83ae61 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -666,11 +666,11 @@ static void image_init(Image *ima, short source, short type)
ima->stereo3d_format = MEM_cnew<Stereo3dFormat>("Image Stereo Format");
}
-static Image *image_alloc(Main *bmain, const char *name, short source, short type)
+static Image *image_alloc_ex(Main *bmain, const char *name, short source, short type, int flag)
{
Image *ima;
- ima = static_cast<Image *>(BKE_libblock_alloc(bmain, ID_IM, name, 0));
+ ima = static_cast<Image *>(BKE_libblock_alloc(bmain, ID_IM, name, flag));
if (ima) {
image_init(ima, source, type);
}
@@ -678,6 +678,11 @@ static Image *image_alloc(Main *bmain, const char *name, short source, short typ
return ima;
}
+static Image *image_alloc(Main *bmain, const char *name, short source, short type)
+{
+ return image_alloc_ex(bmain, name, source, type, 0);
+}
+
/**
* Get the ibuf from an image cache by its index and entry.
* Local use here only.
@@ -1006,7 +1011,7 @@ void BKE_image_alpha_mode_from_extension(Image *image)
image->alpha_mode = BKE_image_alpha_mode_from_extension_ex(image->filepath);
}
-Image *BKE_image_load(Main *bmain, const char *filepath)
+Image *BKE_image_load_ex(Main *bmain, const char *filepath, int flag)
{
Image *ima;
int file;
@@ -1026,7 +1031,7 @@ Image *BKE_image_load(Main *bmain, const char *filepath)
close(file);
}
- ima = image_alloc(bmain, BLI_path_basename(filepath), IMA_SRC_FILE, IMA_TYPE_IMAGE);
+ ima = image_alloc_ex(bmain, BLI_path_basename(filepath), IMA_SRC_FILE, IMA_TYPE_IMAGE, flag);
STRNCPY(ima->filepath, filepath);
if (BLI_path_extension_check_array(filepath, imb_ext_movie)) {
@@ -1038,6 +1043,11 @@ Image *BKE_image_load(Main *bmain, const char *filepath)
return ima;
}
+Image *BKE_image_load(Main *bmain, const char *filepath)
+{
+ return BKE_image_load_ex(bmain, filepath, 0);
+}
+
Image *BKE_image_load_exists_ex(Main *bmain, const char *filepath, bool *r_exists)
{
Image *ima;
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index 063e60ecf03..6dd24db8834 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -141,6 +141,12 @@ double BLI_dir_free_space(const char *dir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(
*/
char *BLI_current_working_dir(char *dir, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
eFileAttributes BLI_file_attributes(const char *path);
+/**
+ * Changes the current working directory to the provided path.
+ *
+ * \return true on success, false otherwise.
+ */
+bool BLI_change_working_dir(char *dir);
/** \} */
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 3abd482d6b3..9844adfd011 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -458,7 +458,7 @@ int BLI_delete_soft(const char *file, const char **error_message)
return err;
}
-/* Not used anywhere! */
+/* Not used anywhere! Convention is to use BLI_rename. */
# if 0
int BLI_move(const char *file, const char *to)
{
@@ -822,8 +822,8 @@ static int delete_soft(const char *file, const char **error_message)
Class NSStringClass = objc_getClass("NSString");
SEL stringWithUTF8StringSel = sel_registerName("stringWithUTF8String:");
- id pathString = ((
- id(*)(Class, SEL, const char *))objc_msgSend)(NSStringClass, stringWithUTF8StringSel, file);
+ id pathString = ((id(*)(Class, SEL, const char *))objc_msgSend)(
+ NSStringClass, stringWithUTF8StringSel, file);
Class NSFileManagerClass = objc_getClass("NSFileManager");
SEL defaultManagerSel = sel_registerName("defaultManager");
@@ -834,8 +834,8 @@ static int delete_soft(const char *file, const char **error_message)
id nsurl = ((id(*)(Class, SEL, id))objc_msgSend)(NSURLClass, fileURLWithPathSel, pathString);
SEL trashItemAtURLSel = sel_registerName("trashItemAtURL:resultingItemURL:error:");
- BOOL deleteSuccessful = ((
- BOOL(*)(id, SEL, id, id, id))objc_msgSend)(fileManager, trashItemAtURLSel, nsurl, nil, nil);
+ BOOL deleteSuccessful = ((BOOL(*)(id, SEL, id, id, id))objc_msgSend)(
+ fileManager, trashItemAtURLSel, nsurl, nil, nil);
if (deleteSuccessful) {
ret = 0;
@@ -1123,7 +1123,7 @@ static int copy_single_file(const char *from, const char *to)
return RecursiveOp_Callback_OK;
}
-/* Not used anywhere! */
+/* Not used anywhere! Convention is to use BLI_rename. */
# if 0
static int move_callback_pre(const char *from, const char *to)
{
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 4fa5ca0c088..6faa8754640 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -56,6 +56,22 @@
#include "BLI_string.h"
#include "BLI_utildefines.h"
+bool BLI_change_working_dir(char *dir)
+{
+ if (!BLI_is_dir(dir)) {
+ return false;
+ }
+#if defined(WIN32)
+ wchar_t wdir[FILE_MAX];
+ if (conv_utf_8_to_16(dir, wdir, ARRAY_SIZE(wdir)) != 0) {
+ return false;
+ }
+ return _wchdir(wdir) == 0;
+#else
+ return chdir(dir) == 0;
+#endif
+}
+
char *BLI_current_working_dir(char *dir, const size_t maxncpy)
{
#if defined(WIN32)
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 09d796fc315..044d5dfad44 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -152,6 +152,17 @@ const EnumPropertyItem rna_enum_usd_attr_import_mode_items[] = {
{0, NULL, 0, NULL, NULL},
};
+const EnumPropertyItem prop_usdz_downscale_size[] = {
+ {USD_TEXTURE_SIZE_KEEP, "KEEP", 0, "Keep", "Keep all current texture sizes"},
+ {USD_TEXTURE_SIZE_256, "256", 0, "256", "Resize to a maximum of 256 pixels"},
+ {USD_TEXTURE_SIZE_512, "512", 0, "512", "Resize to a maximum of 512 pixels"},
+ {USD_TEXTURE_SIZE_1024, "1024", 0, "1024", "Resize to a maximum of 1024 pixels"},
+ {USD_TEXTURE_SIZE_2048, "2048", 0, "2048", "Resize to a maximum of 256 pixels"},
+ {USD_TEXTURE_SIZE_4096, "4096", 0, "4096", "Resize to a maximum of 256 pixels"},
+ {USD_TEXTURE_SIZE_CUSTOM, "CUSTOM", 0, "Custom", "Specify a custom size"},
+ {0, NULL, 0, NULL, NULL},
+};
+
/* Stored in the wmOperator's customdata field to indicate it should run as a background job.
* This is set when the operator is invoked, and not set when it is only executed. */
enum { AS_BACKGROUND_JOB = 1 };
@@ -303,6 +314,12 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
const bool export_blendshapes = RNA_boolean_get(op->ptr, "export_blendshapes");
+ const eUSDZTextureDownscaleSize usdz_downscale_size = RNA_enum_get(op->ptr, "usdz_downscale_size");
+
+ const int usdz_downscale_custom_size = RNA_int_get(op->ptr, "usdz_downscale_custom_size");
+
+ const bool usdz_is_arkit = RNA_boolean_get(op->ptr, "usdz_is_arkit");
+
const bool export_blender_metadata = RNA_boolean_get(op->ptr, "export_blender_metadata");
struct USDExportParams params = {RNA_int_get(op->ptr, "start"),
@@ -362,6 +379,9 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
fix_skel_root,
overwrite_textures,
export_blendshapes,
+ usdz_downscale_size,
+ usdz_downscale_custom_size,
+ usdz_is_a
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list