Add allocation API, switch to offsets in more places
This commit is contained in:
parent
709ec5ea3a
commit
f1bc7326eb
|
@ -246,11 +246,12 @@ static void fill_generic_attribute(BL::Mesh &b_mesh,
|
|||
if (polys_num == 0) {
|
||||
return;
|
||||
}
|
||||
const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
|
||||
const int *poly_offsets = static_cast<const int *>(b_mesh.polygons[0].ptr.data);
|
||||
for (int i = 0; i < polys_num; i++) {
|
||||
const MPoly &b_poly = polys[i];
|
||||
for (int j = 0; j < b_poly.totloop; j++) {
|
||||
*data = get_value_at_index(b_poly.loopstart + j);
|
||||
const int poly_start = poly_offsets[i];
|
||||
const int poly_size = poly_offsets[i + 1] - poly_start;
|
||||
for (int j = 0; j < poly_size; j++) {
|
||||
*data = get_value_at_index(poly_start + j);
|
||||
data++;
|
||||
}
|
||||
}
|
||||
|
@ -578,7 +579,7 @@ static void attr_create_subd_uv_map(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh,
|
|||
if (polys_num == 0) {
|
||||
return;
|
||||
}
|
||||
const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
|
||||
const int *poly_offsets = static_cast<const int *>(b_mesh.polygons[0].ptr.data);
|
||||
|
||||
if (!b_mesh.uv_layers.empty()) {
|
||||
BL::Mesh::uv_layers_iterator l;
|
||||
|
@ -614,9 +615,10 @@ static void attr_create_subd_uv_map(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh,
|
|||
float2 *fdata = uv_attr->data_float2();
|
||||
|
||||
for (int i = 0; i < polys_num; i++) {
|
||||
const MPoly &b_poly = polys[i];
|
||||
for (int j = 0; j < b_poly.totloop; j++) {
|
||||
*(fdata++) = get_float2(l->data[b_poly.loopstart + j].uv());
|
||||
const int poly_start = poly_offsets[i];
|
||||
const int poly_size = poly_offsets[i + 1] - poly_start;
|
||||
for (int j = 0; j < poly_size; j++) {
|
||||
*(fdata++) = get_float2(l->data[poly_start + j].uv());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -880,11 +882,12 @@ static void attr_create_random_per_island(Scene *scene,
|
|||
}
|
||||
else {
|
||||
if (polys_num != 0) {
|
||||
const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
|
||||
const int *poly_offsets = static_cast<const int *>(b_mesh.polygons[0].ptr.data);
|
||||
BL::IntAttribute corner_verts = *find_corner_vert_attribute(b_mesh);
|
||||
for (int i = 0; i < polys_num; i++) {
|
||||
const MPoly &b_poly = polys[i];
|
||||
const int vert = corner_verts.data[b_poly.loopstart].value();
|
||||
const int poly_start = poly_offsets[i];
|
||||
const int poly_size = poly_offsets[i + 1] - poly_start;
|
||||
const int vert = corner_verts.data[poly_start].value();
|
||||
data[i] = hash_uint_to_float(vertices_sets.find(vert));
|
||||
}
|
||||
}
|
||||
|
@ -957,11 +960,12 @@ static void create_mesh(Scene *scene,
|
|||
numtris = numfaces;
|
||||
}
|
||||
else {
|
||||
const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
|
||||
const int *poly_offsets = static_cast<const int *>(b_mesh.polygons[0].ptr.data);
|
||||
for (int i = 0; i < polys_num; i++) {
|
||||
const MPoly &b_poly = polys[i];
|
||||
numngons += (b_poly.totloop == 4) ? 0 : 1;
|
||||
numcorners += b_poly.totloop;
|
||||
const int poly_start = poly_offsets[i];
|
||||
const int poly_size = poly_offsets[i + 1] - poly_start;
|
||||
numngons += (poly_size == 4) ? 0 : 1;
|
||||
numcorners += poly_size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1052,23 +1056,23 @@ static void create_mesh(Scene *scene,
|
|||
else {
|
||||
vector<int> vi;
|
||||
|
||||
const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
|
||||
const int *poly_offsets = static_cast<const int *>(b_mesh.polygons[0].ptr.data);
|
||||
std::optional<BL::IntAttribute> corner_verts = find_corner_vert_attribute(b_mesh);
|
||||
|
||||
for (int i = 0; i < numfaces; i++) {
|
||||
const MPoly &b_poly = polys[i];
|
||||
int n = b_poly.totloop;
|
||||
const int poly_start = poly_offsets[i];
|
||||
const int poly_size = poly_offsets[i + 1] - poly_start;
|
||||
int shader = get_material_index(i);
|
||||
bool smooth = !get_face_sharp(i) || use_loop_normals;
|
||||
|
||||
vi.resize(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
vi.resize(poly_size);
|
||||
for (int i = 0; i < poly_size; i++) {
|
||||
/* NOTE: Autosmooth is already taken care about. */
|
||||
vi[i] = corner_verts->data[b_poly.loopstart + i].value();
|
||||
vi[i] = corner_verts->data[poly_start + i].value();
|
||||
}
|
||||
|
||||
/* create subd faces */
|
||||
mesh->add_subd_face(&vi[0], n, shader, smooth);
|
||||
mesh->add_subd_face(&vi[0], poly_size, shader, smooth);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,6 +161,8 @@ void BKE_mesh_ensure_skin_customdata(struct Mesh *me);
|
|||
|
||||
struct Mesh *BKE_mesh_new_nomain(
|
||||
int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len);
|
||||
/** Add poly offsets to describe faces to a new mesh. */
|
||||
void BKE_mesh_ensure_poly_offsets(struct Mesh *mesh);
|
||||
struct Mesh *BKE_mesh_new_nomain_from_template(const struct Mesh *me_src,
|
||||
int verts_len,
|
||||
int edges_len,
|
||||
|
|
|
@ -1770,7 +1770,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
|
|||
{sizeof(float[3]), "", 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
|
||||
/* 24: CD_RECAST */
|
||||
{sizeof(MRecast), "MRecast", 1, N_("Recast"), nullptr, nullptr, nullptr, nullptr},
|
||||
/* 25: CD_MPOLY */
|
||||
/* 25: CD_MPOLY */ /* DEPRECATED */
|
||||
{sizeof(MPoly), "MPoly", 1, N_("NGon Face"), nullptr, nullptr, nullptr, nullptr, nullptr},
|
||||
/* 26: CD_MLOOP */ /* DEPRECATED*/
|
||||
{sizeof(MLoop),
|
||||
|
@ -2031,14 +2031,14 @@ const CustomData_MeshMasks CD_MASK_BAREMESH = {
|
|||
/*vmask*/ CD_MASK_PROP_FLOAT3,
|
||||
/*emask*/ CD_MASK_MEDGE,
|
||||
/*fmask*/ 0,
|
||||
/*pmask*/ CD_MASK_MPOLY | CD_MASK_FACEMAP,
|
||||
/*pmask*/ CD_MASK_FACEMAP,
|
||||
/*lmask*/ CD_MASK_PROP_INT32,
|
||||
};
|
||||
const CustomData_MeshMasks CD_MASK_BAREMESH_ORIGINDEX = {
|
||||
/*vmask*/ CD_MASK_PROP_FLOAT3 | CD_MASK_ORIGINDEX,
|
||||
/*emask*/ CD_MASK_MEDGE | CD_MASK_ORIGINDEX,
|
||||
/*fmask*/ 0,
|
||||
/*pmask*/ CD_MASK_MPOLY | CD_MASK_FACEMAP | CD_MASK_ORIGINDEX,
|
||||
/*pmask*/ CD_MASK_FACEMAP | CD_MASK_ORIGINDEX,
|
||||
/*lmask*/ CD_MASK_PROP_INT32,
|
||||
};
|
||||
const CustomData_MeshMasks CD_MASK_MESH = {
|
||||
|
@ -2048,7 +2048,7 @@ const CustomData_MeshMasks CD_MASK_MESH = {
|
|||
(CD_MASK_MEDGE | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL | CD_MASK_BWEIGHT | CD_MASK_CREASE),
|
||||
/*fmask*/ 0,
|
||||
/*pmask*/
|
||||
(CD_MASK_MPOLY | CD_MASK_FACEMAP | CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL),
|
||||
(CD_MASK_FACEMAP | CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL),
|
||||
/*lmask*/
|
||||
(CD_MASK_MDISPS | CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL),
|
||||
};
|
||||
|
@ -2088,8 +2088,8 @@ const CustomData_MeshMasks CD_MASK_EVERYTHING = {
|
|||
CD_MASK_ORIGSPACE | CD_MASK_TANGENT | CD_MASK_TESSLOOPNORMAL | CD_MASK_PREVIEW_MCOL |
|
||||
CD_MASK_PROP_ALL),
|
||||
/*pmask*/
|
||||
(CD_MASK_MPOLY | CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_FACEMAP |
|
||||
CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL),
|
||||
(CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_FACEMAP | CD_MASK_FREESTYLE_FACE |
|
||||
CD_MASK_PROP_ALL),
|
||||
/*lmask*/
|
||||
(CD_MASK_BM_ELEM_PYPTR | CD_MASK_MDISPS | CD_MASK_NORMAL | CD_MASK_CUSTOMLOOPNORMAL |
|
||||
CD_MASK_MLOOPTANGENT | CD_MASK_PREVIEW_MLOOPCOL | CD_MASK_ORIGSPACE_MLOOP |
|
||||
|
|
|
@ -520,7 +520,7 @@ static int customdata_compare(
|
|||
{
|
||||
CustomDataLayer *l1, *l2;
|
||||
int layer_count1 = 0, layer_count2 = 0, j;
|
||||
const uint64_t cd_mask_non_generic = CD_MASK_MEDGE | CD_MASK_MPOLY | CD_MASK_MDEFORMVERT;
|
||||
const uint64_t cd_mask_non_generic = CD_MASK_MEDGE | CD_MASK_MDEFORMVERT;
|
||||
const uint64_t cd_mask_all_attr = CD_MASK_PROP_ALL | cd_mask_non_generic;
|
||||
|
||||
/* The uv selection / pin layers are ignored in the comparisons because
|
||||
|
@ -932,6 +932,22 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name)
|
|||
return me;
|
||||
}
|
||||
|
||||
void BKE_mesh_poly_offsets_ensure(Mesh *mesh)
|
||||
{
|
||||
BLI_assert(mesh->poly_offsets_data == nullptr);
|
||||
if (mesh->totpoly == 0) {
|
||||
return;
|
||||
}
|
||||
if (!mesh->poly_offsets_data) {
|
||||
mesh->poly_offsets_data = static_cast<int *>(
|
||||
MEM_malloc_arrayN(mesh->totpoly + 1, sizeof(int), __func__));
|
||||
}
|
||||
#ifdef DEBUG
|
||||
mesh->poly_offsets_for_write().fill(-1);
|
||||
#endif
|
||||
mesh->poly_offsets_for_write().last() = mesh->totloop;
|
||||
}
|
||||
|
||||
/* Custom data layer functions; those assume that totXXX are set correctly. */
|
||||
static void mesh_ensure_cdlayers_primary(Mesh *mesh, bool do_tessface)
|
||||
{
|
||||
|
@ -950,13 +966,6 @@ static void mesh_ensure_cdlayers_primary(Mesh *mesh, bool do_tessface)
|
|||
CustomData_add_layer_named(
|
||||
&mesh->ldata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, mesh->totloop, ".corner_edge");
|
||||
}
|
||||
if (mesh->totpoly != 0) {
|
||||
if (!mesh->poly_offsets_data) {
|
||||
mesh->poly_offsets_data = static_cast<int *>(
|
||||
MEM_malloc_arrayN(mesh->totpoly + 1, sizeof(int), __func__));
|
||||
}
|
||||
mesh->poly_offsets_for_write().last() = mesh->totloop;
|
||||
}
|
||||
if (do_tessface && !CustomData_get_layer(&mesh->fdata, CD_MFACE)) {
|
||||
CustomData_add_layer(&mesh->fdata, CD_MFACE, CD_SET_DEFAULT, nullptr, mesh->totface);
|
||||
}
|
||||
|
@ -982,12 +991,8 @@ Mesh *BKE_mesh_new_nomain(
|
|||
mesh->totloop = loops_len;
|
||||
mesh->totpoly = polys_len;
|
||||
|
||||
#ifdef DEBUG
|
||||
mesh->poly_offsets_for_write().fill(-1);
|
||||
#endif
|
||||
mesh->poly_offsets_for_write().last() == loops_len;
|
||||
|
||||
mesh_ensure_cdlayers_primary(mesh, true);
|
||||
BKE_mesh_poly_offsets_ensure(mesh);
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
@ -1084,6 +1089,7 @@ Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src,
|
|||
/* The destination mesh should at least have valid primary CD layers,
|
||||
* even in cases where the source mesh does not. */
|
||||
mesh_ensure_cdlayers_primary(me_dst, do_tessface);
|
||||
BKE_mesh_poly_offsets_ensure(me_dst);
|
||||
|
||||
/* Expect that normals aren't copied at all, since the destination mesh is new. */
|
||||
BLI_assert(BKE_mesh_vertex_normals_are_dirty(me_dst));
|
||||
|
|
|
@ -404,9 +404,6 @@ static void copy_poly_attributes(Mesh *dest_mesh,
|
|||
const CustomData *source_cd = &orig_me->pdata;
|
||||
for (int source_layer_i = 0; source_layer_i < source_cd->totlayer; ++source_layer_i) {
|
||||
int ty = source_cd->layers[source_layer_i].type;
|
||||
if (ty == CD_MPOLY) {
|
||||
continue;
|
||||
}
|
||||
const char *name = source_cd->layers[source_layer_i].name;
|
||||
int target_layer_i = CustomData_get_named_layer_index(target_cd, ty, name);
|
||||
if (target_layer_i != -1) {
|
||||
|
|
|
@ -975,7 +975,6 @@ static int mesh_tessface_calc(Mesh &mesh,
|
|||
|
||||
const int looptri_num = poly_to_tri_count(totpoly, totloop);
|
||||
|
||||
const MPoly *mp, *mpoly;
|
||||
MFace *mface, *mf;
|
||||
MemArena *arena = nullptr;
|
||||
int *mface_to_poly_map;
|
||||
|
@ -983,7 +982,7 @@ static int mesh_tessface_calc(Mesh &mesh,
|
|||
int poly_index, mface_index;
|
||||
uint j;
|
||||
|
||||
mpoly = (const MPoly *)CustomData_get_layer(pdata, CD_MPOLY);
|
||||
const blender::OffsetIndices polys = mesh.polys();
|
||||
const Span<int> corner_verts = mesh.corner_verts();
|
||||
const int *material_indices = static_cast<const int *>(
|
||||
CustomData_get_layer_named(pdata, CD_PROP_INT32, "material_index"));
|
||||
|
@ -999,10 +998,9 @@ static int mesh_tessface_calc(Mesh &mesh,
|
|||
lindices = (uint(*)[4])MEM_malloc_arrayN(size_t(looptri_num), sizeof(*lindices), __func__);
|
||||
|
||||
mface_index = 0;
|
||||
mp = mpoly;
|
||||
for (poly_index = 0; poly_index < totpoly; poly_index++, mp++) {
|
||||
const uint mp_loopstart = uint(mp->loopstart);
|
||||
const uint mp_totloop = uint(mp->totloop);
|
||||
for (poly_index = 0; poly_index < totpoly; poly_index++) {
|
||||
const uint mp_loopstart = uint(polys[poly_index].start());
|
||||
const uint mp_totloop = uint(polys[poly_index].size());
|
||||
uint l1, l2, l3, l4;
|
||||
uint *lidx;
|
||||
if (mp_totloop < 3) {
|
||||
|
@ -1234,7 +1232,7 @@ void BKE_mesh_tessface_ensure(struct Mesh *mesh)
|
|||
void BKE_mesh_legacy_sharp_faces_to_flags(Mesh *mesh)
|
||||
{
|
||||
using namespace blender;
|
||||
MutableSpan<int> poly_offsets(mesh->mpoly, mesh->totvert);
|
||||
MutableSpan<MPoly> polys(mesh->mpoly, mesh->totvert);
|
||||
if (const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"))) {
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](const IndexRange range) {
|
||||
|
@ -1506,7 +1504,7 @@ void BKE_mesh_legacy_convert_hide_layers_to_flags(Mesh *mesh)
|
|||
}
|
||||
});
|
||||
|
||||
MutableSpan<int> poly_offsets(mesh->mpoly, mesh->totvert);
|
||||
MutableSpan<MPoly> polys(mesh->mpoly, mesh->totvert);
|
||||
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
|
||||
".hide_poly", ATTR_DOMAIN_FACE, false);
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
|
||||
|
@ -1578,7 +1576,7 @@ void BKE_mesh_legacy_convert_material_indices_to_mpoly(Mesh *mesh)
|
|||
using namespace blender;
|
||||
using namespace blender::bke;
|
||||
const AttributeAccessor attributes = mesh->attributes();
|
||||
MutableSpan<int> poly_offsets(mesh->mpoly, mesh->totvert);
|
||||
MutableSpan<MPoly> polys(mesh->mpoly, mesh->totvert);
|
||||
const VArray<int> material_indices = attributes.lookup_or_default<int>(
|
||||
"material_index", ATTR_DOMAIN_FACE, 0);
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
|
||||
|
@ -1819,7 +1817,7 @@ void BKE_mesh_legacy_convert_selection_layers_to_flags(Mesh *mesh)
|
|||
}
|
||||
});
|
||||
|
||||
MutableSpan<int> poly_offsets(mesh->mpoly, mesh->totvert);
|
||||
MutableSpan<MPoly> polys(mesh->mpoly, mesh->totvert);
|
||||
const VArray<bool> select_poly = attributes.lookup_or_default<bool>(
|
||||
".select_poly", ATTR_DOMAIN_FACE, false);
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
|
||||
|
|
|
@ -690,7 +690,7 @@ static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
|
|||
args->vert_positions = pbvh->vert_positions;
|
||||
args->corner_verts = {pbvh->corner_verts, pbvh->mesh->totloop};
|
||||
args->corner_edges = pbvh->mesh ? pbvh->mesh->corner_edges() : blender::Span<int>();
|
||||
args->mpoly = pbvh->mpoly;
|
||||
args->polys = pbvh->polys;
|
||||
args->mlooptri = pbvh->looptri;
|
||||
|
||||
if (ELEM(pbvh->header.type, PBVH_FACES, PBVH_GRIDS)) {
|
||||
|
@ -707,7 +707,7 @@ static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
|
|||
args->pdata = pbvh->pdata;
|
||||
args->totprim = node->totprim;
|
||||
args->me = pbvh->mesh;
|
||||
args->mpoly = pbvh->mpoly;
|
||||
args->polys = pbvh->polys;
|
||||
args->vert_normals = pbvh->vert_normals;
|
||||
|
||||
args->active_color = pbvh->mesh->active_color_attribute;
|
||||
|
@ -726,7 +726,7 @@ static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
|
|||
args->grid_indices = node->prim_indices;
|
||||
args->subdiv_ccg = pbvh->subdiv_ccg;
|
||||
args->face_sets = pbvh->face_sets;
|
||||
args->mpoly = pbvh->mpoly;
|
||||
args->polys = pbvh->polys;
|
||||
|
||||
args->active_color = pbvh->mesh->active_color_attribute;
|
||||
args->render_color = pbvh->mesh->default_color_attribute;
|
||||
|
@ -3731,7 +3731,8 @@ static void pbvh_face_iter_step(PBVHFaceIter *fd, bool do_step)
|
|||
}
|
||||
|
||||
fd->last_face_index_ = face_index;
|
||||
const MPoly *mp = fd->mpoly_ + face_index;
|
||||
const int poly_start = fd->poly_offsets_[face_index];
|
||||
const int poly_size = fd->poly_offsets_[face_index + 1] - poly_start;
|
||||
|
||||
fd->face.i = fd->index = face_index;
|
||||
|
||||
|
@ -3742,17 +3743,17 @@ static void pbvh_face_iter_step(PBVHFaceIter *fd, bool do_step)
|
|||
fd->hide = fd->hide_poly_ + face_index;
|
||||
}
|
||||
|
||||
pbvh_face_iter_verts_reserve(fd, mp->totloop);
|
||||
pbvh_face_iter_verts_reserve(fd, poly_size);
|
||||
|
||||
const int grid_area = fd->subdiv_key_.grid_area;
|
||||
|
||||
for (int i = 0; i < mp->totloop; i++) {
|
||||
for (int i = 0; i < poly_size; i++) {
|
||||
if (fd->pbvh_type_ == PBVH_GRIDS) {
|
||||
/* Grid corners. */
|
||||
fd->verts[i].i = (mp->loopstart + i) * grid_area + grid_area - 1;
|
||||
fd->verts[i].i = (poly_start + i) * grid_area + grid_area - 1;
|
||||
}
|
||||
else {
|
||||
fd->verts[i].i = fd->corner_verts_[mp->loopstart + i];
|
||||
fd->verts[i].i = fd->corner_verts_[poly_start + i];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -3780,7 +3781,7 @@ void BKE_pbvh_face_iter_init(PBVH *pbvh, PBVHNode *node, PBVHFaceIter *fd)
|
|||
fd->subdiv_key_ = pbvh->gridkey;
|
||||
ATTR_FALLTHROUGH;
|
||||
case PBVH_FACES:
|
||||
fd->mpoly_ = pbvh->mpoly;
|
||||
fd->poly_offsets_ = pbvh->polys.data();
|
||||
fd->corner_verts_ = pbvh->corner_verts;
|
||||
fd->looptri_ = pbvh->looptri;
|
||||
fd->hide_poly_ = pbvh->hide_poly;
|
||||
|
@ -3862,18 +3863,19 @@ void BKE_pbvh_sync_visibility_from_verts(PBVH *pbvh, Mesh *mesh)
|
|||
break;
|
||||
}
|
||||
case PBVH_GRIDS: {
|
||||
const MPoly *mp = BKE_mesh_poly_offsets(mesh);
|
||||
const blender::OffsetIndices polys = mesh->polys();
|
||||
CCGKey key = pbvh->gridkey;
|
||||
|
||||
bool *hide_poly = static_cast<bool *>(CustomData_get_layer_named_for_write(
|
||||
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly));
|
||||
|
||||
bool delete_hide_poly = true;
|
||||
for (int face_index = 0; face_index < mesh->totpoly; face_index++, mp++) {
|
||||
for (int face_index = 0; face_index < mesh->totpoly; face_index++) {
|
||||
const blender::IndexRange poly = polys[face_index];
|
||||
bool hidden = false;
|
||||
|
||||
for (int loop_index = 0; !hidden && loop_index < mp->totloop; loop_index++) {
|
||||
int grid_index = mp->loopstart + loop_index;
|
||||
for (int loop_index = 0; !hidden && loop_index < poly.size(); loop_index++) {
|
||||
int grid_index = poly[loop_index];
|
||||
|
||||
if (pbvh->grid_hidden[grid_index] &&
|
||||
BLI_BITMAP_TEST(pbvh->grid_hidden[grid_index], key.grid_area - 1)) {
|
||||
|
|
|
@ -1613,7 +1613,7 @@ static void set_ccgdm_all_geometry(CCGDerivedMesh *ccgdm,
|
|||
medge = dm->getEdgeArray(dm);
|
||||
|
||||
const int *material_indices = static_cast<const int *>(
|
||||
CustomData_get_layer_named(&dm->polyData, CD_MPOLY, "material_index"));
|
||||
CustomData_get_layer_named(&dm->polyData, CD_PROP_INT32, "material_index"));
|
||||
const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&dm->polyData, CD_PROP_BOOL, "sharp_face"));
|
||||
|
||||
|
|
|
@ -1080,7 +1080,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
|
|||
&me->ldata, CD_PROP_INT32, CD_CONSTRUCT, nullptr, me->totloop, ".corner_vert");
|
||||
CustomData_add_layer_named(
|
||||
&me->ldata, CD_PROP_INT32, CD_CONSTRUCT, nullptr, me->totloop, ".corner_edge");
|
||||
CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, me->totpoly);
|
||||
BKE_mesh_ensure_poly_offsets(me);
|
||||
MutableSpan<float3> positions = me->vert_positions_for_write();
|
||||
MutableSpan<MEdge> medge = me->edges_for_write();
|
||||
MutableSpan<int> poly_offsets = me->poly_offsets_for_write();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
/* Needed for BKE_ccg.h. */
|
||||
#include "BLI_assert.h"
|
||||
#include "BLI_bitmap.h"
|
||||
#include "BLI_offset_indices.hh"
|
||||
#include "BLI_span.hh"
|
||||
|
||||
#include "BKE_ccg.h"
|
||||
|
@ -25,7 +26,6 @@ struct Mesh;
|
|||
struct MLoopTri;
|
||||
struct CustomData;
|
||||
struct MLoop;
|
||||
struct MPoly;
|
||||
struct SubdivCCG;
|
||||
struct BMesh;
|
||||
|
||||
|
@ -35,9 +35,9 @@ struct PBVH_GPU_Args {
|
|||
BMesh *bm;
|
||||
const Mesh *me;
|
||||
const float (*vert_positions)[3];
|
||||
blender::OffsetIndices<int> polys;
|
||||
blender::Span<int> corner_verts;
|
||||
blender::Span<int> corner_edges;
|
||||
const MPoly *mpoly;
|
||||
int mesh_verts_num, mesh_faces_num, mesh_grids_num;
|
||||
CustomData *vdata, *ldata, *pdata;
|
||||
const float (*vert_normals)[3];
|
||||
|
|
|
@ -336,8 +336,6 @@ struct PBVHBatches {
|
|||
float fno[3];
|
||||
short no[3];
|
||||
int last_poly = -1;
|
||||
const blender::OffsetIndices<int> polys(
|
||||
blender::Span(args->poly_offsets, args->mesh_faces_num));
|
||||
const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(args->pdata, CD_PROP_BOOL, "sharp_face"));
|
||||
|
||||
|
@ -348,10 +346,8 @@ struct PBVHBatches {
|
|||
|
||||
if (sharp_faces && sharp_faces[tri->poly]) {
|
||||
smooth = true;
|
||||
const IndexRange poly = polys[tri->poly];
|
||||
BKE_mesh_calc_poly_normal(blender::Span(&args->corner_verts[poly.start()], poly.size()),
|
||||
args->vert_positions,
|
||||
fno);
|
||||
BKE_mesh_calc_poly_normal(
|
||||
args->corner_verts.slice(args->polys[tri->poly]), args->vert_positions, fno);
|
||||
normal_float_to_short_v3(no, fno);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -234,7 +234,7 @@ void ED_mesh_uv_loop_reset_ex(Mesh *me, const int layernum)
|
|||
float2 *mloopuv = static_cast<float2 *>(
|
||||
CustomData_get_layer_n_for_write(&me->ldata, CD_PROP_FLOAT2, layernum, me->totloop));
|
||||
|
||||
const OffsetIndices polys = me->polys();
|
||||
const blender::OffsetIndices polys = me->polys();
|
||||
for (int i = 0; i < me->totpoly; i++) {
|
||||
mesh_uv_reset_mface(polys[i], mloopuv);
|
||||
}
|
||||
|
@ -1322,9 +1322,8 @@ static void mesh_add_polys(Mesh *mesh, int len)
|
|||
CustomData_copy(&mesh->pdata, &pdata, CD_MASK_MESH.pmask, CD_SET_DEFAULT, totpoly);
|
||||
CustomData_copy_data(&mesh->pdata, &pdata, 0, 0, mesh->totpoly);
|
||||
|
||||
if (!CustomData_has_layer(&pdata, CD_MPOLY)) {
|
||||
CustomData_add_layer(&pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, totpoly);
|
||||
}
|
||||
/* TODO: Fill new data and make sure RNA API can deal set enough things. */
|
||||
mesh->poly_offsets_data = static_cast<int *>(MEM_reallocN(mesh->poly_offsets_data, totpoly + 1));
|
||||
|
||||
CustomData_free(&mesh->pdata, mesh->totpoly);
|
||||
mesh->pdata = pdata;
|
||||
|
|
|
@ -591,8 +591,7 @@ int ED_mesh_join_objects_exec(bContext *C, wmOperator *op)
|
|||
&ldata, CD_PROP_INT32, CD_CONSTRUCT, nullptr, totloop, ".corner_vert");
|
||||
int *corner_edges = (int *)CustomData_add_layer_named(
|
||||
&ldata, CD_PROP_INT32, CD_CONSTRUCT, nullptr, totloop, ".corner_edge");
|
||||
int *poly_offsets = (MPoly *)CustomData_add_layer(
|
||||
&pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, totpoly);
|
||||
int *poly_offsets = static_cast<int *>(MEM_malloc_arrayN(totpoly + 1, sizeof(int), __func__));
|
||||
|
||||
vertofs = 0;
|
||||
edgeofs = 0;
|
||||
|
|
|
@ -550,8 +550,7 @@ static void sculpt_face_sets_init_flood_fill(Object *ob, const FaceSetsFloodFill
|
|||
&ss->epmap_mem,
|
||||
edges.data(),
|
||||
edges.size(),
|
||||
polys.data(),
|
||||
polys.size(),
|
||||
polys,
|
||||
corner_edges.data(),
|
||||
corner_edges.size());
|
||||
}
|
||||
|
@ -570,10 +569,9 @@ static void sculpt_face_sets_init_flood_fill(Object *ob, const FaceSetsFloodFill
|
|||
|
||||
while (!queue.empty()) {
|
||||
const int poly_i = queue.front();
|
||||
const MPoly &poly = polys[poly_i];
|
||||
queue.pop();
|
||||
|
||||
for (const int edge_i : corner_edges.slice(poly.loopstart, poly.totloop)) {
|
||||
for (const int edge_i : corner_edges.slice(polys[poly_i])) {
|
||||
const Span<int> neighbor_polys(ss->epmap[edge_i].indices, ss->epmap[edge_i].count);
|
||||
for (const int neighbor_i : neighbor_polys) {
|
||||
if (neighbor_i == poly_i) {
|
||||
|
@ -1110,8 +1108,7 @@ static void sculpt_face_set_grow(Object *ob,
|
|||
if (!modify_hidden && prev_face_sets[p] <= 0) {
|
||||
continue;
|
||||
}
|
||||
const MPoly *c_poly = &polys[p];
|
||||
for (const int vert : corner_verts.slice(c_poly->loopstart, c_poly->totloop)) {
|
||||
for (const int vert : corner_verts.slice(polys[p])) {
|
||||
const MeshElemMap *vert_map = &ss->pmap[vert];
|
||||
for (int i = 0; i < vert_map->count; i++) {
|
||||
const int neighbor_face_index = vert_map->indices[i];
|
||||
|
@ -1141,8 +1138,7 @@ static void sculpt_face_set_shrink(Object *ob,
|
|||
continue;
|
||||
}
|
||||
if (abs(prev_face_sets[p]) == active_face_set_id) {
|
||||
const MPoly *c_poly = &polys[p];
|
||||
for (const int vert_i : corner_verts.slice(c_poly->loopstart, c_poly->totloop)) {
|
||||
for (const int vert_i : corner_verts.slice(polys[p])) {
|
||||
const MeshElemMap *vert_map = &ss->pmap[vert_i];
|
||||
for (int i = 0; i < vert_map->count; i++) {
|
||||
const int neighbor_face_index = vert_map->indices[i];
|
||||
|
|
|
@ -631,8 +631,8 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
|||
|
||||
const float(*subsurfedPositions)[3] = BKE_mesh_vert_positions(subdiv_mesh);
|
||||
const MEdge *subsurfedEdges = BKE_mesh_edges(subdiv_mesh);
|
||||
const OffsetIndices subsurfedPolys = subdiv_mesh->polys();
|
||||
const int *subsurfedCornerVerts = subdiv_mesh->corner_verts().data();
|
||||
const blender::OffsetIndices subsurfedPolys = subdiv_mesh->polys();
|
||||
const blender::Span<int> subsurfedCornerVerts = subdiv_mesh->corner_verts();
|
||||
|
||||
const int *origVertIndices = static_cast<const int *>(
|
||||
CustomData_get_layer(&subdiv_mesh->vdata, CD_ORIGINDEX));
|
||||
|
@ -665,7 +665,6 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
|||
|
||||
/* Prepare and feed faces to the solver */
|
||||
for (int i = 0; i < subdiv_mesh->totpoly; i++) {
|
||||
const MPoly *mpoly = &subsurfedPolys[i];
|
||||
ParamKey key, vkeys[4];
|
||||
bool pin[4], select[4];
|
||||
const float *co[4];
|
||||
|
@ -684,52 +683,32 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
|||
}
|
||||
}
|
||||
|
||||
const int *poly_corner_verts = &subsurfedCornerVerts[mpoly->loopstart];
|
||||
const blender::Span<int> poly_verts = subsurfedCornerVerts.slice(subsurfedPolys[i]);
|
||||
|
||||
/* We will not check for v4 here. Sub-surface faces always have 4 vertices. */
|
||||
BLI_assert(mpoly->totloop == 4);
|
||||
key = (ParamKey)i;
|
||||
vkeys[0] = (ParamKey)poly_corner_verts[0];
|
||||
vkeys[1] = (ParamKey)poly_corner_verts[1];
|
||||
vkeys[2] = (ParamKey)poly_corner_verts[2];
|
||||
vkeys[3] = (ParamKey)poly_corner_verts[3];
|
||||
vkeys[0] = (ParamKey)poly_verts[0];
|
||||
vkeys[1] = (ParamKey)poly_verts[1];
|
||||
vkeys[2] = (ParamKey)poly_verts[2];
|
||||
vkeys[3] = (ParamKey)poly_verts[3];
|
||||
|
||||
co[0] = subsurfedPositions[poly_corner_verts[0]];
|
||||
co[1] = subsurfedPositions[poly_corner_verts[1]];
|
||||
co[2] = subsurfedPositions[poly_corner_verts[2]];
|
||||
co[3] = subsurfedPositions[poly_corner_verts[3]];
|
||||
co[0] = subsurfedPositions[poly_verts[0]];
|
||||
co[1] = subsurfedPositions[poly_verts[1]];
|
||||
co[2] = subsurfedPositions[poly_verts[2]];
|
||||
co[3] = subsurfedPositions[poly_verts[3]];
|
||||
|
||||
/* This is where all the magic is done.
|
||||
* If the vertex exists in the, we pass the original uv pointer to the solver, thus
|
||||
* flushing the solution to the edit mesh. */
|
||||
texface_from_original_index(scene,
|
||||
offsets,
|
||||
origFace,
|
||||
origVertIndices[poly_corner_verts[0]],
|
||||
&uv[0],
|
||||
&pin[0],
|
||||
&select[0]);
|
||||
texface_from_original_index(scene,
|
||||
offsets,
|
||||
origFace,
|
||||
origVertIndices[poly_corner_verts[1]],
|
||||
&uv[1],
|
||||
&pin[1],
|
||||
&select[1]);
|
||||
texface_from_original_index(scene,
|
||||
offsets,
|
||||
origFace,
|
||||
origVertIndices[poly_corner_verts[2]],
|
||||
&uv[2],
|
||||
&pin[2],
|
||||
&select[2]);
|
||||
texface_from_original_index(scene,
|
||||
offsets,
|
||||
origFace,
|
||||
origVertIndices[poly_corner_verts[3]],
|
||||
&uv[3],
|
||||
&pin[3],
|
||||
&select[3]);
|
||||
texface_from_original_index(
|
||||
scene, offsets, origFace, origVertIndices[poly_verts[0]], &uv[0], &pin[0], &select[0]);
|
||||
texface_from_original_index(
|
||||
scene, offsets, origFace, origVertIndices[poly_verts[1]], &uv[1], &pin[1], &select[1]);
|
||||
texface_from_original_index(
|
||||
scene, offsets, origFace, origVertIndices[poly_verts[2]], &uv[2], &pin[2], &select[2]);
|
||||
texface_from_original_index(
|
||||
scene, offsets, origFace, origVertIndices[poly_verts[3]], &uv[3], &pin[3], &select[3]);
|
||||
|
||||
GEO_uv_parametrizer_face_add(handle, key, 4, vkeys, co, uv, pin, select);
|
||||
}
|
||||
|
|
|
@ -580,13 +580,13 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
|
|||
mesh->totpoly = group->totpoly;
|
||||
mesh->totloop = group->totloop;
|
||||
mesh->totcol = group->materials.size();
|
||||
BKE_mesh_poly_offsets_ensure(mesh);
|
||||
|
||||
float3 *vert_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);
|
||||
MPoly *polys = (MPoly *)CustomData_add_layer(
|
||||
&mesh->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, mesh->totpoly);
|
||||
blender::MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write();
|
||||
int *corner_verts = (int *)CustomData_add_layer_named(
|
||||
&mesh->ldata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, mesh->totloop, ".corner_vert");
|
||||
int *corner_edges = (int *)CustomData_add_layer_named(
|
||||
|
@ -629,7 +629,7 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
|
|||
// Data copy
|
||||
////////////////////
|
||||
|
||||
int vertex_index = 0, edge_index = 0, loop_index = 0;
|
||||
int vertex_index = 0, edge_index = 0, loop_index = 0, poly_index = 0;
|
||||
int visible_faces, visible_segments;
|
||||
bool visible;
|
||||
Strip::vertex_container::iterator v[3];
|
||||
|
@ -710,11 +710,10 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
|
|||
++edge_index;
|
||||
|
||||
// poly
|
||||
polys->loopstart = loop_index;
|
||||
polys->totloop = 3;
|
||||
poly_offsets[poly_index] = loop_index;
|
||||
*material_indices = matnr;
|
||||
++material_indices;
|
||||
++polys;
|
||||
++poly_index;
|
||||
|
||||
// Even and odd loops connect triangles vertices differently
|
||||
bool is_odd = n % 2;
|
||||
|
|
|
@ -456,7 +456,7 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me)
|
|||
if (total_poly_count > 0) {
|
||||
me->totpoly = total_poly_count;
|
||||
me->totloop = total_loop_count;
|
||||
CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, me->totpoly);
|
||||
BKE_mesh_ensure_poly_offsets(me);
|
||||
CustomData_add_layer_named(
|
||||
&me->ldata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, me->totloop, ".corner_vert");
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ Mesh *STLMeshHelper::to_mesh(Main *bmain, char *mesh_name)
|
|||
|
||||
mesh->totpoly = tris_.size();
|
||||
mesh->totloop = tris_.size() * 3;
|
||||
CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, mesh->totpoly);
|
||||
BKE_mesh_ensure_poly_offsets(mesh);
|
||||
CustomData_add_layer_named(
|
||||
&mesh->ldata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, mesh->totloop, ".corner_vert");
|
||||
|
||||
|
|
|
@ -190,7 +190,6 @@ typedef enum eCustomDataType {
|
|||
#define CD_MASK_CLOTH_ORCO (1 << CD_CLOTH_ORCO)
|
||||
// #define CD_MASK_RECAST (1 << CD_RECAST) /* DEPRECATED */
|
||||
|
||||
#define CD_MASK_MPOLY (1 << CD_MPOLY)
|
||||
#define CD_MASK_SHAPE_KEYINDEX (1 << CD_SHAPE_KEYINDEX)
|
||||
#define CD_MASK_SHAPEKEY (1 << CD_SHAPEKEY)
|
||||
#define CD_MASK_BWEIGHT (1 << CD_BWEIGHT)
|
||||
|
|
Loading…
Reference in New Issue