50 #include <pxr/usd/usd/stage.h>
51 #include <pxr/usd/usdGeom/metrics.h>
52 #include <pxr/usd/usdGeom/scope.h>
53 #include <pxr/usd/usdGeom/tokens.h>
54 #include <pxr/usd/usdGeom/xformCommonAPI.h>
72 if (!
object.IsValid()) {
76 for (
const pxr::UsdPrim &childPrim :
object.GetChildren()) {
83 BLI_strncpy(usd_path->
path,
object.GetPrimPath().GetString().c_str(),
sizeof(usd_path->
path));
93 if (!
stage || pxr::UsdGeomGetStageUpAxis(
stage) == pxr::UsdGeomTokens->
z) {
105 float axis[3] = {1.0f, 0.0f, 0.0f};
142 std::cout <<
"USD import of '" <<
data->filepath <<
"' took ";
147 static void import_startjob(
void *customdata,
short *stop,
short *do_update,
float *progress)
152 data->do_update = do_update;
153 data->progress = progress;
154 data->was_canceled =
false;
155 data->archive =
nullptr;
156 data->start_time = timeit::Clock::now();
161 if (
data->params.create_collection) {
162 char display_name[1024];
166 data->bmain,
data->scene->master_collection, display_name);
175 data->view_layer, import_collection);
192 data->settings.cache_file = cache_file;
194 *
data->do_update =
true;
195 *
data->progress = 0.05f;
198 data->was_canceled =
true;
202 *
data->do_update =
true;
203 *
data->progress = 0.1f;
205 pxr::UsdStageRefPtr
stage = pxr::UsdStage::Open(
data->filepath);
209 data->import_ok =
false;
216 if (
data->params.set_frame_range) {
217 data->scene->r.sfra =
stage->GetStartTimeCode();
218 data->scene->r.efra =
stage->GetEndTimeCode();
221 *
data->do_update =
true;
222 *
data->progress = 0.15f;
226 data->archive = archive;
230 *
data->do_update =
true;
231 *
data->progress = 0.2f;
233 const float size =
static_cast<float>(archive->
readers().size());
239 *
data->do_update =
true;
240 *
data->progress = 0.25f;
247 reader->create_object(
data->bmain, 0.0);
248 if ((++i & 1023) == 0) {
249 *
data->do_update =
true;
250 *
data->progress = 0.25f + 0.25f * (i /
size);
262 Object *ob = reader->object();
264 reader->read_object_data(
data->bmain, 0.0);
268 if (parent ==
nullptr) {
275 *
data->progress = 0.5f + 0.5f * (++i /
size);
276 *
data->do_update =
true;
279 data->was_canceled =
true;
284 data->import_ok = !
data->was_canceled;
295 if (
data->was_canceled &&
data->archive) {
305 if (
Object *ob = reader->object()) {
310 else if (
data->archive) {
325 Object *ob = reader->object();
339 Object *ob = reader->object();
360 switch (
data->error_code) {
363 data->import_ok = !
data->was_canceled;
366 WM_report(
RPT_ERROR,
"Could not open USD archive for reading! See console for detail.");
378 delete data->archive;
387 const char *filepath,
389 bool as_background_job)
416 bool import_ok =
false;
417 if (as_background_job) {
434 short stop = 0, do_update = 0;
435 float progress = 0.0f;
454 pxr::UsdPrim iobject = usd_reader->
prim();
456 if (!iobject.IsValid()) {
457 *err_str =
"Invalid object: verify object path";
466 struct Mesh *existing_mesh,
468 const char **err_str,
473 if (usd_reader ==
nullptr) {
477 return usd_reader->
read_mesh(existing_mesh,
time, read_flag, err_str);
485 if (usd_reader ==
nullptr) {
501 const char *object_path)
503 if (object_path[0] ==
'\0') {
509 if (!archive || !archive->
valid()) {
513 pxr::UsdPrim prim = archive->
stage()->GetPrimAtPath(pxr::SdfPath(object_path));
522 if (usd_reader ==
nullptr) {
526 usd_reader->
object(
object);
529 return reinterpret_cast<CacheReader *
>(usd_reader);
543 const char *filepath,
549 pxr::UsdStageRefPtr
stage = pxr::UsdStage::Open(filepath);
576 float r_mat_world[4][4],
585 bool is_constant =
false;
592 if (object->
parent ==
nullptr) {
598 float mat_parent[4][4];
601 float mat_local[4][4];
void * BKE_cachefile_add(struct Main *bmain, const char *name)
struct Collection * BKE_collection_add(struct Main *bmain, struct Collection *parent, const char *name)
bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob)
struct Scene * CTX_data_scene(const bContext *C)
struct wmWindowManager * CTX_wm_manager(const bContext *C)
struct ViewLayer * CTX_data_view_layer(const bContext *C)
struct Main * CTX_data_main(const bContext *C)
struct wmWindow * CTX_wm_window(const bContext *C)
struct LayerCollection * BKE_layer_collection_get_active(struct ViewLayer *view_layer)
void BKE_main_collection_sync(const struct Main *bmain)
void BKE_layer_collection_resync_allow(void)
void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer)
struct Base * BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob)
struct LayerCollection * BKE_layer_collection_first_from_scene_collection(const struct ViewLayer *view_layer, const struct Collection *collection)
void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, struct Base *selbase)
void BKE_layer_collection_resync_forbid(void)
void id_us_min(struct ID *id)
void id_fake_user_set(struct ID *id)
void BKE_id_free_us(struct Main *bmain, void *idv) ATTR_NONNULL()
const char * BKE_main_blendfile_path_from_global(void)
General operations, lookup, etc. for blender objects.
void BKE_object_get_parent_matrix(struct Object *ob, struct Object *par, float r_parentmat[4][4])
File and directory operations.
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void unit_m4(float m[4][4])
void copy_m4_m3(float m1[4][4], const float m2[3][3])
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], float angle)
void BLI_path_to_display_name(char *display_name, int maxlen, const char *name) ATTR_NONNULL()
const char * BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
#define STRNCPY(dst, src)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag)
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
@ ID_RECALC_COPY_ON_WRITE
Object groups, one object can be in many groups at once.
_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 const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
virtual Mesh * read_mesh(struct Mesh *existing_mesh, double motionSampleTime, int read_flag, const char **err_str)=0
virtual bool topology_changed(const Mesh *, double)
const pxr::UsdPrim & prim() const
USDPrimReader * parent() const
USDPrimReader * create_reader(const pxr::UsdPrim &prim)
const std::vector< USDPrimReader * > & readers() const
pxr::UsdStageRefPtr stage()
void collect_readers(struct Main *bmain)
void *(* MEM_callocN)(size_t len, const char *str)
static void import_endjob(void *customdata)
static USDStageReader * stage_reader_from_handle(CacheArchiveHandle *handle)
static void convert_to_z_up(pxr::UsdStageRefPtr stage, ImportSettings *r_settings)
static void import_freejob(void *user_data)
static bool gather_objects_paths(const pxr::UsdPrim &object, ListBase *object_paths)
static void report_job_duration(const ExportJobData *data)
static CacheArchiveHandle * handle_from_stage_reader(USDStageReader *reader)
void ensure_usd_plugin_path_registered()
static void import_startjob(void *customdata, short *stop, short *do_update, float *progress)
Clock::time_point TimePoint
void print_duration(Nanoseconds duration)
std::chrono::nanoseconds Nanoseconds
struct Collection * collection
timeit::TimePoint start_time
float conversion_mat[4][4]
static USDPrimReader * get_usd_reader(CacheReader *reader, Object *, const char **err_str)
struct Mesh * USD_read_mesh(struct CacheReader *reader, struct Object *ob, struct Mesh *existing_mesh, const double time, const char **err_str, const int read_flag)
void USD_CacheReader_incref(CacheReader *reader)
CacheArchiveHandle * USD_create_handle(struct Main *, const char *filepath, ListBase *object_paths)
void USD_get_transform(struct CacheReader *reader, float r_mat_world[4][4], float time, float scale)
bool USD_import(struct bContext *C, const char *filepath, const USDImportParams *params, bool as_background_job)
void USD_CacheReader_free(CacheReader *reader)
CacheReader * CacheReader_open_usd_object(CacheArchiveHandle *handle, CacheReader *reader, Object *object, const char *object_path)
void USD_free_handle(CacheArchiveHandle *handle)
bool USD_mesh_topology_changed(CacheReader *reader, Object *ob, Mesh *existing_mesh, const double time, const char **err_str)
void WM_main_add_notifier(unsigned int type, void *reference)
void WM_report(eReportType type, const char *message)
void WM_reportf(eReportType type, const char *format,...)
void WM_set_locked_interface(wmWindowManager *wm, bool lock)
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
void WM_jobs_callbacks(wmJob *wm_job, wm_jobs_start_callback startjob, void(*initjob)(void *), void(*update)(void *), void(*endjob)(void *))
void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void(*free)(void *))
void WM_jobs_timer(wmJob *wm_job, double timestep, unsigned int note, unsigned int endnote)
wmJob * WM_jobs_get(wmWindowManager *wm, wmWindow *win, const void *owner, const char *name, int flag, int job_type)