Mesh: Replace MLoop struct with generic attributes #104424

Merged
Hans Goudey merged 261 commits from refactor-mesh-corners-generic into main 2023-03-20 15:55:25 +01:00
78 changed files with 822 additions and 813 deletions
Showing only changes of commit ade37d8380 - Show all commits

View File

@ -127,7 +127,7 @@ struct DerivedMesh {
* and freed on the next ->release(). consider using getVert/Edge/Face if
* you are only interested in a few verts/edges/faces.
*/
struct MVert *(*getVertArray)(DerivedMesh *dm);
float (*) (*getVertArray)(DerivedMesh *dm)[3];
struct MEdge *(*getEdgeArray)(DerivedMesh *dm);
struct MLoop *(*getLoopArray)(DerivedMesh *dm);
struct MPoly *(*getPolyArray)(DerivedMesh *dm);
@ -135,7 +135,7 @@ struct DerivedMesh {
/** Copy all verts/edges/faces from the derived mesh into
* *{vert/edge/face}_r (must point to a buffer large enough)
*/
void (*copyVertArray)(DerivedMesh *dm, struct MVert *r_vert);
void (*copyVertArray)(DerivedMesh *dm, float (*r_positions)[3]);
void (*copyEdgeArray)(DerivedMesh *dm, struct MEdge *r_edge);
void (*copyLoopArray)(DerivedMesh *dm, struct MLoop *r_loop);
void (*copyPolyArray)(DerivedMesh *dm, struct MPoly *r_poly);

View File

@ -678,6 +678,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
* float array rather than MVert*. Tracked along with mesh_final as an
* optimization to avoid copying coordinates back and forth if there are
* multiple sequential deform only modifiers. */
/* TODO(@Hans): Remove this. */
float(*deformed_verts)[3] = nullptr;
int num_deformed_verts = mesh_input->totvert;
bool isPrevDeform = false;

View File

@ -29,6 +29,7 @@
#include "BLI_math.h"
#include "BLI_math_vector.hh"
#include "BLI_memarena.h"
#include "BLI_resource_scope.hh"
#include "BLI_span.hh"
#include "BLI_string.h"
#include "BLI_task.hh"
@ -227,6 +228,7 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
Vector<CustomDataLayer, 16> edge_layers;
Vector<CustomDataLayer, 16> loop_layers;
Vector<CustomDataLayer, 16> poly_layers;
blender::ResourceScope temp_arrays_for_legacy_format;
/* cache only - don't write */
mesh->mface = nullptr;
@ -251,9 +253,6 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
else {
Set<std::string> names_to_skip;
if (!BLO_write_is_undo(writer)) {
BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh);
BKE_mesh_legacy_bevel_weight_from_layers(mesh);
/* When converting to the old mesh format, don't save redundant attributes. */
names_to_skip.add_multiple_new({".hide_vert",
".hide_edge",
@ -275,6 +274,13 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
CustomData_blend_write_prepare(mesh->edata, edge_layers, names_to_skip);
CustomData_blend_write_prepare(mesh->ldata, loop_layers, names_to_skip);
CustomData_blend_write_prepare(mesh->pdata, poly_layers, names_to_skip);
if (!BLO_write_is_undo(writer)) {
BKE_mesh_legacy_convert_positions_to_verts(mesh, temp_arrays_for_legacy_format, vert_layers);
BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh);
BKE_mesh_legacy_bevel_weight_from_layers(mesh);
}
}
BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
@ -359,6 +365,7 @@ static void mesh_blend_read_data(BlendDataReader *reader, ID *id)
BKE_mesh_legacy_convert_flags_to_hide_layers(mesh);
BKE_mesh_legacy_convert_mpoly_to_material_indices(mesh);
BKE_mesh_legacy_bevel_weight_to_layers(mesh);
BKE_mesh_legacy_convert_verts_to_positions(mesh);
}
/* We don't expect to load normals from files, since they are derived data. */
@ -479,9 +486,8 @@ static int customdata_compare(
const float thresh_sq = thresh * thresh;
CustomDataLayer *l1, *l2;
int layer_count1 = 0, layer_count2 = 0, j;
const uint64_t cd_mask_non_generic = CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MPOLY |
CD_MASK_MLOOPUV | CD_MASK_PROP_BYTE_COLOR |
CD_MASK_MDEFORMVERT;
const uint64_t cd_mask_non_generic = CD_MASK_MEDGE | CD_MASK_MPOLY | CD_MASK_MLOOPUV |
CD_MASK_PROP_BYTE_COLOR | CD_MASK_MDEFORMVERT;
const uint64_t cd_mask_all_attr = CD_MASK_PROP_ALL | cd_mask_non_generic;
const Span<MLoop> loops_1 = m1->loops();
const Span<MLoop> loops_2 = m2->loops();

View File

@ -17,8 +17,10 @@
#include "BLI_edgehash.h"
#include "BLI_math.h"
#include "BLI_math_vec_types.hh"
#include "BLI_memarena.h"
#include "BLI_polyfill_2d.h"
#include "BLI_resource_scope.hh"
#include "BLI_task.hh"
#include "BLI_utildefines.h"
@ -29,6 +31,9 @@
#include "BKE_mesh_legacy_convert.h"
#include "BKE_multires.h"
using blender::MutableSpan;
using blender::Span;
/* -------------------------------------------------------------------- */
/** \name NGon Tessellation (NGon to MFace Conversion)
* \{ */
@ -578,7 +583,7 @@ int BKE_mesh_mface_index_validate(MFace *mface, CustomData *fdata, int mfindex,
static int mesh_tessface_calc(CustomData *fdata,
CustomData *ldata,
CustomData *pdata,
MVert *mvert,
float (*positions)[3],
int totface,
int totloop,
int totpoly)
@ -708,9 +713,9 @@ static int mesh_tessface_calc(CustomData *fdata,
/* Calculate the normal, flipped: to get a positive 2D cross product. */
ml = mloop + mp_loopstart;
co_prev = mvert[ml[mp_totloop - 1].v].co;
co_prev = positions[ml[mp_totloop - 1].v];
for (j = 0; j < mp_totloop; j++, ml++) {
co_curr = mvert[ml->v].co;
co_curr = positions[ml->v];
add_newell_cross_v3_v3v3(normal, co_prev, co_curr);
co_prev = co_curr;
}
@ -723,7 +728,7 @@ static int mesh_tessface_calc(CustomData *fdata,
ml = mloop + mp_loopstart;
for (j = 0; j < mp_totloop; j++, ml++) {
mul_v2_m3v3(projverts[j], axis_mat, mvert[ml->v].co);
mul_v2_m3v3(projverts[j], axis_mat, positions[ml->v]);
}
BLI_polyfill_calc_arena(projverts, mp_totloop, 1, tris, arena);
@ -925,7 +930,8 @@ void BKE_mesh_add_mface_layers(CustomData *fdata, CustomData *ldata, int total)
void BKE_mesh_legacy_bevel_weight_from_layers(Mesh *mesh)
{
using namespace blender;
MutableSpan<MVert> verts = mesh->positions_for_write();
MutableSpan<MVert> verts(static_cast<MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)),
mesh->totvert);
if (const float *weights = static_cast<const float *>(
CustomData_get_layer(&mesh->vdata, CD_BWEIGHT))) {
mesh->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
@ -958,7 +964,8 @@ void BKE_mesh_legacy_bevel_weight_from_layers(Mesh *mesh)
void BKE_mesh_legacy_bevel_weight_to_layers(Mesh *mesh)
{
using namespace blender;
const Span<MVert> verts = mesh->positions();
const Span<MVert> verts(static_cast<MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)),
mesh->totvert);
if (mesh->cd_flag & ME_CDFLAG_VERT_BWEIGHT) {
float *weights = static_cast<float *>(
CustomData_add_layer(&mesh->vdata, CD_BWEIGHT, CD_CONSTRUCT, nullptr, verts.size()));
@ -989,7 +996,8 @@ void BKE_mesh_legacy_convert_hide_layers_to_flags(Mesh *mesh)
using namespace blender::bke;
const AttributeAccessor attributes = mesh->attributes();
MutableSpan<MVert> verts = mesh->positions_for_write();
MutableSpan<MVert> verts(static_cast<MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)),
mesh->totvert);
const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
".hide_vert", ATTR_DOMAIN_POINT, false);
threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
@ -1023,7 +1031,8 @@ void BKE_mesh_legacy_convert_flags_to_hide_layers(Mesh *mesh)
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh->attributes_for_write();
const Span<MVert> verts = mesh->positions();
const Span<MVert> verts(static_cast<MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)),
mesh->totvert);
if (std::any_of(
verts.begin(), verts.end(), [](const MVert &vert) { return vert.flag & ME_HIDE; })) {
SpanAttributeWriter<bool> hide_vert = attributes.lookup_or_add_for_write_only_span<bool>(
@ -1115,7 +1124,8 @@ void BKE_mesh_legacy_convert_selection_layers_to_flags(Mesh *mesh)
using namespace blender::bke;
const AttributeAccessor attributes = mesh->attributes();
MutableSpan<MVert> verts = mesh->positions_for_write();
MutableSpan<MVert> verts(static_cast<MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)),
mesh->totvert);
const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
".selection_vert", ATTR_DOMAIN_POINT, false);
threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
@ -1149,7 +1159,8 @@ void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh->attributes_for_write();
const Span<MVert> verts = mesh->positions();
const Span<MVert> verts(static_cast<MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)),
mesh->totvert);
if (std::any_of(
verts.begin(), verts.end(), [](const MVert &vert) { return vert.flag & SELECT; })) {
SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_only_span<bool>(
@ -1190,3 +1201,60 @@ void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Vertex and Position Conversion
* \{ */
void BKE_mesh_legacy_convert_positions_to_verts(
Mesh *mesh,
blender::ResourceScope &temp_arrays_for_convert,
blender::Vector<CustomDataLayer, 16> &vert_layers_to_write)
{
Vector<CustomDataLayer, 16> new_layer_to_write;
for (const CustomDataLayer &layer : vert_layers_to_write) {
if (layer.type != CD_PROP_FLOAT2) {
new_layer_to_write.append(layer);
continue;
}
const Span<float3> positions{static_cast<const float3 *>(layer.data), mesh->totvert};
CustomDataLayer mvert_layer = layer;
mvert_layer.type = CD_MVERT;
MutableSpan<MVert> verts = temp_arrays_for_convert.construct<Array<MVert>>(mesh->totvert);
mvert_layer.data = verts.data();
threading::parallel_for(verts.index_range(), 2048, [&](IndexRange range) {
for (const int i : range) {
copy_v3_v3(verts[i].co, positions[i]);
}
});
new_layer_to_write.append(mvert_layer);
}
vert_layers_to_write = new_layer_to_write;
mesh->ldata.totlayer = new_layer_to_write.size();
mesh->ldata.maxlayer = mesh->ldata.totlayer;
}
void BKE_mesh_legacy_convert_verts_to_positions(Mesh *mesh)
{
using namespace blender;
using namespace blender::bke;
const Span<MVert> verts(static_cast<MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)),
mesh->totvert);
MutableSpan<float3> positions(
static_cast<float3 *>(CustomData_add_layer_named(
&mesh->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, "position")),
mesh->totvert);
threading::parallel_for(verts.index_range(), 2048, [&](IndexRange range) {
for (const int i : range) {
positions = verts[i].co;
}
});
CustomData_free_layers(&mesh->vdata, CD_MVERT);
}
/** \} */

View File

@ -210,7 +210,7 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
const int totvert_final = totvert - tot_vtargetmap;
const MVert *mv;
const int *mv;
float(*positions)[3] = MEM_malloc_arrayN(totvert_final, sizeof(float[3]), __func__);
int *oldv = MEM_malloc_arrayN(totvert_final, sizeof(*oldv), __func__);
int *newv = MEM_malloc_arrayN(totvert, sizeof(*newv), __func__);

View File

@ -131,7 +131,6 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
(axis == 2 && mmd->flag & MOD_MIR_BISECT_AXIS_Z));
Mesh *result;
MVert *mv, *mv_prev;
MEdge *me;
MLoop *ml;
MPoly *mp;
@ -239,10 +238,11 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
}
/* mirror vertex coordinates */
mv_prev = BKE_mesh_positions_for_write(result);
mv = mv_prev + maxVerts;
for (i = 0; i < maxVerts; i++, mv++, mv_prev++) {
mul_m4_v3(mtx, mv->co);
float(*positions)[3] = BKE_mesh_positions(result);
for (i = 0; i < maxVerts; i++) {
const int vert_index_prev = i;
const int vert_index = maxVerts + i;
mul_m4_v3(mtx, positions[vert_index]);
if (do_vtargetmap) {
/* Compare location of the original and mirrored vertex,
@ -259,13 +259,14 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
* old, incorrect behavior of merging the source vertex into its copy.
*/
if (use_correct_order_on_merge) {
if (UNLIKELY(len_squared_v3v3(mv_prev->co, mv->co) < tolerance_sq)) {
if (UNLIKELY(len_squared_v3v3(positions[vert_index_prev], positions[vert_index]) <
tolerance_sq)) {
*vtmap_b = i;
tot_vtargetmap++;
/* average location */
mid_v3_v3v3(mv->co, mv_prev->co, mv->co);
copy_v3_v3(mv_prev->co, mv->co);
mid_v3_v3v3(positions[vert_index], positions[vert_index_prev], positions[vert_index]);
copy_v3_v3(positions[vert_index_prev], positions[vert_index]);
}
else {
*vtmap_b = -1;
@ -275,13 +276,14 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
*vtmap_a = -1;
}
else {
if (UNLIKELY(len_squared_v3v3(mv_prev->co, mv->co) < tolerance_sq)) {
if (UNLIKELY(len_squared_v3v3(positions[vert_index_prev], positions[vert_index]) <
tolerance_sq)) {
*vtmap_a = maxVerts + i;
tot_vtargetmap++;
/* average location */
mid_v3_v3v3(mv->co, mv_prev->co, mv->co);
copy_v3_v3(mv_prev->co, mv->co);
mid_v3_v3v3(positions[vert_index], positions[vert_index_prev], positions[vert_index]);
copy_v3_v3(positions[vert_index_prev], positions[vert_index]);
}
else {
*vtmap_a = -1;

View File

@ -1191,8 +1191,8 @@ void BKE_modifier_blend_write(BlendWriter *writer, const ID *id_owner, ListBase
CollisionModifierData *collmd = (CollisionModifierData *)md;
/* TODO: CollisionModifier should use pointcache
* + have proper reset events before enabling this. */
writestruct(wd, DATA, MVert, collmd->numverts, collmd->x);
writestruct(wd, DATA, MVert, collmd->numverts, collmd->xnew);
writestruct(wd, DATA, float[3], collmd->numverts, collmd->x);
writestruct(wd, DATA, float[3], collmd->numverts, collmd->xnew);
writestruct(wd, DATA, MFace, collmd->numfaces, collmd->mfaces);
#endif
}

View File

@ -19,7 +19,6 @@ struct Mesh;
struct MLoop;
struct MPoly;
struct MultiresModifierData;
struct MVert;
struct Object;
struct Subdiv;
struct SubdivCCG;

View File

@ -1239,7 +1239,7 @@ typedef struct ParticleInterpolationData {
HairKey *hkey[2];
Mesh *mesh;
MVert *mvert[2];
float *positions[2];
int keyed;
ParticleKey *kkey[2];
@ -1399,9 +1399,9 @@ static void init_particle_interpolation(Object *ob,
pind->dietime = (key + pa->totkey - 1)->time;
if (pind->mesh) {
MVert *verts = BKE_mesh_positions_for_write(pind->mesh);
pind->mvert[0] = &verts[pa->hair_index];
pind->mvert[1] = pind->mvert[0] + 1;
float(*positions)[3] = BKE_mesh_positions_for_write(pind->mesh);
pind->positions[0] = &positions[pa->hair_index];
pind->positions[1] = pind->positions[0] + 1;
}
}
}
@ -1419,9 +1419,9 @@ static void hair_to_particle(ParticleKey *key, HairKey *hkey)
key->time = hkey->time;
}
static void mvert_to_particle(ParticleKey *key, MVert *mvert, HairKey *hkey)
static void mvert_to_particle(ParticleKey *key, float position[3], HairKey *hkey)
{
copy_v3_v3(key->co, mvert->co);
copy_v3_v3(key->co, position);
key->time = hkey->time;
}
@ -1519,7 +1519,7 @@ static void do_particle_interpolation(ParticleSystem *psys,
while (pind->hkey[1]->time < real_t) {
pind->hkey[1]++;
pind->mvert[1]++;
pind->positions[1]++;
}
pind->hkey[0] = pind->hkey[1] - 1;
@ -1531,9 +1531,9 @@ static void do_particle_interpolation(ParticleSystem *psys,
edit_to_particle(keys + 2, pind->ekey[1]);
}
else if (pind->mesh) {
pind->mvert[0] = pind->mvert[1] - 1;
mvert_to_particle(keys + 1, pind->mvert[0], pind->hkey[0]);
mvert_to_particle(keys + 2, pind->mvert[1], pind->hkey[1]);
pind->positions[0] = pind->positions[1] - 1;
mvert_to_particle(keys + 1, pind->positions[0], pind->hkey[0]);
mvert_to_particle(keys + 2, pind->positions[1], pind->hkey[1]);
}
else if (pind->keyed) {
memcpy(keys + 1, pind->kkey[0], sizeof(ParticleKey));
@ -1559,10 +1559,10 @@ static void do_particle_interpolation(ParticleSystem *psys,
}
else if (pind->mesh) {
if (pind->hkey[0] != pa->hair) {
mvert_to_particle(keys, pind->mvert[0] - 1, pind->hkey[0] - 1);
mvert_to_particle(keys, pind->positions[0] - 1, pind->hkey[0] - 1);
}
else {
mvert_to_particle(keys, pind->mvert[0], pind->hkey[0]);
mvert_to_particle(keys, pind->positions[0], pind->hkey[0]);
}
}
else {
@ -1584,10 +1584,10 @@ static void do_particle_interpolation(ParticleSystem *psys,
}
else if (pind->mesh) {
if (pind->hkey[1] != pa->hair + pa->totkey - 1) {
mvert_to_particle(keys + 3, pind->mvert[1] + 1, pind->hkey[1] + 1);
mvert_to_particle(keys + 3, pind->positions[1] + 1, pind->hkey[1] + 1);
}
else {
mvert_to_particle(keys + 3, pind->mvert[1], pind->hkey[1]);
mvert_to_particle(keys + 3, pind->positions[1], pind->hkey[1]);
}
}
else {
@ -2120,8 +2120,8 @@ void psys_particle_on_dm(Mesh *mesh_final,
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh_final);
if (from == PART_FROM_VERT) {
const MVert *verts = BKE_mesh_positions(mesh_final);
copy_v3_v3(vec, verts[mapindex].co);
const float(*positions)[3] = BKE_mesh_positions(mesh_final);
copy_v3_v3(vec, positions[mapindex]);
if (nor) {
copy_v3_v3(nor, vert_normals[mapindex]);
@ -2145,11 +2145,10 @@ void psys_particle_on_dm(Mesh *mesh_final,
else { /* PART_FROM_FACE / PART_FROM_VOLUME */
MFace *mface;
MTFace *mtface;
MVert *mvert;
MFace *mfaces = CustomData_get_layer(&mesh_final->fdata, CD_MFACE);
mface = &mfaces[mapindex];
mvert = BKE_mesh_positions_for_write(mesh_final);
float(*positions)[3] = BKE_mesh_positions_for_write(mesh_final);
mtface = CustomData_get_layer(&mesh_final->fdata, CD_MTFACE);
if (mtface) {
@ -2158,7 +2157,7 @@ void psys_particle_on_dm(Mesh *mesh_final,
if (from == PART_FROM_VOLUME) {
psys_interpolate_face(mesh_final,
mvert,
positions,
vert_normals,
mface,
mtface,
@ -2181,7 +2180,7 @@ void psys_particle_on_dm(Mesh *mesh_final,
}
else {
psys_interpolate_face(mesh_final,
mvert,
positions,
vert_normals,
mface,
mtface,
@ -3869,10 +3868,10 @@ static void psys_face_mat(Object *ob, Mesh *mesh, ParticleData *pa, float mat[4]
}
}
else {
const MVert *verts = BKE_mesh_positions(mesh);
copy_v3_v3(v[0], verts[mface->v1].co);
copy_v3_v3(v[1], verts[mface->v2].co);
copy_v3_v3(v[2], verts[mface->v3].co);
const float(*positions)[3] = BKE_mesh_positions(mesh);
copy_v3_v3(v[0], positions[mface->v1]);
copy_v3_v3(v[1], positions[mface->v2]);
copy_v3_v3(v[2], positions[mface->v3]);
}
triatomat(v[0], v[1], v[2], (osface) ? osface->uv : NULL, mat);

View File

@ -97,18 +97,15 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
{
ParticleData *pa = NULL;
float min[3], max[3], delta[3], d;
MVert *mv, *mvert = BKE_mesh_positions_for_write(mesh);
float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
int totvert = mesh->totvert, from = psys->part->from;
int i, j, k, p, res = psys->part->grid_res, size[3], axis;
/* find bounding box of dm */
if (totvert > 0) {
mv = mvert;
copy_v3_v3(min, mv->co);
copy_v3_v3(max, mv->co);
mv++;
for (i = 1; i < totvert; i++, mv++) {
minmax_v3v3_v3(min, max, mv->co);
INIT_MINMAX(min, max);
for (i = 1; i < totvert; i++) {
minmax_v3v3_v3(min, max, positions[i]);
}
}
else {
@ -162,8 +159,8 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
min[1] -= d / 2.0f;
min[2] -= d / 2.0f;
for (i = 0, mv = mvert; i < totvert; i++, mv++) {
sub_v3_v3v3(vec, mv->co, min);
for (i = 0; i < totvert; i++) {
sub_v3_v3v3(vec, positions[i], min);
vec[0] /= delta[0];
vec[1] /= delta[1];
vec[2] /= delta[2];
@ -220,9 +217,9 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
for (i = 0; i < totface; i++, mface++) {
ParticleData *pa1 = NULL, *pa2 = NULL;
copy_v3_v3(v1, mvert[mface->v1].co);
copy_v3_v3(v2, mvert[mface->v2].co);
copy_v3_v3(v3, mvert[mface->v3].co);
copy_v3_v3(v1, positions[mface->v1]);
copy_v3_v3(v2, positions[mface->v2]);
copy_v3_v3(v3, positions[mface->v3]);
bool intersects_tri = isect_ray_tri_watertight_v3(
co1, &isect_precalc, v1, v2, v3, &lambda, NULL);
@ -231,7 +228,7 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
}
if (mface->v4 && (!intersects_tri || from == PART_FROM_VOLUME)) {
copy_v3_v3(v4, mvert[mface->v4].co);
copy_v3_v3(v4, positions[mface->v4]);
if (isect_ray_tri_watertight_v3(co1, &isect_precalc, v1, v3, v4, &lambda, NULL)) {
pa2 = (pa + (int)(lambda * size[a]) * a0mul);
@ -569,14 +566,15 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
{
ParticleThreadContext *ctx = thread->ctx;
Mesh *mesh = ctx->mesh;
float *v1, *v2, *v3, *v4, nor[3], co[3];
const float *v1, *v2, *v3, *v4;
const float nor[3], co[3];
float cur_d, min_d, randu, randv;
int distr = ctx->distr;
int i, intersect, tot;
int rng_skip_tot = PSYS_RND_DIST_SKIP; /* count how many rng_* calls won't need skipping */
MFace *mface;
MVert *mvert = BKE_mesh_positions_for_write(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
pa->num = i = ctx->index[p];
MFace *mfaces = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
@ -613,8 +611,18 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
/* experimental */
tot = mesh->totface;
psys_interpolate_face(
mesh, mvert, BKE_mesh_vertex_normals_ensure(mesh), mface, 0, 0, pa->fuv, co, nor, 0, 0, 0);
psys_interpolate_face(mesh,
positions,
BKE_mesh_vertex_normals_ensure(mesh),
mface,
0,
0,
pa->fuv,
co,
nor,
0,
0,
0);
normalize_v3(nor);
negate_v3(nor);
@ -627,9 +635,9 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
continue;
}
v1 = mvert[mface->v1].co;
v2 = mvert[mface->v2].co;
v3 = mvert[mface->v3].co;
v1 = positions[mface->v1];
v2 = positions[mface->v2];
v3 = positions[mface->v3];
if (isect_ray_tri_v3(co, nor, v2, v3, v1, &cur_d, NULL)) {
if (cur_d < min_d) {
@ -639,7 +647,7 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
}
}
if (mface->v4) {
v4 = mvert[mface->v4].co;
v4 = positions[mface->v4];
if (isect_ray_tri_v3(co, nor, v4, v1, v3, &cur_d, NULL)) {
if (cur_d < min_d) {
@ -992,7 +1000,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
BKE_mesh_orco_ensure(ob, mesh);
if (from == PART_FROM_VERT) {
MVert *mv = BKE_mesh_positions_for_write(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
const float(*orcodata)[3] = CustomData_get_layer(&mesh->vdata, CD_ORCO);
int totvert = mesh->totvert;
@ -1004,7 +1012,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
BKE_mesh_orco_verts_transform(ob->data, &co, 1, 1);
}
else {
copy_v3_v3(co, mv[p].co);
copy_v3_v3(co, positions[p]);
}
BLI_kdtree_3d_insert(tree, p, co);
}
@ -1039,7 +1047,6 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
/* Calculate weights from face areas */
if ((part->flag & PART_EDISTR || children) && from != PART_FROM_VERT) {
MVert *v1, *v2, *v3, *v4;
float totarea = 0.0f, co1[3], co2[3], co3[3], co4[3];
const float(*orcodata)[3];
@ -1063,16 +1070,12 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
}
}
else {
MVert *verts = BKE_mesh_positions_for_write(mesh);
v1 = &verts[mf->v1];
v2 = &verts[mf->v2];
v3 = &verts[mf->v3];
copy_v3_v3(co1, v1->co);
copy_v3_v3(co2, v2->co);
copy_v3_v3(co3, v3->co);
const float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
copy_v3_v3(co1, positions[mf->v1]);
copy_v3_v3(co2, positions[mf->v2]);
copy_v3_v3(co3, positions[mf->v3]);
if (mf->v4) {
v4 = &verts[mf->v4];
copy_v3_v3(co4, v4->co);
copy_v3_v3(co4, positions[mf->v4]);
}
}

View File

@ -2781,18 +2781,18 @@ void BKE_psys_collision_neartest_cb(void *userdata,
ParticleCollision *col = (ParticleCollision *)userdata;
ParticleCollisionElement pce;
const MVertTri *vt = &col->md->tri[index];
MVert *x = col->md->x;
MVert *v = col->md->current_v;
float(*x)[3] = col->md->x;
float(*v)[3] = col->md->current_v;
float t = hit->dist / col->original_ray_length;
int collision = 0;
pce.x[0] = x[vt->tri[0]].co;
pce.x[1] = x[vt->tri[1]].co;
pce.x[2] = x[vt->tri[2]].co;
pce.x[0] = x[vt->tri[0]];
pce.x[1] = x[vt->tri[1]];
pce.x[2] = x[vt->tri[2]];
pce.v[0] = v[vt->tri[0]].co;
pce.v[1] = v[vt->tri[1]].co;
pce.v[2] = v[vt->tri[2]].co;
pce.v[0] = v[vt->tri[0]];
pce.v[1] = v[vt->tri[1]];
pce.v[2] = v[vt->tri[2]];
pce.tot = 3;
pce.inside = 0;
@ -3309,7 +3309,6 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
ParticleSystem *psys = sim->psys;
ParticleSettings *part = psys->part;
Mesh *mesh;
MVert *mvert;
MEdge *medge;
MDeformVert *dvert;
HairKey *key;
@ -3323,7 +3322,7 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
if (!mesh) {
*r_mesh = mesh = BKE_mesh_new_nomain(totpoint, totedge, 0, 0, 0);
}
mvert = BKE_mesh_positions_for_write(mesh);
float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
medge = BKE_mesh_edges_for_write(mesh);
dvert = BKE_mesh_deform_verts_for_write(mesh);
@ -3347,6 +3346,8 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
psys->clmd->sim_parms->vgroup_mass = 1;
int vert_index = 0;
/* XXX placeholder for more flexible future hair settings */
hair_radius = part->size;
@ -3385,16 +3386,16 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
hair->radius = hair_radius;
hair->bending_stiffness = bending_stiffness;
add_v3_v3v3(mvert->co, co, co);
sub_v3_v3(mvert->co, co_next);
mul_m4_v3(hairmat, mvert->co);
add_v3_v3v3(positions[vert_index], co, co);
sub_v3_v3(positions[vert_index], co_next);
mul_m4_v3(hairmat, positions[vert_index]);
medge->v1 = pa->hair_index - 1;
medge->v2 = pa->hair_index;
dvert = hair_set_pinning(dvert, 1.0f);
mvert++;
vert_index++;
medge++;
}
@ -3406,8 +3407,8 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
hair->radius = hair_radius;
hair->bending_stiffness = bending_stiffness;
copy_v3_v3(mvert->co, co);
mul_m4_v3(hairmat, mvert->co);
copy_v3_v3(positions[vert_index], co);
mul_m4_v3(hairmat, positions[vert_index]);
if (k) {
medge->v1 = pa->hair_index + k - 1;
@ -3422,7 +3423,7 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
dvert = hair_set_pinning(dvert, 1.0f);
}
mvert++;
vert_index++;
if (k) {
medge++;
}

View File

@ -1960,7 +1960,7 @@ void BKE_pbvh_node_get_loops(PBVH *pbvh,
}
}
const int *BKE_pbvh_node_get_vert_indices(PBVHNode *node);
const int *BKE_pbvh_node_get_vert_indices(PBVHNode *node)
{
return node->vert_indices;
}
@ -3062,7 +3062,6 @@ void BKE_pbvh_node_color_buffer_free(PBVH *pbvh)
void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int mode)
{
struct CCGElem **grids;
struct MVert *verts;
int *grid_indices;
int totgrid, gridsize, uniq_verts, totvert;
@ -3095,7 +3094,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
vi->totvert = uniq_verts;
}
vi->vert_indices = vert_indices;
vi->mverts = verts;
vi->mverts = pbvh->positions;
if (pbvh->header.type == PBVH_BMESH) {
BLI_gsetIterator_init(&vi->bm_unique_verts, node->bm_unique_verts);

View File

@ -15,7 +15,6 @@ extern "C" {
struct MLoop;
struct MLoopTri;
struct MPoly;
struct MVert;
/* Axis-aligned bounding box */
typedef struct {
@ -56,7 +55,7 @@ struct PBVHNode {
int *prim_indices;
unsigned int totprim; /* Number of primitives inside prim_indices. */
/* Array of indices into the mesh's MVert array. Contains the
/* Array of indices into the mesh's vertex array. Contains the
* indices of all vertices used by faces that are within this
* node's bounding box.
*

View File

@ -359,12 +359,12 @@ static rbCollisionShape *rigidbody_get_shape_convexhull_from_mesh(Object *ob,
{
rbCollisionShape *shape = NULL;
Mesh *mesh = NULL;
MVert *mvert = NULL;
float(*positions)[3] = NULL;
int totvert = 0;
if (ob->type == OB_MESH && ob->data) {
mesh = rigidbody_get_mesh(ob);
mvert = (mesh) ? BKE_mesh_positions_for_write(mesh) : NULL;
positions = (mesh) ? BKE_mesh_positions_for_write(mesh) : NULL;
totvert = (mesh) ? mesh->totvert : 0;
}
else {
@ -372,7 +372,8 @@ static rbCollisionShape *rigidbody_get_shape_convexhull_from_mesh(Object *ob,
}
if (totvert) {
shape = RB_shape_new_convex_hull((float *)mvert, sizeof(MVert), totvert, margin, can_embed);
shape = RB_shape_new_convex_hull(
(float *)positions, sizeof(float[3]), totvert, margin, can_embed);
}
else {
CLOG_ERROR(&LOG, "no vertices to define Convex Hull collision shape with");
@ -401,7 +402,7 @@ static rbCollisionShape *rigidbody_get_shape_trimesh_from_mesh(Object *ob)
return NULL;
}
const MVert *mvert = BKE_mesh_positions(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
totvert = mesh->totvert;
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
tottri = mesh->runtime.looptris.len;
@ -419,12 +420,12 @@ 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 *)mvert, totvert, sizeof(MVert));
RB_trimesh_add_vertices(mdata, (float *)positions, 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 (mvert && looptri) {
if (positions && looptri) {
for (i = 0; i < tottri; i++) {
/* add first triangle - verts 1,2,3 */
const MLoopTri *lt = &looptri[i];
@ -676,14 +677,14 @@ void BKE_rigidbody_calc_volume(Object *ob, float *r_vol)
return;
}
const MVert *mvert = BKE_mesh_positions(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
totvert = mesh->totvert;
lt = BKE_mesh_runtime_looptri_ensure(mesh);
tottri = mesh->runtime.looptris.len;
const MLoop *mloop = BKE_mesh_loops(mesh);
if (totvert > 0 && tottri > 0) {
BKE_mesh_calc_volume(mvert, totvert, lt, tottri, mloop, &volume, NULL);
BKE_mesh_calc_volume(positions, totvert, lt, tottri, mloop, &volume, NULL);
const float volume_scale = mat4_to_volume_scale(ob->obmat);
volume *= fabsf(volume_scale);
}
@ -750,14 +751,14 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3])
return;
}
const MVert *mvert = BKE_mesh_positions(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
totvert = mesh->totvert;
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
tottri = mesh->runtime.looptris.len;
const MLoop *mloop = BKE_mesh_loops(mesh);
if (totvert > 0 && tottri > 0) {
BKE_mesh_calc_volume(mvert, totvert, looptri, tottri, mloop, NULL, r_center);
BKE_mesh_calc_volume(positions, totvert, looptri, tottri, mloop, NULL, r_center);
}
}
break;
@ -1671,14 +1672,14 @@ 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) {
MVert *mvert = BKE_mesh_positions_for_write(mesh);
float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
int totvert = mesh->totvert;
const BoundBox *bb = BKE_object_boundbox_get(ob);
RB_shape_trimesh_update(rbo->shared->physics_shape,
(float *)mvert,
(float *)positions,
totvert,
sizeof(MVert),
sizeof(float[3]),
bb->vec[0],
bb->vec[6]);
}

View File

@ -59,7 +59,7 @@ typedef struct ShrinkwrapCalcData {
struct Object *ob; /* object we are applying shrinkwrap to */
struct MVert *vert; /* Array of verts being projected. */
float (*positions)[3]; /* Array of verts being projected. */
const float (*vert_normals)[3];
float (*vertexCos)[3]; /* vertexs being shrinkwraped */
int numVerts;
@ -192,7 +192,7 @@ static void merge_vert_dir(ShrinkwrapBoundaryVertData *vdata,
static ShrinkwrapBoundaryData *shrinkwrap_build_boundary_data(struct Mesh *mesh)
{
const MVert *mvert = BKE_mesh_positions(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
const MEdge *medge = BKE_mesh_edges(mesh);
const MLoop *mloop = BKE_mesh_loops(mesh);
@ -288,7 +288,7 @@ static ShrinkwrapBoundaryData *shrinkwrap_build_boundary_data(struct Mesh *mesh)
const MEdge *edge = &medge[i];
float dir[3];
sub_v3_v3v3(dir, mvert[edge->v2].co, mvert[edge->v1].co);
sub_v3_v3v3(dir, positions[edge->v2], positions[edge->v1]);
normalize_v3(dir);
merge_vert_dir(boundary_verts, vert_status, vert_boundary_id[edge->v1], dir, 1);
@ -357,8 +357,8 @@ static void shrinkwrap_calc_nearest_vertex_cb_ex(void *__restrict userdata,
}
/* Convert the vertex to tree coordinates */
if (calc->vert) {
copy_v3_v3(tmp_co, calc->vert[i].co);
if (calc->positions) {
copy_v3_v3(tmp_co, calc->positions[i]);
}
else {
copy_v3_v3(tmp_co, co);
@ -520,12 +520,12 @@ static void shrinkwrap_calc_normal_projection_cb_ex(void *__restrict userdata,
return;
}
if (calc->vert != NULL && calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) {
/* calc->vert contains verts from evaluated mesh. */
if (calc->positions != NULL && calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) {
/* calc->positions contains verts from evaluated mesh. */
/* These coordinates are deformed by vertexCos only for normal projection
* (to get correct normals) for other cases calc->verts contains undeformed coordinates and
* vertexCos should be used */
copy_v3_v3(tmp_co, calc->vert[i].co);
copy_v3_v3(tmp_co, calc->positions[i]);
copy_v3_v3(tmp_no, calc->vert_normals[i]);
}
else {
@ -641,7 +641,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc)
/* Prepare data to retrieve the direction in which we should project each vertex */
if (calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) {
if (calc->vert == NULL) {
if (calc->positions == NULL) {
return;
}
}
@ -939,7 +939,7 @@ static void target_project_edge(const ShrinkwrapTreeData *tree,
{
const BVHTreeFromMesh *data = &tree->treeData;
const MEdge *edge = &data->edge[eidx];
const float *vedge_co[2] = {data->vert[edge->v1].co, data->vert[edge->v2].co};
const float *vedge_co[2] = {data->positions[edge->v1], data->positions[edge->v2]};
#ifdef TRACE_TARGET_PROJECT
printf("EDGE %d (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)\n",
@ -1017,9 +1017,8 @@ static void mesh_looptri_target_project(void *userdata,
const MLoopTri *lt = &data->looptri[index];
const MLoop *loop[3] = {
&data->loop[lt->tri[0]], &data->loop[lt->tri[1]], &data->loop[lt->tri[2]]};
const MVert *vtri[3] = {
&data->vert[loop[0]->v], &data->vert[loop[1]->v], &data->vert[loop[2]->v]};
const float *vtri_co[3] = {vtri[0]->co, vtri[1]->co, vtri[2]->co};
const float *vtri_co[3] = {
data->positions[loop[0]->v], data->positions[loop[1]->v], data->positions[loop[2]->v]};
float raw_hit_co[3], hit_co[3], hit_no[3], dist_sq, vtri_no[3][3];
/* First find the closest point and bail out if it's worse than the current solution. */
@ -1121,8 +1120,8 @@ static void shrinkwrap_calc_nearest_surface_point_cb_ex(void *__restrict userdat
}
/* Convert the vertex to tree coordinates */
if (calc->vert) {
copy_v3_v3(tmp_co, calc->vert[i].co);
if (calc->positions) {
copy_v3_v3(tmp_co, calc->positions[i].co);
}
else {
copy_v3_v3(tmp_co, co);
@ -1207,9 +1206,9 @@ void BKE_shrinkwrap_compute_smooth_normal(const struct ShrinkwrapTreeData *tree,
}
interp_weights_tri_v3(w,
treeData->vert[vert_indices[0]].co,
treeData->vert[vert_indices[1]].co,
treeData->vert[vert_indices[2]].co,
treeData->positions[vert_indices[0]],
treeData->positions[vert_indices[1]],
treeData->positions[vert_indices[2]],
tmp_co);
/* Interpolate using weights. */
@ -1412,7 +1411,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd,
if (mesh != NULL && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) {
/* Setup arrays to get vertexs positions, normals and deform weights */
calc.vert = BKE_mesh_positions_for_write(mesh);
calc.positions = BKE_mesh_positions_for_write(mesh);
calc.vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
/* Using vertexs positions/normals as if a subsurface was applied */
@ -1428,11 +1427,11 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd,
dm, &ssmd, scene, NULL, (ob->mode & OB_MODE_EDIT) ? SUBSURF_IN_EDIT_MODE : 0);
if (ss_mesh) {
calc.vert = ss_mesh->getVertDataArray(ss_mesh, CD_MVERT);
if (calc.vert) {
calc.positions = ss_mesh->getVertArray(ss_mesh);
if (calc.positions) {
/* TRICKY: this code assumes subsurface will have the transformed original vertices
* in their original order at the end of the vert array. */
calc.vert = calc.vert + ss_mesh->getNumVerts(ss_mesh) - dm->getNumVerts(dm);
calc.positions = calc.positions + ss_mesh->getNumVerts(ss_mesh) - dm->getNumVerts(dm);
}
}
@ -1575,7 +1574,7 @@ void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object
calc.vgroup = -1;
calc.target = target_me;
calc.keepDist = ssmd.keepDist;
calc.vert = BKE_mesh_positions_for_write(src_me);
calc.positions = BKE_mesh_positions_for_write(src_me);
BLI_SPACE_TRANSFORM_SETUP(&calc.local2target, ob_target, ob_target);
ShrinkwrapTreeData tree;

View File

@ -255,8 +255,8 @@ typedef struct ccdf_minmax {
typedef struct ccd_Mesh {
int mvert_num, tri_num;
const MVert *mvert;
const MVert *mprevvert;
const float (*positions)[3];
const float (*positions_prev)[3];
const MVertTri *tri;
int safety;
ccdf_minmax *mima;
@ -290,20 +290,20 @@ static ccd_Mesh *ccd_mesh_make(Object *ob)
pccd_M->safety = CCD_SAFETY;
pccd_M->bbmin[0] = pccd_M->bbmin[1] = pccd_M->bbmin[2] = 1e30f;
pccd_M->bbmax[0] = pccd_M->bbmax[1] = pccd_M->bbmax[2] = -1e30f;
pccd_M->mprevvert = NULL;
pccd_M->positions_prev = NULL;
/* Blow it up with force-field ranges. */
hull = max_ff(ob->pd->pdef_sbift, ob->pd->pdef_sboft);
/* Allocate and copy verts. */
pccd_M->mvert = MEM_dupallocN(cmd->xnew);
pccd_M->positions = MEM_dupallocN(cmd->xnew);
/* note that xnew coords are already in global space, */
/* determine the ortho BB */
for (i = 0; i < pccd_M->mvert_num; i++) {
const float *v;
/* evaluate limits */
v = pccd_M->mvert[i].co;
v = pccd_M->positions[i];
pccd_M->bbmin[0] = min_ff(pccd_M->bbmin[0], v[0] - hull);
pccd_M->bbmin[1] = min_ff(pccd_M->bbmin[1], v[1] - hull);
pccd_M->bbmin[2] = min_ff(pccd_M->bbmin[2], v[2] - hull);
@ -325,7 +325,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob)
mima->minx = mima->miny = mima->minz = 1e30f;
mima->maxx = mima->maxy = mima->maxz = -1e30f;
v = pccd_M->mvert[vt->tri[0]].co;
v = pccd_M->positions[vt->tri[0]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@ -333,7 +333,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
v = pccd_M->mvert[vt->tri[1]].co;
v = pccd_M->positions[vt->tri[1]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@ -341,7 +341,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
v = pccd_M->mvert[vt->tri[2]].co;
v = pccd_M->positions[vt->tri[2]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@ -381,19 +381,19 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
hull = max_ff(ob->pd->pdef_sbift, ob->pd->pdef_sboft);
/* rotate current to previous */
if (pccd_M->mprevvert) {
MEM_freeN((void *)pccd_M->mprevvert);
if (pccd_M->positions_prev) {
MEM_freeN((void *)pccd_M->positions_prev);
}
pccd_M->mprevvert = pccd_M->mvert;
pccd_M->positions_prev = pccd_M->positions;
/* Allocate and copy verts. */
pccd_M->mvert = MEM_dupallocN(cmd->xnew);
pccd_M->positions = MEM_dupallocN(cmd->xnew);
/* note that xnew coords are already in global space, */
/* determine the ortho BB */
for (i = 0; i < pccd_M->mvert_num; i++) {
const float *v;
/* evaluate limits */
v = pccd_M->mvert[i].co;
v = pccd_M->positions[i];
pccd_M->bbmin[0] = min_ff(pccd_M->bbmin[0], v[0] - hull);
pccd_M->bbmin[1] = min_ff(pccd_M->bbmin[1], v[1] - hull);
pccd_M->bbmin[2] = min_ff(pccd_M->bbmin[2], v[2] - hull);
@ -403,7 +403,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
pccd_M->bbmax[2] = max_ff(pccd_M->bbmax[2], v[2] + hull);
/* evaluate limits */
v = pccd_M->mprevvert[i].co;
v = pccd_M->positions_prev[i];
pccd_M->bbmin[0] = min_ff(pccd_M->bbmin[0], v[0] - hull);
pccd_M->bbmin[1] = min_ff(pccd_M->bbmin[1], v[1] - hull);
pccd_M->bbmin[2] = min_ff(pccd_M->bbmin[2], v[2] - hull);
@ -420,8 +420,8 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->minx = mima->miny = mima->minz = 1e30f;
mima->maxx = mima->maxy = mima->maxz = -1e30f;
/* mvert */
v = pccd_M->mvert[vt->tri[0]].co;
/* positions */
v = pccd_M->positions[vt->tri[0]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@ -429,7 +429,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
v = pccd_M->mvert[vt->tri[1]].co;
v = pccd_M->positions[vt->tri[1]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@ -437,7 +437,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
v = pccd_M->mvert[vt->tri[2]].co;
v = pccd_M->positions[vt->tri[2]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@ -445,8 +445,8 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
/* mprevvert */
v = pccd_M->mprevvert[vt->tri[0]].co;
/* positions_prev */
v = pccd_M->positions_prev[vt->tri[0]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@ -454,7 +454,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
v = pccd_M->mprevvert[vt->tri[1]].co;
v = pccd_M->positions_prev[vt->tri[1]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@ -462,7 +462,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
v = pccd_M->mprevvert[vt->tri[2]].co;
v = pccd_M->positions_prev[vt->tri[2]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@ -476,10 +476,10 @@ static void ccd_mesh_free(ccd_Mesh *ccdm)
{
/* Make sure we're not nuking objects we don't know. */
if (ccdm && (ccdm->safety == CCD_SAFETY)) {
MEM_freeN((void *)ccdm->mvert);
MEM_freeN((void *)ccdm->positions);
MEM_freeN((void *)ccdm->tri);
if (ccdm->mprevvert) {
MEM_freeN((void *)ccdm->mprevvert);
if (ccdm->positions_prev) {
MEM_freeN((void *)ccdm->positions_prev);
}
MEM_freeN(ccdm->mima);
MEM_freeN(ccdm);
@ -1068,12 +1068,12 @@ static int sb_detect_face_pointCached(const float face_v1[3],
{
/* only with deflecting set */
if (ob->pd && ob->pd->deflect) {
const MVert *mvert = NULL;
const MVert *mprevvert = NULL;
const float(*positions)[3] = NULL;
const float(*positions_prev)[3] = NULL;
if (ccdm) {
mvert = ccdm->mvert;
positions = ccdm->positions;
a = ccdm->mvert_num;
mprevvert = ccdm->mprevvert;
positions_prev = ccdm->positions_prev;
outerfacethickness = ob->pd->pdef_sboft;
if ((aabbmax[0] < ccdm->bbmin[0]) || (aabbmax[1] < ccdm->bbmin[1]) ||
(aabbmax[2] < ccdm->bbmin[2]) || (aabbmin[0] > ccdm->bbmax[0]) ||
@ -1091,12 +1091,12 @@ static int sb_detect_face_pointCached(const float face_v1[3],
}
/* Use mesh. */
if (mvert) {
if (positions) {
while (a) {
copy_v3_v3(nv1, mvert[a - 1].co);
if (mprevvert) {
copy_v3_v3(nv1, positions[a - 1]);
if (positions_prev) {
mul_v3_fl(nv1, time);
madd_v3_v3fl(nv1, mprevvert[a - 1].co, 1.0f - time);
madd_v3_v3fl(nv1, positions_prev[a - 1], 1.0f - time);
}
/* Origin to face_v2. */
sub_v3_v3(nv1, face_v2);
@ -1120,7 +1120,7 @@ static int sb_detect_face_pointCached(const float face_v1[3],
}
a--;
} /* while (a) */
} /* if (mvert) */
} /* if (positions) */
} /* if (ob->pd && ob->pd->deflect) */
BLI_ghashIterator_step(ihash);
}
@ -1160,15 +1160,15 @@ static int sb_detect_face_collisionCached(const float face_v1[3],
{
/* only with deflecting set */
if (ob->pd && ob->pd->deflect) {
const MVert *mvert = NULL;
const MVert *mprevvert = NULL;
const float(*positions)[3] = NULL;
const float(*positions_prev)[3] = NULL;
const MVertTri *vt = NULL;
const ccdf_minmax *mima = NULL;
if (ccdm) {
mvert = ccdm->mvert;
positions = ccdm->positions;
vt = ccdm->tri;
mprevvert = ccdm->mprevvert;
positions_prev = ccdm->positions_prev;
mima = ccdm->mima;
a = ccdm->tri_num;
@ -1197,21 +1197,21 @@ static int sb_detect_face_collisionCached(const float face_v1[3],
continue;
}
if (mvert) {
if (positions) {
copy_v3_v3(nv1, mvert[vt->tri[0]].co);
copy_v3_v3(nv2, mvert[vt->tri[1]].co);
copy_v3_v3(nv3, mvert[vt->tri[2]].co);
copy_v3_v3(nv1, positions[vt->tri[0]]);
copy_v3_v3(nv2, positions[vt->tri[1]]);
copy_v3_v3(nv3, positions[vt->tri[2]]);
if (mprevvert) {
if (positions_prev) {
mul_v3_fl(nv1, time);
madd_v3_v3fl(nv1, mprevvert[vt->tri[0]].co, 1.0f - time);
madd_v3_v3fl(nv1, positions_prev[vt->tri[0]], 1.0f - time);
mul_v3_fl(nv2, time);
madd_v3_v3fl(nv2, mprevvert[vt->tri[1]].co, 1.0f - time);
madd_v3_v3fl(nv2, positions_prev[vt->tri[1]], 1.0f - time);
mul_v3_fl(nv3, time);
madd_v3_v3fl(nv3, mprevvert[vt->tri[2]].co, 1.0f - time);
madd_v3_v3fl(nv3, positions_prev[vt->tri[2]], 1.0f - time);
}
}
@ -1336,14 +1336,14 @@ static int sb_detect_edge_collisionCached(const float edge_v1[3],
{
/* only with deflecting set */
if (ob->pd && ob->pd->deflect) {
const MVert *mvert = NULL;
const MVert *mprevvert = NULL;
const float(*positions)[3] = NULL;
const float(*positions_prev)[3] = NULL;
const MVertTri *vt = NULL;
const ccdf_minmax *mima = NULL;
if (ccdm) {
mvert = ccdm->mvert;
mprevvert = ccdm->mprevvert;
positions = ccdm->positions;
positions_prev = ccdm->positions_prev;
vt = ccdm->tri;
mima = ccdm->mima;
a = ccdm->tri_num;
@ -1373,21 +1373,21 @@ static int sb_detect_edge_collisionCached(const float edge_v1[3],
continue;
}
if (mvert) {
if (positions) {
copy_v3_v3(nv1, mvert[vt->tri[0]].co);
copy_v3_v3(nv2, mvert[vt->tri[1]].co);
copy_v3_v3(nv3, mvert[vt->tri[2]].co);
copy_v3_v3(nv1, positions[vt->tri[0]]);
copy_v3_v3(nv2, positions[vt->tri[1]]);
copy_v3_v3(nv3, positions[vt->tri[2]]);
if (mprevvert) {
if (positions_prev) {
mul_v3_fl(nv1, time);
madd_v3_v3fl(nv1, mprevvert[vt->tri[0]].co, 1.0f - time);
madd_v3_v3fl(nv1, positions_prev[vt->tri[0]], 1.0f - time);
mul_v3_fl(nv2, time);
madd_v3_v3fl(nv2, mprevvert[vt->tri[1]].co, 1.0f - time);
madd_v3_v3fl(nv2, positions_prev[vt->tri[1]], 1.0f - time);
mul_v3_fl(nv3, time);
madd_v3_v3fl(nv3, mprevvert[vt->tri[2]].co, 1.0f - time);
madd_v3_v3fl(nv3, positions_prev[vt->tri[2]], 1.0f - time);
}
}
@ -1635,14 +1635,14 @@ static int sb_detect_vertex_collisionCached(float opco[3],
{
/* only with deflecting set */
if (ob->pd && ob->pd->deflect) {
const MVert *mvert = NULL;
const MVert *mprevvert = NULL;
const float(*positions)[3] = NULL;
const float(*positions_prev)[3] = NULL;
const MVertTri *vt = NULL;
const ccdf_minmax *mima = NULL;
if (ccdm) {
mvert = ccdm->mvert;
mprevvert = ccdm->mprevvert;
positions = ccdm->positions;
positions_prev = ccdm->positions_prev;
vt = ccdm->tri;
mima = ccdm->mima;
a = ccdm->tri_num;
@ -1686,30 +1686,30 @@ static int sb_detect_vertex_collisionCached(float opco[3],
continue;
}
if (mvert) {
if (positions) {
copy_v3_v3(nv1, mvert[vt->tri[0]].co);
copy_v3_v3(nv2, mvert[vt->tri[1]].co);
copy_v3_v3(nv3, mvert[vt->tri[2]].co);
copy_v3_v3(nv1, positions[vt->tri[0]]);
copy_v3_v3(nv2, positions[vt->tri[1]]);
copy_v3_v3(nv3, positions[vt->tri[2]]);
if (mprevvert) {
if (positions_prev) {
/* Grab the average speed of the collider vertices before we spoil nvX
* humm could be done once a SB steps but then we' need to store that too
* since the AABB reduced probability to get here drastically
* it might be a nice tradeoff CPU <--> memory.
*/
sub_v3_v3v3(vv1, nv1, mprevvert[vt->tri[0]].co);
sub_v3_v3v3(vv2, nv2, mprevvert[vt->tri[1]].co);
sub_v3_v3v3(vv3, nv3, mprevvert[vt->tri[2]].co);
sub_v3_v3v3(vv1, nv1, positions_prev[vt->tri[0]]);
sub_v3_v3v3(vv2, nv2, positions_prev[vt->tri[1]]);
sub_v3_v3v3(vv3, nv3, positions_prev[vt->tri[2]]);
mul_v3_fl(nv1, time);
madd_v3_v3fl(nv1, mprevvert[vt->tri[0]].co, 1.0f - time);
madd_v3_v3fl(nv1, positions_prev[vt->tri[0]], 1.0f - time);
mul_v3_fl(nv2, time);
madd_v3_v3fl(nv2, mprevvert[vt->tri[1]].co, 1.0f - time);
madd_v3_v3fl(nv2, positions_prev[vt->tri[1]], 1.0f - time);
mul_v3_fl(nv3, time);
madd_v3_v3fl(nv3, mprevvert[vt->tri[2]].co, 1.0f - time);
madd_v3_v3fl(nv3, positions_prev[vt->tri[2]], 1.0f - time);
}
}
@ -1743,7 +1743,7 @@ static int sb_detect_vertex_collisionCached(float opco[3],
deflected = 2;
}
}
if ((mprevvert) && (*damp > 0.0f)) {
if ((positions_prev) && (*damp > 0.0f)) {
choose_winner(ve, opco, nv1, nv2, nv3, vv1, vv2, vv3);
add_v3_v3(avel, ve);
cavel++;
@ -2632,7 +2632,7 @@ static void springs_from_mesh(Object *ob)
BodyPoint *bp;
int a;
float scale = 1.0f;
const MVert *verts = BKE_mesh_positions(me);
const float(*positions)[3] = BKE_mesh_positions(me);
sb = ob->soft;
if (me && sb) {
@ -2643,7 +2643,7 @@ static void springs_from_mesh(Object *ob)
if (me->totvert) {
bp = ob->soft->bpoint;
for (a = 0; a < me->totvert; a++, bp++) {
copy_v3_v3(bp->origS, verts[a].co);
copy_v3_v3(bp->origS, positions[a]);
mul_m4_v3(ob->obmat, bp->origS);
}
}
@ -2755,7 +2755,7 @@ static void mesh_faces_to_scratch(Object *ob)
MLoopTri *looptri, *lt;
BodyFace *bodyface;
int a;
const MVert *verts = BKE_mesh_positions(me);
const float(*positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
@ -2763,7 +2763,7 @@ static void mesh_faces_to_scratch(Object *ob)
sb->scratch->totface = poly_to_tri_count(me->totpoly, me->totloop);
looptri = lt = MEM_mallocN(sizeof(*looptri) * sb->scratch->totface, __func__);
BKE_mesh_recalc_looptri(loops, polys, verts, me->totloop, me->totpoly, looptri);
BKE_mesh_recalc_looptri(loops, polys, positions, me->totloop, me->totpoly, looptri);
bodyface = sb->scratch->bodyface = MEM_mallocN(sizeof(BodyFace) * sb->scratch->totface,
"SB_body_Faces");

View File

@ -34,7 +34,7 @@
typedef struct ConverterStorage {
SubdivSettings settings;
const Mesh *mesh;
const MVert *verts;
const float (*positions)[3];
const MEdge *edges;
const MPoly *polys;
const MLoop *loops;
@ -394,7 +394,7 @@ static void init_user_data(OpenSubdiv_Converter *converter,
ConverterStorage *user_data = MEM_mallocN(sizeof(ConverterStorage), __func__);
user_data->settings = *settings;
user_data->mesh = mesh;
user_data->verts = BKE_mesh_positions(mesh);
user_data->positions = BKE_mesh_positions(mesh);
user_data->edges = BKE_mesh_edges(mesh);
user_data->polys = BKE_mesh_polys(mesh);
user_data->loops = BKE_mesh_loops(mesh);

View File

@ -81,7 +81,8 @@ static void set_coarse_positions(Subdiv *subdiv,
const Mesh *mesh,
const float (*coarse_vertex_cos)[3])
{
const MVert *mvert = BKE_mesh_positions(mesh);
const float (*positions)[3]
= BKE_mesh_positions(mesh);
const MPoly *mpoly = BKE_mesh_polys(mesh);
const MLoop *mloop = BKE_mesh_loops(mesh);
/* Mark vertices which needs new coordinates. */
@ -109,8 +110,7 @@ static void set_coarse_positions(Subdiv *subdiv,
vertex_co = coarse_vertex_cos[vertex_index];
}
else {
const MVert *vertex = &mvert[vertex_index];
vertex_co = vertex->co;
vertex_co = positions[vertex_index];
}
copy_v3_v3(&buffer[manifold_vertex_index][0], vertex_co);
manifold_vertex_index++;

View File

@ -562,9 +562,8 @@ static void ss_sync_ccg_from_derivedmesh(CCGSubSurf *ss,
CCGVertHDL *fVerts = NULL;
BLI_array_declare(fVerts);
#endif
MVert *mvert = dm->getVertArray(dm);
float(*positions)[3] = dm->getVertArray(dm);
MEdge *medge = dm->getEdgeArray(dm);
MVert *mv;
MEdge *me;
MLoop *mloop = dm->getLoopArray(dm), *ml;
MPoly *mpoly = dm->getPolyArray(dm), *mp;
@ -575,16 +574,15 @@ static void ss_sync_ccg_from_derivedmesh(CCGSubSurf *ss,
ccgSubSurf_initFullSync(ss);
mv = mvert;
index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX);
for (i = 0; i < totvert; i++, mv++) {
for (i = 0; i < totvert; i++) {
CCGVert *v;
if (vertexCos) {
ccgSubSurf_syncVert(ss, POINTER_FROM_INT(i), vertexCos[i], 0, &v);
}
else {
ccgSubSurf_syncVert(ss, POINTER_FROM_INT(i), mv->co, 0, &v);
ccgSubSurf_syncVert(ss, POINTER_FROM_INT(i), positions[i], 0, &v);
}
((int *)ccgSubSurf_getVertUserData(ss, v))[1] = (index) ? *index++ : i;
@ -876,12 +874,12 @@ static void ccgDM_getFinalVertNo(DerivedMesh *dm, int vertNum, float r_no[3])
}
/* utility function */
BLI_INLINE void ccgDM_to_MVert(MVert *mv, const CCGKey *key, CCGElem *elem)
BLI_INLINE void ccgDM_to_MVert(float mv[3], const CCGKey *key, CCGElem *elem)
{
copy_v3_v3(mv->co, CCG_elem_co(key, elem));
copy_v3_v3(mv, CCG_elem_co(key, elem));
}
static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
static void ccgDM_copyFinalVertArray(DerivedMesh *dm, float (*r_positions)[3])
{
CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
CCGSubSurf *ss = ccgdm->ss;
@ -901,12 +899,12 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
vd = ccgSubSurf_getFaceCenterData(f);
ccgDM_to_MVert(&mvert[i++], &key, vd);
ccgDM_to_MVert(&r_positions[i++], &key, vd);
for (S = 0; S < numVerts; S++) {
for (x = 1; x < gridSize - 1; x++) {
vd = ccgSubSurf_getFaceGridEdgeData(ss, f, S, x);
ccgDM_to_MVert(&mvert[i++], &key, vd);
ccgDM_to_MVert(&r_positions[i++], &key, vd);
}
}
@ -914,7 +912,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
for (y = 1; y < gridSize - 1; y++) {
for (x = 1; x < gridSize - 1; x++) {
vd = ccgSubSurf_getFaceGridData(ss, f, S, x, y);
ccgDM_to_MVert(&mvert[i++], &key, vd);
ccgDM_to_MVert(&r_positions[i++], &key, vd);
}
}
}
@ -930,7 +928,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
* unit length. This is most likely caused by edges with no faces which are now zeroed out,
* see comment in: `ccgSubSurf__calcVertNormals()`. */
vd = ccgSubSurf_getEdgeData(ss, e, x);
ccgDM_to_MVert(&mvert[i++], &key, vd);
ccgDM_to_MVert(&r_positions[i++], &key, vd);
}
}
@ -939,7 +937,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
CCGVert *v = ccgdm->vertMap[index].vert;
vd = ccgSubSurf_getVertData(ss, v);
ccgDM_to_MVert(&mvert[i++], &key, vd);
ccgDM_to_MVert(&r_positions[i++], &key, vd);
}
}

View File

@ -369,10 +369,9 @@ static void extract_range_iter_lvert_mesh(void *__restrict userdata,
const ExtractorIterData *data = static_cast<ExtractorIterData *>(userdata);
const MeshRenderData *mr = data->mr;
const int lvert_index = data->loose_elems[iter];
const MVert *mv = &((const MVert *)data->elems)[lvert_index];
for (const ExtractorRunData &run_data : data->extractors) {
run_data.extractor->iter_lvert_mesh(
mr, mv, iter, POINTER_OFFSET(extract_data, run_data.data_offset));
mr, iter, POINTER_OFFSET(extract_data, run_data.data_offset));
}
}
@ -406,7 +405,7 @@ BLI_INLINE void extract_task_range_run_iter(const MeshRenderData *mr,
break;
case MR_ITER_LVERT:
range_data.loose_elems = mr->lverts;
range_data.elems = is_mesh ? mr->mvert : (void *)mr->bm->vtable;
range_data.elems = is_mesh ? mr->positions : (void *)mr->bm->vtable;
func = is_mesh ? extract_range_iter_lvert_mesh : extract_range_iter_lvert_bm;
stop = mr->vert_loose_len;
break;

View File

@ -9,6 +9,8 @@
#pragma once
#include "BLI_math_vec_types.hh"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
@ -70,7 +72,7 @@ struct MeshRenderData {
int freestyle_face_ofs;
/** Mesh */
Mesh *me;
const float (*positions)[3];
const blender::float3 *positions;
const MEdge *medge;
const MLoop *mloop;
const MPoly *mpoly;
@ -265,10 +267,7 @@ using ExtractLVertBMeshFn = void(const MeshRenderData *mr,
const BMVert *eve,
int lvert_index,
void *data);
using ExtractLVertMeshFn = void(const MeshRenderData *mr,
const MVert *mv,
int lvert_index,
void *data);
using ExtractLVertMeshFn = void(const MeshRenderData *mr, int lvert_index, void *data);
using ExtractLooseGeomSubdivFn = void(const DRWSubdivCache *subdiv_cache,
const MeshRenderData *mr,
void *buffer,

View File

@ -113,7 +113,6 @@ static void extract_points_iter_lvert_bm(const MeshRenderData *mr,
}
static void extract_points_iter_lvert_mesh(const MeshRenderData *mr,
const MVert *UNUSED(mv),
const int lvert_index,
void *_userdata)
{

View File

@ -131,10 +131,10 @@ static void extract_edge_fac_iter_poly_mesh(const MeshRenderData *mr,
const int ml_index_last = mp->totloop + mp->loopstart - 1;
const int ml_index_other = (ml_index == ml_index_last) ? mp->loopstart : (ml_index + 1);
const MLoop *ml_next = &mr->mloop[ml_index_other];
const MVert *v1 = &mr->mvert[ml->v];
const MVert *v2 = &mr->mvert[ml_next->v];
float ratio = loop_edge_factor_get(
mr->poly_normals[mp_index], v1->co, mr->vert_normals[ml->v], v2->co);
float ratio = loop_edge_factor_get(mr->poly_normals[mp_index],
mr->positions[ml->v],
mr->vert_normals[ml->v],
mr->positions[ml_next->v]);
data->vbo_data[ml_index] = ratio * 253 + 1;
}
else {

View File

@ -223,7 +223,6 @@ static void extract_edit_data_iter_lvert_bm(const MeshRenderData *mr,
}
static void extract_edit_data_iter_lvert_mesh(const MeshRenderData *mr,
const MVert *UNUSED(mv),
const int lvert_index,
void *_data)
{

View File

@ -167,15 +167,16 @@ static void extract_edituv_stretch_angle_iter_poly_mesh(const MeshRenderData *mr
float(*auv)[2] = data->auv, *last_auv = data->last_auv;
float(*av)[3] = data->av, *last_av = data->last_av;
int l_next = ml_index + 1;
const MVert *v, *v_next;
if (ml_index == mp->loopstart) {
/* First loop in face. */
const int ml_index_last = ml_index_end - 1;
const int l_next_tmp = mp->loopstart;
v = &mr->mvert[mr->mloop[ml_index_last].v];
v_next = &mr->mvert[mr->mloop[l_next_tmp].v];
compute_normalize_edge_vectors(
auv, av, data->luv[ml_index_last].uv, data->luv[l_next_tmp].uv, v->co, v_next->co);
compute_normalize_edge_vectors(auv,
av,
data->luv[ml_index_last].uv,
data->luv[l_next_tmp].uv,
mr->positions[mr->mloop[ml_index_last].v],
mr->positions[mr->mloop[l_next_tmp].v]);
/* Save last edge. */
copy_v2_v2(last_auv, auv[1]);
copy_v3_v3(last_av, av[1]);
@ -190,10 +191,12 @@ static void extract_edituv_stretch_angle_iter_poly_mesh(const MeshRenderData *mr
copy_v3_v3(av[1], last_av);
}
else {
v = &mr->mvert[mr->mloop[ml_index].v];
v_next = &mr->mvert[mr->mloop[l_next].v];
compute_normalize_edge_vectors(
auv, av, data->luv[ml_index].uv, data->luv[l_next].uv, v->co, v_next->co);
compute_normalize_edge_vectors(auv,
av,
data->luv[ml_index].uv,
data->luv[l_next].uv,
mr->positions[mr->mloop[ml_index].v],
mr->positions[mr->mloop[l_next].v]);
}
edituv_get_edituv_stretch_angle(auv, av, &data->vbo_data[ml_index]);
}

View File

@ -75,7 +75,6 @@ static void extract_fdots_pos_iter_poly_mesh(const MeshRenderData *mr,
float *co = center[mp_index];
zero_v3(co);
const MVert *mvert = mr->mvert;
const MLoop *mloop = mr->mloop;
const BLI_bitmap *facedot_tags = mr->me->runtime.subsurf_face_dot_tags;
@ -84,13 +83,12 @@ static void extract_fdots_pos_iter_poly_mesh(const MeshRenderData *mr,
const MLoop *ml = &mloop[ml_index];
if (mr->use_subsurf_fdots) {
if (BLI_BITMAP_TEST(facedot_tags, ml->v)) {
copy_v3_v3(center[mp_index], mvert[ml->v].co);
copy_v3_v3(center[mp_index], mr->positions[ml->v]);
break;
}
}
else {
const MVert *mv = &mvert[ml->v];
add_v3_v3(center[mp_index], mv->co);
add_v3_v3(center[mp_index], mr->positions[ml->v]);
}
}

View File

@ -217,9 +217,9 @@ static void statvis_calc_thickness(const MeshRenderData *mr, float *r_thickness)
const MLoopTri *mlooptri = mr->mlooptri;
for (int i = 0; i < mr->tri_len; i++, mlooptri++) {
const int index = mlooptri->poly;
const float *cos[3] = {mr->mvert[mr->mloop[mlooptri->tri[0]].v].co,
mr->mvert[mr->mloop[mlooptri->tri[1]].v].co,
mr->mvert[mr->mloop[mlooptri->tri[2]].v].co};
const float *cos[3] = {mr->positions[mr->mloop[mlooptri->tri[0]].v],
mr->positions[mr->mloop[mlooptri->tri[1]].v],
mr->positions[mr->mloop[mlooptri->tri[2]].v]};
float ray_co[3];
float ray_no[3];
@ -259,7 +259,7 @@ static void statvis_calc_thickness(const MeshRenderData *mr, float *r_thickness)
}
struct BVHTree_OverlapData {
const MVert *verts;
const float3 *positions;
const MLoop *loops;
const MLoopTri *mlooptri;
float epsilon;
@ -276,12 +276,12 @@ static bool bvh_overlap_cb(void *userdata, int index_a, int index_b, int UNUSED(
return false;
}
const float *tri_a_co[3] = {data->verts[data->loops[tri_a->tri[0]].v].co,
data->verts[data->loops[tri_a->tri[1]].v].co,
data->verts[data->loops[tri_a->tri[2]].v].co};
const float *tri_b_co[3] = {data->verts[data->loops[tri_b->tri[0]].v].co,
data->verts[data->loops[tri_b->tri[1]].v].co,
data->verts[data->loops[tri_b->tri[2]].v].co};
const float *tri_a_co[3] = {data->positions[data->loops[tri_a->tri[0]].v],
data->positions[data->loops[tri_a->tri[1]].v],
data->positions[data->loops[tri_a->tri[2]].v]};
const float *tri_b_co[3] = {data->positions[data->loops[tri_b->tri[0]].v],
data->positions[data->loops[tri_b->tri[1]].v],
data->positions[data->loops[tri_b->tri[2]].v]};
float ix_pair[2][3];
int verts_shared = 0;
@ -342,7 +342,7 @@ static void statvis_calc_intersect(const MeshRenderData *mr, float *r_intersect)
BVHTree *tree = BKE_bvhtree_from_mesh_get(&treeData, mr->me, BVHTREE_FROM_LOOPTRI, 4);
struct BVHTree_OverlapData data = {nullptr};
data.verts = mr->mvert;
data.positions = mr->positions;
data.loops = mr->mloop;
data.mlooptri = mr->mlooptri;
data.epsilon = BLI_bvhtree_get_epsilon(tree);
@ -454,9 +454,9 @@ static void statvis_calc_distort(const MeshRenderData *mr, float *r_distort)
const MLoop *l_next = &mr->mloop[mp->loopstart + (i + 1) % mp->totloop];
float no_corner[3];
normal_tri_v3(no_corner,
mr->mvert[l_prev->v].co,
mr->mvert[l_curr->v].co,
mr->mvert[l_next->v].co);
mr->positions[l_prev->v],
mr->positions[l_curr->v],
mr->positions[l_next->v]);
/* simple way to detect (what is most likely) concave */
if (dot_v3v3(f_no, no_corner) < 0.0f) {
negate_v3(no_corner);
@ -534,8 +534,6 @@ static void statvis_calc_sharp(const MeshRenderData *mr, float *r_sharp)
for (int i = 0; i < mp->totloop; i++) {
const MLoop *l_curr = &mr->mloop[mp->loopstart + (i + 0) % mp->totloop];
const MLoop *l_next = &mr->mloop[mp->loopstart + (i + 1) % mp->totloop];
const MVert *v_curr = &mr->mvert[l_curr->v];
const MVert *v_next = &mr->mvert[l_next->v];
float angle;
void **pval;
bool value_is_init = BLI_edgehash_ensure_p(eh, l_curr->v, l_next->v, &pval);
@ -548,7 +546,10 @@ static void statvis_calc_sharp(const MeshRenderData *mr, float *r_sharp)
const float *f1_no = mr->poly_normals[mp_index];
const float *f2_no = static_cast<const float *>(*pval);
angle = angle_normalized_v3v3(f1_no, f2_no);
angle = is_edge_convex_v3(v_curr->co, v_next->co, f1_no, f2_no) ? angle : -angle;
angle = is_edge_convex_v3(
mr->positions[l_curr->v], mr->positions[l_next->v], f1_no, f2_no) ?
angle :
-angle;
/* Tag as manifold. */
*pval = nullptr;
}

View File

@ -95,9 +95,8 @@ static void extract_pos_nor_iter_poly_mesh(const MeshRenderData *mr,
const MLoop *ml = &mloop[ml_index];
PosNorLoop *vert = &data->vbo_data[ml_index];
const MVert *mv = &mr->mvert[ml->v];
const bool vert_hidden = mr->hide_vert && mr->hide_vert[ml->v];
copy_v3_v3(vert->pos, mv->co);
copy_v3_v3(vert->pos, mr->positions[ml->v]);
vert->nor = data->normals[ml->v].low;
/* Flag for paint mode overlay. */
if (poly_hidden || vert_hidden ||
@ -136,8 +135,8 @@ static void extract_pos_nor_iter_ledge_mesh(const MeshRenderData *mr,
MeshExtract_PosNor_Data *data = static_cast<MeshExtract_PosNor_Data *>(_data);
const int ml_index = mr->loop_len + ledge_index * 2;
PosNorLoop *vert = &data->vbo_data[ml_index];
copy_v3_v3(vert[0].pos, mr->mvert[med->v1].co);
copy_v3_v3(vert[1].pos, mr->mvert[med->v2].co);
copy_v3_v3(vert[0].pos, mr->positions[med->v1].co);
copy_v3_v3(vert[1].pos, mr->positions[med->v2].co);
vert[0].nor = data->normals[med->v1].low;
vert[1].nor = data->normals[med->v2].low;
}
@ -157,7 +156,6 @@ static void extract_pos_nor_iter_lvert_bm(const MeshRenderData *mr,
}
static void extract_pos_nor_iter_lvert_mesh(const MeshRenderData *mr,
const MVert *mv,
const int lvert_index,
void *_data)
{
@ -167,7 +165,7 @@ static void extract_pos_nor_iter_lvert_mesh(const MeshRenderData *mr,
const int ml_index = offset + lvert_index;
const int v_index = mr->lverts[lvert_index];
PosNorLoop *vert = &data->vbo_data[ml_index];
copy_v3_v3(vert->pos, mv->co);
copy_v3_v3(vert->pos, mr->positions[v_index]);
vert->nor = data->normals[v_index].low;
}
@ -442,8 +440,7 @@ static void extract_pos_nor_hq_iter_poly_mesh(const MeshRenderData *mr,
const bool vert_hidden = mr->hide_vert && mr->hide_vert[ml->v];
PosNorHQLoop *vert = &data->vbo_data[ml_index];
const MVert *mv = &mr->mvert[ml->v];
copy_v3_v3(vert->pos, mv->co);
copy_v3_v3(vert->pos, mr->positions[ml->v]);
copy_v3_v3_short(vert->nor, data->normals[ml->v].high);
/* Flag for paint mode overlay. */
@ -484,8 +481,8 @@ static void extract_pos_nor_hq_iter_ledge_mesh(const MeshRenderData *mr,
MeshExtract_PosNorHQ_Data *data = static_cast<MeshExtract_PosNorHQ_Data *>(_data);
const int ml_index = mr->loop_len + ledge_index * 2;
PosNorHQLoop *vert = &data->vbo_data[ml_index];
copy_v3_v3(vert[0].pos, mr->mvert[med->v1].co);
copy_v3_v3(vert[1].pos, mr->mvert[med->v2].co);
copy_v3_v3(vert[0].pos, mr->positions[med->v1]);
copy_v3_v3(vert[1].pos, mr->positions[med->v2]);
copy_v3_v3_short(vert[0].nor, data->normals[med->v1].high);
vert[0].nor[3] = 0;
copy_v3_v3_short(vert[1].nor, data->normals[med->v2].high);
@ -508,7 +505,6 @@ static void extract_pos_nor_hq_iter_lvert_bm(const MeshRenderData *mr,
}
static void extract_pos_nor_hq_iter_lvert_mesh(const MeshRenderData *mr,
const MVert *mv,
const int lvert_index,
void *_data)
{
@ -518,7 +514,7 @@ static void extract_pos_nor_hq_iter_lvert_mesh(const MeshRenderData *mr,
const int ml_index = offset + lvert_index;
const int v_index = mr->lverts[lvert_index];
PosNorHQLoop *vert = &data->vbo_data[ml_index];
copy_v3_v3(vert->pos, mv->co);
copy_v3_v3(vert->pos, mr->positions[v_index]);
copy_v3_v3_short(vert->nor, data->normals[v_index].high);
vert->nor[3] = 0;
}

View File

@ -169,7 +169,6 @@ static void extract_vert_idx_iter_ledge_mesh(const MeshRenderData *mr,
}
static void extract_vert_idx_iter_lvert_mesh(const MeshRenderData *mr,
const MVert *UNUSED(mv),
const int lvert_index,
void *data)
{

View File

@ -88,9 +88,8 @@ static void extract_tan_init_common(const MeshRenderData *mr,
}
}
else {
const MVert *mv = mr->mvert;
for (int v = 0; v < mr->vert_len; v++, mv++) {
copy_v3_v3(orco[v], mv->co);
for (int v = 0; v < mr->vert_len; v++) {
copy_v3_v3(orco[v], mr->positions[v]);
}
}
BKE_mesh_orco_verts_transform(mr->me, orco, mr->vert_len, 0);
@ -114,7 +113,7 @@ static void extract_tan_init_common(const MeshRenderData *mr,
&tangent_mask);
}
else {
BKE_mesh_calc_loop_tangent_ex(mr->mvert,
BKE_mesh_calc_loop_tangent_ex(reinterpret_cast<const float(*)[3]>(mr->positions),
mr->mpoly,
mr->poly_len,
mr->mloop,

View File

@ -409,10 +409,10 @@ static void add_verts_to_dgroups(ReportList *reports,
}
/* transform verts to global space */
const MVert *mesh_verts = BKE_mesh_positions(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
for (int i = 0; i < mesh->totvert; i++) {
if (!vertsfilled) {
copy_v3_v3(verts[i], mesh_verts[i].co);
copy_v3_v3(verts[i], positions[i]);
}
mul_m4_v3(ob->obmat, verts[i]);
}

View File

@ -68,6 +68,7 @@
#include "object_intern.h"
using blender::float3;
using blender::MutableSpan;
using blender::Span;
@ -1287,12 +1288,12 @@ static blender::Vector<int> getSurroundingVerts(Mesh *me, int vert)
* coord is the place the average is stored,
* points is the point cloud, count is the number of points in the cloud.
*/
static void getSingleCoordinate(MVert *points, int count, float coord[3])
static void getSingleCoordinate(float3 *points, int count, float coord[3])
{
int i;
zero_v3(coord);
for (i = 0; i < count; i++) {
add_v3_v3(coord, points[i].co);
add_v3_v3(coord, points[i]);
}
mul_v3_fl(coord, 1.0f / count);
}
@ -1358,7 +1359,7 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
Mesh *me_deform;
MDeformWeight *dw, *dw_eval;
MVert m;
float3 m;
MDeformVert *dvert = me->deform_verts_for_write().data() + index;
MDeformVert *dvert_eval = mesh_eval->deform_verts_for_write().data() + index;
int totweight = dvert->totweight;
@ -1383,9 +1384,9 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
do {
wasChange = false;
me_deform = mesh_get_eval_deform(depsgraph, scene_eval, object_eval, &CD_MASK_BAREMESH);
const Span<MVert> verts = me_deform->positions();
m = verts[index];
copy_v3_v3(oldPos, m.co);
const Span<float3> positions = me_deform->positions();
m = positions[index];
copy_v3_v3(oldPos, m);
distToStart = dot_v3v3(norm, oldPos) + d;
if (distToBe == originalDistToBe) {
@ -1426,9 +1427,8 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
}
dw_eval->weight = dw->weight;
me_deform = mesh_get_eval_deform(depsgraph, scene_eval, object_eval, &CD_MASK_BAREMESH);
m = verts[index];
getVerticalAndHorizontalChange(
norm, d, coord, oldPos, distToStart, m.co, changes, dists, i);
m = positions[index];
getVerticalAndHorizontalChange(norm, d, coord, oldPos, distToStart, m, changes, dists, i);
dw->weight = oldw;
dw_eval->weight = oldw;
if (!k) {
@ -1532,28 +1532,28 @@ static void vgroup_fix(
int i;
Mesh *me = static_cast<Mesh *>(ob->data);
MVert *mvert = me->positions_for_write().data();
float3 *positions = me->positions_for_write().data();
if (!(me->editflag & ME_EDIT_PAINT_VERT_SEL)) {
return;
}
const bke::AttributeAccessor attributes = me->attributes();
const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
".selection_vert", ATTR_DOMAIN_POINT, false);
for (i = 0; i < me->totvert && mvert; i++, mvert++) {
for (i = 0; i < me->totvert && positions; i++) {
if (selection_vert[i]) {
blender::Vector<int> verts = getSurroundingVerts(me, i);
const int count = verts.size();
if (!verts.is_empty()) {
MVert m;
MVert *p = static_cast<MVert *>(MEM_callocN(sizeof(MVert) * (count), "deformedPoints"));
float3 m;
float3 *p = static_cast<float3 *>(MEM_callocN(sizeof(float3) * (count), "deformedPoints"));
int k;
Mesh *me_deform = mesh_get_eval_deform(
depsgraph, scene_eval, object_eval, &CD_MASK_BAREMESH);
const Span<MVert> verts_deform = me_deform->positions();
const Span<float3> positions_deform = me_deform->positions();
k = count;
while (k--) {
p[k] = verts_deform[verts[k]];
p[k] = positions_deform[verts[k]];
}
if (count >= 3) {
@ -1561,8 +1561,8 @@ static void vgroup_fix(
float coord[3];
float norm[3];
getSingleCoordinate(p, count, coord);
m = verts_deform[i];
sub_v3_v3v3(norm, m.co, coord);
m = positions_deform[i];
sub_v3_v3v3(norm, m, coord);
mag = normalize_v3(norm);
if (mag) { /* zeros fix */
d = -dot_v3v3(norm, coord);

View File

@ -1451,28 +1451,23 @@ void recalc_emitter_field(Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), Part
vec = edit->emitter_cosnos;
nor = vec + 3;
const MVert *verts = BKE_mesh_positions(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh);
MFace *mfaces = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
for (i = 0; i < totface; i++, vec += 6, nor += 6) {
MFace *mface = &mfaces[i];
const MVert *mvert;
mvert = &verts[mface->v1];
copy_v3_v3(vec, mvert->co);
copy_v3_v3(vec, positions[mface->v1]);
copy_v3_v3(nor, vert_normals[mface->v1]);
mvert = &verts[mface->v2];
add_v3_v3v3(vec, vec, mvert->co);
add_v3_v3v3(vec, vec, positions[mface->v2]);
add_v3_v3(nor, vert_normals[mface->v2]);
mvert = &verts[mface->v3];
add_v3_v3v3(vec, vec, mvert->co);
add_v3_v3v3(vec, vec, positions[mface->v3]);
add_v3_v3(nor, vert_normals[mface->v3]);
if (mface->v4) {
mvert = &verts[mface->v4];
add_v3_v3v3(vec, vec, mvert->co);
add_v3_v3v3(vec, vec, positions[mface->v4]);
add_v3_v3(nor, vert_normals[mface->v4]);
mul_v3_fl(vec, 0.25);
@ -4142,7 +4137,6 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
float *ipoint)
{
MFace *mface = NULL;
MVert *mvert = NULL;
int i, totface, intersect = 0;
float cur_d, cur_uv[2], v1[3], v2[3], v3[3], v4[3], min[3], max[3], p_min[3], p_max[3];
float cur_ipoint[3];
@ -4180,7 +4174,7 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
totface = mesh->totface;
mface = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
mvert = BKE_mesh_positions_for_write(mesh);
float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
/* lets intersect the faces */
for (i = 0; i < totface; i++, mface++) {
@ -4193,11 +4187,11 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
}
}
else {
copy_v3_v3(v1, mvert[mface->v1].co);
copy_v3_v3(v2, mvert[mface->v2].co);
copy_v3_v3(v3, mvert[mface->v3].co);
copy_v3_v3(v1, positions[mface->v1]);
copy_v3_v3(v2, positions[mface->v2]);
copy_v3_v3(v3, positions[mface->v3]);
if (mface->v4) {
copy_v3_v3(v4, mvert[mface->v4].co);
copy_v3_v3(v4, positions[mface->v4]);
}
}

View File

@ -411,7 +411,7 @@ typedef struct ProjPaintState {
int totedge_eval;
int totvert_eval;
const MVert *mvert_eval;
const float (*positions_eval)[3];
const float (*vert_normals)[3];
const MEdge *medge_eval;
const MPoly *mpoly_eval;
@ -919,9 +919,9 @@ static bool project_bucket_point_occluded(const ProjPaintState *ps,
if (do_clip) {
const float *vtri_co[3] = {
ps->mvert_eval[ps->mloop_eval[lt->tri[0]].v].co,
ps->mvert_eval[ps->mloop_eval[lt->tri[1]].v].co,
ps->mvert_eval[ps->mloop_eval[lt->tri[2]].v].co,
ps->positions_eval[ps->mloop_eval[lt->tri[0]].v],
ps->positions_eval[ps->mloop_eval[lt->tri[1]].v],
ps->positions_eval[ps->mloop_eval[lt->tri[2]].v],
};
isect_ret = project_paint_occlude_ptv_clip(
pixelScreenCo, UNPACK3(vtri_ss), UNPACK3(vtri_co), w, ps->is_ortho, ps->rv3d);
@ -1733,9 +1733,9 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps,
/* In case the normalizing per pixel isn't optimal,
* we could cache or access from evaluated mesh. */
normal_tri_v3(no,
ps->mvert_eval[lt_vtri[0]].co,
ps->mvert_eval[lt_vtri[1]].co,
ps->mvert_eval[lt_vtri[2]].co);
ps->positions_eval[lt_vtri[0]],
ps->positions_eval[lt_vtri[1]],
ps->positions_eval[lt_vtri[2]]);
}
if (UNLIKELY(ps->is_flip_object)) {
@ -1750,9 +1750,9 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps,
/* Annoying but for the perspective view we need to get the pixels location in 3D space :/ */
float viewDirPersp[3];
const float *co1, *co2, *co3;
co1 = ps->mvert_eval[lt_vtri[0]].co;
co2 = ps->mvert_eval[lt_vtri[1]].co;
co3 = ps->mvert_eval[lt_vtri[2]].co;
co1 = ps->positions_eval[lt_vtri[0]];
co2 = ps->positions_eval[lt_vtri[1]];
co3 = ps->positions_eval[lt_vtri[2]];
/* Get the direction from the viewPoint to the pixel and normalize */
viewDirPersp[0] = (ps->viewPos[0] - (w[0] * co1[0] + w[1] * co2[0] + w[2] * co3[0]));
@ -3026,9 +3026,9 @@ static void project_paint_face_init(const ProjPaintState *ps,
const bool do_backfacecull = ps->do_backfacecull;
const bool do_clip = RV3D_CLIPPING_ENABLED(ps->v3d, ps->rv3d);
vCo[0] = ps->mvert_eval[lt_vtri[0]].co;
vCo[1] = ps->mvert_eval[lt_vtri[1]].co;
vCo[2] = ps->mvert_eval[lt_vtri[2]].co;
vCo[0] = ps->positions_eval[lt_vtri[0]];
vCo[1] = ps->positions_eval[lt_vtri[1]];
vCo[2] = ps->positions_eval[lt_vtri[2]];
/* Use lt_uv_pxoffset instead of lt_tri_uv so we can offset the UV half a pixel
* this is done so we can avoid offsetting all the pixels by 0.5 which causes
@ -3125,9 +3125,9 @@ static void project_paint_face_init(const ProjPaintState *ps,
* because it is a relatively expensive operation. */
if (do_clip || do_3d_mapping) {
interp_v3_v3v3v3(wco,
ps->mvert_eval[lt_vtri[0]].co,
ps->mvert_eval[lt_vtri[1]].co,
ps->mvert_eval[lt_vtri[2]].co,
ps->positions_eval[lt_vtri[0]],
ps->positions_eval[lt_vtri[1]],
ps->positions_eval[lt_vtri[2]],
w);
if (do_clip && ED_view3d_clipping_test(ps->rv3d, wco, true)) {
/* Watch out that no code below this needs to run */
@ -3788,7 +3788,6 @@ static void proj_paint_state_viewport_init(ProjPaintState *ps, const char symmet
static void proj_paint_state_screen_coords_init(ProjPaintState *ps, const int diameter)
{
const MVert *mv;
float *projScreenCo;
float projMargin;
int a;
@ -3799,8 +3798,8 @@ static void proj_paint_state_screen_coords_init(ProjPaintState *ps, const int di
projScreenCo = *ps->screenCoords;
if (ps->is_ortho) {
for (a = 0, mv = ps->mvert_eval; a < ps->totvert_eval; a++, mv++, projScreenCo += 4) {
mul_v3_m4v3(projScreenCo, ps->projectMat, mv->co);
for (a = 0; a < ps->totvert_eval; a++, projScreenCo += 4) {
mul_v3_m4v3(projScreenCo, ps->projectMat, ps->positions_eval[a]);
/* screen space, not clamped */
projScreenCo[0] = (float)(ps->winx * 0.5f) + (ps->winx * 0.5f) * projScreenCo[0];
@ -3809,8 +3808,8 @@ static void proj_paint_state_screen_coords_init(ProjPaintState *ps, const int di
}
}
else {
for (a = 0, mv = ps->mvert_eval; a < ps->totvert_eval; a++, mv++, projScreenCo += 4) {
copy_v3_v3(projScreenCo, mv->co);
for (a = 0; a < ps->totvert_eval; a++, projScreenCo += 4) {
copy_v3_v3(projScreenCo, ps->positions_eval[a]);
projScreenCo[3] = 1.0f;
mul_m4_v4(ps->projectMat, projScreenCo);
@ -3879,7 +3878,7 @@ static void proj_paint_state_cavity_init(ProjPaintState *ps)
for (a = 0, me = ps->medge_eval; a < ps->totedge_eval; a++, me++) {
float e[3];
sub_v3_v3v3(e, ps->mvert_eval[me->v1].co, ps->mvert_eval[me->v2].co);
sub_v3_v3v3(e, ps->positions_eval[me->v1], ps->positions_eval[me->v2]);
normalize_v3(e);
add_v3_v3(edges[me->v2], e);
counter[me->v2]++;
@ -3950,13 +3949,12 @@ static void proj_paint_state_vert_flags_init(ProjPaintState *ps)
{
if (ps->do_backfacecull && ps->do_mask_normal) {
float viewDirPersp[3];
const MVert *mv;
float no[3];
int a;
ps->vertFlags = MEM_callocN(sizeof(char) * ps->totvert_eval, "paint-vertFlags");
for (a = 0, mv = ps->mvert_eval; a < ps->totvert_eval; a++, mv++) {
for (a = 0; a < ps->totvert_eval; a++) {
copy_v3_v3(no, ps->vert_normals[a]);
if (UNLIKELY(ps->is_flip_object)) {
negate_v3(no);
@ -3969,7 +3967,7 @@ static void proj_paint_state_vert_flags_init(ProjPaintState *ps)
}
}
else {
sub_v3_v3v3(viewDirPersp, ps->viewPos, mv->co);
sub_v3_v3v3(viewDirPersp, ps->viewPos, ps->positions_eval[a]);
normalize_v3(viewDirPersp);
if (UNLIKELY(ps->is_flip_object)) {
negate_v3(viewDirPersp);
@ -4056,7 +4054,7 @@ static bool proj_paint_state_mesh_eval_init(const bContext *C, ProjPaintState *p
}
ps->mat_array[totmat - 1] = NULL;
ps->mvert_eval = BKE_mesh_positions(ps->me_eval);
ps->positions_eval = BKE_mesh_positions(ps->me_eval);
ps->vert_normals = BKE_mesh_vertex_normals_ensure(ps->me_eval);
if (ps->do_mask_cavity) {
ps->medge_eval = BKE_mesh_edges(ps->me_eval);
@ -5668,9 +5666,9 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po
UnifiedPaintSettings *ups = &ps->scene->toolsettings->unified_paint_settings;
interp_v3_v3v3v3(world,
ps->mvert_eval[lt_vtri[0]].co,
ps->mvert_eval[lt_vtri[1]].co,
ps->mvert_eval[lt_vtri[2]].co,
ps->positions_eval[lt_vtri[0]],
ps->positions_eval[lt_vtri[1]],
ps->positions_eval[lt_vtri[2]],
w);
ups->average_stroke_counter++;

View File

@ -2070,7 +2070,7 @@ static void do_wpaint_brush_smear_task_cb_ex(void *__restrict userdata,
* Otherwise, take the current vert. */
const int v_index = has_grids ? ss->mloop[vd.grid_indices[vd.g]].v : vd.vert_indices[vd.i];
const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f;
const MVert *mv_curr = &ss->mvert[v_index];
const float3 &mv_curr = ss->positions[v_index];
/* If the vertex is selected */
if (!(use_face_sel || use_vert_sel) || selection_vert[v_index]) {
@ -2097,11 +2097,11 @@ static void do_wpaint_brush_smear_task_cb_ex(void *__restrict userdata,
for (int k = 0; k < mp->totloop; k++, ml_other++) {
const uint v_other_index = ml_other->v;
if (v_other_index != v_index) {
const MVert *mv_other = &ss->mvert[v_other_index];
const float3 &mv_other = ss->positions[v_other_index];
/* Get the direction from the selected vert to the neighbor. */
float other_dir[3];
sub_v3_v3v3(other_dir, mv_curr->co, mv_other->co);
sub_v3_v3v3(other_dir, mv_curr, mv_other);
project_plane_v3_v3v3(other_dir, other_dir, cache->view_normal);
normalize_v3(other_dir);
@ -3305,7 +3305,7 @@ static void do_vpaint_brush_smear(bContext *C,
const int v_index = has_grids ? ss->mloop[vd.grid_indices[vd.g]].v :
vd.vert_indices[vd.i];
const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f;
const MVert *mv_curr = &ss->mvert[v_index];
const float3 &mv_curr = &ss->mvert[v_index];
/* if the vertex is selected for painting. */
if (!use_vert_sel || selection_vert[v_index]) {
@ -3342,7 +3342,7 @@ static void do_vpaint_brush_smear(bContext *C,
for (int k = 0; k < mp->totloop; k++, ml_other++) {
const uint v_other_index = ml_other->v;
if (v_other_index != v_index) {
const MVert *mv_other = &ss->mvert[v_other_index];
const float3 &mv_other = &ss->mvert[v_other_index];
/* Get the direction from the
* selected vert to the neighbor. */

View File

@ -55,6 +55,8 @@
#include <climits>
using blender::float3;
namespace Freestyle {
const char *BlenderStrokeRenderer::uvNames[] = {"along_stroke", "along_stroke_tips"};
@ -576,7 +578,7 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
mesh->totloop = group->totloop;
mesh->totcol = group->materials.size();
MVert *verts = (MVert *)CustomData_add_layer_named(
float3 *mesh_positions = (float3 *)CustomData_add_layer_named(
&mesh->vdata, CD_PROP_FLOAT3, CD_SET_DEFAULT, nullptr, mesh->totvert, "position");
MEdge *edges = (MEdge *)CustomData_add_layer(
&mesh->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, mesh->totedge);
@ -663,19 +665,17 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
else {
if (!visible) {
// first vertex
verts->co[0] = svRep[0]->point2d()[0];
verts->co[1] = svRep[0]->point2d()[1];
verts->co[2] = get_stroke_vertex_z();
mesh_positions[vertex_index][0] = svRep[0]->point2d()[0];
mesh_positions[vertex_index][1] = svRep[0]->point2d()[1];
mesh_positions[vertex_index][2] = get_stroke_vertex_z();
++verts;
++vertex_index;
// second vertex
verts->co[0] = svRep[1]->point2d()[0];
verts->co[1] = svRep[1]->point2d()[1];
verts->co[2] = get_stroke_vertex_z();
mesh_positions[vertex_index][0] = svRep[1]->point2d()[0];
mesh_positions[vertex_index][1] = svRep[1]->point2d()[1];
mesh_positions[vertex_index][2] = get_stroke_vertex_z();
++verts;
++vertex_index;
// first edge
@ -687,10 +687,9 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
visible = true;
// vertex
verts->co[0] = svRep[2]->point2d()[0];
verts->co[1] = svRep[2]->point2d()[1];
verts->co[2] = get_stroke_vertex_z();
++verts;
mesh_positions[vertex_index][0] = svRep[2]->point2d()[0];
mesh_positions[vertex_index][1] = svRep[2]->point2d()[1];
mesh_positions[vertex_index][2] = get_stroke_vertex_z();
++vertex_index;
// edges

View File

@ -122,7 +122,7 @@ void ABCHairWriter::write_hair_sample(const HierarchyContext &context,
MTFace *mtface = (MTFace *)CustomData_get_layer(&mesh->fdata, CD_MTFACE);
MFace *mface = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
const MVert *mverts = BKE_mesh_positions(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh);
if ((!mtface || !mface) && !uv_warning_shown_) {
@ -162,7 +162,7 @@ void ABCHairWriter::write_hair_sample(const HierarchyContext &context,
uv_values.emplace_back(r_uv[0], r_uv[1]);
psys_interpolate_face(mesh,
mverts,
positions,
vert_normals,
face,
tface,
@ -245,7 +245,7 @@ void ABCHairWriter::write_hair_child_sample(const HierarchyContext &context,
MFace *mface = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
MTFace *mtface = (MTFace *)CustomData_get_layer(&mesh->fdata, CD_MTFACE);
const MVert *mverts = BKE_mesh_positions(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh);
ParticleSystem *psys = context.particle_system;
@ -279,7 +279,7 @@ void ABCHairWriter::write_hair_child_sample(const HierarchyContext &context,
uv_values.emplace_back(r_uv[0], r_uv[1]);
psys_interpolate_face(mesh,
mverts,
positions,
vert_normals,
face,
tface,

View File

@ -212,10 +212,9 @@ static void rna_ParticleHairKey_location_object_get(PointerRNA *ptr, float *valu
if (pa) {
Mesh *hair_mesh = (psmd->psys->flag & PSYS_HAIR_DYNAMICS) ? psmd->psys->hair_out_mesh : NULL;
const MVert *verts = BKE_mesh_positions(hair_mesh);
const float(*positions)[3] = BKE_mesh_positions(hair_mesh);
if (hair_mesh) {
const MVert *mv = &verts[pa->hair_index + (hkey - pa->hair)];
copy_v3_v3(values, mv->co);
copy_v3_v3(values, positions[pa->hair_index + (hkey - pa->hair)]);
}
else {
float hairmat[4][4];
@ -279,9 +278,8 @@ static void hair_key_location_object_set(HairKey *hair_key,
if (hair_key_index == -1) {
return;
}
MVert *verts = BKE_mesh_positions_for_write(hair_mesh);
MVert *mv = &verts[particle->hair_index + (hair_key_index)];
copy_v3_v3(mv->co, src_co);
float(*positions)[3] = BKE_mesh_positions_for_write(hair_mesh);
copy_v3_v3(positions[particle->hair_index + (hair_key_index)], src_co);
return;
}
@ -324,9 +322,8 @@ static void rna_ParticleHairKey_co_object(HairKey *hairkey,
NULL;
if (particle) {
if (hair_mesh) {
const MVert *verts = BKE_mesh_positions(hair_mesh);
const MVert *mv = &verts[particle->hair_index + (hairkey - particle->hair)];
copy_v3_v3(n_co, mv->co);
const float(*positions)[3] = BKE_mesh_positions(hair_mesh);
copy_v3_v3(n_co, positions[particle->hair_index + (hairkey - particle->hair)]);
}
else {
float hairmat[4][4];

View File

@ -125,15 +125,15 @@ static int svert_sum_cmp(const void *e1, const void *e2)
}
static void svert_from_mvert(SortVertsElem *sv,
const MVert *mv,
const float (*positions)[3],
const int i_begin,
const int i_end)
{
int i;
for (i = i_begin; i < i_end; i++, sv++, mv++) {
for (i = i_begin; i < i_end; i++, sv++) {
sv->vertex_num = i;
copy_v3_v3(sv->co, mv->co);
sv->sum_co = sum_v3(mv->co);
copy_v3_v3(sv->co, positions[i]);
sv->sum_co = sum_v3(positions[i]);
}
}
@ -145,7 +145,7 @@ static void svert_from_mvert(SortVertsElem *sv,
* The `int doubles_map[verts_source_num]` array must have been allocated by caller.
*/
static void dm_mvert_map_doubles(int *doubles_map,
const MVert *mverts,
const float (*positions)[3],
const int target_start,
const int target_verts_num,
const int source_start,
@ -166,10 +166,10 @@ static void dm_mvert_map_doubles(int *doubles_map,
sorted_verts_source = MEM_malloc_arrayN(source_verts_num, sizeof(SortVertsElem), __func__);
/* Copy target vertices index and cos into SortVertsElem array */
svert_from_mvert(sorted_verts_target, mverts + target_start, target_start, target_end);
svert_from_mvert(sorted_verts_target, positions + target_start, target_start, target_end);
/* Copy source vertices index and cos into SortVertsElem array */
svert_from_mvert(sorted_verts_source, mverts + source_start, source_start, source_end);
svert_from_mvert(sorted_verts_source, positions + source_start, source_start, source_end);
/* sort arrays according to sum of vertex coordinates (sumco) */
qsort(sorted_verts_target, target_verts_num, sizeof(SortVertsElem), svert_sum_cmp);
@ -237,8 +237,8 @@ static void dm_mvert_map_doubles(int *doubles_map,
* then there will be no mapping at all for this source. */
while (best_target_vertex != -1 &&
!ELEM(doubles_map[best_target_vertex], -1, best_target_vertex)) {
if (compare_len_v3v3(mverts[sve_source->vertex_num].co,
mverts[doubles_map[best_target_vertex]].co,
if (compare_len_v3v3(positions[sve_source->vertex_num],
positions[doubles_map[best_target_vertex]],
dist)) {
best_target_vertex = doubles_map[best_target_vertex];
}
@ -275,11 +275,10 @@ static void mesh_merge_transform(Mesh *result,
{
int *index_orig;
int i;
MVert *mv;
MEdge *me;
MLoop *ml;
MPoly *mp;
MVert *result_verts = BKE_mesh_positions_for_write(result);
float(*result_positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *result_edges = BKE_mesh_edges_for_write(result);
MPoly *result_polys = BKE_mesh_polys_for_write(result);
MLoop *result_loops = BKE_mesh_loops_for_write(result);
@ -289,10 +288,8 @@ static void mesh_merge_transform(Mesh *result,
CustomData_copy_data(&cap_mesh->ldata, &result->ldata, 0, cap_loops_index, cap_nloops);
CustomData_copy_data(&cap_mesh->pdata, &result->pdata, 0, cap_polys_index, cap_npolys);
mv = result_verts + cap_verts_index;
for (i = 0; i < cap_nverts; i++, mv++) {
mul_m4_v3(cap_offset, mv->co);
for (i = 0; i < cap_nverts; i++) {
mul_m4_v3(cap_offset, result_positions[cap_verts_index + i]);
}
/* We have to correct normals too, if we do not tag them as dirty later! */
@ -428,7 +425,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* Build up offset array, accumulating all settings options. */
unit_m4(offset);
const MVert *src_verts = BKE_mesh_positions(mesh);
const float(*src_positions)[3] = BKE_mesh_positions(mesh);
const MEdge *src_edges = BKE_mesh_edges(mesh);
const MPoly *src_polys = BKE_mesh_polys(mesh);
const MLoop *src_loops = BKE_mesh_loops(mesh);
@ -439,12 +436,8 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
if (amd->offset_type & MOD_ARR_OFF_RELATIVE) {
float min[3], max[3];
const MVert *src_mv;
INIT_MINMAX(min, max);
for (src_mv = src_verts, j = chunk_nverts; j--; src_mv++) {
minmax_v3v3_v3(min, max, src_mv->co);
}
BKE_mesh_minmax(mesh, min, max);
for (j = 3; j--;) {
offset[3][j] += amd->scale[j] * (max[j] - min[j]);
@ -541,7 +534,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* Initialize a result dm */
result = BKE_mesh_new_nomain_from_template(
mesh, result_nverts, result_nedges, 0, result_nloops, result_npolys);
MVert *result_verts = BKE_mesh_positions_for_write(result);
float(*result_positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *result_edges = BKE_mesh_edges_for_write(result);
MPoly *result_polys = BKE_mesh_polys_for_write(result);
MLoop *result_loops = BKE_mesh_loops_for_write(result);
@ -559,9 +552,9 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, chunk_npolys);
/* Subdivision-surface for eg won't have mesh data in the custom-data arrays.
* Now add #MVert/#MEdge/#MPoly layers. */
if (!CustomData_has_layer(&mesh->vdata, CD_MVERT)) {
memcpy(result_verts, src_verts, sizeof(MVert) * mesh->totvert);
* Now add #position/#MEdge/#MPoly layers. */
if (!src_positions) {
memcpy(result_positions, src_positions, sizeof(float[3]) * mesh->totvert);
}
if (!CustomData_has_layer(&mesh->edata, CD_MEDGE)) {
memcpy(result_edges, src_edges, sizeof(MEdge) * mesh->totedge);
@ -599,7 +592,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* apply offset to all new verts */
for (i = 0; i < chunk_nverts; i++) {
const int i_dst = vert_offset + i;
mul_m4_v3(current_offset, result_verts[i_dst].co);
mul_m4_v3(current_offset, result_positions[i_dst]);
/* We have to correct normals too, if we do not tag them as dirty! */
if (!use_recalc_normals) {
@ -643,8 +636,8 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
while (target != -1 && !ELEM(full_doubles_map[target], -1, target)) {
/* If target is already mapped, we only follow that mapping if final target remains
* close enough from current vert (otherwise no mapping at all). */
if (compare_len_v3v3(result_verts[this_chunk_index].co,
result_verts[full_doubles_map[target]].co,
if (compare_len_v3v3(result_positions[this_chunk_index],
result_positions[full_doubles_map[target]],
amd->merge_dist)) {
target = full_doubles_map[target];
}
@ -658,7 +651,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
}
else {
dm_mvert_map_doubles(full_doubles_map,
result_verts,
result_positions,
(c - 1) * chunk_nverts,
chunk_nverts,
c * chunk_nverts,
@ -696,7 +689,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
if (use_merge && (amd->flags & MOD_ARR_MERGEFINAL) && (count > 1)) {
/* Merge first and last copies */
dm_mvert_map_doubles(full_doubles_map,
result_verts,
result_positions,
last_chunk_start,
last_chunk_nverts,
first_chunk_start,
@ -726,7 +719,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* Identify doubles with first chunk */
if (use_merge) {
dm_mvert_map_doubles(full_doubles_map,
result_verts,
result_positions,
first_chunk_start,
first_chunk_nverts,
start_cap_start,
@ -756,7 +749,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* Identify doubles with last chunk */
if (use_merge) {
dm_mvert_map_doubles(full_doubles_map,
result_verts,
result_positions,
last_chunk_start,
last_chunk_nverts,
end_cap_start,

View File

@ -93,7 +93,6 @@ static void deformVerts(ModifierData *md,
{
CollisionModifierData *collmd = (CollisionModifierData *)md;
Mesh *mesh_src;
MVert *tempVert = NULL;
Object *ob = ctx->object;
/* If collision is disabled, free the stale data and exit. */
@ -149,7 +148,7 @@ static void deformVerts(ModifierData *md,
for (uint i = 0; i < mvert_num; i++) {
/* we save global positions */
mul_m4_v3(ob->obmat, collmd->x[i].co);
mul_m4_v3(ob->obmat, collmd->x[i]);
}
collmd->xnew = MEM_dupallocN(collmd->x); /* Frame end position. */
@ -177,25 +176,25 @@ static void deformVerts(ModifierData *md,
}
else if (mvert_num == collmd->mvert_num) {
/* put positions to old positions */
tempVert = collmd->x;
float(*temp)[3] = collmd->x;
collmd->x = collmd->xnew;
collmd->xnew = tempVert;
collmd->xnew = temp;
collmd->time_x = collmd->time_xnew;
memcpy(collmd->xnew, BKE_mesh_positions(mesh_src), mvert_num * sizeof(MVert));
memcpy(collmd->xnew, BKE_mesh_positions(mesh_src), mvert_num * sizeof(float[3]));
bool is_static = true;
for (uint i = 0; i < mvert_num; i++) {
/* we save global positions */
mul_m4_v3(ob->obmat, collmd->xnew[i].co);
mul_m4_v3(ob->obmat, collmd->xnew[i]);
/* detect motion */
is_static = is_static && equals_v3v3(collmd->x[i].co, collmd->xnew[i].co);
is_static = is_static && equals_v3v3(collmd->x[i], collmd->xnew[i]);
}
memcpy(collmd->current_xnew, collmd->x, mvert_num * sizeof(MVert));
memcpy(collmd->current_x, collmd->x, mvert_num * sizeof(MVert));
memcpy(collmd->current_xnew, collmd->x, mvert_num * sizeof(float[3]));
memcpy(collmd->current_x, collmd->x, mvert_num * sizeof(float[3]));
/* check if GUI setting has changed for bvh */
if (collmd->bvhtree) {
@ -265,9 +264,9 @@ static void blendRead(BlendDataReader *UNUSED(reader), ModifierData *md)
collmd->xnew = newdataadr(fd, collmd->xnew);
collmd->mfaces = newdataadr(fd, collmd->mfaces);
collmd->current_x = MEM_calloc_arrayN(collmd->mvert_num, sizeof(MVert), "current_x");
collmd->current_xnew = MEM_calloc_arrayN(collmd->mvert_num, sizeof(MVert), "current_xnew");
collmd->current_v = MEM_calloc_arrayN(collmd->mvert_num, sizeof(MVert), "current_v");
collmd->current_x = MEM_calloc_arrayN(collmd->mvert_num, sizeof(float[3]), "current_x");
collmd->current_xnew = MEM_calloc_arrayN(collmd->mvert_num, sizeof(float[3]), "current_xnew");
collmd->current_v = MEM_calloc_arrayN(collmd->mvert_num, sizeof(float[3]), "current_v");
#endif
collmd->x = NULL;

View File

@ -93,7 +93,6 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p
{
ParticleSystem *psys = psmd->psys;
MFace *fa = NULL, *mface = NULL;
MVert *mvert = NULL;
ParticleData *pa;
KDTree_3d *tree;
RNG *rng;
@ -102,7 +101,7 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p
int i, p, v1, v2, v3, v4 = 0;
const bool invert_vgroup = (emd->flag & eExplodeFlag_INVERT_VGROUP) != 0;
mvert = BKE_mesh_positions_for_write(mesh);
float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
mface = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
totvert = mesh->totvert;
totface = mesh->totface;
@ -162,10 +161,10 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p
/* set face-particle-indexes to nearest particle to face center */
for (i = 0, fa = mface; i < totface; i++, fa++) {
add_v3_v3v3(center, mvert[fa->v1].co, mvert[fa->v2].co);
add_v3_v3(center, mvert[fa->v3].co);
add_v3_v3v3(center, positions[fa->v1], positions[fa->v2]);
add_v3_v3(center, positions[fa->v3]);
if (fa->v4) {
add_v3_v3(center, mvert[fa->v4].co);
add_v3_v3(center, positions[fa->v4]);
mul_v3_fl(center, 0.25);
}
else {
@ -643,7 +642,7 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh)
Mesh *split_m;
MFace *mf = NULL, *df1 = NULL;
MFace *mface = CustomData_get_layer(&mesh->fdata, CD_MFACE);
MVert *dupve, *mv;
float *dupve, *mv;
EdgeHash *edgehash;
EdgeHashIterator *ehi;
int totvert = mesh->totvert;
@ -732,18 +731,12 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh)
layers_num = CustomData_number_of_layers(&split_m->fdata, CD_MTFACE);
const MVert *mesh_verts = BKE_mesh_positions(mesh);
MVert *split_m_verts = BKE_mesh_positions_for_write(split_m);
const float(*positions)[3] = BKE_mesh_positions(mesh);
float(*split_m_positions)[3] = BKE_mesh_positions_for_write(split_m);
/* copy new faces & verts (is it really this painful with custom data??) */
for (i = 0; i < totvert; i++) {
MVert source;
MVert *dest;
source = mesh_verts[i];
dest = &split_m_verts[i];
CustomData_copy_data(&mesh->vdata, &split_m->vdata, i, i, 1);
*dest = source;
}
/* override original facepa (original pointer is saved in caller function) */
@ -761,16 +754,16 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh)
for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
BLI_edgehashIterator_getKey(ehi, &ed_v1, &ed_v2);
esplit = POINTER_AS_INT(BLI_edgehashIterator_getValue(ehi));
mv = &split_m_verts[ed_v2];
dupve = &split_m_verts[esplit];
mv = &split_m_positions[ed_v2];
dupve = &split_m_positions[esplit];
CustomData_copy_data(&split_m->vdata, &split_m->vdata, ed_v2, esplit, 1);
*dupve = *mv;
copy_v3_v3(dupve, mv);
mv = &split_m_verts[ed_v1];
mv = &split_m_positions[ed_v1];
mid_v3_v3v3(dupve->co, dupve->co, mv->co);
mid_v3_v3v3(dupve, dupve, mv);
}
BLI_edgehashIterator_free(ehi);
@ -991,26 +984,25 @@ static Mesh *explodeMesh(ExplodeModifierData *emd,
psmd->psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
const MVert *mesh_verts = BKE_mesh_positions(mesh);
MVert *explode_verts = BKE_mesh_positions_for_write(explode);
const float(*positions)[3] = BKE_mesh_positions(mesh);
float(*explode_positions)[3] = BKE_mesh_positions_for_write(explode);
/* duplicate & displace vertices */
ehi = BLI_edgehashIterator_new(vertpahash);
for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
MVert source;
MVert *dest;
float *dest;
/* get particle + vertex from hash */
BLI_edgehashIterator_getKey(ehi, &ed_v1, &ed_v2);
ed_v2 -= totvert;
v = POINTER_AS_INT(BLI_edgehashIterator_getValue(ehi));
source = mesh_verts[ed_v1];
dest = &explode_verts[v];
copy_v3_v3(explode_positions[v], positions[ed_v1]);
dest = &explode_positions[v];
CustomData_copy_data(&mesh->vdata, &explode->vdata, ed_v1, v, 1);
*dest = source;
copy_v3_v3(explode_positions[v], positions[ed_v1]);
if (ed_v2 != totpart) {
/* get particle */
@ -1021,7 +1013,7 @@ static Mesh *explodeMesh(ExplodeModifierData *emd,
state.time = ctime;
psys_get_particle_state(&sim, ed_v2, &state, 1);
vertco = explode_verts[v].co;
vertco = explode_positions[v];
mul_m4_v3(ctx->object->obmat, vertco);
sub_v3_v3(vertco, birth.co);

View File

@ -49,6 +49,7 @@
#include "BLI_vector.hh"
using blender::Array;
using blender::float3;
using blender::IndexRange;
using blender::ListBaseWrapper;
using blender::MutableSpan;
@ -338,8 +339,8 @@ static void copy_masked_verts_to_new_mesh(const Mesh &src_mesh,
Span<int> vertex_map)
{
BLI_assert(src_mesh.totvert == vertex_map.size());
const Span<MVert> src_verts = src_mesh.positions();
MutableSpan<MVert> dst_verts = dst_mesh.positions_for_write();
const Span<float3> src_positions = src_mesh.positions();
MutableSpan<float3> dst_positions = dst_mesh.positions_for_write();
for (const int i_src : vertex_map.index_range()) {
const int i_dst = vertex_map[i_src];
@ -347,10 +348,6 @@ static void copy_masked_verts_to_new_mesh(const Mesh &src_mesh,
continue;
}
const MVert &v_src = src_verts[i_src];
MVert &v_dst = dst_verts[i_dst];
v_dst = v_src;
CustomData_copy_data(&src_mesh.vdata, &dst_mesh.vdata, i_src, i_dst, 1);
}
}
@ -376,11 +373,10 @@ static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh,
uint verts_add_num,
MutableSpan<int> r_edge_map)
{
using namespace blender;
BLI_assert(src_mesh.totvert == vertex_mask.size());
BLI_assert(src_mesh.totedge == r_edge_map.size());
const Span<MVert> src_verts = src_mesh.positions();
const Span<MEdge> src_edges = src_mesh.edges();
MutableSpan<MVert> dst_verts = dst_mesh.positions_for_write();
MutableSpan<MEdge> dst_edges = dst_mesh.edges_for_write();
uint vert_index = dst_mesh.totvert - verts_add_num;
@ -420,11 +416,6 @@ static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh,
float weights[2] = {1.0f - fac, fac};
CustomData_interp(
&src_mesh.vdata, &dst_mesh.vdata, (int *)&e_src.v1, weights, nullptr, 2, vert_index);
MVert &v = dst_verts[vert_index];
const MVert &v1 = src_verts[e_src.v1];
const MVert &v2 = src_verts[e_src.v2];
interp_v3_v3v3(v.co, v1.co, v2.co, fac);
vert_index++;
}
}

View File

@ -179,14 +179,8 @@ static void meshcache_do(MeshCacheModifierData *mcmd,
/* the moons align! */
int i;
float(*vertexCos_Source)[3] = MEM_malloc_arrayN(
verts_num, sizeof(*vertexCos_Source), __func__);
float(*vertexCos_New)[3] = MEM_malloc_arrayN(verts_num, sizeof(*vertexCos_New), __func__);
const MVert *mv = BKE_mesh_positions(me);
for (i = 0; i < verts_num; i++, mv++) {
copy_v3_v3(vertexCos_Source[i], mv->co);
}
const float(*positions)[3] = BKE_mesh_positions(me);
BKE_mesh_calc_relative_deform(
BKE_mesh_polys(me),
@ -194,8 +188,8 @@ static void meshcache_do(MeshCacheModifierData *mcmd,
BKE_mesh_loops(me),
me->totvert,
(const float(*)[3])vertexCos_Source, /* From the original Mesh. */
(const float(*)[3])vertexCos_Real, /* the input we've been given (shape keys!) */
(const float(*)[3])positions, /* From the original Mesh. */
(const float(*)[3])vertexCos_Real, /* the input we've been given (shape keys!) */
(const float(*)[3])vertexCos, /* The result of this modifier. */
vertexCos_New /* The result of this function. */
@ -204,7 +198,6 @@ static void meshcache_do(MeshCacheModifierData *mcmd,
/* write the corrected locations back into the result */
memcpy(vertexCos, vertexCos_New, sizeof(*vertexCos) * verts_num);
MEM_freeN(vertexCos_Source);
MEM_freeN(vertexCos_New);
}
}

View File

@ -60,6 +60,7 @@
# include "usd.h"
#endif
using blender::float3;
using blender::Span;
static void initData(ModifierData *md)
@ -178,17 +179,17 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
if (me != nullptr) {
const Span<MVert> mesh_verts = mesh->positions();
const Span<float3> mesh_positions = mesh->positions();
const Span<MEdge> mesh_edges = mesh->edges();
const Span<MPoly> mesh_polys = mesh->polys();
const Span<MVert> me_verts = me->positions();
const Span<float3> me_positions = me->positions();
const Span<MEdge> me_edges = me->edges();
const Span<MPoly> me_polys = me->polys();
/* TODO(sybren+bastien): possibly check relevant custom data layers (UV/color depending on
* flags) and duplicate those too.
* XXX(Hans): This probably isn't true anymore with various CoW improvements, etc. */
if ((me_verts.data() == mesh_verts.data()) || (me_edges.data() == mesh_edges.data()) ||
if ((me_positions.data() == mesh_positions.data()) || (me_edges.data() == mesh_edges.data()) ||
(me_polys.data() == mesh_polys.data())) {
/* We need to duplicate data here, otherwise we'll modify org mesh, see T51701. */
mesh = reinterpret_cast<Mesh *>(

View File

@ -220,7 +220,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
mesh->flag & ME_AUTOSMOOTH &&
CustomData_has_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL);
/* NOTE: Orco needs final coordinates on CPU side, which are expected to be
* accessible via MVert. For this reason we do not evaluate multires to
* accessible via mesh vertices. For this reason we do not evaluate multires to
* grids when orco is requested. */
const bool for_orco = (ctx->flag & MOD_APPLY_ORCO) != 0;
/* Needed when rendering or baking will in sculpt mode. */
@ -245,7 +245,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
sculpt_session->multires.level = mmd->sculptlvl;
sculpt_session->totvert = mesh->totvert;
sculpt_session->totpoly = mesh->totpoly;
sculpt_session->mvert = NULL;
sculpt_session->positions = NULL;
sculpt_session->mpoly = NULL;
sculpt_session->mloop = NULL;
}

View File

@ -317,10 +317,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
result = BKE_mesh_new_nomain_from_template(mesh, maxvert, maxedge, 0, maxloop, maxpoly);
const MVert *orig_mvert = BKE_mesh_positions(mesh);
const float(*orig_positions)[3] = BKE_mesh_positions(mesh);
const MPoly *orig_mpoly = BKE_mesh_polys(mesh);
const MLoop *orig_mloop = BKE_mesh_loops(mesh);
MVert *mvert = BKE_mesh_positions_for_write(result);
float(*positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *edges = BKE_mesh_edges_for_write(result);
MPoly *mpoly = BKE_mesh_polys_for_write(result);
MLoop *mloop = BKE_mesh_loops_for_write(result);
@ -351,13 +351,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* set vertices coordinates */
for (k = 0; k < totvert; k++) {
ParticleKey state;
const MVert *inMV;
int vindex = p_skip * totvert + k;
MVert *mv = mvert + vindex;
inMV = orig_mvert + k;
CustomData_copy_data(&mesh->vdata, &result->vdata, k, p_skip * totvert + k, 1);
*mv = *inMV;
CustomData_copy_data(&mesh->vdata, &result->vdata, k, vindex, 1);
if (vert_part_index != NULL) {
vert_part_index[vindex] = p;
@ -367,10 +363,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
/* Change orientation based on object trackflag. */
copy_v3_v3(temp_co, mv->co);
mv->co[axis] = temp_co[track];
mv->co[(axis + 1) % 3] = temp_co[(track + 1) % 3];
mv->co[(axis + 2) % 3] = temp_co[(track + 2) % 3];
copy_v3_v3(temp_co, positions[vindex]);
positions[vindex][axis] = temp_co[track];
positions[vindex][(axis + 1) % 3] = temp_co[(track + 1) % 3];
positions[vindex][(axis + 2) % 3] = temp_co[(track + 2) % 3];
/* get particle state */
if ((psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) &&
@ -384,13 +380,14 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
state.time = pimd->position * (1.0f - ran);
}
else {
state.time = (mv->co[axis] - min_co) / (max_co - min_co) * pimd->position * (1.0f - ran);
state.time = (positions[vindex][axis] - min_co) / (max_co - min_co) * pimd->position *
(1.0f - ran);
if (trackneg) {
state.time = 1.0f - state.time;
}
mv->co[axis] = 0.0;
positions[vindex][axis] = 0.0;
}
psys_get_particle_on_path(&sim, p, &state, 1);
@ -464,13 +461,13 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
psys_get_particle_state(&sim, p, &state, 1);
}
mul_qt_v3(state.rot, mv->co);
mul_qt_v3(state.rot, positions[vindex]);
if (pimd->flag & eParticleInstanceFlag_UseSize) {
mul_v3_fl(mv->co, size[p]);
mul_v3_fl(positions[vindex], size[p]);
}
add_v3_v3(mv->co, state.co);
add_v3_v3(positions[vindex], state.co);
mul_m4_v3(spacemat, mv->co);
mul_m4_v3(spacemat, positions[vindex]);
}
/* Create edges and adjust edge vertex indices. */

View File

@ -61,7 +61,7 @@ static void init_dualcon_mesh(DualConInput *input, Mesh *mesh)
memset(input, 0, sizeof(DualConInput));
input->co = (void *)BKE_mesh_positions(mesh);
input->co_stride = sizeof(MVert);
input->co_stride = sizeof(float[3]);
input->totco = mesh->totvert;
input->mloop = (void *)BKE_mesh_loops(mesh);
@ -80,7 +80,7 @@ static void init_dualcon_mesh(DualConInput *input, Mesh *mesh)
* keep track of the current elements */
typedef struct {
Mesh *mesh;
MVert *verts;
float (*positions)[3];
MPoly *polys;
MLoop *loops;
int curvert, curface;
@ -96,7 +96,7 @@ static void *dualcon_alloc_output(int totvert, int totquad)
}
output->mesh = BKE_mesh_new_nomain(totvert, 0, 0, 4 * totquad, totquad);
output->verts = BKE_mesh_positions_for_write(output->mesh);
output->positions = BKE_mesh_positions_for_write(output->mesh);
output->polys = BKE_mesh_polys_for_write(output->mesh);
output->loops = BKE_mesh_loops_for_write(output->mesh);
@ -109,7 +109,7 @@ static void dualcon_add_vert(void *output_v, const float co[3])
BLI_assert(output->curvert < output->mesh->totvert);
copy_v3_v3(output->verts[output->curvert].co, co);
copy_v3_v3(output->positions[output->curvert], co);
output->curvert++;
}

View File

@ -118,7 +118,7 @@ static void screwvert_iter_step(ScrewVertIter *iter)
}
static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
MVert *mvert_new,
float (*positions_new)[3],
const uint totvert,
const uint step_tot,
const float axis_vec[3],
@ -134,18 +134,18 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
float axis_co[3];
if (use_offset) {
float offset_co[3];
sub_v3_v3v3(offset_co, mvert_new[i].co, axis_offset);
sub_v3_v3v3(offset_co, positions_new[i], axis_offset);
project_v3_v3v3_normalized(axis_co, offset_co, axis_vec);
add_v3_v3(axis_co, axis_offset);
}
else {
project_v3_v3v3_normalized(axis_co, mvert_new[i].co, axis_vec);
project_v3_v3v3_normalized(axis_co, positions_new[i], axis_vec);
}
const float dist_sq = len_squared_v3v3(axis_co, mvert_new[i].co);
const float dist_sq = len_squared_v3v3(axis_co, positions_new[i]);
if (dist_sq <= merge_threshold_sq) {
BLI_BITMAP_ENABLE(vert_tag, i);
tot_doubles += 1;
copy_v3_v3(mvert_new[i].co, axis_co);
copy_v3_v3(positions_new[i], axis_co);
}
}
@ -244,8 +244,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
MPoly *mp_new;
MLoop *ml_new;
MEdge *med_new, *med_new_firstloop;
MVert *mv_new, *mv_new_base;
const MVert *mv_orig;
Object *ob_axis = ltmd->ob_axis;
ScrewVertConnect *vc, *vc_tmp, *vert_connect = NULL;
@ -388,12 +386,12 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
result = BKE_mesh_new_nomain_from_template(
mesh, (int)maxVerts, (int)maxEdges, 0, (int)maxPolys * 4, (int)maxPolys);
const MVert *mvert_orig = BKE_mesh_positions(mesh);
const float(*positions_orig)[3] = BKE_mesh_positions(mesh);
const MEdge *medge_orig = BKE_mesh_edges(mesh);
const MPoly *mpoly_orig = BKE_mesh_polys(mesh);
const MLoop *mloop_orig = BKE_mesh_loops(mesh);
MVert *mvert_new = BKE_mesh_positions_for_write(result);
float(*positions_new)[3] = BKE_mesh_positions_for_write(result);
MEdge *medge_new = BKE_mesh_edges_for_write(result);
MPoly *mpoly_new = BKE_mesh_polys_for_write(result);
MLoop *mloop_new = BKE_mesh_loops_for_write(result);
@ -418,8 +416,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
for (i = 0, mv_orig = mvert_orig; i < totvert; i++, mv_orig++) {
const float v = dist_signed_squared_to_plane_v3(mv_orig->co, uv_axis_plane);
for (i = 0; i < totvert; i++) {
const float v = dist_signed_squared_to_plane_v3(positions_orig[i], uv_axis_plane);
uv_v_minmax[0] = min_ff(v, uv_v_minmax[0]);
uv_v_minmax[1] = max_ff(v, uv_v_minmax[1]);
}
@ -433,8 +431,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* Set the locations of the first set of verts */
mv_new = mvert_new;
mv_orig = mvert_orig;
int vert_index_new = 0;
int vert_index_orig = 0;
BLI_bitmap *vert_tag = BLI_BITMAP_NEW(totvert, __func__);
@ -447,7 +445,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
med_new->crease = med_orig->crease;
med_new->flag = med_orig->flag & ~ME_LOOSEEDGE;
/* Tag #MVert as not loose. */
/* Tag vertex as not loose. */
BLI_BITMAP_ENABLE(vert_tag, med_orig->v1);
BLI_BITMAP_ENABLE(vert_tag, med_orig->v2);
}
@ -513,24 +511,23 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* Copy Vert Locations */
/* - We can do this in a later loop - only do here if no normal calc */
if (!totedge) {
for (i = 0; i < totvert; i++, mv_orig++, mv_new++) {
copy_v3_v3(mv_new->co, mv_orig->co);
for (i = 0; i < totvert; i++, vert_index_new++, vert_index_orig++) {
copy_v3_v3(positions_new[i], positions_orig[i]);
/* No edges: this is really a dummy normal. */
normalize_v3_v3(vc->no, mv_new->co);
normalize_v3_v3(vc->no, positions_new[i]);
}
}
else {
// printf("\n\n\n\n\nStarting Modifier\n");
/* set edge users */
med_new = medge_new;
mv_new = mvert_new;
if (ob_axis != NULL) {
/* `mtx_tx` is initialized early on. */
for (i = 0; i < totvert; i++, mv_new++, mv_orig++, vc++) {
vc->co[0] = mv_new->co[0] = mv_orig->co[0];
vc->co[1] = mv_new->co[1] = mv_orig->co[1];
vc->co[2] = mv_new->co[2] = mv_orig->co[2];
for (i = 0; i < totvert; i++, vc++) {
vc->co[0] = positions_new[i][0] = positions_orig[vert_index_orig][0];
vc->co[1] = positions_new[i][1] = positions_orig[vert_index_orig][1];
vc->co[2] = positions_new[i][2] = positions_orig[vert_index_orig][2];
vc->flag = 0;
vc->e[0] = vc->e[1] = NULL;
@ -545,10 +542,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
}
else {
for (i = 0; i < totvert; i++, mv_new++, mv_orig++, vc++) {
vc->co[0] = mv_new->co[0] = mv_orig->co[0];
vc->co[1] = mv_new->co[1] = mv_orig->co[1];
vc->co[2] = mv_new->co[2] = mv_orig->co[2];
for (i = 0; i < totvert; i++, vc++) {
vc->co[0] = positions_new[i][0] = positions_orig[i][0];
vc->co[1] = positions_new[i][1] = positions_orig[i][1];
vc->co[2] = positions_new[i][2] = positions_orig[i][2];
vc->flag = 0;
vc->e[0] = vc->e[1] = NULL;
@ -783,8 +780,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
if (SV_IS_VALID(vc->v[1])) {
/* 2 edges connected. */
/* make 2 connecting vert locations relative to the middle vert */
sub_v3_v3v3(tmp_vec1, mvert_new[vc->v[0]].co, mvert_new[i].co);
sub_v3_v3v3(tmp_vec2, mvert_new[vc->v[1]].co, mvert_new[i].co);
sub_v3_v3v3(tmp_vec1, positions_new[vc->v[0]], positions_new[i]);
sub_v3_v3v3(tmp_vec2, positions_new[vc->v[1]], positions_new[i]);
/* normalize so both edges have the same influence, no matter their length */
normalize_v3(tmp_vec1);
normalize_v3(tmp_vec2);
@ -804,10 +801,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* only 1 edge connected - same as above except
* don't need to average edge direction */
if (vc->e[0]->v2 == i) {
sub_v3_v3v3(tmp_vec1, mvert_new[i].co, mvert_new[vc->v[0]].co);
sub_v3_v3v3(tmp_vec1, positions_new[i], positions_new[vc->v[0]]);
}
else {
sub_v3_v3v3(tmp_vec1, mvert_new[vc->v[0]].co, mvert_new[i].co);
sub_v3_v3v3(tmp_vec1, positions_new[vc->v[0]], positions_new[i]);
}
}
@ -846,11 +843,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
}
else {
mv_orig = mvert_orig;
mv_new = mvert_new;
for (i = 0; i < totvert; i++, mv_new++, mv_orig++) {
copy_v3_v3(mv_new->co, mv_orig->co);
for (i = 0; i < totvert; i++) {
copy_v3_v3(positions_new[i], positions_orig[i]);
}
}
/* done with edge connectivity based normal flipping */
@ -878,33 +872,31 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* copy a slice */
CustomData_copy_data(&mesh->vdata, &result->vdata, 0, (int)varray_stride, (int)totvert);
mv_new_base = mvert_new;
mv_new = &mvert_new[varray_stride]; /* advance to the next slice */
for (j = 0; j < totvert; j++, mv_new_base++, mv_new++) {
for (j = 0; j < totvert; j++) {
const int vert_index_new = varray_stride + j;
/* set normal */
if (vert_connect) {
if (do_normal_create) {
/* Set the normal now its transformed. */
mul_v3_m3v3(vert_normals_new[mv_new - mvert_new], mat3, vert_connect[j].no);
mul_v3_m3v3(vert_normals_new[vert_index_new], mat3, vert_connect[j].no);
}
}
/* set location */
copy_v3_v3(mv_new->co, mv_new_base->co);
copy_v3_v3(positions_new[vert_index_new], positions_new[j]);
/* only need to set these if using non cleared memory */
// mv_new->mat_nr = mv_new->flag = 0;
if (ob_axis != NULL) {
sub_v3_v3(mv_new->co, mtx_tx[3]);
sub_v3_v3(positions_new[vert_index_new], mtx_tx[3]);
mul_m4_v3(mat, mv_new->co);
mul_m4_v3(mat, positions_new[vert_index_new]);
add_v3_v3(mv_new->co, mtx_tx[3]);
add_v3_v3(positions_new[vert_index_new], mtx_tx[3]);
}
else {
mul_m4_v3(mat, mv_new->co);
mul_m4_v3(mat, positions_new[vert_index_new]);
}
/* add the new edge */
@ -975,8 +967,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
if (has_mloop_orig == false && mloopuv_layers_tot) {
uv_v_offset_a = dist_signed_to_plane_v3(mvert_new[medge_new[i].v1].co, uv_axis_plane);
uv_v_offset_b = dist_signed_to_plane_v3(mvert_new[medge_new[i].v2].co, uv_axis_plane);
uv_v_offset_a = dist_signed_to_plane_v3(positions_new[medge_new[i].v1], uv_axis_plane);
uv_v_offset_b = dist_signed_to_plane_v3(positions_new[medge_new[i].v2], uv_axis_plane);
if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
uv_v_offset_a = (uv_v_offset_a - uv_v_minmax[0]) * uv_v_range_inv;
@ -1139,7 +1131,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
if (do_remove_doubles) {
result = mesh_remove_doubles_on_axis(result,
mvert_new,
positions_new,
totvert,
step_tot,
axis_vec,

View File

@ -132,12 +132,12 @@ typedef enum {
} SkinNodeFlag;
typedef struct Frame {
/* Index in the MVert array */
/* Index in the vertex array */
BMVert *verts[4];
/* Location of each corner */
float co[4][3];
/* Indicates which corners have been merged with another
* frame's corner (so they share an MVert index) */
* frame's corner (so they share a vertex index) */
struct {
/* Merge to target frame/corner (no merge if frame is null) */
struct Frame *frame;
@ -520,7 +520,7 @@ static float half_v2(const float v[2])
static void end_node_frames(int v,
SkinNode *skin_nodes,
const MVert *mvert,
const float (*positions)[3],
const MVertSkin *nodes,
const MeshElemMap *emap,
EMat *emat)
@ -540,8 +540,8 @@ static void end_node_frames(int v,
mat[0][2] = mat[1][0] = mat[2][1] = 1;
/* Caps */
create_frame(&skin_nodes[v].frames[0], mvert[v].co, rad, mat, avg);
create_frame(&skin_nodes[v].frames[1], mvert[v].co, rad, mat, -avg);
create_frame(&skin_nodes[v].frames[0], positions[v], rad, mat, avg);
create_frame(&skin_nodes[v].frames[1], positions[v], rad, mat, -avg);
}
else {
/* For nodes with an incoming edge, create a single (capped) frame */
@ -557,7 +557,7 @@ static void end_node_frames(int v,
Frame *frame = &skin_nodes[v].frames[0];
/* End frame */
create_frame(frame, mvert[v].co, rad, mat, 0);
create_frame(frame, positions[v], rad, mat, 0);
/* The caps might need to have their normals inverted. So check if they
* need to be flipped when creating faces. */
@ -605,7 +605,7 @@ static int connection_node_mat(float mat[3][3], int v, const MeshElemMap *emap,
static void connection_node_frames(int v,
SkinNode *skin_nodes,
const MVert *mvert,
const float (*positions)[3],
const MVertSkin *nodes,
const MeshElemMap *emap,
EMat *emat)
@ -630,14 +630,14 @@ static void connection_node_frames(int v,
if (e1->origin != v) {
negate_v3(mat[0]);
}
create_frame(&skin_nodes[v].frames[0], mvert[v].co, rad, mat, avg);
create_frame(&skin_nodes[v].frames[0], positions[v], rad, mat, avg);
skin_nodes[v].seam_edges[0] = emap[v].indices[0];
copy_m3_m3(mat, e2->mat);
if (e2->origin != v) {
negate_v3(mat[0]);
}
create_frame(&skin_nodes[v].frames[1], mvert[v].co, rad, mat, avg);
create_frame(&skin_nodes[v].frames[1], positions[v], rad, mat, avg);
skin_nodes[v].seam_edges[1] = emap[v].indices[1];
return;
@ -645,11 +645,14 @@ static void connection_node_frames(int v,
/* Build regular frame */
node_frames_init(&skin_nodes[v], 1);
create_frame(&skin_nodes[v].frames[0], mvert[v].co, rad, mat, 0);
create_frame(&skin_nodes[v].frames[0], positions[v], rad, mat, 0);
}
static SkinNode *build_frames(
const MVert *mvert, int verts_num, const MVertSkin *nodes, const MeshElemMap *emap, EMat *emat)
static SkinNode *build_frames(const float (*positions)[3],
int verts_num,
const MVertSkin *nodes,
const MeshElemMap *emap,
EMat *emat)
{
SkinNode *skin_nodes;
int v;
@ -658,10 +661,10 @@ static SkinNode *build_frames(
for (v = 0; v < verts_num; v++) {
if (emap[v].count <= 1) {
end_node_frames(v, skin_nodes, mvert, nodes, emap, emat);
end_node_frames(v, skin_nodes, positions, nodes, emap, emat);
}
else if (emap[v].count == 2) {
connection_node_frames(v, skin_nodes, mvert, nodes, emap, emat);
connection_node_frames(v, skin_nodes, positions, nodes, emap, emat);
}
else {
/* Branch node generates no frames */
@ -714,7 +717,7 @@ static void build_emats_stack(BLI_Stack *stack,
const MeshElemMap *emap,
const MEdge *medge,
const MVertSkin *vs,
const MVert *mvert)
const float (*positions)[3])
{
EdgeStackElem stack_elem;
float axis[3], angle;
@ -741,11 +744,11 @@ static void build_emats_stack(BLI_Stack *stack,
/* If parent is a branch node, start a new edge chain */
if (parent_is_branch) {
calc_edge_mat(emat[e].mat, mvert[parent_v].co, mvert[v].co);
calc_edge_mat(emat[e].mat, positions[parent_v], positions[v]);
}
else {
/* Build edge matrix guided by parent matrix */
sub_v3_v3v3(emat[e].mat[0], mvert[v].co, mvert[parent_v].co);
sub_v3_v3v3(emat[e].mat[0], positions[v], positions[parent_v]);
normalize_v3(emat[e].mat[0]);
angle = angle_normalized_v3v3(stack_elem.mat[0], emat[e].mat[0]);
cross_v3_v3v3(axis, stack_elem.mat[0], emat[e].mat[0]);
@ -765,7 +768,7 @@ static void build_emats_stack(BLI_Stack *stack,
}
static EMat *build_edge_mats(const MVertSkin *vs,
const MVert *mvert,
const float (*positions)[3],
const int verts_num,
const MEdge *medge,
const MeshElemMap *emap,
@ -789,7 +792,7 @@ static EMat *build_edge_mats(const MVertSkin *vs,
if (vs[v].flag & MVERT_SKIN_ROOT) {
if (emap[v].count >= 1) {
const MEdge *e = &medge[emap[v].indices[0]];
calc_edge_mat(stack_elem.mat, mvert[v].co, mvert[BKE_mesh_edge_other_vert(e, v)].co);
calc_edge_mat(stack_elem.mat, positions[v], positions[BKE_mesh_edge_other_vert(e, v)]);
stack_elem.parent_v = v;
/* Add adjacent edges to stack */
@ -809,7 +812,7 @@ static EMat *build_edge_mats(const MVertSkin *vs,
}
while (!BLI_stack_is_empty(stack)) {
build_emats_stack(stack, visited_e, emat, emap, medge, vs, mvert);
build_emats_stack(stack, visited_e, emat, emap, medge, vs, positions);
}
MEM_freeN(visited_e);
@ -825,7 +828,7 @@ static EMat *build_edge_mats(const MVertSkin *vs,
* nodes, at least two intermediate frames are required. (This avoids
* having any special cases for dealing with sharing a frame between
* two hulls.) */
static int calc_edge_subdivisions(const MVert *mvert,
static int calc_edge_subdivisions(const float (*positions)[3],
const MVertSkin *nodes,
const MEdge *e,
const int *degree)
@ -855,7 +858,7 @@ static int calc_edge_subdivisions(const MVert *mvert,
if (avg_radius != 0.0f) {
/* possible (but unlikely) that we overflow INT_MAX */
float subdivisions_num_fl;
const float edge_len = len_v3v3(mvert[e->v1].co, mvert[e->v2].co);
const float edge_len = len_v3v3(positions[e->v1], positions[e->v2]);
subdivisions_num_fl = (edge_len / avg_radius);
if (subdivisions_num_fl < NUM_SUBDIVISIONS_MAX) {
subdivisions_num = (int)subdivisions_num_fl;
@ -889,7 +892,7 @@ static Mesh *subdivide_base(const Mesh *orig)
float radrat;
const MVertSkin *orignode = CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN);
const MVert *origvert = BKE_mesh_positions(orig);
const float(*orig_positions)[3] = BKE_mesh_positions(orig);
const MEdge *origedge = BKE_mesh_edges(orig);
const MDeformVert *origdvert = BKE_mesh_deform_verts(orig);
int orig_vert_num = orig->totvert;
@ -905,7 +908,7 @@ static Mesh *subdivide_base(const Mesh *orig)
/* Per edge, store how many subdivisions are needed */
int *edge_subd = MEM_calloc_arrayN((uint)orig_edge_num, sizeof(int), "edge_subd");
for (i = 0, subd_num = 0; i < orig_edge_num; i++) {
edge_subd[i] += calc_edge_subdivisions(origvert, orignode, &origedge[i], degree);
edge_subd[i] += calc_edge_subdivisions(orig_positions, orignode, &origedge[i], degree);
BLI_assert(edge_subd[i] >= 0);
subd_num += edge_subd[i];
}
@ -916,7 +919,7 @@ static Mesh *subdivide_base(const Mesh *orig)
Mesh *result = BKE_mesh_new_nomain_from_template(
orig, orig_vert_num + subd_num, orig_edge_num + subd_num, 0, 0, 0);
MVert *outvert = BKE_mesh_positions_for_write(result);
float(*out_positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *outedge = BKE_mesh_edges_for_write(result);
MVertSkin *outnode = CustomData_get_layer(&result->vdata, CD_MVERT_SKIN);
MDeformVert *outdvert = NULL;
@ -978,7 +981,7 @@ static Mesh *subdivide_base(const Mesh *orig)
float t = powf(r, radrat);
/* Interpolate vertex coord */
interp_v3_v3v3(outvert[v].co, outvert[e->v1].co, outvert[e->v2].co, t);
interp_v3_v3v3(out_positions[v], out_positions[e->v1], out_positions[e->v2], t);
/* Interpolate skin radii */
interp_v3_v3v3(outnode[v].radius, orignode[e->v1].radius, orignode[e->v2].radius, t);
@ -1910,7 +1913,6 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
SkinNode *skin_nodes;
MeshElemMap *emap;
int *emapmem;
const MVert *mvert;
const MEdge *medge;
const MDeformVert *dvert;
int verts_num, edges_num;
@ -1918,7 +1920,7 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
nodes = CustomData_get_layer(&origmesh->vdata, CD_MVERT_SKIN);
mvert = BKE_mesh_positions(origmesh);
const float(*positions)[3] = BKE_mesh_positions(origmesh);
dvert = BKE_mesh_deform_verts(origmesh);
medge = BKE_mesh_edges(origmesh);
verts_num = origmesh->totvert;
@ -1926,8 +1928,8 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
BKE_mesh_vert_edge_map_create(&emap, &emapmem, medge, verts_num, edges_num);
emat = build_edge_mats(nodes, mvert, verts_num, medge, emap, edges_num, &has_valid_root);
skin_nodes = build_frames(mvert, verts_num, nodes, emap, emat);
emat = build_edge_mats(nodes, positions, verts_num, medge, emap, edges_num, &has_valid_root);
skin_nodes = build_frames(positions, verts_num, nodes, emap, emat);
MEM_freeN(emat);
emat = NULL;

View File

@ -215,7 +215,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
MOD_get_vgroup(ctx->object, mesh, smd->defgrp_name, &dvert, &defgrp_index);
const MVert *orig_mvert = BKE_mesh_positions(mesh);
const const float(*orig_positions)[3] = BKE_mesh_positions(mesh);
const MEdge *orig_medge = BKE_mesh_edges(mesh);
const MPoly *orig_mpoly = BKE_mesh_polys(mesh);
const MLoop *orig_mloop = BKE_mesh_loops(mesh);
@ -335,7 +335,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
(int)((loops_num * stride) + newLoops),
(int)((polys_num * stride) + newPolys));
MVert *mvert = BKE_mesh_positions_for_write(result);
float(*positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *medge = BKE_mesh_edges_for_write(result);
MPoly *mpoly = BKE_mesh_polys_for_write(result);
MLoop *mloop = BKE_mesh_loops_for_write(result);
@ -398,7 +398,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
if (((ofs_new >= ofs_orig) == do_flip) == test) { \
i_end = verts_num; \
do_shell_align = true; \
mv = mvert; \
vert_index = 0; \
} \
else { \
if (do_shell) { \
@ -409,7 +409,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
i_end = newVerts; \
do_shell_align = false; \
} \
mv = &mvert[verts_num]; \
vert_index = verts_num; \
} \
(void)0
@ -495,7 +495,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
vert_lens = MEM_malloc_arrayN(verts_num, sizeof(float), "vert_lens");
copy_vn_fl(vert_lens, (int)verts_num, FLT_MAX);
for (uint i = 0; i < edges_num; i++) {
const float ed_len_sq = len_squared_v3v3(mvert[medge[i].v1].co, mvert[medge[i].v2].co);
const float ed_len_sq = len_squared_v3v3(positions[medge[i].v1], positions[medge[i].v2]);
vert_lens[medge[i].v1] = min_ff(vert_lens[medge[i].v1], ed_len_sq);
vert_lens[medge[i].v2] = min_ff(vert_lens[medge[i].v2], ed_len_sq);
}
@ -547,7 +547,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
!ELEM(edge_user_pairs[i][1], INVALID_UNUSED, INVALID_PAIR)) {
const float *n0 = poly_nors[edge_user_pairs[i][0]];
const float *n1 = poly_nors[edge_user_pairs[i][1]];
sub_v3_v3v3(e, orig_mvert[ed->v1].co, orig_mvert[ed->v2].co);
sub_v3_v3v3(e, orig_positions[ed->v1], orig_positions[ed->v2]);
normalize_v3(e);
const float angle = angle_signed_on_axis_v3v3_v3(n0, n1, e);
if (do_angle_clamp) {
@ -571,10 +571,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
ofs_new_vgroup = ofs_new;
MVert *mv;
int vert_index;
INIT_VERT_ARRAY_OFFSETS(false);
for (i_orig = 0; i_orig < i_end; i_orig++, mv++) {
for (i_orig = 0; i_orig < i_end; i_orig++, vert_index++) {
const uint i = do_shell_align ? i_orig : new_vert_arr[i_orig];
if (dvert) {
const MDeformVert *dv = &dvert[i];
@ -608,10 +608,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
}
}
if (vert_nors) {
madd_v3_v3fl(mv->co, vert_nors[i], ofs_new_vgroup);
madd_v3_v3fl(positions[vert_index], vert_nors[i], ofs_new_vgroup);
}
else {
madd_v3_v3fl(mv->co, mesh_vert_normals[i], ofs_new_vgroup);
madd_v3_v3fl(positions[vert_index], mesh_vert_normals[i], ofs_new_vgroup);
}
}
}
@ -623,10 +623,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
ofs_new_vgroup = ofs_orig;
/* as above but swapped */
MVert *mv;
int vert_index;
INIT_VERT_ARRAY_OFFSETS(true);
for (i_orig = 0; i_orig < i_end; i_orig++, mv++) {
for (i_orig = 0; i_orig < i_end; i_orig++, vert_index++) {
const uint i = do_shell_align ? i_orig : new_vert_arr[i_orig];
if (dvert) {
const MDeformVert *dv = &dvert[i];
@ -660,10 +660,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
}
}
if (vert_nors) {
madd_v3_v3fl(mv->co, vert_nors[i], ofs_new_vgroup);
madd_v3_v3fl(positions[vert_index], vert_nors[i], ofs_new_vgroup);
}
else {
madd_v3_v3fl(mv->co, mesh_vert_normals[i], ofs_new_vgroup);
madd_v3_v3fl(positions[vert_index], mesh_vert_normals[i], ofs_new_vgroup);
}
}
}
@ -713,8 +713,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
if (vert_nors == NULL) {
vert_nors = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "mod_solid_vno");
const MVert *mv;
for (i = 0, mv = mvert; i < verts_num; i++, mv++) {
for (i = 0; i < verts_num; i++) {
copy_v3_v3(vert_nors[i], mesh_vert_normals[i]);
}
}
@ -730,12 +729,12 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
const MLoop *ml = &mloop[mp->loopstart];
sub_v3_v3v3(nor_prev, mvert[ml[i_curr - 1].v].co, mvert[ml[i_curr].v].co);
sub_v3_v3v3(nor_prev, positions[ml[i_curr - 1].v], positions[ml[i_curr].v]);
normalize_v3(nor_prev);
while (i_next < mp->totloop) {
float angle;
sub_v3_v3v3(nor_next, mvert[ml[i_curr].v].co, mvert[ml[i_next].v].co);
sub_v3_v3v3(nor_next, positions[ml[i_curr].v], positions[ml[i_next].v]);
normalize_v3(nor_next);
angle = angle_normalized_v3v3(nor_prev, nor_next);
@ -847,7 +846,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
vert_angs[ed->v2] = max_ff(vert_angs[ed->v2], angle);
}
if (do_bevel_convex) {
sub_v3_v3v3(e, orig_mvert[ed->v1].co, orig_mvert[ed->v2].co);
sub_v3_v3v3(e, orig_positions[ed->v1], orig_positions[ed->v2]);
normalize_v3(e);
edge_angs[i] = angle_signed_on_axis_v3v3_v3(n0, n1, e);
if (!do_rim) {
@ -867,7 +866,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
const float offset_sq = offset * offset;
copy_vn_fl(vert_lens_sq, (int)verts_num, FLT_MAX);
for (i = 0; i < edges_num; i++) {
const float ed_len = len_squared_v3v3(mvert[medge[i].v1].co, mvert[medge[i].v2].co);
const float ed_len = len_squared_v3v3(positions[medge[i].v1], positions[medge[i].v2]);
vert_lens_sq[medge[i].v1] = min_ff(vert_lens_sq[medge[i].v1], ed_len);
vert_lens_sq[medge[i].v2] = min_ff(vert_lens_sq[medge[i].v2], ed_len);
}
@ -926,14 +925,15 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
uint i_orig, i_end;
bool do_shell_align;
MVert *mv;
int vert_index;
INIT_VERT_ARRAY_OFFSETS(false);
for (i_orig = 0; i_orig < i_end; i_orig++, mv++) {
for (i_orig = 0; i_orig < i_end; i_orig++, vert_index++) {
const uint i_other = do_shell_align ? i_orig : new_vert_arr[i_orig];
if (vert_accum[i_other]) { /* zero if unselected */
madd_v3_v3fl(
mv->co, vert_nors[i_other], ofs_new * (vert_angles[i_other] / vert_accum[i_other]));
madd_v3_v3fl(positions[vert_index],
vert_nors[i_other],
ofs_new * (vert_angles[i_other] / vert_accum[i_other]));
}
}
}
@ -943,14 +943,15 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
bool do_shell_align;
/* same as above but swapped, intentional use of 'ofs_new' */
MVert *mv;
int vert_index;
INIT_VERT_ARRAY_OFFSETS(true);
for (i_orig = 0; i_orig < i_end; i_orig++, mv++) {
for (i_orig = 0; i_orig < i_end; i_orig++, vert_index++) {
const uint i_other = do_shell_align ? i_orig : new_vert_arr[i_orig];
if (vert_accum[i_other]) { /* zero if unselected */
madd_v3_v3fl(
mv->co, vert_nors[i_other], ofs_orig * (vert_angles[i_other] / vert_accum[i_other]));
madd_v3_v3fl(positions[vert_index],
vert_nors[i_other],
ofs_orig * (vert_angles[i_other] / vert_accum[i_other]));
}
}
}
@ -1155,10 +1156,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
#ifdef SOLIDIFY_SIDE_NORMALS
if (do_side_normals) {
normal_quad_v3(nor,
mvert[ml[j - 4].v].co,
mvert[ml[j - 3].v].co,
mvert[ml[j - 2].v].co,
mvert[ml[j - 1].v].co);
positions[ml[j - 4].v],
positions[ml[j - 3].v],
positions[ml[j - 2].v],
positions[ml[j - 1].v]);
add_v3_v3(edge_vert_nos[ed->v1], nor);
add_v3_v3(edge_vert_nos[ed->v2], nor);

View File

@ -184,7 +184,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
const bool do_flat_faces = dvert && (smd->flag & MOD_SOLIDIFY_NONMANIFOLD_FLAT_FACES);
const MVert *orig_mvert = BKE_mesh_positions(mesh);
const float(*orig_positions)[3] = BKE_mesh_positions(mesh);
const MEdge *orig_medge = BKE_mesh_edges(mesh);
const MPoly *orig_mpoly = BKE_mesh_polys(mesh);
const MLoop *orig_mloop = BKE_mesh_loops(mesh);
@ -219,7 +219,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
if (len_squared_v3(poly_nors[i]) < 0.5f) {
const MEdge *e = orig_medge + orig_mloop[mp->loopstart].e;
float edgedir[3];
sub_v3_v3v3(edgedir, orig_mvert[e->v2].co, orig_mvert[e->v1].co);
sub_v3_v3v3(edgedir, orig_positions[e->v2], orig_positions[e->v1]);
if (fabsf(edgedir[2]) < fabsf(edgedir[1])) {
poly_nors[i][2] = 1.0f;
}
@ -292,9 +292,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
verts_num, sizeof(*orig_mvert_co), "orig_mvert_co in solidify");
/* Fill in the original vertex positions. */
for (uint i = 0; i < verts_num; i++) {
orig_mvert_co[i][0] = orig_mvert[i].co[0];
orig_mvert_co[i][1] = orig_mvert[i].co[1];
orig_mvert_co[i][2] = orig_mvert[i].co[2];
orig_mvert_co[i][0] = orig_positions[i][0];
orig_mvert_co[i][1] = orig_positions[i][1];
orig_mvert_co[i][2] = orig_positions[i][2];
}
/* Create edge to #NewEdgeRef map. */
@ -1397,9 +1397,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
}
}
const MVert *mv = orig_mvert;
gs_ptr = orig_vert_groups_arr;
for (uint i = 0; i < verts_num; i++, mv++, gs_ptr++) {
for (uint i = 0; i < verts_num; i++, gs_ptr++) {
if (*gs_ptr) {
EdgeGroup *g = *gs_ptr;
for (uint j = 0; g->valid; j++, g++) {
@ -1961,7 +1960,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
(int)(new_loops_num),
(int)(new_polys_num));
MVert *mvert = BKE_mesh_positions_for_write(result);
float(*positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *medge = BKE_mesh_edges_for_write(result);
MPoly *mpoly = BKE_mesh_polys_for_write(result);
MLoop *mloop = BKE_mesh_loops_for_write(result);
@ -2003,7 +2002,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
for (uint j = 0; g->valid; j++, g++) {
if (g->new_vert != MOD_SOLIDIFY_EMPTY_TAG) {
CustomData_copy_data(&mesh->vdata, &result->vdata, (int)i, (int)g->new_vert, 1);
copy_v3_v3(mvert[g->new_vert].co, g->co);
copy_v3_v3(positions[g->new_vert], g->co);
}
}
}
@ -2109,8 +2108,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
/* Make boundary edges/faces. */
{
gs_ptr = orig_vert_groups_arr;
const MVert *mv = orig_mvert;
for (uint i = 0; i < verts_num; i++, gs_ptr++, mv++) {
for (uint i = 0; i < verts_num; i++, gs_ptr++) {
EdgeGroup *gs = *gs_ptr;
if (gs) {
EdgeGroup *g = gs;

View File

@ -125,7 +125,6 @@ static void deformVerts(ModifierData *md,
if (surmd->mesh) {
uint mesh_verts_num = 0, i = 0;
int init = 0;
MVert *x, *v;
BKE_mesh_vert_coords_apply(surmd->mesh, vertexCos);
@ -142,8 +141,8 @@ static void deformVerts(ModifierData *md,
surmd->v = NULL;
}
surmd->x = MEM_calloc_arrayN(mesh_verts_num, sizeof(MVert), "MVert");
surmd->v = MEM_calloc_arrayN(mesh_verts_num, sizeof(MVert), "MVert");
surmd->x = MEM_calloc_arrayN(mesh_verts_num, sizeof(float[3]), __func__);
surmd->v = MEM_calloc_arrayN(mesh_verts_num, sizeof(float[3]), __func__);
surmd->verts_num = mesh_verts_num;
@ -151,19 +150,19 @@ static void deformVerts(ModifierData *md,
}
/* convert to global coordinates and calculate velocity */
MVert *verts = BKE_mesh_positions_for_write(surmd->mesh);
for (i = 0, x = surmd->x, v = surmd->v; i < mesh_verts_num; i++, x++, v++) {
float *vec = verts[i].co;
float(*positions)[3] = BKE_mesh_positions_for_write(surmd->mesh);
for (i = 0; i < mesh_verts_num; i++) {
float *vec = positions[i];
mul_m4_v3(ctx->object->obmat, vec);
if (init) {
v->co[0] = v->co[1] = v->co[2] = 0.0f;
surmd->v[i][0] = surmd->v[i][1] = surmd->v[i][2] = 0.0f;
}
else {
sub_v3_v3v3(v->co, vec, x->co);
sub_v3_v3v3(surmd->v[i], vec, surmd->x[i]);
}
copy_v3_v3(x->co, vec);
copy_v3_v3(surmd->x[i], vec);
}
surmd->cfra = cfra;

View File

@ -1171,7 +1171,7 @@ static bool surfacedeformBind(Object *ob,
Mesh *mesh)
{
BVHTreeFromMesh treeData = {NULL};
const MVert *mvert = BKE_mesh_positions(target);
const float(*positions)[3] = BKE_mesh_positions(target);
const MPoly *mpoly = BKE_mesh_polys(target);
const MEdge *medge = BKE_mesh_edges(target);
const MLoop *mloop = BKE_mesh_loops(target);
@ -1270,7 +1270,7 @@ static bool surfacedeformBind(Object *ob,
invert_m4_m4(data.imat, smd_orig->mat);
for (int i = 0; i < target_verts_num; i++) {
mul_v3_m4v3(data.targetCos[i], smd_orig->mat, mvert[i].co);
mul_v3_m4v3(data.targetCos[i], smd_orig->mat, positions[i]);
}
TaskParallelSettings settings;

View File

@ -130,17 +130,17 @@ void MOD_get_texture_coords(MappingInfoModifierData *dmd,
texmapping = MOD_DISP_MAP_LOCAL;
}
const MVert *mv = BKE_mesh_positions(mesh);
for (i = 0; i < verts_num; i++, mv++, r_texco++) {
const float(*positions)[3] = BKE_mesh_positions(mesh);
for (i = 0; i < verts_num; i++, r_texco++) {
switch (texmapping) {
case MOD_DISP_MAP_LOCAL:
copy_v3_v3(*r_texco, cos != NULL ? *cos : mv->co);
copy_v3_v3(*r_texco, cos != NULL ? *cos : positions[i]);
break;
case MOD_DISP_MAP_GLOBAL:
mul_v3_m4v3(*r_texco, ob->obmat, cos != NULL ? *cos : mv->co);
mul_v3_m4v3(*r_texco, ob->obmat, cos != NULL ? *cos : positions[i]);
break;
case MOD_DISP_MAP_OBJECT:
mul_v3_m4v3(*r_texco, ob->obmat, cos != NULL ? *cos : mv->co);
mul_v3_m4v3(*r_texco, ob->obmat, cos != NULL ? *cos : positions[i]);
mul_m4_v3(mapref_imat, *r_texco);
break;
}

View File

@ -71,7 +71,7 @@ typedef struct WeightedNormalData {
const int loops_num;
const int polys_num;
const MVert *mvert;
const float (*positions)[3];
const float (*vert_normals)[3];
MEdge *medge;
@ -186,7 +186,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
const int loops_num = wn_data->loops_num;
const int polys_num = wn_data->polys_num;
const MVert *mvert = wn_data->mvert;
const float(*positions)[3] = wn_data->positions;
MEdge *medge = wn_data->medge;
const MLoop *mloop = wn_data->mloop;
@ -221,7 +221,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
/* This will give us loop normal spaces,
* we do not actually care about computed loop_normals for now... */
loop_normals = MEM_calloc_arrayN((size_t)loops_num, sizeof(*loop_normals), __func__);
BKE_mesh_normals_loop_split(mvert,
BKE_mesh_normals_loop_split(positions,
wn_data->vert_normals,
verts_num,
medge,
@ -348,7 +348,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
}
}
BKE_mesh_normals_loop_custom_set(mvert,
BKE_mesh_normals_loop_custom_set(positions,
wn_data->vert_normals,
verts_num,
medge,
@ -379,7 +379,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
copy_v3_v3(vert_normals[mv_index], items_data[mv_index].normal);
}
BKE_mesh_normals_loop_custom_from_verts_set(mvert,
BKE_mesh_normals_loop_custom_from_verts_set(positions,
wn_data->vert_normals,
vert_normals,
verts_num,
@ -397,7 +397,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
else {
loop_normals = MEM_calloc_arrayN((size_t)loops_num, sizeof(*loop_normals), __func__);
BKE_mesh_normals_loop_split(mvert,
BKE_mesh_normals_loop_split(positions,
wn_data->vert_normals,
verts_num,
medge,
@ -421,7 +421,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
}
}
BKE_mesh_normals_loop_custom_set(mvert,
BKE_mesh_normals_loop_custom_set(positions,
wn_data->vert_normals,
verts_num,
medge,
@ -446,7 +446,7 @@ static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *w
{
const int polys_num = wn_data->polys_num;
const MVert *mvert = wn_data->mvert;
const float(*positions)[3] = wn_data->positions;
const MLoop *mloop = wn_data->mloop;
const MPoly *mpoly = wn_data->mpoly;
@ -457,7 +457,7 @@ static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *w
ModePair *f_area = face_area;
for (mp_index = 0, mp = mpoly; mp_index < polys_num; mp_index++, mp++, f_area++) {
f_area->val = BKE_mesh_calc_poly_area(mp, &mloop[mp->loopstart], mvert);
f_area->val = BKE_mesh_calc_poly_area(mp, &mloop[mp->loopstart], positions);
f_area->index = mp_index;
}
@ -472,7 +472,7 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData
const int loops_num = wn_data->loops_num;
const int polys_num = wn_data->polys_num;
const MVert *mvert = wn_data->mvert;
const float(*positions)[3] = wn_data->positions;
const MLoop *mloop = wn_data->mloop;
const MPoly *mpoly = wn_data->mpoly;
@ -487,7 +487,7 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData
const MLoop *ml_start = &mloop[mp->loopstart];
float *index_angle = MEM_malloc_arrayN((size_t)mp->totloop, sizeof(*index_angle), __func__);
BKE_mesh_calc_poly_angles(mp, ml_start, mvert, index_angle);
BKE_mesh_calc_poly_angles(mp, ml_start, positions, index_angle);
ModePair *c_angl = &corner_angle[mp->loopstart];
float *angl = index_angle;
@ -513,7 +513,7 @@ static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalD
const int loops_num = wn_data->loops_num;
const int polys_num = wn_data->polys_num;
const MVert *mvert = wn_data->mvert;
const float(*positions)[3] = wn_data->positions;
const MLoop *mloop = wn_data->mloop;
const MPoly *mpoly = wn_data->mpoly;
@ -527,9 +527,9 @@ static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalD
for (mp_index = 0, mp = mpoly; mp_index < polys_num; mp_index++, mp++) {
const MLoop *ml_start = &mloop[mp->loopstart];
float face_area = BKE_mesh_calc_poly_area(mp, ml_start, mvert);
float face_area = BKE_mesh_calc_poly_area(mp, ml_start, positions);
float *index_angle = MEM_malloc_arrayN((size_t)mp->totloop, sizeof(*index_angle), __func__);
BKE_mesh_calc_poly_angles(mp, ml_start, mvert, index_angle);
BKE_mesh_calc_poly_angles(mp, ml_start, positions, index_angle);
ModePair *cmbnd = &combined[mp->loopstart];
float *angl = index_angle;
@ -579,7 +579,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
const int edges_num = result->totedge;
const int loops_num = result->totloop;
const int polys_num = result->totpoly;
const MVert *mvert = BKE_mesh_positions(result);
const float(*positions)[3] = BKE_mesh_positions(result);
MEdge *medge = BKE_mesh_edges_for_write(result);
const MPoly *mpoly = BKE_mesh_polys(result);
const MLoop *mloop = BKE_mesh_loops(result);
@ -622,7 +622,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
.loops_num = loops_num,
.polys_num = polys_num,
.mvert = mvert,
.positions = positions,
.vert_normals = BKE_mesh_vertex_normals_ensure(result),
.medge = medge,

View File

@ -140,7 +140,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
/* Use new generic get_texture_coords, but do not modify our DNA struct for it...
* XXX Why use a ModifierData stuff here ? Why not a simple, generic struct for parameters?
* What e.g. if a modifier wants to use several textures?
* Why use only v_co, and not MVert (or both)?
* Why use only v_co, and not mesh positions (or both)?
*/
t_map.texture = texture;
t_map.map_object = tex_map_object;

View File

@ -46,7 +46,7 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
}
/* Copy vertices. */
MutableSpan<MVert> dst_verts = result->positions_for_write();
MutableSpan<float3> dst_positions = result->positions_for_write();
for (const int i : IndexRange(verts_num)) {
float co[3];
int original_index;
@ -60,7 +60,7 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
}
# endif
/* Copy the position of the original point. */
copy_v3_v3(dst_verts[i].co, co);
dst_positions[i] =, co;
}
else {
BLI_assert_msg(0, "Unexpected new vertex in hull output");

View File

@ -922,7 +922,7 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
mesh_in.attributes(),
mesh_out->attributes_for_write());
MutableSpan<MVert> dst_verts = mesh_out->positions_for_write();
mesh_out->positions_for_write().copy_from(vertex_positions);
MutableSpan<MEdge> dst_edges = mesh_out->edges_for_write();
MutableSpan<MPoly> dst_polys = mesh_out->polys_for_write();
MutableSpan<MLoop> dst_loops = mesh_out->loops_for_write();
@ -937,9 +937,6 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
dst_loops[i].v = loops[i];
dst_loops[i].e = loop_edges[i];
}
for (const int i : IndexRange(mesh_out->totvert)) {
copy_v3_v3(dst_verts[i].co, vertex_positions[i]);
}
dst_edges.copy_from(new_edges);
geometry_set.replace_mesh(mesh_out);
}

View File

@ -522,7 +522,6 @@ static void duplicate_faces(GeometrySet &geometry_set,
geometry_set.keep_only_during_modify({GEO_COMPONENT_TYPE_MESH});
const Mesh &mesh = *geometry_set.get_mesh_for_read();
const Span<MVert> verts = mesh.positions();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@ -547,7 +546,6 @@ static void duplicate_faces(GeometrySet &geometry_set,
offsets[selection.size()] = total_polys;
Mesh *new_mesh = BKE_mesh_new_nomain(total_loops, total_loops, 0, total_loops, total_polys);
MutableSpan<MVert> new_verts = new_mesh->positions_for_write();
MutableSpan<MEdge> new_edges = new_mesh->edges_for_write();
MutableSpan<MPoly> new_polys = new_mesh->polys_for_write();
MutableSpan<MLoop> new_loops = new_mesh->loops_for_write();
@ -568,7 +566,6 @@ static void duplicate_faces(GeometrySet &geometry_set,
for (const int i_loops : IndexRange(source.totloop)) {
const MLoop &current_loop = loops[source.loopstart + i_loops];
loop_mapping[loop_index] = source.loopstart + i_loops;
new_verts[loop_index] = verts[current_loop.v];
vert_mapping[loop_index] = current_loop.v;
new_edges[loop_index] = edges[current_loop.e];
edge_mapping[loop_index] = current_loop.e;
@ -894,10 +891,9 @@ static void duplicate_points_mesh(GeometrySet &geometry_set,
const IndexAttributes &attribute_outputs)
{
const Mesh &mesh = *geometry_set.get_mesh_for_read();
const Span<MVert> src_verts = mesh.positions();
bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_POINT};
FieldEvaluator evaluator{field_context, src_verts.size()};
FieldEvaluator evaluator{field_context, mesh.totvert};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
evaluator.evaluate();
@ -907,9 +903,6 @@ static void duplicate_points_mesh(GeometrySet &geometry_set,
Array<int> offsets = accumulate_counts_to_offsets(selection, counts);
Mesh *new_mesh = BKE_mesh_new_nomain(offsets.last(), 0, 0, 0, 0);
MutableSpan<MVert> dst_verts = new_mesh->positions_for_write();
threaded_slice_fill(offsets.as_span(), selection, src_verts, dst_verts);
copy_attributes_without_id(geometry_set,
GEO_COMPONENT_TYPE_MESH,

View File

@ -243,7 +243,7 @@ static void extrude_mesh_vertices(Mesh &mesh,
const IndexRange new_vert_range{orig_vert_size, selection.size()};
const IndexRange new_edge_range{orig_edge_size, selection.size()};
MutableSpan<MVert> new_verts = mesh.positions_for_write().slice(new_vert_range);
MutableSpan<float3> new_positions = mesh.positions_for_write().slice(new_vert_range);
MutableSpan<MEdge> new_edges = mesh.edges_for_write().slice(new_edge_range);
for (const int i_selection : selection.index_range()) {
@ -286,9 +286,7 @@ static void extrude_mesh_vertices(Mesh &mesh,
devirtualize_varray(offsets, [&](const auto offsets) {
threading::parallel_for(selection.index_range(), 1024, [&](const IndexRange range) {
for (const int i : range) {
const float3 offset = offsets[selection[i]];
add_v3_v3(new_verts[i].co, offset);
new_verts[i].flag = 0;
new_positions[i] += offsets[selection[i]];
}
});
});
@ -605,21 +603,19 @@ static void extrude_mesh_edges(Mesh &mesh,
return true;
});
MutableSpan<MVert> new_verts = mesh.positions_for_write().slice(new_vert_range);
MutableSpan<float3> new_positions = mesh.positions_for_write().slice(new_vert_range);
if (edge_offsets.is_single()) {
const float3 offset = edge_offsets.get_internal_single();
threading::parallel_for(new_verts.index_range(), 1024, [&](const IndexRange range) {
threading::parallel_for(new_positions.index_range(), 1024, [&](const IndexRange range) {
for (const int i : range) {
add_v3_v3(new_verts[i].co, offset);
new_verts[i].flag = 0;
new_positions[i] += offset;
}
});
}
else {
threading::parallel_for(new_verts.index_range(), 1024, [&](const IndexRange range) {
threading::parallel_for(new_positions.index_range(), 1024, [&](const IndexRange range) {
for (const int i : range) {
add_v3_v3(new_verts[i].co, vert_offsets[new_vert_indices[i]]);
new_verts[i].flag = 0;
new_positions[i] += vert_offsets[new_vert_indices[i]];
}
});
}
@ -977,15 +973,19 @@ static void extrude_mesh_face_regions(Mesh &mesh,
/* Translate vertices based on the offset. If the vertex is used by a selected edge, it will
* have been duplicated and only the new vertex should use the offset. Otherwise the vertex might
* still need an offset, but it was reused on the inside of a region of extruded faces. */
MutableSpan<MVert> verts = mesh.positions_for_write();
MutableSpan<float3> positions = mesh.positions_for_write();
if (poly_offsets.is_single()) {
const float3 offset = poly_offsets.get_internal_single();
threading::parallel_for(
IndexRange(all_selected_verts.size()), 1024, [&](const IndexRange range) {
for (const int i_orig : all_selected_verts.as_span().slice(range)) {
const int i_new = new_vert_indices.index_of_try(i_orig);
MVert &vert = verts[(i_new == -1) ? i_orig : new_vert_range[i_new]];
add_v3_v3(vert.co, offset);
if (i_new == -1) {
positions[i_orig] += offset;
}
else {
new_vert_range[i_new] += offset;
}
}
});
}
@ -995,16 +995,16 @@ static void extrude_mesh_face_regions(Mesh &mesh,
for (const int i_orig : all_selected_verts.as_span().slice(range)) {
const int i_new = new_vert_indices.index_of_try(i_orig);
const float3 offset = vert_offsets[i_orig];
MVert &vert = verts[(i_new == -1) ? i_orig : new_vert_range[i_new]];
add_v3_v3(vert.co, offset);
if (i_new == -1) {
positions[i_orig] += offset;
}
else {
new_vert_range[i_new] += offset;
}
}
});
}
for (MVert &vert : verts.slice(new_vert_range)) {
vert.flag = 0;
}
MutableSpan<int> vert_orig_indices = get_orig_index_layer(mesh, ATTR_DOMAIN_POINT);
vert_orig_indices.slice(new_vert_range).fill(ORIGINDEX_NONE);
@ -1083,7 +1083,7 @@ static void extrude_individual_mesh_faces(Mesh &mesh,
side_poly_range.size(),
side_loop_range.size());
MutableSpan<MVert> new_verts = mesh.positions_for_write().slice(new_vert_range);
MutableSpan<float3> new_positions = mesh.positions_for_write().slice(new_vert_range);
MutableSpan<MEdge> edges = mesh.edges_for_write();
MutableSpan<MEdge> connect_edges = edges.slice(connect_edge_range);
MutableSpan<MEdge> duplicate_edges = edges.slice(duplicate_edge_range);
@ -1260,9 +1260,8 @@ static void extrude_individual_mesh_faces(Mesh &mesh,
threading::parallel_for(poly_selection.index_range(), 1024, [&](const IndexRange range) {
for (const int i_selection : range) {
const IndexRange poly_corner_range = selected_corner_range(index_offsets, i_selection);
for (MVert &vert : new_verts.slice(poly_corner_range)) {
add_v3_v3(vert.co, poly_offset[poly_selection[i_selection]]);
vert.flag = 0;
for (float3 &position : new_positions.slice(poly_corner_range)) {
position += poly_offset[poly_selection[i_selection]];
}
}
});

View File

@ -64,20 +64,27 @@ class AngleFieldInput final : public bke::MeshFieldInput {
const eAttrDomain domain,
IndexMask UNUSED(mask)) const final
{
const Span<MVert> verts = mesh.positions();
const Span<float3> positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge);
auto angle_fn = [edge_map = std::move(edge_map), verts, polys, loops](const int i) -> float {
auto angle_fn =
[edge_map = std::move(edge_map), positions, polys, loops](const int i) -> float {
if (edge_map[i].face_count != 2) {
return 0.0f;
}
const MPoly &mpoly_1 = polys[edge_map[i].face_index_1];
const MPoly &mpoly_2 = polys[edge_map[i].face_index_2];
float3 normal_1, normal_2;
BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], verts.data(), normal_1);
BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), normal_2);
BKE_mesh_calc_poly_normal(&mpoly_1,
&loops[mpoly_1.loopstart],
reinterpret_cast<const float(*)[3]>(positions.data()),
normal_1);
BKE_mesh_calc_poly_normal(&mpoly_2,
&loops[mpoly_2.loopstart],
reinterpret_cast<const float(*)[3]>(positions.data()),
normal_2);
return angle_normalized_v3v3(normal_1, normal_2);
};
@ -108,14 +115,14 @@ class SignedAngleFieldInput final : public bke::MeshFieldInput {
const eAttrDomain domain,
IndexMask UNUSED(mask)) const final
{
const Span<MVert> verts = mesh.positions();
const Span<float3> positions = mesh.positions();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge);
auto angle_fn =
[edge_map = std::move(edge_map), verts, edges, polys, loops](const int i) -> float {
[edge_map = std::move(edge_map), positions, edges, polys, loops](const int i) -> float {
if (edge_map[i].face_count != 2) {
return 0.0f;
}
@ -124,18 +131,25 @@ class SignedAngleFieldInput final : public bke::MeshFieldInput {
/* Find the normals of the 2 polys. */
float3 poly_1_normal, poly_2_normal;
BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], verts.data(), poly_1_normal);
BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), poly_2_normal);
BKE_mesh_calc_poly_normal(&mpoly_1,
&loops[mpoly_1.loopstart],
reinterpret_cast<const float(*)[3]>(positions.data()),
poly_1_normal);
BKE_mesh_calc_poly_normal(&mpoly_2,
&loops[mpoly_2.loopstart],
reinterpret_cast<const float(*)[3]>(positions.data()),
poly_2_normal);
/* Find the centerpoint of the axis edge */
const float3 edge_centerpoint = (float3(verts[edges[i].v1].co) +
float3(verts[edges[i].v2].co)) *
0.5f;
const float3 edge_centerpoint = (positions[edges[i].v1] + positions[edges[i].v2]) * 0.5f;
/* Get the centerpoint of poly 2 and subtract the edge centerpoint to get a tangent
* normal for poly 2. */
float3 poly_center_2;
BKE_mesh_calc_poly_center(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), poly_center_2);
BKE_mesh_calc_poly_center(&mpoly_2,
&loops[mpoly_2.loopstart],
reinterpret_cast<const float(*)[3]>(positions.data()),
poly_center_2);
const float3 poly_2_tangent = math::normalize(poly_center_2 - edge_centerpoint);
const float concavity = math::dot(poly_1_normal, poly_2_tangent);

View File

@ -79,19 +79,19 @@ static VArray<float3> construct_edge_positions_gvarray(const Mesh &mesh,
const VertexNumber vertex,
const eAttrDomain domain)
{
const Span<MVert> verts = mesh.positions();
const Span<float3> positions = mesh.positions();
const Span<MEdge> edges = mesh.edges();
if (vertex == VERTEX_ONE) {
return mesh.attributes().adapt_domain<float3>(
VArray<float3>::ForFunc(edges.size(),
[verts, edges](const int i) { return verts[edges[i].v1].co; }),
VArray<float3>::ForFunc(
edges.size(), [positions, edges](const int i) { return positions[edges[i].v1]; }),
ATTR_DOMAIN_EDGE,
domain);
}
return mesh.attributes().adapt_domain<float3>(
VArray<float3>::ForFunc(edges.size(),
[verts, edges](const int i) { return verts[edges[i].v2].co; }),
[positions, edges](const int i) { return positions[edges[i].v2]; }),
ATTR_DOMAIN_EDGE,
domain);
}

View File

@ -18,13 +18,14 @@ static void node_declare(NodeDeclarationBuilder &b)
static VArray<float> construct_face_area_varray(const Mesh &mesh, const eAttrDomain domain)
{
const Span<MVert> verts = mesh.positions();
const Span<float3> positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
auto area_fn = [verts, polys, loops](const int i) -> float {
auto area_fn = [positions, polys, loops](const int i) -> float {
const MPoly &poly = polys[i];
return BKE_mesh_calc_poly_area(&poly, &loops[poly.loopstart], verts.data());
return BKE_mesh_calc_poly_area(
&poly, &loops[poly.loopstart], reinterpret_cast<const float(*)[3]>(positions.data()));
};
return mesh.attributes().adapt_domain<float>(

View File

@ -37,7 +37,7 @@ class PlanarFieldInput final : public bke::MeshFieldInput {
const eAttrDomain domain,
IndexMask /*mask*/) const final
{
const Span<MVert> verts = mesh.positions();
const Span<float3> positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
const Span<float3> poly_normals{(float3 *)BKE_mesh_poly_normals_ensure(&mesh), mesh.totpoly};
@ -48,7 +48,7 @@ class PlanarFieldInput final : public bke::MeshFieldInput {
evaluator.evaluate();
const VArray<float> thresholds = evaluator.get_evaluated<float>(0);
auto planar_fn = [verts, polys, loops, thresholds, poly_normals](const int i) -> bool {
auto planar_fn = [positions, polys, loops, thresholds, poly_normals](const int i) -> bool {
const MPoly &poly = polys[i];
if (poly.totloop <= 3) {
return true;
@ -60,7 +60,7 @@ class PlanarFieldInput final : public bke::MeshFieldInput {
float max = -FLT_MAX;
for (const int i_loop : poly_loops.index_range()) {
const float3 vert = verts[poly_loops[i_loop].v].co;
const float3 &vert = positions[poly_loops[i_loop].v];
float dot = math::dot(reference_normal, vert);
if (dot > max) {
max = dot;

View File

@ -109,7 +109,7 @@ static Mesh *create_circle_mesh(const float radius,
circle_corner_total(fill_type, verts_num),
circle_face_total(fill_type, verts_num));
BKE_id_material_eval_ensure_default_slot(&mesh->id);
MutableSpan<MVert> verts = mesh->positions_for_write();
MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
@ -118,10 +118,10 @@ static Mesh *create_circle_mesh(const float radius,
const float angle_delta = 2.0f * (M_PI / static_cast<float>(verts_num));
for (const int i : IndexRange(verts_num)) {
const float angle = i * angle_delta;
copy_v3_v3(verts[i].co, float3(std::cos(angle) * radius, std::sin(angle) * radius, 0.0f));
positions[i] = float3(std::cos(angle) * radius, std::sin(angle) * radius, 0.0f);
}
if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
copy_v3_v3(verts.last().co, float3(0));
positions.last() = float3(0);
}
/* Create outer edges. */

View File

@ -255,7 +255,7 @@ int ConeConfig::calculate_total_corners()
return corner_total;
}
static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConfig &config)
static void calculate_cone_verts(const MutableSpan<float3> positions, const ConeConfig &config)
{
Array<float2> circle(config.circle_segments);
const float angle_delta = 2.0f * (M_PI / static_cast<float>(config.circle_segments));
@ -270,7 +270,7 @@ static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConf
/* Top cone tip or triangle fan center. */
if (config.top_has_center_vert) {
copy_v3_fl3(verts[vert_index++].co, 0.0f, 0.0f, config.height);
positions[vert_index++] = {0.0f, 0.0f, config.height};
}
/* Top fill including the outer edge of the fill. */
@ -282,7 +282,7 @@ static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConf
for (const int j : IndexRange(config.circle_segments)) {
const float x = circle[j].x * top_fill_radius;
const float y = circle[j].y * top_fill_radius;
copy_v3_fl3(verts[vert_index++].co, x, y, config.height);
positions[vert_index++] = {x, y, config.height};
}
}
}
@ -297,7 +297,7 @@ static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConf
for (const int j : IndexRange(config.circle_segments)) {
const float x = circle[j].x * ring_radius;
const float y = circle[j].y * ring_radius;
copy_v3_fl3(verts[vert_index++].co, x, y, ring_height);
positions[vert_index++] = {x, y, ring_height};
}
}
@ -310,14 +310,14 @@ static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConf
for (const int j : IndexRange(config.circle_segments)) {
const float x = circle[j].x * bottom_fill_radius;
const float y = circle[j].y * bottom_fill_radius;
copy_v3_fl3(verts[vert_index++].co, x, y, -config.height);
positions[vert_index++] = {x, y, -config.height};
}
}
}
/* Bottom cone tip or triangle fan center. */
if (config.bottom_has_center_vert) {
copy_v3_fl3(verts[vert_index++].co, 0.0f, 0.0f, -config.height);
positions[vert_index++] = {0.0f, 0.0f, -config.height};
}
}
@ -657,7 +657,7 @@ static Mesh *create_vertex_mesh()
{
/* Returns a mesh with a single vertex at the origin. */
Mesh *mesh = BKE_mesh_new_nomain(1, 0, 0, 0, 0);
copy_v3_fl3(mesh->positions_for_write().first().co, 0.0f, 0.0f, 0.0f);
mesh->positions_for_write().first() = float3(0);
return mesh;
}
@ -689,12 +689,12 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
config.tot_verts, config.tot_edges, 0, config.tot_corners, config.tot_faces);
BKE_id_material_eval_ensure_default_slot(&mesh->id);
MutableSpan<MVert> verts = mesh->positions_for_write();
MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
calculate_cone_verts(verts, config);
calculate_cone_verts(positions, config);
calculate_cone_edges(edges, config);
calculate_cone_faces(loops, polys, config);
calculate_cone_uvs(mesh, config);

View File

@ -16,7 +16,7 @@
namespace blender::nodes {
static void calculate_uvs(
Mesh *mesh, Span<MVert> verts, Span<MLoop> loops, const float size_x, const float size_y)
Mesh *mesh, Span<float3> positions, Span<MLoop> loops, const float size_x, const float size_y)
{
MutableAttributeAccessor attributes = mesh->attributes_for_write();
@ -27,7 +27,7 @@ static void calculate_uvs(
const float dy = (size_y == 0.0f) ? 0.0f : 1.0f / size_y;
threading::parallel_for(loops.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
const float3 &co = verts[loops[i].v].co;
const float3 &co = positions[loops[i].v];
uv_attribute.span[i].x = (co.x + size_x * 0.5f) * dx;
uv_attribute.span[i].y = (co.y + size_y * 0.5f) * dy;
}
@ -49,7 +49,7 @@ Mesh *create_grid_mesh(const int verts_x,
0,
edges_x * edges_y * 4,
edges_x * edges_y);
MutableSpan<MVert> verts = mesh->positions_for_write();
MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
@ -65,9 +65,9 @@ Mesh *create_grid_mesh(const int verts_x,
threading::parallel_for(IndexRange(verts_y), 512, [&](IndexRange y_range) {
for (const int y : y_range) {
const int vert_index = y_offset + y;
verts[vert_index].co[0] = (x - x_shift) * dx;
verts[vert_index].co[1] = (y - y_shift) * dy;
verts[vert_index].co[2] = 0.0f;
positions[vert_index].x = (x - x_shift) * dx;
positions[vert_index].y = (y - y_shift) * dy;
positions[vert_index].z = 0.0f;
}
});
}
@ -142,7 +142,7 @@ Mesh *create_grid_mesh(const int verts_x,
});
if (mesh->totpoly != 0) {
calculate_uvs(mesh, verts, loops, size_x, size_y);
calculate_uvs(mesh, positions, loops, size_x, size_y);
}
return mesh;

View File

@ -179,15 +179,15 @@ Mesh *create_line_mesh(const float3 start, const float3 delta, const int count)
Mesh *mesh = BKE_mesh_new_nomain(count, count - 1, 0, 0, 0);
BKE_id_material_eval_ensure_default_slot(&mesh->id);
MutableSpan<MVert> verts = mesh->positions_for_write();
MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
threading::parallel_invoke(
1024 < count,
[&]() {
threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
threading::parallel_for(positions.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
copy_v3_v3(verts[i].co, start + delta * i);
positions[i] = start + delta * i;
}
});
},

View File

@ -63,7 +63,7 @@ static int sphere_face_total(const int segments, const int rings)
* Also calculate vertex normals here, since the calculation is trivial, and it allows avoiding the
* calculation later, if it's necessary. The vertex normals are just the normalized positions.
*/
BLI_NOINLINE static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
BLI_NOINLINE static void calculate_sphere_vertex_data(MutableSpan<float3> positions,
MutableSpan<float3> vert_normals,
const float radius,
const int segments,
@ -83,7 +83,7 @@ BLI_NOINLINE static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
segment_sines[segment] = std::sin(phi);
}
copy_v3_v3(verts[0].co, float3(0.0f, 0.0f, radius));
positions[0] = float3(0.0f, 0.0f, radius);
vert_normals.first() = float3(0.0f, 0.0f, 1.0f);
int vert_index = 1;
@ -94,13 +94,13 @@ BLI_NOINLINE static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
for (const int segment : IndexRange(1, segments)) {
const float x = sin_theta * segment_cosines[segment];
const float y = sin_theta * segment_sines[segment];
copy_v3_v3(verts[vert_index].co, float3(x, y, z) * radius);
positions[vert_index] = float3(x, y, z) * radius;
vert_normals[vert_index] = float3(x, y, z);
vert_index++;
}
}
copy_v3_v3(verts.last().co, float3(0.0f, 0.0f, -radius));
positions.last() = float3(0.0f, 0.0f, -radius);
vert_normals.last() = float3(0.0f, 0.0f, -1.0f);
}
@ -301,7 +301,7 @@ static Mesh *create_uv_sphere_mesh(const float radius, const int segments, const
sphere_corner_total(segments, rings),
sphere_face_total(segments, rings));
BKE_id_material_eval_ensure_default_slot(&mesh->id);
MutableSpan<MVert> verts = mesh->positions_for_write();
MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
@ -310,7 +310,7 @@ static Mesh *create_uv_sphere_mesh(const float radius, const int segments, const
1024 < segments * rings,
[&]() {
MutableSpan vert_normals{(float3 *)BKE_mesh_vertex_normals_for_write(mesh), mesh->totvert};
calculate_sphere_vertex_data(verts, vert_normals, radius, segments, rings);
calculate_sphere_vertex_data(positions, vert_normals, radius, segments, rings);
BKE_mesh_vertex_normals_clear_dirty(mesh);
},
[&]() { calculate_sphere_edge_indices(edges, segments, rings); },

View File

@ -158,7 +158,7 @@ static void scale_vertex_islands_uniformly(Mesh &mesh,
const UniformScaleParams &params,
const GetVertexIndicesFn get_vertex_indices)
{
MutableSpan<MVert> verts = mesh.positions_for_write();
MutableSpan<float3> positions = mesh.positions_for_write();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@ -183,10 +183,7 @@ static void scale_vertex_islands_uniformly(Mesh &mesh,
center *= f;
for (const int vert_index : vertex_indices) {
MVert &vert = verts[vert_index];
const float3 old_position = vert.co;
const float3 new_position = transform_with_uniform_scale(old_position, center, scale);
copy_v3_v3(vert.co, new_position);
positions[vert_index] = transform_with_uniform_scale(positions[vert_index], center, scale);
}
}
});
@ -199,7 +196,7 @@ static void scale_vertex_islands_on_axis(Mesh &mesh,
const AxisScaleParams &params,
const GetVertexIndicesFn get_vertex_indices)
{
MutableSpan<MVert> verts = mesh.positions_for_write();
MutableSpan<float3> positions = mesh.positions_for_write();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@ -232,10 +229,7 @@ static void scale_vertex_islands_on_axis(Mesh &mesh,
const float4x4 transform = create_single_axis_transform(center, axis, scale);
for (const int vert_index : vertex_indices) {
MVert &vert = verts[vert_index];
const float3 old_position = vert.co;
const float3 new_position = transform * old_position;
copy_v3_v3(vert.co, new_position);
positions[vert_index] = transform * positions[vert_index];
}
}
});

View File

@ -264,7 +264,7 @@ static void get_closest_mesh_corners(const Mesh &mesh,
const MutableSpan<float> r_distances_sq,
const MutableSpan<float3> r_positions)
{
const Span<MVert> verts = mesh.positions();
const Span<float3> positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@ -279,24 +279,23 @@ static void get_closest_mesh_corners(const Mesh &mesh,
/* Find the closest vertex in the polygon. */
float min_distance_sq = FLT_MAX;
const MVert *closest_mvert;
int closest_vert;
int closest_loop_index = 0;
for (const int loop_index : IndexRange(poly.loopstart, poly.totloop)) {
const MLoop &loop = loops[loop_index];
const int vertex_index = loop.v;
const MVert &mvert = verts[vertex_index];
const float distance_sq = math::distance_squared(position, float3(mvert.co));
const float distance_sq = math::distance_squared(position, positions[vertex_index]);
if (distance_sq < min_distance_sq) {
min_distance_sq = distance_sq;
closest_loop_index = loop_index;
closest_mvert = &mvert;
closest_vert = vertex_index;
}
}
if (!r_corner_indices.is_empty()) {
r_corner_indices[i] = closest_loop_index;
}
if (!r_positions.is_empty()) {
r_positions[i] = closest_mvert->co;
r_positions[i] = positions[closest_vert];
}
if (!r_distances_sq.is_empty()) {
r_distances_sq[i] = min_distance_sq;

View File

@ -37,7 +37,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
const float margin,
const eAttrDomain domain)
{
const Span<MVert> verts = mesh.positions();
const Span<float3> positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@ -67,7 +67,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
for (const int i : IndexRange(mp.totloop)) {
const MLoop &ml = loops[mp.loopstart + i];
mp_vkeys[i] = ml.v;
mp_co[i] = verts[ml.v].co;
mp_co[i] = positions[ml.v];
mp_uv[i] = uv[mp.loopstart + i];
mp_pin[i] = false;
mp_select[i] = false;

View File

@ -62,7 +62,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
const GeometryNodeUVUnwrapMethod method,
const eAttrDomain domain)
{
const Span<MVert> verts = mesh.positions();
const Span<float3> positions = mesh.positions();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@ -95,7 +95,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
for (const int i : IndexRange(mp.totloop)) {
const MLoop &ml = loops[mp.loopstart + i];
mp_vkeys[i] = ml.v;
mp_co[i] = verts[ml.v].co;
mp_co[i] = positions[ml.v];
mp_uv[i] = uv[mp.loopstart + i];
mp_pin[i] = false;
mp_select[i] = false;

View File

@ -123,7 +123,7 @@ static Mesh *create_mesh_from_volume_grids(Span<openvdb::GridBase::ConstPtr> gri
Mesh *mesh = BKE_mesh_new_nomain(vert_offset, 0, 0, loop_offset, poly_offset);
BKE_id_material_eval_ensure_default_slot(&mesh->id);
MutableSpan<MVert> verts = mesh->positions_for_write();
MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
@ -135,7 +135,7 @@ static Mesh *create_mesh_from_volume_grids(Span<openvdb::GridBase::ConstPtr> gri
vert_offsets[i],
poly_offsets[i],
loop_offsets[i],
verts,
positions,
polys,
loops);
}

View File

@ -1148,9 +1148,9 @@ static PyObject *C_BVHTree_FromObject(PyObject *UNUSED(cls), PyObject *args, PyO
coords = MEM_mallocN(sizeof(*coords) * (size_t)coords_len, __func__);
tris = MEM_mallocN(sizeof(*tris) * (size_t)tris_len, __func__);
const MVert *verts = BKE_mesh_positions(mesh);
const float(*positions)[3] = BKE_mesh_positions(mesh);
for (int i = 0; i < mesh->totvert; i++) {
copy_v3_v3(coords[i], verts[i].co);
copy_v3_v3(coords[i], positions[i].co);
}
mloop = BKE_mesh_loops(mesh);

View File

@ -92,7 +92,7 @@ typedef struct TSpace {
} TSpace;
typedef struct TriTessFace {
const MVert *mverts[3];
const float *positions[3];
const float *vert_normals[3];
const TSpace *tspace[3];
const float *loop_normal[3];
@ -194,9 +194,9 @@ static void calc_point_from_barycentric_cage(TriTessFace *triangles_low,
triangle[1] = &triangles_cage[primitive_id];
for (i = 0; i < 2; i++) {
copy_v3_v3(data[i][0], triangle[i]->mverts[0]->co);
copy_v3_v3(data[i][1], triangle[i]->mverts[1]->co);
copy_v3_v3(data[i][2], triangle[i]->mverts[2]->co);
copy_v3_v3(data[i][0], triangle[i]->positions[0]);
copy_v3_v3(data[i][1], triangle[i]->positions[1]);
copy_v3_v3(data[i][2], triangle[i]->positions[2]);
interp_barycentric_tri_v3(data[i], u, v, coord[i]);
}
@ -236,9 +236,9 @@ static void calc_point_from_barycentric_extrusion(TriTessFace *triangles,
TriTessFace *triangle = &triangles[primitive_id];
is_smooth = triangle->is_smooth || is_cage;
copy_v3_v3(data[0], triangle->mverts[0]->co);
copy_v3_v3(data[1], triangle->mverts[1]->co);
copy_v3_v3(data[2], triangle->mverts[2]->co);
copy_v3_v3(data[0], triangle->positions[0]);
copy_v3_v3(data[1], triangle->positions[1]);
copy_v3_v3(data[2], triangle->positions[2]);
interp_barycentric_tri_v3(data, u, v, coord);
@ -393,8 +393,8 @@ static bool cast_ray_highpoly(BVHTreeFromMesh *treeData,
/* compute position differentials on low poly object */
float duco_low[3], dvco_low[3], dxco[3], dyco[3];
sub_v3_v3v3(duco_low, triangle_low->mverts[0]->co, triangle_low->mverts[2]->co);
sub_v3_v3v3(dvco_low, triangle_low->mverts[1]->co, triangle_low->mverts[2]->co);
sub_v3_v3v3(duco_low, triangle_low->positions[0], triangle_low->positions[2]);
sub_v3_v3v3(dvco_low, triangle_low->positions[1], triangle_low->positions[2]);
mul_v3_v3fl(dxco, duco_low, pixel_low->du_dx);
madd_v3_v3fl(dxco, dvco_low, pixel_low->dv_dx);
@ -415,9 +415,9 @@ static bool cast_ray_highpoly(BVHTreeFromMesh *treeData,
/* compute barycentric differentials from position differentials */
barycentric_differentials_from_position(hits[hit_mesh].co,
triangle_high->mverts[0]->co,
triangle_high->mverts[1]->co,
triangle_high->mverts[2]->co,
triangle_high->positions[0],
triangle_high->positions[1],
triangle_high->positions[2],
dxco,
dyco,
triangle_high->normal,
@ -459,7 +459,7 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
unsigned int mpoly_prev = UINT_MAX;
float no[3];
const MVert *verts = BKE_mesh_positions(me);
const float(*positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
@ -473,10 +473,10 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
if (precomputed_normals != NULL) {
BKE_mesh_recalc_looptri_with_normals(
loops, polys, verts, me->totloop, me->totpoly, looptri, precomputed_normals);
loops, polys, positions, me->totloop, me->totpoly, looptri, precomputed_normals);
}
else {
BKE_mesh_recalc_looptri(loops, polys, verts, me->totloop, me->totpoly, looptri);
BKE_mesh_recalc_looptri(loops, polys, positions, me->totloop, me->totpoly, looptri);
}
const TSpace *tspace = NULL;
@ -497,9 +497,9 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
const MLoopTri *lt = &looptri[i];
const MPoly *mp = &polys[lt->poly];
triangles[i].mverts[0] = &verts[loops[lt->tri[0]].v];
triangles[i].mverts[1] = &verts[loops[lt->tri[1]].v];
triangles[i].mverts[2] = &verts[loops[lt->tri[2]].v];
triangles[i].positions[0] = &positions[loops[lt->tri[0]].v];
triangles[i].positions[1] = &positions[loops[lt->tri[1]].v];
triangles[i].positions[2] = &positions[loops[lt->tri[2]].v];
triangles[i].vert_normals[0] = vert_normals[loops[lt->tri[0]].v];
triangles[i].vert_normals[1] = vert_normals[loops[lt->tri[1]].v];
triangles[i].vert_normals[2] = vert_normals[loops[lt->tri[2]].v];
@ -519,7 +519,7 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
if (calculate_normal) {
if (lt->poly != mpoly_prev) {
BKE_mesh_calc_poly_normal(mp, &loops[mp->loopstart], verts, no);
BKE_mesh_calc_poly_normal(mp, &loops[mp->loopstart], positions, no);
mpoly_prev = lt->poly;
}
copy_v3_v3(triangles[i].normal, no);
@ -741,10 +741,10 @@ void RE_bake_pixels_populate(Mesh *me,
const int tottri = poly_to_tri_count(me->totpoly, me->totloop);
MLoopTri *looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__);
const MVert *verts = BKE_mesh_positions(me);
const float(*positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
BKE_mesh_recalc_looptri(loops, polys, verts, me->totloop, me->totpoly, looptri);
BKE_mesh_recalc_looptri(loops, polys, positions, me->totloop, me->totpoly, looptri);
const int *material_indices = BKE_mesh_material_indices(me);

View File

@ -364,7 +364,6 @@ static void pointdensity_cache_object(PointDensity *pd, Object *ob)
{
float *data_color;
int i;
const MVert *mvert = NULL, *mv;
Mesh *mesh = ob->data;
#if 0 /* UNUSED */
@ -380,7 +379,7 @@ static void pointdensity_cache_object(PointDensity *pd, Object *ob)
}
#endif
mvert = BKE_mesh_positions(mesh); /* local object space */
const float(*positions)[3] = BKE_mesh_positions(mesh); /* local object space */
pd->totpoints = mesh->totvert;
if (pd->totpoints == 0) {
return;
@ -390,10 +389,10 @@ static void pointdensity_cache_object(PointDensity *pd, Object *ob)
alloc_point_data(pd);
point_data_pointers(pd, NULL, NULL, &data_color);
for (i = 0, mv = mvert; i < pd->totpoints; i++, mv++) {
for (i = 0; i < pd->totpoints; i++) {
float co[3];
copy_v3_v3(co, mv->co);
copy_v3_v3(co, positions[i]);
switch (pd->ob_cache_space) {
case TEX_PD_OBJECTSPACE:

View File

@ -1215,8 +1215,8 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd,
colliders = BKE_collider_cache_create(depsgraph, NULL, NULL);
if (colliders && collfac > 0.0f) {
for (col = colliders->first; col; col = col->next) {
MVert *loc0 = col->collmd->x;
MVert *loc1 = col->collmd->xnew;
float3 *loc0 = col->collmd->x;
float3 *loc1 = col->collmd->xnew;
float vel[3];
float weights[8];
int di, dj, dk;