Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_mesh.h1
-rw-r--r--source/blender/blenkernel/BKE_mesh_remesh_voxel.h44
-rw-r--r--source/blender/blenkernel/BKE_mesh_sample.hh2
-rw-r--r--source/blender/blenkernel/BKE_node.h13
-rw-r--r--source/blender/blenkernel/BKE_pointcache.h2
-rw-r--r--source/blender/blenkernel/BKE_spline.hh3
-rw-r--r--source/blender/blenkernel/CMakeLists.txt7
-rw-r--r--source/blender/blenkernel/intern/armature.c4
-rw-r--r--source/blender/blenkernel/intern/blendfile.c2
-rw-r--r--source/blender/blenkernel/intern/cachefile.c93
-rw-r--r--source/blender/blenkernel/intern/constraint.c21
-rw-r--r--source/blender/blenkernel/intern/effect.c2
-rw-r--r--source/blender/blenkernel/intern/mask_rasterize.c4
-rw-r--r--source/blender/blenkernel/intern/mesh_normals.cc21
-rw-r--r--source/blender/blenkernel/intern/mesh_remesh_voxel.cc276
-rw-r--r--source/blender/blenkernel/intern/mesh_sample.cc23
-rw-r--r--source/blender/blenkernel/intern/object.c43
-rw-r--r--source/blender/blenkernel/intern/particle_system.c2
-rw-r--r--source/blender/blenkernel/intern/pointcache.c12
-rw-r--r--source/blender/blenkernel/intern/screen.c2
-rw-r--r--source/blender/blenkernel/intern/softbody.c4
-rw-r--r--source/blender/blenkernel/intern/spline_base.cc16
-rw-r--r--source/blender/blenkernel/intern/volume_to_mesh.cc2
-rw-r--r--source/blender/blenlib/BLI_math_vector.h1
-rw-r--r--source/blender/blenlib/BLI_range.h34
-rw-r--r--source/blender/blenlib/CMakeLists.txt1
-rw-r--r--source/blender/blenlib/intern/boxpack_2d.c4
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c13
-rw-r--r--source/blender/blenlib/intern/mesh_intersect.cc4
-rw-r--r--source/blender/blenlib/intern/path_util.c2
-rw-r--r--source/blender/blenlib/intern/scanfill.c22
-rw-r--r--source/blender/blenlib/intern/storage.c2
-rw-r--r--source/blender/blenlib/tests/BLI_math_vector_test.cc18
-rw-r--r--source/blender/blenloader/BLO_readfile.h3
-rw-r--r--source/blender/blenloader/intern/versioning_300.c10
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh_normals.c26
-rw-r--r--source/blender/bmesh/tools/bmesh_bevel.c4
-rw-r--r--source/blender/draw/engines/select/select_engine.c2
-rw-r--r--source/blender/draw/intern/draw_manager.c1
-rw-r--r--source/blender/editors/animation/anim_draw.c21
-rw-r--r--source/blender/editors/animation/anim_motion_paths.c63
-rw-r--r--source/blender/editors/animation/keyframes_draw.c98
-rw-r--r--source/blender/editors/animation/keyframes_keylist.c168
-rw-r--r--source/blender/editors/animation/time_scrub_ui.c4
-rw-r--r--source/blender/editors/armature/pose_lib.c10
-rw-r--r--source/blender/editors/armature/pose_slide.c108
-rw-r--r--source/blender/editors/gpencil/annotate_paint.c28
-rw-r--r--source/blender/editors/include/ED_keyframes_keylist.h35
-rw-r--r--source/blender/editors/include/UI_interface.h5
-rw-r--r--source/blender/editors/interface/interface.c2
-rw-r--r--source/blender/editors/interface/interface_icons.c1
-rw-r--r--source/blender/editors/interface/interface_ops.c109
-rw-r--r--source/blender/editors/io/io_ops.c1
-rw-r--r--source/blender/editors/io/io_usd.c279
-rw-r--r--source/blender/editors/io/io_usd.h2
-rw-r--r--source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c4
-rw-r--r--source/blender/editors/mesh/editmesh_select.c28
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c41
-rw-r--r--source/blender/editors/object/object_relations.c6
-rw-r--r--source/blender/editors/object/object_remesh.cc33
-rw-r--r--source/blender/editors/screen/screen_ops.c56
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c6
-rw-r--r--source/blender/editors/space_action/action_select.c48
-rw-r--r--source/blender/editors/space_clip/space_clip.c7
-rw-r--r--source/blender/editors/space_console/space_console.c14
-rw-r--r--source/blender/editors/space_file/file_draw.c3
-rw-r--r--source/blender/editors/space_file/file_ops.c18
-rw-r--r--source/blender/editors/space_file/space_file.c7
-rw-r--r--source/blender/editors/space_image/space_image.c7
-rw-r--r--source/blender/editors/space_info/info_stats.c5
-rw-r--r--source/blender/editors/space_nla/nla_draw.c26
-rw-r--r--source/blender/editors/space_node/node_select.cc3
-rw-r--r--source/blender/editors/space_node/space_node.c46
-rw-r--r--source/blender/editors/space_outliner/outliner_dragdrop.c146
-rw-r--r--source/blender/editors/space_outliner/outliner_select.c3
-rw-r--r--source/blender/editors/space_sequencer/sequencer_select.c8
-rw-r--r--source/blender/editors/space_sequencer/sequencer_view.c3
-rw-r--r--source/blender/editors/space_sequencer/space_sequencer.c24
-rw-r--r--source/blender/editors/space_text/space_text.c14
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c77
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c18
-rw-r--r--source/blender/editors/transform/transform_ops.c35
-rw-r--r--source/blender/editors/util/numinput.c2
-rw-r--r--source/blender/editors/uvedit/uvedit_select.c55
-rw-r--r--source/blender/functions/FN_cpp_type.hh178
-rw-r--r--source/blender/functions/FN_cpp_type_make.hh96
-rw-r--r--source/blender/functions/intern/multi_function_network_optimization.cc2
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c10
-rw-r--r--source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c14
-rw-r--r--source/blender/gpu/intern/gpu_immediate.cc12
-rw-r--r--source/blender/gpu/intern/gpu_material.c4
-rw-r--r--source/blender/io/alembic/ABC_alembic.h17
-rw-r--r--source/blender/io/alembic/intern/abc_util.h9
-rw-r--r--source/blender/io/alembic/intern/alembic_capi.cc35
-rw-r--r--source/blender/io/collada/SceneExporter.cpp2
-rw-r--r--source/blender/io/common/CMakeLists.txt1
-rw-r--r--source/blender/io/common/IO_types.h34
-rw-r--r--source/blender/io/usd/CMakeLists.txt30
-rw-r--r--source/blender/io/usd/intern/usd_capi_export.cc (renamed from source/blender/io/usd/intern/usd_capi.cc)16
-rw-r--r--source/blender/io/usd/intern/usd_capi_import.cc578
-rw-r--r--source/blender/io/usd/intern/usd_common.cc43
-rw-r--r--source/blender/io/usd/intern/usd_common.h25
-rw-r--r--source/blender/io/usd/intern/usd_reader_camera.cc100
-rw-r--r--source/blender/io/usd/intern/usd_reader_camera.h42
-rw-r--r--source/blender/io/usd/intern/usd_reader_curve.cc256
-rw-r--r--source/blender/io/usd/intern/usd_reader_curve.h62
-rw-r--r--source/blender/io/usd/intern/usd_reader_geom.cc59
-rw-r--r--source/blender/io/usd/intern/usd_reader_geom.h52
-rw-r--r--source/blender/io/usd/intern/usd_reader_instance.cc64
-rw-r--r--source/blender/io/usd/intern/usd_reader_instance.h47
-rw-r--r--source/blender/io/usd/intern/usd_reader_light.cc252
-rw-r--r--source/blender/io/usd/intern/usd_reader_light.h41
-rw-r--r--source/blender/io/usd/intern/usd_reader_material.cc703
-rw-r--r--source/blender/io/usd/intern/usd_reader_material.h131
-rw-r--r--source/blender/io/usd/intern/usd_reader_mesh.cc853
-rw-r--r--source/blender/io/usd/intern/usd_reader_mesh.h95
-rw-r--r--source/blender/io/usd/intern/usd_reader_nurbs.cc256
-rw-r--r--source/blender/io/usd/intern/usd_reader_nurbs.h61
-rw-r--r--source/blender/io/usd/intern/usd_reader_prim.cc80
-rw-r--r--source/blender/io/usd/intern/usd_reader_prim.h131
-rw-r--r--source/blender/io/usd/intern/usd_reader_stage.cc324
-rw-r--r--source/blender/io/usd/intern/usd_reader_stage.h90
-rw-r--r--source/blender/io/usd/intern/usd_reader_volume.cc114
-rw-r--r--source/blender/io/usd/intern/usd_reader_volume.h49
-rw-r--r--source/blender/io/usd/intern/usd_reader_xform.cc184
-rw-r--r--source/blender/io/usd/intern/usd_reader_xform.h68
-rw-r--r--source/blender/io/usd/usd.h69
-rw-r--r--source/blender/makesdna/DNA_cachefile_defaults.h1
-rw-r--r--source/blender/makesdna/DNA_cachefile_types.h26
-rw-r--r--source/blender/makesrna/intern/rna_access.c4
-rw-r--r--source/blender/makesrna/intern/rna_cachefile.c12
-rw-r--r--source/blender/makesrna/intern/rna_space.c20
-rw-r--r--source/blender/modifiers/CMakeLists.txt10
-rw-r--r--source/blender/modifiers/intern/MOD_meshsequencecache.c63
-rw-r--r--source/blender/modifiers/intern/MOD_nodes.cc8
-rw-r--r--source/blender/modifiers/intern/MOD_nodes_evaluator.cc57
-rw-r--r--source/blender/modifiers/intern/MOD_remesh.c2
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_nonmanifold.c13
-rw-r--r--source/blender/nodes/NOD_static_types.h12
-rw-r--r--source/blender/nodes/NOD_type_callbacks.hh2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc3
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc16
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc2
-rw-r--r--source/blender/nodes/intern/node_geometry_exec.cc4
-rw-r--r--source/blender/nodes/intern/node_socket.cc68
-rw-r--r--source/blender/nodes/intern/type_callbacks.cc27
-rw-r--r--source/blender/python/intern/bpy_app_translations.c2
-rw-r--r--source/blender/simulation/intern/implicit_blender.c2
-rw-r--r--source/blender/windowmanager/WM_api.h7
-rw-r--r--source/blender/windowmanager/WM_types.h16
-rw-r--r--source/blender/windowmanager/intern/wm_dragdrop.c82
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c3
-rw-r--r--source/blender/windowmanager/intern/wm_files.c15
-rw-r--r--source/blender/windowmanager/intern/wm_window.c2
157 files changed, 6872 insertions, 1329 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index e3be9cd8ef8..ef1384c804b 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -280,6 +280,7 @@ void BKE_mesh_recalc_looptri_with_normals(const struct MLoop *mloop,
/* *** mesh_normals.cc *** */
+void BKE_mesh_normals_tag_dirty(struct Mesh *mesh);
void BKE_mesh_calc_normals_mapping_simple(struct Mesh *me);
void BKE_mesh_calc_normals_mapping(struct MVert *mverts,
int numVerts,
diff --git a/source/blender/blenkernel/BKE_mesh_remesh_voxel.h b/source/blender/blenkernel/BKE_mesh_remesh_voxel.h
index 3ada2eb6c6c..80ced9b5f57 100644
--- a/source/blender/blenkernel/BKE_mesh_remesh_voxel.h
+++ b/source/blender/blenkernel/BKE_mesh_remesh_voxel.h
@@ -23,45 +23,29 @@
* \ingroup bke
*/
-#ifdef WITH_OPENVDB
-# include "openvdb_capi.h"
-#endif
-
#ifdef __cplusplus
extern "C" {
#endif
struct Mesh;
-/* OpenVDB Voxel Remesher */
-#ifdef WITH_OPENVDB
-struct OpenVDBLevelSet *BKE_mesh_remesh_voxel_ovdb_mesh_to_level_set_create(
- struct Mesh *mesh, struct OpenVDBTransform *transform);
-struct Mesh *BKE_mesh_remesh_voxel_ovdb_volume_to_mesh_nomain(struct OpenVDBLevelSet *level_set,
- double isovalue,
- double adaptivity,
- bool relax_disoriented_triangles);
-#endif
-
-struct Mesh *BKE_mesh_remesh_voxel_fix_poles(struct Mesh *mesh);
-struct Mesh *BKE_mesh_remesh_voxel_to_mesh_nomain(struct Mesh *mesh,
- float voxel_size,
- float adaptivity,
- float isovalue);
-struct Mesh *BKE_mesh_remesh_quadriflow_to_mesh_nomain(struct Mesh *mesh,
- int target_faces,
- int seed,
- bool preserve_sharp,
- bool preserve_boundary,
- bool adaptive_scale,
- void (*update_cb)(void *,
- float progress,
- int *cancel),
- void *update_cb_data);
+struct Mesh *BKE_mesh_remesh_voxel_fix_poles(const struct Mesh *mesh);
+struct Mesh *BKE_mesh_remesh_voxel(const struct Mesh *mesh,
+ float voxel_size,
+ float adaptivity,
+ float isovalue);
+struct Mesh *BKE_mesh_remesh_quadriflow(const struct Mesh *mesh,
+ int target_faces,
+ int seed,
+ bool preserve_sharp,
+ bool preserve_boundary,
+ bool adaptive_scale,
+ void (*update_cb)(void *, float progress, int *cancel),
+ void *update_cb_data);
/* Data reprojection functions */
void BKE_mesh_remesh_reproject_paint_mask(struct Mesh *target, struct Mesh *source);
-void BKE_remesh_reproject_vertex_paint(struct Mesh *target, struct Mesh *source);
+void BKE_remesh_reproject_vertex_paint(struct Mesh *target, const struct Mesh *source);
void BKE_remesh_reproject_sculpt_face_sets(struct Mesh *target, struct Mesh *source);
#ifdef __cplusplus
diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh
index dc747ba5b42..2fbf7372a09 100644
--- a/source/blender/blenkernel/BKE_mesh_sample.hh
+++ b/source/blender/blenkernel/BKE_mesh_sample.hh
@@ -40,8 +40,6 @@ using fn::GMutableSpan;
using fn::GSpan;
using fn::GVArray;
-Span<MLoopTri> get_mesh_looptris(const Mesh &mesh);
-
void sample_point_attribute(const Mesh &mesh,
Span<int> looptri_indices,
Span<float3> bary_coords,
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 7dd4b6ab85b..73921f3e61d 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -125,6 +125,9 @@ using NodeExpandInMFNetworkFunction = void (*)(blender::nodes::NodeMFNetworkBuil
using NodeGeometryExecFunction = void (*)(blender::nodes::GeoNodeExecParams params);
using SocketGetCPPTypeFunction = const blender::fn::CPPType *(*)();
using SocketGetCPPValueFunction = void (*)(const struct bNodeSocket &socket, void *r_value);
+using SocketGetGeometryNodesCPPTypeFunction = const blender::fn::CPPType *(*)();
+using SocketGetGeometryNodesCPPValueFunction = void (*)(const struct bNodeSocket &socket,
+ void *r_value);
using SocketExpandInMFNetworkFunction = void (*)(blender::nodes::SocketMFNetworkBuilder &builder);
#else
@@ -132,6 +135,8 @@ typedef void *NodeExpandInMFNetworkFunction;
typedef void *SocketExpandInMFNetworkFunction;
typedef void *NodeGeometryExecFunction;
typedef void *SocketGetCPPTypeFunction;
+typedef void *SocketGetGeometryNodesCPPTypeFunction;
+typedef void *SocketGetGeometryNodesCPPValueFunction;
typedef void *SocketGetCPPValueFunction;
#endif
@@ -194,9 +199,13 @@ typedef struct bNodeSocketType {
/* Expands the socket into a multi-function node that outputs the socket value. */
SocketExpandInMFNetworkFunction expand_in_mf_network;
/* Return the CPPType of this socket. */
- SocketGetCPPTypeFunction get_cpp_type;
+ SocketGetCPPTypeFunction get_base_cpp_type;
/* Get the value of this socket in a generic way. */
- SocketGetCPPValueFunction get_cpp_value;
+ SocketGetCPPValueFunction get_base_cpp_value;
+ /* Get geometry nodes cpp type. */
+ SocketGetGeometryNodesCPPTypeFunction get_geometry_nodes_cpp_type;
+ /* Get geometry nodes cpp value. */
+ SocketGetGeometryNodesCPPValueFunction get_geometry_nodes_cpp_value;
} bNodeSocketType;
typedef void *(*NodeInitExecFunction)(struct bNodeExecContext *context,
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index 3f99a0dc793..c83fca767a1 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -302,7 +302,7 @@ void BKE_ptcache_remove(void);
/************ ID specific functions ************************/
void BKE_ptcache_id_clear(PTCacheID *id, int mode, unsigned int cfra);
-int BKE_ptcache_id_exist(PTCacheID *id, int cfra);
+bool BKE_ptcache_id_exist(PTCacheID *id, int cfra);
int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *id, int mode);
void BKE_ptcache_id_time(PTCacheID *pid,
struct Scene *scene,
diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh
index 53485ecbd6b..fc145f1ddf1 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -109,6 +109,7 @@ class Spline {
SplinePtr copy() const;
SplinePtr copy_only_settings() const;
SplinePtr copy_without_attributes() const;
+ static void copy_base_settings(const Spline &src, Spline &dst);
Spline::Type type() const;
@@ -209,8 +210,6 @@ class Spline {
virtual void correct_end_tangents() const = 0;
virtual void copy_settings(Spline &dst) const = 0;
virtual void copy_data(Spline &dst) const = 0;
-
- static void copy_base_settings(const Spline &src, Spline &dst);
};
/**
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 78bfe8c9afb..adaef22d5bc 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -698,6 +698,13 @@ if(WITH_ALEMBIC)
add_definitions(-DWITH_ALEMBIC)
endif()
+if(WITH_USD)
+ list(APPEND INC
+ ../io/usd
+ )
+ add_definitions(-DWITH_USD)
+endif()
+
if(WITH_OPENSUBDIV)
list(APPEND INC_SYS
${OPENSUBDIV_INCLUDE_DIRS}
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index b8ed519e8d1..1f02b084534 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -1882,7 +1882,7 @@ void BKE_bone_parent_transform_invert(struct BoneParentTransform *bpt)
{
invert_m4(bpt->rotscale_mat);
invert_m4(bpt->loc_mat);
- invert_v3(bpt->post_scale);
+ invert_v3_safe(bpt->post_scale);
}
void BKE_bone_parent_transform_combine(const struct BoneParentTransform *in1,
@@ -2663,7 +2663,7 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_
}
}
- /* printf("rebuild pose %s, %d bones\n", ob->id.name, counter); */
+ // printf("rebuild pose %s, %d bones\n", ob->id.name, counter);
/* synchronize protected layers with proxy */
/* HACK! To preserve 2.7x behavior that you always can pose even locked bones,
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 19721b4313d..61827be08e5 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -736,10 +736,12 @@ bool BKE_blendfile_userdef_write_all(ReportList *reports)
if (ok_write) {
printf("ok\n");
+ BKE_report(reports, RPT_INFO, "Preferences saved");
}
else {
printf("fail\n");
ok = false;
+ BKE_report(reports, RPT_ERROR, "Saving preferences failed");
}
}
else {
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index eaba5d33a20..75180de94d8 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -55,6 +55,10 @@
# include "ABC_alembic.h"
#endif
+#ifdef WITH_USD
+# include "usd.h"
+#endif
+
static void cachefile_handle_free(CacheFile *cache_file);
static void cache_file_init_data(ID *id)
@@ -166,15 +170,30 @@ void BKE_cachefile_reader_open(CacheFile *cache_file,
Object *object,
const char *object_path)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_ALEMBIC) || defined(WITH_USD)
+
BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE);
if (cache_file->handle == NULL) {
return;
}
- /* Open Alembic cache reader. */
- *reader = CacheReader_open_alembic_object(cache_file->handle, *reader, object, object_path);
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ /* Open Alembic cache reader. */
+ *reader = CacheReader_open_alembic_object(cache_file->handle, *reader, object, object_path);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ /* Open USD cache reader. */
+ *reader = CacheReader_open_usd_object(cache_file->handle, *reader, object, object_path);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
/* Multiple modifiers and constraints can call this function concurrently. */
BLI_spin_lock(&spin);
@@ -197,16 +216,30 @@ void BKE_cachefile_reader_open(CacheFile *cache_file,
void BKE_cachefile_reader_free(CacheFile *cache_file, struct CacheReader **reader)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_ALEMBIC) || defined(WITH_USD)
/* Multiple modifiers and constraints can call this function concurrently, and
* cachefile_handle_free() can also be called at the same time. */
BLI_spin_lock(&spin);
if (*reader != NULL) {
if (cache_file) {
BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE);
+
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ ABC_CacheReader_free(*reader);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ USD_CacheReader_free(*reader);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
}
- CacheReader_free(*reader);
*reader = NULL;
if (cache_file && cache_file->handle_readers) {
@@ -221,7 +254,8 @@ void BKE_cachefile_reader_free(CacheFile *cache_file, struct CacheReader **reade
static void cachefile_handle_free(CacheFile *cache_file)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_ALEMBIC) || defined(WITH_USD)
+
/* Free readers in all modifiers and constraints that use the handle, before
* we free the handle itself. */
BLI_spin_lock(&spin);
@@ -230,7 +264,21 @@ static void cachefile_handle_free(CacheFile *cache_file)
GSET_ITER (gs_iter, cache_file->handle_readers) {
struct CacheReader **reader = BLI_gsetIterator_getKey(&gs_iter);
if (*reader != NULL) {
- CacheReader_free(*reader);
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ ABC_CacheReader_free(*reader);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ USD_CacheReader_free(*reader);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
+
*reader = NULL;
}
}
@@ -242,7 +290,22 @@ static void cachefile_handle_free(CacheFile *cache_file)
/* Free handle. */
if (cache_file->handle) {
- ABC_free_handle(cache_file->handle);
+
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ ABC_free_handle(cache_file->handle);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ USD_free_handle(cache_file->handle);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
+
cache_file->handle = NULL;
}
@@ -289,8 +352,18 @@ void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file
BLI_freelistN(&cache_file->object_paths);
#ifdef WITH_ALEMBIC
- cache_file->handle = ABC_create_handle(bmain, filepath, &cache_file->object_paths);
- BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX);
+ if (BLI_path_extension_check_glob(filepath, "*abc")) {
+ cache_file->type = CACHEFILE_TYPE_ALEMBIC;
+ cache_file->handle = ABC_create_handle(bmain, filepath, &cache_file->object_paths);
+ BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX);
+ }
+#endif
+#ifdef WITH_USD
+ if (BLI_path_extension_check_glob(filepath, "*.usd;*.usda;*.usdc")) {
+ 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);
+ }
#endif
if (DEG_is_active(depsgraph)) {
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 47df31e3a2c..022073b0f12 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -95,6 +95,10 @@
# include "ABC_alembic.h"
#endif
+#ifdef WITH_USD
+# include "usd.h"
+#endif
+
/* ---------------------------------------------------------------------------- */
/* Useful macros for testing various common flag combinations */
@@ -5403,7 +5407,7 @@ static void transformcache_id_looper(bConstraint *con, ConstraintIDFunc func, vo
static void transformcache_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_ALEMBIC) || defined(WITH_USD)
bTransformCacheConstraint *data = con->data;
Scene *scene = cob->scene;
@@ -5421,7 +5425,20 @@ static void transformcache_evaluate(bConstraint *con, bConstraintOb *cob, ListBa
BKE_cachefile_reader_open(cache_file, &data->reader, cob->ob, data->object_path);
}
- ABC_get_transform(data->reader, cob->matrix, time, cache_file->scale);
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ ABC_get_transform(data->reader, cob->matrix, time, cache_file->scale);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ USD_get_transform(data->reader, cob->matrix, time * FPS, cache_file->scale);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
#else
UNUSED_VARS(con, cob);
#endif
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index fc1721eaf3a..334118ddf3f 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -861,7 +861,7 @@ static void get_effector_tot(
int totpart = eff->psys->totpart;
int amount = eff->psys->part->effector_amount;
- *step = (totpart > amount) ? totpart / amount : 1;
+ *step = (totpart > amount) ? (int)ceil((float)totpart / (float)amount) : 1;
}
}
else {
diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c
index 81c161a4a7d..00ed7d86975 100644
--- a/source/blender/blenkernel/intern/mask_rasterize.c
+++ b/source/blender/blenkernel/intern/mask_rasterize.c
@@ -106,7 +106,7 @@
/* for debugging add... */
#ifndef NDEBUG
-/* printf("%u %u %u %u\n", _t[0], _t[1], _t[2], _t[3]); \ */
+// printf("%u %u %u %u\n", _t[0], _t[1], _t[2], _t[3]);
# define FACE_ASSERT(face, vert_max) \
{ \
unsigned int *_t = face; \
@@ -1213,7 +1213,7 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
layer->falloff = masklay->falloff;
}
- /* printf("tris %d, feather tris %d\n", sf_tri_tot, tot_feather_quads); */
+ // printf("tris %d, feather tris %d\n", sf_tri_tot, tot_feather_quads);
}
/* add trianges */
diff --git a/source/blender/blenkernel/intern/mesh_normals.cc b/source/blender/blenkernel/intern/mesh_normals.cc
index f496d6eada1..87b11904f90 100644
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@ -63,6 +63,12 @@ static CLG_LogRef LOG = {"bke.mesh_normals"};
/** \name Mesh Normal Calculation
* \{ */
+void BKE_mesh_normals_tag_dirty(Mesh *mesh)
+{
+ mesh->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
+ mesh->runtime.cd_dirty_poly |= CD_MASK_NORMAL;
+}
+
/**
* Call when there are no polygons.
*/
@@ -981,7 +987,7 @@ void BKE_edges_sharp_from_angle_set(const struct MVert *mverts,
/* Simple mapping from a loop to its polygon index. */
int *loop_to_poly = (int *)MEM_malloc_arrayN((size_t)numLoops, sizeof(*loop_to_poly), __func__);
- LoopSplitTaskDataCommon common_data;
+ LoopSplitTaskDataCommon common_data = {};
common_data.mverts = mverts;
common_data.medges = medges;
common_data.mloops = mloops;
@@ -1189,7 +1195,7 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli
}
}
- // printf("FAN: vert %d, start edge %d\n", mv_pivot_index, ml_curr->e);
+ // printf("FAN: vert %d, start edge %d\n", mv_pivot_index, ml_curr->e);
while (true) {
const MEdge *me_curr = &medges[mlfan_curr->e];
@@ -1206,7 +1212,7 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli
normalize_v3(vec_curr);
}
- // printf("\thandling edge %d / loop %d\n", mlfan_curr->e, mlfan_curr_index);
+ // printf("\thandling edge %d / loop %d\n", mlfan_curr->e, mlfan_curr_index);
{
/* Code similar to accumulate_vertex_normals_poly_v3. */
@@ -1246,9 +1252,8 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli
if (IS_EDGE_SHARP(e2lfan_curr) || (me_curr == me_org)) {
/* Current edge is sharp and we have finished with this fan of faces around this vert,
- * or this vert is smooth, and we have completed a full turn around it.
- */
- // printf("FAN: Finished!\n");
+ * or this vert is smooth, and we have completed a full turn around it. */
+ // printf("FAN: Finished!\n");
break;
}
@@ -1531,12 +1536,12 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common
ml_curr_index,
ml_prev_index,
mp_index))) {
- // printf("SKIPPING!\n");
+ // printf("SKIPPING!\n");
}
else {
LoopSplitTaskData *data, data_local;
- // printf("PROCESSING!\n");
+ // printf("PROCESSING!\n");
if (pool) {
if (data_idx == 0) {
diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
index 059094090f2..63b0403dcea 100644
--- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
+++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
@@ -31,15 +31,12 @@
#include "MEM_guardedalloc.h"
#include "BLI_array.hh"
-#include "BLI_blenlib.h"
#include "BLI_float3.hh"
#include "BLI_index_range.hh"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
+#include "BLI_span.hh"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "DNA_object_types.h"
#include "BKE_bvhutils.h"
#include "BKE_customdata.h"
@@ -52,7 +49,9 @@
#include "bmesh_tools.h"
#ifdef WITH_OPENVDB
-# include "openvdb_capi.h"
+# include <openvdb/openvdb.h>
+# include <openvdb/tools/MeshToVolume.h>
+# include <openvdb/tools/VolumeToMesh.h>
#endif
#ifdef WITH_QUADRIFLOW
@@ -62,114 +61,23 @@
using blender::Array;
using blender::float3;
using blender::IndexRange;
-
-#ifdef WITH_OPENVDB
-struct OpenVDBLevelSet *BKE_mesh_remesh_voxel_ovdb_mesh_to_level_set_create(
- Mesh *mesh, struct OpenVDBTransform *transform)
-{
- BKE_mesh_runtime_looptri_recalc(mesh);
- const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(mesh);
- MVertTri *verttri = (MVertTri *)MEM_callocN(
- sizeof(*verttri) * BKE_mesh_runtime_looptri_len(mesh), "remesh_looptri");
- BKE_mesh_runtime_verttri_from_looptri(
- verttri, mesh->mloop, looptri, BKE_mesh_runtime_looptri_len(mesh));
-
- const int totfaces = BKE_mesh_runtime_looptri_len(mesh);
- const int totverts = mesh->totvert;
- Array<float3> verts(totverts);
- Array<int> faces(totfaces * 3);
-
- for (const int i : IndexRange(totverts)) {
- verts[i] = mesh->mvert[i].co;
- }
-
- for (const int i : IndexRange(totfaces)) {
- MVertTri &vt = verttri[i];
- faces[i * 3] = vt.tri[0];
- faces[i * 3 + 1] = vt.tri[1];
- faces[i * 3 + 2] = vt.tri[2];
- }
-
- struct OpenVDBLevelSet *level_set = OpenVDBLevelSet_create(false, nullptr);
- OpenVDBLevelSet_mesh_to_level_set(
- level_set, (const float *)verts.data(), faces.data(), totverts, totfaces, transform);
-
- MEM_freeN(verttri);
-
- return level_set;
-}
-
-Mesh *BKE_mesh_remesh_voxel_ovdb_volume_to_mesh_nomain(struct OpenVDBLevelSet *level_set,
- double isovalue,
- double adaptivity,
- bool relax_disoriented_triangles)
-{
- struct OpenVDBVolumeToMeshData output_mesh;
- OpenVDBLevelSet_volume_to_mesh(
- level_set, &output_mesh, isovalue, adaptivity, relax_disoriented_triangles);
-
- Mesh *mesh = BKE_mesh_new_nomain(output_mesh.totvertices,
- 0,
- 0,
- (output_mesh.totquads * 4) + (output_mesh.tottriangles * 3),
- output_mesh.totquads + output_mesh.tottriangles);
-
- for (const int i : IndexRange(output_mesh.totvertices)) {
- copy_v3_v3(mesh->mvert[i].co, &output_mesh.vertices[i * 3]);
- }
-
- for (const int i : IndexRange(output_mesh.totquads)) {
- MPoly &poly = mesh->mpoly[i];
- const int loopstart = i * 4;
- poly.loopstart = loopstart;
- poly.totloop = 4;
- mesh->mloop[loopstart].v = output_mesh.quads[loopstart];
- mesh->mloop[loopstart + 1].v = output_mesh.quads[loopstart + 1];
- mesh->mloop[loopstart + 2].v = output_mesh.quads[loopstart + 2];
- mesh->mloop[loopstart + 3].v = output_mesh.quads[loopstart + 3];
- }
-
- const int triangle_poly_start = output_mesh.totquads;
- const int triangle_loop_start = output_mesh.totquads * 4;
- for (const int i : IndexRange(output_mesh.tottriangles)) {
- MPoly &poly = mesh->mpoly[triangle_poly_start + i];
- const int loopstart = triangle_loop_start + i * 3;
- poly.loopstart = loopstart;
- poly.totloop = 3;
- mesh->mloop[loopstart].v = output_mesh.triangles[i * 3 + 2];
- mesh->mloop[loopstart + 1].v = output_mesh.triangles[i * 3 + 1];
- mesh->mloop[loopstart + 2].v = output_mesh.triangles[i * 3];
- }
-
- BKE_mesh_calc_edges(mesh, false, false);
- BKE_mesh_calc_normals(mesh);
-
- MEM_freeN(output_mesh.quads);
- MEM_freeN(output_mesh.vertices);
-
- if (output_mesh.tottriangles > 0) {
- MEM_freeN(output_mesh.triangles);
- }
-
- return mesh;
-}
-#endif
+using blender::MutableSpan;
+using blender::Span;
#ifdef WITH_QUADRIFLOW
-static Mesh *BKE_mesh_remesh_quadriflow(Mesh *input_mesh,
- int target_faces,
- int seed,
- bool preserve_sharp,
- bool preserve_boundary,
- bool adaptive_scale,
- void (*update_cb)(void *, float progress, int *cancel),
- void *update_cb_data)
+static Mesh *remesh_quadriflow(const Mesh *input_mesh,
+ int target_faces,
+ int seed,
+ bool preserve_sharp,
+ bool preserve_boundary,
+ bool adaptive_scale,
+ void (*update_cb)(void *, float progress, int *cancel),
+ void *update_cb_data)
{
/* Ensure that the triangulated mesh data is up to data */
- BKE_mesh_runtime_looptri_recalc(input_mesh);
const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(input_mesh);
- /* Gather the required data for export to the internal quadiflow mesh format */
+ /* Gather the required data for export to the internal quadriflow mesh format. */
MVertTri *verttri = (MVertTri *)MEM_callocN(
sizeof(*verttri) * BKE_mesh_runtime_looptri_len(input_mesh), "remesh_looptri");
BKE_mesh_runtime_verttri_from_looptri(
@@ -254,30 +162,27 @@ static Mesh *BKE_mesh_remesh_quadriflow(Mesh *input_mesh,
}
#endif
-Mesh *BKE_mesh_remesh_quadriflow_to_mesh_nomain(Mesh *mesh,
- int target_faces,
- int seed,
- bool preserve_sharp,
- bool preserve_boundary,
- bool adaptive_scale,
- void (*update_cb)(void *,
- float progress,
- int *cancel),
- void *update_cb_data)
+Mesh *BKE_mesh_remesh_quadriflow(const Mesh *mesh,
+ int target_faces,
+ int seed,
+ bool preserve_sharp,
+ bool preserve_boundary,
+ bool adaptive_scale,
+ void (*update_cb)(void *, float progress, int *cancel),
+ void *update_cb_data)
{
- Mesh *new_mesh = nullptr;
#ifdef WITH_QUADRIFLOW
if (target_faces <= 0) {
target_faces = -1;
}
- new_mesh = BKE_mesh_remesh_quadriflow(mesh,
- target_faces,
- seed,
- preserve_sharp,
- preserve_boundary,
- adaptive_scale,
- update_cb,
- update_cb_data);
+ return remesh_quadriflow(mesh,
+ target_faces,
+ seed,
+ preserve_sharp,
+ preserve_boundary,
+ adaptive_scale,
+ update_cb,
+ update_cb_data);
#else
UNUSED_VARS(mesh,
target_faces,
@@ -287,29 +192,102 @@ Mesh *BKE_mesh_remesh_quadriflow_to_mesh_nomain(Mesh *mesh,
adaptive_scale,
update_cb,
update_cb_data);
+ return nullptr;
#endif
- return new_mesh;
}
-Mesh *BKE_mesh_remesh_voxel_to_mesh_nomain(Mesh *mesh,
- float voxel_size,
- float adaptivity,
- float isovalue)
+#ifdef WITH_OPENVDB
+static openvdb::FloatGrid::Ptr remesh_voxel_level_set_create(const Mesh *mesh,
+ const float voxel_size)
+{
+ Span<MLoop> mloop{mesh->mloop, mesh->totloop};
+ Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(mesh),
+ BKE_mesh_runtime_looptri_len(mesh)};
+
+ std::vector<openvdb::Vec3s> points(mesh->totvert);
+ std::vector<openvdb::Vec3I> triangles(looptris.size());
+
+ for (const int i : IndexRange(mesh->totvert)) {
+ const float3 co = mesh->mvert[i].co;
+ points[i] = openvdb::Vec3s(co.x, co.y, co.z);
+ }
+
+ for (const int i : IndexRange(looptris.size())) {
+ const MLoopTri &loop_tri = looptris[i];
+ triangles[i] = openvdb::Vec3I(
+ mloop[loop_tri.tri[0]].v, mloop[loop_tri.tri[1]].v, mloop[loop_tri.tri[2]].v);
+ }
+
+ openvdb::math::Transform::Ptr transform = openvdb::math::Transform::createLinearTransform(
+ voxel_size);
+ openvdb::FloatGrid::Ptr grid = openvdb::tools::meshToLevelSet<openvdb::FloatGrid>(
+ *transform, points, triangles, 1.0f);
+
+ return grid;
+}
+
+static Mesh *remesh_voxel_volume_to_mesh(const openvdb::FloatGrid::Ptr level_set_grid,
+ const float isovalue,
+ const float adaptivity,
+ const bool relax_disoriented_triangles)
+{
+ std::vector<openvdb::Vec3s> vertices;
+ std::vector<openvdb::Vec4I> quads;
+ std::vector<openvdb::Vec3I> tris;
+ openvdb::tools::volumeToMesh<openvdb::FloatGrid>(
+ *level_set_grid, vertices, tris, quads, isovalue, adaptivity, relax_disoriented_triangles);
+
+ Mesh *mesh = BKE_mesh_new_nomain(
+ vertices.size(), 0, 0, quads.size() * 4 + tris.size() * 3, quads.size() + tris.size());
+ MutableSpan<MVert> mverts{mesh->mvert, mesh->totvert};
+ MutableSpan<MLoop> mloops{mesh->mloop, mesh->totloop};
+ MutableSpan<MPoly> mpolys{mesh->mpoly, mesh->totpoly};
+
+ for (const int i : mverts.index_range()) {
+ copy_v3_v3(mverts[i].co, float3(vertices[i].x(), vertices[i].y(), vertices[i].z()));
+ }
+
+ for (const int i : IndexRange(quads.size())) {
+ MPoly &poly = mpolys[i];
+ const int loopstart = i * 4;
+ poly.loopstart = loopstart;
+ poly.totloop = 4;
+ mloops[loopstart].v = quads[i][0];
+ mloops[loopstart + 1].v = quads[i][3];
+ mloops[loopstart + 2].v = quads[i][2];
+ mloops[loopstart + 3].v = quads[i][1];
+ }
+
+ const int triangle_loop_start = quads.size() * 4;
+ for (const int i : IndexRange(tris.size())) {
+ MPoly &poly = mpolys[quads.size() + i];
+ const int loopstart = triangle_loop_start + i * 3;
+ poly.loopstart = loopstart;
+ poly.totloop = 3;
+ mloops[loopstart].v = tris[i][2];
+ mloops[loopstart + 1].v = tris[i][1];
+ mloops[loopstart + 2].v = tris[i][0];
+ }
+
+ BKE_mesh_calc_edges(mesh, false, false);
+ BKE_mesh_normals_tag_dirty(mesh);
+
+ return mesh;
+}
+#endif
+
+Mesh *BKE_mesh_remesh_voxel(const Mesh *mesh,
+ const float voxel_size,
+ const float adaptivity,
+ const float isovalue)
{
- Mesh *new_mesh = nullptr;
#ifdef WITH_OPENVDB
- struct OpenVDBLevelSet *level_set;
- struct OpenVDBTransform *xform = OpenVDBTransform_create();
- OpenVDBTransform_create_linear_transform(xform, (double)voxel_size);
- level_set = BKE_mesh_remesh_voxel_ovdb_mesh_to_level_set_create(mesh, xform);
- new_mesh = BKE_mesh_remesh_voxel_ovdb_volume_to_mesh_nomain(
- level_set, (double)isovalue, (double)adaptivity, false);
- OpenVDBLevelSet_free(level_set);
- OpenVDBTransform_free(xform);
+ openvdb::FloatGrid::Ptr level_set = remesh_voxel_level_set_create(mesh, voxel_size);
+ return remesh_voxel_volume_to_mesh(level_set, isovalue, adaptivity, false);
#else
UNUSED_VARS(mesh, voxel_size, adaptivity, isovalue);
+ return nullptr;
#endif
- return new_mesh;
}
void BKE_mesh_remesh_reproject_paint_mask(Mesh *target, Mesh *source)
@@ -367,12 +345,12 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, Mesh *source)
&target->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, nullptr, target->totpoly);
}
- int *source_face_sets;
+ const int *source_face_sets;
if (CustomData_has_layer(&source->pdata, CD_SCULPT_FACE_SETS)) {
- source_face_sets = (int *)CustomData_get_layer(&source->pdata, CD_SCULPT_FACE_SETS);
+ source_face_sets = (const int *)CustomData_get_layer(&source->pdata, CD_SCULPT_FACE_SETS);
}
else {
- source_face_sets = (int *)CustomData_add_layer(
+ source_face_sets = (const int *)CustomData_add_layer(
&source->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, nullptr, source->totpoly);
}
@@ -397,7 +375,7 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, Mesh *source)
free_bvhtree_from_mesh(&bvhtree);
}
-void BKE_remesh_reproject_vertex_paint(Mesh *target, Mesh *source)
+void BKE_remesh_reproject_vertex_paint(Mesh *target, const Mesh *source)
{
BVHTreeFromMesh bvhtree = {{nullptr}};
BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2);
@@ -412,7 +390,7 @@ void BKE_remesh_reproject_vertex_paint(Mesh *target, Mesh *source)
MPropCol *target_color = (MPropCol *)CustomData_get_layer_n(
&target->vdata, CD_PROP_COLOR, layer_n);
MVert *target_verts = (MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
- MPropCol *source_color = (MPropCol *)CustomData_get_layer_n(
+ const MPropCol *source_color = (const MPropCol *)CustomData_get_layer_n(
&source->vdata, CD_PROP_COLOR, layer_n);
for (int i = 0; i < target->totvert; i++) {
BVHTreeNearest nearest;
@@ -428,13 +406,12 @@ void BKE_remesh_reproject_vertex_paint(Mesh *target, Mesh *source)
free_bvhtree_from_mesh(&bvhtree);
}
-struct Mesh *BKE_mesh_remesh_voxel_fix_poles(struct Mesh *mesh)
+struct Mesh *BKE_mesh_remesh_voxel_fix_poles(const Mesh *mesh)
{
const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(mesh);
- BMesh *bm;
const BMeshCreateParams bmesh_create_params = {true};
- bm = BM_mesh_create(&allocsize, &bmesh_create_params);
+ BMesh *bm = BM_mesh_create(&allocsize, &bmesh_create_params);
BMeshFromMeshParams bmesh_from_mesh_params{};
bmesh_from_mesh_params.calc_face_normal = true;
@@ -529,7 +506,6 @@ struct Mesh *BKE_mesh_remesh_voxel_fix_poles(struct Mesh *mesh)
bmesh_to_mesh_params.calc_object_remap = false;
Mesh *result = BKE_mesh_from_bmesh_nomain(bm, &bmesh_to_mesh_params, mesh);
- BKE_id_free(nullptr, mesh);
BM_mesh_free(bm);
return result;
}
diff --git a/source/blender/blenkernel/intern/mesh_sample.cc b/source/blender/blenkernel/intern/mesh_sample.cc
index bd46407d060..5388f6e530e 100644
--- a/source/blender/blenkernel/intern/mesh_sample.cc
+++ b/source/blender/blenkernel/intern/mesh_sample.cc
@@ -24,14 +24,6 @@
namespace blender::bke::mesh_surface_sample {
-Span<MLoopTri> get_mesh_looptris(const Mesh &mesh)
-{
- /* This only updates a cache and can be considered to be logically const. */
- const MLoopTri *looptris = BKE_mesh_runtime_looptri_ensure(const_cast<Mesh *>(&mesh));
- const int looptris_len = BKE_mesh_runtime_looptri_len(&mesh);
- return {looptris, looptris_len};
-}
-
template<typename T>
BLI_NOINLINE static void sample_point_attribute(const Mesh &mesh,
const Span<int> looptri_indices,
@@ -39,7 +31,8 @@ BLI_NOINLINE static void sample_point_attribute(const Mesh &mesh,
const VArray<T> &data_in,
const MutableSpan<T> data_out)
{
- const Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+ const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+ BKE_mesh_runtime_looptri_len(&mesh)};
for (const int i : bary_coords.index_range()) {
const int looptri_index = looptri_indices[i];
@@ -85,7 +78,8 @@ BLI_NOINLINE static void sample_corner_attribute(const Mesh &mesh,
const VArray<T> &data_in,
const MutableSpan<T> data_out)
{
- Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+ const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+ BKE_mesh_runtime_looptri_len(&mesh)};
for (const int i : bary_coords.index_range()) {
const int looptri_index = looptri_indices[i];
@@ -130,7 +124,8 @@ void sample_face_attribute(const Mesh &mesh,
const VArray<T> &data_in,
const MutableSpan<T> data_out)
{
- Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+ const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+ BKE_mesh_runtime_looptri_len(&mesh)};
for (const int i : data_out.index_range()) {
const int looptri_index = looptri_indices[i];
@@ -172,7 +167,8 @@ Span<float3> MeshAttributeInterpolator::ensure_barycentric_coords()
}
bary_coords_.reinitialize(positions_.size());
- Span<MLoopTri> looptris = get_mesh_looptris(*mesh_);
+ const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(mesh_),
+ BKE_mesh_runtime_looptri_len(mesh_)};
for (const int i : bary_coords_.index_range()) {
const int looptri_index = looptri_indices_[i];
@@ -199,7 +195,8 @@ Span<float3> MeshAttributeInterpolator::ensure_nearest_weights()
}
nearest_weights_.reinitialize(positions_.size());
- Span<MLoopTri> looptris = get_mesh_looptris(*mesh_);
+ const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(mesh_),
+ BKE_mesh_runtime_looptri_len(mesh_)};
for (const int i : nearest_weights_.index_range()) {
const int looptri_index = looptri_indices_[i];
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 89de37d6e4b..6a309e040c0 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -144,6 +144,7 @@
#include "DRW_engine.h"
#include "BLO_read_write.h"
+#include "BLO_readfile.h"
#include "SEQ_sequencer.h"
@@ -833,7 +834,7 @@ static void object_blend_read_lib(BlendLibReader *reader, ID *id)
{
Object *ob = (Object *)id;
- bool warn = false;
+ BlendFileReadReport *reports = BLO_read_lib_reports(reader);
/* XXX deprecated - old animation system <<< */
BLO_read_id_address(reader, ob->id.lib, &ob->ipo);
@@ -851,8 +852,8 @@ static void object_blend_read_lib(BlendLibReader *reader, ID *id)
else {
if (ob->instance_collection != NULL) {
ID *new_id = BLO_read_get_new_id_address(reader, ob->id.lib, &ob->instance_collection->id);
- BLO_reportf_wrap(BLO_read_lib_reports(reader),
- RPT_WARNING,
+ BLO_reportf_wrap(reports,
+ RPT_INFO,
TIP_("Non-Empty object '%s' cannot duplicate collection '%s' "
"anymore in Blender 2.80, removed instancing"),
ob->id.name + 2,
@@ -870,11 +871,17 @@ static void object_blend_read_lib(BlendLibReader *reader, ID *id)
ob->proxy = NULL;
if (ob->id.lib) {
- printf("Proxy lost from object %s lib %s\n", ob->id.name + 2, ob->id.lib->filepath);
+ BLO_reportf_wrap(reports,
+ RPT_INFO,
+ TIP_("Proxy lost from object %s lib %s\n"),
+ ob->id.name + 2,
+ ob->id.lib->filepath);
}
else {
- printf("Proxy lost from object %s lib <NONE>\n", ob->id.name + 2);
+ BLO_reportf_wrap(
+ reports, RPT_INFO, TIP_("Proxy lost from object %s lib <NONE>\n"), ob->id.name + 2);
}
+ reports->count.missing_obproxies++;
}
else {
/* this triggers object_update to always use a copy */
@@ -887,15 +894,7 @@ static void object_blend_read_lib(BlendLibReader *reader, ID *id)
BLO_read_id_address(reader, ob->id.lib, &ob->data);
if (ob->data == NULL && poin != NULL) {
- if (ob->id.lib) {
- printf("Can't find obdata of %s lib %s\n", ob->id.name + 2, ob->id.lib->filepath);
- }
- else {
- printf("Object %s lost data.\n", ob->id.name + 2);
- }
-
ob->type = OB_EMPTY;
- warn = true;
if (ob->pose) {
/* we can't call #BKE_pose_free() here because of library linking
@@ -911,6 +910,18 @@ static void object_blend_read_lib(BlendLibReader *reader, ID *id)
ob->pose = NULL;
ob->mode &= ~OB_MODE_POSE;
}
+
+ if (ob->id.lib) {
+ BLO_reportf_wrap(reports,
+ RPT_INFO,
+ TIP_("Can't find obdata of %s lib %s\n"),
+ ob->id.name + 2,
+ ob->id.lib->filepath);
+ }
+ else {
+ BLO_reportf_wrap(reports, RPT_INFO, TIP_("Object %s lost data\n"), ob->id.name + 2);
+ }
+ reports->count.missing_obdata++;
}
for (int a = 0; a < ob->totcol; a++) {
BLO_read_id_address(reader, ob->id.lib, &ob->mat[a]);
@@ -922,7 +933,7 @@ static void object_blend_read_lib(BlendLibReader *reader, ID *id)
const short *totcol_data = BKE_object_material_len_p(ob);
/* Only expand so as not to lose any object materials that might be set. */
if (totcol_data && (*totcol_data > ob->totcol)) {
- /* printf("'%s' %d -> %d\n", ob->id.name, ob->totcol, *totcol_data); */
+ // printf("'%s' %d -> %d\n", ob->id.name, ob->totcol, *totcol_data);
BKE_object_material_resize(BLO_read_lib_get_main(reader), ob, *totcol_data, false);
}
}
@@ -992,10 +1003,6 @@ static void object_blend_read_lib(BlendLibReader *reader, ID *id)
BLO_read_id_address(reader, ob->id.lib, &ob->rigidbody_constraint->ob1);
BLO_read_id_address(reader, ob->id.lib, &ob->rigidbody_constraint->ob2);
}
-
- if (warn) {
- BLO_reportf_wrap(BLO_read_lib_reports(reader), RPT_WARNING, "Warning in console");
- }
}
/* XXX deprecated - old animation system */
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 06d3daaf4d6..9c0c5639777 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -3112,7 +3112,7 @@ static void collision_fail(ParticleData *pa, ParticleCollision *col)
copy_v3_v3(pa->state.vel, col->pce.vel);
mul_v3_fl(pa->state.vel, col->inv_timestep);
- /* printf("max iterations\n"); */
+ // printf("max iterations\n");
}
/* Particle - Mesh collision detection and response
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 9ed5b0230e6..a6adff35a7f 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -2753,18 +2753,18 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
pid->cache->flag |= PTCACHE_FLAG_INFO_DIRTY;
}
-int BKE_ptcache_id_exist(PTCacheID *pid, int cfra)
+bool BKE_ptcache_id_exist(PTCacheID *pid, int cfra)
{
if (!pid->cache) {
- return 0;
+ return false;
}
if (cfra < pid->cache->startframe || cfra > pid->cache->endframe) {
- return 0;
+ return false;
}
if (pid->cache->cached_frames && pid->cache->cached_frames[cfra - pid->cache->startframe] == 0) {
- return 0;
+ return false;
}
if (pid->cache->flag & PTCACHE_DISK_CACHE) {
@@ -2779,10 +2779,10 @@ int BKE_ptcache_id_exist(PTCacheID *pid, int cfra)
for (; pm; pm = pm->next) {
if (pm->frame == cfra) {
- return 1;
+ return true;
}
}
- return 0;
+ return false;
}
void BKE_ptcache_id_time(
PTCacheID *pid, Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index c3885b5dcf7..e44c5a6b40e 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -766,7 +766,7 @@ void BKE_screen_remove_double_scrverts(bScreen *screen)
while (v1) {
if (v1->newv == NULL) { /* !?! */
if (v1->vec.x == verg->vec.x && v1->vec.y == verg->vec.y) {
- /* printf("doublevert\n"); */
+ // printf("doublevert\n");
v1->newv = verg;
}
}
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index e4e2ed94b41..1a408aceeb2 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -2225,7 +2225,7 @@ static void sb_cf_threads_run(Scene *scene,
totthread--;
}
- /* printf("sb_cf_threads_run spawning %d threads\n", totthread); */
+ // printf("sb_cf_threads_run spawning %d threads\n", totthread);
sb_threads = MEM_callocN(sizeof(SB_thread_context) * totthread, "SBThread");
memset(sb_threads, 0, sizeof(SB_thread_context) * totthread);
@@ -2812,7 +2812,7 @@ static void reference_to_scratch(Object *ob)
}
mul_v3_fl(accu_pos, 1.0f / accu_mass);
copy_v3_v3(sb->scratch->Ref.com, accu_pos);
- /* printf("reference_to_scratch\n"); */
+ // printf("reference_to_scratch\n");
}
/*
diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc
index a7caae967f6..dda7abea0fc 100644
--- a/source/blender/blenkernel/intern/spline_base.cc
+++ b/source/blender/blenkernel/intern/spline_base.cc
@@ -189,7 +189,11 @@ static float3 direction_bisect(const float3 &prev, const float3 &middle, const f
const float3 dir_prev = (middle - prev).normalized();
const float3 dir_next = (next - middle).normalized();
- return (dir_prev + dir_next).normalized();
+ const float3 result = (dir_prev + dir_next).normalized();
+ if (UNLIKELY(result.is_zero())) {
+ return float3(0.0f, 0.0f, 1.0f);
+ }
+ return result;
}
static void calculate_tangents(Span<float3> positions,
@@ -197,6 +201,7 @@ static void calculate_tangents(Span<float3> positions,
MutableSpan<float3> tangents)
{
if (positions.size() == 1) {
+ tangents.first() = float3(0.0f, 0.0f, 1.0f);
return;
}
@@ -237,13 +242,8 @@ Span<float3> Spline::evaluated_tangents() const
Span<float3> positions = this->evaluated_positions();
- if (eval_size == 1) {
- evaluated_tangents_cache_.first() = float3(1.0f, 0.0f, 0.0f);
- }
- else {
- calculate_tangents(positions, is_cyclic_, evaluated_tangents_cache_);
- this->correct_end_tangents();
- }
+ calculate_tangents(positions, is_cyclic_, evaluated_tangents_cache_);
+ this->correct_end_tangents();
tangent_cache_dirty_ = false;
return evaluated_tangents_cache_;
diff --git a/source/blender/blenkernel/intern/volume_to_mesh.cc b/source/blender/blenkernel/intern/volume_to_mesh.cc
index 7ab67516242..e9d6eea4614 100644
--- a/source/blender/blenkernel/intern/volume_to_mesh.cc
+++ b/source/blender/blenkernel/intern/volume_to_mesh.cc
@@ -159,7 +159,7 @@ static Mesh *new_mesh_from_openvdb_data(Span<openvdb::Vec3s> verts,
}
BKE_mesh_calc_edges(mesh, false, false);
- BKE_mesh_calc_normals(mesh);
+ BKE_mesh_normals_tag_dirty(mesh);
return mesh;
}
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 2f4cf1721af..860ba14a3ed 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -185,6 +185,7 @@ MINLINE void negate_v3_db(double r[3]);
MINLINE void invert_v2(float r[2]);
MINLINE void invert_v3(float r[3]);
+MINLINE void invert_v3_safe(float r[3]); /* Invert the vector, but leaves zero values as zero. */
MINLINE void abs_v2(float r[2]);
MINLINE void abs_v2_v2(float r[2], const float a[2]);
diff --git a/source/blender/blenlib/BLI_range.h b/source/blender/blenlib/BLI_range.h
new file mode 100644
index 00000000000..ad4cd6c162e
--- /dev/null
+++ b/source/blender/blenlib/BLI_range.h
@@ -0,0 +1,34 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bli
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Range2f {
+ float min;
+ float max;
+} Range2f;
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index ea5572f1c8a..b6603dce378 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -265,6 +265,7 @@ set(SRC
BLI_quadric.h
BLI_rand.h
BLI_rand.hh
+ BLI_range.h
BLI_rect.h
BLI_resource_scope.hh
BLI_scanfill.h
diff --git a/source/blender/blenlib/intern/boxpack_2d.c b/source/blender/blenlib/intern/boxpack_2d.c
index ea6c2d8d498..4a07f1134d0 100644
--- a/source/blender/blenlib/intern/boxpack_2d.c
+++ b/source/blender/blenlib/intern/boxpack_2d.c
@@ -409,8 +409,8 @@ void BLI_box_pack_2d(BoxPack *boxarray, const uint len, float *r_tot_x, float *r
for (i = 0; i < verts_pack_len && isect; i++) {
vert = &vs_ctx.vertarray[vertex_pack_indices[i]];
- /* printf("\ttesting vert %i %i %i %f %f\n", i,
- * vert->free, verts_pack_len, vert->x, vert->y); */
+ // printf("\ttesting vert %i %i %i %f %f\n", i,
+ // vert->free, verts_pack_len, vert->x, vert->y);
/* This vert has a free quadrant
* Test if we can place the box here
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 55f7a152b83..dddefd60b1b 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -847,6 +847,19 @@ MINLINE void invert_v3(float r[3])
r[2] = 1.0f / r[2];
}
+MINLINE void invert_v3_safe(float r[3])
+{
+ if (r[0] != 0.0f) {
+ r[0] = 1.0f / r[0];
+ }
+ if (r[1] != 0.0f) {
+ r[1] = 1.0f / r[1];
+ }
+ if (r[2] != 0.0f) {
+ r[2] = 1.0f / r[2];
+ }
+}
+
MINLINE void abs_v2(float r[2])
{
r[0] = fabsf(r[0]);
diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc
index dcd432a88d5..5651e52799e 100644
--- a/source/blender/blenlib/intern/mesh_intersect.cc
+++ b/source/blender/blenlib/intern/mesh_intersect.cc
@@ -1165,8 +1165,8 @@ static int filter_plane_side(const double3 &p,
* interesect_tri_tri and helper functions.
* This code uses the algorithm of Guigue and Devillers, as described
* in "Faster Triangle-Triangle Intersection Tests".
- * Adapted from github code by Eric Haines:
- * github.com/erich666/jgt-code/tree/master/Volume_08/Number_1/Guigue2003
+ * Adapted from code by Eric Haines:
+ * https://github.com/erich666/jgt-code/tree/master/Volume_08/Number_1/Guigue2003
*/
/**
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 4d0dc43ed1e..99fae1f1616 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1897,7 +1897,7 @@ bool BLI_path_name_at_index(const char *__restrict path,
if (index_step == index) {
*r_offset = prev;
*r_len = i - prev;
- /* printf("!!! %d %d\n", start, end); */
+ // printf("!!! %d %d\n", start, end);
return true;
}
index_step += 1;
diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c
index b0d00007580..f0cf19bf508 100644
--- a/source/blender/blenlib/intern/scanfill.c
+++ b/source/blender/blenlib/intern/scanfill.c
@@ -430,7 +430,7 @@ static void testvertexnearedge(ScanFillContext *sf_ctx)
/* new edge */
ed1 = BLI_scanfill_edge_add(sf_ctx, eed->v1, eve);
- /* printf("fill: vertex near edge %x\n", eve); */
+ // printf("fill: vertex near edge %x\n", eve);
ed1->poly_nr = eed->poly_nr;
eed->v1 = eve;
eve->edge_tot = 3;
@@ -608,7 +608,7 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl
sc = scdata;
for (a = 0; a < verts; a++) {
- /* printf("VERTEX %d index %d\n", a, sc->vert->tmp.u); */
+ // printf("VERTEX %d index %d\n", a, sc->vert->tmp.u);
/* Set connect-flags. */
for (ed1 = sc->edge_first; ed1; ed1 = eed_next) {
eed_next = ed1->next;
@@ -634,13 +634,13 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl
* (and doesn't work during grab). */
/* if (callLocalInterruptCallBack()) break; */
if (totface >= maxface) {
- /* printf("Fill error: endless loop. Escaped at vert %d, tot: %d.\n", a, verts); */
+ // printf("Fill error: endless loop. Escaped at vert %d, tot: %d.\n", a, verts);
a = verts;
break;
}
if (ed2 == NULL) {
sc->edge_first = sc->edge_last = NULL;
- /* printf("just 1 edge to vert\n"); */
+ // printf("just 1 edge to vert\n");
BLI_addtail(&sf_ctx->filledgebase, ed1);
ed1->v2->f = SF_VERT_NEW;
ed1->v1->edge_tot--;
@@ -662,7 +662,7 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl
break;
}
- /* printf("test verts %d %d %d\n", v1->tmp.u, v2->tmp.u, v3->tmp.u); */
+ // printf("test verts %d %d %d\n", v1->tmp.u, v2->tmp.u, v3->tmp.u);
miny = min_ff(v1->xy[1], v3->xy[1]);
sc1 = sc + 1;
@@ -705,7 +705,7 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl
if (best_sc) {
/* make new edge, and start over */
- /* printf("add new edge %d %d and start again\n", v2->tmp.u, best_sc->vert->tmp.u); */
+ // printf("add new edge %d %d and start again\n", v2->tmp.u, best_sc->vert->tmp.u);
ed3 = BLI_scanfill_edge_add(sf_ctx, v2, best_sc->vert);
BLI_remlink(&sf_ctx->filledgebase, ed3);
@@ -717,7 +717,7 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl
}
else {
/* new triangle */
- /* printf("add face %d %d %d\n", v1->tmp.u, v2->tmp.u, v3->tmp.u); */
+ // printf("add face %d %d %d\n", v1->tmp.u, v2->tmp.u, v3->tmp.u);
addfillface(sf_ctx, v1, v2, v3);
totface++;
BLI_remlink((ListBase *)&(sc->edge_first), ed1);
@@ -741,11 +741,11 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl
ed3->v1->edge_tot++;
ed3->v2->edge_tot++;
- /* printf("add new edge %x %x\n", v1, v3); */
+ // printf("add new edge %x %x\n", v1, v3);
sc1 = addedgetoscanlist(scdata, ed3, verts);
if (sc1) { /* ed3 already exists: remove if a boundary */
- /* printf("Edge exists\n"); */
+ // printf("Edge exists\n");
ed3->v1->edge_tot--;
ed3->v2->edge_tot--;
@@ -954,7 +954,7 @@ unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const
poly++;
}
}
- /* printf("amount of poly's: %d\n", poly); */
+ // printf("amount of poly's: %d\n", poly);
}
else if (poly) {
/* we pre-calculated poly_nr */
@@ -1020,7 +1020,7 @@ unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const
}
}
if (BLI_listbase_is_empty(&sf_ctx->filledgebase)) {
- /* printf("All edges removed\n"); */
+ // printf("All edges removed\n");
return 0;
}
}
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 19b925535e2..47bb2f0e8dd 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -114,7 +114,7 @@ double BLI_dir_free_space(const char *dir)
tmp[0] = '\\';
tmp[1] = 0; /* Just a fail-safe. */
- if (ELEM(dir[0] == '/', '\\')) {
+ if (ELEM(dir[0], '/', '\\')) {
tmp[0] = '\\';
tmp[1] = 0;
}
diff --git a/source/blender/blenlib/tests/BLI_math_vector_test.cc b/source/blender/blenlib/tests/BLI_math_vector_test.cc
index 7e75a521d4c..955f02b8065 100644
--- a/source/blender/blenlib/tests/BLI_math_vector_test.cc
+++ b/source/blender/blenlib/tests/BLI_math_vector_test.cc
@@ -45,3 +45,21 @@ TEST(math_vector, ClampVecWithVecs)
EXPECT_FLOAT_EQ(1.0f, c[0]);
EXPECT_FLOAT_EQ(3.0f, c[1]);
}
+
+TEST(math_vector, test_invert_v3_safe)
+{
+ float v3_with_zeroes[3] = {0.0f, 2.0f, 3.0f};
+ invert_v3_safe(v3_with_zeroes);
+ EXPECT_FLOAT_EQ(0.0f, v3_with_zeroes[0]);
+ EXPECT_FLOAT_EQ(0.5f, v3_with_zeroes[1]);
+ EXPECT_FLOAT_EQ(0.33333333333f, v3_with_zeroes[2]);
+
+ float v3_without_zeroes[3] = {1.0f, 2.0f, 3.0f};
+ float inverted_unsafe[3] = {1.0f, 2.0f, 3.0f};
+ invert_v3_safe(v3_without_zeroes);
+ invert_v3(inverted_unsafe);
+
+ EXPECT_FLOAT_EQ(inverted_unsafe[0], v3_without_zeroes[0]);
+ EXPECT_FLOAT_EQ(inverted_unsafe[1], v3_without_zeroes[1]);
+ EXPECT_FLOAT_EQ(inverted_unsafe[2], v3_without_zeroes[2]);
+}
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 04e13fbd1d6..c3a33115613 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -108,6 +108,9 @@ typedef struct BlendFileReadReport {
* during this file read. */
int missing_libraries;
int missing_linked_id;
+ /* Some sub-categories of the above `missing_linked_id` counter. */
+ int missing_obdata;
+ int missing_obproxies;
/* Number of root override IDs that were resynced. */
int resynced_lib_overrides;
} count;
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 95440f78cd2..9aec18ea279 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -583,11 +583,6 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
sizeof(scene->master_collection->id.name) - 2);
}
}
- LISTBASE_FOREACH (Material *, mat, &bmain->materials) {
- if (!(mat->lineart.flags & LRT_MATERIAL_CUSTOM_OCCLUSION_EFFECTIVENESS)) {
- mat->lineart.mat_occlusion = 1;
- }
- }
}
if (!MAIN_VERSION_ATLEAST(bmain, 300, 9)) {
@@ -618,6 +613,11 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
tool_settings->snap_uv_mode &= ~(1 << 4);
}
}
+ LISTBASE_FOREACH (Material *, mat, &bmain->materials) {
+ if (!(mat->lineart.flags & LRT_MATERIAL_CUSTOM_OCCLUSION_EFFECTIVENESS)) {
+ mat->lineart.mat_occlusion = 1;
+ }
+ }
}
if (!MAIN_VERSION_ATLEAST(bmain, 300, 13)) {
diff --git a/source/blender/bmesh/intern/bmesh_mesh_normals.c b/source/blender/bmesh/intern/bmesh_mesh_normals.c
index 6dfaa0ca688..746f094aed6 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_normals.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_normals.c
@@ -50,6 +50,8 @@ static void bm_edge_tag_from_smooth(const float (*fnos)[3],
BMEdge *e,
const float split_angle_cos);
+static void bm_edge_tag_clear(BMEdge *e);
+
/* -------------------------------------------------------------------- */
/** \name Update Vertex & Face Normals
* \{ */
@@ -754,7 +756,7 @@ static int bm_mesh_loops_calc_normals_for_loop(BMesh *bm,
/* Fix/update all clnors of this fan with computed average value. */
/* Prints continuously when merge custom normals, so commenting. */
- /* printf("Invalid clnors in this fan!\n"); */
+ // printf("Invalid clnors in this fan!\n");
while ((clnor = BLI_SMALLSTACK_POP(clnors))) {
// print_v2("org clnor", clnor);
@@ -820,9 +822,10 @@ BLI_INLINE bool bm_edge_is_smooth_no_angle_test(const BMEdge *e,
const BMLoop *l_a,
const BMLoop *l_b)
{
+ BLI_assert(l_a->radial_next == l_b);
return (
/* The face is manifold. */
- (l_a->radial_next == l_b) &&
+ (l_b->radial_next == l_a) &&
/* Faces have winding that faces the same way. */
(l_a->v != l_b->v) &&
/* The edge is smooth. */
@@ -863,6 +866,13 @@ static void bm_edge_tag_from_smooth(const float (*fnos)[3], BMEdge *e, const flo
}
}
+static void bm_edge_tag_clear(BMEdge *e)
+{
+ /* No need for atomics here as this is a single byte. */
+ char *hflag_p = &e->head.hflag;
+ *hflag_p = *hflag_p & ~BM_ELEM_TAG;
+}
+
/**
* A version of #bm_edge_tag_from_smooth that sets sharp edges
* when they would be considered smooth but exceed the split angle .
@@ -944,9 +954,13 @@ static void bm_mesh_loops_calc_normals_for_vert_with_clnors(BMesh *bm,
continue;
}
+ /* Always set as #bm_mesh_loops_calc_normals_for_loop checks the tag. */
if (do_edge_tag) {
bm_edge_tag_from_smooth(fnos, e_curr_iter, split_angle_cos);
}
+ else {
+ bm_edge_tag_clear(e_curr_iter);
+ }
do { /* Radial loops. */
if (l_curr->v != v) {
@@ -1052,9 +1066,13 @@ static void bm_mesh_loops_calc_normals_for_vert_without_clnors(
continue;
}
+ /* Always set as #bm_mesh_loops_calc_normals_for_loop checks the tag. */
if (do_edge_tag) {
bm_edge_tag_from_smooth(fnos, e_curr_iter, split_angle_cos);
}
+ else {
+ bm_edge_tag_clear(e_curr_iter);
+ }
do { /* Radial loops. */
if (l_curr->v != v) {
@@ -1816,8 +1834,8 @@ void BM_lnorspace_invalidate(BMesh *bm, const bool do_invalidate_all)
BM_mesh_elem_index_ensure(bm, BM_VERT);
/* When we affect a given vertex, we may affect following smooth fans:
- * - all smooth fans of said vertex;
- * - all smooth fans of all immediate loop-neighbors vertices;
+ * - all smooth fans of said vertex;
+ * - all smooth fans of all immediate loop-neighbors vertices;
* This can be simplified as 'all loops of selected vertices and their immediate neighbors'
* need to be tagged for update.
*/
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c
index 0f99f04ad57..e306fe47770 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -2511,7 +2511,7 @@ static void bevel_harden_normals(BevelParams *bp, BMesh *bm)
pnorm = lnext->f->no;
}
else {
- /* printf("unexpected harden case (edge)\n"); */
+ // printf("unexpected harden case (edge)\n");
}
}
else if (fkind == F_VERT) {
@@ -2554,7 +2554,7 @@ static void bevel_harden_normals(BevelParams *bp, BMesh *bm)
pnorm = norm;
}
else {
- /* printf("unexpected harden case (vert)\n"); */
+ // printf("unexpected harden case (vert)\n");
}
}
}
diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c
index 86b4a0ac727..96ab8a28e09 100644
--- a/source/blender/draw/engines/select/select_engine.c
+++ b/source/blender/draw/engines/select/select_engine.c
@@ -193,7 +193,7 @@ static void select_cache_init(void *vedata)
if (e_data.context.select_mode & SCE_SELECT_VERTEX) {
DRW_PASS_CREATE(psl->select_id_vert_pass, state);
pd->shgrp_vert = DRW_shgroup_create(sh->select_id_flat, psl->select_id_vert_pass);
- DRW_shgroup_uniform_float_copy(pd->shgrp_vert, "sizeVertex", G_draw.block.sizeVertex);
+ DRW_shgroup_uniform_float_copy(pd->shgrp_vert, "sizeVertex", 2 * G_draw.block.sizeVertex);
}
}
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 35072518b66..a8cbe7b18b5 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -2682,6 +2682,7 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons
drw_viewport_var_init();
/* Update UBO's */
+ UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
DRW_globals_update();
/* Init Select Engine */
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c
index baf8adf28d0..6469c47ab11 100644
--- a/source/blender/editors/animation/anim_draw.c
+++ b/source/blender/editors/animation/anim_draw.c
@@ -494,7 +494,7 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
Object *ob = CTX_data_active_object(C);
Mask *mask = CTX_data_edit_mask(C);
bDopeSheet ads = {NULL};
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
ActKeyColumn *aknext, *akprev;
float cfranext, cfraprev;
bool donenext = false, doneprev = false;
@@ -502,9 +502,6 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
cfranext = cfraprev = (float)(CFRA);
- /* init binarytree-list for getting keyframes */
- BLI_dlrbTree_init(&keys);
-
/* seed up dummy dopesheet context with flags to perform necessary filtering */
if ((scene->flag & SCE_KEYS_NO_SELONLY) == 0) {
/* only selected channels are included */
@@ -512,22 +509,22 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
}
/* populate tree with keyframe nodes */
- scene_to_keylist(&ads, scene, &keys, 0);
- gpencil_to_keylist(&ads, scene->gpd, &keys, false);
+ scene_to_keylist(&ads, scene, keylist, 0);
+ gpencil_to_keylist(&ads, scene->gpd, keylist, false);
if (ob) {
- ob_to_keylist(&ads, ob, &keys, 0);
- gpencil_to_keylist(&ads, ob->data, &keys, false);
+ ob_to_keylist(&ads, ob, keylist, 0);
+ gpencil_to_keylist(&ads, ob->data, keylist, false);
}
if (mask) {
MaskLayer *masklay = BKE_mask_layer_active(mask);
- mask_to_keylist(&ads, masklay, &keys);
+ mask_to_keylist(&ads, masklay, keylist);
}
/* find matching keyframe in the right direction */
do {
- aknext = (ActKeyColumn *)BLI_dlrbTree_search_next(&keys, compare_ak_cfraPtr, &cfranext);
+ aknext = ED_keylist_find_next(keylist, cfranext);
if (aknext) {
if (CFRA == (int)aknext->cfra) {
@@ -545,7 +542,7 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
} while ((aknext != NULL) && (donenext == false));
do {
- akprev = (ActKeyColumn *)BLI_dlrbTree_search_prev(&keys, compare_ak_cfraPtr, &cfraprev);
+ akprev = ED_keylist_find_prev(keylist, cfraprev);
if (akprev) {
if (CFRA == (int)akprev->cfra) {
@@ -562,7 +559,7 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
} while ((akprev != NULL) && (doneprev == false));
/* free temp stuff */
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
/* any success? */
if (doneprev || donenext) {
diff --git a/source/blender/editors/animation/anim_motion_paths.c b/source/blender/editors/animation/anim_motion_paths.c
index bddd5dbff55..2a3ae35aab0 100644
--- a/source/blender/editors/animation/anim_motion_paths.c
+++ b/source/blender/editors/animation/anim_motion_paths.c
@@ -55,7 +55,7 @@ typedef struct MPathTarget {
bMotionPath *mpath; /* motion path in question */
- DLRBT_Tree keys; /* temp, to know where the keyframes are */
+ struct AnimKeylist *keylist; /* temp, to know where the keyframes are */
/* Original (Source Objects) */
Object *ob; /* source object */
@@ -187,7 +187,7 @@ static void motionpaths_calc_bake_targets(ListBase *targets, int cframe)
float mframe = (float)(cframe);
/* Tag if it's a keyframe */
- if (BLI_dlrbTree_search_exact(&mpt->keys, compare_ak_cfraPtr, &mframe)) {
+ if (ED_keylist_find_exact(mpt->keylist, mframe)) {
mpv->flag |= MOTIONPATH_VERT_KEY;
}
else {
@@ -234,52 +234,54 @@ static void motionpath_get_global_framerange(ListBase *targets, int *r_sfra, int
}
}
-static int motionpath_get_prev_keyframe(MPathTarget *mpt, DLRBT_Tree *fcu_keys, int current_frame)
+static int motionpath_get_prev_keyframe(MPathTarget *mpt,
+ struct AnimKeylist *keylist,
+ int current_frame)
{
if (current_frame <= mpt->mpath->start_frame) {
return mpt->mpath->start_frame;
}
float current_frame_float = current_frame;
- DLRBT_Node *node = BLI_dlrbTree_search_prev(fcu_keys, compare_ak_cfraPtr, &current_frame_float);
- if (node == NULL) {
+ const ActKeyColumn *ak = ED_keylist_find_prev(keylist, current_frame_float);
+ if (ak == NULL) {
return mpt->mpath->start_frame;
}
- ActKeyColumn *key_data = (ActKeyColumn *)node;
- return key_data->cfra;
+ return ak->cfra;
}
static int motionpath_get_prev_prev_keyframe(MPathTarget *mpt,
- DLRBT_Tree *fcu_keys,
+ struct AnimKeylist *keylist,
int current_frame)
{
- int frame = motionpath_get_prev_keyframe(mpt, fcu_keys, current_frame);
- return motionpath_get_prev_keyframe(mpt, fcu_keys, frame);
+ int frame = motionpath_get_prev_keyframe(mpt, keylist, current_frame);
+ return motionpath_get_prev_keyframe(mpt, keylist, frame);
}
-static int motionpath_get_next_keyframe(MPathTarget *mpt, DLRBT_Tree *fcu_keys, int current_frame)
+static int motionpath_get_next_keyframe(MPathTarget *mpt,
+ struct AnimKeylist *keylist,
+ int current_frame)
{
if (current_frame >= mpt->mpath->end_frame) {
return mpt->mpath->end_frame;
}
float current_frame_float = current_frame;
- DLRBT_Node *node = BLI_dlrbTree_search_next(fcu_keys, compare_ak_cfraPtr, &current_frame_float);
- if (node == NULL) {
+ const ActKeyColumn *ak = ED_keylist_find_next(keylist, current_frame_float);
+ if (ak == NULL) {
return mpt->mpath->end_frame;
}
- ActKeyColumn *key_data = (ActKeyColumn *)node;
- return key_data->cfra;
+ return ak->cfra;
}
static int motionpath_get_next_next_keyframe(MPathTarget *mpt,
- DLRBT_Tree *fcu_keys,
+ struct AnimKeylist *keylist,
int current_frame)
{
- int frame = motionpath_get_next_keyframe(mpt, fcu_keys, current_frame);
- return motionpath_get_next_keyframe(mpt, fcu_keys, frame);
+ int frame = motionpath_get_next_keyframe(mpt, keylist, current_frame);
+ return motionpath_get_next_keyframe(mpt, keylist, frame);
}
static bool motionpath_check_can_use_keyframe_range(MPathTarget *UNUSED(mpt),
@@ -324,17 +326,16 @@ static void motionpath_calculate_update_range(MPathTarget *mpt,
* Could be optimized further by storing some flags about which channels has been modified so
* we ignore all others (which can potentially make an update range unnecessary wide). */
for (FCurve *fcu = fcurve_list->first; fcu != NULL; fcu = fcu->next) {
- DLRBT_Tree fcu_keys;
- BLI_dlrbTree_init(&fcu_keys);
- fcurve_to_keylist(adt, fcu, &fcu_keys, 0);
+ struct AnimKeylist *keylist = ED_keylist_create();
+ fcurve_to_keylist(adt, fcu, keylist, 0);
- int fcu_sfra = motionpath_get_prev_prev_keyframe(mpt, &fcu_keys, current_frame);
- int fcu_efra = motionpath_get_next_next_keyframe(mpt, &fcu_keys, current_frame);
+ int fcu_sfra = motionpath_get_prev_prev_keyframe(mpt, keylist, current_frame);
+ int fcu_efra = motionpath_get_next_next_keyframe(mpt, keylist, current_frame);
/* Extend range further, since acceleration compensation propagates even further away. */
if (fcu->auto_smoothing != FCURVE_SMOOTH_NONE) {
- fcu_sfra = motionpath_get_prev_prev_keyframe(mpt, &fcu_keys, fcu_sfra);
- fcu_efra = motionpath_get_next_next_keyframe(mpt, &fcu_keys, fcu_efra);
+ fcu_sfra = motionpath_get_prev_prev_keyframe(mpt, keylist, fcu_sfra);
+ fcu_efra = motionpath_get_next_next_keyframe(mpt, keylist, fcu_efra);
}
if (fcu_sfra <= fcu_efra) {
@@ -342,14 +343,14 @@ static void motionpath_calculate_update_range(MPathTarget *mpt,
*r_efra = max_ii(*r_efra, fcu_efra);
}
- BLI_dlrbTree_free(&fcu_keys);
+ ED_keylist_free(keylist);
}
}
static void motionpath_free_free_tree_data(ListBase *targets)
{
LISTBASE_FOREACH (MPathTarget *, mpt, targets) {
- BLI_dlrbTree_free(&mpt->keys);
+ ED_keylist_free(mpt->keylist);
}
}
@@ -418,7 +419,7 @@ void animviz_calc_motionpaths(Depsgraph *depsgraph,
AnimData *adt = BKE_animdata_from_id(&mpt->ob_eval->id);
/* build list of all keyframes in active action for object or pchan */
- BLI_dlrbTree_init(&mpt->keys);
+ mpt->keylist = ED_keylist_create();
ListBase *fcurve_list = NULL;
if (adt) {
@@ -433,12 +434,12 @@ void animviz_calc_motionpaths(Depsgraph *depsgraph,
if (agrp) {
fcurve_list = &agrp->channels;
- agroup_to_keylist(adt, agrp, &mpt->keys, 0);
+ agroup_to_keylist(adt, agrp, mpt->keylist, 0);
}
}
else {
fcurve_list = &adt->action->curves;
- action_to_keylist(adt, adt->action, &mpt->keys, 0);
+ action_to_keylist(adt, adt->action, mpt->keylist, 0);
}
}
@@ -502,7 +503,7 @@ void animviz_calc_motionpaths(Depsgraph *depsgraph,
avs->recalc &= ~ANIMVIZ_RECALC_PATHS;
/* Clean temp data */
- BLI_dlrbTree_free(&mpt->keys);
+ ED_keylist_free(mpt->keylist);
/* Free previous batches to force update. */
GPU_VERTBUF_DISCARD_SAFE(mpath->points_vbo);
diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c
index 4f512c9d7ca..deed79942ac 100644
--- a/source/blender/editors/animation/keyframes_draw.c
+++ b/source/blender/editors/animation/keyframes_draw.c
@@ -184,16 +184,12 @@ void draw_keyframe_shape(float x,
}
static void draw_keylist(View2D *v2d,
- DLRBT_Tree *keys,
+ const struct AnimKeylist *keylist,
float ypos,
float yscale_fac,
bool channelLocked,
int saction_flag)
{
- if (keys == NULL) {
- return;
- }
-
const float icon_sz = U.widget_unit * 0.5f * yscale_fac;
const float half_icon_sz = 0.5f * icon_sz;
const float smaller_sz = 0.35f * icon_sz;
@@ -228,6 +224,8 @@ static void draw_keylist(View2D *v2d,
copy_v4_v4(ipo_color_mix, ipo_color);
ipo_color_mix[3] *= 0.5f;
+ const ListBase *keys = ED_keylist_listbase(keylist);
+
LISTBASE_FOREACH (ActKeyColumn *, ab, keys) {
/* Draw grease pencil bars between keyframes. */
if ((ab->next != NULL) && (ab->block.flag & ACTKEYBLOCK_FLAG_GPENCIL)) {
@@ -378,134 +376,118 @@ static void draw_keylist(View2D *v2d,
void draw_summary_channel(
View2D *v2d, bAnimContext *ac, float ypos, float yscale_fac, int saction_flag)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
saction_flag &= ~SACTION_SHOW_EXTREMES;
- BLI_dlrbTree_init(&keys);
+ summary_to_keylist(ac, keylist, saction_flag);
- summary_to_keylist(ac, &keys, saction_flag);
+ draw_keylist(v2d, keylist, ypos, yscale_fac, false, saction_flag);
- draw_keylist(v2d, &keys, ypos, yscale_fac, false, saction_flag);
-
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
void draw_scene_channel(
View2D *v2d, bDopeSheet *ads, Scene *sce, float ypos, float yscale_fac, int saction_flag)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
saction_flag &= ~SACTION_SHOW_EXTREMES;
- BLI_dlrbTree_init(&keys);
-
- scene_to_keylist(ads, sce, &keys, saction_flag);
+ scene_to_keylist(ads, sce, keylist, saction_flag);
- draw_keylist(v2d, &keys, ypos, yscale_fac, false, saction_flag);
+ draw_keylist(v2d, keylist, ypos, yscale_fac, false, saction_flag);
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
void draw_object_channel(
View2D *v2d, bDopeSheet *ads, Object *ob, float ypos, float yscale_fac, int saction_flag)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
saction_flag &= ~SACTION_SHOW_EXTREMES;
- BLI_dlrbTree_init(&keys);
-
- ob_to_keylist(ads, ob, &keys, saction_flag);
+ ob_to_keylist(ads, ob, keylist, saction_flag);
- draw_keylist(v2d, &keys, ypos, yscale_fac, false, saction_flag);
+ draw_keylist(v2d, keylist, ypos, yscale_fac, false, saction_flag);
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
void draw_fcurve_channel(
View2D *v2d, AnimData *adt, FCurve *fcu, float ypos, float yscale_fac, int saction_flag)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
bool locked = (fcu->flag & FCURVE_PROTECTED) ||
((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) ||
((adt && adt->action) && ID_IS_LINKED(adt->action));
- BLI_dlrbTree_init(&keys);
+ fcurve_to_keylist(adt, fcu, keylist, saction_flag);
- fcurve_to_keylist(adt, fcu, &keys, saction_flag);
+ draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
- draw_keylist(v2d, &keys, ypos, yscale_fac, locked, saction_flag);
-
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
void draw_agroup_channel(
View2D *v2d, AnimData *adt, bActionGroup *agrp, float ypos, float yscale_fac, int saction_flag)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
bool locked = (agrp->flag & AGRP_PROTECTED) ||
((adt && adt->action) && ID_IS_LINKED(adt->action));
- BLI_dlrbTree_init(&keys);
-
- agroup_to_keylist(adt, agrp, &keys, saction_flag);
+ agroup_to_keylist(adt, agrp, keylist, saction_flag);
- draw_keylist(v2d, &keys, ypos, yscale_fac, locked, saction_flag);
+ draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
void draw_action_channel(
View2D *v2d, AnimData *adt, bAction *act, float ypos, float yscale_fac, int saction_flag)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
bool locked = (act && ID_IS_LINKED(act));
saction_flag &= ~SACTION_SHOW_EXTREMES;
- BLI_dlrbTree_init(&keys);
-
- action_to_keylist(adt, act, &keys, saction_flag);
+ action_to_keylist(adt, act, keylist, saction_flag);
- draw_keylist(v2d, &keys, ypos, yscale_fac, locked, saction_flag);
+ draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
void draw_gpencil_channel(
View2D *v2d, bDopeSheet *ads, bGPdata *gpd, float ypos, float yscale_fac, int saction_flag)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
saction_flag &= ~SACTION_SHOW_EXTREMES;
- BLI_dlrbTree_init(&keys);
+ gpencil_to_keylist(ads, gpd, keylist, false);
- gpencil_to_keylist(ads, gpd, &keys, false);
+ draw_keylist(v2d, keylist, ypos, yscale_fac, false, saction_flag);
- draw_keylist(v2d, &keys, ypos, yscale_fac, false, saction_flag);
-
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
void draw_gpl_channel(
View2D *v2d, bDopeSheet *ads, bGPDlayer *gpl, float ypos, float yscale_fac, int saction_flag)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
bool locked = (gpl->flag & GP_LAYER_LOCKED) != 0;
- BLI_dlrbTree_init(&keys);
-
- gpl_to_keylist(ads, gpl, &keys);
+ gpl_to_keylist(ads, gpl, keylist);
- draw_keylist(v2d, &keys, ypos, yscale_fac, locked, saction_flag);
+ draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
void draw_masklay_channel(View2D *v2d,
@@ -515,15 +497,13 @@ void draw_masklay_channel(View2D *v2d,
float yscale_fac,
int saction_flag)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
bool locked = (masklay->flag & MASK_LAYERFLAG_LOCKED) != 0;
- BLI_dlrbTree_init(&keys);
-
- mask_to_keylist(ads, masklay, &keys);
+ mask_to_keylist(ads, masklay, keylist);
- draw_keylist(v2d, &keys, ypos, yscale_fac, locked, saction_flag);
+ draw_keylist(v2d, keylist, ypos, yscale_fac, locked, saction_flag);
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
diff --git a/source/blender/editors/animation/keyframes_keylist.c b/source/blender/editors/animation/keyframes_keylist.c
index 47ed2b56300..8f0f6d753be 100644
--- a/source/blender/editors/animation/keyframes_keylist.c
+++ b/source/blender/editors/animation/keyframes_keylist.c
@@ -32,6 +32,7 @@
#include "BLI_dlrbTree.h"
#include "BLI_listbase.h"
+#include "BLI_range.h"
#include "BLI_utildefines.h"
#include "DNA_anim_types.h"
@@ -48,6 +49,83 @@
/* *************************** Keyframe Processing *************************** */
+typedef struct AnimKeylist {
+ DLRBT_Tree keys;
+} AnimKeylist;
+
+static void ED_keylist_init(AnimKeylist *keylist)
+{
+ BLI_dlrbTree_init(&keylist->keys);
+}
+
+AnimKeylist *ED_keylist_create(void)
+{
+ AnimKeylist *keylist = MEM_callocN(sizeof(AnimKeylist), __func__);
+ ED_keylist_init(keylist);
+ return keylist;
+}
+
+void ED_keylist_free(AnimKeylist *keylist)
+{
+ BLI_assert(keylist);
+ BLI_dlrbTree_free(&keylist->keys);
+ MEM_freeN(keylist);
+}
+
+ActKeyColumn *ED_keylist_find_exact(const AnimKeylist *keylist, float cfra)
+{
+ return (ActKeyColumn *)BLI_dlrbTree_search_exact(&keylist->keys, compare_ak_cfraPtr, &cfra);
+}
+
+ActKeyColumn *ED_keylist_find_next(const AnimKeylist *keylist, float cfra)
+{
+ return (ActKeyColumn *)BLI_dlrbTree_search_next(&keylist->keys, compare_ak_cfraPtr, &cfra);
+}
+
+ActKeyColumn *ED_keylist_find_prev(const AnimKeylist *keylist, float cfra)
+{
+ return (ActKeyColumn *)BLI_dlrbTree_search_prev(&keylist->keys, compare_ak_cfraPtr, &cfra);
+}
+
+/* TODO(jbakker): Should we change this to use `ED_keylist_find_next(keys, min_fra)` and only check
+ * boundary of `max_fra`. */
+ActKeyColumn *ED_keylist_find_any_between(const AnimKeylist *keylist, float min_fra, float max_fra)
+{
+ for (ActKeyColumn *ak = keylist->keys.root; ak;
+ ak = (ak->cfra < min_fra) ? ak->right : ak->left) {
+ if (IN_RANGE(ak->cfra, min_fra, max_fra)) {
+ return ak;
+ }
+ }
+ return NULL;
+}
+
+bool ED_keylist_is_empty(const struct AnimKeylist *keylist)
+{
+ return keylist->keys.root == NULL;
+}
+
+const struct ListBase *ED_keylist_listbase(const AnimKeylist *keylist)
+{
+ return (ListBase *)&keylist->keys;
+}
+
+bool ED_keylist_frame_range(const struct AnimKeylist *keylist, Range2f *r_frame_range)
+{
+ BLI_assert(r_frame_range);
+
+ if (ED_keylist_is_empty(keylist)) {
+ return false;
+ }
+
+ const ActKeyColumn *first_column = (const ActKeyColumn *)keylist->keys.first;
+ r_frame_range->min = first_column->cfra;
+
+ const ActKeyColumn *last_column = (const ActKeyColumn *)keylist->keys.last;
+ r_frame_range->max = last_column->cfra;
+
+ return true;
+}
/* ActKeyColumns (Keyframe Columns) ------------------------------------------ */
BLI_INLINE bool is_cfra_eq(float a, float b)
@@ -323,33 +401,33 @@ static void nupdate_ak_masklayshape(void *node, void *data)
/* --------------- */
/* Add the given BezTriple to the given 'list' of Keyframes */
-static void add_bezt_to_keycolumns_list(DLRBT_Tree *keys, BezTripleChain *bezt)
+static void add_bezt_to_keycolumns_list(AnimKeylist *keylist, BezTripleChain *bezt)
{
- if (ELEM(NULL, keys, bezt)) {
+ if (ELEM(NULL, keylist, bezt)) {
return;
}
- BLI_dlrbTree_add(keys, compare_ak_bezt, nalloc_ak_bezt, nupdate_ak_bezt, bezt);
+ BLI_dlrbTree_add(&keylist->keys, compare_ak_bezt, nalloc_ak_bezt, nupdate_ak_bezt, bezt);
}
/* Add the given GPencil Frame to the given 'list' of Keyframes */
-static void add_gpframe_to_keycolumns_list(DLRBT_Tree *keys, bGPDframe *gpf)
+static void add_gpframe_to_keycolumns_list(AnimKeylist *keylist, bGPDframe *gpf)
{
- if (ELEM(NULL, keys, gpf)) {
+ if (ELEM(NULL, keylist, gpf)) {
return;
}
- BLI_dlrbTree_add(keys, compare_ak_gpframe, nalloc_ak_gpframe, nupdate_ak_gpframe, gpf);
+ BLI_dlrbTree_add(&keylist->keys, compare_ak_gpframe, nalloc_ak_gpframe, nupdate_ak_gpframe, gpf);
}
/* Add the given MaskLayerShape Frame to the given 'list' of Keyframes */
-static void add_masklay_to_keycolumns_list(DLRBT_Tree *keys, MaskLayerShape *masklay_shape)
+static void add_masklay_to_keycolumns_list(AnimKeylist *keylist, MaskLayerShape *masklay_shape)
{
- if (ELEM(NULL, keys, masklay_shape)) {
+ if (ELEM(NULL, keylist, masklay_shape)) {
return;
}
- BLI_dlrbTree_add(keys,
+ BLI_dlrbTree_add(&keylist->keys,
compare_ak_masklayshape,
nalloc_ak_masklayshape,
nupdate_ak_masklayshape,
@@ -423,9 +501,9 @@ static void add_keyblock_info(ActKeyColumn *col, const ActKeyBlockInfo *block)
}
}
-static void add_bezt_to_keyblocks_list(DLRBT_Tree *keys, BezTriple *bezt, int bezt_len)
+static void add_bezt_to_keyblocks_list(AnimKeylist *keylist, BezTriple *bezt, int bezt_len)
{
- ActKeyColumn *col = keys->first;
+ ActKeyColumn *col = keylist->keys.first;
if (bezt && bezt_len >= 2) {
ActKeyBlockInfo block;
@@ -444,7 +522,7 @@ static void add_bezt_to_keyblocks_list(DLRBT_Tree *keys, BezTriple *bezt, int be
/* Backtrack to find the right location. */
if (is_cfra_lt(bezt[1].vec[1][0], col->cfra)) {
ActKeyColumn *newcol = (ActKeyColumn *)BLI_dlrbTree_search_exact(
- keys, compare_ak_cfraPtr, &bezt[1].vec[1][0]);
+ &keylist->keys, compare_ak_cfraPtr, &bezt[1].vec[1][0]);
if (newcol != NULL) {
col = newcol;
@@ -486,22 +564,22 @@ static void add_bezt_to_keyblocks_list(DLRBT_Tree *keys, BezTriple *bezt, int be
* This must be called even by animation sources that don't generate
* keyblocks to keep the data structure consistent after adding columns.
*/
-static void update_keyblocks(DLRBT_Tree *keys, BezTriple *bezt, int bezt_len)
+static void update_keyblocks(AnimKeylist *keylist, BezTriple *bezt, int bezt_len)
{
/* Recompute the prev/next linked list. */
- BLI_dlrbTree_linkedlist_sync(keys);
+ BLI_dlrbTree_linkedlist_sync(&keylist->keys);
/* Find the curve count */
int max_curve = 0;
- LISTBASE_FOREACH (ActKeyColumn *, col, keys) {
+ LISTBASE_FOREACH (ActKeyColumn *, col, &keylist->keys) {
max_curve = MAX2(max_curve, col->totcurve);
}
/* Propagate blocks to inserted keys */
ActKeyColumn *prev_ready = NULL;
- LISTBASE_FOREACH (ActKeyColumn *, col, keys) {
+ LISTBASE_FOREACH (ActKeyColumn *, col, &keylist->keys) {
/* Pre-existing column. */
if (col->totcurve > 0) {
prev_ready = col;
@@ -516,7 +594,7 @@ static void update_keyblocks(DLRBT_Tree *keys, BezTriple *bezt, int bezt_len)
}
/* Add blocks on top */
- add_bezt_to_keyblocks_list(keys, bezt, bezt_len);
+ add_bezt_to_keyblocks_list(keylist, bezt, bezt_len);
}
/* --------- */
@@ -540,7 +618,7 @@ int actkeyblock_get_valid_hold(ActKeyColumn *ac)
/* *************************** Keyframe List Conversions *************************** */
-void summary_to_keylist(bAnimContext *ac, DLRBT_Tree *keys, int saction_flag)
+void summary_to_keylist(bAnimContext *ac, AnimKeylist *keylist, int saction_flag)
{
if (ac) {
ListBase anim_data = {NULL, NULL};
@@ -561,13 +639,13 @@ void summary_to_keylist(bAnimContext *ac, DLRBT_Tree *keys, int saction_flag)
switch (ale->datatype) {
case ALE_FCURVE:
- fcurve_to_keylist(ale->adt, ale->data, keys, saction_flag);
+ fcurve_to_keylist(ale->adt, ale->data, keylist, saction_flag);
break;
case ALE_MASKLAY:
- mask_to_keylist(ac->ads, ale->data, keys);
+ mask_to_keylist(ac->ads, ale->data, keylist);
break;
case ALE_GPFRAME:
- gpl_to_keylist(ac->ads, ale->data, keys);
+ gpl_to_keylist(ac->ads, ale->data, keylist);
break;
default:
// printf("%s: datatype %d unhandled\n", __func__, ale->datatype);
@@ -579,7 +657,7 @@ void summary_to_keylist(bAnimContext *ac, DLRBT_Tree *keys, int saction_flag)
}
}
-void scene_to_keylist(bDopeSheet *ads, Scene *sce, DLRBT_Tree *keys, int saction_flag)
+void scene_to_keylist(bDopeSheet *ads, Scene *sce, AnimKeylist *keylist, int saction_flag)
{
bAnimContext ac = {NULL};
ListBase anim_data = {NULL, NULL};
@@ -608,13 +686,13 @@ void scene_to_keylist(bDopeSheet *ads, Scene *sce, DLRBT_Tree *keys, int saction
/* loop through each F-Curve, grabbing the keyframes */
for (ale = anim_data.first; ale; ale = ale->next) {
- fcurve_to_keylist(ale->adt, ale->data, keys, saction_flag);
+ fcurve_to_keylist(ale->adt, ale->data, keylist, saction_flag);
}
ANIM_animdata_freelist(&anim_data);
}
-void ob_to_keylist(bDopeSheet *ads, Object *ob, DLRBT_Tree *keys, int saction_flag)
+void ob_to_keylist(bDopeSheet *ads, Object *ob, AnimKeylist *keylist, int saction_flag)
{
bAnimContext ac = {NULL};
ListBase anim_data = {NULL, NULL};
@@ -646,7 +724,7 @@ void ob_to_keylist(bDopeSheet *ads, Object *ob, DLRBT_Tree *keys, int saction_fl
/* loop through each F-Curve, grabbing the keyframes */
for (ale = anim_data.first; ale; ale = ale->next) {
- fcurve_to_keylist(ale->adt, ale->data, keys, saction_flag);
+ fcurve_to_keylist(ale->adt, ale->data, keylist, saction_flag);
}
ANIM_animdata_freelist(&anim_data);
@@ -654,7 +732,7 @@ void ob_to_keylist(bDopeSheet *ads, Object *ob, DLRBT_Tree *keys, int saction_fl
void cachefile_to_keylist(bDopeSheet *ads,
CacheFile *cache_file,
- DLRBT_Tree *keys,
+ AnimKeylist *keylist,
int saction_flag)
{
if (cache_file == NULL) {
@@ -680,13 +758,13 @@ void cachefile_to_keylist(bDopeSheet *ads,
/* loop through each F-Curve, grabbing the keyframes */
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
- fcurve_to_keylist(ale->adt, ale->data, keys, saction_flag);
+ fcurve_to_keylist(ale->adt, ale->data, keylist, saction_flag);
}
ANIM_animdata_freelist(&anim_data);
}
-void fcurve_to_keylist(AnimData *adt, FCurve *fcu, DLRBT_Tree *keys, int saction_flag)
+void fcurve_to_keylist(AnimData *adt, FCurve *fcu, AnimKeylist *keylist, int saction_flag)
{
if (fcu && fcu->totvert && fcu->bezt) {
/* apply NLA-mapping (if applicable) */
@@ -710,11 +788,11 @@ void fcurve_to_keylist(AnimData *adt, FCurve *fcu, DLRBT_Tree *keys, int saction
chain.next = (v + 1 < fcu->totvert) ? &fcu->bezt[v + 1] : is_cyclic ? &fcu->bezt[1] : NULL;
}
- add_bezt_to_keycolumns_list(keys, &chain);
+ add_bezt_to_keycolumns_list(keylist, &chain);
}
/* Update keyblocks. */
- update_keyblocks(keys, fcu->bezt, fcu->totvert);
+ update_keyblocks(keylist, fcu->bezt, fcu->totvert);
/* unapply NLA-mapping if applicable */
if (adt) {
@@ -723,71 +801,71 @@ void fcurve_to_keylist(AnimData *adt, FCurve *fcu, DLRBT_Tree *keys, int saction
}
}
-void agroup_to_keylist(AnimData *adt, bActionGroup *agrp, DLRBT_Tree *keys, int saction_flag)
+void agroup_to_keylist(AnimData *adt, bActionGroup *agrp, AnimKeylist *keylist, int saction_flag)
{
FCurve *fcu;
if (agrp) {
/* loop through F-Curves */
for (fcu = agrp->channels.first; fcu && fcu->grp == agrp; fcu = fcu->next) {
- fcurve_to_keylist(adt, fcu, keys, saction_flag);
+ fcurve_to_keylist(adt, fcu, keylist, saction_flag);
}
}
}
-void action_to_keylist(AnimData *adt, bAction *act, DLRBT_Tree *keys, int saction_flag)
+void action_to_keylist(AnimData *adt, bAction *act, AnimKeylist *keylist, int saction_flag)
{
FCurve *fcu;
if (act) {
/* loop through F-Curves */
for (fcu = act->curves.first; fcu; fcu = fcu->next) {
- fcurve_to_keylist(adt, fcu, keys, saction_flag);
+ fcurve_to_keylist(adt, fcu, keylist, saction_flag);
}
}
}
-void gpencil_to_keylist(bDopeSheet *ads, bGPdata *gpd, DLRBT_Tree *keys, const bool active)
+void gpencil_to_keylist(bDopeSheet *ads, bGPdata *gpd, AnimKeylist *keylist, const bool active)
{
bGPDlayer *gpl;
- if (gpd && keys) {
+ if (gpd && keylist) {
/* for now, just aggregate out all the frames, but only for visible layers */
for (gpl = gpd->layers.last; gpl; gpl = gpl->prev) {
if ((gpl->flag & GP_LAYER_HIDE) == 0) {
if ((!active) || ((active) && (gpl->flag & GP_LAYER_SELECT))) {
- gpl_to_keylist(ads, gpl, keys);
+ gpl_to_keylist(ads, gpl, keylist);
}
}
}
}
}
-void gpl_to_keylist(bDopeSheet *UNUSED(ads), bGPDlayer *gpl, DLRBT_Tree *keys)
+void gpl_to_keylist(bDopeSheet *UNUSED(ads), bGPDlayer *gpl, AnimKeylist *keylist)
{
bGPDframe *gpf;
- if (gpl && keys) {
+ if (gpl && keylist) {
/* Although the frames should already be in an ordered list,
* they are not suitable for displaying yet. */
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
- add_gpframe_to_keycolumns_list(keys, gpf);
+ add_gpframe_to_keycolumns_list(keylist, gpf);
}
- update_keyblocks(keys, NULL, 0);
+ update_keyblocks(keylist, NULL, 0);
}
}
-void mask_to_keylist(bDopeSheet *UNUSED(ads), MaskLayer *masklay, DLRBT_Tree *keys)
+void mask_to_keylist(bDopeSheet *UNUSED(ads), MaskLayer *masklay, AnimKeylist *keylist)
{
MaskLayerShape *masklay_shape;
- if (masklay && keys) {
+ if (masklay && keylist) {
for (masklay_shape = masklay->splines_shapes.first; masklay_shape;
masklay_shape = masklay_shape->next) {
- add_masklay_to_keycolumns_list(keys, masklay_shape);
+ add_masklay_to_keycolumns_list(keylist, masklay_shape);
}
- update_keyblocks(keys, NULL, 0);
+ update_keyblocks(keylist, NULL, 0);
}
}
diff --git a/source/blender/editors/animation/time_scrub_ui.c b/source/blender/editors/animation/time_scrub_ui.c
index 6af033f3cf2..182e61e53b6 100644
--- a/source/blender/editors/animation/time_scrub_ui.c
+++ b/source/blender/editors/animation/time_scrub_ui.c
@@ -244,6 +244,10 @@ void ED_time_scrub_channel_search_draw(const bContext *C, ARegion *region, bDope
UI_block_align_end(block);
UI_block_layout_resolve(block, NULL, NULL);
+ /* Make sure the events are consumed from the search and dont reach other UI blocks since this is
+ * drawn on top of animchannels. */
+ UI_block_flag_enable(block, UI_BLOCK_CLIP_EVENTS);
+ UI_block_bounds_set_normal(block, 0);
UI_block_end(C, block);
UI_block_draw(C, block);
diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c
index cb70b2810d1..646356e7a45 100644
--- a/source/blender/editors/armature/pose_lib.c
+++ b/source/blender/editors/armature/pose_lib.c
@@ -304,8 +304,6 @@ static int poselib_sanitize_exec(bContext *C, wmOperator *op)
{
Object *ob = get_poselib_object(C);
bAction *act = (ob) ? ob->poselib : NULL;
- DLRBT_Tree keys;
- ActKeyColumn *ak;
TimeMarker *marker, *markern;
/* validate action */
@@ -315,11 +313,11 @@ static int poselib_sanitize_exec(bContext *C, wmOperator *op)
}
/* determine which frames have keys */
- BLI_dlrbTree_init(&keys);
- action_to_keylist(NULL, act, &keys, 0);
+ struct AnimKeylist *keylist = ED_keylist_create();
+ action_to_keylist(NULL, act, keylist, 0);
/* for each key, make sure there is a corresponding pose */
- for (ak = keys.first; ak; ak = ak->next) {
+ LISTBASE_FOREACH (const ActKeyColumn *, ak, ED_keylist_listbase(keylist)) {
/* check if any pose matches this */
/* TODO: don't go looking through the list like this every time... */
for (marker = act->markers.first; marker; marker = marker->next) {
@@ -356,7 +354,7 @@ static int poselib_sanitize_exec(bContext *C, wmOperator *op)
}
/* free temp memory */
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
/* send notifiers for this - using keyframe editing notifiers, since action
* may be being shown in anim editors as active action
diff --git a/source/blender/editors/armature/pose_slide.c b/source/blender/editors/armature/pose_slide.c
index 38f562ebf25..238799650a0 100644
--- a/source/blender/editors/armature/pose_slide.c
+++ b/source/blender/editors/armature/pose_slide.c
@@ -146,7 +146,7 @@ typedef struct tPoseSlideOp {
/** links between posechannels and f-curves for all the pose objects. */
ListBase pfLinks;
/** binary tree for quicker searching for keyframes (when applicable) */
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist;
/** current frame number - global time */
int cframe;
@@ -277,7 +277,7 @@ static int pose_slide_init(bContext *C, wmOperator *op, ePoseSlide_Modes mode)
/* Do basic initialize of RB-BST used for finding keyframes, but leave the filling of it up
* to the caller of this (usually only invoke() will do it, to make things more efficient). */
- BLI_dlrbTree_init(&pso->keys);
+ pso->keylist = ED_keylist_create();
/* Initialize numeric input. */
initNumInput(&pso->num);
@@ -306,7 +306,7 @@ static void pose_slide_exit(bContext *C, wmOperator *op)
poseAnim_mapping_free(&pso->pfLinks);
/* Free RB-BST for keyframes (if it contained data). */
- BLI_dlrbTree_free(&pso->keys);
+ ED_keylist_free(pso->keylist);
if (pso->ob_data_array != NULL) {
MEM_freeN(pso->ob_data_array);
@@ -971,60 +971,56 @@ static int pose_slide_invoke_common(bContext *C, wmOperator *op, const wmEvent *
/* Do this for each F-Curve. */
for (ld = pfl->fcurves.first; ld; ld = ld->next) {
FCurve *fcu = (FCurve *)ld->data;
- fcurve_to_keylist(pfl->ob->adt, fcu, &pso->keys, 0);
+ fcurve_to_keylist(pfl->ob->adt, fcu, pso->keylist, 0);
}
}
/* Cancel if no keyframes found. */
- if (pso->keys.root) {
- ActKeyColumn *ak;
- float cframe = (float)pso->cframe;
-
- /* Firstly, check if the current frame is a keyframe. */
- ak = (ActKeyColumn *)BLI_dlrbTree_search_exact(&pso->keys, compare_ak_cfraPtr, &cframe);
-
- if (ak == NULL) {
- /* Current frame is not a keyframe, so search. */
- ActKeyColumn *pk = (ActKeyColumn *)BLI_dlrbTree_search_prev(
- &pso->keys, compare_ak_cfraPtr, &cframe);
- ActKeyColumn *nk = (ActKeyColumn *)BLI_dlrbTree_search_next(
- &pso->keys, compare_ak_cfraPtr, &cframe);
-
- /* New set the frames. */
- /* Prev frame. */
- pso->prevFrame = (pk) ? (pk->cfra) : (pso->cframe - 1);
- RNA_int_set(op->ptr, "prev_frame", pso->prevFrame);
- /* Next frame. */
- pso->nextFrame = (nk) ? (nk->cfra) : (pso->cframe + 1);
- RNA_int_set(op->ptr, "next_frame", pso->nextFrame);
- }
- else {
- /* Current frame itself is a keyframe, so just take keyframes on either side. */
- /* Prev frame. */
- pso->prevFrame = (ak->prev) ? (ak->prev->cfra) : (pso->cframe - 1);
- RNA_int_set(op->ptr, "prev_frame", pso->prevFrame);
- /* Next frame. */
- pso->nextFrame = (ak->next) ? (ak->next->cfra) : (pso->cframe + 1);
- RNA_int_set(op->ptr, "next_frame", pso->nextFrame);
- }
-
- /* Apply NLA mapping corrections so the frame look-ups work. */
- for (uint ob_index = 0; ob_index < pso->objects_len; ob_index++) {
- tPoseSlideObject *ob_data = &pso->ob_data_array[ob_index];
- if (ob_data->valid) {
- ob_data->prevFrameF = BKE_nla_tweakedit_remap(
- ob_data->ob->adt, pso->prevFrame, NLATIME_CONVERT_UNMAP);
- ob_data->nextFrameF = BKE_nla_tweakedit_remap(
- ob_data->ob->adt, pso->nextFrame, NLATIME_CONVERT_UNMAP);
- }
- }
- }
- else {
+ if (ED_keylist_is_empty(pso->keylist)) {
BKE_report(op->reports, RPT_ERROR, "No keyframes to slide between");
pose_slide_exit(C, op);
return OPERATOR_CANCELLED;
}
+ float cframe = (float)pso->cframe;
+
+ /* Firstly, check if the current frame is a keyframe. */
+ const ActKeyColumn *ak = ED_keylist_find_exact(pso->keylist, cframe);
+
+ if (ak == NULL) {
+ /* Current frame is not a keyframe, so search. */
+ const ActKeyColumn *pk = ED_keylist_find_prev(pso->keylist, cframe);
+ const ActKeyColumn *nk = ED_keylist_find_next(pso->keylist, cframe);
+
+ /* New set the frames. */
+ /* Prev frame. */
+ pso->prevFrame = (pk) ? (pk->cfra) : (pso->cframe - 1);
+ RNA_int_set(op->ptr, "prev_frame", pso->prevFrame);
+ /* Next frame. */
+ pso->nextFrame = (nk) ? (nk->cfra) : (pso->cframe + 1);
+ RNA_int_set(op->ptr, "next_frame", pso->nextFrame);
+ }
+ else {
+ /* Current frame itself is a keyframe, so just take keyframes on either side. */
+ /* Prev frame. */
+ pso->prevFrame = (ak->prev) ? (ak->prev->cfra) : (pso->cframe - 1);
+ RNA_int_set(op->ptr, "prev_frame", pso->prevFrame);
+ /* Next frame. */
+ pso->nextFrame = (ak->next) ? (ak->next->cfra) : (pso->cframe + 1);
+ RNA_int_set(op->ptr, "next_frame", pso->nextFrame);
+ }
+
+ /* Apply NLA mapping corrections so the frame look-ups work. */
+ for (uint ob_index = 0; ob_index < pso->objects_len; ob_index++) {
+ tPoseSlideObject *ob_data = &pso->ob_data_array[ob_index];
+ if (ob_data->valid) {
+ ob_data->prevFrameF = BKE_nla_tweakedit_remap(
+ ob_data->ob->adt, pso->prevFrame, NLATIME_CONVERT_UNMAP);
+ ob_data->nextFrameF = BKE_nla_tweakedit_remap(
+ ob_data->ob->adt, pso->nextFrame, NLATIME_CONVERT_UNMAP);
+ }
+ }
+
/* Initial apply for operator. */
/* TODO: need to calculate factor for initial round too. */
if (!ELEM(pso->mode, POSESLIDE_PUSH_REST, POSESLIDE_RELAX_REST)) {
@@ -1705,26 +1701,22 @@ typedef union tPosePropagate_ModeData {
*/
static float pose_propagate_get_boneHoldEndFrame(tPChanFCurveLink *pfl, float startFrame)
{
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
Object *ob = pfl->ob;
AnimData *adt = ob->adt;
LinkData *ld;
float endFrame = startFrame;
- /* Set up optimized data-structures for searching for relevant keyframes + holds. */
- BLI_dlrbTree_init(&keys);
-
for (ld = pfl->fcurves.first; ld; ld = ld->next) {
FCurve *fcu = (FCurve *)ld->data;
- fcurve_to_keylist(adt, fcu, &keys, 0);
+ fcurve_to_keylist(adt, fcu, keylist, 0);
}
/* Find the long keyframe (i.e. hold), and hence obtain the endFrame value
* - the best case would be one that starts on the frame itself
*/
- ActKeyColumn *ab = (ActKeyColumn *)BLI_dlrbTree_search_exact(
- &keys, compare_ak_cfraPtr, &startFrame);
+ ActKeyColumn *ab = ED_keylist_find_exact(keylist, startFrame);
/* There are only two cases for no-exact match:
* 1) the current frame is just before another key but not on a key itself
@@ -1735,11 +1727,11 @@ static float pose_propagate_get_boneHoldEndFrame(tPChanFCurveLink *pfl, float st
*/
if (ab == NULL) {
/* We've got case 1, so try the one after. */
- ab = (ActKeyColumn *)BLI_dlrbTree_search_next(&keys, compare_ak_cfraPtr, &startFrame);
+ ab = ED_keylist_find_next(keylist, startFrame);
if ((actkeyblock_get_valid_hold(ab) & ACTKEYBLOCK_FLAG_STATIC_HOLD) == 0) {
/* Try the block before this frame then as last resort. */
- ab = (ActKeyColumn *)BLI_dlrbTree_search_prev(&keys, compare_ak_cfraPtr, &startFrame);
+ ab = ED_keylist_find_prev(keylist, startFrame);
}
}
@@ -1774,7 +1766,7 @@ static float pose_propagate_get_boneHoldEndFrame(tPChanFCurveLink *pfl, float st
}
/* Free temp memory. */
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
/* Return the end frame we've found. */
return endFrame;
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index 9bf44370c80..31ef094afa6 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -1507,7 +1507,7 @@ static void annotation_session_cleanup(tGPsdata *p)
/* free stroke buffer */
if (gpd->runtime.sbuffer) {
- /* printf("\t\tGP - free sbuffer\n"); */
+ // printf("\t\tGP - free sbuffer\n");
MEM_freeN(gpd->runtime.sbuffer);
gpd->runtime.sbuffer = NULL;
}
@@ -2221,20 +2221,20 @@ static int annotation_draw_exec(bContext *C, wmOperator *op)
tGPsdata *p = NULL;
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- /* printf("GPencil - Starting Re-Drawing\n"); */
+ // printf("GPencil - Starting Re-Drawing\n");
/* try to initialize context data needed while drawing */
if (!annotation_draw_init(C, op, NULL)) {
if (op->customdata) {
MEM_freeN(op->customdata);
}
- /* printf("\tGP - no valid data\n"); */
+ // printf("\tGP - no valid data\n");
return OPERATOR_CANCELLED;
}
p = op->customdata;
- /* printf("\tGP - Start redrawing stroke\n"); */
+ // printf("\tGP - Start redrawing stroke\n");
/* loop over the stroke RNA elements recorded (i.e. progress of mouse movement),
* setting the relevant values in context at each step, then applying
@@ -2242,7 +2242,7 @@ static int annotation_draw_exec(bContext *C, wmOperator *op)
RNA_BEGIN (op->ptr, itemptr, "stroke") {
float mousef[2];
- /* printf("\t\tGP - stroke elem\n"); */
+ // printf("\t\tGP - stroke elem\n");
/* get relevant data for this point from stroke */
RNA_float_get_array(&itemptr, "mouse", mousef);
@@ -2277,7 +2277,7 @@ static int annotation_draw_exec(bContext *C, wmOperator *op)
}
RNA_END;
- /* printf("\tGP - done\n"); */
+ // printf("\tGP - done\n");
/* cleanup */
annotation_draw_exit(C, op);
@@ -2361,7 +2361,7 @@ static int annotation_draw_invoke(bContext *C, wmOperator *op, const wmEvent *ev
/* only start drawing immediately if we're allowed to do so... */
if (RNA_boolean_get(op->ptr, "wait_for_input") == false) {
/* hotkey invoked - start drawing */
- /* printf("\tGP - set first spot\n"); */
+ // printf("\tGP - set first spot\n");
p->status = GP_STATUS_PAINTING;
/* handle the initial drawing - i.e. for just doing a simple dot */
@@ -2370,7 +2370,7 @@ static int annotation_draw_invoke(bContext *C, wmOperator *op, const wmEvent *ev
}
else {
/* toolbar invoked - don't start drawing yet... */
- /* printf("\tGP - hotkey invoked... waiting for click-drag\n"); */
+ // printf("\tGP - hotkey invoked... waiting for click-drag\n");
op->flag |= OP_IS_MODAL_CURSOR_REGION;
}
@@ -2399,7 +2399,7 @@ static tGPsdata *annotation_stroke_begin(bContext *C, wmOperator *op)
p->status = GP_STATUS_ERROR;
}
- /* printf("\t\tGP - start stroke\n"); */
+ // printf("\t\tGP - start stroke\n");
/* we may need to set up paint env again if we're resuming */
/* XXX: watch it with the paintmode! in future,
@@ -2547,7 +2547,7 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
if (event->val == KM_PRESS &&
ELEM(event->type, EVT_RETKEY, EVT_PADENTER, EVT_ESCKEY, EVT_SPACEKEY, EVT_EKEY)) {
/* exit() ends the current stroke before cleaning up */
- /* printf("\t\tGP - end of paint op + end of stroke\n"); */
+ // printf("\t\tGP - end of paint op + end of stroke\n");
p->status = GP_STATUS_DONE;
estate = OPERATOR_FINISHED;
}
@@ -2571,7 +2571,7 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
if (sketch) {
/* end stroke only, and then wait to resume painting soon */
- /* printf("\t\tGP - end stroke only\n"); */
+ // printf("\t\tGP - end stroke only\n");
annotation_stroke_end(op);
/* If eraser mode is on, turn it off after the stroke finishes
@@ -2602,7 +2602,7 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
}
else {
- /* printf("\t\tGP - end of stroke + op\n"); */
+ // printf("\t\tGP - end of stroke + op\n");
p->status = GP_STATUS_DONE;
estate = OPERATOR_FINISHED;
}
@@ -2719,7 +2719,7 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
}
else {
/* event handled, so just tag as running modal */
- /* printf("\t\t\t\tGP - add point handled!\n"); */
+ // printf("\t\t\t\tGP - add point handled!\n");
estate = OPERATOR_RUNNING_MODAL;
}
}
@@ -2729,7 +2729,7 @@ static int annotation_draw_modal(bContext *C, wmOperator *op, const wmEvent *eve
/* just resize the brush (local version)
* TODO: fix the hardcoded size jumps (set to make a visible difference) and hardcoded keys
*/
- /* printf("\t\tGP - resize eraser\n"); */
+ // printf("\t\tGP - resize eraser\n");
switch (event->type) {
case WHEELDOWNMOUSE: /* larger */
case EVT_PADPLUSKEY:
diff --git a/source/blender/editors/include/ED_keyframes_keylist.h b/source/blender/editors/include/ED_keyframes_keylist.h
index be3eac66771..e7d1b5d4363 100644
--- a/source/blender/editors/include/ED_keyframes_keylist.h
+++ b/source/blender/editors/include/ED_keyframes_keylist.h
@@ -37,9 +37,12 @@ struct Scene;
struct bAnimContext;
struct bDopeSheet;
struct bGPDlayer;
+struct Range2f;
/* ****************************** Base Structs ****************************** */
+struct AnimKeylist;
+
/* Information about the stretch of time from current to the next column */
typedef struct ActKeyBlockInfo {
/* Combination of flags from all curves. */
@@ -133,49 +136,61 @@ typedef enum eKeyframeExtremeDrawOpts {
/* ******************************* Methods ****************************** */
+struct AnimKeylist *ED_keylist_create(void);
+void ED_keylist_free(struct AnimKeylist *keylist);
+struct ActKeyColumn *ED_keylist_find_exact(const struct AnimKeylist *keylist, float cfra);
+struct ActKeyColumn *ED_keylist_find_next(const struct AnimKeylist *keylist, float cfra);
+struct ActKeyColumn *ED_keylist_find_prev(const struct AnimKeylist *keylist, float cfra);
+struct ActKeyColumn *ED_keylist_find_any_between(const struct AnimKeylist *keylist,
+ float min_fra,
+ float max_fra);
+bool ED_keylist_is_empty(const struct AnimKeylist *keylist);
+const struct ListBase /* ActKeyColumn */ *ED_keylist_listbase(const struct AnimKeylist *keylist);
+bool ED_keylist_frame_range(const struct AnimKeylist *keylist, struct Range2f *r_frame_range);
+
/* Key-data Generation --------------- */
/* F-Curve */
void fcurve_to_keylist(struct AnimData *adt,
struct FCurve *fcu,
- struct DLRBT_Tree *keys,
+ struct AnimKeylist *keylist,
int saction_flag);
/* Action Group */
void agroup_to_keylist(struct AnimData *adt,
struct bActionGroup *agrp,
- struct DLRBT_Tree *keys,
+ struct AnimKeylist *keylist,
int saction_flag);
/* Action */
void action_to_keylist(struct AnimData *adt,
struct bAction *act,
- struct DLRBT_Tree *keys,
+ struct AnimKeylist *keylist,
int saction_flag);
/* Object */
void ob_to_keylist(struct bDopeSheet *ads,
struct Object *ob,
- struct DLRBT_Tree *keys,
+ struct AnimKeylist *keylist,
int saction_flag);
/* Cache File */
void cachefile_to_keylist(struct bDopeSheet *ads,
struct CacheFile *cache_file,
- struct DLRBT_Tree *keys,
+ struct AnimKeylist *keylist,
int saction_flag);
/* Scene */
void scene_to_keylist(struct bDopeSheet *ads,
struct Scene *sce,
- struct DLRBT_Tree *keys,
+ struct AnimKeylist *keylist,
int saction_flag);
/* DopeSheet Summary */
-void summary_to_keylist(struct bAnimContext *ac, struct DLRBT_Tree *keys, int saction_flag);
+void summary_to_keylist(struct bAnimContext *ac, struct AnimKeylist *keylist, int saction_flag);
/* Grease Pencil datablock summary */
void gpencil_to_keylist(struct bDopeSheet *ads,
struct bGPdata *gpd,
- struct DLRBT_Tree *keys,
+ struct AnimKeylist *keylist,
const bool active);
/* Grease Pencil Layer */
-void gpl_to_keylist(struct bDopeSheet *ads, struct bGPDlayer *gpl, struct DLRBT_Tree *keys);
+void gpl_to_keylist(struct bDopeSheet *ads, struct bGPDlayer *gpl, struct AnimKeylist *keylist);
/* Mask */
-void mask_to_keylist(struct bDopeSheet *ads, struct MaskLayer *masklay, struct DLRBT_Tree *keys);
+void mask_to_keylist(struct bDopeSheet *ads, struct MaskLayer *masklay, struct AnimKeylist *keylist);
/* ActKeyColumn API ---------------- */
/* Comparator callback used for ActKeyColumns and cframe float-value pointer */
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index a6e465d04e8..30be3588b5a 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2577,10 +2577,7 @@ void ED_keymap_ui(struct wmKeyConfig *keyconf);
void ED_uilisttypes_ui(void);
void UI_drop_color_copy(struct wmDrag *drag, struct wmDropBox *drop);
-bool UI_drop_color_poll(struct bContext *C,
- struct wmDrag *drag,
- const struct wmEvent *event,
- const char **r_tooltip);
+bool UI_drop_color_poll(struct bContext *C, struct wmDrag *drag, const struct wmEvent *event);
bool UI_context_copy_to_selected_list(struct bContext *C,
struct PointerRNA *ptr,
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index a2b25aed582..d3a3df98d99 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -4017,9 +4017,11 @@ uiBut *ui_but_change_type(uiBut *but, eButType new_type)
UNUSED_VARS_NDEBUG(found_layout);
ui_button_group_replace_but_ptr(uiLayoutGetBlock(but->layout), old_but_ptr, but);
}
+#ifdef WITH_PYTHON
if (UI_editsource_enable_check()) {
UI_editsource_but_replace(old_but_ptr, but);
}
+#endif
}
return but;
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 0ffc5659191..6755eded05c 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -2425,6 +2425,7 @@ void UI_icon_draw_ex(float x,
ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon)
{
#ifdef WITH_HEADLESS
+ UNUSED_VARS(icon);
return NULL;
#else
const int ALERT_IMG_SIZE = 256;
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 3ab49b8773b..dd10d942fc9 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -998,55 +998,69 @@ static bool copy_to_selected_button(bContext *C, bool all, bool poll)
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
/* if there is a valid property that is editable... */
- if (ptr.data && prop) {
- char *path = NULL;
- bool use_path_from_id;
- ListBase lb = {NULL};
-
- if (UI_context_copy_to_selected_list(C, &ptr, prop, &lb, &use_path_from_id, &path) &&
- !BLI_listbase_is_empty(&lb)) {
- LISTBASE_FOREACH (CollectionPointerLink *, link, &lb) {
- if (link->ptr.data != ptr.data) {
- if (use_path_from_id) {
- /* Path relative to ID. */
- lprop = NULL;
- RNA_id_pointer_create(link->ptr.owner_id, &idptr);
- RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
- }
- else if (path) {
- /* Path relative to elements from list. */
- lprop = NULL;
- RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop);
- }
- else {
- lptr = link->ptr;
- lprop = prop;
- }
+ if (ptr.data == NULL || prop == NULL) {
+ return false;
+ }
- if (lptr.data == ptr.data) {
- /* lptr might not be the same as link->ptr! */
- continue;
- }
+ char *path = NULL;
+ bool use_path_from_id;
+ ListBase lb = {NULL};
- if (lprop == prop) {
- if (RNA_property_editable(&lptr, lprop)) {
- if (poll) {
- success = true;
- break;
- }
- if (RNA_property_copy(bmain, &lptr, &ptr, prop, (all) ? -1 : index)) {
- RNA_property_update(C, &lptr, prop);
- success = true;
- }
- }
- }
- }
- }
- }
+ if (!UI_context_copy_to_selected_list(C, &ptr, prop, &lb, &use_path_from_id, &path)) {
+ return false;
+ }
+ if (BLI_listbase_is_empty(&lb)) {
MEM_SAFE_FREE(path);
- BLI_freelistN(&lb);
+ return false;
}
+ LISTBASE_FOREACH (CollectionPointerLink *, link, &lb) {
+ if (link->ptr.data == ptr.data) {
+ continue;
+ }
+
+ if (use_path_from_id) {
+ /* Path relative to ID. */
+ lprop = NULL;
+ RNA_id_pointer_create(link->ptr.owner_id, &idptr);
+ RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
+ }
+ else if (path) {
+ /* Path relative to elements from list. */
+ lprop = NULL;
+ RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop);
+ }
+ else {
+ lptr = link->ptr;
+ lprop = prop;
+ }
+
+ if (lptr.data == ptr.data) {
+ /* lptr might not be the same as link->ptr! */
+ continue;
+ }
+
+ if (lprop != prop) {
+ continue;
+ }
+
+ if (!RNA_property_editable(&lptr, lprop)) {
+ continue;
+ }
+
+ if (poll) {
+ success = true;
+ break;
+ }
+ if (RNA_property_copy(bmain, &lptr, &ptr, prop, (all) ? -1 : index)) {
+ RNA_property_update(C, &lptr, prop);
+ success = true;
+ }
+ }
+
+ MEM_SAFE_FREE(path);
+ BLI_freelistN(&lb);
+
return success;
}
@@ -1557,7 +1571,7 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
}
/* Try to find a valid po file for current language... */
edittranslation_find_po_file(root, uilng, popath, FILE_MAX);
- /* printf("po path: %s\n", popath); */
+ // printf("po path: %s\n", popath);
if (popath[0] == '\0') {
BKE_reportf(
op->reports, RPT_ERROR, "No valid po found for language '%s' under %s", uilng, root);
@@ -1759,10 +1773,7 @@ static void UI_OT_button_string_clear(wmOperatorType *ot)
/** \name Drop Color Operator
* \{ */
-bool UI_drop_color_poll(struct bContext *C,
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+bool UI_drop_color_poll(struct bContext *C, wmDrag *drag, const wmEvent *UNUSED(event))
{
/* should only return true for regions that include buttons, for now
* return true always */
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index 9fa34a1c55d..b2788ee49a2 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -52,6 +52,7 @@ void ED_operatortypes_io(void)
WM_operatortype_append(WM_OT_alembic_export);
#endif
#ifdef WITH_USD
+ WM_operatortype_append(WM_OT_usd_import);
WM_operatortype_append(WM_OT_usd_export);
#endif
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 0eadb38abb5..d0007d9e5be 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -22,23 +22,30 @@
*/
#ifdef WITH_USD
+# include "DNA_modifier_types.h"
# include "DNA_space_types.h"
+# include <string.h>
# include "BKE_context.h"
# include "BKE_main.h"
# include "BKE_report.h"
+# include "BLI_blenlib.h"
# include "BLI_path_util.h"
# include "BLI_string.h"
# include "BLI_utildefines.h"
# include "BLT_translation.h"
+# include "ED_object.h"
+
# include "MEM_guardedalloc.h"
# include "RNA_access.h"
# include "RNA_define.h"
+# include "RNA_enum_types.h"
+
# include "UI_interface.h"
# include "UI_resources.h"
@@ -50,6 +57,8 @@
# include "io_usd.h"
# include "usd.h"
+# include "stdio.h"
+
const EnumPropertyItem rna_enum_usd_export_evaluation_mode_items[] = {
{DAG_EVAL_RENDER,
"RENDER",
@@ -242,4 +251,274 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
"are different settings for viewport and rendering");
}
+/* ====== USD Import ====== */
+
+static int wm_usd_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ eUSDOperatorOptions *options = MEM_callocN(sizeof(eUSDOperatorOptions), "eUSDOperatorOptions");
+ options->as_background_job = true;
+ op->customdata = options;
+
+ return WM_operator_filesel(C, op, event);
+}
+
+static int wm_usd_import_exec(bContext *C, wmOperator *op)
+{
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ BKE_report(op->reports, RPT_ERROR, "No filename given");
+ return OPERATOR_CANCELLED;
+ }
+
+ char filename[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filename);
+
+ eUSDOperatorOptions *options = (eUSDOperatorOptions *)op->customdata;
+ const bool as_background_job = (options != NULL && options->as_background_job);
+ MEM_SAFE_FREE(op->customdata);
+
+ const float scale = RNA_float_get(op->ptr, "scale");
+
+ const bool set_frame_range = RNA_boolean_get(op->ptr, "set_frame_range");
+
+ const bool read_mesh_uvs = RNA_boolean_get(op->ptr, "read_mesh_uvs");
+ const bool read_mesh_colors = RNA_boolean_get(op->ptr, "read_mesh_colors");
+
+ char mesh_read_flag = MOD_MESHSEQ_READ_VERT | MOD_MESHSEQ_READ_POLY;
+ if (read_mesh_uvs) {
+ mesh_read_flag |= MOD_MESHSEQ_READ_UV;
+ }
+ if (read_mesh_colors) {
+ mesh_read_flag |= MOD_MESHSEQ_READ_COLOR;
+ }
+
+ const bool import_cameras = RNA_boolean_get(op->ptr, "import_cameras");
+ const bool import_curves = RNA_boolean_get(op->ptr, "import_curves");
+ const bool import_lights = RNA_boolean_get(op->ptr, "import_lights");
+ const bool import_materials = RNA_boolean_get(op->ptr, "import_materials");
+ const bool import_meshes = RNA_boolean_get(op->ptr, "import_meshes");
+ const bool import_volumes = RNA_boolean_get(op->ptr, "import_volumes");
+
+ const bool import_subdiv = RNA_boolean_get(op->ptr, "import_subdiv");
+
+ const bool import_instance_proxies = RNA_boolean_get(op->ptr, "import_instance_proxies");
+
+ const bool import_visible_only = RNA_boolean_get(op->ptr, "import_visible_only");
+
+ const bool create_collection = RNA_boolean_get(op->ptr, "create_collection");
+
+ char *prim_path_mask = malloc(1024);
+ RNA_string_get(op->ptr, "prim_path_mask", prim_path_mask);
+
+ const bool import_guide = RNA_boolean_get(op->ptr, "import_guide");
+ const bool import_proxy = RNA_boolean_get(op->ptr, "import_proxy");
+ const bool import_render = RNA_boolean_get(op->ptr, "import_render");
+
+ const bool import_usd_preview = RNA_boolean_get(op->ptr, "import_usd_preview");
+ const bool set_material_blend = RNA_boolean_get(op->ptr, "set_material_blend");
+
+ const float light_intensity_scale = RNA_float_get(op->ptr, "light_intensity_scale");
+
+ /* TODO(makowalski): Add support for sequences. */
+ const bool is_sequence = false;
+ int offset = 0;
+ int sequence_len = 1;
+
+ /* Switch out of edit mode to avoid being stuck in it (T54326). */
+ Object *obedit = CTX_data_edit_object(C);
+ if (obedit) {
+ ED_object_mode_set(C, OB_MODE_EDIT);
+ }
+
+ const bool validate_meshes = false;
+ const bool use_instancing = false;
+
+ struct USDImportParams params = {.scale = scale,
+ .is_sequence = is_sequence,
+ .set_frame_range = set_frame_range,
+ .sequence_len = sequence_len,
+ .offset = offset,
+ .validate_meshes = validate_meshes,
+ .mesh_read_flag = mesh_read_flag,
+ .import_cameras = import_cameras,
+ .import_curves = import_curves,
+ .import_lights = import_lights,
+ .import_materials = import_materials,
+ .import_meshes = import_meshes,
+ .import_volumes = import_volumes,
+ .prim_path_mask = prim_path_mask,
+ .import_subdiv = import_subdiv,
+ .import_instance_proxies = import_instance_proxies,
+ .create_collection = create_collection,
+ .import_guide = import_guide,
+ .import_proxy = import_proxy,
+ .import_render = import_render,
+ .import_visible_only = import_visible_only,
+ .use_instancing = use_instancing,
+ .import_usd_preview = import_usd_preview,
+ .set_material_blend = set_material_blend,
+ .light_intensity_scale = light_intensity_scale};
+
+ const bool ok = USD_import(C, filename, &params, as_background_job);
+
+ return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+}
+
+static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op)
+{
+ uiLayout *layout = op->layout;
+ struct PointerRNA *ptr = op->ptr;
+
+ uiLayoutSetPropSep(layout, true);
+ uiLayoutSetPropDecorate(layout, false);
+
+ uiLayout *box = uiLayoutBox(layout);
+ uiLayout *col = uiLayoutColumnWithHeading(box, true, IFACE_("Data Types"));
+ uiItemR(col, ptr, "import_cameras", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "import_curves", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "import_lights", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "import_materials", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "import_meshes", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "import_volumes", 0, NULL, ICON_NONE);
+ uiItemR(box, ptr, "prim_path_mask", 0, NULL, ICON_NONE);
+ uiItemR(box, ptr, "scale", 0, NULL, ICON_NONE);
+
+ box = uiLayoutBox(layout);
+ col = uiLayoutColumnWithHeading(box, true, IFACE_("Mesh Data"));
+ uiItemR(col, ptr, "read_mesh_uvs", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "read_mesh_colors", 0, NULL, ICON_NONE);
+ col = uiLayoutColumnWithHeading(box, true, IFACE_("Include"));
+ uiItemR(col, ptr, "import_subdiv", 0, IFACE_("Subdivision"), ICON_NONE);
+ uiItemR(col, ptr, "import_instance_proxies", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "import_visible_only", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "import_guide", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "import_proxy", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "import_render", 0, NULL, ICON_NONE);
+
+ col = uiLayoutColumnWithHeading(box, true, IFACE_("Options"));
+ uiItemR(col, ptr, "set_frame_range", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "relative_path", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "create_collection", 0, NULL, ICON_NONE);
+ uiItemR(box, ptr, "light_intensity_scale", 0, NULL, ICON_NONE);
+
+ box = uiLayoutBox(layout);
+ col = uiLayoutColumnWithHeading(box, true, IFACE_("Experimental"));
+ uiItemR(col, ptr, "import_usd_preview", 0, NULL, ICON_NONE);
+ uiLayoutSetEnabled(col, RNA_boolean_get(ptr, "import_materials"));
+ uiLayout *row = uiLayoutRow(col, true);
+ uiItemR(row, ptr, "set_material_blend", 0, NULL, ICON_NONE);
+ uiLayoutSetEnabled(row, RNA_boolean_get(ptr, "import_usd_preview"));
+}
+
+void WM_OT_usd_import(struct wmOperatorType *ot)
+{
+ ot->name = "Import USD";
+ ot->description = "Import USD stage into current scene";
+ ot->idname = "WM_OT_usd_import";
+
+ ot->invoke = wm_usd_import_invoke;
+ ot->exec = wm_usd_import_exec;
+ ot->poll = WM_operator_winactive;
+ ot->ui = wm_usd_import_draw;
+
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_FOLDER | FILE_TYPE_USD,
+ FILE_BLENDER,
+ FILE_OPENFILE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_ALPHA);
+
+ RNA_def_float(
+ ot->srna,
+ "scale",
+ 1.0f,
+ 0.0001f,
+ 1000.0f,
+ "Scale",
+ "Value by which to enlarge or shrink the objects with respect to the world's origin",
+ 0.0001f,
+ 1000.0f);
+
+ RNA_def_boolean(ot->srna,
+ "set_frame_range",
+ true,
+ "Set Frame Range",
+ "Update the scene's start and end frame to match those of the USD archive");
+
+ RNA_def_boolean(ot->srna, "import_cameras", true, "Cameras", "");
+ RNA_def_boolean(ot->srna, "import_curves", true, "Curves", "");
+ RNA_def_boolean(ot->srna, "import_lights", true, "Lights", "");
+ RNA_def_boolean(ot->srna, "import_materials", true, "Materials", "");
+ RNA_def_boolean(ot->srna, "import_meshes", true, "Meshes", "");
+ RNA_def_boolean(ot->srna, "import_volumes", true, "Volumes", "");
+
+ RNA_def_boolean(ot->srna,
+ "import_subdiv",
+ false,
+ "Import Subdivision Scheme",
+ "Create subdivision surface modifiers based on the USD "
+ "SubdivisionScheme attribute");
+
+ RNA_def_boolean(ot->srna,
+ "import_instance_proxies",
+ true,
+ "Import Instance Proxies",
+ "Create unique Blender objects for USD instances");
+
+ RNA_def_boolean(ot->srna,
+ "import_visible_only",
+ true,
+ "Visible Primitives Only",
+ "Do not import invisible USD primitives. "
+ "Only applies to primitives with a non-animated visibility attribute. "
+ "Primitives with animated visibility will always be imported");
+
+ RNA_def_boolean(ot->srna,
+ "create_collection",
+ false,
+ "Create Collection",
+ "Add all imported objects to a new collection");
+
+ RNA_def_boolean(ot->srna, "read_mesh_uvs", true, "UV Coordinates", "Read mesh UV coordinates");
+
+ RNA_def_boolean(ot->srna, "read_mesh_colors", false, "Vertex Colors", "Read mesh vertex colors");
+
+ RNA_def_string(ot->srna,
+ "prim_path_mask",
+ NULL,
+ 1024,
+ "Path Mask",
+ "Import only the subset of the USD scene rooted at the given primitive");
+
+ RNA_def_boolean(ot->srna, "import_guide", false, "Guide", "Import guide geometry");
+
+ RNA_def_boolean(ot->srna, "import_proxy", true, "Proxy", "Import proxy geometry");
+
+ RNA_def_boolean(ot->srna, "import_render", true, "Render", "Import final render geometry");
+
+ RNA_def_boolean(ot->srna,
+ "import_usd_preview",
+ false,
+ "Import USD Preview",
+ "Convert UsdPreviewSurface shaders to Principled BSDF shader networks");
+
+ RNA_def_boolean(ot->srna,
+ "set_material_blend",
+ true,
+ "Set Material Blend",
+ "If the Import USD Preview option is enabled, "
+ "the material blend method will automatically be set based on the "
+ "shader's opacity and opacityThreshold inputs");
+
+ RNA_def_float(ot->srna,
+ "light_intensity_scale",
+ 1.0f,
+ 0.0001f,
+ 10000.0f,
+ "Light Intensity Scale",
+ "Scale for the intensity of imported lights",
+ 0.0001f,
+ 1000.0f);
+}
+
#endif /* WITH_USD */
diff --git a/source/blender/editors/io/io_usd.h b/source/blender/editors/io/io_usd.h
index 671984b6f34..7424cc0df32 100644
--- a/source/blender/editors/io/io_usd.h
+++ b/source/blender/editors/io/io_usd.h
@@ -26,3 +26,5 @@
struct wmOperatorType;
void WM_OT_usd_export(struct wmOperatorType *ot);
+
+void WM_OT_usd_import(struct wmOperatorType *ot);
diff --git a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
index 38d530ba911..1af489b60ce 100644
--- a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
+++ b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
@@ -468,7 +468,9 @@ void MESH_GGT_spin(struct wmGizmoGroupType *gzgt)
gzgt->poll = ED_gizmo_poll_or_unlink_delayed_from_tool;
gzgt->setup = gizmo_mesh_spin_init_setup;
- gzgt->setup_keymap = WM_gizmogroup_setup_keymap_generic_maybe_drag;
+ /* This works well with right click selection but overrides left-mouse selection
+ * when clicking which is needed to create a full 360 degree revolution, see: T89912. */
+ // gzgt->setup_keymap = WM_gizmogroup_setup_keymap_generic_maybe_drag;
gzgt->refresh = gizmo_mesh_spin_init_refresh;
gzgt->message_subscribe = gizmo_mesh_spin_init_message_subscribe;
gzgt->draw_prepare = gizmo_mesh_spin_init_draw_prepare;
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index 830c9abb41e..8e38d41f971 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -1860,10 +1860,16 @@ void MESH_OT_loop_select(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
/* properties */
- RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "Extend the selection");
- RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Remove from the selection");
- RNA_def_boolean(ot->srna, "toggle", 0, "Toggle Select", "Toggle the selection");
- RNA_def_boolean(ot->srna, "ring", 0, "Select Ring", "Select ring");
+ PropertyRNA *prop;
+
+ prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "Extend the selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Remove from the selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle Select", "Toggle the selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "ring", 0, "Select Ring", "Select ring");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
void MESH_OT_edgering_select(wmOperatorType *ot)
@@ -1880,10 +1886,16 @@ void MESH_OT_edgering_select(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_UNDO;
- RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
- RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Remove from the selection");
- RNA_def_boolean(ot->srna, "toggle", 0, "Toggle Select", "Toggle the selection");
- RNA_def_boolean(ot->srna, "ring", 1, "Select Ring", "Select ring");
+ /* Properties. */
+ PropertyRNA *prop;
+ prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Remove from the selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle Select", "Toggle the selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "ring", 1, "Select Ring", "Select ring");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/** \} */
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 41a9f426798..215ce0185f1 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -4666,7 +4666,7 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
const int type = RNA_enum_get(op->ptr, "type");
- int retval = 0;
+ bool changed_multi = false;
if (ED_operator_editmesh(C)) {
uint bases_len = 0;
@@ -4676,6 +4676,7 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
for (uint bs_index = 0; bs_index < bases_len; bs_index++) {
Base *base = bases[bs_index];
BMEditMesh *em = BKE_editmesh_from_object(base->object);
+ bool changed = false;
if (type == 0) {
if ((em->bm->totvertsel == 0) && (em->bm->totedgesel == 0) && (em->bm->totfacesel == 0)) {
@@ -4690,20 +4691,20 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
/* editmode separate */
switch (type) {
case MESH_SEPARATE_SELECTED:
- retval = mesh_separate_selected(bmain, scene, view_layer, base, em->bm);
+ changed = mesh_separate_selected(bmain, scene, view_layer, base, em->bm);
break;
case MESH_SEPARATE_MATERIAL:
- retval = mesh_separate_material(bmain, scene, view_layer, base, em->bm);
+ changed = mesh_separate_material(bmain, scene, view_layer, base, em->bm);
break;
case MESH_SEPARATE_LOOSE:
- retval = mesh_separate_loose(bmain, scene, view_layer, base, em->bm);
+ changed = mesh_separate_loose(bmain, scene, view_layer, base, em->bm);
break;
default:
BLI_assert(0);
break;
}
- if (retval) {
+ if (changed) {
EDBM_update(base->object->data,
&(const struct EDBMUpdate_Params){
.calc_looptri = true,
@@ -4711,6 +4712,7 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
.is_destructive = true,
});
}
+ changed_multi |= changed;
}
MEM_freeN(bases);
}
@@ -4727,7 +4729,7 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
Mesh *me = ob->data;
if (!ID_IS_LINKED(me)) {
BMesh *bm_old = NULL;
- int retval_iter = 0;
+ bool changed = false;
bm_old = BM_mesh_create(&bm_mesh_allocsize_default,
&((struct BMeshCreateParams){
@@ -4738,17 +4740,17 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
switch (type) {
case MESH_SEPARATE_MATERIAL:
- retval_iter = mesh_separate_material(bmain, scene, view_layer, base_iter, bm_old);
+ changed = mesh_separate_material(bmain, scene, view_layer, base_iter, bm_old);
break;
case MESH_SEPARATE_LOOSE:
- retval_iter = mesh_separate_loose(bmain, scene, view_layer, base_iter, bm_old);
+ changed = mesh_separate_loose(bmain, scene, view_layer, base_iter, bm_old);
break;
default:
BLI_assert(0);
break;
}
- if (retval_iter) {
+ if (changed) {
BM_mesh_bm_to_me(bmain,
bm_old,
me,
@@ -4762,14 +4764,14 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
BM_mesh_free(bm_old);
- retval |= retval_iter;
+ changed_multi |= changed;
}
}
}
CTX_DATA_END;
}
- if (retval) {
+ if (changed_multi) {
/* delay depsgraph recalc until all objects are duplicated */
DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL);
@@ -9538,18 +9540,11 @@ static int edbm_set_normals_from_faces_exec(bContext *C, wmOperator *op)
BKE_editmesh_ensure_autosmooth(em, obedit->data);
BKE_editmesh_lnorspace_update(em, obedit->data);
- float(*vnors)[3] = MEM_callocN(sizeof(*vnors) * bm->totvert, __func__);
- BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
- if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
- BM_ITER_ELEM (v, &viter, f, BM_VERTS_OF_FACE) {
- const int v_index = BM_elem_index_get(v);
- add_v3_v3(vnors[v_index], f->no);
- }
- }
- }
- for (int i = 0; i < bm->totvert; i++) {
- if (!is_zero_v3(vnors[i]) && normalize_v3(vnors[i]) < CLNORS_VALID_VEC_LEN) {
- zero_v3(vnors[i]);
+ float(*vnors)[3] = MEM_mallocN(sizeof(*vnors) * bm->totvert, __func__);
+ {
+ int v_index;
+ BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, v_index) {
+ BM_vert_calc_normal_ex(v, BM_ELEM_SELECT, vnors[v_index]);
}
}
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index c61965b3e23..f576c0c8517 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -2736,7 +2736,11 @@ static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent
return OPERATOR_CANCELLED;
}
- BKE_object_material_assign(CTX_data_main(C), base->object, ma, 1, BKE_MAT_ASSIGN_USERPREF);
+ Object *ob = base->object;
+ const short active_mat_slot = ob->actcol;
+
+ BKE_object_material_assign(
+ CTX_data_main(C), base->object, ma, active_mat_slot, BKE_MAT_ASSIGN_USERPREF);
DEG_id_tag_update(&base->object->id, ID_RECALC_TRANSFORM);
diff --git a/source/blender/editors/object/object_remesh.cc b/source/blender/editors/object/object_remesh.cc
index 6bee04e2b4f..d56cb3c7548 100644
--- a/source/blender/editors/object/object_remesh.cc
+++ b/source/blender/editors/object/object_remesh.cc
@@ -29,14 +29,14 @@
#include "MEM_guardedalloc.h"
-#include "BLI_blenlib.h"
#include "BLI_math.h"
+#include "BLI_string.h"
+#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
#include "DNA_userdef_types.h"
#include "BLT_translation.h"
@@ -132,7 +132,6 @@ static int voxel_remesh_exec(bContext *C, wmOperator *op)
Object *ob = CTX_data_active_object(C);
Mesh *mesh = static_cast<Mesh *>(ob->data);
- Mesh *new_mesh;
if (mesh->remesh_voxel_size <= 0.0f) {
BKE_report(op->reports, RPT_ERROR, "Voxel remesher cannot run with a voxel size of 0.0");
@@ -151,7 +150,7 @@ static int voxel_remesh_exec(bContext *C, wmOperator *op)
isovalue = mesh->remesh_voxel_size * 0.3f;
}
- new_mesh = BKE_mesh_remesh_voxel_to_mesh_nomain(
+ Mesh *new_mesh = BKE_mesh_remesh_voxel(
mesh, mesh->remesh_voxel_size, mesh->remesh_voxel_adaptivity, isovalue);
if (!new_mesh) {
@@ -164,10 +163,13 @@ static int voxel_remesh_exec(bContext *C, wmOperator *op)
}
if (mesh->flag & ME_REMESH_FIX_POLES && mesh->remesh_voxel_adaptivity <= 0.0f) {
- new_mesh = BKE_mesh_remesh_voxel_fix_poles(new_mesh);
- BKE_mesh_calc_normals(new_mesh);
+ Mesh *mesh_fixed_poles = BKE_mesh_remesh_voxel_fix_poles(new_mesh);
+ BKE_id_free(nullptr, new_mesh);
+ new_mesh = mesh_fixed_poles;
}
+ BKE_mesh_calc_normals(new_mesh);
+
if (mesh->flag & ME_REMESH_REPROJECT_VOLUME || mesh->flag & ME_REMESH_REPROJECT_PAINT_MASK ||
mesh->flag & ME_REMESH_REPROJECT_SCULPT_FACE_SETS) {
BKE_mesh_runtime_clear_geometry(mesh);
@@ -853,19 +855,18 @@ static void quadriflow_start_job(void *customdata, short *stop, short *do_update
/* Bisect the input mesh using the paint symmetry settings */
bisect_mesh = remesh_symmetry_bisect(bisect_mesh, qj->symmetry_axes);
- new_mesh = BKE_mesh_remesh_quadriflow_to_mesh_nomain(
- bisect_mesh,
- qj->target_faces,
- qj->seed,
- qj->use_preserve_sharp,
- (qj->use_preserve_boundary || qj->use_mesh_symmetry),
+ new_mesh = BKE_mesh_remesh_quadriflow(bisect_mesh,
+ qj->target_faces,
+ qj->seed,
+ qj->use_preserve_sharp,
+ (qj->use_preserve_boundary || qj->use_mesh_symmetry),
#ifdef USE_MESH_CURVATURE
- qj->use_mesh_curvature,
+ qj->use_mesh_curvature,
#else
- false,
+ false,
#endif
- quadriflow_update_job,
- (void *)qj);
+ quadriflow_update_job,
+ (void *)qj);
BKE_id_free(nullptr, bisect_mesh);
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 8d7d742e44b..107466a8a0b 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3057,8 +3057,7 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op)
float cfra = (float)(CFRA);
/* init binarytree-list for getting keyframes */
- DLRBT_Tree keys;
- BLI_dlrbTree_init(&keys);
+ struct AnimKeylist *keylist = ED_keylist_create();
/* seed up dummy dopesheet context with flags to perform necessary filtering */
if ((scene->flag & SCE_KEYS_NO_SELONLY) == 0) {
@@ -3067,14 +3066,14 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op)
}
/* populate tree with keyframe nodes */
- scene_to_keylist(&ads, scene, &keys, 0);
+ scene_to_keylist(&ads, scene, keylist, 0);
if (ob) {
- ob_to_keylist(&ads, ob, &keys, 0);
+ ob_to_keylist(&ads, ob, keylist, 0);
if (ob->type == OB_GPENCIL) {
const bool active = !(scene->flag & SCE_KEYS_NO_SELONLY);
- gpencil_to_keylist(&ads, ob->data, &keys, active);
+ gpencil_to_keylist(&ads, ob->data, keylist, active);
}
}
@@ -3082,17 +3081,17 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op)
Mask *mask = CTX_data_edit_mask(C);
if (mask) {
MaskLayer *masklay = BKE_mask_layer_active(mask);
- mask_to_keylist(&ads, masklay, &keys);
+ mask_to_keylist(&ads, masklay, keylist);
}
}
/* find matching keyframe in the right direction */
ActKeyColumn *ak;
if (next) {
- ak = (ActKeyColumn *)BLI_dlrbTree_search_next(&keys, compare_ak_cfraPtr, &cfra);
+ ak = ED_keylist_find_next(keylist, cfra);
}
else {
- ak = (ActKeyColumn *)BLI_dlrbTree_search_prev(&keys, compare_ak_cfraPtr, &cfra);
+ ak = ED_keylist_find_prev(keylist, cfra);
}
while ((ak != NULL) && (done == false)) {
@@ -3113,7 +3112,7 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op)
}
/* free temp stuff */
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
/* any success? */
if (done == false) {
@@ -4488,10 +4487,8 @@ static bool match_region_with_redraws(const ScrArea *area,
return false;
}
-static void screen_animation_region_tag_redraw(ScrArea *area,
- ARegion *region,
- const Scene *scene,
- eScreen_Redraws_Flag redraws)
+static void screen_animation_region_tag_redraw(
+ bContext *C, ScrArea *area, ARegion *region, const Scene *scene, eScreen_Redraws_Flag redraws)
{
/* Do follow time here if editor type supports it */
if ((redraws & TIME_FOLLOW) &&
@@ -4515,10 +4512,29 @@ static void screen_animation_region_tag_redraw(ScrArea *area,
* We do need to redraw when this area is in full screen as no other areas
* will be tagged for redrawing. */
if (region->regiontype == RGN_TYPE_WINDOW && !area->full) {
- if (ELEM(area->spacetype, SPACE_GRAPH, SPACE_NLA, SPACE_ACTION)) {
+ if (ELEM(area->spacetype, SPACE_NLA, SPACE_ACTION)) {
return;
}
+ /* Drivers Editor needs a full redraw on playback for graph_draw_driver_debug().
+ * This will make it slower than regular graph editor during playback, but drawing this in
+ * graph_main_region_draw_overlay() is not feasible because it requires animation filtering
+ * which has significant overhead which needs to be avoided in the overlay which is redrawn on
+ * every UI interaction. */
+ if (area->spacetype == SPACE_GRAPH) {
+ const SpaceGraph *sipo = area->spacedata.first;
+ if (sipo->mode != SIPO_MODE_DRIVERS) {
+ return;
+ }
+ bAnimContext ac;
+ if (ANIM_animdata_get_context(C, &ac) == false) {
+ return;
+ }
+ if (ac.datatype != ANIMCONT_DRIVERS) {
+ return;
+ }
+ }
+
if (area->spacetype == SPACE_SEQ) {
const SpaceSeq *sseq = area->spacedata.first;
if (!ED_space_sequencer_has_playback_animation(sseq, scene)) {
@@ -4712,7 +4728,7 @@ static int screen_animation_step_invoke(bContext *C, wmOperator *UNUSED(op), con
}
if (redraw) {
- screen_animation_region_tag_redraw(area, region, scene, sad->redraws);
+ screen_animation_region_tag_redraw(C, area, region, scene, sad->redraws);
}
}
}
@@ -5695,10 +5711,7 @@ static void keymap_modal_set(wmKeyConfig *keyconf)
WM_modalkeymap_assign(keymap, "SCREEN_OT_area_move");
}
-static bool blend_file_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool blend_file_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
if (drag->type == WM_DRAG_PATH) {
if (drag->icon == ICON_FILE_BLEND) {
@@ -5728,8 +5741,9 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
/* dropbox for entire window */
ListBase *lb = WM_dropboxmap_find("Window", 0, 0);
- WM_dropbox_add(lb, "WM_OT_drop_blend_file", blend_file_drop_poll, blend_file_drop_copy, NULL);
- WM_dropbox_add(lb, "UI_OT_drop_color", UI_drop_color_poll, UI_drop_color_copy, NULL);
+ WM_dropbox_add(
+ lb, "WM_OT_drop_blend_file", blend_file_drop_poll, blend_file_drop_copy, NULL, NULL);
+ WM_dropbox_add(lb, "UI_OT_drop_color", UI_drop_color_poll, UI_drop_color_copy, NULL, NULL);
keymap_modal_set(keyconf);
}
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index a8ad6ab1b74..a58b1947b0c 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4512,7 +4512,7 @@ static void project_paint_begin(const bContext *C,
ps->buckets_x = (int)(ps->screen_width / (((float)diameter) / PROJ_BUCKET_BRUSH_DIV));
ps->buckets_y = (int)(ps->screen_height / (((float)diameter) / PROJ_BUCKET_BRUSH_DIV));
- /* printf("\tscreenspace bucket division x:%d y:%d\n", ps->buckets_x, ps->buckets_y); */
+ // printf("\tscreenspace bucket division x:%d y:%d\n", ps->buckets_x, ps->buckets_y);
if (ps->buckets_x > PROJ_BUCKET_RECT_MAX || ps->buckets_y > PROJ_BUCKET_RECT_MAX) {
reset_threads = true;
@@ -5194,8 +5194,8 @@ static void do_projectpaint_thread(TaskPool *__restrict UNUSED(pool), void *ph_v
softenArena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 16), "paint soften arena");
}
- /* printf("brush bounds %d %d %d %d\n",
- * bucketMin[0], bucketMin[1], bucketMax[0], bucketMax[1]); */
+ // printf("brush bounds %d %d %d %d\n",
+ // bucketMin[0], bucketMin[1], bucketMax[0], bucketMax[1]);
while (project_bucket_iter_next(ps, &bucket_index, &bucket_bounds, pos)) {
diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c
index 59d2063ea84..64ccca2c907 100644
--- a/source/blender/editors/space_action/action_select.c
+++ b/source/blender/editors/space_action/action_select.c
@@ -93,7 +93,7 @@ static bAnimListElem *actkeys_find_list_element_at_position(bAnimContext *ac,
}
static void actkeys_list_element_to_keylist(bAnimContext *ac,
- DLRBT_Tree *anim_keys,
+ struct AnimKeylist *keylist,
bAnimListElem *ale)
{
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
@@ -107,44 +107,44 @@ static void actkeys_list_element_to_keylist(bAnimContext *ac,
switch (ale->datatype) {
case ALE_SCE: {
Scene *scene = (Scene *)ale->key_data;
- scene_to_keylist(ads, scene, anim_keys, 0);
+ scene_to_keylist(ads, scene, keylist, 0);
break;
}
case ALE_OB: {
Object *ob = (Object *)ale->key_data;
- ob_to_keylist(ads, ob, anim_keys, 0);
+ ob_to_keylist(ads, ob, keylist, 0);
break;
}
case ALE_ACT: {
bAction *act = (bAction *)ale->key_data;
- action_to_keylist(adt, act, anim_keys, 0);
+ action_to_keylist(adt, act, keylist, 0);
break;
}
case ALE_FCURVE: {
FCurve *fcu = (FCurve *)ale->key_data;
- fcurve_to_keylist(adt, fcu, anim_keys, 0);
+ fcurve_to_keylist(adt, fcu, keylist, 0);
break;
}
}
}
else if (ale->type == ANIMTYPE_SUMMARY) {
/* dopesheet summary covers everything */
- summary_to_keylist(ac, anim_keys, 0);
+ summary_to_keylist(ac, keylist, 0);
}
else if (ale->type == ANIMTYPE_GROUP) {
/* TODO: why don't we just give groups key_data too? */
bActionGroup *agrp = (bActionGroup *)ale->data;
- agroup_to_keylist(adt, agrp, anim_keys, 0);
+ agroup_to_keylist(adt, agrp, keylist, 0);
}
else if (ale->type == ANIMTYPE_GPLAYER) {
/* TODO: why don't we just give gplayers key_data too? */
bGPDlayer *gpl = (bGPDlayer *)ale->data;
- gpl_to_keylist(ads, gpl, anim_keys);
+ gpl_to_keylist(ads, gpl, keylist);
}
else if (ale->type == ANIMTYPE_MASKLAYER) {
/* TODO: why don't we just give masklayers key_data too? */
MaskLayer *masklay = (MaskLayer *)ale->data;
- mask_to_keylist(ads, masklay, anim_keys);
+ mask_to_keylist(ads, masklay, keylist);
}
}
@@ -160,9 +160,8 @@ static void actkeys_find_key_in_list_element(bAnimContext *ac,
View2D *v2d = &ac->region->v2d;
- DLRBT_Tree anim_keys;
- BLI_dlrbTree_init(&anim_keys);
- actkeys_list_element_to_keylist(ac, &anim_keys, ale);
+ struct AnimKeylist *keylist = ED_keylist_create();
+ actkeys_list_element_to_keylist(ac, keylist, ale);
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
@@ -174,22 +173,21 @@ static void actkeys_find_key_in_list_element(bAnimContext *ac,
float xmin = UI_view2d_region_to_view_x(v2d, region_x - (int)key_hsize);
float xmax = UI_view2d_region_to_view_x(v2d, region_x + (int)key_hsize);
- for (ActKeyColumn *ak = anim_keys.root; ak; ak = (ak->cfra < xmin) ? ak->right : ak->left) {
- if (IN_RANGE(ak->cfra, xmin, xmax)) {
- /* set the frame to use, and apply inverse-correction for NLA-mapping
- * so that the frame will get selected by the selection functions without
- * requiring to map each frame once again...
- */
- *r_selx = BKE_nla_tweakedit_remap(adt, ak->cfra, NLATIME_CONVERT_UNMAP);
- *r_frame = ak->cfra;
- *r_found = true;
- *r_is_selected = (ak->sel & SELECT) != 0;
- break;
- }
+ const ActKeyColumn *ak = ED_keylist_find_any_between(keylist, xmin, xmax);
+ if (ak) {
+
+ /* set the frame to use, and apply inverse-correction for NLA-mapping
+ * so that the frame will get selected by the selection functions without
+ * requiring to map each frame once again...
+ */
+ *r_selx = BKE_nla_tweakedit_remap(adt, ak->cfra, NLATIME_CONVERT_UNMAP);
+ *r_frame = ak->cfra;
+ *r_found = true;
+ *r_is_selected = (ak->sel & SELECT) != 0;
}
/* cleanup temporary lists */
- BLI_dlrbTree_free(&anim_keys);
+ ED_keylist_free(keylist);
}
static void actkeys_find_key_at_position(bAnimContext *ac,
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index aef3385f2dc..e2fbb4a5a59 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -605,10 +605,7 @@ static int /*eContextResult*/ clip_context(const bContext *C,
}
/* dropboxes */
-static bool clip_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool clip_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
if (drag->type == WM_DRAG_PATH) {
/* rule might not work? */
@@ -639,7 +636,7 @@ static void clip_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
- WM_dropbox_add(lb, "CLIP_OT_open", clip_drop_poll, clip_drop_copy, NULL);
+ WM_dropbox_add(lb, "CLIP_OT_open", clip_drop_poll, clip_drop_copy, NULL, NULL);
}
static void clip_refresh(const bContext *C, ScrArea *area)
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index 3029eed1017..47d15efb6ca 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -158,10 +158,7 @@ static void console_cursor(wmWindow *win, ScrArea *UNUSED(area), ARegion *region
/* ************* dropboxes ************* */
-static bool id_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(tooltip))
+static bool id_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
return WM_drag_get_local_ID(drag, 0) != NULL;
}
@@ -176,10 +173,7 @@ static void id_drop_copy(wmDrag *drag, wmDropBox *drop)
MEM_freeN(text);
}
-static bool path_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(tooltip))
+static bool path_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
return (drag->type == WM_DRAG_PATH);
}
@@ -196,8 +190,8 @@ static void console_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
- WM_dropbox_add(lb, "CONSOLE_OT_insert", id_drop_poll, id_drop_copy, NULL);
- WM_dropbox_add(lb, "CONSOLE_OT_insert", path_drop_poll, path_drop_copy, NULL);
+ WM_dropbox_add(lb, "CONSOLE_OT_insert", id_drop_poll, id_drop_copy, NULL, NULL);
+ WM_dropbox_add(lb, "CONSOLE_OT_insert", path_drop_poll, path_drop_copy, NULL, NULL);
}
/* ************* end drop *********** */
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 37a56816677..7d9b8583838 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -82,6 +82,9 @@ void ED_file_path_button(bScreen *screen,
PointerRNA params_rna_ptr;
uiBut *but;
+ BLI_assert_msg(params != NULL,
+ "File select parameters not set. The caller is expected to check this.");
+
RNA_pointer_create(&screen->id, &RNA_FileSelectParams, params, &params_rna_ptr);
/* callbacks for operator check functions */
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 616e7fe51db..944eb9988fa 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -2830,20 +2830,10 @@ static bool file_delete_single(const FileSelectParams *params,
FileDirEntry *file,
const char **r_error_message)
{
- if (file->typeflag & FILE_TYPE_ASSET) {
- ID *id = filelist_file_get_id(file);
- if (!id) {
- *r_error_message = "File is not a local data-block asset.";
- return false;
- }
- ED_asset_clear_id(id);
- }
- else {
- char str[FILE_MAX];
- BLI_join_dirfile(str, sizeof(str), params->dir, file->relpath);
- if (BLI_delete_soft(str, r_error_message) != 0 || BLI_exists(str)) {
- return false;
- }
+ char str[FILE_MAX];
+ BLI_join_dirfile(str, sizeof(str), params->dir, file->relpath);
+ if (BLI_delete_soft(str, r_error_message) != 0 || BLI_exists(str)) {
+ return false;
}
return true;
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 46cc96ba0d4..d7a6523de26 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -815,10 +815,7 @@ static void file_ui_region_listener(const wmRegionListenerParams *listener_param
}
}
-static bool filepath_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool filepath_drop_poll(bContext *C, wmDrag *drag, const wmEvent *UNUSED(event))
{
if (drag->type == WM_DRAG_PATH) {
SpaceFile *sfile = CTX_wm_space_file(C);
@@ -839,7 +836,7 @@ static void file_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
- WM_dropbox_add(lb, "FILE_OT_filepath_drop", filepath_drop_poll, filepath_drop_copy, NULL);
+ WM_dropbox_add(lb, "FILE_OT_filepath_drop", filepath_drop_poll, filepath_drop_copy, NULL, NULL);
}
static int file_space_subtype_get(ScrArea *area)
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 5a03b4f6ef0..4107fd619aa 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -253,10 +253,7 @@ static void image_keymap(struct wmKeyConfig *keyconf)
}
/* dropboxes */
-static bool image_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool image_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
ScrArea *area = CTX_wm_area(C);
if (ED_region_overlap_isect_any_xy(area, &event->x)) {
@@ -282,7 +279,7 @@ static void image_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
- WM_dropbox_add(lb, "IMAGE_OT_open", image_drop_poll, image_drop_copy, NULL);
+ WM_dropbox_add(lb, "IMAGE_OT_open", image_drop_poll, image_drop_copy, NULL, NULL);
}
/**
diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c
index d7671a372c6..983e04127e0 100644
--- a/source/blender/editors/space_info/info_stats.c
+++ b/source/blender/editors/space_info/info_stats.c
@@ -764,6 +764,7 @@ void ED_info_draw_stats(
FRAMES,
STROKES,
POINTS,
+ LIGHTS,
MAX_LABELS_COUNT
};
char labels[MAX_LABELS_COUNT][64];
@@ -779,6 +780,7 @@ void ED_info_draw_stats(
STRNCPY(labels[FRAMES], IFACE_("Frames"));
STRNCPY(labels[STROKES], IFACE_("Strokes"));
STRNCPY(labels[POINTS], IFACE_("Points"));
+ STRNCPY(labels[LIGHTS], IFACE_("Lights"));
int longest_label = 0;
int i;
@@ -832,6 +834,9 @@ void ED_info_draw_stats(
stats_row(col1, labels[FACES], col2, stats_fmt.totfacesculpt, stats_fmt.totface, y, height);
}
}
+ else if ((ob) && (ob->type == OB_LAMP)) {
+ stats_row(col1, labels[LIGHTS], col2, stats_fmt.totlampsel, stats_fmt.totlamp, y, height);
+ }
else {
stats_row(col1, labels[VERTS], col2, stats_fmt.totvert, NULL, y, height);
stats_row(col1, labels[EDGES], col2, stats_fmt.totedge, NULL, y, height);
diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c
index c96047da0c8..2bf4c7d4344 100644
--- a/source/blender/editors/space_nla/nla_draw.c
+++ b/source/blender/editors/space_nla/nla_draw.c
@@ -35,6 +35,7 @@
#include "BLI_blenlib.h"
#include "BLI_dlrbTree.h"
+#include "BLI_range.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
@@ -95,12 +96,16 @@ void nla_action_get_color(AnimData *adt, bAction *act, float color[4])
static void nla_action_draw_keyframes(
View2D *v2d, AnimData *adt, bAction *act, float y, float ymin, float ymax)
{
+ if (act == NULL) {
+ return;
+ }
+
/* get a list of the keyframes with NLA-scaling applied */
- DLRBT_Tree keys;
- BLI_dlrbTree_init(&keys);
- action_to_keylist(adt, act, &keys, 0);
+ struct AnimKeylist *keylist = ED_keylist_create();
+ action_to_keylist(adt, act, keylist, 0);
- if (ELEM(NULL, act, keys.first)) {
+ if (ED_keylist_is_empty(keylist)) {
+ ED_keylist_free(keylist);
return;
}
@@ -122,15 +127,16 @@ static void nla_action_draw_keyframes(
/* - draw a rect from the first to the last frame (no extra overlaps for now)
* that is slightly stumpier than the track background (hardcoded 2-units here)
*/
- float f1 = ((ActKeyColumn *)keys.first)->cfra;
- float f2 = ((ActKeyColumn *)keys.last)->cfra;
- immRectf(pos_id, f1, ymin + 2, f2, ymax - 2);
+ Range2f frame_range;
+ ED_keylist_frame_range(keylist, &frame_range);
+ immRectf(pos_id, frame_range.min, ymin + 2, frame_range.max, ymax - 2);
immUnbindProgram();
/* Count keys before drawing. */
/* NOTE: It's safe to cast #DLRBT_Tree, as it's designed to degrade down to a #ListBase. */
- uint key_len = BLI_listbase_count((ListBase *)&keys);
+ const ListBase *keys = ED_keylist_listbase(keylist);
+ uint key_len = BLI_listbase_count(keys);
if (key_len > 0) {
format = immVertexFormat();
@@ -151,7 +157,7 @@ static void nla_action_draw_keyframes(
/* - disregard the selection status of keyframes so they draw a certain way
* - size is 6.0f which is smaller than the editable keyframes, so that there is a distinction
*/
- LISTBASE_FOREACH (ActKeyColumn *, ak, &keys) {
+ LISTBASE_FOREACH (const ActKeyColumn *, ak, keys) {
draw_keyframe_shape(ak->cfra,
y,
6.0f,
@@ -174,7 +180,7 @@ static void nla_action_draw_keyframes(
}
/* free icons */
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
}
/* Strip Markers ------------------------ */
diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc
index 6c07c41f451..a1068f29624 100644
--- a/source/blender/editors/space_node/node_select.cc
+++ b/source/blender/editors/space_node/node_select.cc
@@ -664,7 +664,8 @@ void NODE_OT_select(wmOperatorType *ot)
/* properties */
WM_operator_properties_generic_select(ot);
- RNA_def_boolean(ot->srna, "extend", false, "Extend", "");
+ prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
RNA_def_boolean(ot->srna, "socket_select", false, "Socket Select", "");
prop = RNA_def_boolean(ot->srna,
"deselect_all",
diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c
index ff848a7bb95..956fb3aa867 100644
--- a/source/blender/editors/space_node/space_node.c
+++ b/source/blender/editors/space_node/space_node.c
@@ -664,42 +664,29 @@ static void node_main_region_draw(const bContext *C, ARegion *region)
/* ************* dropboxes ************* */
-static bool node_group_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool node_group_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
return WM_drag_is_ID_type(drag, ID_NT);
}
-static bool node_object_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool node_object_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
return WM_drag_is_ID_type(drag, ID_OB);
}
static bool node_collection_drop_poll(bContext *UNUSED(C),
wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+ const wmEvent *UNUSED(event))
{
return WM_drag_is_ID_type(drag, ID_GR);
}
-static bool node_texture_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool node_texture_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
return WM_drag_is_ID_type(drag, ID_TE);
}
-static bool node_ima_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool node_ima_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
if (drag->type == WM_DRAG_PATH) {
/* rule might not work? */
@@ -708,10 +695,7 @@ static bool node_ima_drop_poll(bContext *UNUSED(C),
return WM_drag_is_ID_type(drag, ID_IM);
}
-static bool node_mask_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool node_mask_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
return WM_drag_is_ID_type(drag, ID_MSK);
}
@@ -753,32 +737,38 @@ static void node_dropboxes(void)
"NODE_OT_add_object",
node_object_drop_poll,
node_id_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"NODE_OT_add_collection",
node_collection_drop_poll,
node_id_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"NODE_OT_add_texture",
node_texture_drop_poll,
node_id_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"NODE_OT_add_group",
node_group_drop_poll,
node_group_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"NODE_OT_add_file",
node_ima_drop_poll,
node_id_path_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"NODE_OT_add_mask",
node_mask_drop_poll,
node_id_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
}
/* ************* end drop *********** */
diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c
index 86aab86db10..36b2966dc43 100644
--- a/source/blender/editors/space_outliner/outliner_dragdrop.c
+++ b/source/blender/editors/space_outliner/outliner_dragdrop.c
@@ -31,6 +31,7 @@
#include "DNA_space_types.h"
#include "BLI_listbase.h"
+#include "BLI_string.h"
#include "BLT_translation.h"
@@ -316,10 +317,7 @@ static bool allow_parenting_without_modifier_key(SpaceOutliner *space_outliner)
}
}
-static bool parent_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool parent_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
@@ -455,10 +453,7 @@ void OUTLINER_OT_parent_drop(wmOperatorType *ot)
/* ******************** Parent Clear Operator *********************** */
-static bool parent_clear_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool parent_clear_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
@@ -541,10 +536,7 @@ void OUTLINER_OT_parent_clear(wmOperatorType *ot)
/* ******************** Scene Drop Operator *********************** */
-static bool scene_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool scene_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
/* Ensure item under cursor is valid drop target */
Object *ob = (Object *)WM_drag_get_local_ID(drag, ID_OB);
@@ -609,10 +601,7 @@ void OUTLINER_OT_scene_drop(wmOperatorType *ot)
/* ******************** Material Drop Operator *********************** */
-static bool material_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool material_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
/* Ensure item under cursor is valid drop target */
Material *ma = (Material *)WM_drag_get_local_ID(drag, ID_MA);
@@ -833,10 +822,7 @@ static bool datastack_drop_are_types_valid(StackDropData *drop_data)
return true;
}
-static bool datastack_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **r_tooltip)
+static bool datastack_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
if (drag->type != WM_DRAG_DATASTACK) {
return false;
@@ -873,33 +859,40 @@ static bool datastack_drop_poll(bContext *C,
break;
}
+ if (changed) {
+ ED_region_tag_redraw_no_rebuild(region);
+ }
+
+ return true;
+}
+
+static char *datastack_drop_tooltip(bContext *UNUSED(C),
+ wmDrag *drag,
+ const wmEvent *UNUSED(event))
+{
+ StackDropData *drop_data = drag->poin;
switch (drop_data->drop_action) {
case DATA_STACK_DROP_REORDER:
- *r_tooltip = TIP_("Reorder");
+ return BLI_strdup(TIP_("Reorder"));
break;
case DATA_STACK_DROP_COPY:
if (drop_data->pchan_parent) {
- *r_tooltip = TIP_("Copy to bone");
+ return BLI_strdup(TIP_("Copy to bone"));
}
else {
- *r_tooltip = TIP_("Copy to object");
+ return BLI_strdup(TIP_("Copy to object"));
}
break;
case DATA_STACK_DROP_LINK:
if (drop_data->pchan_parent) {
- *r_tooltip = TIP_("Link all to bone");
+ return BLI_strdup(TIP_("Link all to bone"));
}
else {
- *r_tooltip = TIP_("Link all to object");
+ return BLI_strdup(TIP_("Link all to object"));
}
break;
}
-
- if (changed) {
- ED_region_tag_redraw_no_rebuild(region);
- }
-
- return true;
+ return NULL;
}
static void datastack_drop_link(bContext *C, StackDropData *drop_data)
@@ -1155,10 +1148,7 @@ static bool collection_drop_init(bContext *C,
return true;
}
-static bool collection_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **r_tooltip)
+static bool collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
ARegion *region = CTX_wm_region(C);
@@ -1172,45 +1162,20 @@ static bool collection_drop_poll(bContext *C,
if (!data.from || event->ctrl) {
tselem->flag |= TSE_DRAG_INTO;
changed = true;
- *r_tooltip = TIP_("Link inside Collection");
}
else {
switch (data.insert_type) {
case TE_INSERT_BEFORE:
tselem->flag |= TSE_DRAG_BEFORE;
changed = true;
- if (te->prev && outliner_is_collection_tree_element(te->prev)) {
- *r_tooltip = TIP_("Move between collections");
- }
- else {
- *r_tooltip = TIP_("Move before collection");
- }
break;
case TE_INSERT_AFTER:
tselem->flag |= TSE_DRAG_AFTER;
changed = true;
- if (te->next && outliner_is_collection_tree_element(te->next)) {
- *r_tooltip = TIP_("Move between collections");
- }
- else {
- *r_tooltip = TIP_("Move after collection");
- }
break;
case TE_INSERT_INTO: {
tselem->flag |= TSE_DRAG_INTO;
changed = true;
-
- /* Check the type of the drag IDs to avoid the incorrect "Shift to parent"
- * for collections. Checking the type of the first ID works fine here since
- * all drag IDs are the same type. */
- wmDragID *drag_id = (wmDragID *)drag->ids.first;
- const bool is_object = (GS(drag_id->id->name) == ID_OB);
- if (is_object) {
- *r_tooltip = TIP_("Move inside collection (Ctrl to link, Shift to parent)");
- }
- else {
- *r_tooltip = TIP_("Move inside collection (Ctrl to link)");
- }
break;
}
}
@@ -1226,6 +1191,49 @@ static bool collection_drop_poll(bContext *C,
return false;
}
+static char *collection_drop_tooltip(bContext *C, wmDrag *drag, const wmEvent *event)
+{
+ CollectionDrop data;
+ if (!event->shift && collection_drop_init(C, drag, event, &data)) {
+ TreeElement *te = data.te;
+ if (!data.from || event->ctrl) {
+ return BLI_strdup(TIP_("Link inside Collection"));
+ }
+ switch (data.insert_type) {
+ case TE_INSERT_BEFORE:
+ if (te->prev && outliner_is_collection_tree_element(te->prev)) {
+ return BLI_strdup(TIP_("Move between collections"));
+ }
+ else {
+ return BLI_strdup(TIP_("Move before collection"));
+ }
+ break;
+ case TE_INSERT_AFTER:
+ if (te->next && outliner_is_collection_tree_element(te->next)) {
+ return BLI_strdup(TIP_("Move between collections"));
+ }
+ else {
+ return BLI_strdup(TIP_("Move after collection"));
+ }
+ break;
+ case TE_INSERT_INTO: {
+
+ /* Check the type of the drag IDs to avoid the incorrect "Shift to parent"
+ * for collections. Checking the type of the first ID works fine here since
+ * all drag IDs are the same type. */
+ wmDragID *drag_id = (wmDragID *)drag->ids.first;
+ const bool is_object = (GS(drag_id->id->name) == ID_OB);
+ if (is_object) {
+ return BLI_strdup(TIP_("Move inside collection (Ctrl to link, Shift to parent)"));
+ }
+ return BLI_strdup(TIP_("Move inside collection (Ctrl to link)"));
+ break;
+ }
+ }
+ }
+ return NULL;
+}
+
static int collection_drop_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
Main *bmain = CTX_data_main(C);
@@ -1499,10 +1507,16 @@ void outliner_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Outliner", SPACE_OUTLINER, RGN_TYPE_WINDOW);
- WM_dropbox_add(lb, "OUTLINER_OT_parent_drop", parent_drop_poll, NULL, NULL);
- WM_dropbox_add(lb, "OUTLINER_OT_parent_clear", parent_clear_poll, NULL, NULL);
- WM_dropbox_add(lb, "OUTLINER_OT_scene_drop", scene_drop_poll, NULL, NULL);
- WM_dropbox_add(lb, "OUTLINER_OT_material_drop", material_drop_poll, NULL, NULL);
- WM_dropbox_add(lb, "OUTLINER_OT_datastack_drop", datastack_drop_poll, NULL, NULL);
- WM_dropbox_add(lb, "OUTLINER_OT_collection_drop", collection_drop_poll, NULL, NULL);
+ WM_dropbox_add(lb, "OUTLINER_OT_parent_drop", parent_drop_poll, NULL, NULL, NULL);
+ WM_dropbox_add(lb, "OUTLINER_OT_parent_clear", parent_clear_poll, NULL, NULL, NULL);
+ WM_dropbox_add(lb, "OUTLINER_OT_scene_drop", scene_drop_poll, NULL, NULL, NULL);
+ WM_dropbox_add(lb, "OUTLINER_OT_material_drop", material_drop_poll, NULL, NULL, NULL);
+ WM_dropbox_add(
+ lb, "OUTLINER_OT_datastack_drop", datastack_drop_poll, NULL, NULL, datastack_drop_tooltip);
+ WM_dropbox_add(lb,
+ "OUTLINER_OT_collection_drop",
+ collection_drop_poll,
+ NULL,
+ NULL,
+ collection_drop_tooltip);
}
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index aaa52f6b649..898e66e7a39 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -1682,7 +1682,8 @@ void OUTLINER_OT_item_activate(wmOperatorType *ot)
ot->flag |= OPTYPE_REGISTER | OPTYPE_UNDO;
PropertyRNA *prop;
- RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend selection for activation");
+ prop = RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend selection for activation");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
prop = RNA_def_boolean(
ot->srna, "extend_range", false, "Extend Range", "Select a range from active element");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c
index 5980bfe37cd..333edd0ed5f 100644
--- a/source/blender/editors/space_sequencer/sequencer_select.c
+++ b/source/blender/editors/space_sequencer/sequencer_select.c
@@ -999,7 +999,9 @@ void SEQUENCER_OT_select_linked_pick(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* Properties. */
- RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
+ PropertyRNA *prop;
+ prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/** \} */
@@ -1227,7 +1229,9 @@ void SEQUENCER_OT_select_side_of_frame(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
/* Properties. */
- RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
+ PropertyRNA *prop;
+ prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
ot->prop = RNA_def_enum(ot->srna, "side", sequencer_select_left_right_types, 0, "Side", "");
}
diff --git a/source/blender/editors/space_sequencer/sequencer_view.c b/source/blender/editors/space_sequencer/sequencer_view.c
index 337ac2e0009..c5385e24d2c 100644
--- a/source/blender/editors/space_sequencer/sequencer_view.c
+++ b/source/blender/editors/space_sequencer/sequencer_view.c
@@ -275,7 +275,6 @@ static int sequencer_view_selected_exec(bContext *C, wmOperator *op)
View2D *v2d = UI_view2d_fromcontext(C);
ARegion *region = CTX_wm_region(C);
Editing *ed = SEQ_editing_get(scene, false);
- Sequence *last_seq = SEQ_select_active_get(scene);
Sequence *seq;
rctf cur_new = v2d->cur;
@@ -293,7 +292,7 @@ static int sequencer_view_selected_exec(bContext *C, wmOperator *op)
}
for (seq = ed->seqbasep->first; seq; seq = seq->next) {
- if ((seq->flag & SELECT) || (seq == last_seq)) {
+ if ((seq->flag & SELECT)) {
xmin = min_ii(xmin, seq->startdisp);
xmax = max_ii(xmax, seq->enddisp);
diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 6de95f0995a..00f3bf6ac72 100644
--- a/source/blender/editors/space_sequencer/space_sequencer.c
+++ b/source/blender/editors/space_sequencer/space_sequencer.c
@@ -364,10 +364,7 @@ static void sequencer_listener(const wmSpaceTypeListenerParams *params)
/* ************* dropboxes ************* */
-static bool image_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool image_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
ARegion *region = CTX_wm_region(C);
Scene *scene = CTX_data_scene(C);
@@ -384,10 +381,7 @@ static bool image_drop_poll(bContext *C,
return 0;
}
-static bool movie_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool movie_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
ARegion *region = CTX_wm_region(C);
Scene *scene = CTX_data_scene(C);
@@ -403,10 +397,7 @@ static bool movie_drop_poll(bContext *C,
return 0;
}
-static bool sound_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool sound_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
ARegion *region = CTX_wm_region(C);
Scene *scene = CTX_data_scene(C);
@@ -448,9 +439,12 @@ static void sequencer_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Sequencer", SPACE_SEQ, RGN_TYPE_WINDOW);
- WM_dropbox_add(lb, "SEQUENCER_OT_image_strip_add", image_drop_poll, sequencer_drop_copy, NULL);
- WM_dropbox_add(lb, "SEQUENCER_OT_movie_strip_add", movie_drop_poll, sequencer_drop_copy, NULL);
- WM_dropbox_add(lb, "SEQUENCER_OT_sound_strip_add", sound_drop_poll, sequencer_drop_copy, NULL);
+ WM_dropbox_add(
+ lb, "SEQUENCER_OT_image_strip_add", image_drop_poll, sequencer_drop_copy, NULL, NULL);
+ WM_dropbox_add(
+ lb, "SEQUENCER_OT_movie_strip_add", movie_drop_poll, sequencer_drop_copy, NULL, NULL);
+ WM_dropbox_add(
+ lb, "SEQUENCER_OT_sound_strip_add", sound_drop_poll, sequencer_drop_copy, NULL, NULL);
}
/* ************* end drop *********** */
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c
index af783051661..89e92231657 100644
--- a/source/blender/editors/space_text/space_text.c
+++ b/source/blender/editors/space_text/space_text.c
@@ -312,10 +312,7 @@ static void text_cursor(wmWindow *win, ScrArea *area, ARegion *region)
/* ************* dropboxes ************* */
-static bool text_drop_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool text_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
if (drag->type == WM_DRAG_PATH) {
/* rule might not work? */
@@ -332,10 +329,7 @@ static void text_drop_copy(wmDrag *drag, wmDropBox *drop)
RNA_string_set(drop->ptr, "filepath", drag->path);
}
-static bool text_drop_paste_poll(bContext *UNUSED(C),
- wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+static bool text_drop_paste_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
{
return (drag->type == WM_DRAG_ID);
}
@@ -356,8 +350,8 @@ static void text_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
- WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy, NULL);
- WM_dropbox_add(lb, "TEXT_OT_insert", text_drop_paste_poll, text_drop_paste, NULL);
+ WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy, NULL, NULL);
+ WM_dropbox_add(lb, "TEXT_OT_insert", text_drop_paste_poll, text_drop_paste, NULL, NULL);
}
/* ************* end drop *********** */
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 54f10e259f9..a2564469c16 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -513,49 +513,38 @@ static bool view3d_drop_id_in_main_region_poll(bContext *C,
return WM_drag_is_ID_type(drag, id_type);
}
-static bool view3d_ob_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool view3d_ob_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
return view3d_drop_id_in_main_region_poll(C, drag, event, ID_OB);
}
-static bool view3d_collection_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool view3d_collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
return view3d_drop_id_in_main_region_poll(C, drag, event, ID_GR);
}
-static bool view3d_mat_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static bool view3d_mat_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
return view3d_drop_id_in_main_region_poll(C, drag, event, ID_MA);
}
-static bool view3d_object_data_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **r_tooltip)
+static bool view3d_object_data_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
ID_Type id_type = view3d_drop_id_in_main_region_poll_get_id_type(C, drag, event);
- if (id_type) {
- if (OB_DATA_SUPPORT_ID(id_type)) {
- *r_tooltip = TIP_("Create object instance from object-data");
- return true;
- }
+ if (id_type && OB_DATA_SUPPORT_ID(id_type)) {
+ return true;
}
return false;
}
-static bool view3d_ima_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **UNUSED(r_tooltip))
+static char *view3d_object_data_drop_tooltip(bContext *UNUSED(C),
+ wmDrag *UNUSED(drag),
+ const wmEvent *UNUSED(event))
+{
+ return BLI_strdup(TIP_("Create object instance from object-data"));
+}
+
+static bool view3d_ima_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
if (ED_region_overlap_isect_any_xy(CTX_wm_area(C), &event->x)) {
return false;
@@ -580,12 +569,9 @@ static bool view3d_ima_bg_is_camera_view(bContext *C)
return false;
}
-static bool view3d_ima_bg_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **r_tooltip)
+static bool view3d_ima_bg_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
- if (!view3d_ima_drop_poll(C, drag, event, r_tooltip)) {
+ if (!view3d_ima_drop_poll(C, drag, event)) {
return false;
}
@@ -596,12 +582,9 @@ static bool view3d_ima_bg_drop_poll(bContext *C,
return view3d_ima_bg_is_camera_view(C);
}
-static bool view3d_ima_empty_drop_poll(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- const char **r_tooltip)
+static bool view3d_ima_empty_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
{
- if (!view3d_ima_drop_poll(C, drag, event, r_tooltip)) {
+ if (!view3d_ima_drop_poll(C, drag, event)) {
return false;
}
@@ -620,8 +603,7 @@ static bool view3d_ima_empty_drop_poll(bContext *C,
static bool view3d_volume_drop_poll(bContext *UNUSED(C),
wmDrag *drag,
- const wmEvent *UNUSED(event),
- const char **UNUSED(r_tooltip))
+ const wmEvent *UNUSED(event))
{
return (drag->type == WM_DRAG_PATH) && (drag->icon == ICON_FILE_VOLUME);
}
@@ -700,37 +682,44 @@ static void view3d_dropboxes(void)
"OBJECT_OT_add_named",
view3d_ob_drop_poll,
view3d_ob_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"OBJECT_OT_drop_named_material",
view3d_mat_drop_poll,
view3d_id_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"VIEW3D_OT_background_image_add",
view3d_ima_bg_drop_poll,
view3d_id_path_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"OBJECT_OT_drop_named_image",
view3d_ima_empty_drop_poll,
view3d_id_path_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"OBJECT_OT_volume_import",
view3d_volume_drop_poll,
view3d_id_path_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"OBJECT_OT_collection_instance_add",
view3d_collection_drop_poll,
view3d_collection_drop_copy,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ NULL);
WM_dropbox_add(lb,
"OBJECT_OT_data_instance_add",
view3d_object_data_drop_poll,
view3d_id_drop_copy_with_type,
- WM_drag_free_imported_drag_ID);
+ WM_drag_free_imported_drag_ID,
+ view3d_object_data_drop_tooltip);
}
static void view3d_widgets(void)
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index ecf43c734e2..5ec3e9cae5a 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1589,9 +1589,12 @@ void VIEW3D_OT_select_menu(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_ENUM_NO_TRANSLATE);
ot->prop = prop;
- RNA_def_boolean(ot->srna, "extend", 0, "Extend", "");
- RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "");
- RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
+ prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
static Base *object_mouse_select_menu(bContext *C,
@@ -1764,9 +1767,12 @@ void VIEW3D_OT_bone_select_menu(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_ENUM_NO_TRANSLATE);
ot->prop = prop;
- RNA_def_boolean(ot->srna, "extend", 0, "Extend", "");
- RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "");
- RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
+ prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
static bool bone_mouse_select_menu(bContext *C,
const uint *buffer,
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index 2c424d8ace3..45c077b8a07 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -371,25 +371,24 @@ static void transformops_exit(bContext *C, wmOperator *op)
G.moving = 0;
}
+static int transformops_mode(wmOperator *op)
+{
+ for (TransformModeItem *tmode = transform_modes; tmode->idname; tmode++) {
+ if (op->type->idname == tmode->idname) {
+ return tmode->mode;
+ }
+ }
+
+ return RNA_enum_get(op->ptr, "mode");
+}
+
static int transformops_data(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval = 1;
if (op->customdata == NULL) {
TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data2");
- TransformModeItem *tmode;
- int mode = -1;
-
- for (tmode = transform_modes; tmode->idname; tmode++) {
- if (op->type->idname == tmode->idname) {
- mode = tmode->mode;
- break;
- }
- }
-
- if (mode == -1) {
- mode = RNA_enum_get(op->ptr, "mode");
- }
+ int mode = transformops_mode(op);
retval = initTransform(C, t, op, event, mode);
/* store data */
@@ -556,6 +555,16 @@ static bool transform_poll_property(const bContext *UNUSED(C),
}
}
+ /* Orientation Axis. */
+ {
+ if (STREQ(prop_id, "orient_axis")) {
+ eTfmMode mode = (eTfmMode)transformops_mode(op);
+ if (mode == TFM_ALIGN) {
+ return false;
+ }
+ }
+ }
+
/* Proportional Editing. */
{
PropertyRNA *prop_pet = RNA_struct_find_property(op->ptr, "use_proportional_edit");
diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c
index 15d672dea56..823837e2a42 100644
--- a/source/blender/editors/util/numinput.c
+++ b/source/blender/editors/util/numinput.c
@@ -309,7 +309,7 @@ bool user_string_to_number(bContext *C,
return success;
#else
- UNUSED_VARS(C, unit, type);
+ UNUSED_VARS(C, unit, type, use_single_line_error, r_error);
*r_value = atof(str);
return true;
#endif
diff --git a/source/blender/editors/uvedit/uvedit_select.c b/source/blender/editors/uvedit/uvedit_select.c
index 20aadb84b7b..4c597d80534 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -2140,11 +2140,12 @@ void UV_OT_select(wmOperatorType *ot)
/* properties */
PropertyRNA *prop;
- RNA_def_boolean(ot->srna,
- "extend",
- 0,
- "Extend",
- "Extend selection rather than clearing the existing selection");
+ prop = RNA_def_boolean(ot->srna,
+ "extend",
+ 0,
+ "Extend",
+ "Extend selection rather than clearing the existing selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
prop = RNA_def_boolean(ot->srna,
"deselect_all",
false,
@@ -2152,7 +2153,7 @@ void UV_OT_select(wmOperatorType *ot)
"Deselect all when nothing under the cursor");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- RNA_def_float_vector(
+ prop = RNA_def_float_vector(
ot->srna,
"location",
2,
@@ -2163,6 +2164,7 @@ void UV_OT_select(wmOperatorType *ot)
"Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
-100.0f,
100.0f);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/** \} */
@@ -2296,12 +2298,14 @@ void UV_OT_select_loop(wmOperatorType *ot)
ot->poll = ED_operator_uvedit; /* requires space image */
/* properties */
- RNA_def_boolean(ot->srna,
- "extend",
- 0,
- "Extend",
- "Extend selection rather than clearing the existing selection");
- RNA_def_float_vector(
+ PropertyRNA *prop;
+ prop = RNA_def_boolean(ot->srna,
+ "extend",
+ 0,
+ "Extend",
+ "Extend selection rather than clearing the existing selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_float_vector(
ot->srna,
"location",
2,
@@ -2312,6 +2316,7 @@ void UV_OT_select_loop(wmOperatorType *ot)
"Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
-100.0f,
100.0f);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/** \} */
@@ -2494,17 +2499,20 @@ void UV_OT_select_linked_pick(wmOperatorType *ot)
ot->poll = ED_operator_uvedit; /* requires space image */
/* properties */
- RNA_def_boolean(ot->srna,
- "extend",
- 0,
- "Extend",
- "Extend selection rather than clearing the existing selection");
- RNA_def_boolean(ot->srna,
- "deselect",
- 0,
- "Deselect",
- "Deselect linked UV vertices rather than selecting them");
- RNA_def_float_vector(
+ PropertyRNA *prop;
+ prop = RNA_def_boolean(ot->srna,
+ "extend",
+ 0,
+ "Extend",
+ "Extend selection rather than clearing the existing selection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna,
+ "deselect",
+ 0,
+ "Deselect",
+ "Deselect linked UV vertices rather than selecting them");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_float_vector(
ot->srna,
"location",
2,
@@ -2515,6 +2523,7 @@ void UV_OT_select_linked_pick(wmOperatorType *ot)
"Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
-100.0f,
100.0f);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/** \} */
diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh
index bc3f398c8e9..7277bf99c12 100644
--- a/source/blender/functions/FN_cpp_type.hh
+++ b/source/blender/functions/FN_cpp_type.hh
@@ -70,64 +70,73 @@
#include "BLI_string_ref.hh"
#include "BLI_utility_mixins.hh"
+/**
+ * Different types support different features. Features like copy constructability can be detected
+ * automatically easily. For some features this is harder as of C++17. Those have flags in this
+ * enum and need to be determined by the programmer.
+ */
+enum class CPPTypeFlags {
+ None = 0,
+ Hashable = 1 << 0,
+ Printable = 1 << 1,
+ EqualityComparable = 1 << 2,
+
+ BasicType = Hashable | Printable | EqualityComparable,
+};
+ENUM_OPERATORS(CPPTypeFlags, CPPTypeFlags::EqualityComparable)
+
namespace blender::fn {
-struct CPPTypeMembers {
- int64_t size = 0;
- int64_t alignment = 0;
- uintptr_t alignment_mask = 0;
- bool is_trivially_destructible = false;
- bool has_special_member_functions = false;
+/** Utility class to pass template parameters to constructor of `CPPType`. */
+template<typename T, CPPTypeFlags Flags> struct CPPTypeParam {
+};
- void (*default_construct)(void *ptr) = nullptr;
- void (*default_construct_indices)(void *ptr, IndexMask mask) = nullptr;
+class CPPType : NonCopyable, NonMovable {
+ private:
+ int64_t size_ = 0;
+ int64_t alignment_ = 0;
+ uintptr_t alignment_mask_ = 0;
+ bool is_trivially_destructible_ = false;
+ bool has_special_member_functions_ = false;
- void (*destruct)(void *ptr) = nullptr;
- void (*destruct_indices)(void *ptr, IndexMask mask) = nullptr;
+ void (*default_construct_)(void *ptr) = nullptr;
+ void (*default_construct_indices_)(void *ptr, IndexMask mask) = nullptr;
- void (*copy_assign)(const void *src, void *dst) = nullptr;
- void (*copy_assign_indices)(const void *src, void *dst, IndexMask mask) = nullptr;
+ void (*destruct_)(void *ptr) = nullptr;
+ void (*destruct_indices_)(void *ptr, IndexMask mask) = nullptr;
- void (*copy_construct)(const void *src, void *dst) = nullptr;
- void (*copy_construct_indices)(const void *src, void *dst, IndexMask mask) = nullptr;
+ void (*copy_assign_)(const void *src, void *dst) = nullptr;
+ void (*copy_assign_indices_)(const void *src, void *dst, IndexMask mask) = nullptr;
- void (*move_assign)(void *src, void *dst) = nullptr;
- void (*move_assign_indices)(void *src, void *dst, IndexMask mask) = nullptr;
+ void (*copy_construct_)(const void *src, void *dst) = nullptr;
+ void (*copy_construct_indices_)(const void *src, void *dst, IndexMask mask) = nullptr;
- void (*move_construct)(void *src, void *dst) = nullptr;
- void (*move_construct_indices)(void *src, void *dst, IndexMask mask) = nullptr;
+ void (*move_assign_)(void *src, void *dst) = nullptr;
+ void (*move_assign_indices_)(void *src, void *dst, IndexMask mask) = nullptr;
- void (*relocate_assign)(void *src, void *dst) = nullptr;
- void (*relocate_assign_indices)(void *src, void *dst, IndexMask mask) = nullptr;
+ void (*move_construct_)(void *src, void *dst) = nullptr;
+ void (*move_construct_indices_)(void *src, void *dst, IndexMask mask) = nullptr;
- void (*relocate_construct)(void *src, void *dst) = nullptr;
- void (*relocate_construct_indices)(void *src, void *dst, IndexMask mask) = nullptr;
+ void (*relocate_assign_)(void *src, void *dst) = nullptr;
+ void (*relocate_assign_indices_)(void *src, void *dst, IndexMask mask) = nullptr;
- void (*fill_assign_indices)(const void *value, void *dst, IndexMask mask) = nullptr;
+ void (*relocate_construct_)(void *src, void *dst) = nullptr;
+ void (*relocate_construct_indices_)(void *src, void *dst, IndexMask mask) = nullptr;
- void (*fill_construct_indices)(const void *value, void *dst, IndexMask mask) = nullptr;
+ void (*fill_assign_indices_)(const void *value, void *dst, IndexMask mask) = nullptr;
- void (*print)(const void *value, std::stringstream &ss) = nullptr;
- bool (*is_equal)(const void *a, const void *b) = nullptr;
- uint64_t (*hash)(const void *value) = nullptr;
+ void (*fill_construct_indices_)(const void *value, void *dst, IndexMask mask) = nullptr;
- const void *default_value = nullptr;
- std::string name;
-};
+ void (*print_)(const void *value, std::stringstream &ss) = nullptr;
+ bool (*is_equal_)(const void *a, const void *b) = nullptr;
+ uint64_t (*hash_)(const void *value) = nullptr;
-class CPPType : NonCopyable, NonMovable {
- private:
- CPPTypeMembers m_;
+ const void *default_value_ = nullptr;
+ std::string debug_name_;
public:
- CPPType(CPPTypeMembers members) : m_(std::move(members))
- {
- BLI_assert(is_power_of_2_i(m_.alignment));
- m_.alignment_mask = (uintptr_t)members.alignment - (uintptr_t)1;
- m_.has_special_member_functions = (m_.default_construct && m_.copy_construct &&
- m_.copy_assign && m_.move_construct && m_.move_assign &&
- m_.destruct);
- }
+ template<typename T, CPPTypeFlags Flags> CPPType(CPPTypeParam<T, Flags>, StringRef debug_name);
+ virtual ~CPPType() = default;
/**
* Two types only compare equal when their pointer is equal. No two instances of CPPType for the
@@ -148,7 +157,11 @@ class CPPType : NonCopyable, NonMovable {
* This only works for types that actually implement the template specialization using
* `MAKE_CPP_TYPE`.
*/
- template<typename T> static const CPPType &get();
+ template<typename T> static const CPPType &get()
+ {
+ return CPPType::get_impl<std::remove_cv_t<T>>();
+ }
+ template<typename T> static const CPPType &get_impl();
/**
* Returns the name of the type for debugging purposes. This name should not be used as
@@ -156,7 +169,7 @@ class CPPType : NonCopyable, NonMovable {
*/
StringRefNull name() const
{
- return m_.name;
+ return debug_name_;
}
/**
@@ -167,7 +180,7 @@ class CPPType : NonCopyable, NonMovable {
*/
int64_t size() const
{
- return m_.size;
+ return size_;
}
/**
@@ -178,7 +191,7 @@ class CPPType : NonCopyable, NonMovable {
*/
int64_t alignment() const
{
- return m_.alignment;
+ return alignment_;
}
/**
@@ -190,52 +203,52 @@ class CPPType : NonCopyable, NonMovable {
*/
bool is_trivially_destructible() const
{
- return m_.is_trivially_destructible;
+ return is_trivially_destructible_;
}
bool is_default_constructible() const
{
- return m_.default_construct != nullptr;
+ return default_construct_ != nullptr;
}
bool is_copy_constructible() const
{
- return m_.copy_assign != nullptr;
+ return copy_assign_ != nullptr;
}
bool is_move_constructible() const
{
- return m_.move_assign != nullptr;
+ return move_assign_ != nullptr;
}
bool is_destructible() const
{
- return m_.destruct != nullptr;
+ return destruct_ != nullptr;
}
bool is_copy_assignable() const
{
- return m_.copy_assign != nullptr;
+ return copy_assign_ != nullptr;
}
bool is_move_assignable() const
{
- return m_.copy_construct != nullptr;
+ return copy_construct_ != nullptr;
}
bool is_printable() const
{
- return m_.print != nullptr;
+ return print_ != nullptr;
}
bool is_equality_comparable() const
{
- return m_.is_equal != nullptr;
+ return is_equal_ != nullptr;
}
bool is_hashable() const
{
- return m_.hash != nullptr;
+ return hash_ != nullptr;
}
/**
@@ -249,7 +262,7 @@ class CPPType : NonCopyable, NonMovable {
*/
bool has_special_member_functions() const
{
- return m_.has_special_member_functions;
+ return has_special_member_functions_;
}
/**
@@ -257,7 +270,7 @@ class CPPType : NonCopyable, NonMovable {
*/
bool pointer_has_valid_alignment(const void *ptr) const
{
- return ((uintptr_t)ptr & m_.alignment_mask) == 0;
+ return ((uintptr_t)ptr & alignment_mask_) == 0;
}
bool pointer_can_point_to_instance(const void *ptr) const
@@ -277,7 +290,7 @@ class CPPType : NonCopyable, NonMovable {
{
BLI_assert(this->pointer_can_point_to_instance(ptr));
- m_.default_construct(ptr);
+ default_construct_(ptr);
}
void default_construct_n(void *ptr, int64_t n) const
@@ -289,7 +302,7 @@ class CPPType : NonCopyable, NonMovable {
{
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(ptr));
- m_.default_construct_indices(ptr, mask);
+ default_construct_indices_(ptr, mask);
}
/**
@@ -304,7 +317,7 @@ class CPPType : NonCopyable, NonMovable {
{
BLI_assert(this->pointer_can_point_to_instance(ptr));
- m_.destruct(ptr);
+ destruct_(ptr);
}
void destruct_n(void *ptr, int64_t n) const
@@ -316,7 +329,7 @@ class CPPType : NonCopyable, NonMovable {
{
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(ptr));
- m_.destruct_indices(ptr, mask);
+ destruct_indices_(ptr, mask);
}
/**
@@ -331,7 +344,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
- m_.copy_assign(src, dst);
+ copy_assign_(src, dst);
}
void copy_assign_n(const void *src, void *dst, int64_t n) const
@@ -345,7 +358,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
- m_.copy_assign_indices(src, dst, mask);
+ copy_assign_indices_(src, dst, mask);
}
/**
@@ -362,7 +375,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
- m_.copy_construct(src, dst);
+ copy_construct_(src, dst);
}
void copy_construct_n(const void *src, void *dst, int64_t n) const
@@ -376,7 +389,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
- m_.copy_construct_indices(src, dst, mask);
+ copy_construct_indices_(src, dst, mask);
}
/**
@@ -393,7 +406,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
- m_.move_assign(src, dst);
+ move_assign_(src, dst);
}
void move_assign_n(void *src, void *dst, int64_t n) const
@@ -407,7 +420,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
- m_.move_assign_indices(src, dst, mask);
+ move_assign_indices_(src, dst, mask);
}
/**
@@ -424,7 +437,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
- m_.move_construct(src, dst);
+ move_construct_(src, dst);
}
void move_construct_n(void *src, void *dst, int64_t n) const
@@ -438,7 +451,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
- m_.move_construct_indices(src, dst, mask);
+ move_construct_indices_(src, dst, mask);
}
/**
@@ -455,7 +468,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
- m_.relocate_assign(src, dst);
+ relocate_assign_(src, dst);
}
void relocate_assign_n(void *src, void *dst, int64_t n) const
@@ -469,7 +482,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
- m_.relocate_assign_indices(src, dst, mask);
+ relocate_assign_indices_(src, dst, mask);
}
/**
@@ -486,7 +499,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(this->pointer_can_point_to_instance(src));
BLI_assert(this->pointer_can_point_to_instance(dst));
- m_.relocate_construct(src, dst);
+ relocate_construct_(src, dst);
}
void relocate_construct_n(void *src, void *dst, int64_t n) const
@@ -500,7 +513,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
- m_.relocate_construct_indices(src, dst, mask);
+ relocate_construct_indices_(src, dst, mask);
}
/**
@@ -518,7 +531,7 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(value));
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
- m_.fill_assign_indices(value, dst, mask);
+ fill_assign_indices_(value, dst, mask);
}
/**
@@ -536,13 +549,13 @@ class CPPType : NonCopyable, NonMovable {
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(value));
BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
- m_.fill_construct_indices(value, dst, mask);
+ fill_construct_indices_(value, dst, mask);
}
void print(const void *value, std::stringstream &ss) const
{
BLI_assert(this->pointer_can_point_to_instance(value));
- m_.print(value, ss);
+ print_(value, ss);
}
std::string to_string(const void *value) const
@@ -566,7 +579,7 @@ class CPPType : NonCopyable, NonMovable {
{
BLI_assert(this->pointer_can_point_to_instance(a));
BLI_assert(this->pointer_can_point_to_instance(b));
- return m_.is_equal(a, b);
+ return is_equal_(a, b);
}
bool is_equal_or_false(const void *a, const void *b) const
@@ -580,7 +593,7 @@ class CPPType : NonCopyable, NonMovable {
uint64_t hash(const void *value) const
{
BLI_assert(this->pointer_can_point_to_instance(value));
- return m_.hash(value);
+ return hash_(value);
}
uint64_t hash_or_fallback(const void *value, uint64_t fallback_hash) const
@@ -597,7 +610,7 @@ class CPPType : NonCopyable, NonMovable {
*/
const void *default_value() const
{
- return m_.default_value;
+ return default_value_;
}
uint64_t hash() const
@@ -605,12 +618,9 @@ class CPPType : NonCopyable, NonMovable {
return get_default_hash(this);
}
- /**
- * Low level access to the callbacks for this CPPType.
- */
- const CPPTypeMembers &members() const
+ void (*destruct_fn() const)(void *)
{
- return m_;
+ return destruct_;
}
template<typename T> bool is() const
diff --git a/source/blender/functions/FN_cpp_type_make.hh b/source/blender/functions/FN_cpp_type_make.hh
index b8e5373ccf7..088f6b469f4 100644
--- a/source/blender/functions/FN_cpp_type_make.hh
+++ b/source/blender/functions/FN_cpp_type_make.hh
@@ -185,100 +185,80 @@ template<typename T> uint64_t hash_cb(const void *value)
} // namespace blender::fn::cpp_type_util
-/**
- * Different types support different features. Features like copy constructability can be detected
- * automatically easily. For some features this is harder as of C++17. Those have flags in this
- * enum and need to be determined by the programmer.
- */
-enum class CPPTypeFlags {
- None = 0,
- Hashable = 1 << 0,
- Printable = 1 << 1,
- EqualityComparable = 1 << 2,
-
- BasicType = Hashable | Printable | EqualityComparable,
-};
-ENUM_OPERATORS(CPPTypeFlags, CPPTypeFlags::EqualityComparable)
-
namespace blender::fn {
-template<typename T, CPPTypeFlags flags>
-inline std::unique_ptr<const CPPType> create_cpp_type(StringRef name)
+template<typename T, CPPTypeFlags Flags>
+CPPType::CPPType(CPPTypeParam<T, Flags> /* unused */, StringRef debug_name)
{
using namespace cpp_type_util;
- CPPTypeMembers m;
- m.name = name;
- m.size = (int64_t)sizeof(T);
- m.alignment = (int64_t)alignof(T);
- m.is_trivially_destructible = std::is_trivially_destructible_v<T>;
+ debug_name_ = debug_name;
+ size_ = (int64_t)sizeof(T);
+ alignment_ = (int64_t)alignof(T);
+ is_trivially_destructible_ = std::is_trivially_destructible_v<T>;
if constexpr (std::is_default_constructible_v<T>) {
- m.default_construct = default_construct_cb<T>;
- m.default_construct_indices = default_construct_indices_cb<T>;
+ default_construct_ = default_construct_cb<T>;
+ default_construct_indices_ = default_construct_indices_cb<T>;
static T default_value;
- m.default_value = (void *)&default_value;
+ default_value_ = (void *)&default_value;
}
if constexpr (std::is_destructible_v<T>) {
- m.destruct = destruct_cb<T>;
- m.destruct_indices = destruct_indices_cb<T>;
+ destruct_ = destruct_cb<T>;
+ destruct_indices_ = destruct_indices_cb<T>;
}
if constexpr (std::is_copy_assignable_v<T>) {
- m.copy_assign = copy_assign_cb<T>;
- m.copy_assign_indices = copy_assign_indices_cb<T>;
+ copy_assign_ = copy_assign_cb<T>;
+ copy_assign_indices_ = copy_assign_indices_cb<T>;
}
if constexpr (std::is_copy_constructible_v<T>) {
- m.copy_construct = copy_construct_cb<T>;
- m.copy_construct_indices = copy_construct_indices_cb<T>;
+ copy_construct_ = copy_construct_cb<T>;
+ copy_construct_indices_ = copy_construct_indices_cb<T>;
}
if constexpr (std::is_move_assignable_v<T>) {
- m.move_assign = move_assign_cb<T>;
- m.move_assign_indices = move_assign_indices_cb<T>;
+ move_assign_ = move_assign_cb<T>;
+ move_assign_indices_ = move_assign_indices_cb<T>;
}
if constexpr (std::is_move_constructible_v<T>) {
- m.move_construct = move_construct_cb<T>;
- m.move_construct_indices = move_construct_indices_cb<T>;
+ move_construct_ = move_construct_cb<T>;
+ move_construct_indices_ = move_construct_indices_cb<T>;
}
if constexpr (std::is_destructible_v<T>) {
if constexpr (std::is_move_assignable_v<T>) {
- m.relocate_assign = relocate_assign_cb<T>;
- m.relocate_assign_indices = relocate_assign_indices_cb<T>;
+ relocate_assign_ = relocate_assign_cb<T>;
+ relocate_assign_indices_ = relocate_assign_indices_cb<T>;
}
if constexpr (std::is_move_constructible_v<T>) {
- m.relocate_construct = relocate_construct_cb<T>;
- m.relocate_construct_indices = relocate_construct_indices_cb<T>;
+ relocate_construct_ = relocate_construct_cb<T>;
+ relocate_construct_indices_ = relocate_construct_indices_cb<T>;
}
}
if constexpr (std::is_copy_assignable_v<T>) {
- m.fill_assign_indices = fill_assign_indices_cb<T>;
+ fill_assign_indices_ = fill_assign_indices_cb<T>;
}
if constexpr (std::is_copy_constructible_v<T>) {
- m.fill_construct_indices = fill_construct_indices_cb<T>;
+ fill_construct_indices_ = fill_construct_indices_cb<T>;
}
- if constexpr ((bool)(flags & CPPTypeFlags::Hashable)) {
- m.hash = hash_cb<T>;
+ if constexpr ((bool)(Flags & CPPTypeFlags::Hashable)) {
+ hash_ = hash_cb<T>;
}
- if constexpr ((bool)(flags & CPPTypeFlags::Printable)) {
- m.print = print_cb<T>;
+ if constexpr ((bool)(Flags & CPPTypeFlags::Printable)) {
+ print_ = print_cb<T>;
}
- if constexpr ((bool)(flags & CPPTypeFlags::EqualityComparable)) {
- m.is_equal = is_equal_cb<T>;
+ if constexpr ((bool)(Flags & CPPTypeFlags::EqualityComparable)) {
+ is_equal_ = is_equal_cb<T>;
}
- const CPPType *type = new CPPType(std::move(m));
- return std::unique_ptr<const CPPType>(type);
+ alignment_mask_ = (uintptr_t)alignment_ - (uintptr_t)1;
+ has_special_member_functions_ = (default_construct_ && copy_construct_ && copy_assign_ &&
+ move_construct_ && move_assign_ && destruct_);
}
} // namespace blender::fn
#define MAKE_CPP_TYPE(IDENTIFIER, TYPE_NAME, FLAGS) \
- template<> const blender::fn::CPPType &blender::fn::CPPType::get<TYPE_NAME>() \
- { \
- static std::unique_ptr<const CPPType> cpp_type = \
- blender::fn::create_cpp_type<TYPE_NAME, FLAGS>(STRINGIFY(IDENTIFIER)); \
- return *cpp_type; \
- } \
- /* Support using `CPPType::get<const T>()`. Otherwise the caller would have to remove const. */ \
- template<> const blender::fn::CPPType &blender::fn::CPPType::get<const TYPE_NAME>() \
+ template<> const blender::fn::CPPType &blender::fn::CPPType::get_impl<TYPE_NAME>() \
{ \
- return blender::fn::CPPType::get<TYPE_NAME>(); \
+ static CPPType cpp_type{blender::fn::CPPTypeParam<TYPE_NAME, FLAGS>(), \
+ STRINGIFY(IDENTIFIER)}; \
+ return cpp_type; \
}
diff --git a/source/blender/functions/intern/multi_function_network_optimization.cc b/source/blender/functions/intern/multi_function_network_optimization.cc
index 0f65d320f62..75c3583c5e5 100644
--- a/source/blender/functions/intern/multi_function_network_optimization.cc
+++ b/source/blender/functions/intern/multi_function_network_optimization.cc
@@ -263,7 +263,7 @@ static Array<MFOutputSocket *> add_constant_folded_sockets(const MultiFunction &
const CPPType &cpp_type = data_type.single_type();
GMutableSpan array = params.computed_array(param_index);
void *buffer = array.data();
- scope.add(buffer, array.type().members().destruct, AT);
+ scope.add(buffer, array.type().destruct_fn(), AT);
constant_fn = &scope.construct<CustomMF_GenericConstant>(AT, cpp_type, buffer);
break;
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index ac458041ca3..73ca4b9c529 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -261,10 +261,12 @@ static void updateDepsgraph(GpencilModifierData *md,
else {
add_this_collection(ctx->scene->master_collection, ctx, mode);
}
- DEG_add_object_relation(
- ctx->node, ctx->scene->camera, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
- DEG_add_object_relation(
- ctx->node, ctx->scene->camera, DEG_OB_COMP_PARAMETERS, "Line Art Modifier");
+ if (ctx->scene->camera) {
+ DEG_add_object_relation(
+ ctx->node, ctx->scene->camera, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
+ DEG_add_object_relation(
+ ctx->node, ctx->scene->camera, DEG_OB_COMP_PARAMETERS, "Line Art Modifier");
+ }
}
static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 06f5e12c891..8762ca1f384 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -1953,7 +1953,7 @@ static uchar lineart_intersection_mask_check(Collection *c, Object *ob)
* See if this object in such collection is used for generating line art,
* Disabling a collection for line art will doable all objects inside.
*/
-static int lineart_usage_check(Collection *c, Object *ob)
+static int lineart_usage_check(Collection *c, Object *ob, bool is_render)
{
if (!c) {
@@ -1966,8 +1966,12 @@ static int lineart_usage_check(Collection *c, Object *ob)
return ob->lineart.usage;
}
- if (c->children.first == NULL) {
+ if (c->gobject.first) {
if (BKE_collection_has_object(c, (Object *)(ob->id.orig_id))) {
+ if ((is_render && (c->flag & COLLECTION_RESTRICT_RENDER)) ||
+ ((!is_render) && (c->flag & COLLECTION_RESTRICT_VIEWPORT))) {
+ return OBJECT_LRT_EXCLUDE;
+ }
if (ob->lineart.usage == OBJECT_LRT_INHERIT) {
switch (c->lineart_usage) {
case COLLECTION_LRT_OCCLUSION_ONLY:
@@ -1986,7 +1990,7 @@ static int lineart_usage_check(Collection *c, Object *ob)
}
LISTBASE_FOREACH (CollectionChild *, cc, &c->children) {
- int result = lineart_usage_check(cc->collection, ob);
+ int result = lineart_usage_check(cc->collection, ob, is_render);
if (result > OBJECT_LRT_INHERIT) {
return result;
}
@@ -2115,9 +2119,11 @@ static void lineart_main_load_geometries(
LineartObjectLoadTaskInfo *olti = lineart_mem_acquire(
&rb->render_data_pool, sizeof(LineartObjectLoadTaskInfo) * thread_count);
+ bool is_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER;
+
DEG_OBJECT_ITER_BEGIN (depsgraph, ob, flags) {
LineartObjectInfo *obi = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartObjectInfo));
- obi->usage = lineart_usage_check(scene->master_collection, ob);
+ obi->usage = lineart_usage_check(scene->master_collection, ob, is_render);
obi->override_intersection_mask = lineart_intersection_mask_check(scene->master_collection,
ob);
Mesh *use_mesh;
diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc
index 062741a6270..cdd56a117db 100644
--- a/source/blender/gpu/intern/gpu_immediate.cc
+++ b/source/blender/gpu/intern/gpu_immediate.cc
@@ -313,7 +313,7 @@ void immAttr1f(uint attr_id, float x)
setAttrValueBit(attr_id);
float *data = (float *)(imm->vertex_data + attr->offset);
- /* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data);
data[0] = x;
}
@@ -329,7 +329,7 @@ void immAttr2f(uint attr_id, float x, float y)
setAttrValueBit(attr_id);
float *data = (float *)(imm->vertex_data + attr->offset);
- /* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data);
data[0] = x;
data[1] = y;
@@ -346,7 +346,7 @@ void immAttr3f(uint attr_id, float x, float y, float z)
setAttrValueBit(attr_id);
float *data = (float *)(imm->vertex_data + attr->offset);
- /* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data);
data[0] = x;
data[1] = y;
@@ -364,7 +364,7 @@ void immAttr4f(uint attr_id, float x, float y, float z, float w)
setAttrValueBit(attr_id);
float *data = (float *)(imm->vertex_data + attr->offset);
- /* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data);
data[0] = x;
data[1] = y;
@@ -445,7 +445,7 @@ void immAttr3ub(uint attr_id, uchar r, uchar g, uchar b)
setAttrValueBit(attr_id);
uchar *data = imm->vertex_data + attr->offset;
- /* printf("%s %td %p\n", __FUNCTION__, data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, data - imm->buffer_data, data);
data[0] = r;
data[1] = g;
@@ -463,7 +463,7 @@ void immAttr4ub(uint attr_id, uchar r, uchar g, uchar b, uchar a)
setAttrValueBit(attr_id);
uchar *data = imm->vertex_data + attr->offset;
- /* printf("%s %td %p\n", __FUNCTION__, data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, data - imm->buffer_data, data);
data[0] = r;
data[1] = g;
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 675036b31c3..37089785e0e 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -452,8 +452,8 @@ static void compute_sss_translucence_kernel(const GPUSssKernelData *kd,
/* Distance from surface. */
float d = kd->max_radius * ((float)i + 0.00001f) / ((float)resolution);
- /* For each distance d we compute the radiance incoming from an hypothetic parallel plane. */
- /* Compute radius of the footprint on the hypothetic plane */
+ /* For each distance d we compute the radiance incoming from an hypothetical parallel plane. */
+ /* Compute radius of the footprint on the hypothetical plane. */
float r_fp = sqrtf(kd->max_radius * kd->max_radius - d * d);
float r_step = r_fp / INTEGRAL_RESOLUTION;
float area_accum = 0.0f;
diff --git a/source/blender/io/alembic/ABC_alembic.h b/source/blender/io/alembic/ABC_alembic.h
index 3d1391ac2a4..0dbebb1e4c4 100644
--- a/source/blender/io/alembic/ABC_alembic.h
+++ b/source/blender/io/alembic/ABC_alembic.h
@@ -25,6 +25,7 @@
extern "C" {
#endif
+struct CacheArchiveHandle;
struct CacheReader;
struct ListBase;
struct Main;
@@ -33,8 +34,6 @@ struct Object;
struct Scene;
struct bContext;
-typedef struct AbcArchiveHandle AbcArchiveHandle;
-
int ABC_get_version(void);
struct AlembicExportParams {
@@ -100,11 +99,11 @@ bool ABC_import(struct bContext *C,
bool validate_meshes,
bool as_background_job);
-AbcArchiveHandle *ABC_create_handle(struct Main *bmain,
- const char *filename,
- struct ListBase *object_paths);
+struct CacheArchiveHandle *ABC_create_handle(struct Main *bmain,
+ const char *filename,
+ struct ListBase *object_paths);
-void ABC_free_handle(AbcArchiveHandle *handle);
+void ABC_free_handle(struct CacheArchiveHandle *handle);
void ABC_get_transform(struct CacheReader *reader,
float r_mat_world[4][4],
@@ -125,10 +124,10 @@ bool ABC_mesh_topology_changed(struct CacheReader *reader,
const float time,
const char **err_str);
-void CacheReader_incref(struct CacheReader *reader);
-void CacheReader_free(struct CacheReader *reader);
+void ABC_CacheReader_incref(struct CacheReader *reader);
+void ABC_CacheReader_free(struct CacheReader *reader);
-struct CacheReader *CacheReader_open_alembic_object(struct AbcArchiveHandle *handle,
+struct CacheReader *CacheReader_open_alembic_object(struct CacheArchiveHandle *handle,
struct CacheReader *reader,
struct Object *object,
const char *object_path);
diff --git a/source/blender/io/alembic/intern/abc_util.h b/source/blender/io/alembic/intern/abc_util.h
index 98f4b0376a7..ced9fde0f85 100644
--- a/source/blender/io/alembic/intern/abc_util.h
+++ b/source/blender/io/alembic/intern/abc_util.h
@@ -22,15 +22,6 @@
#include <Alembic/Abc/All.h>
#include <Alembic/AbcGeom/All.h>
-/**
- * \brief The CacheReader struct is only used for anonymous pointers,
- * to interface between C and C++ code. This library only creates
- * pointers to AbcObjectReader (or subclasses thereof).
- */
-struct CacheReader {
- int unused;
-};
-
using Alembic::Abc::chrono_t;
struct ID;
diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc
index e8d70bf3edb..b94b75b2216 100644
--- a/source/blender/io/alembic/intern/alembic_capi.cc
+++ b/source/blender/io/alembic/intern/alembic_capi.cc
@@ -19,6 +19,7 @@
*/
#include "../ABC_alembic.h"
+#include "IO_types.h"
#include <Alembic/AbcMaterial/IMaterial.h>
@@ -89,18 +90,14 @@ using Alembic::AbcMaterial::IMaterial;
using namespace blender::io::alembic;
-struct AbcArchiveHandle {
- int unused;
-};
-
-BLI_INLINE ArchiveReader *archive_from_handle(AbcArchiveHandle *handle)
+BLI_INLINE ArchiveReader *archive_from_handle(CacheArchiveHandle *handle)
{
return reinterpret_cast<ArchiveReader *>(handle);
}
-BLI_INLINE AbcArchiveHandle *handle_from_archive(ArchiveReader *archive)
+BLI_INLINE CacheArchiveHandle *handle_from_archive(ArchiveReader *archive)
{
- return reinterpret_cast<AbcArchiveHandle *>(archive);
+ return reinterpret_cast<CacheArchiveHandle *>(archive);
}
//#define USE_NURBS
@@ -150,8 +147,8 @@ static bool gather_objects_paths(const IObject &object, ListBase *object_paths)
}
if (get_path) {
- void *abc_path_void = MEM_callocN(sizeof(AlembicObjectPath), "AlembicObjectPath");
- AlembicObjectPath *abc_path = static_cast<AlembicObjectPath *>(abc_path_void);
+ void *abc_path_void = MEM_callocN(sizeof(CacheObjectPath), "CacheObjectPath");
+ CacheObjectPath *abc_path = static_cast<CacheObjectPath *>(abc_path_void);
BLI_strncpy(abc_path->path, object.getFullName().c_str(), sizeof(abc_path->path));
BLI_addtail(object_paths, abc_path);
@@ -160,9 +157,9 @@ static bool gather_objects_paths(const IObject &object, ListBase *object_paths)
return parent_is_part_of_this_object;
}
-AbcArchiveHandle *ABC_create_handle(struct Main *bmain,
- const char *filename,
- ListBase *object_paths)
+CacheArchiveHandle *ABC_create_handle(struct Main *bmain,
+ const char *filename,
+ ListBase *object_paths)
{
ArchiveReader *archive = new ArchiveReader(bmain, filename);
@@ -178,7 +175,7 @@ AbcArchiveHandle *ABC_create_handle(struct Main *bmain,
return handle_from_archive(archive);
}
-void ABC_free_handle(AbcArchiveHandle *handle)
+void ABC_free_handle(CacheArchiveHandle *handle)
{
delete archive_from_handle(handle);
}
@@ -359,8 +356,8 @@ static std::pair<bool, AbcObjectReader *> visit_object(
readers.push_back(reader);
reader->incref();
- AlembicObjectPath *abc_path = static_cast<AlembicObjectPath *>(
- MEM_callocN(sizeof(AlembicObjectPath), "AlembicObjectPath"));
+ CacheObjectPath *abc_path = static_cast<CacheObjectPath *>(
+ MEM_callocN(sizeof(CacheObjectPath), "CacheObjectPath"));
BLI_strncpy(abc_path->path, full_name.c_str(), sizeof(abc_path->path));
BLI_addtail(&settings.cache_file->object_paths, abc_path);
@@ -812,7 +809,7 @@ bool ABC_mesh_topology_changed(
/* ************************************************************************** */
-void CacheReader_free(CacheReader *reader)
+void ABC_CacheReader_free(CacheReader *reader)
{
AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
abc_reader->decref();
@@ -822,13 +819,13 @@ void CacheReader_free(CacheReader *reader)
}
}
-void CacheReader_incref(CacheReader *reader)
+void ABC_CacheReader_incref(CacheReader *reader)
{
AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
abc_reader->incref();
}
-CacheReader *CacheReader_open_alembic_object(AbcArchiveHandle *handle,
+CacheReader *CacheReader_open_alembic_object(CacheArchiveHandle *handle,
CacheReader *reader,
Object *object,
const char *object_path)
@@ -847,7 +844,7 @@ CacheReader *CacheReader_open_alembic_object(AbcArchiveHandle *handle,
find_iobject(archive->getTop(), iobject, object_path);
if (reader) {
- CacheReader_free(reader);
+ ABC_CacheReader_free(reader);
}
ImportSettings settings;
diff --git a/source/blender/io/collada/SceneExporter.cpp b/source/blender/io/collada/SceneExporter.cpp
index 5bbd22b8275..09da2288cfc 100644
--- a/source/blender/io/collada/SceneExporter.cpp
+++ b/source/blender/io/collada/SceneExporter.cpp
@@ -172,7 +172,7 @@ void SceneExporter::writeNode(Object *ob)
else if (ob->type == OB_EMPTY) { /* TODO: handle groups (OB_DUPLICOLLECTION */
if ((ob->transflag & OB_DUPLICOLLECTION) == OB_DUPLICOLLECTION && ob->instance_collection) {
Collection *collection = ob->instance_collection;
- /* printf("group detected '%s'\n", group->id.name + 2); */
+ // printf("group detected '%s'\n", group->id.name + 2);
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (collection, object) {
printf("\t%s\n", object->id.name);
}
diff --git a/source/blender/io/common/CMakeLists.txt b/source/blender/io/common/CMakeLists.txt
index 7e39af32f11..2aaf5d57fd6 100644
--- a/source/blender/io/common/CMakeLists.txt
+++ b/source/blender/io/common/CMakeLists.txt
@@ -37,6 +37,7 @@ set(SRC
IO_abstract_hierarchy_iterator.h
IO_dupli_persistent_id.hh
+ IO_types.h
intern/dupli_parent_finder.hh
)
diff --git a/source/blender/io/common/IO_types.h b/source/blender/io/common/IO_types.h
new file mode 100644
index 00000000000..4570e29f6ed
--- /dev/null
+++ b/source/blender/io/common/IO_types.h
@@ -0,0 +1,34 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+#pragma once
+
+/* The CacheArchiveHandle struct is only used for anonymous pointers,
+ * to interface between C and C++ code. This is currently used
+ * to hide pointers to alembic ArchiveReader and USDStageReader. */
+struct CacheArchiveHandle {
+ int unused;
+};
+
+/* The CacheReader struct is only used for anonymous pointers,
+ * to interface between C and C++ code. This is currently used
+ * to hide pointers to AbcObjectReader and USDPrimReader
+ * (or subclasses thereof). */
+struct CacheReader {
+ int unused;
+};
diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt
index 6ea30f48a13..5499fe36898 100644
--- a/source/blender/io/usd/CMakeLists.txt
+++ b/source/blender/io/usd/CMakeLists.txt
@@ -56,7 +56,9 @@ set(INC_SYS
)
set(SRC
- intern/usd_capi.cc
+ intern/usd_capi_export.cc
+ intern/usd_capi_import.cc
+ intern/usd_common.cc
intern/usd_hierarchy_iterator.cc
intern/usd_writer_abstract.cc
intern/usd_writer_camera.cc
@@ -66,7 +68,21 @@ set(SRC
intern/usd_writer_metaball.cc
intern/usd_writer_transform.cc
+ intern/usd_reader_camera.cc
+ intern/usd_reader_curve.cc
+ intern/usd_reader_geom.cc
+ intern/usd_reader_light.cc
+ intern/usd_reader_material.cc
+ intern/usd_reader_mesh.cc
+ intern/usd_reader_nurbs.cc
+ intern/usd_reader_prim.cc
+ intern/usd_reader_stage.cc
+ intern/usd_reader_xform.cc
+ intern/usd_reader_volume.cc
+
usd.h
+
+ intern/usd_common.h
intern/usd_exporter_context.h
intern/usd_hierarchy_iterator.h
intern/usd_writer_abstract.h
@@ -76,6 +92,18 @@ set(SRC
intern/usd_writer_mesh.h
intern/usd_writer_metaball.h
intern/usd_writer_transform.h
+
+ intern/usd_reader_camera.h
+ intern/usd_reader_curve.h
+ intern/usd_reader_geom.h
+ intern/usd_reader_light.h
+ intern/usd_reader_material.h
+ intern/usd_reader_mesh.h
+ intern/usd_reader_nurbs.h
+ intern/usd_reader_prim.h
+ intern/usd_reader_stage.h
+ intern/usd_reader_xform.h
+ intern/usd_reader_volume.h
)
set(LIB
diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi_export.cc
index dc2b46e5cea..25f12e683cf 100644
--- a/source/blender/io/usd/intern/usd_capi.cc
+++ b/source/blender/io/usd/intern/usd_capi_export.cc
@@ -18,6 +18,7 @@
*/
#include "usd.h"
+#include "usd_common.h"
#include "usd_hierarchy_iterator.h"
#include <pxr/base/plug/registry.h>
@@ -59,21 +60,6 @@ struct ExportJobData {
bool export_ok;
};
-static void ensure_usd_plugin_path_registered()
-{
- static bool plugin_path_registered = false;
- if (plugin_path_registered) {
- return;
- }
- plugin_path_registered = true;
-
- /* Tell USD which directory to search for its JSON files. If 'datafiles/usd'
- * does not exist, the USD library will not be able to read or write any files. */
- const std::string blender_usd_datafiles = BKE_appdir_folder_id(BLENDER_DATAFILES, "usd");
- /* The trailing slash indicates to the USD library that the path is a directory. */
- pxr::PlugRegistry::GetInstance().RegisterPlugins(blender_usd_datafiles + "/");
-}
-
static void export_startjob(void *customdata,
/* Cannot be const, this function implements wm_jobs_start_callback.
* NOLINTNEXTLINE: readability-non-const-parameter. */
diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc
new file mode 100644
index 00000000000..8255fca284c
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_capi_import.cc
@@ -0,0 +1,578 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2019 Blender Foundation.
+ * All rights reserved.
+ */
+
+#include "IO_types.h"
+#include "usd.h"
+#include "usd_common.h"
+#include "usd_hierarchy_iterator.h"
+#include "usd_reader_geom.h"
+#include "usd_reader_prim.h"
+#include "usd_reader_stage.h"
+
+#include "BKE_appdir.h"
+#include "BKE_blender_version.h"
+#include "BKE_cachefile.h"
+#include "BKE_cdderivedmesh.h"
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_layer.h"
+#include "BKE_lib_id.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_node.h"
+#include "BKE_object.h"
+#include "BKE_scene.h"
+#include "BKE_world.h"
+
+#include "BLI_fileops.h"
+#include "BLI_listbase.h"
+#include "BLI_math_matrix.h"
+#include "BLI_math_rotation.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
+
+#include "DNA_cachefile_types.h"
+#include "DNA_collection_types.h"
+#include "DNA_node_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_world_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include <pxr/usd/usd/stage.h>
+#include <pxr/usd/usdGeom/metrics.h>
+#include <pxr/usd/usdGeom/scope.h>
+#include <pxr/usd/usdGeom/tokens.h>
+#include <pxr/usd/usdGeom/xformCommonAPI.h>
+
+#include <iostream>
+
+namespace blender::io::usd {
+
+static CacheArchiveHandle *handle_from_stage_reader(USDStageReader *reader)
+{
+ return reinterpret_cast<CacheArchiveHandle *>(reader);
+}
+
+static USDStageReader *stage_reader_from_handle(CacheArchiveHandle *handle)
+{
+ return reinterpret_cast<USDStageReader *>(handle);
+}
+
+static bool gather_objects_paths(const pxr::UsdPrim &object, ListBase *object_paths)
+{
+ if (!object.IsValid()) {
+ return false;
+ }
+
+ for (const pxr::UsdPrim &childPrim : object.GetChildren()) {
+ gather_objects_paths(childPrim, object_paths);
+ }
+
+ void *usd_path_void = MEM_callocN(sizeof(CacheObjectPath), "CacheObjectPath");
+ CacheObjectPath *usd_path = static_cast<CacheObjectPath *>(usd_path_void);
+
+ BLI_strncpy(usd_path->path, object.GetPrimPath().GetString().c_str(), sizeof(usd_path->path));
+ BLI_addtail(object_paths, usd_path);
+
+ return true;
+}
+
+/* Update the given import settings with the global rotation matrix to orient
+ * imported objects with Z-up, if necessary */
+static void convert_to_z_up(pxr::UsdStageRefPtr stage, ImportSettings *r_settings)
+{
+ if (!stage || pxr::UsdGeomGetStageUpAxis(stage) == pxr::UsdGeomTokens->z) {
+ return;
+ }
+
+ if (!r_settings) {
+ return;
+ }
+
+ r_settings->do_convert_mat = true;
+
+ /* Rotate 90 degrees about the X-axis. */
+ float rmat[3][3];
+ float axis[3] = {1.0f, 0.0f, 0.0f};
+ axis_angle_normalized_to_mat3(rmat, axis, M_PI / 2.0f);
+
+ unit_m4(r_settings->conversion_mat);
+ copy_m4_m3(r_settings->conversion_mat, rmat);
+}
+
+enum {
+ USD_NO_ERROR = 0,
+ USD_ARCHIVE_FAIL,
+};
+
+struct ImportJobData {
+ Main *bmain;
+ Scene *scene;
+ ViewLayer *view_layer;
+ wmWindowManager *wm;
+
+ char filename[1024];
+ USDImportParams params;
+ ImportSettings settings;
+
+ USDStageReader *archive;
+
+ short *stop;
+ short *do_update;
+ float *progress;
+
+ char error_code;
+ bool was_canceled;
+ bool import_ok;
+};
+
+static void import_startjob(void *customdata, short *stop, short *do_update, float *progress)
+{
+ ImportJobData *data = static_cast<ImportJobData *>(customdata);
+
+ data->stop = stop;
+ data->do_update = do_update;
+ data->progress = progress;
+ data->was_canceled = false;
+ data->archive = nullptr;
+
+ WM_set_locked_interface(data->wm, true);
+ G.is_break = false;
+
+ if (data->params.create_collection) {
+ char display_name[1024];
+ BLI_path_to_display_name(
+ display_name, strlen(data->filename), BLI_path_basename(data->filename));
+ Collection *import_collection = BKE_collection_add(
+ data->bmain, data->scene->master_collection, display_name);
+ id_fake_user_set(&import_collection->id);
+
+ DEG_id_tag_update(&import_collection->id, ID_RECALC_COPY_ON_WRITE);
+ DEG_relations_tag_update(data->bmain);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, nullptr);
+
+ data->view_layer->active_collection = BKE_layer_collection_first_from_scene_collection(
+ data->view_layer, import_collection);
+ }
+
+ BLI_path_abs(data->filename, BKE_main_blendfile_path_from_global());
+
+ CacheFile *cache_file = static_cast<CacheFile *>(
+ BKE_cachefile_add(data->bmain, BLI_path_basename(data->filename)));
+
+ /* Decrement the ID ref-count because it is going to be incremented for each
+ * modifier and constraint that it will be attached to, so since currently
+ * it is not used by anyone, its use count will off by one. */
+ id_us_min(&cache_file->id);
+
+ cache_file->is_sequence = data->params.is_sequence;
+ cache_file->scale = data->params.scale;
+ STRNCPY(cache_file->filepath, data->filename);
+
+ data->settings.cache_file = cache_file;
+
+ *data->do_update = true;
+ *data->progress = 0.05f;
+
+ if (G.is_break) {
+ data->was_canceled = true;
+ return;
+ }
+
+ *data->do_update = true;
+ *data->progress = 0.1f;
+
+ pxr::UsdStageRefPtr stage = pxr::UsdStage::Open(data->filename);
+
+ if (!stage) {
+ WM_reportf(RPT_ERROR, "USD Import: unable to open stage to read %s", data->filename);
+ data->import_ok = false;
+ return;
+ }
+
+ convert_to_z_up(stage, &data->settings);
+
+ /* Set up the stage for animated data. */
+ if (data->params.set_frame_range) {
+ data->scene->r.sfra = stage->GetStartTimeCode();
+ data->scene->r.efra = stage->GetEndTimeCode();
+ }
+
+ *data->progress = 0.15f;
+
+ USDStageReader *archive = new USDStageReader(stage, data->params, data->settings);
+
+ data->archive = archive;
+
+ archive->collect_readers(data->bmain);
+
+ *data->progress = 0.2f;
+
+ const float size = static_cast<float>(archive->readers().size());
+ size_t i = 0;
+
+ /* Setup parenthood */
+
+ for (USDPrimReader *reader : archive->readers()) {
+
+ if (!reader) {
+ continue;
+ }
+
+ Object *ob = reader->object();
+
+ reader->read_object_data(data->bmain, 0.0);
+
+ USDPrimReader *parent = reader->parent();
+
+ if (parent == nullptr) {
+ ob->parent = nullptr;
+ }
+ else {
+ ob->parent = parent->object();
+ }
+
+ *data->progress = 0.2f + 0.8f * (++i / size);
+ *data->do_update = true;
+
+ if (G.is_break) {
+ data->was_canceled = true;
+ return;
+ }
+ }
+
+ data->import_ok = !data->was_canceled;
+
+ *progress = 1.0f;
+ *do_update = true;
+}
+
+static void import_endjob(void *customdata)
+{
+ ImportJobData *data = static_cast<ImportJobData *>(customdata);
+
+ /* Delete objects on cancellation. */
+ if (data->was_canceled && data->archive) {
+
+ for (USDPrimReader *reader : data->archive->readers()) {
+
+ if (!reader) {
+ continue;
+ }
+
+ /* It's possible that cancellation occurred between the creation of
+ * the reader and the creation of the Blender object. */
+ if (Object *ob = reader->object()) {
+ BKE_id_free_us(data->bmain, ob);
+ }
+ }
+ }
+ else if (data->archive) {
+ /* Add object to scene. */
+ Base *base;
+ LayerCollection *lc;
+ ViewLayer *view_layer = data->view_layer;
+
+ BKE_view_layer_base_deselect_all(view_layer);
+
+ lc = BKE_layer_collection_get_active(view_layer);
+
+ for (USDPrimReader *reader : data->archive->readers()) {
+
+ if (!reader) {
+ continue;
+ }
+
+ Object *ob = reader->object();
+
+ if (!ob) {
+ continue;
+ }
+
+ BKE_collection_object_add(data->bmain, lc->collection, ob);
+
+ base = BKE_view_layer_base_find(view_layer, ob);
+ /* TODO: is setting active needed? */
+ BKE_view_layer_base_select_and_set_active(view_layer, base);
+
+ DEG_id_tag_update(&lc->collection->id, ID_RECALC_COPY_ON_WRITE);
+ DEG_id_tag_update_ex(data->bmain,
+ &ob->id,
+ ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION |
+ ID_RECALC_BASE_FLAGS);
+ }
+
+ DEG_id_tag_update(&data->scene->id, ID_RECALC_BASE_FLAGS);
+ DEG_relations_tag_update(data->bmain);
+ }
+
+ WM_set_locked_interface(data->wm, false);
+
+ switch (data->error_code) {
+ default:
+ case USD_NO_ERROR:
+ data->import_ok = !data->was_canceled;
+ break;
+ case USD_ARCHIVE_FAIL:
+ WM_report(RPT_ERROR, "Could not open USD archive for reading! See console for detail.");
+ break;
+ }
+
+ WM_main_add_notifier(NC_SCENE | ND_FRAME, data->scene);
+}
+
+static void import_freejob(void *user_data)
+{
+ ImportJobData *data = static_cast<ImportJobData *>(user_data);
+
+ delete data->archive;
+ delete data;
+}
+
+} // namespace blender::io::usd
+
+using namespace blender::io::usd;
+
+bool USD_import(struct bContext *C,
+ const char *filepath,
+ const USDImportParams *params,
+ bool as_background_job)
+{
+ blender::io::usd::ensure_usd_plugin_path_registered();
+
+ /* Using new here since MEM_* funcs do not call ctor to properly initialize
+ * data. */
+ ImportJobData *job = new ImportJobData();
+ job->bmain = CTX_data_main(C);
+ job->scene = CTX_data_scene(C);
+ job->view_layer = CTX_data_view_layer(C);
+ job->wm = CTX_wm_manager(C);
+ job->import_ok = false;
+ BLI_strncpy(job->filename, filepath, 1024);
+
+ job->settings.scale = params->scale;
+ job->settings.sequence_offset = params->offset;
+ job->settings.is_sequence = params->is_sequence;
+ job->settings.sequence_len = params->sequence_len;
+ job->settings.validate_meshes = params->validate_meshes;
+ job->settings.sequence_len = params->sequence_len;
+ job->error_code = USD_NO_ERROR;
+ job->was_canceled = false;
+ job->archive = nullptr;
+
+ job->params = *params;
+
+ G.is_break = false;
+
+ bool import_ok = false;
+ if (as_background_job) {
+ wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
+ CTX_wm_window(C),
+ job->scene,
+ "USD Import",
+ WM_JOB_PROGRESS,
+ WM_JOB_TYPE_ALEMBIC);
+
+ /* setup job */
+ WM_jobs_customdata_set(wm_job, job, import_freejob);
+ WM_jobs_timer(wm_job, 0.1, NC_SCENE, NC_SCENE);
+ WM_jobs_callbacks(wm_job, import_startjob, nullptr, nullptr, import_endjob);
+
+ WM_jobs_start(CTX_wm_manager(C), wm_job);
+ }
+ else {
+ /* Fake a job context, so that we don't need NULL pointer checks while importing. */
+ short stop = 0, do_update = 0;
+ float progress = 0.f;
+
+ import_startjob(job, &stop, &do_update, &progress);
+ import_endjob(job);
+ import_ok = job->import_ok;
+
+ import_freejob(job);
+ }
+
+ return import_ok;
+}
+
+/* TODO(makowalski): Extend this function with basic validation that the
+ * USD reader is compatible with the type of the given (currently unused) 'ob'
+ * Object parameter, similar to the logic in get_abc_reader() in the
+ * Alembic importer code. */
+static USDPrimReader *get_usd_reader(CacheReader *reader, Object * /* ob */, const char **err_str)
+{
+ USDPrimReader *usd_reader = reinterpret_cast<USDPrimReader *>(reader);
+ pxr::UsdPrim iobject = usd_reader->prim();
+
+ if (!iobject.IsValid()) {
+ *err_str = "Invalid object: verify object path";
+ return nullptr;
+ }
+
+ return usd_reader;
+}
+
+struct Mesh *USD_read_mesh(struct CacheReader *reader,
+ struct Object *ob,
+ struct Mesh *existing_mesh,
+ const float time,
+ const char **err_str,
+ const int read_flag)
+{
+ USDGeomReader *usd_reader = dynamic_cast<USDGeomReader *>(get_usd_reader(reader, ob, err_str));
+
+ if (usd_reader == nullptr) {
+ return nullptr;
+ }
+
+ return usd_reader->read_mesh(existing_mesh, time, read_flag, err_str);
+}
+
+bool USD_mesh_topology_changed(
+ CacheReader *reader, Object *ob, Mesh *existing_mesh, const float time, const char **err_str)
+{
+ USDGeomReader *usd_reader = dynamic_cast<USDGeomReader *>(get_usd_reader(reader, ob, err_str));
+
+ if (usd_reader == nullptr) {
+ return false;
+ }
+
+ return usd_reader->topology_changed(existing_mesh, time);
+}
+
+void USD_CacheReader_incref(CacheReader *reader)
+{
+ USDPrimReader *usd_reader = reinterpret_cast<USDPrimReader *>(reader);
+ usd_reader->incref();
+}
+
+CacheReader *CacheReader_open_usd_object(CacheArchiveHandle *handle,
+ CacheReader *reader,
+ Object *object,
+ const char *object_path)
+{
+ if (object_path[0] == '\0') {
+ return reader;
+ }
+
+ USDStageReader *archive = stage_reader_from_handle(handle);
+
+ if (!archive || !archive->valid()) {
+ return reader;
+ }
+
+ pxr::UsdPrim prim = archive->stage()->GetPrimAtPath(pxr::SdfPath(object_path));
+
+ if (reader) {
+ USD_CacheReader_free(reader);
+ }
+
+ /* TODO(makowalski): The handle does not have the proper import params or settings. */
+ USDPrimReader *usd_reader = archive->create_reader(prim);
+
+ if (usd_reader == nullptr) {
+ /* This object is not supported */
+ return nullptr;
+ }
+ usd_reader->object(object);
+ usd_reader->incref();
+
+ return reinterpret_cast<CacheReader *>(usd_reader);
+}
+
+void USD_CacheReader_free(CacheReader *reader)
+{
+ USDPrimReader *usd_reader = reinterpret_cast<USDPrimReader *>(reader);
+ usd_reader->decref();
+
+ if (usd_reader->refcount() == 0) {
+ delete usd_reader;
+ }
+}
+
+CacheArchiveHandle *USD_create_handle(struct Main * /*bmain*/,
+ const char *filename,
+ ListBase *object_paths)
+{
+ pxr::UsdStageRefPtr stage = pxr::UsdStage::Open(filename);
+
+ if (!stage) {
+ return nullptr;
+ }
+
+ USDImportParams params{};
+
+ blender::io::usd::ImportSettings settings{};
+ convert_to_z_up(stage, &settings);
+
+ USDStageReader *stage_reader = new USDStageReader(stage, params, settings);
+
+ if (object_paths) {
+ gather_objects_paths(stage->GetPseudoRoot(), object_paths);
+ }
+
+ return handle_from_stage_reader(stage_reader);
+}
+
+void USD_free_handle(CacheArchiveHandle *handle)
+{
+ USDStageReader *stage_reader = stage_reader_from_handle(handle);
+ delete stage_reader;
+}
+
+void USD_get_transform(struct CacheReader *reader,
+ float r_mat_world[4][4],
+ float time,
+ float scale)
+{
+ if (!reader) {
+ return;
+ }
+ USDXformReader *usd_reader = reinterpret_cast<USDXformReader *>(reader);
+
+ bool is_constant = false;
+
+ /* Convert from the local matrix we obtain from USD to world coordinates
+ * for Blender. This conversion is done here rather than by Blender due to
+ * work around the non-standard interpretation of CONSTRAINT_SPACE_LOCAL in
+ * BKE_constraint_mat_convertspace(). */
+ Object *object = usd_reader->object();
+ if (object->parent == nullptr) {
+ /* No parent, so local space is the same as world space. */
+ usd_reader->read_matrix(r_mat_world, time, scale, &is_constant);
+ return;
+ }
+
+ float mat_parent[4][4];
+ BKE_object_get_parent_matrix(object, object->parent, mat_parent);
+
+ float mat_local[4][4];
+ usd_reader->read_matrix(mat_local, time, scale, &is_constant);
+ mul_m4_m4m4(r_mat_world, mat_parent, object->parentinv);
+ mul_m4_m4m4(r_mat_world, r_mat_world, mat_local);
+}
diff --git a/source/blender/io/usd/intern/usd_common.cc b/source/blender/io/usd/intern/usd_common.cc
new file mode 100644
index 00000000000..0cd9c3019ef
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_common.cc
@@ -0,0 +1,43 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+
+#include "usd_common.h"
+
+#include <pxr/base/plug/registry.h>
+
+#include "BKE_appdir.h"
+
+namespace blender::io::usd {
+
+void ensure_usd_plugin_path_registered()
+{
+ static bool plugin_path_registered = false;
+ if (plugin_path_registered) {
+ return;
+ }
+ plugin_path_registered = true;
+
+ /* Tell USD which directory to search for its JSON files. If 'datafiles/usd'
+ * does not exist, the USD library will not be able to read or write any files. */
+ const std::string blender_usd_datafiles = BKE_appdir_folder_id(BLENDER_DATAFILES, "usd");
+ /* The trailing slash indicates to the USD library that the path is a directory. */
+ pxr::PlugRegistry::GetInstance().RegisterPlugins(blender_usd_datafiles + "/");
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_common.h b/source/blender/io/usd/intern/usd_common.h
new file mode 100644
index 00000000000..36667bbc6b1
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_common.h
@@ -0,0 +1,25 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+#pragma once
+
+namespace blender::io::usd {
+
+void ensure_usd_plugin_path_registered();
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_camera.cc b/source/blender/io/usd/intern/usd_reader_camera.cc
new file mode 100644
index 00000000000..2732ed5770d
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_camera.cc
@@ -0,0 +1,100 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_camera.h"
+
+#include "DNA_camera_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_camera.h"
+#include "BKE_object.h"
+
+#include "BLI_math.h"
+
+#include <pxr/pxr.h>
+#include <pxr/usd/usdGeom/camera.h>
+
+namespace blender::io::usd {
+
+void USDCameraReader::create_object(Main *bmain, const double /* motionSampleTime */)
+{
+ Camera *bcam = static_cast<Camera *>(BKE_camera_add(bmain, name_.c_str()));
+
+ object_ = BKE_object_add_only_object(bmain, OB_CAMERA, name_.c_str());
+ object_->data = bcam;
+}
+
+void USDCameraReader::read_object_data(Main *bmain, const double motionSampleTime)
+{
+ Camera *bcam = (Camera *)object_->data;
+
+ pxr::UsdGeomCamera cam_prim(prim_);
+
+ if (!cam_prim) {
+ return;
+ }
+
+ pxr::VtValue val;
+ cam_prim.GetFocalLengthAttr().Get(&val, motionSampleTime);
+ pxr::VtValue verApOffset;
+ cam_prim.GetVerticalApertureOffsetAttr().Get(&verApOffset, motionSampleTime);
+ pxr::VtValue horApOffset;
+ cam_prim.GetHorizontalApertureOffsetAttr().Get(&horApOffset, motionSampleTime);
+ pxr::VtValue clippingRangeVal;
+ cam_prim.GetClippingRangeAttr().Get(&clippingRangeVal, motionSampleTime);
+ pxr::VtValue focalDistanceVal;
+ cam_prim.GetFocusDistanceAttr().Get(&focalDistanceVal, motionSampleTime);
+ pxr::VtValue fstopVal;
+ cam_prim.GetFStopAttr().Get(&fstopVal, motionSampleTime);
+ pxr::VtValue projectionVal;
+ cam_prim.GetProjectionAttr().Get(&projectionVal, motionSampleTime);
+ pxr::VtValue verAp;
+ cam_prim.GetVerticalApertureAttr().Get(&verAp, motionSampleTime);
+ pxr::VtValue horAp;
+ cam_prim.GetHorizontalApertureAttr().Get(&horAp, motionSampleTime);
+
+ bcam->lens = val.Get<float>();
+ /* TODO(makowalski) */
+#if 0
+ bcam->sensor_x = 0.0f;
+ bcam->sensor_y = 0.0f;
+#endif
+ bcam->shiftx = verApOffset.Get<float>();
+ bcam->shifty = horApOffset.Get<float>();
+
+ bcam->type = (projectionVal.Get<pxr::TfToken>().GetString() == "perspective") ? CAM_PERSP :
+ CAM_ORTHO;
+
+ /* Calling UncheckedGet() to silence compiler warnings. */
+ bcam->clip_start = max_ff(0.1f, clippingRangeVal.UncheckedGet<pxr::GfVec2f>()[0]);
+ bcam->clip_end = clippingRangeVal.UncheckedGet<pxr::GfVec2f>()[1];
+
+ bcam->dof.focus_distance = focalDistanceVal.Get<float>();
+ bcam->dof.aperture_fstop = static_cast<float>(fstopVal.Get<float>());
+
+ if (bcam->type == CAM_ORTHO) {
+ bcam->ortho_scale = max_ff(verAp.Get<float>(), horAp.Get<float>());
+ }
+
+ USDXformReader::read_object_data(bmain, motionSampleTime);
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_camera.h b/source/blender/io/usd/intern/usd_reader_camera.h
new file mode 100644
index 00000000000..a4156aa8be2
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_camera.h
@@ -0,0 +1,42 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+#include "usd_reader_xform.h"
+
+namespace blender::io::usd {
+
+class USDCameraReader : public USDXformReader {
+
+ public:
+ USDCameraReader(const pxr::UsdPrim &object,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : USDXformReader(object, import_params, settings)
+ {
+ }
+
+ void create_object(Main *bmain, double motionSampleTime) override;
+ void read_object_data(Main *bmain, double motionSampleTime) override;
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_curve.cc b/source/blender/io/usd/intern/usd_reader_curve.cc
new file mode 100644
index 00000000000..31ecf27cf7e
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_curve.cc
@@ -0,0 +1,256 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation,
+ * Copyright (C) 2016 Kévin Dietrich.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_curve.h"
+
+#include "BKE_curve.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+
+#include "BLI_listbase.h"
+
+#include "DNA_curve_types.h"
+#include "DNA_object_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include <pxr/base/vt/array.h>
+#include <pxr/base/vt/types.h>
+#include <pxr/base/vt/value.h>
+
+#include <pxr/usd/usdGeom/basisCurves.h>
+#include <pxr/usd/usdGeom/curves.h>
+
+namespace blender::io::usd {
+
+void USDCurvesReader::create_object(Main *bmain, const double /* motionSampleTime */)
+{
+ curve_ = BKE_curve_add(bmain, name_.c_str(), OB_CURVE);
+
+ curve_->flag |= CU_DEFORM_FILL | CU_3D;
+ curve_->actvert = CU_ACT_NONE;
+ curve_->resolu = 2;
+
+ object_ = BKE_object_add_only_object(bmain, OB_CURVE, name_.c_str());
+ object_->data = curve_;
+}
+
+void USDCurvesReader::read_object_data(Main *bmain, double motionSampleTime)
+{
+ Curve *cu = (Curve *)object_->data;
+ read_curve_sample(cu, motionSampleTime);
+
+ if (curve_prim_.GetPointsAttr().ValueMightBeTimeVarying()) {
+ add_cache_modifier();
+ }
+
+ USDXformReader::read_object_data(bmain, motionSampleTime);
+}
+
+void USDCurvesReader::read_curve_sample(Curve *cu, const double motionSampleTime)
+{
+ curve_prim_ = pxr::UsdGeomBasisCurves(prim_);
+
+ if (!curve_prim_) {
+ return;
+ }
+
+ pxr::UsdAttribute widthsAttr = curve_prim_.GetWidthsAttr();
+ pxr::UsdAttribute vertexAttr = curve_prim_.GetCurveVertexCountsAttr();
+ pxr::UsdAttribute pointsAttr = curve_prim_.GetPointsAttr();
+
+ pxr::VtIntArray usdCounts;
+
+ vertexAttr.Get(&usdCounts, motionSampleTime);
+ int num_subcurves = usdCounts.size();
+
+ pxr::VtVec3fArray usdPoints;
+ pointsAttr.Get(&usdPoints, motionSampleTime);
+
+ pxr::VtFloatArray usdWidths;
+ widthsAttr.Get(&usdWidths, motionSampleTime);
+
+ pxr::UsdAttribute basisAttr = curve_prim_.GetBasisAttr();
+ pxr::TfToken basis;
+ basisAttr.Get(&basis, motionSampleTime);
+
+ pxr::UsdAttribute typeAttr = curve_prim_.GetTypeAttr();
+ pxr::TfToken type;
+ typeAttr.Get(&type, motionSampleTime);
+
+ pxr::UsdAttribute wrapAttr = curve_prim_.GetWrapAttr();
+ pxr::TfToken wrap;
+ wrapAttr.Get(&wrap, motionSampleTime);
+
+ pxr::VtVec3fArray usdNormals;
+ curve_prim_.GetNormalsAttr().Get(&usdNormals, motionSampleTime);
+
+ /* If normals, extrude, else bevel.
+ * Perhaps to be replaced by Blender/USD Schema. */
+ if (!usdNormals.empty()) {
+ /* Set extrusion to 1.0f. */
+ curve_->ext1 = 1.0f;
+ }
+ else {
+ /* Set bevel depth to 1.0f. */
+ curve_->ext2 = 1.0f;
+ }
+
+ size_t idx = 0;
+ for (size_t i = 0; i < num_subcurves; i++) {
+ const int num_verts = usdCounts[i];
+ Nurb *nu = static_cast<Nurb *>(MEM_callocN(sizeof(Nurb), __func__));
+
+ if (basis == pxr::UsdGeomTokens->bspline) {
+ nu->flag = CU_SMOOTH;
+ nu->type = CU_NURBS;
+ }
+ else if (basis == pxr::UsdGeomTokens->bezier) {
+ /* TODO(makowalski): Beziers are not properly imported as beziers. */
+ nu->type = CU_POLY;
+ }
+ else if (basis.IsEmpty()) {
+ nu->type = CU_POLY;
+ }
+ nu->resolu = cu->resolu;
+ nu->resolv = cu->resolv;
+
+ nu->pntsu = num_verts;
+ nu->pntsv = 1;
+
+ if (type == pxr::UsdGeomTokens->cubic) {
+ nu->orderu = 4;
+ }
+ else if (type == pxr::UsdGeomTokens->linear) {
+ nu->orderu = 2;
+ }
+
+ if (wrap == pxr::UsdGeomTokens->periodic) {
+ nu->flagu |= CU_NURB_CYCLIC;
+ }
+ else if (wrap == pxr::UsdGeomTokens->pinned) {
+ nu->flagu |= CU_NURB_ENDPOINT;
+ }
+
+ float weight = 1.0f;
+
+ nu->bp = static_cast<BPoint *>(MEM_callocN(sizeof(BPoint) * nu->pntsu, __func__));
+ BPoint *bp = nu->bp;
+
+ for (int j = 0; j < nu->pntsu; j++, bp++, idx++) {
+ bp->vec[0] = (float)usdPoints[idx][0];
+ bp->vec[1] = (float)usdPoints[idx][1];
+ bp->vec[2] = (float)usdPoints[idx][2];
+ bp->vec[3] = weight;
+ bp->f1 = SELECT;
+ bp->weight = weight;
+
+ float radius = curve_->width;
+ if (idx < usdWidths.size()) {
+ radius = usdWidths[idx];
+ }
+
+ bp->radius = radius;
+ }
+
+ BKE_nurb_knot_calc_u(nu);
+ BKE_nurb_knot_calc_v(nu);
+
+ BLI_addtail(BKE_curve_nurbs_get(cu), nu);
+ }
+}
+
+Mesh *USDCurvesReader::read_mesh(struct Mesh *existing_mesh,
+ const double motionSampleTime,
+ const int /* read_flag */,
+ const char ** /* err_str */)
+{
+ if (!curve_prim_) {
+ return existing_mesh;
+ }
+
+ pxr::UsdAttribute widthsAttr = curve_prim_.GetWidthsAttr();
+ pxr::UsdAttribute vertexAttr = curve_prim_.GetCurveVertexCountsAttr();
+ pxr::UsdAttribute pointsAttr = curve_prim_.GetPointsAttr();
+
+ pxr::VtIntArray usdCounts;
+
+ vertexAttr.Get(&usdCounts, motionSampleTime);
+ int num_subcurves = usdCounts.size();
+
+ pxr::VtVec3fArray usdPoints;
+ pointsAttr.Get(&usdPoints, motionSampleTime);
+
+ int vertex_idx = 0;
+ int curve_idx;
+ Curve *curve = static_cast<Curve *>(object_->data);
+
+ const int curve_count = BLI_listbase_count(&curve->nurb);
+ bool same_topology = curve_count == num_subcurves;
+
+ if (same_topology) {
+ Nurb *nurbs = static_cast<Nurb *>(curve->nurb.first);
+ for (curve_idx = 0; nurbs; nurbs = nurbs->next, curve_idx++) {
+ const int num_in_usd = usdCounts[curve_idx];
+ const int num_in_blender = nurbs->pntsu;
+
+ if (num_in_usd != num_in_blender) {
+ same_topology = false;
+ break;
+ }
+ }
+ }
+
+ if (!same_topology) {
+ BKE_nurbList_free(&curve->nurb);
+ read_curve_sample(curve, motionSampleTime);
+ }
+ else {
+ Nurb *nurbs = static_cast<Nurb *>(curve->nurb.first);
+ for (curve_idx = 0; nurbs; nurbs = nurbs->next, curve_idx++) {
+ const int totpoint = usdCounts[curve_idx];
+
+ if (nurbs->bp) {
+ BPoint *point = nurbs->bp;
+
+ for (int i = 0; i < totpoint; i++, point++, vertex_idx++) {
+ point->vec[0] = usdPoints[vertex_idx][0];
+ point->vec[1] = usdPoints[vertex_idx][1];
+ point->vec[2] = usdPoints[vertex_idx][2];
+ }
+ }
+ else if (nurbs->bezt) {
+ BezTriple *bezier = nurbs->bezt;
+
+ for (int i = 0; i < totpoint; i++, bezier++, vertex_idx++) {
+ bezier->vec[1][0] = usdPoints[vertex_idx][0];
+ bezier->vec[1][1] = usdPoints[vertex_idx][1];
+ bezier->vec[1][2] = usdPoints[vertex_idx][2];
+ }
+ }
+ }
+ }
+
+ return BKE_mesh_new_nomain_from_curve(object_);
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_curve.h b/source/blender/io/usd/intern/usd_reader_curve.h
new file mode 100644
index 00000000000..1e676bbbd02
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_curve.h
@@ -0,0 +1,62 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation,
+ * Copyright (C) 2016 Kévin Dietrich.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+#include "usd_reader_geom.h"
+
+#include "pxr/usd/usdGeom/basisCurves.h"
+
+struct Curve;
+
+namespace blender::io::usd {
+
+class USDCurvesReader : public USDGeomReader {
+ protected:
+ pxr::UsdGeomBasisCurves curve_prim_;
+ Curve *curve_;
+
+ public:
+ USDCurvesReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : USDGeomReader(prim, import_params, settings), curve_prim_(prim), curve_(nullptr)
+ {
+ }
+
+ bool valid() const override
+ {
+ return static_cast<bool>(curve_prim_);
+ }
+
+ void create_object(Main *bmain, double motionSampleTime) override;
+ void read_object_data(Main *bmain, double motionSampleTime) override;
+
+ void read_curve_sample(Curve *cu, double motionSampleTime);
+
+ Mesh *read_mesh(struct Mesh *existing_mesh,
+ double motionSampleTime,
+ int read_flag,
+ const char **err_str) override;
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_geom.cc b/source/blender/io/usd/intern/usd_reader_geom.cc
new file mode 100644
index 00000000000..23c5f57120c
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_geom.cc
@@ -0,0 +1,59 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_geom.h"
+
+#include "BKE_lib_id.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_math_geom.h"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_cachefile_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_space_types.h" /* for FILE_MAX */
+
+namespace blender::io::usd {
+
+void USDGeomReader::add_cache_modifier()
+{
+ ModifierData *md = BKE_modifier_new(eModifierType_MeshSequenceCache);
+ BLI_addtail(&object_->modifiers, md);
+
+ MeshSeqCacheModifierData *mcmd = reinterpret_cast<MeshSeqCacheModifierData *>(md);
+
+ mcmd->cache_file = settings_->cache_file;
+ id_us_plus(&mcmd->cache_file->id);
+ mcmd->read_flag = import_params_.mesh_read_flag;
+
+ BLI_strncpy(mcmd->object_path, prim_.GetPath().GetString().c_str(), FILE_MAX);
+}
+
+void USDGeomReader::add_subdiv_modifier()
+{
+ ModifierData *md = BKE_modifier_new(eModifierType_Subsurf);
+ BLI_addtail(&object_->modifiers, md);
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_geom.h b/source/blender/io/usd/intern/usd_reader_geom.h
new file mode 100644
index 00000000000..99e22248f2b
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_geom.h
@@ -0,0 +1,52 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+#include "usd_reader_xform.h"
+
+struct Mesh;
+
+namespace blender::io::usd {
+
+class USDGeomReader : public USDXformReader {
+
+ public:
+ USDGeomReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : USDXformReader(prim, import_params, settings)
+ {
+ }
+
+ virtual Mesh *read_mesh(struct Mesh *existing_mesh,
+ double motionSampleTime,
+ int read_flag,
+ const char **err_str) = 0;
+
+ virtual bool topology_changed(Mesh * /* existing_mesh */, double /* motionSampleTime */)
+ {
+ return true;
+ }
+
+ void add_cache_modifier();
+ void add_subdiv_modifier();
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_instance.cc b/source/blender/io/usd/intern/usd_reader_instance.cc
new file mode 100644
index 00000000000..e645b0237b9
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_instance.cc
@@ -0,0 +1,64 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_instance.h"
+
+#include "BKE_object.h"
+#include "DNA_object_types.h"
+
+#include <iostream>
+
+namespace blender::io::usd {
+
+USDInstanceReader::USDInstanceReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : USDXformReader(prim, import_params, settings)
+{
+}
+
+bool USDInstanceReader::valid() const
+{
+ return prim_.IsValid() && prim_.IsInstance();
+}
+
+void USDInstanceReader::create_object(Main *bmain, const double /* motionSampleTime */)
+{
+ this->object_ = BKE_object_add_only_object(bmain, OB_EMPTY, name_.c_str());
+ this->object_->data = nullptr;
+ this->object_->transflag |= OB_DUPLICOLLECTION;
+}
+
+void USDInstanceReader::set_instance_collection(Collection *coll)
+{
+ if (this->object_) {
+ this->object_->instance_collection = coll;
+ }
+}
+
+pxr::SdfPath USDInstanceReader::proto_path() const
+{
+ if (pxr::UsdPrim master = prim_.GetMaster()) {
+ return master.GetPath();
+ }
+
+ return pxr::SdfPath();
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_instance.h b/source/blender/io/usd/intern/usd_reader_instance.h
new file mode 100644
index 00000000000..efc1c69a7dd
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_instance.h
@@ -0,0 +1,47 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd_reader_xform.h"
+
+#include <pxr/usd/usdGeom/xform.h>
+
+struct Collection;
+
+namespace blender::io::usd {
+
+/* Wraps the UsdGeomXform schema. Creates a Blender Empty object. */
+
+class USDInstanceReader : public USDXformReader {
+
+ public:
+ USDInstanceReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings);
+
+ bool valid() const override;
+
+ void create_object(Main *bmain, double motionSampleTime) override;
+
+ void set_instance_collection(Collection *coll);
+
+ pxr::SdfPath proto_path() const;
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_light.cc b/source/blender/io/usd/intern/usd_reader_light.cc
new file mode 100644
index 00000000000..fda0c17968a
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_light.cc
@@ -0,0 +1,252 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_light.h"
+
+#include "BKE_light.h"
+#include "BKE_object.h"
+
+#include "DNA_light_types.h"
+#include "DNA_object_types.h"
+
+#include <pxr/usd/usdLux/light.h>
+
+#include <pxr/usd/usdLux/diskLight.h>
+#include <pxr/usd/usdLux/distantLight.h>
+#include <pxr/usd/usdLux/rectLight.h>
+#include <pxr/usd/usdLux/shapingAPI.h>
+#include <pxr/usd/usdLux/sphereLight.h>
+
+#include <iostream>
+
+namespace blender::io::usd {
+
+void USDLightReader::create_object(Main *bmain, const double /* motionSampleTime */)
+{
+ Light *blight = static_cast<Light *>(BKE_light_add(bmain, name_.c_str()));
+
+ object_ = BKE_object_add_only_object(bmain, OB_LAMP, name_.c_str());
+ object_->data = blight;
+}
+
+void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime)
+{
+ Light *blight = (Light *)object_->data;
+
+ if (blight == nullptr) {
+ return;
+ }
+
+ if (!prim_) {
+ return;
+ }
+
+ pxr::UsdLuxLight light_prim(prim_);
+
+ if (!light_prim) {
+ return;
+ }
+
+ pxr::UsdLuxShapingAPI shaping_api(light_prim);
+
+ /* Set light type. */
+
+ if (prim_.IsA<pxr::UsdLuxDiskLight>()) {
+ blight->type = LA_AREA;
+ blight->area_shape = LA_AREA_DISK;
+ /* Ellipse lights are not currently supported */
+ }
+ else if (prim_.IsA<pxr::UsdLuxRectLight>()) {
+ blight->type = LA_AREA;
+ blight->area_shape = LA_AREA_RECT;
+ }
+ else if (prim_.IsA<pxr::UsdLuxSphereLight>()) {
+ blight->type = LA_LOCAL;
+
+ if (shaping_api && shaping_api.GetShapingConeAngleAttr().IsAuthored()) {
+ blight->type = LA_SPOT;
+ }
+ }
+ else if (prim_.IsA<pxr::UsdLuxDistantLight>()) {
+ blight->type = LA_SUN;
+ }
+
+ /* Set light values. */
+
+ if (pxr::UsdAttribute intensity_attr = light_prim.GetIntensityAttr()) {
+ float intensity = 0.0f;
+ if (intensity_attr.Get(&intensity, motionSampleTime)) {
+ blight->energy = intensity * this->import_params_.light_intensity_scale;
+ }
+ }
+
+ /* TODO(makowalsk): Not currently supported. */
+#if 0
+ pxr::VtValue exposure;
+ light_prim.GetExposureAttr().Get(&exposure, motionSampleTime);
+#endif
+
+ /* TODO(makowalsk): Not currently supported */
+#if 0
+ pxr::VtValue diffuse;
+ light_prim.GetDiffuseAttr().Get(&diffuse, motionSampleTime);
+#endif
+
+ if (pxr::UsdAttribute spec_attr = light_prim.GetSpecularAttr()) {
+ float spec = 0.0f;
+ if (spec_attr.Get(&spec, motionSampleTime)) {
+ blight->spec_fac = spec;
+ }
+ }
+
+ if (pxr::UsdAttribute color_attr = light_prim.GetColorAttr()) {
+ pxr::GfVec3f color;
+ if (color_attr.Get(&color, motionSampleTime)) {
+ blight->r = color[0];
+ blight->g = color[1];
+ blight->b = color[2];
+ }
+ }
+
+ /* TODO(makowalski): Not currently supported. */
+#if 0
+ pxr::VtValue use_color_temp;
+ light_prim.GetEnableColorTemperatureAttr().Get(&use_color_temp, motionSampleTime);
+#endif
+
+ /* TODO(makowalski): Not currently supported. */
+#if 0
+ pxr::VtValue color_temp;
+ light_prim.GetColorTemperatureAttr().Get(&color_temp, motionSampleTime);
+#endif
+
+ switch (blight->type) {
+ case LA_AREA:
+ if (blight->area_shape == LA_AREA_RECT && prim_.IsA<pxr::UsdLuxRectLight>()) {
+
+ pxr::UsdLuxRectLight rect_light(prim_);
+
+ if (!rect_light) {
+ break;
+ }
+
+ if (pxr::UsdAttribute width_attr = rect_light.GetWidthAttr()) {
+ float width = 0.0f;
+ if (width_attr.Get(&width, motionSampleTime)) {
+ blight->area_size = width;
+ }
+ }
+
+ if (pxr::UsdAttribute height_attr = rect_light.GetHeightAttr()) {
+ float height = 0.0f;
+ if (height_attr.Get(&height, motionSampleTime)) {
+ blight->area_sizey = height;
+ }
+ }
+ }
+ else if (blight->area_shape == LA_AREA_DISK && prim_.IsA<pxr::UsdLuxDiskLight>()) {
+
+ pxr::UsdLuxDiskLight disk_light(prim_);
+
+ if (!disk_light) {
+ break;
+ }
+
+ if (pxr::UsdAttribute radius_attr = disk_light.GetRadiusAttr()) {
+ float radius = 0.0f;
+ if (radius_attr.Get(&radius, motionSampleTime)) {
+ blight->area_size = radius * 2.0f;
+ }
+ }
+ }
+ break;
+ case LA_LOCAL:
+ if (prim_.IsA<pxr::UsdLuxSphereLight>()) {
+
+ pxr::UsdLuxSphereLight sphere_light(prim_);
+
+ if (!sphere_light) {
+ break;
+ }
+
+ if (pxr::UsdAttribute radius_attr = sphere_light.GetRadiusAttr()) {
+ float radius = 0.0f;
+ if (radius_attr.Get(&radius, motionSampleTime)) {
+ blight->area_size = radius;
+ }
+ }
+ }
+ break;
+ case LA_SPOT:
+ if (prim_.IsA<pxr::UsdLuxSphereLight>()) {
+
+ pxr::UsdLuxSphereLight sphere_light(prim_);
+
+ if (!sphere_light) {
+ break;
+ }
+
+ if (pxr::UsdAttribute radius_attr = sphere_light.GetRadiusAttr()) {
+ float radius = 0.0f;
+ if (radius_attr.Get(&radius, motionSampleTime)) {
+ blight->area_size = radius;
+ }
+ }
+
+ if (!shaping_api) {
+ break;
+ }
+
+ if (pxr::UsdAttribute cone_angle_attr = shaping_api.GetShapingConeAngleAttr()) {
+ float cone_angle = 0.0f;
+ if (cone_angle_attr.Get(&cone_angle, motionSampleTime)) {
+ blight->spotsize = cone_angle * ((float)M_PI / 180.0f) * 2.0f;
+ }
+ }
+
+ if (pxr::UsdAttribute cone_softness_attr = shaping_api.GetShapingConeSoftnessAttr()) {
+ float cone_softness = 0.0f;
+ if (cone_softness_attr.Get(&cone_softness, motionSampleTime)) {
+ blight->spotblend = cone_softness;
+ }
+ }
+ }
+ break;
+ case LA_SUN:
+ if (prim_.IsA<pxr::UsdLuxDistantLight>()) {
+ pxr::UsdLuxDistantLight distant_light(prim_);
+
+ if (!distant_light) {
+ break;
+ }
+
+ if (pxr::UsdAttribute angle_attr = distant_light.GetAngleAttr()) {
+ float angle = 0.0f;
+ if (angle_attr.Get(&angle, motionSampleTime)) {
+ blight->sun_angle = angle * (float)M_PI / 180.0f;
+ }
+ }
+ }
+ break;
+ }
+
+ USDXformReader::read_object_data(bmain, motionSampleTime);
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_light.h b/source/blender/io/usd/intern/usd_reader_light.h
new file mode 100644
index 00000000000..e7860fd2c80
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_light.h
@@ -0,0 +1,41 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+#include "usd_reader_xform.h"
+
+namespace blender::io::usd {
+
+class USDLightReader : public USDXformReader {
+
+ public:
+ USDLightReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : USDXformReader(prim, import_params, settings)
+ {
+ }
+
+ void create_object(Main *bmain, double motionSampleTime) override;
+
+ void read_object_data(Main *bmain, double motionSampleTime) override;
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc
new file mode 100644
index 00000000000..02ed7c35e57
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_material.cc
@@ -0,0 +1,703 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 NVIDIA Corporation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_material.h"
+
+#include "BKE_image.h"
+#include "BKE_main.h"
+#include "BKE_material.h"
+#include "BKE_node.h"
+
+#include "BLI_math_vector.h"
+#include "BLI_string.h"
+
+#include "DNA_material_types.h"
+
+#include <pxr/base/gf/vec3f.h>
+#include <pxr/usd/usdShade/material.h>
+#include <pxr/usd/usdShade/shader.h>
+
+#include <iostream>
+#include <vector>
+
+namespace usdtokens {
+
+/* Parameter names. */
+static const pxr::TfToken a("a", pxr::TfToken::Immortal);
+static const pxr::TfToken b("b", pxr::TfToken::Immortal);
+static const pxr::TfToken clearcoat("clearcoat", pxr::TfToken::Immortal);
+static const pxr::TfToken clearcoatRoughness("clearcoatRoughness", pxr::TfToken::Immortal);
+static const pxr::TfToken diffuseColor("diffuseColor", pxr::TfToken::Immortal);
+static const pxr::TfToken emissiveColor("emissiveColor", pxr::TfToken::Immortal);
+static const pxr::TfToken file("file", pxr::TfToken::Immortal);
+static const pxr::TfToken g("g", pxr::TfToken::Immortal);
+static const pxr::TfToken ior("ior", pxr::TfToken::Immortal);
+static const pxr::TfToken metallic("metallic", pxr::TfToken::Immortal);
+static const pxr::TfToken normal("normal", pxr::TfToken::Immortal);
+static const pxr::TfToken occlusion("occlusion", pxr::TfToken::Immortal);
+static const pxr::TfToken opacity("opacity", pxr::TfToken::Immortal);
+static const pxr::TfToken opacityThreshold("opacityThreshold", pxr::TfToken::Immortal);
+static const pxr::TfToken r("r", pxr::TfToken::Immortal);
+static const pxr::TfToken result("result", pxr::TfToken::Immortal);
+static const pxr::TfToken rgb("rgb", pxr::TfToken::Immortal);
+static const pxr::TfToken rgba("rgba", pxr::TfToken::Immortal);
+static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal);
+static const pxr::TfToken sourceColorSpace("sourceColorSpace", pxr::TfToken::Immortal);
+static const pxr::TfToken specularColor("specularColor", pxr::TfToken::Immortal);
+static const pxr::TfToken st("st", pxr::TfToken::Immortal);
+static const pxr::TfToken varname("varname", pxr::TfToken::Immortal);
+
+/* Color space names. */
+static const pxr::TfToken raw("raw", pxr::TfToken::Immortal);
+static const pxr::TfToken RAW("RAW", pxr::TfToken::Immortal);
+
+/* USD shader names. */
+static const pxr::TfToken UsdPreviewSurface("UsdPreviewSurface", pxr::TfToken::Immortal);
+static const pxr::TfToken UsdPrimvarReader_float2("UsdPrimvarReader_float2",
+ pxr::TfToken::Immortal);
+static const pxr::TfToken UsdUVTexture("UsdUVTexture", pxr::TfToken::Immortal);
+} // namespace usdtokens
+
+/* Add a node of the given type at the given location coordinates. */
+static bNode *add_node(
+ const bContext *C, bNodeTree *ntree, const int type, const float locx, const float locy)
+{
+ bNode *new_node = nodeAddStaticNode(C, ntree, type);
+
+ if (new_node) {
+ new_node->locx = locx;
+ new_node->locy = locy;
+ }
+
+ return new_node;
+}
+
+/* Connect the output socket of node 'source' to the input socket of node 'dest'. */
+static void link_nodes(
+ bNodeTree *ntree, bNode *source, const char *sock_out, bNode *dest, const char *sock_in)
+{
+ bNodeSocket *source_socket = nodeFindSocket(source, SOCK_OUT, sock_out);
+
+ if (!source_socket) {
+ std::cerr << "PROGRAMMER ERROR: Couldn't find output socket " << sock_out << std::endl;
+ return;
+ }
+
+ bNodeSocket *dest_socket = nodeFindSocket(dest, SOCK_IN, sock_in);
+
+ if (!dest_socket) {
+ std::cerr << "PROGRAMMER ERROR: Couldn't find input socket " << sock_in << std::endl;
+ return;
+ }
+
+ nodeAddLink(ntree, source, source_socket, dest, dest_socket);
+}
+
+/* Returns true if the given shader may have opacity < 1.0, based
+ * on heuristics. */
+static bool needs_blend(const pxr::UsdShadeShader &usd_shader)
+{
+ if (!usd_shader) {
+ return false;
+ }
+
+ bool needs_blend = false;
+
+ if (pxr::UsdShadeInput opacity_input = usd_shader.GetInput(usdtokens::opacity)) {
+
+ if (opacity_input.HasConnectedSource()) {
+ needs_blend = true;
+ }
+ else {
+ pxr::VtValue val;
+ if (opacity_input.GetAttr().HasAuthoredValue() && opacity_input.GetAttr().Get(&val)) {
+ float opacity = val.Get<float>();
+ needs_blend = opacity < 1.0f;
+ }
+ }
+ }
+
+ return needs_blend;
+}
+
+/* Returns the given shader's opacityThreshold input value, if this input has an
+ * authored value. Otherwise, returns the given default value. */
+static float get_opacity_threshold(const pxr::UsdShadeShader &usd_shader,
+ float default_value = 0.0f)
+{
+ if (!usd_shader) {
+ return default_value;
+ }
+
+ pxr::UsdShadeInput opacity_threshold_input = usd_shader.GetInput(usdtokens::opacityThreshold);
+
+ if (!opacity_threshold_input) {
+ return default_value;
+ }
+
+ pxr::VtValue val;
+ if (opacity_threshold_input.GetAttr().HasAuthoredValue() &&
+ opacity_threshold_input.GetAttr().Get(&val)) {
+ return val.Get<float>();
+ }
+
+ return default_value;
+}
+
+static pxr::TfToken get_source_color_space(const pxr::UsdShadeShader &usd_shader)
+{
+ if (!usd_shader) {
+ return pxr::TfToken();
+ }
+
+ pxr::UsdShadeInput color_space_input = usd_shader.GetInput(usdtokens::sourceColorSpace);
+
+ if (!color_space_input) {
+ return pxr::TfToken();
+ }
+
+ pxr::VtValue color_space_val;
+ if (color_space_input.Get(&color_space_val) && color_space_val.IsHolding<pxr::TfToken>()) {
+ return color_space_val.Get<pxr::TfToken>();
+ }
+
+ return pxr::TfToken();
+}
+
+/* Attempts to return in r_preview_surface the UsdPreviewSurface shader source
+ * of the given material. Returns true if a UsdPreviewSurface source was found
+ * and returns false otherwise. */
+static bool get_usd_preview_surface(const pxr::UsdShadeMaterial &usd_material,
+ pxr::UsdShadeShader &r_preview_surface)
+{
+ if (!usd_material) {
+ return false;
+ }
+
+ if (pxr::UsdShadeShader surf_shader = usd_material.ComputeSurfaceSource()) {
+ /* Check if we have a UsdPreviewSurface shader. */
+ pxr::TfToken shader_id;
+ if (surf_shader.GetShaderId(&shader_id) && shader_id == usdtokens::UsdPreviewSurface) {
+ r_preview_surface = surf_shader;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/* Set the Blender material's viewport display color, metallic and roughness
+ * properties from the given USD preview surface shader's inputs. */
+static void set_viewport_material_props(Material *mtl, const pxr::UsdShadeShader &usd_preview)
+{
+ if (!(mtl && usd_preview)) {
+ return;
+ }
+
+ if (pxr::UsdShadeInput diffuse_color_input = usd_preview.GetInput(usdtokens::diffuseColor)) {
+ pxr::VtValue val;
+ if (diffuse_color_input.GetAttr().HasAuthoredValue() &&
+ diffuse_color_input.GetAttr().Get(&val) && val.IsHolding<pxr::GfVec3f>()) {
+ pxr::GfVec3f color = val.UncheckedGet<pxr::GfVec3f>();
+ mtl->r = color[0];
+ mtl->g = color[1];
+ mtl->b = color[2];
+ }
+ }
+
+ if (pxr::UsdShadeInput metallic_input = usd_preview.GetInput(usdtokens::metallic)) {
+ pxr::VtValue val;
+ if (metallic_input.GetAttr().HasAuthoredValue() && metallic_input.GetAttr().Get(&val) &&
+ val.IsHolding<float>()) {
+ mtl->metallic = val.Get<float>();
+ }
+ }
+
+ if (pxr::UsdShadeInput roughness_input = usd_preview.GetInput(usdtokens::roughness)) {
+ pxr::VtValue val;
+ if (roughness_input.GetAttr().HasAuthoredValue() && roughness_input.GetAttr().Get(&val) &&
+ val.IsHolding<float>()) {
+ mtl->roughness = val.Get<float>();
+ }
+ }
+}
+
+namespace blender::io::usd {
+
+namespace {
+
+/* Compute the x- and y-coordinates for placing a new node in an unoccupied region of
+ * the column with the given index. Returns the coordinates in r_locx and r_locy and
+ * updates the column-occupancy information in r_ctx. */
+void compute_node_loc(const int column, float *r_locx, float *r_locy, NodePlacementContext *r_ctx)
+{
+ if (!(r_locx && r_locy && r_ctx)) {
+ return;
+ }
+
+ (*r_locx) = r_ctx->origx - column * r_ctx->horizontal_step;
+
+ if (column >= r_ctx->column_offsets.size()) {
+ r_ctx->column_offsets.push_back(0.0f);
+ }
+
+ (*r_locy) = r_ctx->origy - r_ctx->column_offsets[column];
+
+ /* Record the y-offset of the occupied region in
+ * the column, including padding. */
+ r_ctx->column_offsets[column] += r_ctx->vertical_step + 10.0f;
+}
+
+} // End anonymous namespace.
+
+USDMaterialReader::USDMaterialReader(const USDImportParams &params, Main *bmain)
+ : params_(params), bmain_(bmain)
+{
+}
+
+Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_material) const
+{
+ if (!(bmain_ && usd_material)) {
+ return nullptr;
+ }
+
+ std::string mtl_name = usd_material.GetPrim().GetName().GetString();
+
+ /* Create the material. */
+ Material *mtl = BKE_material_add(bmain_, mtl_name.c_str());
+
+ /* Get the UsdPreviewSurface shader source for the material,
+ * if there is one. */
+ pxr::UsdShadeShader usd_preview;
+ if (get_usd_preview_surface(usd_material, usd_preview)) {
+
+ set_viewport_material_props(mtl, usd_preview);
+
+ /* Optionally, create shader nodes to represent a UsdPreviewSurface. */
+ if (params_.import_usd_preview) {
+ import_usd_preview(mtl, usd_preview);
+ }
+ }
+
+ return mtl;
+}
+
+/* Create the Principled BSDF shader node network. */
+void USDMaterialReader::import_usd_preview(Material *mtl,
+ const pxr::UsdShadeShader &usd_shader) const
+{
+ if (!(bmain_ && mtl && usd_shader)) {
+ return;
+ }
+
+ /* Create the Material's node tree containing the principled BSDF
+ * and output shaders. */
+
+ /* Add the node tree. */
+ bNodeTree *ntree = ntreeAddTree(nullptr, "Shader Nodetree", "ShaderNodeTree");
+ mtl->nodetree = ntree;
+ mtl->use_nodes = true;
+
+ /* Create the Principled BSDF shader node. */
+ bNode *principled = add_node(nullptr, ntree, SH_NODE_BSDF_PRINCIPLED, 0.0f, 300.0f);
+
+ if (!principled) {
+ std::cerr << "ERROR: Couldn't create SH_NODE_BSDF_PRINCIPLED node for USD shader "
+ << usd_shader.GetPath() << std::endl;
+ return;
+ }
+
+ /* Create the material output node. */
+ bNode *output = add_node(nullptr, ntree, SH_NODE_OUTPUT_MATERIAL, 300.0f, 300.0f);
+
+ if (!output) {
+ std::cerr << "ERROR: Couldn't create SH_NODE_OUTPUT_MATERIAL node for USD shader "
+ << usd_shader.GetPath() << std::endl;
+ return;
+ }
+
+ /* Connect the Principled BSDF node to the output node. */
+ link_nodes(ntree, principled, "BSDF", output, "Surface");
+
+ /* Recursively create the principled shader input networks. */
+ set_principled_node_inputs(principled, ntree, usd_shader);
+
+ nodeSetActive(ntree, output);
+
+ ntreeUpdateTree(bmain_, ntree);
+
+ /* Optionally, set the material blend mode. */
+
+ if (params_.set_material_blend) {
+ if (needs_blend(usd_shader)) {
+ float opacity_threshold = get_opacity_threshold(usd_shader, 0.0f);
+ if (opacity_threshold > 0.0f) {
+ mtl->blend_method = MA_BM_CLIP;
+ mtl->alpha_threshold = opacity_threshold;
+ }
+ else {
+ mtl->blend_method = MA_BM_BLEND;
+ }
+ }
+ }
+}
+
+void USDMaterialReader::set_principled_node_inputs(bNode *principled,
+ bNodeTree *ntree,
+ const pxr::UsdShadeShader &usd_shader) const
+{
+ /* The context struct keeps track of the locations for adding
+ * input nodes. */
+ NodePlacementContext context(0.0f, 300.0);
+
+ /* The column index (from right to left relative to the principled
+ * node) where we're adding the nodes. */
+ int column = 0;
+
+ /* Recursively set the principled shader inputs. */
+
+ if (pxr::UsdShadeInput diffuse_input = usd_shader.GetInput(usdtokens::diffuseColor)) {
+ set_node_input(diffuse_input, principled, "Base Color", ntree, column, &context);
+ }
+
+ if (pxr::UsdShadeInput emissive_input = usd_shader.GetInput(usdtokens::emissiveColor)) {
+ set_node_input(emissive_input, principled, "Emission", ntree, column, &context);
+ }
+
+ if (pxr::UsdShadeInput specular_input = usd_shader.GetInput(usdtokens::specularColor)) {
+ set_node_input(specular_input, principled, "Specular", ntree, column, &context);
+ }
+
+ if (pxr::UsdShadeInput metallic_input = usd_shader.GetInput(usdtokens::metallic)) {
+ ;
+ set_node_input(metallic_input, principled, "Metallic", ntree, column, &context);
+ }
+
+ if (pxr::UsdShadeInput roughness_input = usd_shader.GetInput(usdtokens::roughness)) {
+ set_node_input(roughness_input, principled, "Roughness", ntree, column, &context);
+ }
+
+ if (pxr::UsdShadeInput clearcoat_input = usd_shader.GetInput(usdtokens::clearcoat)) {
+ set_node_input(clearcoat_input, principled, "Clearcoat", ntree, column, &context);
+ }
+
+ if (pxr::UsdShadeInput clearcoat_roughness_input = usd_shader.GetInput(
+ usdtokens::clearcoatRoughness)) {
+ set_node_input(
+ clearcoat_roughness_input, principled, "Clearcoat Roughness", ntree, column, &context);
+ }
+
+ if (pxr::UsdShadeInput opacity_input = usd_shader.GetInput(usdtokens::opacity)) {
+ set_node_input(opacity_input, principled, "Alpha", ntree, column, &context);
+ }
+
+ if (pxr::UsdShadeInput ior_input = usd_shader.GetInput(usdtokens::ior)) {
+ set_node_input(ior_input, principled, "IOR", ntree, column, &context);
+ }
+
+ if (pxr::UsdShadeInput normal_input = usd_shader.GetInput(usdtokens::normal)) {
+ set_node_input(normal_input, principled, "Normal", ntree, column, &context);
+ }
+}
+
+/* Convert the given USD shader input to an input on the given Blender node. */
+void USDMaterialReader::set_node_input(const pxr::UsdShadeInput &usd_input,
+ bNode *dest_node,
+ const char *dest_socket_name,
+ bNodeTree *ntree,
+ const int column,
+ NodePlacementContext *r_ctx) const
+{
+ if (!(usd_input && dest_node && r_ctx)) {
+ return;
+ }
+
+ if (usd_input.HasConnectedSource()) {
+ /* The USD shader input has a connected source shader. Follow the connection
+ * and attempt to convert the connected USD shader to a Blender node. */
+ follow_connection(usd_input, dest_node, dest_socket_name, ntree, column, r_ctx);
+ }
+ else {
+ /* Set the destination node socket value from the USD shader input value. */
+
+ bNodeSocket *sock = nodeFindSocket(dest_node, SOCK_IN, dest_socket_name);
+ if (!sock) {
+ std::cerr << "ERROR: couldn't get destination node socket " << dest_socket_name << std::endl;
+ return;
+ }
+
+ pxr::VtValue val;
+ if (!usd_input.Get(&val)) {
+ std::cerr << "ERROR: couldn't get value for usd shader input "
+ << usd_input.GetPrim().GetPath() << std::endl;
+ return;
+ }
+
+ switch (sock->type) {
+ case SOCK_FLOAT:
+ if (val.IsHolding<float>()) {
+ ((bNodeSocketValueFloat *)sock->default_value)->value = val.UncheckedGet<float>();
+ }
+ else if (val.IsHolding<pxr::GfVec3f>()) {
+ pxr::GfVec3f v3f = val.UncheckedGet<pxr::GfVec3f>();
+ float average = (v3f[0] + v3f[1] + v3f[2]) / 3.0f;
+ ((bNodeSocketValueFloat *)sock->default_value)->value = average;
+ }
+ break;
+ case SOCK_RGBA:
+ if (val.IsHolding<pxr::GfVec3f>()) {
+ pxr::GfVec3f v3f = val.UncheckedGet<pxr::GfVec3f>();
+ copy_v3_v3(((bNodeSocketValueRGBA *)sock->default_value)->value, v3f.data());
+ }
+ break;
+ case SOCK_VECTOR:
+ if (val.IsHolding<pxr::GfVec3f>()) {
+ pxr::GfVec3f v3f = val.UncheckedGet<pxr::GfVec3f>();
+ copy_v3_v3(((bNodeSocketValueVector *)sock->default_value)->value, v3f.data());
+ }
+ else if (val.IsHolding<pxr::GfVec2f>()) {
+ pxr::GfVec2f v2f = val.UncheckedGet<pxr::GfVec2f>();
+ copy_v2_v2(((bNodeSocketValueVector *)sock->default_value)->value, v2f.data());
+ }
+ break;
+ default:
+ std::cerr << "WARNING: unexpected type " << sock->idname << " for destination node socket "
+ << dest_socket_name << std::endl;
+ break;
+ }
+ }
+}
+
+/* Follow the connected source of the USD input to create corresponding inputs
+ * for the given Blender node. */
+void USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input,
+ bNode *dest_node,
+ const char *dest_socket_name,
+ bNodeTree *ntree,
+ int column,
+ NodePlacementContext *r_ctx) const
+{
+ if (!(usd_input && dest_node && dest_socket_name && ntree && r_ctx)) {
+ return;
+ }
+
+ pxr::UsdShadeConnectableAPI source;
+ pxr::TfToken source_name;
+ pxr::UsdShadeAttributeType source_type;
+
+ usd_input.GetConnectedSource(&source, &source_name, &source_type);
+
+ if (!(source && source.GetPrim().IsA<pxr::UsdShadeShader>())) {
+ return;
+ }
+
+ pxr::UsdShadeShader source_shader(source.GetPrim());
+
+ if (!source_shader) {
+ return;
+ }
+
+ pxr::TfToken shader_id;
+ if (!source_shader.GetShaderId(&shader_id)) {
+ std::cerr << "ERROR: couldn't get shader id for source shader "
+ << source_shader.GetPrim().GetPath() << std::endl;
+ return;
+ }
+
+ /* For now, only convert UsdUVTexture and UsdPrimvarReader_float2 inputs. */
+ if (shader_id == usdtokens::UsdUVTexture) {
+
+ if (strcmp(dest_socket_name, "Normal") == 0) {
+
+ /* The normal texture input requires creating a normal map node. */
+ float locx = 0.0f;
+ float locy = 0.0f;
+ compute_node_loc(column + 1, &locx, &locy, r_ctx);
+
+ bNode *normal_map = add_node(nullptr, ntree, SH_NODE_NORMAL_MAP, locx, locy);
+
+ /* Currently, the Normal Map node has Tangent Space as the default,
+ * which is what we need, so we don't need to explicitly set it. */
+
+ /* Connect the Normal Map to the Normal input. */
+ link_nodes(ntree, normal_map, "Normal", dest_node, "Normal");
+
+ /* Now, create the Texture Image node input to the Normal Map "Color" input. */
+ convert_usd_uv_texture(
+ source_shader, source_name, normal_map, "Color", ntree, column + 2, r_ctx);
+ }
+ else {
+ convert_usd_uv_texture(
+ source_shader, source_name, dest_node, dest_socket_name, ntree, column + 1, r_ctx);
+ }
+ }
+ else if (shader_id == usdtokens::UsdPrimvarReader_float2) {
+ convert_usd_primvar_reader_float2(
+ source_shader, source_name, dest_node, dest_socket_name, ntree, column + 1, r_ctx);
+ }
+}
+
+void USDMaterialReader::convert_usd_uv_texture(const pxr::UsdShadeShader &usd_shader,
+ const pxr::TfToken &usd_source_name,
+ bNode *dest_node,
+ const char *dest_socket_name,
+ bNodeTree *ntree,
+ const int column,
+ NodePlacementContext *r_ctx) const
+{
+ if (!usd_shader || !dest_node || !ntree || !dest_socket_name || !bmain_ || !r_ctx) {
+ return;
+ }
+
+ float locx = 0.0f;
+ float locy = 0.0f;
+ compute_node_loc(column, &locx, &locy, r_ctx);
+
+ /* Create the Texture Image node. */
+ bNode *tex_image = add_node(nullptr, ntree, SH_NODE_TEX_IMAGE, locx, locy);
+
+ if (!tex_image) {
+ std::cerr << "ERROR: Couldn't create SH_NODE_TEX_IMAGE for node input " << dest_socket_name
+ << std::endl;
+ return;
+ }
+
+ /* Load the texture image. */
+ load_tex_image(usd_shader, tex_image);
+
+ /* Connect to destination node input. */
+
+ /* Get the source socket name. */
+ std::string source_socket_name = usd_source_name == usdtokens::a ? "Alpha" : "Color";
+
+ link_nodes(ntree, tex_image, source_socket_name.c_str(), dest_node, dest_socket_name);
+
+ /* Connect the texture image node "Vector" input. */
+ if (pxr::UsdShadeInput st_input = usd_shader.GetInput(usdtokens::st)) {
+ set_node_input(st_input, tex_image, "Vector", ntree, column, r_ctx);
+ }
+}
+
+/* Load the texture image node's texture from the path given by the USD shader's
+ * file input value. */
+void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader &usd_shader,
+ bNode *tex_image) const
+{
+ if (!(usd_shader && tex_image && tex_image->type == SH_NODE_TEX_IMAGE)) {
+ return;
+ }
+
+ /* Try to load the texture image. */
+ pxr::UsdShadeInput file_input = usd_shader.GetInput(usdtokens::file);
+
+ if (!file_input) {
+ std::cerr << "WARNING: Couldn't get file input for USD shader " << usd_shader.GetPath()
+ << std::endl;
+ return;
+ }
+
+ pxr::VtValue file_val;
+ if (!file_input.Get(&file_val) || !file_val.IsHolding<pxr::SdfAssetPath>()) {
+ std::cerr << "WARNING: Couldn't get file input value for USD shader " << usd_shader.GetPath()
+ << std::endl;
+ return;
+ }
+
+ const pxr::SdfAssetPath &asset_path = file_val.Get<pxr::SdfAssetPath>();
+ std::string file_path = asset_path.GetResolvedPath();
+ if (file_path.empty()) {
+ std::cerr << "WARNING: Couldn't resolve image asset '" << asset_path
+ << "' for Texture Image node." << std::endl;
+ return;
+ }
+
+ const char *im_file = file_path.c_str();
+ Image *image = BKE_image_load_exists(bmain_, im_file);
+ if (!image) {
+ std::cerr << "WARNING: Couldn't open image file '" << im_file << "' for Texture Image node."
+ << std::endl;
+ return;
+ }
+
+ tex_image->id = &image->id;
+
+ /* Set texture color space.
+ * TODO(makowalski): For now, just checking for RAW color space,
+ * assuming sRGB otherwise, but more complex logic might be
+ * required if the color space is "auto". */
+
+ pxr::TfToken color_space = get_source_color_space(usd_shader);
+
+ if (color_space.IsEmpty()) {
+ color_space = file_input.GetAttr().GetColorSpace();
+ }
+
+ if (color_space == usdtokens::RAW || color_space == usdtokens::raw) {
+ STRNCPY(image->colorspace_settings.name, "Raw");
+ }
+}
+
+/* This function creates a Blender UV Map node, under the simplifying assumption that
+ * UsdPrimvarReader_float2 shaders output UV coordinates.
+ * TODO(makowalski): investigate supporting conversion to other Blender node types
+ * (e.g., Attribute Nodes) if needed. */
+void USDMaterialReader::convert_usd_primvar_reader_float2(
+ const pxr::UsdShadeShader &usd_shader,
+ const pxr::TfToken & /* usd_source_name */,
+ bNode *dest_node,
+ const char *dest_socket_name,
+ bNodeTree *ntree,
+ const int column,
+ NodePlacementContext *r_ctx) const
+{
+ if (!usd_shader || !dest_node || !ntree || !dest_socket_name || !bmain_ || !r_ctx) {
+ return;
+ }
+
+ float locx = 0.0f;
+ float locy = 0.0f;
+ compute_node_loc(column, &locx, &locy, r_ctx);
+
+ /* Create the UV Map node. */
+ bNode *uv_map = add_node(nullptr, ntree, SH_NODE_UVMAP, locx, locy);
+
+ if (!uv_map) {
+ std::cerr << "ERROR: Couldn't create SH_NODE_UVMAP for node input " << dest_socket_name
+ << std::endl;
+ return;
+ }
+
+ /* Set the texmap name. */
+ pxr::UsdShadeInput varname_input = usd_shader.GetInput(usdtokens::varname);
+ if (varname_input) {
+ pxr::VtValue varname_val;
+ if (varname_input.Get(&varname_val) && varname_val.IsHolding<pxr::TfToken>()) {
+ std::string varname = varname_val.Get<pxr::TfToken>().GetString();
+ if (!varname.empty()) {
+ NodeShaderUVMap *storage = (NodeShaderUVMap *)uv_map->storage;
+ BLI_strncpy(storage->uv_map, varname.c_str(), sizeof(storage->uv_map));
+ }
+ }
+ }
+
+ /* Connect to destination node input. */
+ link_nodes(ntree, uv_map, "UV", dest_node, dest_socket_name);
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_material.h b/source/blender/io/usd/intern/usd_reader_material.h
new file mode 100644
index 00000000000..3e8fc675931
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_material.h
@@ -0,0 +1,131 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 NVIDIA Corporation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+
+#include <pxr/usd/usdShade/material.h>
+
+struct Main;
+struct Material;
+struct bNode;
+struct bNodeTree;
+
+namespace blender::io::usd {
+
+/* Helper struct used when arranging nodes in columns, keeping track the
+ * occupancy information for a given column. I.e., for column n,
+ * column_offsets[n] is the y-offset (from top to bottom) of the occupied
+ * region in that column. */
+struct NodePlacementContext {
+ float origx;
+ float origy;
+ std::vector<float> column_offsets;
+ const float horizontal_step;
+ const float vertical_step;
+
+ NodePlacementContext(float in_origx,
+ float in_origy,
+ float in_horizontal_step = 300.0f,
+ float in_vertical_step = 300.0f)
+ : origx(in_origx),
+ origy(in_origy),
+ column_offsets(64, 0.0f),
+ horizontal_step(in_horizontal_step),
+ vertical_step(in_vertical_step)
+ {
+ }
+};
+
+/* Converts USD materials to Blender representation. */
+
+/* By default, the USDMaterialReader creates a Blender material with
+ * the same name as the USD material. If the USD material has a
+ * UsdPreviewSurface source, the Blender material's viewport display
+ * color, roughness and metallic properties are set to the corresponding
+ * UsdPreoviewSurface inputs.
+ *
+ * If the Import USD Preview option is enabled, the current implementation
+ * converts UsdPreviewSurface to Blender nodes as follows:
+ *
+ * UsdPreviewSurface -> Pricipled BSDF
+ * UsdUVTexture -> Texture Image + Normal Map
+ * UsdPrimvarReader_float2 -> UV Map
+ *
+ * Limitations: arbitrary primvar readers or UsdTransform2d not yet
+ * supported. For UsdUVTexture, only the file, st and sourceColorSpace
+ * inputs are handled.
+ *
+ * TODO(makowalski): Investigate adding support for converting additional
+ * shaders and inputs. Supporting certain types of inputs, such as texture
+ * scale and bias, will probably require creating Blender Group nodes with
+ * the corresponding inputs. */
+
+class USDMaterialReader {
+ protected:
+ USDImportParams params_;
+
+ Main *bmain_;
+
+ public:
+ USDMaterialReader(const USDImportParams &params, Main *bmain);
+
+ Material *add_material(const pxr::UsdShadeMaterial &usd_material) const;
+
+ protected:
+ void import_usd_preview(Material *mtl, const pxr::UsdShadeShader &usd_shader) const;
+
+ void set_principled_node_inputs(bNode *principled_node,
+ bNodeTree *ntree,
+ const pxr::UsdShadeShader &usd_shader) const;
+
+ void set_node_input(const pxr::UsdShadeInput &usd_input,
+ bNode *dest_node,
+ const char *dest_socket_name,
+ bNodeTree *ntree,
+ int column,
+ NodePlacementContext *r_ctx) const;
+
+ void follow_connection(const pxr::UsdShadeInput &usd_input,
+ bNode *dest_node,
+ const char *dest_socket_name,
+ bNodeTree *ntree,
+ int column,
+ NodePlacementContext *r_ctx) const;
+
+ void convert_usd_uv_texture(const pxr::UsdShadeShader &usd_shader,
+ const pxr::TfToken &usd_source_name,
+ bNode *dest_node,
+ const char *dest_socket_name,
+ bNodeTree *ntree,
+ int column,
+ NodePlacementContext *r_ctx) const;
+
+ void load_tex_image(const pxr::UsdShadeShader &usd_shader, bNode *tex_image) const;
+
+ void convert_usd_primvar_reader_float2(const pxr::UsdShadeShader &usd_shader,
+ const pxr::TfToken &usd_source_name,
+ bNode *dest_node,
+ const char *dest_socket_name,
+ bNodeTree *ntree,
+ int column,
+ NodePlacementContext *r_ctx) const;
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc
new file mode 100644
index 00000000000..f13da4680e2
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -0,0 +1,853 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation and
+ * NVIDIA Corporation. All rights reserved.
+ */
+
+#include "usd_reader_mesh.h"
+#include "usd_reader_material.h"
+
+#include "BKE_customdata.h"
+#include "BKE_main.h"
+#include "BKE_material.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+
+#include "BLI_math.h"
+#include "BLI_math_geom.h"
+#include "BLI_string.h"
+
+#include "DNA_customdata_types.h"
+#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include <pxr/base/vt/array.h>
+#include <pxr/base/vt/types.h>
+#include <pxr/base/vt/value.h>
+#include <pxr/usd/sdf/types.h>
+#include <pxr/usd/usdGeom/mesh.h>
+#include <pxr/usd/usdGeom/subset.h>
+#include <pxr/usd/usdShade/materialBindingAPI.h>
+
+#include <iostream>
+
+namespace usdtokens {
+/* Materials */
+static const pxr::TfToken st("st", pxr::TfToken::Immortal);
+static const pxr::TfToken UVMap("UVMap", pxr::TfToken::Immortal);
+static const pxr::TfToken Cd("Cd", pxr::TfToken::Immortal);
+static const pxr::TfToken displayColor("displayColor", pxr::TfToken::Immortal);
+static const pxr::TfToken normalsPrimvar("normals", pxr::TfToken::Immortal);
+} // namespace usdtokens
+
+namespace utils {
+/* Very similar to abc mesh utils. */
+static void build_mat_map(const Main *bmain, std::map<std::string, Material *> *r_mat_map)
+{
+ if (r_mat_map == nullptr) {
+ return;
+ }
+
+ Material *material = static_cast<Material *>(bmain->materials.first);
+
+ for (; material; material = static_cast<Material *>(material->id.next)) {
+ /* We have to do this because the stored material name is coming directly from usd. */
+ (*r_mat_map)[pxr::TfMakeValidIdentifier(material->id.name + 2)] = material;
+ }
+}
+
+static void assign_materials(Main *bmain,
+ Object *ob,
+ const std::map<pxr::SdfPath, int> &mat_index_map,
+ const USDImportParams &params,
+ pxr::UsdStageRefPtr stage)
+{
+ if (!(stage && bmain && ob)) {
+ return;
+ }
+
+ bool can_assign = true;
+ std::map<pxr::SdfPath, int>::const_iterator it = mat_index_map.begin();
+
+ int matcount = 0;
+ for (; it != mat_index_map.end(); ++it, matcount++) {
+ if (!BKE_object_material_slot_add(bmain, ob)) {
+ can_assign = false;
+ break;
+ }
+ }
+
+ if (!can_assign) {
+ return;
+ }
+
+ /* TODO(kevin): use global map? */
+ std::map<std::string, Material *> mat_map;
+ build_mat_map(bmain, &mat_map);
+
+ blender::io::usd::USDMaterialReader mat_reader(params, bmain);
+
+ for (it = mat_index_map.begin(); it != mat_index_map.end(); ++it) {
+ std::string mat_name = it->first.GetName();
+
+ std::map<std::string, Material *>::iterator mat_iter = mat_map.find(mat_name);
+
+ Material *assigned_mat = nullptr;
+
+ if (mat_iter == mat_map.end()) {
+ /* Blender material doesn't exist, so create it now. */
+
+ /* Look up the USD material. */
+ pxr::UsdPrim prim = stage->GetPrimAtPath(it->first);
+ pxr::UsdShadeMaterial usd_mat(prim);
+
+ if (!usd_mat) {
+ std::cout << "WARNING: Couldn't construct USD material from prim " << it->first
+ << std::endl;
+ continue;
+ }
+
+ /* Add the Blender material. */
+ assigned_mat = mat_reader.add_material(usd_mat);
+
+ if (!assigned_mat) {
+ std::cout << "WARNING: Couldn't create Blender material from USD material " << it->first
+ << std::endl;
+ continue;
+ }
+
+ mat_map[mat_name] = assigned_mat;
+ }
+ else {
+ /* We found an existing Blender material. */
+ assigned_mat = mat_iter->second;
+ }
+
+ if (assigned_mat) {
+ BKE_object_material_assign(bmain, ob, assigned_mat, it->second, BKE_MAT_ASSIGN_OBDATA);
+ }
+ else {
+ /* This shouldn't happen. */
+ std::cout << "WARNING: Couldn't assign material " << mat_name << std::endl;
+ }
+ }
+}
+
+} // namespace utils
+
+static void *add_customdata_cb(Mesh *mesh, const char *name, const int data_type)
+{
+ CustomDataType cd_data_type = static_cast<CustomDataType>(data_type);
+ void *cd_ptr;
+ CustomData *loopdata;
+ int numloops;
+
+ /* unsupported custom data type -- don't do anything. */
+ if (!ELEM(cd_data_type, CD_MLOOPUV, CD_MLOOPCOL)) {
+ return nullptr;
+ }
+
+ loopdata = &mesh->ldata;
+ cd_ptr = CustomData_get_layer_named(loopdata, cd_data_type, name);
+ if (cd_ptr != nullptr) {
+ /* layer already exists, so just return it. */
+ return cd_ptr;
+ }
+
+ /* Create a new layer. */
+ numloops = mesh->totloop;
+ cd_ptr = CustomData_add_layer_named(loopdata, cd_data_type, CD_DEFAULT, nullptr, numloops, name);
+ return cd_ptr;
+}
+
+namespace blender::io::usd {
+
+USDMeshReader::USDMeshReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : USDGeomReader(prim, import_params, settings),
+ mesh_prim_(prim),
+ is_left_handed_(false),
+ has_uvs_(false),
+ is_time_varying_(false),
+ is_initial_load_(false)
+{
+}
+
+void USDMeshReader::create_object(Main *bmain, const double /* motionSampleTime */)
+{
+ Mesh *mesh = BKE_mesh_add(bmain, name_.c_str());
+
+ object_ = BKE_object_add_only_object(bmain, OB_MESH, name_.c_str());
+ object_->data = mesh;
+}
+
+void USDMeshReader::read_object_data(Main *bmain, const double motionSampleTime)
+{
+ Mesh *mesh = (Mesh *)object_->data;
+
+ is_initial_load_ = true;
+ Mesh *read_mesh = this->read_mesh(
+ mesh, motionSampleTime, import_params_.mesh_read_flag, nullptr);
+
+ is_initial_load_ = false;
+ if (read_mesh != mesh) {
+ /* XXX fixme after 2.80; mesh->flag isn't copied by BKE_mesh_nomain_to_mesh() */
+ /* read_mesh can be freed by BKE_mesh_nomain_to_mesh(), so get the flag before that happens. */
+ short autosmooth = (read_mesh->flag & ME_AUTOSMOOTH);
+ BKE_mesh_nomain_to_mesh(read_mesh, mesh, object_, &CD_MASK_MESH, true);
+ mesh->flag |= autosmooth;
+ }
+
+ readFaceSetsSample(bmain, mesh, motionSampleTime);
+
+ if (mesh_prim_.GetPointsAttr().ValueMightBeTimeVarying()) {
+ is_time_varying_ = true;
+ }
+
+ if (is_time_varying_) {
+ add_cache_modifier();
+ }
+
+ if (import_params_.import_subdiv) {
+ pxr::TfToken subdivScheme;
+ mesh_prim_.GetSubdivisionSchemeAttr().Get(&subdivScheme, motionSampleTime);
+
+ if (subdivScheme == pxr::UsdGeomTokens->catmullClark) {
+ add_subdiv_modifier();
+ }
+ }
+
+ USDXformReader::read_object_data(bmain, motionSampleTime);
+}
+
+bool USDMeshReader::valid() const
+{
+ return static_cast<bool>(mesh_prim_);
+}
+
+bool USDMeshReader::topology_changed(Mesh *existing_mesh, const double motionSampleTime)
+{
+ /* TODO(makowalski): Is it the best strategy to cache the mesh
+ * geometry in this function? This needs to be revisited. */
+
+ mesh_prim_.GetFaceVertexIndicesAttr().Get(&face_indices_, motionSampleTime);
+ mesh_prim_.GetFaceVertexCountsAttr().Get(&face_counts_, motionSampleTime);
+ mesh_prim_.GetPointsAttr().Get(&positions_, motionSampleTime);
+
+ /* TODO(makowalski): Reading normals probably doesn't belong in this function,
+ * as this is not required to determine if the topology has changed. */
+
+ /* If 'normals' and 'primvars:normals' are both specified, the latter has precedence. */
+ pxr::UsdGeomPrimvar primvar = mesh_prim_.GetPrimvar(usdtokens::normalsPrimvar);
+ if (primvar.HasValue()) {
+ primvar.ComputeFlattened(&normals_, motionSampleTime);
+ normal_interpolation_ = primvar.GetInterpolation();
+ }
+ else {
+ mesh_prim_.GetNormalsAttr().Get(&normals_, motionSampleTime);
+ normal_interpolation_ = mesh_prim_.GetNormalsInterpolation();
+ }
+
+ return positions_.size() != existing_mesh->totvert ||
+ face_counts_.size() != existing_mesh->totpoly ||
+ face_indices_.size() != existing_mesh->totloop;
+}
+
+void USDMeshReader::read_mpolys(Mesh *mesh)
+{
+ MPoly *mpolys = mesh->mpoly;
+ MLoop *mloops = mesh->mloop;
+
+ int loop_index = 0;
+
+ for (int i = 0; i < face_counts_.size(); i++) {
+ const int face_size = face_counts_[i];
+
+ MPoly &poly = mpolys[i];
+ poly.loopstart = loop_index;
+ poly.totloop = face_size;
+ poly.mat_nr = 0;
+
+ /* Polygons are always assumed to be smooth-shaded. If the mesh should be flat-shaded,
+ * this is encoded in custom loop normals. */
+ poly.flag |= ME_SMOOTH;
+
+ if (is_left_handed_) {
+ int loop_end_index = loop_index + (face_size - 1);
+ for (int f = 0; f < face_size; ++f, ++loop_index) {
+ mloops[loop_index].v = face_indices_[loop_end_index - f];
+ }
+ }
+ else {
+ for (int f = 0; f < face_size; ++f, ++loop_index) {
+ mloops[loop_index].v = face_indices_[loop_index];
+ }
+ }
+ }
+
+ BKE_mesh_calc_edges(mesh, false, false);
+}
+
+void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bool load_uvs)
+{
+ unsigned int loop_index = 0;
+ unsigned int rev_loop_index = 0;
+ unsigned int uv_index = 0;
+
+ const CustomData *ldata = &mesh->ldata;
+
+ struct UVSample {
+ pxr::VtVec2fArray uvs;
+ pxr::TfToken interpolation;
+ };
+
+ std::vector<UVSample> uv_primvars(ldata->totlayer);
+
+ if (has_uvs_) {
+ for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) {
+ const CustomDataLayer *layer = &ldata->layers[layer_idx];
+ std::string layer_name = std::string(layer->name);
+ if (layer->type != CD_MLOOPUV) {
+ continue;
+ }
+
+ pxr::TfToken uv_token;
+
+ /* If first time seeing uv token, store in map of <layer->uid, TfToken> */
+ if (uv_token_map_.find(layer_name) == uv_token_map_.end()) {
+ uv_token = pxr::TfToken(layer_name);
+ uv_token_map_.insert(std::make_pair(layer_name, uv_token));
+ }
+ else {
+ uv_token = uv_token_map_.at(layer_name);
+ }
+
+ /* Early out if no token found, this should never happen */
+ if (uv_token.IsEmpty()) {
+ continue;
+ }
+ /* Early out if not first load and uvs arent animated. */
+ if (!load_uvs && primvar_varying_map_.find(uv_token) != primvar_varying_map_.end() &&
+ !primvar_varying_map_.at(uv_token)) {
+ continue;
+ }
+
+ /* Early out if mesh doesn't have primvar. */
+ if (!mesh_prim_.HasPrimvar(uv_token)) {
+ continue;
+ }
+
+ if (pxr::UsdGeomPrimvar uv_primvar = mesh_prim_.GetPrimvar(uv_token)) {
+ uv_primvar.ComputeFlattened(&uv_primvars[layer_idx].uvs, motionSampleTime);
+ uv_primvars[layer_idx].interpolation = uv_primvar.GetInterpolation();
+ }
+ }
+ }
+
+ for (int i = 0; i < face_counts_.size(); i++) {
+ const int face_size = face_counts_[i];
+
+ rev_loop_index = loop_index + (face_size - 1);
+
+ for (int f = 0; f < face_size; f++, loop_index++, rev_loop_index--) {
+
+ for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) {
+ const CustomDataLayer *layer = &ldata->layers[layer_idx];
+ if (layer->type != CD_MLOOPUV) {
+ continue;
+ }
+
+ /* Early out if mismatched layer sizes. */
+ if (layer_idx > uv_primvars.size()) {
+ continue;
+ }
+
+ /* Early out if no uvs loaded. */
+ if (uv_primvars[layer_idx].uvs.empty()) {
+ continue;
+ }
+
+ const UVSample &sample = uv_primvars[layer_idx];
+
+ if (!(sample.interpolation == pxr::UsdGeomTokens->faceVarying ||
+ sample.interpolation == pxr::UsdGeomTokens->vertex)) {
+ std::cerr << "WARNING: unexpected interpolation type " << sample.interpolation
+ << " for uv " << layer->name << std::endl;
+ continue;
+ }
+
+ /* For Vertex interpolation, use the vertex index. */
+ int usd_uv_index = sample.interpolation == pxr::UsdGeomTokens->vertex ?
+ mesh->mloop[loop_index].v :
+ loop_index;
+
+ if (usd_uv_index >= sample.uvs.size()) {
+ std::cerr << "WARNING: out of bounds uv index " << usd_uv_index << " for uv "
+ << layer->name << " of size " << sample.uvs.size() << std::endl;
+ continue;
+ }
+
+ MLoopUV *mloopuv = static_cast<MLoopUV *>(layer->data);
+ if (is_left_handed_) {
+ uv_index = rev_loop_index;
+ }
+ else {
+ uv_index = loop_index;
+ }
+ mloopuv[uv_index].uv[0] = sample.uvs[usd_uv_index][0];
+ mloopuv[uv_index].uv[1] = sample.uvs[usd_uv_index][1];
+ }
+ }
+ }
+}
+
+void USDMeshReader::read_colors(Mesh *mesh, const double motionSampleTime)
+{
+ if (!(mesh && mesh_prim_ && mesh->totloop > 0)) {
+ return;
+ }
+
+ /* Early out if we read the display color before and if this attribute isn't animated. */
+ if (primvar_varying_map_.find(usdtokens::displayColor) != primvar_varying_map_.end() &&
+ !primvar_varying_map_.at(usdtokens::displayColor)) {
+ return;
+ }
+
+ pxr::UsdGeomPrimvar color_primvar = mesh_prim_.GetDisplayColorPrimvar();
+
+ if (!color_primvar.HasValue()) {
+ return;
+ }
+
+ pxr::TfToken interp = color_primvar.GetInterpolation();
+
+ if (interp == pxr::UsdGeomTokens->varying) {
+ std::cerr << "WARNING: Unsupported varying interpolation for display colors\n" << std::endl;
+ return;
+ }
+
+ if (primvar_varying_map_.find(usdtokens::displayColor) == primvar_varying_map_.end()) {
+ bool might_be_time_varying = color_primvar.ValueMightBeTimeVarying();
+ primvar_varying_map_.insert(std::make_pair(usdtokens::displayColor, might_be_time_varying));
+ if (might_be_time_varying) {
+ is_time_varying_ = true;
+ }
+ }
+
+ pxr::VtArray<pxr::GfVec3f> display_colors;
+
+ if (!color_primvar.ComputeFlattened(&display_colors, motionSampleTime)) {
+ std::cerr << "WARNING: Couldn't compute display colors\n" << std::endl;
+ return;
+ }
+
+ if ((interp == pxr::UsdGeomTokens->faceVarying && display_colors.size() != mesh->totloop) ||
+ (interp == pxr::UsdGeomTokens->vertex && display_colors.size() != mesh->totvert) ||
+ (interp == pxr::UsdGeomTokens->constant && display_colors.size() != 1) ||
+ (interp == pxr::UsdGeomTokens->uniform && display_colors.size() != mesh->totpoly)) {
+ std::cerr << "WARNING: display colors count mismatch\n" << std::endl;
+ return;
+ }
+
+ void *cd_ptr = add_customdata_cb(mesh, "displayColors", CD_MLOOPCOL);
+
+ if (!cd_ptr) {
+ std::cerr << "WARNING: Couldn't add displayColors custom data.\n";
+ return;
+ }
+
+ MLoopCol *colors = static_cast<MLoopCol *>(cd_ptr);
+
+ mesh->mloopcol = colors;
+
+ MPoly *poly = mesh->mpoly;
+
+ for (int i = 0, e = mesh->totpoly; i < e; ++i, ++poly) {
+ for (int j = 0; j < poly->totloop; ++j) {
+ int loop_index = poly->loopstart + j;
+
+ /* Default for constant varying interpolation. */
+ int usd_index = 0;
+
+ if (interp == pxr::UsdGeomTokens->vertex) {
+ usd_index = mesh->mloop[loop_index].v;
+ }
+ else if (interp == pxr::UsdGeomTokens->faceVarying) {
+ usd_index = poly->loopstart;
+ if (is_left_handed_) {
+ usd_index += poly->totloop - 1 - j;
+ }
+ else {
+ usd_index += j;
+ }
+ }
+ else if (interp == pxr::UsdGeomTokens->uniform) {
+ /* Uniform varying uses the poly index. */
+ usd_index = i;
+ }
+
+ if (usd_index >= display_colors.size()) {
+ continue;
+ }
+
+ colors[loop_index].r = unit_float_to_uchar_clamp(display_colors[usd_index][0]);
+ colors[loop_index].g = unit_float_to_uchar_clamp(display_colors[usd_index][1]);
+ colors[loop_index].b = unit_float_to_uchar_clamp(display_colors[usd_index][2]);
+ colors[loop_index].a = unit_float_to_uchar_clamp(1.0);
+ }
+ }
+}
+
+void USDMeshReader::process_normals_vertex_varying(Mesh *mesh)
+{
+ if (!mesh) {
+ return;
+ }
+
+ if (normals_.empty()) {
+ BKE_mesh_calc_normals(mesh);
+ return;
+ }
+
+ if (normals_.size() != mesh->totvert) {
+ std::cerr << "WARNING: vertex varying normals count mismatch for mesh " << prim_path_
+ << std::endl;
+ BKE_mesh_calc_normals(mesh);
+ return;
+ }
+
+ for (int i = 0; i < normals_.size(); i++) {
+ MVert &mvert = mesh->mvert[i];
+ normal_float_to_short_v3(mvert.no, normals_[i].data());
+ }
+}
+
+void USDMeshReader::process_normals_face_varying(Mesh *mesh)
+{
+ if (normals_.empty()) {
+ BKE_mesh_calc_normals(mesh);
+ return;
+ }
+
+ /* Check for normals count mismatches to prevent crashes. */
+ if (normals_.size() != mesh->totloop) {
+ std::cerr << "WARNING: loop normal count mismatch for mesh " << mesh->id.name << std::endl;
+ BKE_mesh_calc_normals(mesh);
+ return;
+ }
+
+ mesh->flag |= ME_AUTOSMOOTH;
+
+ long int loop_count = normals_.size();
+
+ float(*lnors)[3] = static_cast<float(*)[3]>(
+ MEM_malloc_arrayN(loop_count, sizeof(float[3]), "USD::FaceNormals"));
+
+ MPoly *mpoly = mesh->mpoly;
+
+ for (int i = 0, e = mesh->totpoly; i < e; ++i, ++mpoly) {
+ for (int j = 0; j < mpoly->totloop; j++) {
+ int blender_index = mpoly->loopstart + j;
+
+ int usd_index = mpoly->loopstart;
+ if (is_left_handed_) {
+ usd_index += mpoly->totloop - 1 - j;
+ }
+ else {
+ usd_index += j;
+ }
+
+ lnors[blender_index][0] = normals_[usd_index][0];
+ lnors[blender_index][1] = normals_[usd_index][1];
+ lnors[blender_index][2] = normals_[usd_index][2];
+ }
+ }
+ BKE_mesh_set_custom_normals(mesh, lnors);
+
+ MEM_freeN(lnors);
+}
+
+/* Set USD uniform (per-face) normals as Blender loop normals. */
+void USDMeshReader::process_normals_uniform(Mesh *mesh)
+{
+ if (normals_.empty()) {
+ BKE_mesh_calc_normals(mesh);
+ return;
+ }
+
+ /* Check for normals count mismatches to prevent crashes. */
+ if (normals_.size() != mesh->totpoly) {
+ std::cerr << "WARNING: uniform normal count mismatch for mesh " << mesh->id.name << std::endl;
+ BKE_mesh_calc_normals(mesh);
+ return;
+ }
+
+ float(*lnors)[3] = static_cast<float(*)[3]>(
+ MEM_malloc_arrayN(mesh->totloop, sizeof(float[3]), "USD::FaceNormals"));
+
+ MPoly *mpoly = mesh->mpoly;
+
+ for (int i = 0, e = mesh->totpoly; i < e; ++i, ++mpoly) {
+
+ for (int j = 0; j < mpoly->totloop; j++) {
+ int loop_index = mpoly->loopstart + j;
+ lnors[loop_index][0] = normals_[i][0];
+ lnors[loop_index][1] = normals_[i][1];
+ lnors[loop_index][2] = normals_[i][2];
+ }
+ }
+
+ mesh->flag |= ME_AUTOSMOOTH;
+ BKE_mesh_set_custom_normals(mesh, lnors);
+
+ MEM_freeN(lnors);
+}
+
+void USDMeshReader::read_mesh_sample(ImportSettings *settings,
+ Mesh *mesh,
+ const double motionSampleTime,
+ const bool new_mesh)
+{
+ /* Note that for new meshes we always want to read verts and polys,
+ * regradless of the value of the read_flag, to avoid a crash downstream
+ * in code that expect this data to be there. */
+
+ if (new_mesh || (settings->read_flag & MOD_MESHSEQ_READ_VERT) != 0) {
+ for (int i = 0; i < positions_.size(); i++) {
+ MVert &mvert = mesh->mvert[i];
+ mvert.co[0] = positions_[i][0];
+ mvert.co[1] = positions_[i][1];
+ mvert.co[2] = positions_[i][2];
+ }
+ }
+
+ if (new_mesh || (settings->read_flag & MOD_MESHSEQ_READ_POLY) != 0) {
+ read_mpolys(mesh);
+ if (normal_interpolation_ == pxr::UsdGeomTokens->faceVarying) {
+ process_normals_face_varying(mesh);
+ }
+ else if (normal_interpolation_ == pxr::UsdGeomTokens->uniform) {
+ process_normals_uniform(mesh);
+ }
+ else {
+ /* Default */
+ BKE_mesh_calc_normals(mesh);
+ }
+ }
+
+ /* Process point normals after reading polys. This
+ * is important in the case where the normals are empty
+ * and we invoke BKE_mesh_calc_normals(mesh), which requires
+ * edges to be defined. */
+ if ((settings->read_flag & MOD_MESHSEQ_READ_VERT) != 0 &&
+ normal_interpolation_ == pxr::UsdGeomTokens->vertex) {
+ process_normals_vertex_varying(mesh);
+ }
+
+ if ((settings->read_flag & MOD_MESHSEQ_READ_UV) != 0) {
+ read_uvs(mesh, motionSampleTime, new_mesh);
+ }
+
+ if ((settings->read_flag & MOD_MESHSEQ_READ_COLOR) != 0) {
+ read_colors(mesh, motionSampleTime);
+ }
+}
+
+void USDMeshReader::assign_facesets_to_mpoly(double motionSampleTime,
+ MPoly *mpoly,
+ const int /* totpoly */,
+ std::map<pxr::SdfPath, int> *r_mat_map)
+{
+ if (r_mat_map == nullptr) {
+ return;
+ }
+
+ /* Find the geom subsets that have bound materials.
+ * We don't call pxr::UsdShadeMaterialBindingAPI::GetMaterialBindSubsets()
+ * because this function returns only those subsets that are in the 'materialBind'
+ * family, but, in practice, applications (like Houdini) might export subsets
+ * in different families that are bound to materials.
+ * TODO(makowalski): Reassess if the above is the best approach. */
+ const std::vector<pxr::UsdGeomSubset> subsets = pxr::UsdGeomSubset::GetAllGeomSubsets(
+ mesh_prim_);
+
+ int current_mat = 0;
+ if (!subsets.empty()) {
+ for (const pxr::UsdGeomSubset &subset : subsets) {
+ pxr::UsdShadeMaterialBindingAPI subset_api = pxr::UsdShadeMaterialBindingAPI(
+ subset.GetPrim());
+
+ pxr::UsdShadeMaterial subset_mtl = subset_api.ComputeBoundMaterial();
+
+ if (!subset_mtl) {
+ continue;
+ }
+
+ pxr::SdfPath subset_mtl_path = subset_mtl.GetPath();
+
+ if (subset_mtl_path.IsEmpty()) {
+ continue;
+ }
+
+ if (r_mat_map->find(subset_mtl_path) == r_mat_map->end()) {
+ (*r_mat_map)[subset_mtl_path] = 1 + current_mat++;
+ }
+
+ const int mat_idx = (*r_mat_map)[subset_mtl_path] - 1;
+
+ pxr::UsdAttribute indicesAttribute = subset.GetIndicesAttr();
+ pxr::VtIntArray indices;
+ indicesAttribute.Get(&indices, motionSampleTime);
+
+ for (int i = 0; i < indices.size(); i++) {
+ MPoly &poly = mpoly[indices[i]];
+ poly.mat_nr = mat_idx;
+ }
+ }
+ }
+
+ if (r_mat_map->empty()) {
+ pxr::UsdShadeMaterialBindingAPI api = pxr::UsdShadeMaterialBindingAPI(prim_);
+
+ if (pxr::UsdShadeMaterial mtl = api.ComputeBoundMaterial()) {
+
+ pxr::SdfPath mtl_path = mtl.GetPath();
+
+ if (!mtl_path.IsEmpty()) {
+ r_mat_map->insert(std::make_pair(mtl.GetPath(), 1));
+ }
+ }
+ }
+}
+
+void USDMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const double motionSampleTime)
+{
+ if (!import_params_.import_materials) {
+ return;
+ }
+
+ std::map<pxr::SdfPath, int> mat_map;
+ assign_facesets_to_mpoly(motionSampleTime, mesh->mpoly, mesh->totpoly, &mat_map);
+ utils::assign_materials(bmain, object_, mat_map, this->import_params_, this->prim_.GetStage());
+}
+
+Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh,
+ const double motionSampleTime,
+ const int read_flag,
+ const char ** /* err_str */)
+{
+ if (!mesh_prim_) {
+ return existing_mesh;
+ }
+
+ mesh_prim_.GetOrientationAttr().Get(&orientation_);
+ if (orientation_ == pxr::UsdGeomTokens->leftHanded) {
+ is_left_handed_ = true;
+ }
+
+ std::vector<pxr::TfToken> uv_tokens;
+
+ /* Currently we only handle UV primvars. */
+ if (read_flag & MOD_MESHSEQ_READ_UV) {
+
+ std::vector<pxr::UsdGeomPrimvar> primvars = mesh_prim_.GetPrimvars();
+
+ for (pxr::UsdGeomPrimvar p : primvars) {
+
+ pxr::TfToken name = p.GetPrimvarName();
+ pxr::SdfValueTypeName type = p.GetTypeName();
+
+ bool is_uv = false;
+
+ /* Assume all uvs are stored in one of these primvar types */
+ if (type == pxr::SdfValueTypeNames->TexCoord2hArray ||
+ type == pxr::SdfValueTypeNames->TexCoord2fArray ||
+ type == pxr::SdfValueTypeNames->TexCoord2dArray) {
+ is_uv = true;
+ }
+ /* In some cases, the st primvar is stored as float2 values. */
+ else if (name == usdtokens::st && type == pxr::SdfValueTypeNames->Float2Array) {
+ is_uv = true;
+ }
+
+ if (is_uv) {
+
+ pxr::TfToken interp = p.GetInterpolation();
+
+ if (!(interp == pxr::UsdGeomTokens->faceVarying || interp == pxr::UsdGeomTokens->vertex)) {
+ continue;
+ }
+
+ uv_tokens.push_back(p.GetBaseName());
+ has_uvs_ = true;
+
+ /* Record whether the UVs might be time varying. */
+ if (primvar_varying_map_.find(name) == primvar_varying_map_.end()) {
+ bool might_be_time_varying = p.ValueMightBeTimeVarying();
+ primvar_varying_map_.insert(std::make_pair(name, might_be_time_varying));
+ if (might_be_time_varying) {
+ is_time_varying_ = true;
+ }
+ }
+ }
+ }
+ }
+
+ Mesh *active_mesh = existing_mesh;
+ bool new_mesh = false;
+
+ /* TODO(makowalski): inmplement the optimization of only updating the mesh points when
+ * the topology is consistent, as in the Alembic importer. */
+
+ ImportSettings settings;
+ settings.read_flag |= read_flag;
+
+ if (topology_changed(existing_mesh, motionSampleTime)) {
+ new_mesh = true;
+ active_mesh = BKE_mesh_new_nomain_from_template(
+ existing_mesh, positions_.size(), 0, 0, face_indices_.size(), face_counts_.size());
+
+ for (pxr::TfToken token : uv_tokens) {
+ void *cd_ptr = add_customdata_cb(active_mesh, token.GetText(), CD_MLOOPUV);
+ active_mesh->mloopuv = static_cast<MLoopUV *>(cd_ptr);
+ }
+ }
+
+ read_mesh_sample(&settings, active_mesh, motionSampleTime, new_mesh || is_initial_load_);
+
+ if (new_mesh) {
+ /* Here we assume that the number of materials doesn't change, i.e. that
+ * the material slots that were created when the object was loaded from
+ * USD are still valid now. */
+ size_t num_polys = active_mesh->totpoly;
+ if (num_polys > 0 && import_params_.import_materials) {
+ std::map<pxr::SdfPath, int> mat_map;
+ assign_facesets_to_mpoly(motionSampleTime, active_mesh->mpoly, num_polys, &mat_map);
+ }
+ }
+
+ return active_mesh;
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_mesh.h b/source/blender/io/usd/intern/usd_reader_mesh.h
new file mode 100644
index 00000000000..54ad144d191
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_mesh.h
@@ -0,0 +1,95 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation and
+ * NVIDIA Corporation. All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+#include "usd_reader_geom.h"
+
+#include "pxr/usd/usdGeom/mesh.h"
+
+struct MPoly;
+
+namespace blender::io::usd {
+
+class USDMeshReader : public USDGeomReader {
+ private:
+ pxr::UsdGeomMesh mesh_prim_;
+
+ std::unordered_map<std::string, pxr::TfToken> uv_token_map_;
+ std::map<const pxr::TfToken, bool> primvar_varying_map_;
+
+ /* TODO(makowalski): Is it the best strategy to cache the
+ * mesh geometry in the following members? It appears these
+ * arrays are never cleared, so this might bloat memory. */
+ pxr::VtIntArray face_indices_;
+ pxr::VtIntArray face_counts_;
+ pxr::VtVec3fArray positions_;
+ pxr::VtVec3fArray normals_;
+
+ pxr::TfToken normal_interpolation_;
+ pxr::TfToken orientation_;
+ bool is_left_handed_;
+ bool has_uvs_;
+ bool is_time_varying_;
+
+ /* This is to ensure we load all data once, because we reuse the read_mesh function
+ * in the mesh seq modifier, and in initial load. Ideally, a better fix would be
+ * implemented. Note this will break if faces or positions vary. */
+ bool is_initial_load_;
+
+ public:
+ USDMeshReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings);
+
+ bool valid() const override;
+
+ void create_object(Main *bmain, double motionSampleTime) override;
+ void read_object_data(Main *bmain, double motionSampleTime) override;
+
+ struct Mesh *read_mesh(struct Mesh *existing_mesh,
+ double motionSampleTime,
+ int read_flag,
+ const char **err_str) override;
+
+ bool topology_changed(Mesh *existing_mesh, double motionSampleTime) override;
+
+ private:
+ void process_normals_vertex_varying(Mesh *mesh);
+ void process_normals_face_varying(Mesh *mesh);
+ void process_normals_uniform(Mesh *mesh);
+ void readFaceSetsSample(Main *bmain, Mesh *mesh, double motionSampleTime);
+ void assign_facesets_to_mpoly(double motionSampleTime,
+ struct MPoly *mpoly,
+ int totpoly,
+ std::map<pxr::SdfPath, int> *r_mat_map);
+
+ void read_mpolys(Mesh *mesh);
+ void read_uvs(Mesh *mesh, double motionSampleTime, bool load_uvs = false);
+ void read_colors(Mesh *mesh, double motionSampleTime);
+
+ void read_mesh_sample(ImportSettings *settings,
+ Mesh *mesh,
+ double motionSampleTime,
+ bool new_mesh);
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_nurbs.cc b/source/blender/io/usd/intern/usd_reader_nurbs.cc
new file mode 100644
index 00000000000..9b30b524729
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_nurbs.cc
@@ -0,0 +1,256 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_nurbs.h"
+
+#include "BKE_curve.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+
+#include "BLI_listbase.h"
+
+#include "DNA_curve_types.h"
+#include "DNA_object_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include <pxr/base/vt/array.h>
+#include <pxr/base/vt/types.h>
+#include <pxr/base/vt/value.h>
+#include <pxr/usd/sdf/types.h>
+
+#include <pxr/usd/usdGeom/curves.h>
+
+static bool set_knots(const pxr::VtDoubleArray &knots, float *&nu_knots)
+{
+ if (knots.empty()) {
+ return false;
+ }
+
+ /* Skip first and last knots, as they are used for padding. */
+ const size_t num_knots = knots.size();
+ nu_knots = static_cast<float *>(MEM_callocN(num_knots * sizeof(float), __func__));
+
+ for (size_t i = 0; i < num_knots; i++) {
+ nu_knots[i] = (float)knots[i];
+ }
+
+ return true;
+}
+
+namespace blender::io::usd {
+
+void USDNurbsReader::create_object(Main *bmain, const double /* motionSampleTime */)
+{
+ curve_ = BKE_curve_add(bmain, name_.c_str(), OB_CURVE);
+
+ curve_->flag |= CU_DEFORM_FILL | CU_3D;
+ curve_->actvert = CU_ACT_NONE;
+ curve_->resolu = 2;
+
+ object_ = BKE_object_add_only_object(bmain, OB_CURVE, name_.c_str());
+ object_->data = curve_;
+}
+
+void USDNurbsReader::read_object_data(Main *bmain, const double motionSampleTime)
+{
+ Curve *cu = (Curve *)object_->data;
+ read_curve_sample(cu, motionSampleTime);
+
+ if (curve_prim_.GetPointsAttr().ValueMightBeTimeVarying()) {
+ add_cache_modifier();
+ }
+
+ USDXformReader::read_object_data(bmain, motionSampleTime);
+}
+
+void USDNurbsReader::read_curve_sample(Curve *cu, const double motionSampleTime)
+{
+ curve_prim_ = pxr::UsdGeomNurbsCurves(prim_);
+
+ pxr::UsdAttribute widthsAttr = curve_prim_.GetWidthsAttr();
+ pxr::UsdAttribute vertexAttr = curve_prim_.GetCurveVertexCountsAttr();
+ pxr::UsdAttribute pointsAttr = curve_prim_.GetPointsAttr();
+
+ pxr::VtIntArray usdCounts;
+ vertexAttr.Get(&usdCounts, motionSampleTime);
+
+ pxr::VtVec3fArray usdPoints;
+ pointsAttr.Get(&usdPoints, motionSampleTime);
+
+ pxr::VtFloatArray usdWidths;
+ widthsAttr.Get(&usdWidths, motionSampleTime);
+
+ pxr::VtIntArray orders;
+ curve_prim_.GetOrderAttr().Get(&orders, motionSampleTime);
+
+ pxr::VtDoubleArray knots;
+ curve_prim_.GetKnotsAttr().Get(&knots, motionSampleTime);
+
+ pxr::VtVec3fArray usdNormals;
+ curve_prim_.GetNormalsAttr().Get(&usdNormals, motionSampleTime);
+
+ /* If normals, extrude, else bevel.
+ * Perhaps to be replaced by Blender USD Schema. */
+ if (!usdNormals.empty()) {
+ /* Set extrusion to 1. */
+ curve_->ext1 = 1.0f;
+ }
+ else {
+ /* Set bevel depth to 1. */
+ curve_->ext2 = 1.0f;
+ }
+
+ size_t idx = 0;
+ for (size_t i = 0; i < usdCounts.size(); i++) {
+ const int num_verts = usdCounts[i];
+
+ Nurb *nu = static_cast<Nurb *>(MEM_callocN(sizeof(Nurb), __func__));
+ nu->flag = CU_SMOOTH;
+ nu->type = CU_NURBS;
+
+ nu->resolu = cu->resolu;
+ nu->resolv = cu->resolv;
+
+ nu->pntsu = num_verts;
+ nu->pntsv = 1;
+
+ if (i < orders.size()) {
+ nu->orderu = static_cast<short>(orders[i]);
+ }
+ else {
+ nu->orderu = 4;
+ nu->orderv = 4;
+ }
+
+ /* TODO(makowalski): investigate setting Cyclic U and Endpoint U options. */
+#if 0
+ if (knots.size() > 3) {
+ if ((knots[0] == knots[1]) && (knots[knots.size()] == knots[knots.size() - 1])) {
+ nu->flagu |= CU_NURB_ENDPOINT;
+ } else {
+ nu->flagu |= CU_NURB_CYCLIC;
+ }
+ }
+#endif
+
+ float weight = 1.0f;
+
+ nu->bp = static_cast<BPoint *>(MEM_callocN(sizeof(BPoint) * nu->pntsu, __func__));
+ BPoint *bp = nu->bp;
+
+ for (int j = 0; j < nu->pntsu; j++, bp++, idx++) {
+ bp->vec[0] = (float)usdPoints[idx][0];
+ bp->vec[1] = (float)usdPoints[idx][1];
+ bp->vec[2] = (float)usdPoints[idx][2];
+ bp->vec[3] = weight;
+ bp->f1 = SELECT;
+ bp->weight = weight;
+
+ float radius = 0.1f;
+ if (idx < usdWidths.size()) {
+ radius = usdWidths[idx];
+ }
+
+ bp->radius = radius;
+ }
+
+ if (!set_knots(knots, nu->knotsu)) {
+ BKE_nurb_knot_calc_u(nu);
+ }
+
+ BLI_addtail(BKE_curve_nurbs_get(cu), nu);
+ }
+}
+
+Mesh *USDNurbsReader::read_mesh(struct Mesh * /* existing_mesh */,
+ const double motionSampleTime,
+ const int /* read_flag */,
+ const char ** /* err_str */)
+{
+ pxr::UsdGeomCurves curve_prim_(prim_);
+
+ pxr::UsdAttribute widthsAttr = curve_prim_.GetWidthsAttr();
+ pxr::UsdAttribute vertexAttr = curve_prim_.GetCurveVertexCountsAttr();
+ pxr::UsdAttribute pointsAttr = curve_prim_.GetPointsAttr();
+
+ pxr::VtIntArray usdCounts;
+
+ vertexAttr.Get(&usdCounts, motionSampleTime);
+ int num_subcurves = usdCounts.size();
+
+ pxr::VtVec3fArray usdPoints;
+ pointsAttr.Get(&usdPoints, motionSampleTime);
+
+ int vertex_idx = 0;
+ int curve_idx;
+ Curve *curve = static_cast<Curve *>(object_->data);
+
+ const int curve_count = BLI_listbase_count(&curve->nurb);
+ bool same_topology = curve_count == num_subcurves;
+
+ if (same_topology) {
+ Nurb *nurbs = static_cast<Nurb *>(curve->nurb.first);
+ for (curve_idx = 0; nurbs; nurbs = nurbs->next, curve_idx++) {
+ const int num_in_usd = usdCounts[curve_idx];
+ const int num_in_blender = nurbs->pntsu;
+
+ if (num_in_usd != num_in_blender) {
+ same_topology = false;
+ break;
+ }
+ }
+ }
+
+ if (!same_topology) {
+ BKE_nurbList_free(&curve->nurb);
+ read_curve_sample(curve, motionSampleTime);
+ }
+ else {
+ Nurb *nurbs = static_cast<Nurb *>(curve->nurb.first);
+ for (curve_idx = 0; nurbs; nurbs = nurbs->next, curve_idx++) {
+ const int totpoint = usdCounts[curve_idx];
+
+ if (nurbs->bp) {
+ BPoint *point = nurbs->bp;
+
+ for (int i = 0; i < totpoint; i++, point++, vertex_idx++) {
+ point->vec[0] = usdPoints[vertex_idx][0];
+ point->vec[1] = usdPoints[vertex_idx][1];
+ point->vec[2] = usdPoints[vertex_idx][2];
+ }
+ }
+ else if (nurbs->bezt) {
+ BezTriple *bezier = nurbs->bezt;
+
+ for (int i = 0; i < totpoint; i++, bezier++, vertex_idx++) {
+ bezier->vec[1][0] = usdPoints[vertex_idx][0];
+ bezier->vec[1][1] = usdPoints[vertex_idx][1];
+ bezier->vec[1][2] = usdPoints[vertex_idx][2];
+ }
+ }
+ }
+ }
+
+ return BKE_mesh_new_nomain_from_curve(object_);
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_nurbs.h b/source/blender/io/usd/intern/usd_reader_nurbs.h
new file mode 100644
index 00000000000..33a4acf503e
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_nurbs.h
@@ -0,0 +1,61 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+#include "usd_reader_geom.h"
+
+#include "pxr/usd/usdGeom/nurbsCurves.h"
+
+struct Curve;
+
+namespace blender::io::usd {
+
+class USDNurbsReader : public USDGeomReader {
+ protected:
+ pxr::UsdGeomNurbsCurves curve_prim_;
+ Curve *curve_;
+
+ public:
+ USDNurbsReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : USDGeomReader(prim, import_params, settings), curve_prim_(prim), curve_(nullptr)
+ {
+ }
+
+ bool valid() const override
+ {
+ return static_cast<bool>(curve_prim_);
+ }
+
+ void create_object(Main *bmain, double motionSampleTime) override;
+ void read_object_data(Main *bmain, double motionSampleTime) override;
+
+ void read_curve_sample(Curve *cu, double motionSampleTime);
+
+ Mesh *read_mesh(struct Mesh *existing_mesh,
+ double motionSampleTime,
+ int read_flag,
+ const char **err_str) override;
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_prim.cc b/source/blender/io/usd/intern/usd_reader_prim.cc
new file mode 100644
index 00000000000..abd70f49f23
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_prim.cc
@@ -0,0 +1,80 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_prim.h"
+
+#include "BLI_utildefines.h"
+
+namespace blender::io::usd {
+
+USDPrimReader::USDPrimReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : name_(prim.GetName().GetString()),
+ prim_path_(prim.GetPrimPath().GetString()),
+ object_(nullptr),
+ prim_(prim),
+ import_params_(import_params),
+ parent_reader_(nullptr),
+ settings_(&settings),
+ refcount_(0)
+{
+}
+
+USDPrimReader::~USDPrimReader() = default;
+
+const pxr::UsdPrim &USDPrimReader::prim() const
+{
+ return prim_;
+}
+
+Object *USDPrimReader::object() const
+{
+ return object_;
+}
+
+void USDPrimReader::object(Object *ob)
+{
+ object_ = ob;
+}
+
+bool USDPrimReader::valid() const
+{
+ return prim_.IsValid();
+}
+
+int USDPrimReader::refcount() const
+{
+ return refcount_;
+}
+
+void USDPrimReader::incref()
+{
+ refcount_++;
+}
+
+void USDPrimReader::decref()
+{
+ refcount_--;
+ BLI_assert(refcount_ >= 0);
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_prim.h b/source/blender/io/usd/intern/usd_reader_prim.h
new file mode 100644
index 00000000000..5aff52f011f
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_prim.h
@@ -0,0 +1,131 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+
+#include <pxr/usd/usd/prim.h>
+
+struct Main;
+struct Object;
+
+namespace blender::io::usd {
+
+struct ImportSettings {
+ bool do_convert_mat;
+ float conversion_mat[4][4];
+
+ int from_up;
+ int from_forward;
+ float scale;
+ bool is_sequence;
+ bool set_frame_range;
+
+ /* Length and frame offset of file sequences. */
+ int sequence_len;
+ int sequence_offset;
+
+ /* From MeshSeqCacheModifierData.read_flag */
+ int read_flag;
+
+ bool validate_meshes;
+
+ CacheFile *cache_file;
+
+ ImportSettings()
+ : do_convert_mat(false),
+ from_up(0),
+ from_forward(0),
+ scale(1.0f),
+ is_sequence(false),
+ set_frame_range(false),
+ sequence_len(1),
+ sequence_offset(0),
+ read_flag(0),
+ validate_meshes(false),
+ cache_file(NULL)
+ {
+ }
+};
+
+/* Most generic USD Reader. */
+
+class USDPrimReader {
+
+ protected:
+ std::string name_;
+ std::string prim_path_;
+ Object *object_;
+ pxr::UsdPrim prim_;
+ const USDImportParams &import_params_;
+ USDPrimReader *parent_reader_;
+ const ImportSettings *settings_;
+ int refcount_;
+
+ public:
+ USDPrimReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings);
+ virtual ~USDPrimReader();
+
+ const pxr::UsdPrim &prim() const;
+
+ virtual bool valid() const;
+
+ virtual void create_object(Main *bmain, double motionSampleTime) = 0;
+ virtual void read_object_data(Main * /* bmain */, double /* motionSampleTime */){};
+
+ Object *object() const;
+ void object(Object *ob);
+
+ USDPrimReader *parent() const
+ {
+ return parent_reader_;
+ }
+ void parent(USDPrimReader *parent)
+ {
+ parent_reader_ = parent;
+ }
+
+ /* Since readers might be referenced through handles
+ * maintained by modifiers and constraints, we provide
+ * a reference count to facilitate managing the object
+ * lifetime.
+ * TODO(makowalski): investigate transitioning to using
+ * smart pointers for readers, or, alternatively look into
+ * making the lifetime management more robust, e.g., by
+ * making the destructors protected and implementing deletion
+ * in decref(), etc. */
+ int refcount() const;
+ void incref();
+ void decref();
+
+ const std::string &name() const
+ {
+ return name_;
+ }
+ const std::string &prim_path() const
+ {
+ return prim_path_;
+ }
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc
new file mode 100644
index 00000000000..d3693f783ec
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_stage.cc
@@ -0,0 +1,324 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Tangent Animation and
+ * NVIDIA Corporation. All rights reserved.
+ */
+
+#include "usd_reader_stage.h"
+#include "usd_reader_camera.h"
+#include "usd_reader_curve.h"
+#include "usd_reader_instance.h"
+#include "usd_reader_light.h"
+#include "usd_reader_mesh.h"
+#include "usd_reader_nurbs.h"
+#include "usd_reader_prim.h"
+#include "usd_reader_volume.h"
+#include "usd_reader_xform.h"
+
+#include <pxr/pxr.h>
+#include <pxr/usd/usdGeom/camera.h>
+#include <pxr/usd/usdGeom/curves.h>
+#include <pxr/usd/usdGeom/mesh.h>
+#include <pxr/usd/usdGeom/nurbsCurves.h>
+#include <pxr/usd/usdGeom/scope.h>
+#include <pxr/usd/usdLux/light.h>
+
+#include <iostream>
+
+namespace blender::io::usd {
+
+USDStageReader::USDStageReader(pxr::UsdStageRefPtr stage,
+ const USDImportParams &params,
+ const ImportSettings &settings)
+ : stage_(stage), params_(params), settings_(settings)
+{
+}
+
+USDStageReader::~USDStageReader()
+{
+ clear_readers();
+}
+
+bool USDStageReader::valid() const
+{
+ return stage_;
+}
+
+USDPrimReader *USDStageReader::create_reader_if_allowed(const pxr::UsdPrim &prim)
+{
+ if (params_.import_cameras && prim.IsA<pxr::UsdGeomCamera>()) {
+ return new USDCameraReader(prim, params_, settings_);
+ }
+ if (params_.import_curves && prim.IsA<pxr::UsdGeomBasisCurves>()) {
+ return new USDCurvesReader(prim, params_, settings_);
+ }
+ if (params_.import_curves && prim.IsA<pxr::UsdGeomNurbsCurves>()) {
+ return new USDNurbsReader(prim, params_, settings_);
+ }
+ if (params_.import_meshes && prim.IsA<pxr::UsdGeomMesh>()) {
+ return new USDMeshReader(prim, params_, settings_);
+ }
+ if (params_.import_lights && prim.IsA<pxr::UsdLuxLight>()) {
+ return new USDLightReader(prim, params_, settings_);
+ }
+ if (params_.import_volumes && prim.IsA<pxr::UsdVolVolume>()) {
+ return new USDVolumeReader(prim, params_, settings_);
+ }
+ if (prim.IsA<pxr::UsdGeomImageable>()) {
+ return new USDXformReader(prim, params_, settings_);
+ }
+
+ return nullptr;
+}
+
+USDPrimReader *USDStageReader::create_reader(const pxr::UsdPrim &prim)
+{
+ if (prim.IsA<pxr::UsdGeomCamera>()) {
+ return new USDCameraReader(prim, params_, settings_);
+ }
+ if (prim.IsA<pxr::UsdGeomBasisCurves>()) {
+ return new USDCurvesReader(prim, params_, settings_);
+ }
+ if (prim.IsA<pxr::UsdGeomNurbsCurves>()) {
+ return new USDNurbsReader(prim, params_, settings_);
+ }
+ if (prim.IsA<pxr::UsdGeomMesh>()) {
+ return new USDMeshReader(prim, params_, settings_);
+ }
+ if (prim.IsA<pxr::UsdLuxLight>()) {
+ return new USDLightReader(prim, params_, settings_);
+ }
+ if (prim.IsA<pxr::UsdVolVolume>()) {
+ return new USDVolumeReader(prim, params_, settings_);
+ }
+ if (prim.IsA<pxr::UsdGeomImageable>()) {
+ return new USDXformReader(prim, params_, settings_);
+ }
+ return nullptr;
+}
+
+/* Returns true if the given prim should be included in the
+ * traversal based on the import options and the prim's visibility
+ * attribute. Note that the prim will be trivially included
+ * if it has no visibility attribute or if the visibility
+ * is inherited. */
+bool USDStageReader::include_by_visibility(const pxr::UsdGeomImageable &imageable) const
+{
+ if (!params_.import_visible_only) {
+ /* Invisible prims are allowed. */
+ return true;
+ }
+
+ pxr::UsdAttribute visibility_attr = imageable.GetVisibilityAttr();
+
+ if (!visibility_attr) {
+ /* No visibility attribute, so allow. */
+ return true;
+ }
+
+ /* Include if the prim has an animating visibility attribute or is not invisible. */
+
+ if (visibility_attr.ValueMightBeTimeVarying()) {
+ return true;
+ }
+
+ pxr::TfToken visibility;
+ visibility_attr.Get(&visibility);
+ return visibility != pxr::UsdGeomTokens->invisible;
+}
+
+/* Returns true if the given prim should be included in the
+ * traversal based on the import options and the prim's purpose
+ * attribute. E.g., return false (to exclude the prim) if the prim
+ * represents guide geometry and the 'Import Guide' option is
+ * toggled off. */
+bool USDStageReader::include_by_purpose(const pxr::UsdGeomImageable &imageable) const
+{
+ if (params_.import_guide && params_.import_proxy && params_.import_render) {
+ /* The options allow any purpose, so we trivially include the prim. */
+ return true;
+ }
+
+ pxr::UsdAttribute purpose_attr = imageable.GetPurposeAttr();
+
+ if (!purpose_attr) {
+ /* No purpose attribute, so trivially include the prim. */
+ return true;
+ }
+
+ pxr::TfToken purpose;
+ purpose_attr.Get(&purpose);
+
+ if (purpose == pxr::UsdGeomTokens->guide) {
+ return params_.import_guide;
+ }
+ if (purpose == pxr::UsdGeomTokens->proxy) {
+ return params_.import_proxy;
+ }
+ if (purpose == pxr::UsdGeomTokens->render) {
+ return params_.import_render;
+ }
+
+ return true;
+}
+
+/* Determine if the given reader can use the parent of the encapsulated USD prim
+ * to compute the Blender object's transform. If so, the reader is appropriately
+ * flagged and the function returns true. Otherwise, the function returns false. */
+static bool merge_with_parent(USDPrimReader *reader)
+{
+ USDXformReader *xform_reader = dynamic_cast<USDXformReader *>(reader);
+
+ if (!xform_reader) {
+ return false;
+ }
+
+ /* Check if the Xform reader is already merged. */
+ if (xform_reader->use_parent_xform()) {
+ return false;
+ }
+
+ /* Only merge if the parent is an Xform. */
+ if (!xform_reader->prim().GetParent().IsA<pxr::UsdGeomXform>()) {
+ return false;
+ }
+
+ /* Don't merge Xform and Scope prims. */
+ if (xform_reader->prim().IsA<pxr::UsdGeomXform>() ||
+ xform_reader->prim().IsA<pxr::UsdGeomScope>()) {
+ return false;
+ }
+
+ /* Don't merge if the prim has authored transform ops. */
+ if (xform_reader->prim_has_xform_ops()) {
+ return false;
+ }
+
+ /* Flag the Xform reader as merged. */
+ xform_reader->set_use_parent_xform(true);
+
+ return true;
+}
+
+USDPrimReader *USDStageReader::collect_readers(Main *bmain, const pxr::UsdPrim &prim)
+{
+ if (prim.IsA<pxr::UsdGeomImageable>()) {
+ pxr::UsdGeomImageable imageable(prim);
+
+ if (!include_by_purpose(imageable)) {
+ return nullptr;
+ }
+
+ if (!include_by_visibility(imageable)) {
+ return nullptr;
+ }
+ }
+
+ pxr::Usd_PrimFlagsPredicate filter_predicate = pxr::UsdPrimDefaultPredicate;
+
+ if (params_.import_instance_proxies) {
+ filter_predicate = pxr::UsdTraverseInstanceProxies(filter_predicate);
+ }
+
+ pxr::UsdPrimSiblingRange children = prim.GetFilteredChildren(filter_predicate);
+
+ std::vector<USDPrimReader *> child_readers;
+
+ for (const auto &childPrim : children) {
+ if (USDPrimReader *child_reader = collect_readers(bmain, childPrim)) {
+ child_readers.push_back(child_reader);
+ }
+ }
+
+ if (prim.IsPseudoRoot()) {
+ return nullptr;
+ }
+
+ /* Check if we can merge an Xform with its child prim. */
+ if (child_readers.size() == 1) {
+
+ USDPrimReader *child_reader = child_readers.front();
+
+ if (merge_with_parent(child_reader)) {
+ return child_reader;
+ }
+ }
+
+ USDPrimReader *reader = create_reader_if_allowed(prim);
+
+ if (!reader) {
+ return nullptr;
+ }
+
+ reader->create_object(bmain, 0.0);
+
+ readers_.push_back(reader);
+ reader->incref();
+
+ /* Set each child reader's parent. */
+ for (USDPrimReader *child_reader : child_readers) {
+ child_reader->parent(reader);
+ }
+
+ return reader;
+}
+
+void USDStageReader::collect_readers(Main *bmain)
+{
+ if (!valid()) {
+ return;
+ }
+
+ clear_readers();
+
+ /* Iterate through the stage. */
+ pxr::UsdPrim root = stage_->GetPseudoRoot();
+
+ std::string prim_path_mask(params_.prim_path_mask);
+
+ if (!prim_path_mask.empty()) {
+ pxr::UsdPrim prim = stage_->GetPrimAtPath(pxr::SdfPath(prim_path_mask));
+ if (prim.IsValid()) {
+ root = prim;
+ }
+ else {
+ std::cerr << "WARNING: Prim Path Mask " << prim_path_mask
+ << " does not specify a valid prim.\n";
+ }
+ }
+
+ stage_->SetInterpolationType(pxr::UsdInterpolationType::UsdInterpolationTypeHeld);
+ collect_readers(bmain, root);
+}
+
+void USDStageReader::clear_readers()
+{
+ for (USDPrimReader *reader : readers_) {
+ if (!reader) {
+ continue;
+ }
+
+ reader->decref();
+
+ if (reader->refcount() == 0) {
+ delete reader;
+ }
+ }
+
+ readers_.clear();
+}
+
+} // Namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_stage.h b/source/blender/io/usd/intern/usd_reader_stage.h
new file mode 100644
index 00000000000..7cc557f7802
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_stage.h
@@ -0,0 +1,90 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Tangent Animation and
+ * NVIDIA Corporation. All rights reserved.
+ */
+#pragma once
+
+struct Main;
+
+#include "usd.h"
+#include "usd_reader_prim.h"
+
+#include <pxr/usd/usd/stage.h>
+#include <pxr/usd/usdGeom/imageable.h>
+
+#include <vector>
+
+struct ImportSettings;
+
+namespace blender::io::usd {
+
+typedef std::map<pxr::SdfPath, std::vector<USDPrimReader *>> ProtoReaderMap;
+
+class USDStageReader {
+
+ protected:
+ pxr::UsdStageRefPtr stage_;
+ USDImportParams params_;
+ ImportSettings settings_;
+
+ std::vector<USDPrimReader *> readers_;
+
+ public:
+ USDStageReader(pxr::UsdStageRefPtr stage,
+ const USDImportParams &params,
+ const ImportSettings &settings);
+
+ ~USDStageReader();
+
+ USDPrimReader *create_reader_if_allowed(const pxr::UsdPrim &prim);
+
+ USDPrimReader *create_reader(const pxr::UsdPrim &prim);
+
+ void collect_readers(struct Main *bmain);
+
+ bool valid() const;
+
+ pxr::UsdStageRefPtr stage()
+ {
+ return stage_;
+ }
+ const USDImportParams &params() const
+ {
+ return params_;
+ }
+
+ const ImportSettings &settings() const
+ {
+ return settings_;
+ }
+
+ void clear_readers();
+
+ const std::vector<USDPrimReader *> &readers() const
+ {
+ return readers_;
+ };
+
+ private:
+ USDPrimReader *collect_readers(Main *bmain, const pxr::UsdPrim &prim);
+
+ bool include_by_visibility(const pxr::UsdGeomImageable &imageable) const;
+
+ bool include_by_purpose(const pxr::UsdGeomImageable &imageable) const;
+};
+
+}; // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_volume.cc b/source/blender/io/usd/intern/usd_reader_volume.cc
new file mode 100644
index 00000000000..871f791c1dd
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_volume.cc
@@ -0,0 +1,114 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_volume.h"
+
+#include "BKE_object.h"
+#include "BKE_volume.h"
+
+#include "DNA_object_types.h"
+#include "DNA_volume_types.h"
+
+#include <pxr/usd/usdVol/openVDBAsset.h>
+#include <pxr/usd/usdVol/volume.h>
+
+#include <iostream>
+
+namespace usdtokens {
+
+static const pxr::TfToken density("density", pxr::TfToken::Immortal);
+
+}
+
+namespace blender::io::usd {
+
+void USDVolumeReader::create_object(Main *bmain, const double /* motionSampleTime */)
+{
+ Volume *volume = (Volume *)BKE_volume_add(bmain, name_.c_str());
+
+ object_ = BKE_object_add_only_object(bmain, OB_VOLUME, name_.c_str());
+ object_->data = volume;
+}
+
+void USDVolumeReader::read_object_data(Main *bmain, const double motionSampleTime)
+{
+ if (!volume_) {
+ return;
+ }
+
+ Volume *volume = static_cast<Volume *>(object_->data);
+
+ if (!volume) {
+ return;
+ }
+
+ pxr::UsdVolVolume::FieldMap fields = volume_.GetFieldPaths();
+
+ for (pxr::UsdVolVolume::FieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it) {
+
+ pxr::UsdPrim fieldPrim = prim_.GetStage()->GetPrimAtPath(it->second);
+
+ if (!fieldPrim.IsA<pxr::UsdVolOpenVDBAsset>()) {
+ continue;
+ }
+
+ pxr::UsdVolOpenVDBAsset fieldBase(fieldPrim);
+
+ pxr::UsdAttribute fieldNameAttr = fieldBase.GetFieldNameAttr();
+
+ if (fieldNameAttr.IsAuthored()) {
+ pxr::TfToken fieldName;
+ fieldNameAttr.Get(&fieldName, motionSampleTime);
+
+ /* A Blender volume creates density by default. */
+ if (fieldName != usdtokens::density) {
+ BKE_volume_grid_add(volume, fieldName.GetString().c_str(), VOLUME_GRID_FLOAT);
+ }
+ }
+
+ pxr::UsdAttribute filepathAttr = fieldBase.GetFilePathAttr();
+
+ if (filepathAttr.IsAuthored()) {
+ pxr::SdfAssetPath fp;
+ filepathAttr.Get(&fp, motionSampleTime);
+
+ if (filepathAttr.ValueMightBeTimeVarying()) {
+ std::vector<double> filePathTimes;
+ filepathAttr.GetTimeSamples(&filePathTimes);
+
+ if (!filePathTimes.empty()) {
+ int start = static_cast<int>(filePathTimes.front());
+ int end = static_cast<int>(filePathTimes.back());
+
+ volume->is_sequence = static_cast<char>(true);
+ volume->frame_start = start;
+ volume->frame_duration = (end - start) + 1;
+ }
+ }
+
+ std::string filepath = fp.GetResolvedPath();
+
+ strcpy(volume->filepath, filepath.c_str());
+ }
+ }
+
+ USDXformReader::read_object_data(bmain, motionSampleTime);
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_volume.h b/source/blender/io/usd/intern/usd_reader_volume.h
new file mode 100644
index 00000000000..ca2fddb5531
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_volume.h
@@ -0,0 +1,49 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+#include "usd_reader_xform.h"
+
+#include "pxr/usd/usdVol/volume.h"
+
+namespace blender::io::usd {
+
+class USDVolumeReader : public USDXformReader {
+ private:
+ pxr::UsdVolVolume volume_;
+
+ public:
+ USDVolumeReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : USDXformReader(prim, import_params, settings), volume_(prim)
+ {
+ }
+
+ bool valid() const override
+ {
+ return static_cast<bool>(volume_);
+ }
+
+ void create_object(Main *bmain, double motionSampleTime) override;
+ void read_object_data(Main *bmain, double motionSampleTime) override;
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_xform.cc b/source/blender/io/usd/intern/usd_reader_xform.cc
new file mode 100644
index 00000000000..eebcc5eb3d5
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_xform.cc
@@ -0,0 +1,184 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_xform.h"
+
+#include "BKE_constraint.h"
+#include "BKE_lib_id.h"
+#include "BKE_library.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+
+#include "BLI_math_geom.h"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_cachefile_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_space_types.h" /* for FILE_MAX */
+
+#include <pxr/base/gf/math.h>
+#include <pxr/base/gf/matrix4f.h>
+
+#include <pxr/usd/usdGeom/xform.h>
+
+namespace blender::io::usd {
+
+void USDXformReader::create_object(Main *bmain, const double /* motionSampleTime */)
+{
+ object_ = BKE_object_add_only_object(bmain, OB_EMPTY, name_.c_str());
+ object_->empty_drawsize = 0.1f;
+ object_->data = nullptr;
+}
+
+void USDXformReader::read_object_data(Main * /* bmain */, const double motionSampleTime)
+{
+ bool is_constant;
+ float transform_from_usd[4][4];
+
+ read_matrix(transform_from_usd, motionSampleTime, import_params_.scale, &is_constant);
+
+ if (!is_constant) {
+ bConstraint *con = BKE_constraint_add_for_object(
+ object_, nullptr, CONSTRAINT_TYPE_TRANSFORM_CACHE);
+ bTransformCacheConstraint *data = static_cast<bTransformCacheConstraint *>(con->data);
+
+ std::string prim_path = use_parent_xform_ ? prim_.GetParent().GetPath().GetAsString() :
+ prim_path_;
+
+ BLI_strncpy(data->object_path, prim_path.c_str(), FILE_MAX);
+
+ data->cache_file = settings_->cache_file;
+ id_us_plus(&data->cache_file->id);
+ }
+
+ BKE_object_apply_mat4(object_, transform_from_usd, true, false);
+}
+
+void USDXformReader::read_matrix(float r_mat[4][4] /* local matrix */,
+ const float time,
+ const float scale,
+ bool *r_is_constant)
+{
+ if (r_is_constant) {
+ *r_is_constant = true;
+ }
+
+ unit_m4(r_mat);
+
+ pxr::UsdGeomXformable xformable;
+
+ if (use_parent_xform_) {
+ xformable = pxr::UsdGeomXformable(prim_.GetParent());
+ }
+ else {
+ xformable = pxr::UsdGeomXformable(prim_);
+ }
+
+ if (!xformable) {
+ /* This might happen if the prim is a Scope. */
+ return;
+ }
+
+ if (r_is_constant) {
+ *r_is_constant = !xformable.TransformMightBeTimeVarying();
+ }
+
+ pxr::GfMatrix4d usd_local_xf;
+ bool reset_xform_stack;
+ xformable.GetLocalTransformation(&usd_local_xf, &reset_xform_stack, time);
+
+ /* Convert the result to a float matrix. */
+ pxr::GfMatrix4f mat4f = pxr::GfMatrix4f(usd_local_xf);
+ mat4f.Get(r_mat);
+
+ /* Apply global scaling and rotation only to root objects, parenting
+ * will propagate it. */
+ if ((scale != 1.0 || settings_->do_convert_mat) && is_root_xform_) {
+
+ if (scale != 1.0f) {
+ float scale_mat[4][4];
+ scale_m4_fl(scale_mat, scale);
+ mul_m4_m4m4(r_mat, scale_mat, r_mat);
+ }
+
+ if (settings_->do_convert_mat) {
+ mul_m4_m4m4(r_mat, settings_->conversion_mat, r_mat);
+ }
+ }
+}
+
+bool USDXformReader::prim_has_xform_ops() const
+{
+ pxr::UsdGeomXformable xformable(prim_);
+
+ if (!xformable) {
+ /* This might happen if the prim is a Scope. */
+ return false;
+ }
+
+ bool reset_xform_stack = false;
+
+ return !xformable.GetOrderedXformOps(&reset_xform_stack).empty();
+}
+
+bool USDXformReader::is_root_xform_prim() const
+{
+ if (!prim_.IsValid()) {
+ return false;
+ }
+
+ if (prim_.IsInMaster()) {
+ /* We don't consider prototypes to be root prims,
+ * because we never want to apply global scaling
+ * or rotations to the prototypes themselves. */
+ return false;
+ }
+
+ if (prim_.IsA<pxr::UsdGeomXformable>()) {
+ /* If this prim doesn't have an ancestor that's a
+ * UsdGeomXformable, then it's a root prim. Note
+ * that it's not sufficient to only check the immediate
+ * parent prim, since the immediate parent could be a
+ * UsdGeomScope that has an xformable ancestor. */
+ pxr::UsdPrim cur_parent = prim_.GetParent();
+
+ if (use_parent_xform_) {
+ cur_parent = cur_parent.GetParent();
+ }
+
+ while (cur_parent && !cur_parent.IsPseudoRoot()) {
+ if (cur_parent.IsA<pxr::UsdGeomXformable>()) {
+ return false;
+ }
+ cur_parent = cur_parent.GetParent();
+ }
+
+ /* We didn't find an xformable ancestor. */
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_xform.h b/source/blender/io/usd/intern/usd_reader_xform.h
new file mode 100644
index 00000000000..587ac373a4f
--- /dev/null
+++ b/source/blender/io/usd/intern/usd_reader_xform.h
@@ -0,0 +1,68 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Adapted from the Blender Alembic importer implementation.
+ *
+ * Modifications Copyright (C) 2021 Tangent Animation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+#include "usd_reader_prim.h"
+
+namespace blender::io::usd {
+
+class USDXformReader : public USDPrimReader {
+ private:
+ bool use_parent_xform_;
+
+ /* Indicates if the created object is the root of a
+ * transform hierarchy. */
+ bool is_root_xform_;
+
+ public:
+ USDXformReader(const pxr::UsdPrim &prim,
+ const USDImportParams &import_params,
+ const ImportSettings &settings)
+ : USDPrimReader(prim, import_params, settings),
+ use_parent_xform_(false),
+ is_root_xform_(is_root_xform_prim())
+ {
+ }
+
+ void create_object(Main *bmain, double motionSampleTime) override;
+ void read_object_data(Main *bmain, double motionSampleTime) override;
+
+ void read_matrix(float r_mat[4][4], const float time, const float scale, bool *r_is_constant);
+
+ bool use_parent_xform() const
+ {
+ return use_parent_xform_;
+ }
+ void set_use_parent_xform(bool flag)
+ {
+ use_parent_xform_ = flag;
+ is_root_xform_ = is_root_xform_prim();
+ }
+
+ bool prim_has_xform_ops() const;
+
+ protected:
+ /* Returns true if the contained USD prim is the root of a transform hierarchy. */
+ bool is_root_xform_prim() const;
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h
index 40e2d0d8674..6b6b2d37162 100644
--- a/source/blender/io/usd/usd.h
+++ b/source/blender/io/usd/usd.h
@@ -26,6 +26,10 @@ extern "C" {
#endif
struct bContext;
+struct Object;
+struct CacheArchiveHandle;
+struct CacheReader;
+struct CacheFile;
struct USDExportParams {
bool export_animation;
@@ -39,6 +43,34 @@ struct USDExportParams {
enum eEvaluationMode evaluation_mode;
};
+struct USDImportParams {
+ float scale;
+ bool is_sequence;
+ bool set_frame_range;
+ int sequence_len;
+ int offset;
+ bool validate_meshes;
+ char mesh_read_flag;
+ bool import_cameras;
+ bool import_curves;
+ bool import_lights;
+ bool import_materials;
+ bool import_meshes;
+ bool import_volumes;
+ char *prim_path_mask;
+ bool import_subdiv;
+ bool import_instance_proxies;
+ bool create_collection;
+ bool import_guide;
+ bool import_proxy;
+ bool import_render;
+ bool import_visible_only;
+ bool use_instancing;
+ bool import_usd_preview;
+ bool set_material_blend;
+ float light_intensity_scale;
+};
+
/* The USD_export takes a as_background_job parameter, and returns a boolean.
*
* When as_background_job=true, returns false immediately after scheduling
@@ -53,8 +85,45 @@ bool USD_export(struct bContext *C,
const struct USDExportParams *params,
bool as_background_job);
+bool USD_import(struct bContext *C,
+ const char *filepath,
+ const struct USDImportParams *params,
+ bool as_background_job);
+
int USD_get_version(void);
+/* USD Import and Mesh Cache interface. */
+
+struct CacheArchiveHandle *USD_create_handle(struct Main *bmain,
+ const char *filename,
+ struct ListBase *object_paths);
+
+void USD_free_handle(struct CacheArchiveHandle *handle);
+
+void USD_get_transform(struct CacheReader *reader, float r_mat[4][4], float time, float scale);
+
+/* Either modifies current_mesh in-place or constructs a new mesh. */
+struct Mesh *USD_read_mesh(struct CacheReader *reader,
+ struct Object *ob,
+ struct Mesh *existing_mesh,
+ const float time,
+ const char **err_str,
+ int read_flag);
+
+bool USD_mesh_topology_changed(struct CacheReader *reader,
+ struct Object *ob,
+ struct Mesh *existing_mesh,
+ const float time,
+ const char **err_str);
+
+struct CacheReader *CacheReader_open_usd_object(struct CacheArchiveHandle *handle,
+ struct CacheReader *reader,
+ struct Object *object,
+ const char *object_path);
+
+void USD_CacheReader_incref(struct CacheReader *reader);
+void USD_CacheReader_free(struct CacheReader *reader);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/makesdna/DNA_cachefile_defaults.h b/source/blender/makesdna/DNA_cachefile_defaults.h
index d37994bb488..521b72567d4 100644
--- a/source/blender/makesdna/DNA_cachefile_defaults.h
+++ b/source/blender/makesdna/DNA_cachefile_defaults.h
@@ -36,6 +36,7 @@
.scale = 1.0f, \
.object_paths ={NULL, NULL}, \
\
+ .type = 0, \
.handle = NULL, \
.handle_filepath[0] = '\0', \
.handle_readers = NULL, \
diff --git a/source/blender/makesdna/DNA_cachefile_types.h b/source/blender/makesdna/DNA_cachefile_types.h
index 04c99c6c4b1..b38c7827ea5 100644
--- a/source/blender/makesdna/DNA_cachefile_types.h
+++ b/source/blender/makesdna/DNA_cachefile_types.h
@@ -31,6 +31,13 @@ extern "C" {
struct GSet;
+/* CacheFile::type */
+typedef enum {
+ CACHEFILE_TYPE_ALEMBIC = 1,
+ CACHEFILE_TYPE_USD = 2,
+ CACHE_FILE_TYPE_INVALID = 0,
+} eCacheFileType;
+
/* CacheFile::flag */
enum {
CACHEFILE_DS_EXPAND = (1 << 0),
@@ -44,13 +51,13 @@ enum {
};
#endif
-/* Representation of an object's path inside the Alembic file.
+/* Representation of an object's path inside the archive.
* Note that this is not a file path. */
-typedef struct AlembicObjectPath {
- struct AlembicObjectPath *next, *prev;
+typedef struct CacheObjectPath {
+ struct CacheObjectPath *next, *prev;
char path[4096];
-} AlembicObjectPath;
+} CacheObjectPath;
/* CacheFile::velocity_unit
* Determines what temporal unit is used to interpret velocity vectors for motion blur effects. */
@@ -63,7 +70,7 @@ typedef struct CacheFile {
ID id;
struct AnimData *adt;
- /** Paths of the objects inside of the Alembic archive referenced by this CacheFile. */
+ /** Paths of the objects inside of the archive referenced by this CacheFile. */
ListBase object_paths;
/** 1024 = FILE_MAX. */
@@ -84,14 +91,17 @@ typedef struct CacheFile {
short flag;
short draw_flag; /* UNUSED */
- char _pad[3];
+ /* eCacheFileType enum. */
+ char type;
+
+ char _pad[2];
char velocity_unit;
- /* Name of the velocity property in the Alembic file. */
+ /* Name of the velocity property in the archive. */
char velocity_name[64];
/* Runtime */
- struct AbcArchiveHandle *handle;
+ struct CacheArchiveHandle *handle;
char handle_filepath[1024];
struct GSet *handle_readers;
} CacheFile;
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index feacd47c98c..46d60bf0da9 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -6723,7 +6723,7 @@ bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool
return RNA_property_is_set_ex(ptr, prop, use_ghost);
}
/* python raises an error */
- /* printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name); */
+ // printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
return 0;
}
@@ -6735,7 +6735,7 @@ bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
return RNA_property_is_set(ptr, prop);
}
/* python raises an error */
- /* printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name); */
+ // printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
return 0;
}
diff --git a/source/blender/makesrna/intern/rna_cachefile.c b/source/blender/makesrna/intern/rna_cachefile.c
index c25cea1b4b3..b93f494072c 100644
--- a/source/blender/makesrna/intern/rna_cachefile.c
+++ b/source/blender/makesrna/intern/rna_cachefile.c
@@ -64,8 +64,8 @@ static void rna_CacheFile_object_paths_begin(CollectionPropertyIterator *iter, P
/* cachefile.object_paths */
static void rna_def_alembic_object_path(BlenderRNA *brna)
{
- StructRNA *srna = RNA_def_struct(brna, "AlembicObjectPath", NULL);
- RNA_def_struct_sdna(srna, "AlembicObjectPath");
+ StructRNA *srna = RNA_def_struct(brna, "CacheObjectPath", NULL);
+ RNA_def_struct_sdna(srna, "CacheObjectPath");
RNA_def_struct_ui_text(srna, "Object Path", "Path of an object inside of an Alembic archive");
RNA_def_struct_ui_icon(srna, ICON_NONE);
@@ -81,8 +81,8 @@ static void rna_def_alembic_object_path(BlenderRNA *brna)
/* cachefile.object_paths */
static void rna_def_cachefile_object_paths(BlenderRNA *brna, PropertyRNA *cprop)
{
- RNA_def_property_srna(cprop, "AlembicObjectPaths");
- StructRNA *srna = RNA_def_struct(brna, "AlembicObjectPaths", NULL);
+ RNA_def_property_srna(cprop, "CacheObjectPaths");
+ StructRNA *srna = RNA_def_struct(brna, "CacheObjectPaths", NULL);
RNA_def_struct_sdna(srna, "CacheFile");
RNA_def_struct_ui_text(srna, "Object Paths", "Collection of object paths");
}
@@ -169,8 +169,8 @@ static void rna_def_cachefile(BlenderRNA *brna)
NULL,
NULL,
NULL);
- RNA_def_property_struct_type(prop, "AlembicObjectPath");
- RNA_def_property_srna(prop, "AlembicObjectPaths");
+ RNA_def_property_struct_type(prop, "CacheObjectPath");
+ RNA_def_property_srna(prop, "CacheObjectPaths");
RNA_def_property_ui_text(
prop, "Object Paths", "Paths of the objects inside the Alembic archive");
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 1d4318602c2..796e62c8b2a 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -778,6 +778,19 @@ static void rna_Space_show_region_toolbar_update(bContext *C, PointerRNA *ptr)
rna_Space_bool_from_region_flag_update_by_type(C, ptr, RGN_TYPE_TOOLS, RGN_FLAG_HIDDEN);
}
+static bool rna_Space_show_region_tool_props_get(PointerRNA *ptr)
+{
+ return !rna_Space_bool_from_region_flag_get_by_type(ptr, RGN_TYPE_TOOL_PROPS, RGN_FLAG_HIDDEN);
+}
+static void rna_Space_show_region_tool_props_set(PointerRNA *ptr, bool value)
+{
+ rna_Space_bool_from_region_flag_set_by_type(ptr, RGN_TYPE_TOOL_PROPS, RGN_FLAG_HIDDEN, !value);
+}
+static void rna_Space_show_region_tool_props_update(bContext *C, PointerRNA *ptr)
+{
+ rna_Space_bool_from_region_flag_update_by_type(C, ptr, RGN_TYPE_TOOL_PROPS, RGN_FLAG_HIDDEN);
+}
+
/* Channels Region. */
static bool rna_Space_show_region_channels_get(PointerRNA *ptr)
{
@@ -3196,6 +3209,10 @@ static void rna_def_space_generic_show_region_toggles(StructRNA *srna, int regio
region_type_mask &= ~(1 << RGN_TYPE_TOOLS);
DEF_SHOW_REGION_PROPERTY(show_region_toolbar, "Toolbar", "");
}
+ if (region_type_mask & (1 << RGN_TYPE_TOOL_PROPS)) {
+ region_type_mask &= ~(1 << RGN_TYPE_TOOL_PROPS);
+ DEF_SHOW_REGION_PROPERTY(show_region_tool_props, "Toolbar", "");
+ }
if (region_type_mask & (1 << RGN_TYPE_CHANNELS)) {
region_type_mask &= ~(1 << RGN_TYPE_CHANNELS);
DEF_SHOW_REGION_PROPERTY(show_region_channels, "Channels", "");
@@ -6546,7 +6563,8 @@ static void rna_def_space_filebrowser(BlenderRNA *brna)
RNA_def_struct_sdna(srna, "SpaceFile");
RNA_def_struct_ui_text(srna, "Space File Browser", "File browser space data");
- rna_def_space_generic_show_region_toggles(srna, (1 << RGN_TYPE_TOOLS) | (1 << RGN_TYPE_UI));
+ rna_def_space_generic_show_region_toggles(
+ srna, (1 << RGN_TYPE_TOOLS) | (1 << RGN_TYPE_UI) | (1 << RGN_TYPE_TOOL_PROPS));
prop = RNA_def_property(srna, "browse_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, rna_enum_space_file_browse_mode_items);
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index 0138dd0c3ad..d9b9fa96d04 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -141,6 +141,16 @@ if(WITH_ALEMBIC)
)
endif()
+if(WITH_USD)
+ add_definitions(-DWITH_USD)
+ list(APPEND INC
+ ../io/usd
+ )
+ list(APPEND LIB
+ bf_usd
+ )
+endif()
+
if(WITH_MOD_REMESH)
list(APPEND INC
../../../intern/dualcon
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c
index c2f9cd8c867..3e6081e0a18 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.c
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c
@@ -55,18 +55,29 @@
#include "MOD_modifiertypes.h"
#include "MOD_ui_common.h"
-#ifdef WITH_ALEMBIC
-# include "ABC_alembic.h"
+#if defined(WITH_USD) || defined(WITH_ALEMBIC)
# include "BKE_global.h"
# include "BKE_lib_id.h"
#endif
+#ifdef WITH_ALEMBIC
+# include "ABC_alembic.h"
+#endif
+
+#ifdef WITH_USD
+# include "usd.h"
+#endif
+
static void initData(ModifierData *md)
{
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(mcmd, modifier));
+ mcmd->cache_file = NULL;
+ mcmd->object_path[0] = '\0';
+ mcmd->read_flag = MOD_MESHSEQ_READ_ALL;
+
MEMCPY_STRUCT_AFTER(mcmd, DNA_struct_default_get(MeshSeqCacheModifierData), modifier);
}
@@ -109,7 +120,7 @@ static bool isDisabled(const struct Scene *UNUSED(scene),
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_USD) || defined(WITH_ALEMBIC)
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
/* Only used to check whether we are operating on org data or not... */
@@ -127,16 +138,32 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
BKE_cachefile_reader_open(cache_file, &mcmd->reader, ctx->object, mcmd->object_path);
if (!mcmd->reader) {
BKE_modifier_set_error(
- ctx->object, md, "Could not create Alembic reader for file %s", cache_file->filepath);
+ ctx->object, md, "Could not create reader for file %s", cache_file->filepath);
return mesh;
}
}
- /* If this invocation is for the ORCO mesh, and the mesh in Alembic hasn't changed topology, we
+ /* If this invocation is for the ORCO mesh, and the mesh hasn't changed topology, we
* must return the mesh as-is instead of deforming it. */
- if (ctx->flag & MOD_APPLY_ORCO &&
- !ABC_mesh_topology_changed(mcmd->reader, ctx->object, mesh, time, &err_str)) {
- return mesh;
+ if (ctx->flag & MOD_APPLY_ORCO) {
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ if (!ABC_mesh_topology_changed(mcmd->reader, ctx->object, mesh, time, &err_str)) {
+ return mesh;
+ }
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ if (!USD_mesh_topology_changed(mcmd->reader, ctx->object, mesh, time, &err_str)) {
+ return mesh;
+ }
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
}
if (me != NULL) {
@@ -156,7 +183,23 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
}
- Mesh *result = ABC_read_mesh(mcmd->reader, ctx->object, mesh, time, &err_str, mcmd->read_flag);
+ Mesh *result = NULL;
+
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ result = ABC_read_mesh(mcmd->reader, ctx->object, mesh, time, &err_str, mcmd->read_flag);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ result = USD_read_mesh(
+ mcmd->reader, ctx->object, mesh, time * FPS, &err_str, mcmd->read_flag);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
mcmd->velocity_delta = 1.0f;
if (mcmd->cache_file->velocity_unit == CACHEFILE_VELOCITY_UNIT_SECOND) {
@@ -187,7 +230,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
static bool dependsOnTime(ModifierData *md)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_USD) || defined(WITH_ALEMBIC)
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
return (mcmd->cache_file != NULL);
#else
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 5fa11ffdd10..3853b345c14 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -721,17 +721,17 @@ static void initialize_group_input(NodesModifierData &nmd,
return;
}
if (nmd.settings.properties == nullptr) {
- blender::nodes::socket_cpp_value_get(socket, r_value);
+ socket.typeinfo->get_geometry_nodes_cpp_value(socket, r_value);
return;
}
const IDProperty *property = IDP_GetPropertyFromGroup(nmd.settings.properties,
socket.identifier);
if (property == nullptr) {
- blender::nodes::socket_cpp_value_get(socket, r_value);
+ socket.typeinfo->get_geometry_nodes_cpp_value(socket, r_value);
return;
}
if (!property_type->is_correct_type(*property)) {
- blender::nodes::socket_cpp_value_get(socket, r_value);
+ socket.typeinfo->get_geometry_nodes_cpp_value(socket, r_value);
return;
}
property_type->init_cpp_value(*property, r_value);
@@ -883,7 +883,7 @@ static GeometrySet compute_geometry(const DerivedNodeTree &tree,
/* Initialize remaining group inputs. */
for (const OutputSocketRef *socket : remaining_input_sockets) {
- const CPPType &cpp_type = *blender::nodes::socket_cpp_type_get(*socket->typeinfo());
+ const CPPType &cpp_type = *socket->typeinfo()->get_geometry_nodes_cpp_type();
void *value_in = allocator.allocate(cpp_type.size(), cpp_type.alignment());
initialize_group_input(*nmd, *socket->bsocket(), cpp_type, value_in);
group_inputs.add_new({root_context, socket}, {cpp_type, value_in});
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index e652eb8353d..1391587fa7d 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -294,7 +294,11 @@ class LockedNode : NonCopyable, NonMovable {
static const CPPType *get_socket_cpp_type(const SocketRef &socket)
{
- const CPPType *type = nodes::socket_cpp_type_get(*socket.typeinfo());
+ const bNodeSocketType *typeinfo = socket.typeinfo();
+ if (typeinfo->get_geometry_nodes_cpp_type == nullptr) {
+ return nullptr;
+ }
+ const CPPType *type = typeinfo->get_geometry_nodes_cpp_type();
if (type == nullptr) {
return nullptr;
}
@@ -310,6 +314,12 @@ static const CPPType *get_socket_cpp_type(const DSocket socket)
return get_socket_cpp_type(*socket.socket_ref());
}
+static void get_socket_value(const SocketRef &socket, void *r_value)
+{
+ const bNodeSocketType *typeinfo = socket.typeinfo();
+ typeinfo->get_geometry_nodes_cpp_value(*socket.bsocket(), r_value);
+}
+
static bool node_supports_laziness(const DNode node)
{
return node->typeinfo()->geometry_node_execute_supports_laziness;
@@ -1235,14 +1245,8 @@ class GeometryNodesEvaluator {
void *buffer = allocator.allocate(to_type.size(), to_type.alignment());
GMutablePointer value{to_type, buffer};
- if (conversions_.is_convertible(from_type, to_type)) {
- /* Do the conversion if possible. */
- conversions_.convert_to_uninitialized(from_type, to_type, value_to_forward.get(), buffer);
- }
- else {
- /* Cannot convert, use default value instead. */
- to_type.copy_construct(to_type.default_value(), buffer);
- }
+ this->convert_value(from_type, to_type, value_to_forward.get(), buffer);
+
/* Multi input socket values are logged once all values are available. */
if (!to_socket->is_multi_input_socket()) {
this->log_socket_value({to_socket}, value);
@@ -1363,25 +1367,36 @@ class GeometryNodesEvaluator {
{
LinearAllocator<> &allocator = local_allocators_.local();
- bNodeSocket *bsocket = socket->bsocket();
const CPPType &type = *get_socket_cpp_type(socket);
void *buffer = allocator.allocate(type.size(), type.alignment());
- blender::nodes::socket_cpp_value_get(*bsocket, buffer);
+ get_socket_value(*socket.socket_ref(), buffer);
if (type == required_type) {
return {type, buffer};
}
- if (conversions_.is_convertible(type, required_type)) {
- /* Convert the loaded value to the required type if possible. */
- void *converted_buffer = allocator.allocate(required_type.size(), required_type.alignment());
- conversions_.convert_to_uninitialized(type, required_type, buffer, converted_buffer);
- type.destruct(buffer);
- return {required_type, converted_buffer};
+ void *converted_buffer = allocator.allocate(required_type.size(), required_type.alignment());
+ this->convert_value(type, required_type, buffer, converted_buffer);
+ return {required_type, converted_buffer};
+ }
+
+ void convert_value(const CPPType &from_type,
+ const CPPType &to_type,
+ const void *from_value,
+ void *to_value)
+ {
+ if (from_type == to_type) {
+ from_type.copy_construct(from_value, to_value);
+ return;
+ }
+
+ if (conversions_.is_convertible(from_type, to_type)) {
+ /* Do the conversion if possible. */
+ conversions_.convert_to_uninitialized(from_type, to_type, from_value, to_value);
+ }
+ else {
+ /* Cannot convert, use default value instead. */
+ to_type.copy_construct(to_type.default_value(), to_value);
}
- /* Use a default fallback value when the loaded type is not compatible. */
- void *default_buffer = allocator.allocate(required_type.size(), required_type.alignment());
- required_type.copy_construct(required_type.default_value(), default_buffer);
- return {required_type, default_buffer};
}
NodeState &get_node_state(const DNode node)
diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c
index 4677a9bc253..df3db894f4e 100644
--- a/source/blender/modifiers/intern/MOD_remesh.c
+++ b/source/blender/modifiers/intern/MOD_remesh.c
@@ -159,7 +159,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
if (rmd->voxel_size == 0.0f) {
return NULL;
}
- result = BKE_mesh_remesh_voxel_to_mesh_nomain(mesh, rmd->voxel_size, rmd->adaptivity, 0.0f);
+ result = BKE_mesh_remesh_voxel(mesh, rmd->voxel_size, rmd->adaptivity, 0.0f);
if (result == NULL) {
return NULL;
}
diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
index b872f04b60f..18d308e5f02 100644
--- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
+++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
@@ -71,6 +71,15 @@ static float angle_signed_on_axis_normalized_v3v3_v3(const float n[3],
return angle;
}
+static float clamp_nonzero(const float value, const float epsilon)
+{
+ BLI_assert(!(epsilon < 0.0f));
+ if (value < 0.0f) {
+ return min_ff(value, -epsilon);
+ }
+ return max_ff(value, epsilon);
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -164,8 +173,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
const float ofs_front = (smd->offset_fac + 1.0f) * 0.5f * smd->offset;
const float ofs_back = ofs_front - smd->offset * smd->offset_fac;
- const float ofs_front_clamped = max_ff(1e-5f, fabsf(smd->offset > 0 ? ofs_front : ofs_back));
- const float ofs_back_clamped = max_ff(1e-5f, fabsf(smd->offset > 0 ? ofs_back : ofs_front));
+ const float ofs_front_clamped = clamp_nonzero(smd->offset > 0 ? ofs_front : ofs_back, 1e-5f);
+ const float ofs_back_clamped = clamp_nonzero(smd->offset > 0 ? ofs_back : ofs_front, 1e-5f);
const float offset_fac_vg = smd->offset_fac_vg;
const float offset_fac_vg_inv = 1.0f - smd->offset_fac_vg;
const float offset = fabsf(smd->offset) * smd->offset_clamp;
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 103c7297e19..420349356a1 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -291,22 +291,22 @@ DefNode(GeometryNode, GEO_NODE_BOOLEAN, def_geo_boolean, "BOOLEAN", Boolean, "Bo
DefNode(GeometryNode, GEO_NODE_BOUNDING_BOX, 0, "BOUNDING_BOX", BoundBox, "Bounding Box", "")
DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_collection_info, "COLLECTION_INFO", CollectionInfo, "Collection Info", "")
DefNode(GeometryNode, GEO_NODE_CONVEX_HULL, 0, "CONVEX_HULL", ConvexHull, "Convex Hull", "")
+DefNode(GeometryNode, GEO_NODE_CURVE_ENDPOINTS, 0, "CURVE_ENDPOINTS", CurveEndpoints, "Curve Endpoints", "")
DefNode(GeometryNode, GEO_NODE_CURVE_LENGTH, 0, "CURVE_LENGTH", CurveLength, "Curve Length", "")
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT, def_geo_curve_primitive_bezier_segment, "CURVE_PRIMITIVE_BEZIER_SEGMENT", CurvePrimitiveBezierSegment, "Bezier Segment", "")
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_CIRCLE, def_geo_curve_primitive_circle, "CURVE_PRIMITIVE_CIRCLE", CurvePrimitiveCircle, "Curve Circle", "")
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_LINE, def_geo_curve_primitive_line, "CURVE_PRIMITIVE_LINE", CurvePrimitiveLine, "Curve Line", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_QUADRILATERAL, def_geo_curve_primitive_quadrilateral, "CURVE_PRIMITIVE_QUADRILATERAL", CurvePrimitiveQuadrilateral, "Quadrilateral", "")
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER, 0, "CURVE_PRIMITIVE_QUADRATIC_BEZIER", CurveQuadraticBezier, "Quadratic Bezier", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR", CurveStar, "Star", "")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_QUADRILATERAL, def_geo_curve_primitive_quadrilateral, "CURVE_PRIMITIVE_QUADRILATERAL", CurvePrimitiveQuadrilateral, "Quadrilateral", "")
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_SPIRAL, 0, "CURVE_PRIMITIVE_SPIRAL", CurveSpiral, "Curve Spiral", "")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR", CurveStar, "Star", "")
DefNode(GeometryNode, GEO_NODE_CURVE_RESAMPLE, def_geo_curve_resample, "CURVE_RESAMPLE", CurveResample, "Resample Curve", "")
+DefNode(GeometryNode, GEO_NODE_CURVE_REVERSE, 0, "CURVE_REVERSE", CurveReverse, "Curve Reverse", "")
DefNode(GeometryNode, GEO_NODE_CURVE_SET_HANDLES, def_geo_curve_set_handles, "CURVE_SET_HANDLES", CurveSetHandles, "Set Handle Type", "")
DefNode(GeometryNode, GEO_NODE_CURVE_SUBDIVIDE, def_geo_curve_subdivide, "CURVE_SUBDIVIDE", CurveSubdivide, "Curve Subdivide", "")
DefNode(GeometryNode, GEO_NODE_CURVE_TO_MESH, 0, "CURVE_TO_MESH", CurveToMesh, "Curve to Mesh", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_TRIM, def_geo_curve_trim, "CURVE_TRIM", CurveTrim, "Curve Trim", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_REVERSE, 0, "CURVE_REVERSE", CurveReverse, "Curve Reverse", "")
DefNode(GeometryNode, GEO_NODE_CURVE_TO_POINTS, def_geo_curve_to_points, "CURVE_TO_POINTS", CurveToPoints, "Curve to Points", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_ENDPOINTS, 0, "CURVE_ENDPOINTS", CurveEndpoints, "Curve Endpoints", "")
+DefNode(GeometryNode, GEO_NODE_CURVE_TRIM, def_geo_curve_trim, "CURVE_TRIM", CurveTrim, "Curve Trim", "")
DefNode(GeometryNode, GEO_NODE_DELETE_GEOMETRY, 0, "DELETE_GEOMETRY", DeleteGeometry, "Delete Geometry", "")
DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Split", "")
DefNode(GeometryNode, GEO_NODE_EXTRUDE, 0, "EXTRUDE", Extrude, "Extrude", "")
@@ -323,6 +323,7 @@ DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_GRID, 0, "MESH_PRIMITIVE_GRID", Me
DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_ICO_SPHERE, 0, "MESH_PRIMITIVE_ICO_SPHERE", MeshIcoSphere, "Ico Sphere", "")
DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_LINE, def_geo_mesh_line, "MESH_PRIMITIVE_LINE", MeshLine, "Mesh Line", "")
DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE, 0, "MESH_PRIMITIVE_UV_SPHERE", MeshUVSphere, "UV Sphere", "")
+DefNode(GeometryNode, GEO_NODE_MESH_SUBDIVIDE, 0, "MESH_SUBDIVIDE", MeshSubdivide, "Mesh Subdivide", "")
DefNode(GeometryNode, GEO_NODE_MESH_TO_CURVE, 0, "MESH_TO_CURVE", MeshToCurve, "Mesh to Curve", "")
DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, def_geo_object_info, "OBJECT_INFO", ObjectInfo, "Object Info", "")
DefNode(GeometryNode, GEO_NODE_POINT_DISTRIBUTE, def_geo_point_distribute, "POINT_DISTRIBUTE", PointDistribute, "Point Distribute", "")
@@ -335,7 +336,6 @@ DefNode(GeometryNode, GEO_NODE_POINTS_TO_VOLUME, def_geo_points_to_volume, "POIN
DefNode(GeometryNode, GEO_NODE_RAYCAST, def_geo_raycast, "RAYCAST", Raycast, "Raycast", "")
DefNode(GeometryNode, GEO_NODE_SELECT_BY_MATERIAL, 0, "SELECT_BY_MATERIAL", SelectByMaterial, "Select by Material", "")
DefNode(GeometryNode, GEO_NODE_SEPARATE_COMPONENTS, 0, "SEPARATE_COMPONENTS", SeparateComponents, "Separate Components", "")
-DefNode(GeometryNode, GEO_NODE_MESH_SUBDIVIDE, 0, "MESH_SUBDIVIDE", MeshSubdivide, "Mesh Subdivide", "")
DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE, 0, "SUBDIVISION_SURFACE", SubdivisionSurface, "Subdivision Surface", "")
DefNode(GeometryNode, GEO_NODE_SWITCH, def_geo_switch, "SWITCH", Switch, "Switch", "")
DefNode(GeometryNode, GEO_NODE_TRANSFORM, 0, "TRANSFORM", Transform, "Transform", "")
diff --git a/source/blender/nodes/NOD_type_callbacks.hh b/source/blender/nodes/NOD_type_callbacks.hh
index d1a4bd3ad7a..2be78f929db 100644
--- a/source/blender/nodes/NOD_type_callbacks.hh
+++ b/source/blender/nodes/NOD_type_callbacks.hh
@@ -27,10 +27,8 @@ namespace blender::nodes {
using fn::CPPType;
using fn::MFDataType;
-const CPPType *socket_cpp_type_get(const bNodeSocketType &stype);
std::optional<MFDataType> socket_mf_type_get(const bNodeSocketType &stype);
bool socket_is_mf_data_socket(const bNodeSocketType &stype);
-bool socket_cpp_value_get(const bNodeSocket &socket, void *r_value);
void socket_expand_in_mf_network(SocketMFNetworkBuilder &builder);
} // namespace blender::nodes
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
index 6a23443d3ab..ab2136f4e8d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
@@ -204,7 +204,8 @@ static void get_closest_mesh_polygons(const Mesh &mesh,
Array<int> looptri_indices(positions.size());
get_closest_mesh_looptris(mesh, positions, looptri_indices, r_distances_sq, r_positions);
- Span<MLoopTri> looptris = bke::mesh_surface_sample::get_mesh_looptris(mesh);
+ const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+ BKE_mesh_runtime_looptri_len(&mesh)};
for (const int i : positions.index_range()) {
const MLoopTri &looptri = looptris[looptri_indices[i]];
r_poly_indices[i] = looptri.poly;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc b/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
index 4286db52115..91d569282c3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
@@ -150,7 +150,7 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
plConvexHullDelete(hull);
- BKE_mesh_calc_normals(result);
+ BKE_mesh_normals_tag_dirty(result);
return result;
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
index 925ed0f8da8..d46ea2d2050 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
@@ -299,7 +299,7 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
mesh->medge[0].v1 = 0;
mesh->medge[0].v2 = 1;
mesh->medge[0].flag |= ME_LOOSEEDGE;
- BKE_mesh_calc_normals(mesh);
+ BKE_mesh_normals_tag_dirty(mesh);
return mesh;
}
@@ -534,12 +534,10 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
}
}
- BKE_mesh_calc_normals(mesh);
+ BKE_mesh_normals_tag_dirty(mesh);
calculate_uvs(mesh, top_is_point, bottom_is_point, verts_num, fill_type);
- BLI_assert(BKE_mesh_is_valid(mesh));
-
return mesh;
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc
index 245d7800621..165da8ec9f2 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc
@@ -88,7 +88,7 @@ static void geo_node_mesh_subdivide_exec(GeoNodeExecParams params)
}
Mesh *mesh_out = BKE_subdiv_to_mesh(subdiv, &mesh_settings, mesh_in);
- BKE_mesh_calc_normals(mesh_out);
+ BKE_mesh_normals_tag_dirty(mesh_out);
MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
mesh_component.replace(mesh_out);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index d456c72744f..99930b5ae46 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -81,13 +81,6 @@ static float3 normal_to_euler_rotation(const float3 normal)
return rotation;
}
-static Span<MLoopTri> get_mesh_looptris(const Mesh &mesh)
-{
- const MLoopTri *looptris = BKE_mesh_runtime_looptri_ensure(&mesh);
- const int looptris_len = BKE_mesh_runtime_looptri_len(&mesh);
- return {looptris, looptris_len};
-}
-
static void sample_mesh_surface(const Mesh &mesh,
const float4x4 &transform,
const float base_density,
@@ -97,7 +90,8 @@ static void sample_mesh_surface(const Mesh &mesh,
Vector<float3> &r_bary_coords,
Vector<int> &r_looptri_indices)
{
- Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+ const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+ BKE_mesh_runtime_looptri_len(&mesh)};
for (const int looptri_index : looptris.index_range()) {
const MLoopTri &looptri = looptris[looptri_index];
@@ -208,7 +202,8 @@ BLI_NOINLINE static void update_elimination_mask_based_on_density_factors(
Span<int> looptri_indices,
MutableSpan<bool> elimination_mask)
{
- Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+ const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+ BKE_mesh_runtime_looptri_len(&mesh)};
for (const int i : bary_coords.index_range()) {
if (elimination_mask[i]) {
continue;
@@ -365,7 +360,8 @@ BLI_NOINLINE static void compute_special_attributes(Span<GeometryInstanceGroup>
const GeometrySet &set = set_group.geometry_set;
const MeshComponent &component = *set.get_component_for_read<MeshComponent>();
const Mesh &mesh = *component.get_for_read();
- Span<MLoopTri> looptris = get_mesh_looptris(mesh);
+ const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
+ BKE_mesh_runtime_looptri_len(&mesh)};
for (const float4x4 &transform : set_group.transforms) {
const int offset = instance_start_offsets[i_instance];
diff --git a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
index f0f032ed8f4..a2c10af9c4d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
@@ -93,7 +93,7 @@ static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
}
Mesh *mesh_out = BKE_subdiv_to_mesh(subdiv, &mesh_settings, mesh_in);
- BKE_mesh_calc_normals(mesh_out);
+ BKE_mesh_normals_tag_dirty(mesh_out);
MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
mesh_component.replace(mesh_out);
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index bfd1ad02d36..ffa20579acc 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -218,7 +218,7 @@ void GeoNodeExecParams::check_input_access(StringRef identifier,
BLI_assert_unreachable();
}
else if (requested_type != nullptr) {
- const CPPType &expected_type = *socket_cpp_type_get(*found_socket->typeinfo);
+ const CPPType &expected_type = *found_socket->typeinfo->get_geometry_nodes_cpp_type();
if (*requested_type != expected_type) {
std::cout << "The requested type '" << requested_type->name() << "' is incorrect. Expected '"
<< expected_type.name() << "'.\n";
@@ -258,7 +258,7 @@ void GeoNodeExecParams::check_output_access(StringRef identifier, const CPPType
BLI_assert_unreachable();
}
else {
- const CPPType &expected_type = *socket_cpp_type_get(*found_socket->typeinfo);
+ const CPPType &expected_type = *found_socket->typeinfo->get_geometry_nodes_cpp_type();
if (value_type != expected_type) {
std::cout << "The value type '" << value_type.name() << "' is incorrect. Expected '"
<< expected_type.name() << "'.\n";
diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc
index 8fdad0bb242..4be3fd2468b 100644
--- a/source/blender/nodes/intern/node_socket.cc
+++ b/source/blender/nodes/intern/node_socket.cc
@@ -607,60 +607,74 @@ static bNodeSocketType *make_socket_type_virtual()
static bNodeSocketType *make_socket_type_bool()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_BOOLEAN, PROP_NONE);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<bool>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<bool>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(bool *)r_value = ((bNodeSocketValueBoolean *)socket.default_value)->value;
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
static bNodeSocketType *make_socket_type_float(PropertySubType subtype)
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_FLOAT, subtype);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<float>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<float>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(float *)r_value = ((bNodeSocketValueFloat *)socket.default_value)->value;
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
static bNodeSocketType *make_socket_type_int(PropertySubType subtype)
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_INT, subtype);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<int>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<int>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(int *)r_value = ((bNodeSocketValueInt *)socket.default_value)->value;
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
static bNodeSocketType *make_socket_type_vector(PropertySubType subtype)
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_VECTOR, subtype);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<blender::float3>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<blender::float3>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(blender::float3 *)r_value = ((bNodeSocketValueVector *)socket.default_value)->value;
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
static bNodeSocketType *make_socket_type_rgba()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_RGBA, PROP_NONE);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<blender::ColorGeometry4f>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() {
+ return &blender::fn::CPPType::get<blender::ColorGeometry4f>();
+ };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(blender::ColorGeometry4f *)r_value = ((bNodeSocketValueRGBA *)socket.default_value)->value;
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
static bNodeSocketType *make_socket_type_string()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_STRING, PROP_NONE);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<std::string>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<std::string>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
new (r_value) std::string(((bNodeSocketValueString *)socket.default_value)->value);
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
@@ -672,50 +686,60 @@ MAKE_CPP_TYPE(Material, Material *, CPPTypeFlags::BasicType)
static bNodeSocketType *make_socket_type_object()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_OBJECT, PROP_NONE);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<Object *>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<Object *>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(Object **)r_value = ((bNodeSocketValueObject *)socket.default_value)->value;
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
static bNodeSocketType *make_socket_type_geometry()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_GEOMETRY, PROP_NONE);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<GeometrySet>(); };
- socktype->get_cpp_value = [](const bNodeSocket &UNUSED(socket), void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<GeometrySet>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &UNUSED(socket), void *r_value) {
new (r_value) GeometrySet();
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
static bNodeSocketType *make_socket_type_collection()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_COLLECTION, PROP_NONE);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<Collection *>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<Collection *>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(Collection **)r_value = ((bNodeSocketValueCollection *)socket.default_value)->value;
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
static bNodeSocketType *make_socket_type_texture()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_TEXTURE, PROP_NONE);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<Tex *>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<Tex *>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(Tex **)r_value = ((bNodeSocketValueTexture *)socket.default_value)->value;
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
static bNodeSocketType *make_socket_type_material()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_MATERIAL, PROP_NONE);
- socktype->get_cpp_type = []() { return &blender::fn::CPPType::get<Material *>(); };
- socktype->get_cpp_value = [](const bNodeSocket &socket, void *r_value) {
+ socktype->get_base_cpp_type = []() { return &blender::fn::CPPType::get<Material *>(); };
+ socktype->get_base_cpp_value = [](const bNodeSocket &socket, void *r_value) {
*(Material **)r_value = ((bNodeSocketValueMaterial *)socket.default_value)->value;
};
+ socktype->get_geometry_nodes_cpp_type = socktype->get_base_cpp_type;
+ socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;
return socktype;
}
diff --git a/source/blender/nodes/intern/type_callbacks.cc b/source/blender/nodes/intern/type_callbacks.cc
index 5160432aea5..881a02c92e9 100644
--- a/source/blender/nodes/intern/type_callbacks.cc
+++ b/source/blender/nodes/intern/type_callbacks.cc
@@ -19,17 +19,9 @@
namespace blender::nodes {
-const CPPType *socket_cpp_type_get(const bNodeSocketType &stype)
-{
- if (stype.get_cpp_type != nullptr) {
- return stype.get_cpp_type();
- }
- return nullptr;
-}
-
std::optional<MFDataType> socket_mf_type_get(const bNodeSocketType &stype)
{
- const CPPType *cpp_type = socket_cpp_type_get(stype);
+ const CPPType *cpp_type = stype.get_base_cpp_type ? stype.get_base_cpp_type() : nullptr;
if (cpp_type != nullptr) {
return MFDataType::ForSingle(*cpp_type);
}
@@ -41,32 +33,23 @@ bool socket_is_mf_data_socket(const bNodeSocketType &stype)
if (!socket_mf_type_get(stype).has_value()) {
return false;
}
- if (stype.expand_in_mf_network == nullptr && stype.get_cpp_value == nullptr) {
+ if (stype.expand_in_mf_network == nullptr && stype.get_base_cpp_value == nullptr) {
return false;
}
return true;
}
-bool socket_cpp_value_get(const bNodeSocket &socket, void *r_value)
-{
- if (socket.typeinfo->get_cpp_value != nullptr) {
- socket.typeinfo->get_cpp_value(socket, r_value);
- return true;
- }
- return false;
-}
-
void socket_expand_in_mf_network(SocketMFNetworkBuilder &builder)
{
bNodeSocket &socket = builder.bsocket();
if (socket.typeinfo->expand_in_mf_network != nullptr) {
socket.typeinfo->expand_in_mf_network(builder);
}
- else if (socket.typeinfo->get_cpp_value != nullptr) {
- const CPPType &type = *socket_cpp_type_get(*socket.typeinfo);
+ else if (socket.typeinfo->get_base_cpp_value != nullptr) {
+ const CPPType &type = *socket.typeinfo->get_base_cpp_type();
void *buffer = builder.resource_scope().linear_allocator().allocate(type.size(),
type.alignment());
- socket.typeinfo->get_cpp_value(socket, buffer);
+ socket.typeinfo->get_base_cpp_value(socket, buffer);
builder.set_constant_value(type, buffer);
}
else {
diff --git a/source/blender/python/intern/bpy_app_translations.c b/source/blender/python/intern/bpy_app_translations.c
index 7437598582f..de70035eb2b 100644
--- a/source/blender/python/intern/bpy_app_translations.c
+++ b/source/blender/python/intern/bpy_app_translations.c
@@ -746,7 +746,7 @@ static PyObject *app_translations_new(PyTypeObject *type,
PyObject *UNUSED(args),
PyObject *UNUSED(kw))
{
- /* printf("%s (%p)\n", __func__, _translations); */
+ // printf("%s (%p)\n", __func__, _translations);
if (!_translations) {
_translations = (BlenderAppTranslations *)type->tp_alloc(type, 0);
diff --git a/source/blender/simulation/intern/implicit_blender.c b/source/blender/simulation/intern/implicit_blender.c
index 10a5f153662..ad903e9da4a 100644
--- a/source/blender/simulation/intern/implicit_blender.c
+++ b/source/blender/simulation/intern/implicit_blender.c
@@ -2204,7 +2204,7 @@ bool SIM_mass_spring_force_spring_bending_hair(Implicit_Data *data,
world_to_root_v3(data, j, goal, target);
spring_hairbend_forces(data, i, j, k, goal, stiffness, damping, k, vecnull, vecnull, fk);
- negate_v3_v3(fj, fk); /* counterforce */
+ negate_v3_v3(fj, fk); /* Counter-force. */
spring_hairbend_estimate_dfdx(data, i, j, k, goal, stiffness, damping, i, dfk_dxi);
spring_hairbend_estimate_dfdx(data, i, j, k, goal, stiffness, damping, j, dfk_dxj);
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index c0d408be2e0..136c639caea 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -34,6 +34,7 @@
#include "BLI_sys_types.h"
#include "DNA_windowmanager_types.h"
#include "WM_keymap.h"
+#include "WM_types.h"
#ifdef __cplusplus
extern "C" {
@@ -705,13 +706,13 @@ void WM_event_drag_image(struct wmDrag *, struct ImBuf *, float scale, int sx, i
void WM_drag_free(struct wmDrag *drag);
void WM_drag_data_free(int dragtype, void *poin);
void WM_drag_free_list(struct ListBase *lb);
-
struct wmDropBox *WM_dropbox_add(
ListBase *lb,
const char *idname,
- bool (*poll)(struct bContext *, struct wmDrag *, const struct wmEvent *event, const char **),
+ bool (*poll)(struct bContext *, struct wmDrag *, const struct wmEvent *event),
void (*copy)(struct wmDrag *, struct wmDropBox *),
- void (*cancel)(struct Main *, struct wmDrag *, struct wmDropBox *));
+ void (*cancel)(struct Main *, struct wmDrag *, struct wmDropBox *),
+ WMDropboxTooltipFunc tooltip);
ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid);
/* ID drag and drop */
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 4ead0b2699c..4d6cb941347 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -114,6 +114,7 @@ struct bContext;
struct wmEvent;
struct wmOperator;
struct wmWindowManager;
+struct wmDrag;
#include "BLI_compiler_attrs.h"
#include "DNA_listBase.h"
@@ -934,6 +935,10 @@ typedef struct wmDragAsset {
int import_type; /* eFileAssetImportType */
} wmDragAsset;
+typedef char *(*WMDropboxTooltipFunc)(struct bContext *,
+ struct wmDrag *,
+ const struct wmEvent *event);
+
typedef struct wmDrag {
struct wmDrag *next, *prev;
@@ -949,8 +954,8 @@ typedef struct wmDrag {
float scale;
int sx, sy;
- /** If set, draws operator name. */
- char opname[200];
+ /** If filled, draws operator tooltip/operator name. */
+ char tooltip[200];
unsigned int flags;
/** List of wmDragIDs, all are guaranteed to have the same ID type. */
@@ -964,8 +969,8 @@ typedef struct wmDrag {
typedef struct wmDropBox {
struct wmDropBox *next, *prev;
- /** Test if the dropbox is active, then can print optype name. */
- bool (*poll)(struct bContext *, struct wmDrag *, const wmEvent *, const char **);
+ /** Test if the dropbox is active. */
+ bool (*poll)(struct bContext *, struct wmDrag *, const wmEvent *);
/** Before exec, this copies drag info to #wmDrop properties. */
void (*copy)(struct wmDrag *, struct wmDropBox *);
@@ -976,6 +981,9 @@ typedef struct wmDropBox {
*/
void (*cancel)(struct Main *, struct wmDrag *, struct wmDropBox *);
+ /** Custom tooltip shown during dragging. */
+ WMDropboxTooltipFunc tooltip;
+
/**
* If poll succeeds, operator is called.
* Not saved in file, so can be pointer.
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index db72dd2a819..c58d3c53e03 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -96,14 +96,16 @@ ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
wmDropBox *WM_dropbox_add(ListBase *lb,
const char *idname,
- bool (*poll)(bContext *, wmDrag *, const wmEvent *, const char **),
+ bool (*poll)(bContext *, wmDrag *, const wmEvent *),
void (*copy)(wmDrag *, wmDropBox *),
- void (*cancel)(struct Main *, wmDrag *, wmDropBox *))
+ void (*cancel)(struct Main *, wmDrag *, wmDropBox *),
+ WMDropboxTooltipFunc tooltip)
{
wmDropBox *drop = MEM_callocN(sizeof(wmDropBox), "wmDropBox");
drop->poll = poll;
drop->copy = copy;
drop->cancel = cancel;
+ drop->tooltip = tooltip;
drop->ot = WM_operatortype_find(idname, 0);
drop->opcontext = WM_OP_INVOKE_DEFAULT;
@@ -218,22 +220,36 @@ void WM_drag_free_list(struct ListBase *lb)
}
}
-static const char *dropbox_active(bContext *C,
- ListBase *handlers,
- wmDrag *drag,
- const wmEvent *event)
+static char *dropbox_tooltip(bContext *C,
+ wmDrag *drag,
+ const wmEvent *event,
+ const wmDropBox *drop)
+{
+ char *tooltip = NULL;
+ if (drop->tooltip) {
+ tooltip = drop->tooltip(C, drag, event);
+ }
+ if (!tooltip) {
+ tooltip = BLI_strdup(WM_operatortype_name(drop->ot, drop->ptr));
+ }
+ /* XXX Doing translation here might not be ideal, but later we have no more
+ * access to ot (and hence op context)... */
+ return tooltip;
+}
+
+static wmDropBox *dropbox_active(bContext *C,
+ ListBase *handlers,
+ wmDrag *drag,
+ const wmEvent *event)
{
LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
if (handler_base->type == WM_HANDLER_TYPE_DROPBOX) {
wmEventHandler_Dropbox *handler = (wmEventHandler_Dropbox *)handler_base;
if (handler->dropboxes) {
LISTBASE_FOREACH (wmDropBox *, drop, handler->dropboxes) {
- const char *tooltip = NULL;
- if (drop->poll(C, drag, event, &tooltip) &&
+ if (drop->poll(C, drag, event) &&
WM_operator_poll_context(C, drop->ot, drop->opcontext)) {
- /* XXX Doing translation here might not be ideal, but later we have no more
- * access to ot (and hence op context)... */
- return (tooltip) ? tooltip : WM_operatortype_name(drop->ot, drop->ptr);
+ return drop;
}
}
}
@@ -242,29 +258,22 @@ static const char *dropbox_active(bContext *C,
return NULL;
}
-/* return active operator name when mouse is in box */
-static const char *wm_dropbox_active(bContext *C, wmDrag *drag, const wmEvent *event)
+/* return active operator tooltip/name when mouse is in box */
+static char *wm_dropbox_active(bContext *C, wmDrag *drag, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
- ScrArea *area = CTX_wm_area(C);
- ARegion *region = CTX_wm_region(C);
- const char *name;
-
- name = dropbox_active(C, &win->handlers, drag, event);
- if (name) {
- return name;
+ wmDropBox *drop = dropbox_active(C, &win->handlers, drag, event);
+ if (!drop) {
+ ScrArea *area = CTX_wm_area(C);
+ drop = dropbox_active(C, &area->handlers, drag, event);
}
-
- name = dropbox_active(C, &area->handlers, drag, event);
- if (name) {
- return name;
+ if (!drop) {
+ ARegion *region = CTX_wm_region(C);
+ drop = dropbox_active(C, &region->handlers, drag, event);
}
-
- name = dropbox_active(C, &region->handlers, drag, event);
- if (name) {
- return name;
+ if (drop) {
+ return dropbox_tooltip(C, drag, event, drop);
}
-
return NULL;
}
@@ -279,17 +288,18 @@ static void wm_drop_operator_options(bContext *C, wmDrag *drag, const wmEvent *e
return;
}
- drag->opname[0] = 0;
+ drag->tooltip[0] = 0;
/* check buttons (XXX todo rna and value) */
if (UI_but_active_drop_name(C)) {
- BLI_strncpy(drag->opname, IFACE_("Paste name"), sizeof(drag->opname));
+ BLI_strncpy(drag->tooltip, IFACE_("Paste name"), sizeof(drag->tooltip));
}
else {
- const char *opname = wm_dropbox_active(C, drag, event);
+ char *tooltip = wm_dropbox_active(C, drag, event);
- if (opname) {
- BLI_strncpy(drag->opname, opname, sizeof(drag->opname));
+ if (tooltip) {
+ BLI_strncpy(drag->tooltip, tooltip, sizeof(drag->tooltip));
+ MEM_freeN(tooltip);
// WM_cursor_modal_set(win, WM_CURSOR_COPY);
}
// else
@@ -584,7 +594,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
}
/* operator name with roundbox */
- if (drag->opname[0]) {
+ if (drag->tooltip[0]) {
if (drag->imb) {
x = cursorx - drag->sx / 2;
@@ -611,7 +621,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
drag_rect_minmax(rect, x, y, x + w, y + iconsize);
}
else {
- wm_drop_operator_draw(drag->opname, x, y);
+ wm_drop_operator_draw(drag->tooltip, x, y);
}
}
}
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 5e29a22304c..5cc361fc1bd 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -2851,8 +2851,7 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
if (event->custom == EVT_DATA_DRAGDROP) {
ListBase *lb = (ListBase *)event->customdata;
LISTBASE_FOREACH (wmDrag *, drag, lb) {
- const char *tooltip = NULL;
- if (drop->poll(C, drag, event, &tooltip)) {
+ if (drop->poll(C, drag, event)) {
/* Optionally copy drag information to operator properties. Don't call it if the
* operator fails anyway, it might do more than just set properties (e.g.
* typically import an asset). */
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 06aaf95f232..92f3eb67783 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -797,6 +797,7 @@ static void file_read_reports_finalize(BlendFileReadReport *bf_reports)
bf_reports->count.resynced_lib_overrides,
duration_lib_override_recursive_resync_minutes,
duration_lib_override_recursive_resync_seconds);
+
if (bf_reports->resynced_lib_overrides_libraries_count != 0) {
for (LinkNode *node_lib = bf_reports->resynced_lib_overrides_libraries; node_lib != NULL;
node_lib = node_lib->next) {
@@ -805,14 +806,22 @@ static void file_read_reports_finalize(BlendFileReadReport *bf_reports)
bf_reports->reports, RPT_INFO, "Library %s needs overrides resync.", library->filepath);
}
}
+
if (bf_reports->count.missing_libraries != 0 || bf_reports->count.missing_linked_id != 0) {
BKE_reportf(bf_reports->reports,
RPT_WARNING,
- "%d libraries and %d linked data-blocks are missing, please check the "
- "Info and Outliner editors for details",
+ "%d libraries and %d linked data-blocks are missing (including %d ObjectData and "
+ "%d Proxies), please check the Info and Outliner editors for details",
bf_reports->count.missing_libraries,
- bf_reports->count.missing_linked_id);
+ bf_reports->count.missing_linked_id,
+ bf_reports->count.missing_obdata,
+ bf_reports->count.missing_obproxies);
}
+ else {
+ BLI_assert(bf_reports->count.missing_obdata == 0);
+ BLI_assert(bf_reports->count.missing_obproxies == 0);
+ }
+
if (bf_reports->resynced_lib_overrides_libraries_count != 0) {
BKE_reportf(bf_reports->reports,
RPT_WARNING,
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 1b08b8dad92..8f37e7f34a9 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -1416,7 +1416,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
wm_event_add(win, &event);
- /* printf("Drop detected\n"); */
+ // printf("Drop detected\n");
/* add drag data to wm for paths: */