Cleanup: Use const for evaluated cage meshes and related data

Also access the evaluated deform mesh with a function rather than
directly from object runtime data. The goal is to make it easier to use
implicit sharing for these meshes and to improve overall const
correctness.
This commit is contained in:
Hans Goudey 2024-03-28 18:57:57 -04:00
parent 510874f7b9
commit 82b88f130a
44 changed files with 202 additions and 185 deletions

View File

@ -210,7 +210,7 @@ rbCollisionShape *RB_shape_new_cylinder(float radius, float height);
/* Setup (Convex Hull) ------------ */
rbCollisionShape *RB_shape_new_convex_hull(
float *verts, int stride, int count, float margin, bool *can_embed);
const float *verts, int stride, int count, float margin, bool *can_embed);
/* Setup (Triangle Mesh) ---------- */

View File

@ -712,7 +712,7 @@ rbCollisionShape *RB_shape_new_cylinder(float radius, float height)
/* Setup (Convex Hull) ------------ */
rbCollisionShape *RB_shape_new_convex_hull(
float *verts, int stride, int count, float margin, bool *can_embed)
const float *verts, int stride, int count, float margin, bool *can_embed)
{
btConvexHullComputer hull_computer = btConvexHullComputer();
@ -800,7 +800,7 @@ rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh)
}
void RB_shape_trimesh_update(rbCollisionShape *shape,
float *vertices,
const float *vertices,
int num_verts,
int vert_stride,
const float min[3],

View File

@ -53,7 +53,7 @@ void BKE_mesh_calc_loop_tangent_ex(const float (*vert_positions)[3],
uint corner_tris_len,
const blender::Span<bool> sharp_faces,
CustomData *loopdata,
const CustomData *loopdata,
bool calc_active_tangent,
const char (*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME],
int tangent_names_len,
@ -72,7 +72,7 @@ void BKE_mesh_calc_loop_tangents(Mesh *mesh_eval,
int tangent_names_len);
/* Helpers */
void BKE_mesh_add_loop_tangent_named_layer_for_uv(CustomData *uv_data,
void BKE_mesh_add_loop_tangent_named_layer_for_uv(const CustomData *uv_data,
CustomData *tan_data,
int numLoopData,
const char *layer_name);

View File

@ -242,11 +242,11 @@ Object *BKE_object_duplicate(Main *bmain,
*/
void BKE_object_obdata_size_init(Object *ob, float size);
void BKE_object_scale_to_mat3(Object *ob, float r_mat[3][3]);
void BKE_object_scale_to_mat3(const Object *ob, float r_mat[3][3]);
void BKE_object_rot_to_mat3(const Object *ob, float r_mat[3][3], bool use_drot);
void BKE_object_mat3_to_rot(Object *ob, float r_mat[3][3], bool use_compat);
void BKE_object_to_mat3(Object *ob, float r_mat[3][3]);
void BKE_object_to_mat4(Object *ob, float r_mat[4][4]);
void BKE_object_to_mat3(const Object *ob, float r_mat[3][3]);
void BKE_object_to_mat4(const Object *ob, float r_mat[4][4]);
/**
* Applies the global transformation \a mat to the \a ob using a relative parent space if
* supplied.
@ -319,7 +319,7 @@ blender::Vector<Base *> BKE_object_pose_base_array_get(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d);
void BKE_object_get_parent_matrix(Object *ob, Object *par, float r_parentmat[4][4]);
void BKE_object_get_parent_matrix(const Object *ob, Object *par, float r_parentmat[4][4]);
/**
* Compute object world transform and store it in `ob->object_to_world().ptr()`.
@ -334,7 +334,7 @@ void BKE_object_where_is_calc_time(Depsgraph *depsgraph, Scene *scene, Object *o
* No changes to object and its parent would be done.
* Used for bundles orientation in 3d space relative to parented blender camera.
*/
void BKE_object_where_is_calc_mat4(Object *ob, float r_obmat[4][4]);
void BKE_object_where_is_calc_mat4(const Object *ob, float r_obmat[4][4]);
/* Possibly belong in its own module? */
@ -522,8 +522,9 @@ Mesh *BKE_object_get_pre_modified_mesh(const Object *object);
*/
Mesh *BKE_object_get_original_mesh(const Object *object);
Mesh *BKE_object_get_editmesh_eval_final(const Object *object);
Mesh *BKE_object_get_editmesh_eval_cage(const Object *object);
const Mesh *BKE_object_get_editmesh_eval_final(const Object *object);
const Mesh *BKE_object_get_editmesh_eval_cage(const Object *object);
const Mesh *BKE_object_get_mesh_deform_eval(const Object *object);
/* Lattice accessors.
* These functions return either the regular lattice, or the edit-mode lattice,
@ -576,7 +577,7 @@ bool BKE_object_moves_in_time(const Object *object, bool recurse_parent);
/** Return the number of scenes using (instantiating) that object in their collections. */
int BKE_object_scenes_users_get(Main *bmain, Object *ob);
MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, bool use_default);
MovieClip *BKE_object_movieclip_get(Scene *scene, const Object *ob, bool use_default);
void BKE_object_runtime_reset(Object *object);
/**

View File

@ -75,7 +75,7 @@ void BKE_tracking_settings_init(struct MovieTracking *tracking);
* Get transformation matrix for a given object which is used
* for parenting motion tracker reconstruction to 3D world.
*/
void BKE_tracking_get_camera_object_matrix(struct Object *camera_object, float mat[4][4]);
void BKE_tracking_get_camera_object_matrix(const struct Object *camera_object, float mat[4][4]);
/**
* Get projection matrix for camera specified by given tracking object
* and frame number.

View File

@ -173,9 +173,9 @@ Span<float3> BKE_editmesh_vert_coords_when_deformed(
Depsgraph *depsgraph, BMEditMesh *em, Scene *scene, Object *ob, Array<float3> &r_alloc)
{
Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object_eval);
Mesh *mesh_cage = BKE_object_get_editmesh_eval_cage(ob);
const Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object_eval);
const Mesh *mesh_cage = BKE_object_get_editmesh_eval_cage(ob);
Span<float3> vert_positions;
if (mesh_cage && mesh_cage->runtime->deformed_only) {

View File

@ -727,13 +727,13 @@ Material *BKE_object_material_get(Object *ob, short act)
return ma_p ? *ma_p : nullptr;
}
static ID *get_evaluated_object_data_with_materials(Object *ob)
static const ID *get_evaluated_object_data_with_materials(Object *ob)
{
ID *data = static_cast<ID *>(ob->data);
const ID *data = static_cast<ID *>(ob->data);
/* Meshes in edit mode need special handling. */
if (ob->type == OB_MESH && ob->mode == OB_MODE_EDIT) {
Mesh *mesh = static_cast<Mesh *>(ob->data);
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
const Mesh *mesh = static_cast<const Mesh *>(ob->data);
const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
if (mesh->runtime->edit_mesh && editmesh_eval_final) {
data = &editmesh_eval_final->id;
}
@ -745,8 +745,8 @@ Material *BKE_object_material_get_eval(Object *ob, short act)
{
BLI_assert(DEG_is_evaluated_object(ob));
ID *data = get_evaluated_object_data_with_materials(ob);
const short *tot_slots_data_ptr = BKE_id_material_len_p(data);
const ID *data = get_evaluated_object_data_with_materials(ob);
const short *tot_slots_data_ptr = BKE_id_material_len_p(const_cast<ID *>(data));
const int tot_slots_data = tot_slots_data_ptr ? *tot_slots_data_ptr : 0;
if (tot_slots_data == 0) {
@ -757,7 +757,7 @@ Material *BKE_object_material_get_eval(Object *ob, short act)
const int slot_index = clamp_i(act - 1, 0, tot_slots_data - 1);
const int tot_slots_object = ob->totcol;
Material ***materials_data_ptr = BKE_id_material_array_p(data);
Material ***materials_data_ptr = BKE_id_material_array_p(const_cast<ID *>(data));
Material **materials_data = materials_data_ptr ? *materials_data_ptr : nullptr;
Material **materials_object = ob->mat;

View File

@ -769,15 +769,15 @@ static Mesh *mesh_new_from_mball_object(Object *object)
return BKE_mesh_copy_for_eval(mesh_eval);
}
static Mesh *mesh_new_from_mesh(Object *object, Mesh *mesh)
static Mesh *mesh_new_from_mesh(Object *object, const Mesh *mesh)
{
/* While we could copy this into the new mesh,
* add the data to 'mesh' so future calls to this function don't need to re-convert the data. */
if (mesh->runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH) {
BKE_mesh_wrapper_ensure_mdata(mesh);
BKE_mesh_wrapper_ensure_mdata(const_cast<Mesh *>(mesh));
}
else {
mesh = BKE_mesh_wrapper_ensure_subdivision(mesh);
mesh = BKE_mesh_wrapper_ensure_subdivision(const_cast<Mesh *>(mesh));
}
Mesh *mesh_result = (Mesh *)BKE_id_copy_ex(
@ -828,12 +828,11 @@ static Mesh *mesh_new_from_mesh_object(Depsgraph *depsgraph,
if (preserve_all_data_layers || preserve_origindex) {
return mesh_new_from_mesh_object_with_layers(depsgraph, object, preserve_origindex);
}
Mesh *mesh_input = (Mesh *)object->data;
const Mesh *mesh_input = (const Mesh *)object->data;
/* If we are in edit mode, use evaluated mesh from edit structure, matching to what
* viewport is using for visualization. */
if (mesh_input->runtime->edit_mesh != nullptr) {
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object);
if (editmesh_eval_final != nullptr) {
if (const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object)) {
mesh_input = editmesh_eval_final;
}
}

View File

@ -297,7 +297,7 @@ static void DM_calc_loop_tangents_thread(TaskPool *__restrict /*pool*/, void *ta
mikk.genTangSpace();
}
void BKE_mesh_add_loop_tangent_named_layer_for_uv(CustomData *uv_data,
void BKE_mesh_add_loop_tangent_named_layer_for_uv(const CustomData *uv_data,
CustomData *tan_data,
int numLoopData,
const char *layer_name)
@ -393,7 +393,7 @@ void BKE_mesh_calc_loop_tangent_ex(const float (*vert_positions)[3],
const uint corner_tris_len,
const blender::Span<bool> sharp_faces,
CustomData *loopdata,
const CustomData *loopdata,
bool calc_active_tangent,
const char (*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME],
int tangent_names_len,
@ -554,7 +554,7 @@ void BKE_mesh_calc_loop_tangent_ex(const float (*vert_positions)[3],
if (act_uv_index != -1) {
int tan_index = CustomData_get_named_layer_index(
loopdata, CD_TANGENT, loopdata->layers[act_uv_index].name);
CustomData_set_layer_active_index(loopdata, CD_TANGENT, tan_index);
CustomData_set_layer_active_index(loopdata_out, CD_TANGENT, tan_index);
} /* else tangent has been built from orco */
/* Update render layer index */
@ -564,7 +564,7 @@ void BKE_mesh_calc_loop_tangent_ex(const float (*vert_positions)[3],
if (ren_uv_index != -1) {
int tan_index = CustomData_get_named_layer_index(
loopdata, CD_TANGENT, loopdata->layers[ren_uv_index].name);
CustomData_set_layer_render_index(loopdata, CD_TANGENT, tan_index);
CustomData_set_layer_render_index(loopdata_out, CD_TANGENT, tan_index);
} /* else tangent has been built from orco */
}
}

View File

@ -952,10 +952,10 @@ Mesh *BKE_modifier_get_evaluated_mesh_from_evaluated_object(Object *ob_eval)
if ((ob_eval->type == OB_MESH) && (ob_eval->mode & OB_MODE_EDIT)) {
/* In EditMode, evaluated mesh is stored in BMEditMesh, not the object... */
BMEditMesh *em = BKE_editmesh_from_object(ob_eval);
const BMEditMesh *em = BKE_editmesh_from_object(ob_eval);
/* 'em' might not exist yet in some cases, just after loading a .blend file, see #57878. */
if (em != nullptr) {
mesh = BKE_object_get_editmesh_eval_final(ob_eval);
mesh = const_cast<Mesh *>(BKE_object_get_editmesh_eval_final(ob_eval));
}
}
if (mesh == nullptr) {

View File

@ -2764,7 +2764,7 @@ void BKE_object_obdata_size_init(Object *ob, const float size)
/** \name Object Matrix Get/Set API
* \{ */
void BKE_object_scale_to_mat3(Object *ob, float mat[3][3])
void BKE_object_scale_to_mat3(const Object *ob, float mat[3][3])
{
float3 vec;
mul_v3_v3v3(vec, ob->scale, ob->dscale);
@ -2946,7 +2946,7 @@ void BKE_object_tfm_copy(Object *object_dst, const Object *object_src)
#undef TFMCPY4D
}
void BKE_object_to_mat3(Object *ob, float r_mat[3][3]) /* no parent */
void BKE_object_to_mat3(const Object *ob, float r_mat[3][3]) /* no parent */
{
float smat[3][3];
float rmat[3][3];
@ -2959,7 +2959,7 @@ void BKE_object_to_mat3(Object *ob, float r_mat[3][3]) /* no parent */
mul_m3_m3m3(r_mat, rmat, smat);
}
void BKE_object_to_mat4(Object *ob, float r_mat[4][4])
void BKE_object_to_mat4(const Object *ob, float r_mat[4][4])
{
float tmat[3][3];
@ -2987,7 +2987,7 @@ void BKE_object_matrix_local_get(Object *ob, float r_mat[4][4])
/**
* \return success if \a mat is set.
*/
static bool ob_parcurve(Object *ob, Object *par, float r_mat[4][4])
static bool ob_parcurve(const Object *ob, Object *par, float r_mat[4][4])
{
Curve *cu = (Curve *)par->data;
float vec[4], quat[4], radius, ctime;
@ -3046,7 +3046,7 @@ static bool ob_parcurve(Object *ob, Object *par, float r_mat[4][4])
return true;
}
static void ob_parbone(Object *ob, Object *par, float r_mat[4][4])
static void ob_parbone(const Object *ob, const Object *par, float r_mat[4][4])
{
float3 vec;
@ -3056,7 +3056,7 @@ static void ob_parbone(Object *ob, Object *par, float r_mat[4][4])
}
/* Make sure the bone is still valid */
bPoseChannel *pchan = BKE_pose_channel_find_name(par->pose, ob->parsubstr);
const bPoseChannel *pchan = BKE_pose_channel_find_name(par->pose, ob->parsubstr);
if (!pchan || !pchan->bone) {
CLOG_WARN(
&LOG, "Parent Bone: '%s' for Object: '%s' doesn't exist", ob->parsubstr, ob->id.name + 2);
@ -3080,15 +3080,15 @@ static void ob_parbone(Object *ob, Object *par, float r_mat[4][4])
}
}
static void give_parvert(Object *par, int nr, float vec[3])
static void give_parvert(const Object *par, int nr, float vec[3])
{
zero_v3(vec);
if (par->type == OB_MESH) {
Mesh *mesh = (Mesh *)par->data;
BMEditMesh *em = mesh->runtime->edit_mesh;
Mesh *mesh_eval = (em) ? BKE_object_get_editmesh_eval_final(par) :
BKE_object_get_evaluated_mesh(par);
const Mesh *mesh = (const Mesh *)par->data;
const BMEditMesh *em = mesh->runtime->edit_mesh;
const Mesh *mesh_eval = (em) ? BKE_object_get_editmesh_eval_final(par) :
BKE_object_get_evaluated_mesh(par);
if (mesh_eval) {
const Span<float3> positions = mesh_eval->vert_positions();
@ -3201,7 +3201,7 @@ static void give_parvert(Object *par, int nr, float vec[3])
}
}
static void ob_parvert3(Object *ob, Object *par, float r_mat[4][4])
static void ob_parvert3(const Object *ob, const Object *par, float r_mat[4][4])
{
/* in local ob space */
if (OB_TYPE_SUPPORT_PARVERT(par->type)) {
@ -3222,7 +3222,7 @@ static void ob_parvert3(Object *ob, Object *par, float r_mat[4][4])
}
}
void BKE_object_get_parent_matrix(Object *ob, Object *par, float r_parentmat[4][4])
void BKE_object_get_parent_matrix(const Object *ob, Object *par, float r_parentmat[4][4])
{
float tmat[4][4];
float vec[3];
@ -3277,8 +3277,11 @@ void BKE_object_get_parent_matrix(Object *ob, Object *par, float r_parentmat[4][
* \param r_originmat: Optional matrix that stores the space the object is in
* (without its own matrix applied)
*/
static void solve_parenting(
Object *ob, Object *par, const bool set_origin, float r_obmat[4][4], float r_originmat[3][3])
static void solve_parenting(const Object *ob,
Object *par,
const bool set_origin,
float r_obmat[4][4],
float r_originmat[3][3])
{
float totmat[4][4];
float tmat[4][4];
@ -3358,7 +3361,7 @@ void BKE_object_where_is_calc_time(Depsgraph *depsgraph, Scene *scene, Object *o
object_where_is_calc_ex(depsgraph, scene, ob, ctime, nullptr, nullptr);
}
void BKE_object_where_is_calc_mat4(Object *ob, float r_obmat[4][4])
void BKE_object_where_is_calc_mat4(const Object *ob, float r_obmat[4][4])
{
if (ob->parent) {
Object *par = ob->parent;
@ -4202,7 +4205,7 @@ Mesh *BKE_object_get_original_mesh(const Object *object)
return result;
}
Mesh *BKE_object_get_editmesh_eval_final(const Object *object)
const Mesh *BKE_object_get_editmesh_eval_final(const Object *object)
{
BLI_assert(!DEG_is_original_id(&object->id));
BLI_assert(object->type == OB_MESH);
@ -4217,7 +4220,7 @@ Mesh *BKE_object_get_editmesh_eval_final(const Object *object)
return reinterpret_cast<Mesh *>(object->runtime->data_eval);
}
Mesh *BKE_object_get_editmesh_eval_cage(const Object *object)
const Mesh *BKE_object_get_editmesh_eval_cage(const Object *object)
{
BLI_assert(!DEG_is_original_id(&object->id));
BLI_assert(object->type == OB_MESH);
@ -4229,6 +4232,13 @@ Mesh *BKE_object_get_editmesh_eval_cage(const Object *object)
return object->runtime->editmesh_eval_cage;
}
const Mesh *BKE_object_get_mesh_deform_eval(const Object *object)
{
BLI_assert(!DEG_is_original_id(&object->id));
BLI_assert(object->type == OB_MESH);
return object->runtime->mesh_deform_eval;
}
Lattice *BKE_object_get_lattice(const Object *object)
{
ID *data = (ID *)object->data;
@ -4806,7 +4816,7 @@ int BKE_object_scenes_users_get(Main *bmain, Object *ob)
return num_scenes;
}
MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, bool use_default)
MovieClip *BKE_object_movieclip_get(Scene *scene, const Object *ob, bool use_default)
{
MovieClip *clip = use_default ? scene->clip : nullptr;
bConstraint *con = (bConstraint *)ob->constraints.first, *scon = nullptr;
@ -5039,8 +5049,9 @@ KDTree_3d *BKE_object_as_kdtree(Object *ob, int *r_tot)
Mesh *mesh = (Mesh *)ob->data;
uint i;
Mesh *mesh_eval = ob->runtime->mesh_deform_eval ? ob->runtime->mesh_deform_eval :
BKE_object_get_evaluated_mesh(ob);
const Mesh *mesh_eval = BKE_object_get_mesh_deform_eval(ob) ?
BKE_object_get_mesh_deform_eval(ob) :
BKE_object_get_evaluated_mesh(ob);
const int *index;
if (mesh_eval &&

View File

@ -1769,7 +1769,7 @@ static void sculpt_update_object(Depsgraph *depsgraph,
bool used_me_eval = false;
if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
Mesh *me_eval_deform = ob_eval->runtime->mesh_deform_eval;
const Mesh *me_eval_deform = BKE_object_get_mesh_deform_eval(ob_eval);
/* If the fully evaluated mesh has the same topology as the deform-only version, use it.
* This matters because crazyspace evaluation is very restrictive and excludes even modifiers
@ -2127,7 +2127,7 @@ static PBVH *build_pbvh_for_dynamic_topology(Object *ob)
ob->sculpt->attrs.dyntopo_node_id_face->bmesh_cd_offset);
}
static PBVH *build_pbvh_from_regular_mesh(Object *ob, Mesh *me_eval_deform)
static PBVH *build_pbvh_from_regular_mesh(Object *ob, const Mesh *me_eval_deform)
{
Mesh *mesh = BKE_object_get_original_mesh(ob);
PBVH *pbvh = pbvh::build_mesh(mesh);
@ -2200,7 +2200,7 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
pbvh = build_pbvh_from_ccg(ob, mesh_eval->runtime->subdiv_ccg.get());
}
else if (ob->type == OB_MESH) {
Mesh *me_eval_deform = object_eval->runtime->mesh_deform_eval;
const Mesh *me_eval_deform = BKE_object_get_mesh_deform_eval(object_eval);
pbvh = build_pbvh_from_regular_mesh(ob, me_eval_deform);
}
}

View File

@ -44,7 +44,6 @@
#include "BKE_mesh.hh"
#include "BKE_mesh_runtime.hh"
#include "BKE_object.hh"
#include "BKE_object_types.hh"
#include "BKE_pointcache.h"
#include "BKE_report.hh"
#include "BKE_rigidbody.h"
@ -338,13 +337,13 @@ void BKE_rigidbody_object_copy(Main *bmain, Object *ob_dst, const Object *ob_src
/* Setup Utilities - Validate Sim Instances */
/* get the appropriate evaluated mesh based on rigid body mesh source */
static Mesh *rigidbody_get_mesh(Object *ob)
static const Mesh *rigidbody_get_mesh(Object *ob)
{
BLI_assert(ob->type == OB_MESH);
switch (ob->rigidbody_object->mesh_source) {
case RBO_MESH_DEFORM:
return ob->runtime->mesh_deform_eval;
return BKE_object_get_mesh_deform_eval(ob);
case RBO_MESH_FINAL:
return BKE_object_get_evaluated_mesh(ob);
case RBO_MESH_BASE:
@ -366,13 +365,13 @@ static rbCollisionShape *rigidbody_get_shape_convexhull_from_mesh(Object *ob,
bool *can_embed)
{
rbCollisionShape *shape = nullptr;
Mesh *mesh = nullptr;
float(*positions)[3] = nullptr;
const Mesh *mesh = nullptr;
const float(*positions)[3] = nullptr;
int totvert = 0;
if (ob->type == OB_MESH && ob->data) {
mesh = rigidbody_get_mesh(ob);
positions = (mesh) ? reinterpret_cast<float(*)[3]>(mesh->vert_positions_for_write().data()) :
positions = (mesh) ? reinterpret_cast<const float(*)[3]>(mesh->vert_positions().data()) :
nullptr;
totvert = (mesh) ? mesh->verts_num : 0;
}
@ -399,7 +398,7 @@ static rbCollisionShape *rigidbody_get_shape_trimesh_from_mesh(Object *ob)
rbCollisionShape *shape = nullptr;
if (ob->type == OB_MESH) {
Mesh *mesh = rigidbody_get_mesh(ob);
const Mesh *mesh = rigidbody_get_mesh(ob);
if (mesh == nullptr) {
return nullptr;
}
@ -668,7 +667,7 @@ void BKE_rigidbody_calc_volume(Object *ob, float *r_vol)
case RB_SHAPE_CONVEXH:
case RB_SHAPE_TRIMESH: {
if (ob->type == OB_MESH) {
Mesh *mesh = rigidbody_get_mesh(ob);
const Mesh *mesh = rigidbody_get_mesh(ob);
if (mesh == nullptr) {
return;
}
@ -742,7 +741,7 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3])
case RB_SHAPE_CONVEXH:
case RB_SHAPE_TRIMESH: {
if (ob->type == OB_MESH) {
Mesh *mesh = rigidbody_get_mesh(ob);
const Mesh *mesh = rigidbody_get_mesh(ob);
if (mesh == nullptr) {
return;
}
@ -1763,10 +1762,10 @@ static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Object *ob, RigidBodyO
const bool is_selected = base ? (base->flag & BASE_SELECTED) != 0 : false;
if (rbo->shape == RB_SHAPE_TRIMESH && rbo->flag & RBO_FLAG_USE_DEFORM) {
Mesh *mesh = ob->runtime->mesh_deform_eval;
const Mesh *mesh = BKE_object_get_mesh_deform_eval(ob);
if (mesh) {
float(*positions)[3] = reinterpret_cast<float(*)[3]>(
mesh->vert_positions_for_write().data());
const float(*positions)[3] = reinterpret_cast<const float(*)[3]>(
mesh->vert_positions().data());
int totvert = mesh->verts_num;
const std::optional<blender::Bounds<blender::float3>> bounds = BKE_object_boundbox_get(ob);

View File

@ -367,7 +367,7 @@ void BKE_tracking_settings_init(MovieTracking *tracking)
BKE_tracking_object_add(tracking, DATA_("Camera"));
}
void BKE_tracking_get_camera_object_matrix(Object *camera_object, float mat[4][4])
void BKE_tracking_get_camera_object_matrix(const Object *camera_object, float mat[4][4])
{
BLI_assert(camera_object != nullptr);
/* NOTE: Construct matrix from scratch rather than using obmat because the camera object here

View File

@ -237,8 +237,8 @@ static void overlay_edit_mesh_add_ob_to_pass(OVERLAY_PrivateData *pd, Object *ob
/* TODO: Should be its own function. */
Mesh *mesh = (Mesh *)ob->data;
if (BMEditMesh *em = mesh->runtime->edit_mesh) {
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(ob);
const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
const Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(ob);
has_edit_mesh_cage = editmesh_eval_cage && (editmesh_eval_cage != editmesh_eval_final);
has_skin_roots = CustomData_get_offset(&em->bm->vdata, CD_MVERT_SKIN) != -1;

View File

@ -177,11 +177,11 @@ void OVERLAY_wireframe_cache_populate(OVERLAY_Data *vedata,
bool is_mesh_verts_only = false;
if (is_mesh) {
/* TODO: Should be its own function. */
Mesh *mesh = static_cast<Mesh *>(ob->data);
const Mesh *mesh = static_cast<const Mesh *>(ob->data);
if (is_edit_mode) {
BLI_assert(mesh->runtime->edit_mesh);
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(ob);
const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
const Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(ob);
has_edit_mesh_cage = editmesh_eval_cage && (editmesh_eval_cage != editmesh_eval_final);
if (editmesh_eval_final) {
mesh = editmesh_eval_final;

View File

@ -336,8 +336,7 @@ void mesh_render_data_update_faces_sorted(MeshRenderData &mr,
const Mesh *editmesh_final_or_this(const Object *object, const Mesh *mesh)
{
if (mesh->runtime->edit_mesh != nullptr) {
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object);
if (editmesh_eval_final != nullptr) {
if (const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object)) {
return editmesh_eval_final;
}
}
@ -559,8 +558,8 @@ MeshRenderData *mesh_render_data_create(Object *object,
mr->use_hide = use_hide;
if (is_editmode) {
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object);
Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(object);
const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object);
const Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(object);
BLI_assert(editmesh_eval_cage && editmesh_eval_final);
mr->bm = mesh->runtime->edit_mesh->bm;

View File

@ -1407,7 +1407,8 @@ void DRW_mesh_batch_cache_create_requested(TaskGraph *task_graph,
/* Modifiers will only generate an orco layer if the mesh is deformed. */
if (cache.cd_needed.orco != 0) {
/* Orco is always extracted from final mesh. */
Mesh *me_final = (mesh->runtime->edit_mesh) ? BKE_object_get_editmesh_eval_final(ob) : mesh;
const Mesh *me_final = (mesh->runtime->edit_mesh) ? BKE_object_get_editmesh_eval_final(ob) :
mesh;
if (CustomData_get_layer(&me_final->vert_data, CD_ORCO) == nullptr) {
/* Skip orco calculation */
cache.cd_needed.orco = 0;
@ -1512,8 +1513,8 @@ void DRW_mesh_batch_cache_create_requested(TaskGraph *task_graph,
bool do_cage = false, do_uvcage = false;
if (is_editmode && is_mode_active) {
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(ob);
const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
const Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(ob);
do_cage = editmesh_eval_final != editmesh_eval_cage;
do_uvcage = !(editmesh_eval_final->runtime->is_original_bmesh &&

View File

@ -750,7 +750,7 @@ static void draw_subdiv_cache_extra_coarse_face_data_bm(BMesh *bm,
}
static void draw_subdiv_cache_extra_coarse_face_data_mesh(const MeshRenderData &mr,
Mesh *mesh,
const Mesh *mesh,
uint32_t *flags_data)
{
const OffsetIndices faces = mesh->faces();
@ -771,7 +771,7 @@ static void draw_subdiv_cache_extra_coarse_face_data_mesh(const MeshRenderData &
}
}
static void draw_subdiv_cache_extra_coarse_face_data_mapped(Mesh *mesh,
static void draw_subdiv_cache_extra_coarse_face_data_mapped(const Mesh *mesh,
BMesh *bm,
MeshRenderData &mr,
uint32_t *flags_data)
@ -797,7 +797,7 @@ static void draw_subdiv_cache_extra_coarse_face_data_mapped(Mesh *mesh,
}
static void draw_subdiv_cache_update_extra_coarse_face_data(DRWSubdivCache &cache,
Mesh *mesh,
const Mesh *mesh,
MeshRenderData &mr)
{
if (cache.extra_coarse_face_data == nullptr) {
@ -839,7 +839,7 @@ static DRWSubdivCache &mesh_batch_cache_ensure_subdiv_cache(MeshBatchCache &mbc)
return *subdiv_cache;
}
static void draw_subdiv_invalidate_evaluator_for_orco(Subdiv *subdiv, Mesh *mesh)
static void draw_subdiv_invalidate_evaluator_for_orco(Subdiv *subdiv, const Mesh *mesh)
{
if (!(subdiv && subdiv->evaluator)) {
return;
@ -1167,7 +1167,7 @@ static void build_vertex_face_adjacency_maps(DRWSubdivCache &cache)
static bool draw_subdiv_build_cache(DRWSubdivCache &cache,
Subdiv *subdiv,
Mesh *mesh_eval,
const Mesh *mesh_eval,
const SubsurfRuntimeData *runtime_data)
{
SubdivToMeshSettings to_mesh_settings;
@ -2020,7 +2020,7 @@ void draw_subdiv_build_edituv_stretch_angle_buffer(const DRWSubdivCache &cache,
* since all sub-faces are contiguous, they all share the same offset.
*/
static void draw_subdiv_cache_ensure_mat_offsets(DRWSubdivCache &cache,
Mesh *mesh_eval,
const Mesh *mesh_eval,
uint mat_len)
{
draw_subdiv_cache_free_material_data(cache);
@ -2108,7 +2108,7 @@ static bool draw_subdiv_create_requested_buffers(Object *ob,
return false;
}
Mesh *mesh_eval = mesh;
const Mesh *mesh_eval = mesh;
BMesh *bm = nullptr;
if (mesh->runtime->edit_mesh) {
mesh_eval = BKE_object_get_editmesh_eval_final(ob);

View File

@ -258,7 +258,7 @@ void DRW_text_edit_mesh_measure_stats(ARegion *region,
*/
DRWTextStore *dt = DRW_text_cache_ensure();
const short txt_flag = DRW_TEXT_CACHE_GLOBALSPACE;
Mesh *mesh = BKE_object_get_editmesh_eval_cage(ob);
const Mesh *mesh = BKE_object_get_editmesh_eval_cage(ob);
BMEditMesh *em = mesh->runtime->edit_mesh;
float v1[3], v2[3], v3[3], vmid[3], fvec[3];
char numstr[32]; /* Stores the measurement display text here */
@ -379,7 +379,9 @@ void DRW_text_edit_mesh_measure_stats(ARegion *region,
Span<float3> face_normals;
if (use_coords) {
BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
face_normals = BKE_mesh_wrapper_face_normals(mesh);
/* TODO: This is not const correct for wrapper meshes, but it should be okay because
* every evaluated object gets its own evaluated cage mesh (they are not shared). */
face_normals = BKE_mesh_wrapper_face_normals(const_cast<Mesh *>(mesh));
}
BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {

View File

@ -101,7 +101,7 @@ struct DRWSubdivLooseGeom {
* \{ */
struct DRWSubdivCache {
Mesh *mesh;
const Mesh *mesh;
BMesh *bm;
Subdiv *subdiv;
bool optimal_display;

View File

@ -89,7 +89,7 @@ struct MeshRenderData {
int freestyle_edge_ofs;
int freestyle_face_ofs;
/** Mesh */
Mesh *mesh;
const Mesh *mesh;
Span<float3> vert_positions;
Span<int2> edges;
OffsetIndices<int> faces;

View File

@ -268,7 +268,7 @@ static void extract_attr_init_subdiv(const DRWSubdivCache &subdiv_cache,
const DRW_Attributes *attrs_used = &cache.attr_used;
const DRW_AttributeRequest &request = attrs_used->requests[index];
Mesh *coarse_mesh = subdiv_cache.mesh;
const Mesh *coarse_mesh = subdiv_cache.mesh;
/* Prepare VBO for coarse data. The compute shader only expects floats. */
gpu::VertBuf *src_data = GPU_vertbuf_calloc();

View File

@ -253,8 +253,8 @@ static void extract_edituv_stretch_angle_init_subdiv(const DRWSubdivCache &subdi
/* UVs are stored contiguously so we need to compute the offset in the UVs buffer for the active
* UV layer. */
CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_MESH) ? &mr.mesh->corner_data :
&mr.bm->ldata;
const CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_MESH) ? &mr.mesh->corner_data :
&mr.bm->ldata;
uint32_t uv_layers = cache.cd_used.uv;
/* HACK to fix #68857 */

View File

@ -37,7 +37,7 @@ static void extract_orco_init(const MeshRenderData &mr,
GPU_vertbuf_init_with_format(vbo, &format);
GPU_vertbuf_data_alloc(vbo, mr.corners_num);
CustomData *cd_vdata = &mr.mesh->vert_data;
const CustomData *cd_vdata = &mr.mesh->vert_data;
MeshExtract_Orco_Data *data = static_cast<MeshExtract_Orco_Data *>(tls_data);
data->vbo_data = (float(*)[4])GPU_vertbuf_get_data(vbo);

View File

@ -117,7 +117,7 @@ static void extract_sculpt_data_init_subdiv(const DRWSubdivCache &subdiv_cache,
{
gpu::VertBuf *vbo = static_cast<gpu::VertBuf *>(buffer);
Mesh *coarse_mesh = mr.mesh;
const Mesh *coarse_mesh = mr.mesh;
/* First, interpolate mask if available. */
gpu::VertBuf *mask_vbo = nullptr;

View File

@ -38,10 +38,10 @@ static void extract_tan_init_common(const MeshRenderData &mr,
{
GPU_vertformat_deinterleave(format);
CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->ldata :
&mr.mesh->corner_data;
CustomData *cd_vdata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->vdata :
&mr.mesh->vert_data;
const CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->ldata :
&mr.mesh->corner_data;
const CustomData *cd_vdata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->vdata :
&mr.mesh->vert_data;
uint32_t tan_layers = cache.cd_used.tan;
const float(*orco)[3] = (const float(*)[3])CustomData_get_layer(cd_vdata, CD_ORCO);
float(*orco_allocated)[3] = nullptr;
@ -96,7 +96,9 @@ static void extract_tan_init_common(const MeshRenderData &mr,
copy_v3_v3(orco_allocated[v], mr.vert_positions[v]);
}
}
BKE_mesh_orco_verts_transform(mr.mesh, orco_allocated, mr.verts_num, false);
/* TODO: This is not thread-safe. Draw extraction should not modify the mesh. */
BKE_mesh_orco_verts_transform(
const_cast<Mesh *>(mr.mesh), orco_allocated, mr.verts_num, false);
orco = orco_allocated;
}
@ -118,6 +120,7 @@ static void extract_tan_init_common(const MeshRenderData &mr,
&tangent_mask);
}
else {
/* TODO: This is not thread-safe. Draw extraction should not modify the mesh. */
BKE_mesh_calc_loop_tangent_ex(reinterpret_cast<const float(*)[3]>(mr.vert_positions.data()),
mr.faces,
mr.corner_verts.data(),

View File

@ -22,9 +22,9 @@ namespace blender::draw {
/* Initialize the vertex format to be used for UVs. Return true if any UV layer is
* found, false otherwise. */
static bool mesh_extract_uv_format_init(GPUVertFormat *format,
MeshBatchCache &cache,
CustomData *cd_ldata,
eMRExtractType extract_type,
const MeshBatchCache &cache,
const CustomData *cd_ldata,
const eMRExtractType extract_type,
uint32_t &r_uv_layers)
{
GPU_vertformat_deinterleave(format);
@ -89,8 +89,8 @@ static void extract_uv_init(const MeshRenderData &mr,
gpu::VertBuf *vbo = static_cast<gpu::VertBuf *>(buf);
GPUVertFormat format = {0};
CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->ldata :
&mr.mesh->corner_data;
const CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->ldata :
&mr.mesh->corner_data;
int v_len = mr.corners_num;
uint32_t uv_layers = cache.cd_used.uv;
if (!mesh_extract_uv_format_init(&format, cache, cd_ldata, mr.extract_type, uv_layers)) {
@ -136,7 +136,7 @@ static void extract_uv_init_subdiv(const DRWSubdivCache &subdiv_cache,
void *buffer,
void * /*data*/)
{
Mesh *coarse_mesh = subdiv_cache.mesh;
const Mesh *coarse_mesh = subdiv_cache.mesh;
gpu::VertBuf *vbo = static_cast<gpu::VertBuf *>(buffer);
GPUVertFormat format = {0};

View File

@ -159,7 +159,7 @@ static void extract_weights_init_subdiv(const DRWSubdivCache &subdiv_cache,
void *buffer,
void *_data)
{
Mesh *coarse_mesh = subdiv_cache.mesh;
const Mesh *coarse_mesh = subdiv_cache.mesh;
gpu::VertBuf *vbo = static_cast<gpu::VertBuf *>(buffer);
static GPUVertFormat format = {0};

View File

@ -86,7 +86,7 @@ bool ED_transform_snap_object_project_ray_ex(SnapObjectContext *sctx,
float r_loc[3],
float r_no[3],
int *r_index,
Object **r_ob,
const Object **r_ob,
float r_obmat[4][4]);
/**
* Convenience function for snap ray-casting.
@ -155,7 +155,7 @@ eSnapMode ED_transform_snap_object_project_view3d_ex(SnapObjectContext *sctx,
float r_loc[3],
float r_no[3],
int *r_index,
Object **r_ob,
const Object **r_ob,
float r_obmat[4][4],
float r_face_nor[3]);
/**

View File

@ -1082,8 +1082,8 @@ bool EDBM_unified_findnearest_from_raycast(ViewContext *vc,
Span<float3> vert_positions;
{
Object *obedit_eval = DEG_get_evaluated_object(vc->depsgraph, obedit);
Mesh *mesh_eval = BKE_object_get_editmesh_eval_cage(obedit_eval);
const Object *obedit_eval = DEG_get_evaluated_object(vc->depsgraph, obedit);
const Mesh *mesh_eval = BKE_object_get_editmesh_eval_cage(obedit_eval);
if (BKE_mesh_wrapper_vert_len(mesh_eval) == bm->totvert) {
vert_positions = BKE_mesh_wrapper_vert_coords(mesh_eval);
}

View File

@ -903,7 +903,7 @@ void ED_view3d_cursor3d_position_rotation(bContext *C,
SnapObjectContext *snap_context = ED_transform_snap_object_context_create(scene, 0);
float obmat[4][4];
Object *ob_dummy = nullptr;
const Object *ob_dummy = nullptr;
float dist_px = 0;
SnapObjectParams params{};
params.snap_target_select = SCE_SNAP_TARGET_ALL;

View File

@ -242,9 +242,9 @@ static int gizmo_preselect_elem_test_select(bContext *C, wmGizmo *gz, const int
Span<float3> vert_positions;
{
Object *ob = gz_ele->bases[gz_ele->base_index]->object;
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
Mesh *mesh_eval = BKE_object_get_editmesh_eval_cage(ob_eval);
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
const Mesh *mesh_eval = BKE_object_get_editmesh_eval_cage(ob_eval);
if (BKE_mesh_wrapper_vert_len(mesh_eval) == bm->totvert) {
vert_positions = BKE_mesh_wrapper_vert_coords(mesh_eval);
}

View File

@ -291,7 +291,7 @@ eSnapMode SnapData::snap_edge_points_impl(SnapObjectContext *sctx,
}
void SnapData::register_result(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id_eval,
const float4x4 &obmat,
BVHTreeNearest *r_nearest)
@ -316,13 +316,13 @@ void SnapData::register_result(SnapObjectContext *sctx,
#endif
}
void SnapData::register_result(SnapObjectContext *sctx, Object *ob_eval, const ID *id_eval)
void SnapData::register_result(SnapObjectContext *sctx, const Object *ob_eval, const ID *id_eval)
{
this->register_result(sctx, ob_eval, id_eval, this->obmat_, &this->nearest_point);
}
void SnapData::register_result_raycast(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id_eval,
const blender::float4x4 &obmat,
const BVHTreeRayHit *hit,
@ -368,17 +368,17 @@ static ID *data_for_snap(Object *ob_eval, eSnapEditType edit_mode_type, bool *r_
switch (ob_eval->type) {
case OB_MESH: {
Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
if (BKE_object_is_in_editmode(ob_eval)) {
if (edit_mode_type == SNAP_GEOM_EDIT) {
return nullptr;
}
Mesh *editmesh_eval = (edit_mode_type == SNAP_GEOM_FINAL) ?
BKE_object_get_editmesh_eval_final(ob_eval) :
(edit_mode_type == SNAP_GEOM_CAGE) ?
BKE_object_get_editmesh_eval_cage(ob_eval) :
nullptr;
const Mesh *editmesh_eval = (edit_mode_type == SNAP_GEOM_FINAL) ?
BKE_object_get_editmesh_eval_final(ob_eval) :
(edit_mode_type == SNAP_GEOM_CAGE) ?
BKE_object_get_editmesh_eval_cage(ob_eval) :
nullptr;
if (editmesh_eval) {
if (editmesh_eval->runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH) {
@ -409,8 +409,8 @@ static ID *data_for_snap(Object *ob_eval, eSnapEditType edit_mode_type, bool *r_
* \{ */
using IterSnapObjsCallback = eSnapMode (*)(SnapObjectContext *sctx,
Object *ob_eval,
ID *ob_data,
const Object *ob_eval,
const ID *ob_data,
const float4x4 &obmat,
bool is_object_active,
bool use_hide);
@ -588,8 +588,8 @@ bool raycast_tri_backface_culling_test(
* \note Duplicate args here are documented at #snapObjectsRay.
*/
static eSnapMode raycast_obj_fn(SnapObjectContext *sctx,
Object *ob_eval,
ID *ob_data,
const Object *ob_eval,
const ID *ob_data,
const float4x4 &obmat,
bool is_object_active,
bool use_hide)
@ -726,8 +726,8 @@ bool nearest_world_tree(SnapObjectContext *sctx,
}
static eSnapMode nearest_world_object_fn(SnapObjectContext *sctx,
Object *ob_eval,
ID *ob_data,
const Object *ob_eval,
const ID *ob_data,
const float4x4 &obmat,
bool is_object_active,
bool use_hide)
@ -849,7 +849,7 @@ static eSnapMode snap_edge_points(SnapObjectContext *sctx, const float dist_px_s
/* May extend later (for now just snaps to empty or camera center). */
eSnapMode snap_object_center(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const float4x4 &obmat,
eSnapMode snap_to_flag)
{
@ -878,8 +878,8 @@ eSnapMode snap_object_center(SnapObjectContext *sctx,
* \note Duplicate args here are documented at #snapObjectsRay.
*/
static eSnapMode snap_obj_fn(SnapObjectContext *sctx,
Object *ob_eval,
ID *ob_data,
const Object *ob_eval,
const ID *ob_data,
const float4x4 &obmat,
bool is_object_active,
bool use_hide)
@ -1184,7 +1184,7 @@ bool ED_transform_snap_object_project_ray_ex(SnapObjectContext *sctx,
float r_loc[3],
float r_no[3],
int *r_index,
Object **r_ob,
const Object **r_ob,
float r_obmat[4][4])
{
if (!snap_object_context_runtime_init(sctx,
@ -1311,7 +1311,7 @@ eSnapMode ED_transform_snap_object_project_view3d_ex(SnapObjectContext *sctx,
float r_loc[3],
float r_no[3],
int *r_index,
Object **r_ob,
const Object **r_ob,
float r_obmat[4][4],
float r_face_nor[3])
{

View File

@ -85,7 +85,7 @@ struct SnapObjectContext {
/* List of #SnapObjectHitDepth (caller must free). */
ListBase *hit_list;
/* Snapped object. */
Object *ob;
const Object *ob;
/* Snapped data. */
const ID *data;
@ -141,13 +141,13 @@ class SnapData {
bool snap_edge(const blender::float3 &va, const blender::float3 &vb, int edge_index = -1);
eSnapMode snap_edge_points_impl(SnapObjectContext *sctx, int edge_index, float dist_px_sq_orig);
static void register_result(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id_eval,
const blender::float4x4 &obmat,
BVHTreeNearest *r_nearest);
void register_result(SnapObjectContext *sctx, Object *ob_eval, const ID *id_eval);
void register_result(SnapObjectContext *sctx, const Object *ob_eval, const ID *id_eval);
static void register_result_raycast(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id_eval,
const blender::float4x4 &obmat,
const BVHTreeRayHit *hit,
@ -187,32 +187,34 @@ bool nearest_world_tree(SnapObjectContext *sctx,
BVHTreeNearest *r_nearest);
eSnapMode snap_object_center(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const blender::float4x4 &obmat,
eSnapMode snap_to_flag);
/* `transform_snap_object_armature.cc` */
eSnapMode snapArmature(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const blender::float4x4 &obmat,
bool is_object_active);
/* `transform_snap_object_camera.cc` */
eSnapMode snapCamera(SnapObjectContext *sctx,
Object *object,
const Object *object,
const blender::float4x4 &obmat,
eSnapMode snap_to_flag);
/* `transform_snap_object_curve.cc` */
eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const blender::float4x4 &obmat);
eSnapMode snapCurve(SnapObjectContext *sctx,
const Object *ob_eval,
const blender::float4x4 &obmat);
/* `transform_snap_object_editmesh.cc` */
eSnapMode snap_object_editmesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id,
const blender::float4x4 &obmat,
eSnapMode snap_to_flag,
@ -221,21 +223,21 @@ eSnapMode snap_object_editmesh(SnapObjectContext *sctx,
/* `transform_snap_object_mesh.cc` */
eSnapMode snap_object_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id,
const blender::float4x4 &obmat,
eSnapMode snap_to_flag,
bool use_hide);
eSnapMode snap_polygon_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id,
const blender::float4x4 &obmat,
eSnapMode snap_to_flag,
int face);
eSnapMode snap_edge_points_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id,
const blender::float4x4 &obmat,
float dist_px_sq_orig,

View File

@ -21,7 +21,7 @@
using blender::float4x4;
eSnapMode snapArmature(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const float4x4 &obmat,
bool is_object_active)
{

View File

@ -19,7 +19,7 @@
using namespace blender;
eSnapMode snapCamera(SnapObjectContext *sctx,
Object *object,
const Object *object,
const float4x4 &obmat,
eSnapMode snap_to_flag)
{

View File

@ -21,7 +21,7 @@
using blender::float4x4;
using blender::IndexRange;
eSnapMode snapCurve(SnapObjectContext *sctx, Object *ob_eval, const float4x4 &obmat)
eSnapMode snapCurve(SnapObjectContext *sctx, const Object *ob_eval, const float4x4 &obmat)
{
bool has_snap = false;

View File

@ -26,17 +26,17 @@ using namespace blender;
/** \name Snap Object Data
* \{ */
static Mesh *get_mesh_ref(Object *ob_eval)
static const Mesh *get_mesh_ref(const Object *ob_eval)
{
if (Mesh *me = BKE_object_get_editmesh_eval_final(ob_eval)) {
if (const Mesh *me = BKE_object_get_editmesh_eval_final(ob_eval)) {
return me;
}
if (Mesh *me = BKE_object_get_editmesh_eval_cage(ob_eval)) {
if (const Mesh *me = BKE_object_get_editmesh_eval_cage(ob_eval)) {
return me;
}
return static_cast<Mesh *>(ob_eval->data);
return static_cast<const Mesh *>(ob_eval->data);
}
struct SnapCache_EditMesh : public SnapObjectContext::SnapCache {
@ -44,11 +44,11 @@ struct SnapCache_EditMesh : public SnapObjectContext::SnapCache {
Mesh *mesh;
/* Reference to pointers that change when the mesh is changed. It is used to detect updates. */
Mesh *mesh_ref;
const Mesh *mesh_ref;
bke::MeshRuntime *runtime_ref;
bke::EditMeshData *edit_data_ref;
bool has_mesh_updated(Mesh *mesh)
bool has_mesh_updated(const Mesh *mesh)
{
if (mesh != this->mesh_ref || mesh->runtime != this->runtime_ref ||
mesh->runtime->edit_data.get() != this->edit_data_ref)
@ -77,11 +77,11 @@ struct SnapCache_EditMesh : public SnapObjectContext::SnapCache {
};
static Mesh *create_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
eSnapEditType /*edit_mode_type*/)
{
Mesh *mesh = static_cast<Mesh *>(BKE_id_new_nomain(ID_ME, nullptr));
BMEditMesh *em = BKE_editmesh_from_object(ob_eval);
const BMEditMesh *em = BKE_editmesh_from_object(const_cast<Object *>(ob_eval));
BMesh *bm = em->bm;
BM_mesh_bm_to_me_compact(*bm, *mesh, nullptr, false);
@ -148,17 +148,17 @@ static Mesh *create_mesh(SnapObjectContext *sctx,
}
static SnapCache_EditMesh *snap_object_data_editmesh_get(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
bool create)
{
SnapCache_EditMesh *em_cache = nullptr;
bool init = false;
Mesh *mesh_ref = (G.moving) ? /* WORKAROUND:
* Avoid updating while transforming. Do not check if the reference
* mesh has been updated. */
nullptr :
get_mesh_ref(ob_eval);
const Mesh *mesh_ref = (G.moving) ? /* WORKAROUND:
* Avoid updating while transforming. Do not check if the
* reference mesh has been updated. */
nullptr :
get_mesh_ref(ob_eval);
if (std::unique_ptr<SnapObjectContext::SnapCache> *em_cache_p = sctx->editmesh_caches.lookup_ptr(
ob_eval->runtime->data_orig))
@ -213,10 +213,10 @@ static eSnapMode editmesh_snap_mode_supported(BMesh *bm)
}
static SnapCache_EditMesh *editmesh_snapdata_init(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
eSnapMode snap_to_flag)
{
BMEditMesh *em = BKE_editmesh_from_object(ob_eval);
const BMEditMesh *em = BKE_editmesh_from_object(const_cast<Object *>(ob_eval));
if (em == nullptr) {
return nullptr;
}
@ -237,7 +237,7 @@ static SnapCache_EditMesh *editmesh_snapdata_init(SnapObjectContext *sctx,
/** \} */
eSnapMode snap_object_editmesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID * /*id*/,
const float4x4 &obmat,
eSnapMode snap_to_flag,

View File

@ -77,7 +77,7 @@ static void mesh_corner_tris_raycast_backface_culling_cb(void *userdata,
}
static bool raycastMesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const Mesh *mesh_eval,
const float4x4 &obmat,
const uint ob_index,
@ -190,7 +190,7 @@ static bool raycastMesh(SnapObjectContext *sctx,
* \{ */
static bool nearest_world_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const Mesh *mesh_eval,
const float4x4 &obmat,
bool use_hide)
@ -355,7 +355,7 @@ static void cb_snap_tri_edges(void *userdata,
* \{ */
eSnapMode snap_polygon_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id,
const float4x4 &obmat,
eSnapMode snap_to_flag,
@ -410,7 +410,7 @@ eSnapMode snap_polygon_mesh(SnapObjectContext *sctx,
}
eSnapMode snap_edge_points_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id,
const float4x4 &obmat,
float dist_pex_sq_orig,
@ -438,7 +438,7 @@ static eSnapMode mesh_snap_mode_supported(const Mesh *mesh)
}
static eSnapMode snapMesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const Mesh *mesh_eval,
const float4x4 &obmat,
bool use_hide,
@ -579,7 +579,7 @@ static eSnapMode snapMesh(SnapObjectContext *sctx,
/** \} */
eSnapMode snap_object_mesh(SnapObjectContext *sctx,
Object *ob_eval,
const Object *ob_eval,
const ID *id,
const float4x4 &obmat,
eSnapMode snap_to_flag,

View File

@ -306,7 +306,7 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit,
}
if (mode & TM_CALC_MAPLOC) {
Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(obedit);
const Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(obedit);
if (tvs->transverts && editmesh_eval_cage) {
BM_mesh_elem_table_ensure(bm, BM_VERT);
BKE_mesh_foreach_mapped_vert(

View File

@ -742,7 +742,7 @@ static bool rna_Object_is_deform_modified(Object *ob, Scene *scene, int settings
void rna_Object_me_eval_info(
Object *ob, bContext *C, int type, PointerRNA *rnaptr_depsgraph, char *result)
{
Mesh *mesh_eval = nullptr;
const Mesh *mesh_eval = nullptr;
char *ret = nullptr;
result[0] = '\0';
@ -762,7 +762,7 @@ void rna_Object_me_eval_info(
}
break;
case 1:
mesh_eval = ob->runtime->mesh_deform_eval;
mesh_eval = BKE_object_get_mesh_deform_eval(ob);
break;
case 2:
mesh_eval = BKE_object_get_evaluated_mesh(ob);

View File

@ -157,7 +157,7 @@ static void rna_Scene_ray_cast(Scene *scene,
r_location,
r_normal,
r_index,
r_ob,
(const Object **)(r_ob),
(float(*)[4])r_obmat);
ED_transform_snap_object_context_destroy(sctx);

View File

@ -732,7 +732,7 @@ static void wm_xr_raycast(Scene *scene,
float r_location[3],
float r_normal[3],
int *r_index,
Object **r_ob,
const Object **r_ob,
float r_obmat[4][4])
{
/* Uses same raycast method as Scene.ray_cast(). */
@ -1232,7 +1232,7 @@ static void wm_xr_navigation_teleport(bContext *C,
float location[3];
float normal[3];
int index;
Object *ob = nullptr;
const Object *ob = nullptr;
float obmat[4][4];
wm_xr_raycast(scene,