59#ifdef USE_MODIFIER_VALIDATE
60# define ASSERT_IS_VALID_MESH_INPUT(mesh) (BLI_assert(BKE_mesh_is_valid(mesh) == true))
61# define ASSERT_IS_VALID_MESH_OUTPUT(mesh) \
62 (BLI_assert((mesh == nullptr) || (BKE_mesh_is_valid(mesh) == true)))
64# define ASSERT_IS_VALID_MESH_INPUT(mesh) \
68# define ASSERT_IS_VALID_MESH_OUTPUT(mesh) \
116 if (kb && kb->
data) {
146 orco_mesh->vert_positions_for_write().copy_from(orco);
147 orco_mesh->tag_positions_changed();
165 const Mesh *mesh_orco,
168 const int totvert =
mesh.verts_num;
175 layer_orco.
copy_from(mesh_orco->vert_positions());
225 Mesh *mesh_output =
nullptr;
246 if (mesh_component.
get() != input_mesh) {
250 mesh_output = mesh_component.
release();
257 if (mesh_output ==
nullptr) {
270 attributes.
remove(
"rest_position");
288 const bool use_deform,
289 const bool need_mapping,
291 const bool use_cache,
292 const bool allow_shared_mesh,
303 Mesh *mesh_deform =
nullptr;
312 Mesh *mesh_orco =
nullptr;
313 Mesh *mesh_orco_cloth =
nullptr;
321 bool multires_applied =
false;
323 const bool sculpt_dyntopo = (sculpt_mode && ob.
sculpt->
bm) && !use_render;
351 if (
mesh ==
nullptr) {
361 for (; md; md = md->
next, md_datamask = md_datamask->
next) {
400 bool have_non_onlydeform_modifiers_applied =
false;
401 for (; md; md = md->
next, md_datamask = md_datamask->
next) {
413 have_non_onlydeform_modifiers_applied)
419 if (sculpt_mode && (!has_multires || multires_applied || sculpt_dyntopo)) {
420 bool unsupported =
false;
424 if (!sculpt_dyntopo) {
429 if (sculpt_dyntopo) {
437 unsupported |= multires_applied;
440 if (sculpt_dyntopo) {
474 bool check_for_needs_mapping =
false;
475 if (
mesh !=
nullptr) {
476 if (have_non_onlydeform_modifiers_applied ==
false) {
479 check_for_needs_mapping =
true;
486 check_for_needs_mapping =
true;
489 have_non_onlydeform_modifiers_applied =
true;
494 if (check_for_needs_mapping) {
559 if (
mesh != mesh_next) {
591 if (mesh_orco != mesh_next) {
596 mesh_orco = mesh_next;
602 if (!mesh_orco_cloth) {
618 if (mesh_orco_cloth != mesh_next) {
623 mesh_orco_cloth = mesh_next;
627 mesh->runtime->deformed_only =
false;
631 multires_applied =
true;
637 for (md = firstmd; md; md = md->
next) {
641 if (
mesh ==
nullptr) {
642 if (allow_shared_mesh) {
652 const bool is_own_mesh = (
mesh != &mesh_input);
670 if (mesh_orco_cloth) {
685 std::lock_guard
lock{mesh_input.
runtime->eval_mutex};
709 *r_deform = mesh_deform;
711 if (r_geometry_set) {
712 *r_geometry_set =
new GeometrySet(std::move(geometry_set_final));
738 switch (
mesh->runtime->wrapper_type) {
740 if (
mesh->runtime->edit_data->vert_positions.is_empty()) {
742 mesh->runtime->edit_mesh->bm);
744 return mesh->runtime->edit_data->vert_positions;
747 return mesh->vert_positions_for_write();
765 Mesh *mesh_cage =
nullptr;
772 Mesh *mesh_orco =
nullptr;
798 mesh_input.
runtime->edit_mesh, &final_datamask, &mesh_input);
801 if (r_cage && cageIndex == -1) {
819 bool non_deform_modifier_applied =
false;
820 for (
int i = 0; md;
i++, md = md->
next, md_datamask = md_datamask->
next) {
837 if (
mesh == mesh_cage) {
842 if (mesh_cage->
runtime->edit_mesh) {
843 mesh->runtime->is_original_bmesh =
true;
844 mesh->runtime->deformed_only = mesh_cage->
runtime->deformed_only;
845 if (mesh_cage->
runtime->edit_data) {
846 mesh->runtime->edit_data = std::make_unique<EditMeshData>(
847 *mesh_cage->
runtime->edit_data);
861 mesh->tag_positions_changed();
865 non_deform_modifier_applied =
true;
886 if (mesh_orco && mesh_orco != mesh_next) {
889 mesh_orco = mesh_next;
917 if (
mesh != mesh_next) {
922 mesh->runtime->deformed_only =
false;
925 if (r_cage &&
i == cageIndex) {
949 if (r_geometry_set) {
950 *r_geometry_set =
new GeometrySet(std::move(geometry_set_final));
956 const Mesh &mesh_eval)
969 const bool need_mapping)
980 Mesh *mesh_eval =
nullptr, *mesh_deform_eval =
nullptr;
1001 const bool is_mesh_eval_owned = (mesh_eval !=
mesh->runtime->mesh_eval);
1007 ob.
runtime->geometry_set_eval = geometry_set_eval;
1009 ob.
runtime->mesh_deform_eval = mesh_deform_eval;
1010 ob.
runtime->last_data_mask = dataMask;
1011 ob.
runtime->last_need_mapping = need_mapping;
1039 depsgraph, scene, obedit, dataMask, &me_cage, &me_final, &geometry_set_eval);
1041 const bool is_mesh_eval_owned = (me_final !=
mesh->runtime->mesh_eval);
1047 obedit.
runtime->geometry_set_eval = geometry_set_eval;
1055 obedit.
runtime->editmesh_eval_cage = me_cage;
1057 obedit.
runtime->last_data_mask = dataMask;
1063 bool *r_need_mapping)
1070 if (r_need_mapping) {
1071 *r_need_mapping =
false;
1089 if (r_need_mapping) {
1143 if (
mesh->runtime->edit_mesh) {
1157 if (em !=
nullptr) {
1161 BLI_assert_msg(0,
"Request of deformed mesh of object which is in edit mode");
1179 if (!ob->
runtime->mesh_deform_eval ||
1181 (need_mapping && !ob->
runtime->last_need_mapping))
1188 *
depsgraph, *scene, *ob, cddata_masks, need_mapping || ob->
runtime->last_need_mapping);
1191 return ob->
runtime->mesh_deform_eval;
1201 *
depsgraph, *scene, *ob,
true,
false, *dataMask,
false,
false,
nullptr, &
result,
nullptr);
1212 *
depsgraph, *scene, *ob,
false,
false, *dataMask,
false,
false,
nullptr, &
result,
nullptr);
1223 *
depsgraph, *scene, *ob,
false,
false, *dataMask,
false,
false,
nullptr, &
result,
nullptr);
1239 if (!obedit->
runtime->editmesh_eval_cage ||
1248 return obedit->
runtime->editmesh_eval_cage;
1283 if (mesh_eval->
runtime->deformed_only ==
false) {
1297 const float default_osf[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1309 for (
const int i :
faces.index_range()) {
1314 for (j = 0; j < face.
size(); j++, lof++) {
1323 float translate[2], scale[2];
1330 for (j = 0; j < face.
size(); j++) {
1331 mul_v3_m3v3(co, mat, positions[corner_verts[face[j]]]);
1334 for (k = 0; k < 2; k++) {
1335 if (co[k] >
max[k]) {
1338 else if (co[k] <
min[k]) {
1349 if (scale[0] == 0.0f) {
1352 if (scale[1] == 0.0f) {
1359 for (j = 0; j < face.
size(); j++, lof++) {
void CustomData_set_only_copy(const CustomData *data, eCustomDataMask mask)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
const CustomData_MeshMasks CD_MASK_BAREMESH_ORIGINDEX
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
bool CustomData_MeshMasks_are_matching(const CustomData_MeshMasks *mask_ref, const CustomData_MeshMasks *mask_required)
const CustomData_MeshMasks CD_MASK_BAREMESH
void CustomData_free_layers(CustomData *data, eCustomDataType type)
void * CustomData_get_layer_for_write(CustomData *data, eCustomDataType type, int totelem)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
KeyBlock * BKE_keyblock_find_by_index(Key *key, int index)
Key * BKE_key_from_object(Object *ob)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
void BKE_id_free(Main *bmain, void *idv)
General operations, lookup, etc. for materials.
void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
void BKE_mesh_tessface_clear(Mesh *mesh)
blender::Array< blender::float3 > BKE_mesh_orco_verts_get(const Object *ob)
void BKE_mesh_orco_verts_transform(Mesh *mesh, blender::MutableSpan< blender::float3 > orco, bool invert)
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
Mesh * BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
void BKE_mesh_ensure_default_orig_index_customdata(Mesh *mesh)
void BKE_mesh_foreach_mapped_vert(const Mesh *mesh, void(*func)(void *user_data, int index, const float co[3], const float no[3]), void *user_data, MeshForeachFlag flag)
blender::Span< blender::float3 > BKE_mesh_wrapper_vert_coords(const Mesh *mesh)
Mesh * BKE_mesh_wrapper_from_editmesh(std::shared_ptr< BMEditMesh > em, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
void BKE_mesh_wrapper_tag_positions_changed(Mesh *mesh)
void BKE_modifiers_clear_errors(Object *ob)
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
int BKE_modifiers_get_cage_index(const Scene *scene, Object *ob, int *r_lastPossibleCageIndex, bool is_virtual)
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
CDMaskLink * BKE_modifier_calc_data_masks(const Scene *scene, ModifierData *md, CustomData_MeshMasks *final_datamask, int required_mode)
@ eModifierTypeFlag_RequiresOriginalData
bool BKE_modifier_supports_mapping(ModifierData *md)
void BKE_modifier_free_temporary_data(ModifierData *md)
Mesh * BKE_modifier_modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
void BKE_modifier_set_error(const Object *ob, ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
bool BKE_modifier_deform_verts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, blender::MutableSpan< blender::float3 > positions)
void BKE_modifier_deform_vertsEM(ModifierData *md, const ModifierEvalContext *ctx, const BMEditMesh *em, Mesh *mesh, blender::MutableSpan< blender::float3 > positions)
ModifierData * BKE_modifiers_get_virtual_modifierlist(const Object *ob, VirtualModifierData *data)
General operations, lookup, etc. for blender objects.
void BKE_object_eval_assign_data(Object *object, ID *data, bool is_owned)
void BKE_object_free_derived_caches(Object *ob)
void BKE_sculpt_update_object_after_eval(Depsgraph *depsgraph, Object *ob_eval)
void BKE_sculpt_update_object_before_eval(Object *ob_eval)
MultiresModifierData * BKE_sculpt_multires_active(const Scene *scene, Object *ob)
bool BKE_paint_select_face_test(const Object *ob)
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc)
void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3])
Normal to x,y matrix.
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
MINLINE void mul_v2_v2(float r[2], const float a[2])
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void negate_v2_v2(float r[2], const float a[2])
void range_vn_i(int *array_tar, int size, int start)
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void invert_v2(float r[2])
char * STRNCPY(char(&dst)[N], const char *src)
bool DEG_is_evaluating(const Depsgraph *depsgraph)
@ DAG_EVAL_NEED_SHRINKWRAP_BOUNDARY
bool DEG_is_active(const Depsgraph *depsgraph)
uint32_t DEG_get_eval_flags_for_id(const Depsgraph *graph, const ID *id)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
bool DEG_is_evaluated(const T *id)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
T * DEG_get_original(T *id)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void DEG_get_customdata_mask_for_object(const Depsgraph *graph, Object *object, CustomData_MeshMasks *r_mask)
@ ID_TAG_COPIED_ON_EVAL_FINAL_RESULT
#define CD_MASK_PROP_BYTE_COLOR
#define CD_MASK_ORIGINDEX
#define CD_MASK_MDEFORMVERT
#define CD_MASK_MVERT_SKIN
#define CD_MASK_PROP_FLOAT2
#define CD_MASK_ORIGSPACE_MLOOP
#define CD_MASK_CLOTH_ORCO
#define OB_MODE_ALL_SCULPT
Object is a sort of wrapper for general info.
@ OB_MODIFIER_FLAG_ADD_REST_POSITION
BMesh const char void * data
Array< float3 > BM_mesh_vert_coords_alloc(BMesh *bm)
BPy_StructRNA * depsgraph
constexpr int64_t size() const
constexpr int64_t start() const
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr void fill(const T &value) const
constexpr void copy_from(Span< T > values) const
constexpr Span slice(int64_t start, int64_t size) const
constexpr bool is_empty() const
void resize(const int64_t new_size)
void resize(const int64_t new_size_in_bits, const bool value=false)
GAttributeReader lookup(const StringRef attribute_id) const
void ensure_owns_direct_data() override
void replace(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
bool add(const StringRef attribute_id, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
bool remove(const StringRef attribute_id)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
#define ASSERT_IS_VALID_MESH_INPUT(mesh)
#define ASSERT_IS_VALID_MESH_OUTPUT(mesh)
float3 face_normal_calc(Span< float3 > vert_positions, Span< int > face_verts)
const ShrinkwrapBoundaryData & boundary_cache_ensure(const Mesh &mesh)
static void add_orco_mesh(Object &ob, const BMEditMesh *em, Mesh &mesh, const Mesh *mesh_orco, const eCustomDataType layer)
static Mesh * create_orco_mesh(const Object &ob, const Mesh &mesh, const BMEditMesh *em, eCustomDataType layer)
Mesh * editbmesh_get_eval_cage(Depsgraph *depsgraph, const Scene *scene, Object *obedit, BMEditMesh *em, const CustomData_MeshMasks *dataMask)
static void mesh_build_data(Depsgraph &depsgraph, const Scene &scene, Object &ob, const CustomData_MeshMasks &dataMask, const bool need_mapping)
static void object_get_datamask(const Depsgraph &depsgraph, Object &ob, CustomData_MeshMasks &r_mask, bool *r_need_mapping)
Mesh * mesh_create_eval_no_deform_render(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
static void editbmesh_calc_modifiers(Depsgraph &depsgraph, const Scene &scene, Object &ob, const CustomData_MeshMasks &dataMask, Mesh **r_cage, Mesh **r_final, GeometrySet **r_geometry_set)
static void mesh_init_origspace(Mesh &mesh)
Mesh * mesh_create_eval_no_deform(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
static Span< float3 > get_orco_coords(const Object &ob, const BMEditMesh *em, eCustomDataType layer_type, Array< float3 > &storage)
static Mesh * modifier_modify_mesh_and_geometry_set(ModifierData *md, const ModifierEvalContext &mectx, Mesh *input_mesh, GeometrySet &geometry_set)
static void mesh_calc_finalize(const Mesh &mesh_input, Mesh &mesh_eval)
static void make_vertexcos__mapFunc(void *user_data, int index, const float co[3], const float[3])
bool editbmesh_modifier_is_enabled(const Scene *scene, const Object *ob, ModifierData *md, bool has_prev_mesh)
static void mesh_build_extra_data(const Depsgraph &depsgraph, const Object &ob, const Mesh &mesh_eval)
static void mesh_set_only_copy(Mesh *mesh, const CustomData_MeshMasks *mask)
static MutableSpan< float3 > orco_coord_layer_ensure(Mesh &mesh, const eCustomDataType layer)
Mesh * editbmesh_get_eval_cage_from_orig(Depsgraph *depsgraph, const Scene *scene, Object *obedit, const CustomData_MeshMasks *dataMask)
Mesh * mesh_get_eval_deform(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
static void editbmesh_build_data(Depsgraph &depsgraph, const Scene &scene, Object &obedit, CustomData_MeshMasks &dataMask)
void mesh_data_update(Depsgraph &depsgraph, const Scene &scene, Object &ob, const CustomData_MeshMasks &dataMask)
static void mesh_calc_modifiers(Depsgraph &depsgraph, const Scene &scene, Object &ob, const bool use_deform, const bool need_mapping, const CustomData_MeshMasks &dataMask, const bool use_cache, const bool allow_shared_mesh, Mesh **r_deform, Mesh **r_final, GeometrySet **r_geometry_set)
void mesh_get_mapped_verts_coords(Mesh *mesh_eval, MutableSpan< float3 > r_cos)
static MutableSpan< float3 > mesh_wrapper_vert_coords_ensure_for_write(Mesh *mesh)
Mesh * mesh_create_eval_final(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
static void set_rest_position(Mesh &mesh)
void isolate_task(const Function &function)
VecBase< float, 3 > float3
CustomData_MeshMasks mask
struct ClothSimSettings * sim_parms
MeshRuntimeHandle * runtime
struct ModifierData * next
void(* modify_geometry_set)(ModifierData *md, const ModifierEvalContext *ctx, blender::bke::GeometrySet *geometry_set)
void(* required_data_mask)(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
void(* deform_verts_EM)(ModifierData *md, const ModifierEvalContext *ctx, const BMEditMesh *em, Mesh *mesh, blender::MutableSpan< blender::float3 > positions)
ObjectRuntimeHandle * runtime
struct SculptSession * sculpt
struct ToolSettings * toolsettings
const ImplicitSharingInfo * sharing_info
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
bool has(const GeometryComponent::Type component_type) const
void ensure_owns_direct_data()
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
MutableSpan< float3 > vertexcos