Cleanup: Access more mesh data with C++ methods
Recent C++ conversions have enabled more changes likeaf53207b43and7826aed105.
This commit is contained in:
@@ -285,7 +285,6 @@ void BKE_mesh_mselect_active_set(struct Mesh *me, int index, int type);
|
||||
void BKE_mesh_count_selected_items(const struct Mesh *mesh, int r_count[3]);
|
||||
|
||||
float (*BKE_mesh_vert_coords_alloc(const struct Mesh *mesh, int *r_vert_len))[3];
|
||||
void BKE_mesh_vert_coords_get(const struct Mesh *mesh, float (*vert_coords)[3]);
|
||||
|
||||
void BKE_mesh_vert_coords_apply_with_mat4(struct Mesh *mesh,
|
||||
const float (*vert_coords)[3],
|
||||
@@ -295,7 +294,7 @@ void BKE_mesh_vert_coords_apply(struct Mesh *mesh, const float (*vert_coords)[3]
|
||||
/* *** mesh_tessellate.cc *** */
|
||||
|
||||
/**
|
||||
* Calculate tessellation into #MLoopTri which exist only for this purpose.
|
||||
* See #bke::mesh::looptris_calc
|
||||
*/
|
||||
void BKE_mesh_recalc_looptri(const int *corner_verts,
|
||||
const int *face_offsets,
|
||||
@@ -755,11 +754,6 @@ BLI_INLINE const float (*BKE_mesh_vert_positions(const Mesh *mesh))[3]
|
||||
return (const float(*)[3])CustomData_get_layer_named(
|
||||
&mesh->vert_data, CD_PROP_FLOAT3, "position");
|
||||
}
|
||||
BLI_INLINE float (*BKE_mesh_vert_positions_for_write(Mesh *mesh))[3]
|
||||
{
|
||||
return (float(*)[3])CustomData_get_layer_named_for_write(
|
||||
&mesh->vert_data, CD_PROP_FLOAT3, "position", mesh->totvert);
|
||||
}
|
||||
|
||||
BLI_INLINE const int *BKE_mesh_face_offsets(const Mesh *mesh)
|
||||
{
|
||||
|
||||
@@ -87,11 +87,7 @@ extern "C" {
|
||||
|
||||
/**
|
||||
* Recreate #MFace Tessellation.
|
||||
*
|
||||
* \note This doesn't use multi-threading like #BKE_mesh_recalc_looptri since
|
||||
* it's not used in many places and #MFace should be phased out.
|
||||
*/
|
||||
|
||||
void BKE_mesh_tessface_calc(struct Mesh *mesh);
|
||||
|
||||
void BKE_mesh_tessface_ensure(struct Mesh *mesh);
|
||||
|
||||
@@ -255,7 +255,9 @@ bool BKE_mesh_calc_islands_loop_face_uvmap(float (*vert_positions)[3],
|
||||
const float (*luvs)[2],
|
||||
MeshIslandStore *r_island_store);
|
||||
|
||||
#endif
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
/**
|
||||
* Calculate smooth groups from sharp edges.
|
||||
@@ -265,31 +267,23 @@ bool BKE_mesh_calc_islands_loop_face_uvmap(float (*vert_positions)[3],
|
||||
* starting at 1 (0 being used as 'invalid' flag).
|
||||
* Note it's callers's responsibility to MEM_freeN returned array.
|
||||
*/
|
||||
int *BKE_mesh_calc_smoothgroups(int totedge,
|
||||
const int *face_offsets,
|
||||
int faces_num,
|
||||
const int *corner_edges,
|
||||
int totloop,
|
||||
int *BKE_mesh_calc_smoothgroups(int edges_num,
|
||||
blender::OffsetIndices<int> faces,
|
||||
blender::Span<int> corner_edges,
|
||||
const bool *sharp_edges,
|
||||
const bool *sharp_faces,
|
||||
int *r_totgroup,
|
||||
bool use_bitflags);
|
||||
|
||||
/* use on looptri vertex values */
|
||||
#define BKE_MESH_TESSTRI_VINDEX_ORDER(_tri, _v) \
|
||||
((CHECK_TYPE_ANY( \
|
||||
_tri, unsigned int *, int *, int[3], const unsigned int *, const int *, const int[3]), \
|
||||
CHECK_TYPE_ANY(_v, unsigned int, const unsigned int, int, const int)), \
|
||||
(((_tri)[0] == _v) ? 0 : \
|
||||
((_tri)[1] == _v) ? 1 : \
|
||||
((_tri)[2] == _v) ? 2 : \
|
||||
-1))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define BKE_MESH_TESSTRI_VINDEX_ORDER(_tri, _v) \
|
||||
((CHECK_TYPE_ANY( \
|
||||
_tri, unsigned int *, int *, int[3], const unsigned int *, const int *, const int[3]), \
|
||||
CHECK_TYPE_ANY(_v, unsigned int, const unsigned int, int, const int)), \
|
||||
(((_tri)[0] == _v) ? 0 : \
|
||||
((_tri)[1] == _v) ? 1 : \
|
||||
((_tri)[2] == _v) ? 2 : \
|
||||
-1))
|
||||
|
||||
namespace blender::bke::mesh {
|
||||
|
||||
|
||||
@@ -27,13 +27,6 @@ struct Scene;
|
||||
/** Return the number of derived triangles (looptris). */
|
||||
int BKE_mesh_runtime_looptri_len(const struct Mesh *mesh);
|
||||
|
||||
/**
|
||||
* Return mesh triangulation data, calculated lazily when necessary.
|
||||
* See #MLoopTri for further description of mesh triangulation.
|
||||
*
|
||||
* \note Prefer #Mesh::looptris() in C++ code.
|
||||
*/
|
||||
const struct MLoopTri *BKE_mesh_runtime_looptri_ensure(const struct Mesh *mesh);
|
||||
const int *BKE_mesh_runtime_looptri_faces_ensure(const struct Mesh *mesh);
|
||||
|
||||
bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh);
|
||||
|
||||
@@ -1254,11 +1254,12 @@ static void editbmesh_calc_modifiers(Depsgraph *depsgraph,
|
||||
}
|
||||
else {
|
||||
BKE_mesh_wrapper_ensure_mdata(mesh_final);
|
||||
BKE_modifier_deform_verts(md,
|
||||
&mectx,
|
||||
mesh_final,
|
||||
BKE_mesh_vert_positions_for_write(mesh_final),
|
||||
mesh_final->totvert);
|
||||
BKE_modifier_deform_verts(
|
||||
md,
|
||||
&mectx,
|
||||
mesh_final,
|
||||
reinterpret_cast<float(*)[3]>(mesh_final->vert_positions_for_write().data()),
|
||||
mesh_final->totvert);
|
||||
BKE_mesh_tag_positions_changed(mesh_final);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_idprop.h"
|
||||
#include "BKE_lib_id.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
#include "BKE_movieclip.h"
|
||||
#include "BKE_object.h"
|
||||
@@ -547,17 +547,16 @@ static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[
|
||||
}
|
||||
}
|
||||
else if (me_eval) {
|
||||
const float(*vert_normals)[3] = BKE_mesh_vert_normals_ensure(me_eval);
|
||||
const blender::Span<blender::float3> positions = me_eval->vert_positions();
|
||||
const blender::Span<blender::float3> vert_normals = me_eval->vert_normals();
|
||||
const MDeformVert *dvert = static_cast<const MDeformVert *>(
|
||||
CustomData_get_layer(&me_eval->vert_data, CD_MDEFORMVERT));
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(me_eval);
|
||||
int numVerts = me_eval->totvert;
|
||||
|
||||
/* check that dvert is a valid pointers (just in case) */
|
||||
if (dvert) {
|
||||
|
||||
/* get the average of all verts with that are in the vertex-group */
|
||||
for (int i = 0; i < numVerts; i++) {
|
||||
for (const int i : positions.index_range()) {
|
||||
const MDeformVert *dv = &dvert[i];
|
||||
const MDeformWeight *dw = BKE_defvert_find_index(dv, defgroup);
|
||||
|
||||
|
||||
@@ -3824,7 +3824,8 @@ static void dynamicPaint_brushMeshCalculateVelocity(Depsgraph *depsgraph,
|
||||
mesh_p = BKE_mesh_copy_for_eval(dynamicPaint_brush_mesh_get(brush));
|
||||
numOfVerts_p = mesh_p->totvert;
|
||||
|
||||
float(*positions_p)[3] = BKE_mesh_vert_positions_for_write(mesh_p);
|
||||
float(*positions_p)[3] = reinterpret_cast<float(*)[3]>(
|
||||
mesh_p->vert_positions_for_write().data());
|
||||
copy_m4_m4(prev_obmat, ob->object_to_world);
|
||||
|
||||
/* current frame mesh */
|
||||
@@ -3840,7 +3841,8 @@ static void dynamicPaint_brushMeshCalculateVelocity(Depsgraph *depsgraph,
|
||||
eModifierType_DynamicPaint);
|
||||
mesh_c = dynamicPaint_brush_mesh_get(brush);
|
||||
numOfVerts_c = mesh_c->totvert;
|
||||
float(*positions_c)[3] = BKE_mesh_vert_positions_for_write(mesh_c);
|
||||
float(*positions_c)[3] = reinterpret_cast<float(*)[3]>(
|
||||
mesh_c->vert_positions_for_write().data());
|
||||
|
||||
(*brushVel) = (Vec3f *)MEM_mallocN(numOfVerts_c * sizeof(Vec3f), "Dynamic Paint brush velocity");
|
||||
if (!(*brushVel)) {
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
#include "BKE_fluid.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_particle.h"
|
||||
@@ -709,8 +709,8 @@ bool get_effector_data(EffectorCache *eff,
|
||||
else if (eff->pd && eff->pd->shape == PFIELD_SHAPE_POINTS) {
|
||||
/* TODO: hair and points object support */
|
||||
const Mesh *me_eval = BKE_object_get_evaluated_mesh(eff->ob);
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(me_eval);
|
||||
const float(*vert_normals)[3] = BKE_mesh_vert_normals_ensure(me_eval);
|
||||
const blender::Span<blender::float3> positions = me_eval->vert_positions();
|
||||
const blender::Span<blender::float3> vert_normals = me_eval->vert_normals();
|
||||
if (me_eval != nullptr) {
|
||||
copy_v3_v3(efd->loc, positions[*efd->index]);
|
||||
copy_v3_v3(efd->nor, vert_normals[*efd->index]);
|
||||
|
||||
@@ -1731,18 +1731,11 @@ void BKE_mesh_count_selected_items(const Mesh *mesh, int r_count[3])
|
||||
/* We could support faces in paint modes. */
|
||||
}
|
||||
|
||||
void BKE_mesh_vert_coords_get(const Mesh *mesh, float (*vert_coords)[3])
|
||||
{
|
||||
blender::bke::AttributeAccessor attributes = mesh->attributes();
|
||||
VArray<float3> positions = *attributes.lookup_or_default(
|
||||
"position", ATTR_DOMAIN_POINT, float3(0));
|
||||
positions.materialize({(float3 *)vert_coords, mesh->totvert});
|
||||
}
|
||||
|
||||
float (*BKE_mesh_vert_coords_alloc(const Mesh *mesh, int *r_vert_len))[3]
|
||||
{
|
||||
float(*vert_coords)[3] = (float(*)[3])MEM_mallocN(sizeof(float[3]) * mesh->totvert, __func__);
|
||||
BKE_mesh_vert_coords_get(mesh, vert_coords);
|
||||
MutableSpan(reinterpret_cast<float3 *>(vert_coords), mesh->totvert)
|
||||
.copy_from(mesh->vert_positions());
|
||||
if (r_vert_len) {
|
||||
*r_vert_len = mesh->totvert;
|
||||
}
|
||||
|
||||
@@ -601,15 +601,13 @@ static void face_edge_loop_islands_calc(const int totedge,
|
||||
}
|
||||
}
|
||||
|
||||
int *BKE_mesh_calc_smoothgroups(const int totedge,
|
||||
const int *face_offsets,
|
||||
const int faces_num,
|
||||
const int *corner_edges,
|
||||
const int totloop,
|
||||
int *BKE_mesh_calc_smoothgroups(int edges_num,
|
||||
const blender::OffsetIndices<int> faces,
|
||||
const blender::Span<int> corner_edges,
|
||||
const bool *sharp_edges,
|
||||
const bool *sharp_faces,
|
||||
int *r_totgroup,
|
||||
const bool use_bitflags)
|
||||
bool use_bitflags)
|
||||
{
|
||||
int *face_groups = nullptr;
|
||||
|
||||
@@ -633,9 +631,9 @@ int *BKE_mesh_calc_smoothgroups(const int totedge,
|
||||
return true;
|
||||
};
|
||||
|
||||
face_edge_loop_islands_calc(totedge,
|
||||
blender::Span(face_offsets, faces_num + 1),
|
||||
{corner_edges, totloop},
|
||||
face_edge_loop_islands_calc(edges_num,
|
||||
faces,
|
||||
corner_edges,
|
||||
{},
|
||||
use_bitflags,
|
||||
face_is_island_boundary_smooth,
|
||||
|
||||
@@ -221,11 +221,6 @@ int BKE_mesh_runtime_looptri_len(const Mesh *mesh)
|
||||
return poly_to_tri_count(mesh->faces_num, mesh->totloop);
|
||||
}
|
||||
|
||||
const MLoopTri *BKE_mesh_runtime_looptri_ensure(const Mesh *mesh)
|
||||
{
|
||||
return mesh->looptris().data();
|
||||
}
|
||||
|
||||
const int *BKE_mesh_runtime_looptri_faces_ensure(const Mesh *mesh)
|
||||
{
|
||||
return mesh->looptri_faces().data();
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "BKE_customdata.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_lib_id.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_mesh_legacy_convert.h"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
#include "BKE_object.h"
|
||||
@@ -100,7 +100,7 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
|
||||
{
|
||||
ParticleData *pa = nullptr;
|
||||
float min[3], max[3], delta[3], d;
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(mesh);
|
||||
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
||||
int totvert = mesh->totvert, from = psys->part->from;
|
||||
int i, j, k, p, res = psys->part->grid_res, size[3], axis;
|
||||
|
||||
@@ -581,7 +581,7 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
|
||||
int rng_skip_tot = PSYS_RND_DIST_SKIP; /* count how many rng_* calls won't need skipping */
|
||||
|
||||
MFace *mface;
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(mesh);
|
||||
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
||||
|
||||
pa->num = i = ctx->index[p];
|
||||
MFace *mfaces = (MFace *)CustomData_get_layer_for_write(
|
||||
@@ -619,8 +619,18 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
|
||||
/* experimental */
|
||||
tot = mesh->totface_legacy;
|
||||
|
||||
psys_interpolate_face(
|
||||
mesh, positions, BKE_mesh_vert_normals_ensure(mesh), mface, 0, 0, pa->fuv, co, nor, 0, 0, 0);
|
||||
psys_interpolate_face(mesh,
|
||||
reinterpret_cast<const float(*)[3]>(positions.data()),
|
||||
reinterpret_cast<const float(*)[3]>(mesh->vert_normals().data()),
|
||||
mface,
|
||||
0,
|
||||
0,
|
||||
pa->fuv,
|
||||
co,
|
||||
nor,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
|
||||
normalize_v3(nor);
|
||||
negate_v3(nor);
|
||||
@@ -1003,7 +1013,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
|
||||
BKE_mesh_orco_ensure(ob, mesh);
|
||||
|
||||
if (from == PART_FROM_VERT) {
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(mesh);
|
||||
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
||||
const float(*orcodata)[3] = static_cast<const float(*)[3]>(
|
||||
CustomData_get_layer(&mesh->vert_data, CD_ORCO));
|
||||
int totvert = mesh->totvert;
|
||||
@@ -1078,7 +1088,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
|
||||
}
|
||||
}
|
||||
else {
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions_for_write(mesh);
|
||||
blender::MutableSpan<blender::float3> positions = mesh->vert_positions_for_write();
|
||||
copy_v3_v3(co1, positions[mf->v1]);
|
||||
copy_v3_v3(co2, positions[mf->v2]);
|
||||
copy_v3_v3(co3, positions[mf->v3]);
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
#include "BKE_collection.h"
|
||||
#include "BKE_lattice.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_pointcache.h"
|
||||
@@ -3347,9 +3347,8 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
|
||||
if (!mesh) {
|
||||
*r_mesh = mesh = BKE_mesh_new_nomain(totpoint, totedge, 0, 0);
|
||||
}
|
||||
float(*positions)[3] = BKE_mesh_vert_positions_for_write(mesh);
|
||||
vec2i *edge = static_cast<vec2i *>(CustomData_get_layer_named_for_write(
|
||||
&mesh->edge_data, CD_PROP_INT32_2D, ".edge_verts", mesh->totedge));
|
||||
blender::MutableSpan<blender::float3> positions = mesh->vert_positions_for_write();
|
||||
blender::int2 *edge = mesh->edges_for_write().data();
|
||||
dvert = BKE_mesh_deform_verts_for_write(mesh);
|
||||
|
||||
if (psys->clmd->hairdata == nullptr) {
|
||||
@@ -3525,12 +3524,13 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
|
||||
BKE_id_copy_ex(
|
||||
nullptr, &psys->hair_in_mesh->id, (ID **)&psys->hair_out_mesh, LIB_ID_COPY_LOCALIZE);
|
||||
|
||||
clothModifier_do(psys->clmd,
|
||||
sim->depsgraph,
|
||||
sim->scene,
|
||||
sim->ob,
|
||||
psys->hair_in_mesh,
|
||||
BKE_mesh_vert_positions_for_write(psys->hair_out_mesh));
|
||||
clothModifier_do(
|
||||
psys->clmd,
|
||||
sim->depsgraph,
|
||||
sim->scene,
|
||||
sim->ob,
|
||||
psys->hair_in_mesh,
|
||||
reinterpret_cast<float(*)[3]>(psys->hair_out_mesh->vert_positions_for_write().data()));
|
||||
BKE_mesh_tag_positions_changed(psys->hair_out_mesh);
|
||||
|
||||
/* restore cloth effector weights */
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_pointcache.h"
|
||||
@@ -368,7 +368,8 @@ static rbCollisionShape *rigidbody_get_shape_convexhull_from_mesh(Object *ob,
|
||||
|
||||
if (ob->type == OB_MESH && ob->data) {
|
||||
mesh = rigidbody_get_mesh(ob);
|
||||
positions = (mesh) ? BKE_mesh_vert_positions_for_write(mesh) : nullptr;
|
||||
positions = (mesh) ? reinterpret_cast<float(*)[3]>(mesh->vert_positions_for_write().data()) :
|
||||
nullptr;
|
||||
totvert = (mesh) ? mesh->totvert : 0;
|
||||
}
|
||||
else {
|
||||
@@ -394,23 +395,16 @@ static rbCollisionShape *rigidbody_get_shape_trimesh_from_mesh(Object *ob)
|
||||
rbCollisionShape *shape = nullptr;
|
||||
|
||||
if (ob->type == OB_MESH) {
|
||||
Mesh *mesh = nullptr;
|
||||
const MLoopTri *looptri;
|
||||
int totvert;
|
||||
int tottri;
|
||||
|
||||
mesh = rigidbody_get_mesh(ob);
|
||||
|
||||
/* ensure mesh validity, then grab data */
|
||||
Mesh *mesh = rigidbody_get_mesh(ob);
|
||||
if (mesh == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(mesh);
|
||||
totvert = mesh->totvert;
|
||||
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
||||
tottri = BKE_mesh_runtime_looptri_len(mesh);
|
||||
const int *corner_verts = BKE_mesh_corner_verts(mesh);
|
||||
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
||||
const int totvert = mesh->totvert;
|
||||
const blender::Span<MLoopTri> looptris = mesh->looptris();
|
||||
const int tottri = looptris.size();
|
||||
const blender::Span<int> corner_verts = mesh->corner_verts();
|
||||
|
||||
/* sanity checking - potential case when no data will be present */
|
||||
if ((totvert == 0) || (tottri == 0)) {
|
||||
@@ -424,20 +418,20 @@ static rbCollisionShape *rigidbody_get_shape_trimesh_from_mesh(Object *ob)
|
||||
/* init mesh data for collision shape */
|
||||
mdata = RB_trimesh_data_new(tottri, totvert);
|
||||
|
||||
RB_trimesh_add_vertices(mdata, (float *)positions, totvert, sizeof(float[3]));
|
||||
RB_trimesh_add_vertices(mdata, (float *)positions.data(), totvert, sizeof(float[3]));
|
||||
|
||||
/* loop over all faces, adding them as triangles to the collision shape
|
||||
* (so for some faces, more than triangle will get added)
|
||||
*/
|
||||
if (positions && looptri) {
|
||||
if (positions.data()) {
|
||||
for (i = 0; i < tottri; i++) {
|
||||
/* add first triangle - verts 1,2,3 */
|
||||
const MLoopTri *lt = &looptri[i];
|
||||
const MLoopTri < = looptris[i];
|
||||
int vtri[3];
|
||||
|
||||
vtri[0] = corner_verts[lt->tri[0]];
|
||||
vtri[1] = corner_verts[lt->tri[1]];
|
||||
vtri[2] = corner_verts[lt->tri[2]];
|
||||
vtri[0] = corner_verts[lt.tri[0]];
|
||||
vtri[1] = corner_verts[lt.tri[1]];
|
||||
vtri[2] = corner_verts[lt.tri[2]];
|
||||
|
||||
RB_trimesh_add_triangle_indices(mdata, i, UNPACK3(vtri));
|
||||
}
|
||||
@@ -674,22 +668,22 @@ void BKE_rigidbody_calc_volume(Object *ob, float *r_vol)
|
||||
case RB_SHAPE_TRIMESH: {
|
||||
if (ob->type == OB_MESH) {
|
||||
Mesh *mesh = rigidbody_get_mesh(ob);
|
||||
const MLoopTri *lt = nullptr;
|
||||
int totvert, tottri = 0;
|
||||
|
||||
/* ensure mesh validity, then grab data */
|
||||
if (mesh == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(mesh);
|
||||
totvert = mesh->totvert;
|
||||
lt = BKE_mesh_runtime_looptri_ensure(mesh);
|
||||
tottri = BKE_mesh_runtime_looptri_len(mesh);
|
||||
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
||||
const blender::Span<MLoopTri> looptris = mesh->looptris();
|
||||
const int *corner_verts = BKE_mesh_corner_verts(mesh);
|
||||
|
||||
if (totvert > 0 && tottri > 0) {
|
||||
BKE_mesh_calc_volume(positions, totvert, lt, tottri, corner_verts, &volume, nullptr);
|
||||
if (!positions.is_empty() && !looptris.is_empty()) {
|
||||
BKE_mesh_calc_volume(reinterpret_cast<const float(*)[3]>(positions.data()),
|
||||
positions.size(),
|
||||
looptris.data(),
|
||||
looptris.size(),
|
||||
corner_verts,
|
||||
&volume,
|
||||
nullptr);
|
||||
const float volume_scale = mat4_to_volume_scale(ob->object_to_world);
|
||||
volume *= fabsf(volume_scale);
|
||||
}
|
||||
@@ -748,22 +742,21 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3])
|
||||
case RB_SHAPE_TRIMESH: {
|
||||
if (ob->type == OB_MESH) {
|
||||
Mesh *mesh = rigidbody_get_mesh(ob);
|
||||
const MLoopTri *looptri;
|
||||
int totvert, tottri;
|
||||
|
||||
/* ensure mesh validity, then grab data */
|
||||
if (mesh == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(mesh);
|
||||
totvert = mesh->totvert;
|
||||
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
||||
tottri = BKE_mesh_runtime_looptri_len(mesh);
|
||||
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
||||
const blender::Span<MLoopTri> looptris = mesh->looptris();
|
||||
|
||||
if (totvert > 0 && tottri > 0) {
|
||||
BKE_mesh_calc_volume(
|
||||
positions, totvert, looptri, tottri, BKE_mesh_corner_verts(mesh), nullptr, r_center);
|
||||
if (!positions.is_empty() && !looptris.is_empty()) {
|
||||
BKE_mesh_calc_volume(reinterpret_cast<const float(*)[3]>(positions.data()),
|
||||
positions.size(),
|
||||
looptris.data(),
|
||||
looptris.size(),
|
||||
mesh->corner_verts().data(),
|
||||
nullptr,
|
||||
r_center);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1771,7 +1764,8 @@ static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Object *ob, RigidBodyO
|
||||
if (rbo->shape == RB_SHAPE_TRIMESH && rbo->flag & RBO_FLAG_USE_DEFORM) {
|
||||
Mesh *mesh = ob->runtime.mesh_deform_eval;
|
||||
if (mesh) {
|
||||
float(*positions)[3] = BKE_mesh_vert_positions_for_write(mesh);
|
||||
float(*positions)[3] = reinterpret_cast<float(*)[3]>(
|
||||
mesh->vert_positions_for_write().data());
|
||||
int totvert = mesh->totvert;
|
||||
const BoundBox *bb = BKE_object_boundbox_get(ob);
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ static void merge_vert_dir(ShrinkwrapBoundaryVertData *vdata,
|
||||
static ShrinkwrapBoundaryData *shrinkwrap_build_boundary_data(Mesh *mesh)
|
||||
{
|
||||
using namespace blender;
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(mesh);
|
||||
const blender::Span<float3> positions = mesh->vert_positions();
|
||||
const blender::Span<int2> edges = mesh->edges();
|
||||
const Span<int> corner_verts = mesh->corner_verts();
|
||||
const Span<int> corner_edges = mesh->corner_edges();
|
||||
@@ -1424,7 +1424,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd,
|
||||
|
||||
if (mesh != nullptr && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) {
|
||||
/* Setup arrays to get vertex positions, normals and deform weights */
|
||||
calc.vert_positions = BKE_mesh_vert_positions_for_write(mesh);
|
||||
calc.vert_positions = reinterpret_cast<float(*)[3]>(mesh->vert_positions_for_write().data());
|
||||
calc.vert_normals = mesh->vert_normals();
|
||||
|
||||
/* Using vertices positions/normals as if a subsurface was applied */
|
||||
@@ -1554,15 +1554,16 @@ void BKE_shrinkwrap_mesh_nearest_surface_deform(bContext *C, Object *ob_source,
|
||||
|
||||
Mesh *src_me = static_cast<Mesh *>(ob_source->data);
|
||||
|
||||
shrinkwrapModifier_deform(&ssmd,
|
||||
&ctx,
|
||||
sce,
|
||||
ob_source,
|
||||
src_me,
|
||||
nullptr,
|
||||
-1,
|
||||
BKE_mesh_vert_positions_for_write(src_me),
|
||||
src_me->totvert);
|
||||
shrinkwrapModifier_deform(
|
||||
&ssmd,
|
||||
&ctx,
|
||||
sce,
|
||||
ob_source,
|
||||
src_me,
|
||||
nullptr,
|
||||
-1,
|
||||
reinterpret_cast<float(*)[3]>(src_me->vert_positions_for_write().data()),
|
||||
src_me->totvert);
|
||||
BKE_mesh_tag_positions_changed(src_me);
|
||||
}
|
||||
|
||||
@@ -1585,12 +1586,12 @@ void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object
|
||||
|
||||
calc.smd = &ssmd;
|
||||
calc.numVerts = src_me->totvert;
|
||||
calc.vertexCos = BKE_mesh_vert_positions_for_write(src_me);
|
||||
calc.vertexCos = reinterpret_cast<float(*)[3]>(src_me->vert_positions_for_write().data());
|
||||
calc.vert_normals = src_me->vert_normals();
|
||||
calc.vgroup = -1;
|
||||
calc.target = target_me;
|
||||
calc.keepDist = ssmd.keepDist;
|
||||
calc.vert_positions = BKE_mesh_vert_positions_for_write(src_me);
|
||||
calc.vert_positions = reinterpret_cast<float(*)[3]>(src_me->vert_positions_for_write().data());
|
||||
BLI_SPACE_TRANSFORM_SETUP(&calc.local2target, ob_target, ob_target);
|
||||
|
||||
ShrinkwrapTreeData tree;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "BKE_action.h"
|
||||
#include "BKE_armature.h"
|
||||
#include "BKE_deform.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_mesh_iterators.h"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
#include "BKE_modifier.h"
|
||||
@@ -416,7 +416,7 @@ static void add_verts_to_dgroups(ReportList *reports,
|
||||
}
|
||||
|
||||
/* transform verts to global space */
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(mesh);
|
||||
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
||||
for (int i = 0; i < mesh->totvert; i++) {
|
||||
if (!vertsfilled) {
|
||||
copy_v3_v3(verts[i], positions[i]);
|
||||
|
||||
@@ -344,8 +344,9 @@ XFormObjectData *ED_object_data_xform_create_ex(ID *id, bool is_edit_mode)
|
||||
XFormObjectData_Mesh *xod = static_cast<XFormObjectData_Mesh *>(
|
||||
MEM_mallocN(sizeof(*xod) + (sizeof(*xod->elem_array) * elem_array_len), __func__));
|
||||
memset(xod, 0x0, sizeof(*xod));
|
||||
blender::MutableSpan(reinterpret_cast<blender::float3 *>(xod->elem_array), me->totvert)
|
||||
.copy_from(me->vert_positions());
|
||||
|
||||
BKE_mesh_vert_coords_get(me, xod->elem_array);
|
||||
xod_base = &xod->base;
|
||||
|
||||
if (key != nullptr) {
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_mesh_legacy_convert.h"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
#include "BKE_modifier.h"
|
||||
@@ -1459,8 +1459,8 @@ void recalc_emitter_field(Depsgraph * /*depsgraph*/, Object * /*ob*/, ParticleSy
|
||||
vec = edit->emitter_cosnos;
|
||||
nor = vec + 3;
|
||||
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(mesh);
|
||||
const float(*vert_normals)[3] = BKE_mesh_vert_normals_ensure(mesh);
|
||||
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
||||
const blender::Span<blender::float3> vert_normals = mesh->vert_normals();
|
||||
const MFace *mfaces = (const MFace *)CustomData_get_layer(&mesh->fdata_legacy, CD_MFACE);
|
||||
for (i = 0; i < totface; i++, vec += 6, nor += 6) {
|
||||
const MFace *mface = &mfaces[i];
|
||||
@@ -4217,7 +4217,7 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
|
||||
|
||||
totface = mesh->totface_legacy;
|
||||
mface = (const MFace *)CustomData_get_layer(&mesh->fdata_legacy, CD_MFACE);
|
||||
float(*positions)[3] = BKE_mesh_vert_positions_for_write(mesh);
|
||||
blender::MutableSpan<blender::float3> positions = mesh->vert_positions_for_write();
|
||||
|
||||
/* lets intersect the faces */
|
||||
for (i = 0; i < totface; i++, mface++) {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_lib_id.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_mesh_legacy_convert.h"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
#include "BKE_modifier.h"
|
||||
@@ -752,7 +752,7 @@ static bool remap_hair_emitter(Depsgraph *depsgraph,
|
||||
BKE_mesh_tessface_ensure(mesh);
|
||||
|
||||
numverts = mesh->totvert;
|
||||
float(*positions)[3] = BKE_mesh_vert_positions_for_write(mesh);
|
||||
blender::MutableSpan<blender::float3> positions = mesh->vert_positions_for_write();
|
||||
|
||||
/* convert to global coordinates */
|
||||
for (int i = 0; i < numverts; i++) {
|
||||
|
||||
@@ -1167,7 +1167,9 @@ static void sculpt_gesture_trim_geometry_generate(SculptGestureContext *sgcontex
|
||||
const float(*ob_imat)[4] = vc->obact->world_to_object;
|
||||
|
||||
/* Write vertices coordinatesSCULPT_GESTURE_TRIM_DIFFERENCE for the front face. */
|
||||
float(*positions)[3] = BKE_mesh_vert_positions_for_write(trim_operation->mesh);
|
||||
blender::MutableSpan<blender::float3> positions =
|
||||
trim_operation->mesh->vert_positions_for_write();
|
||||
|
||||
float depth_point[3];
|
||||
|
||||
/* Get origin point for SCULPT_GESTURE_TRIM_ORIENTATION_VIEW.
|
||||
@@ -1421,7 +1423,7 @@ static void sculpt_gesture_trim_apply_for_symmetry_pass(bContext * /*C*/,
|
||||
{
|
||||
SculptGestureTrimOperation *trim_operation = (SculptGestureTrimOperation *)sgcontext->operation;
|
||||
Mesh *trim_mesh = trim_operation->mesh;
|
||||
float(*positions)[3] = BKE_mesh_vert_positions_for_write(trim_mesh);
|
||||
blender::MutableSpan<blender::float3> positions = trim_mesh->vert_positions_for_write();
|
||||
for (int i = 0; i < trim_mesh->totvert; i++) {
|
||||
flip_v3_v3(positions[i], trim_operation->true_mesh_co[i], sgcontext->symmpass);
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ static void imapaint_pick_uv(const Mesh *me_eval,
|
||||
int view[4];
|
||||
const ePaintCanvasSource mode = ePaintCanvasSource(scene->toolsettings->imapaint.mode);
|
||||
|
||||
const MLoopTri *lt = BKE_mesh_runtime_looptri_ensure(me_eval);
|
||||
const blender::Span<MLoopTri> tris = me_eval->looptris();
|
||||
const int tottri = BKE_mesh_runtime_looptri_len(me_eval);
|
||||
const int *looptri_faces = BKE_mesh_runtime_looptri_faces_ensure(me_eval);
|
||||
|
||||
@@ -301,7 +301,7 @@ static void imapaint_pick_uv(const Mesh *me_eval,
|
||||
|
||||
/* test all faces in the derivedmesh with the original index of the picked face */
|
||||
/* face means poly here, not triangle, indeed */
|
||||
for (i = 0; i < tottri; i++, lt++) {
|
||||
for (i = 0; i < tottri; i++) {
|
||||
const int face_i = looptri_faces[i];
|
||||
findex = index_mp_to_orig ? index_mp_to_orig[face_i] : face_i;
|
||||
|
||||
@@ -311,7 +311,7 @@ static void imapaint_pick_uv(const Mesh *me_eval,
|
||||
float tri_co[3][3];
|
||||
|
||||
for (int j = 3; j--;) {
|
||||
copy_v3_v3(tri_co[j], positions[corner_verts[lt->tri[j]]]);
|
||||
copy_v3_v3(tri_co[j], positions[corner_verts[tris[i].tri[j]]]);
|
||||
}
|
||||
|
||||
if (mode == PAINT_CANVAS_SOURCE_MATERIAL) {
|
||||
@@ -335,9 +335,9 @@ static void imapaint_pick_uv(const Mesh *me_eval,
|
||||
CustomData_get_layer(&me_eval->loop_data, CD_PROP_FLOAT2));
|
||||
}
|
||||
|
||||
tri_uv[0] = mloopuv[lt->tri[0]];
|
||||
tri_uv[1] = mloopuv[lt->tri[1]];
|
||||
tri_uv[2] = mloopuv[lt->tri[2]];
|
||||
tri_uv[0] = mloopuv[tris[i].tri[0]];
|
||||
tri_uv[1] = mloopuv[tris[i].tri[1]];
|
||||
tri_uv[2] = mloopuv[tris[i].tri[2]];
|
||||
|
||||
p[0] = xy[0];
|
||||
p[1] = xy[1];
|
||||
|
||||
@@ -203,10 +203,8 @@ void OBJMesh::calc_smooth_groups(const bool use_bitflags)
|
||||
const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&export_mesh_->face_data, CD_PROP_BOOL, "sharp_face"));
|
||||
poly_smooth_groups_ = BKE_mesh_calc_smoothgroups(mesh_edges_.size(),
|
||||
mesh_faces_.data(),
|
||||
mesh_faces_.size(),
|
||||
export_mesh_->corner_edges().data(),
|
||||
export_mesh_->totloop,
|
||||
mesh_faces_,
|
||||
export_mesh_->corner_edges(),
|
||||
sharp_edges,
|
||||
sharp_faces,
|
||||
&tot_smooth_groups_,
|
||||
|
||||
@@ -52,11 +52,11 @@ enum {
|
||||
* any changes to the underlying mesh invalidate the #MLoopTri array,
|
||||
* which will need to be re-calculated.
|
||||
*
|
||||
* Users normally access this via #BKE_mesh_runtime_looptri_ensure.
|
||||
* In rare cases its calculated directly, with #BKE_mesh_recalc_looptri.
|
||||
* Users normally access this via #Mesh::looptris().
|
||||
* In rare cases its calculated directly, with #bke::mesh::looptris_calc.
|
||||
*
|
||||
* Typical usage includes:
|
||||
* - OpenGL drawing.
|
||||
* - Viewport drawing.
|
||||
* - #BVHTree creation.
|
||||
* - Physics/collision detection.
|
||||
*
|
||||
|
||||
@@ -101,10 +101,8 @@ static void rna_Mesh_calc_smooth_groups(
|
||||
const bool *sharp_faces = (const bool *)CustomData_get_layer_named(
|
||||
&mesh->face_data, CD_PROP_BOOL, "sharp_face");
|
||||
*r_poly_group = BKE_mesh_calc_smoothgroups(mesh->totedge,
|
||||
BKE_mesh_face_offsets(mesh),
|
||||
mesh->faces_num,
|
||||
mesh->corner_edges().data(),
|
||||
mesh->totloop,
|
||||
mesh->faces(),
|
||||
mesh->corner_edges(),
|
||||
sharp_edges,
|
||||
sharp_faces,
|
||||
r_group_total,
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "RNA_define.h"
|
||||
#include "RNA_enum_types.h"
|
||||
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_mesh_legacy_convert.h"
|
||||
|
||||
#include "BLI_listbase.h"
|
||||
@@ -215,7 +215,7 @@ static void rna_ParticleHairKey_location_object_get(PointerRNA *ptr, float *valu
|
||||
Mesh *hair_mesh = (psmd->psys->flag & PSYS_HAIR_DYNAMICS) ? psmd->psys->hair_out_mesh :
|
||||
nullptr;
|
||||
if (hair_mesh) {
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(hair_mesh);
|
||||
const blender::Span<blender::float3> positions = hair_mesh->vert_positions();
|
||||
copy_v3_v3(values, positions[pa->hair_index + (hkey - pa->hair)]);
|
||||
}
|
||||
else {
|
||||
@@ -280,7 +280,7 @@ static void hair_key_location_object_set(HairKey *hair_key,
|
||||
if (hair_key_index == -1) {
|
||||
return;
|
||||
}
|
||||
float(*positions)[3] = BKE_mesh_vert_positions_for_write(hair_mesh);
|
||||
blender::MutableSpan<blender::float3> positions = hair_mesh->vert_positions_for_write();
|
||||
copy_v3_v3(positions[particle->hair_index + (hair_key_index)], src_co);
|
||||
return;
|
||||
}
|
||||
@@ -324,7 +324,7 @@ static void rna_ParticleHairKey_co_object(HairKey *hairkey,
|
||||
nullptr;
|
||||
if (particle) {
|
||||
if (hair_mesh) {
|
||||
const float(*positions)[3] = BKE_mesh_vert_positions(hair_mesh);
|
||||
const blender::Span<blender::float3> positions = hair_mesh->vert_positions();
|
||||
copy_v3_v3(n_co, positions[particle->hair_index + (hairkey - particle->hair)]);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -150,12 +150,12 @@ static void deformVerts(ModifierData *md,
|
||||
collmd->mvert_num = mvert_num;
|
||||
|
||||
{
|
||||
const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
||||
collmd->tri_num = BKE_mesh_runtime_looptri_len(mesh);
|
||||
const blender::Span<MLoopTri> looptris = mesh->looptris();
|
||||
collmd->tri_num = looptris.size();
|
||||
MVertTri *tri = static_cast<MVertTri *>(
|
||||
MEM_mallocN(sizeof(*tri) * collmd->tri_num, __func__));
|
||||
BKE_mesh_runtime_verttri_from_looptri(
|
||||
tri, mesh->corner_verts().data(), looptri, collmd->tri_num);
|
||||
tri, mesh->corner_verts().data(), looptris.data(), collmd->tri_num);
|
||||
collmd->tri = tri;
|
||||
}
|
||||
|
||||
|
||||
@@ -746,7 +746,7 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh)
|
||||
|
||||
layers_num = CustomData_number_of_layers(&split_m->fdata_legacy, CD_MTFACE);
|
||||
|
||||
float(*split_m_positions)[3] = BKE_mesh_vert_positions_for_write(split_m);
|
||||
blender::MutableSpan<blender::float3> split_m_positions = split_m->vert_positions_for_write();
|
||||
|
||||
/* copy new faces & verts (is it really this painful with custom data??) */
|
||||
for (i = 0; i < totvert; i++) {
|
||||
@@ -1004,7 +1004,7 @@ static Mesh *explodeMesh(ExplodeModifierData *emd,
|
||||
psys_sim_data_init(&sim);
|
||||
|
||||
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
||||
float(*explode_positions)[3] = BKE_mesh_vert_positions_for_write(explode);
|
||||
blender::MutableSpan<blender::float3> explode_positions = explode->vert_positions_for_write();
|
||||
|
||||
/* duplicate & displace vertices */
|
||||
ehi = BLI_edgehashIterator_new(vertpahash);
|
||||
|
||||
@@ -180,7 +180,7 @@ static void meshcache_do(MeshCacheModifierData *mcmd,
|
||||
MEM_malloc_arrayN(verts_num, sizeof(*vertexCos_New), __func__));
|
||||
|
||||
BKE_mesh_calc_relative_deform(
|
||||
BKE_mesh_face_offsets(me),
|
||||
me->face_offsets().data(),
|
||||
me->faces_num,
|
||||
me->corner_verts().data(),
|
||||
me->totvert,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BKE_attribute.hh"
|
||||
#include "BKE_deform.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_particle.h"
|
||||
|
||||
Reference in New Issue
Block a user