Various fixes and cleanups
This commit is contained in:
parent
b15b49ffb9
commit
a44093693e
|
@ -59,7 +59,6 @@ typedef struct BVHTreeFromMesh {
|
|||
|
||||
/* Vertex array, so that callbacks have instant access to data. */
|
||||
const float (*positions)[3];
|
||||
const float (*vert_normals)[3];
|
||||
const struct MEdge *edge;
|
||||
const struct MFace *face;
|
||||
const struct MLoop *loop;
|
||||
|
|
|
@ -697,10 +697,6 @@ void BKE_mesh_calc_poly_normal(const struct MPoly *mpoly,
|
|||
const struct MLoop *loopstart,
|
||||
const float (*positions)[3],
|
||||
float r_no[3]);
|
||||
void BKE_mesh_calc_poly_normal_coords(const struct MPoly *mpoly,
|
||||
const struct MLoop *loopstart,
|
||||
const float (*vertex_coords)[3],
|
||||
float r_no[3]);
|
||||
void BKE_mesh_calc_poly_center(const struct MPoly *mpoly,
|
||||
const struct MLoop *loopstart,
|
||||
const float (*positions)[3],
|
||||
|
|
|
@ -669,8 +669,8 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
|
|||
|
||||
BLI_assert((mesh_input->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) == 0);
|
||||
|
||||
/* TODO: Remove use of "deformed_verts" in mesh modifier stack since mesh positions are now in a
|
||||
* contiguous array. */
|
||||
/* TODO: Remove use of `deformed_verts` in mesh modifier stack
|
||||
* since mesh positions are now stored in a contiguous array. */
|
||||
float(*deformed_verts)[3] = nullptr;
|
||||
int num_deformed_verts = mesh_input->totvert;
|
||||
bool isPrevDeform = false;
|
||||
|
@ -1257,10 +1257,8 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
|
|||
/* This geometry set contains the non-mesh data that might be generated by modifiers. */
|
||||
GeometrySet geometry_set_final;
|
||||
|
||||
/* Deformed vertex locations array. Deform only modifier need this type of
|
||||
* 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: Remove use of `deformed_verts` in mesh modifier stack
|
||||
* since mesh positions are now stored in a contiguous array. */
|
||||
float(*deformed_verts)[3] = nullptr;
|
||||
int num_deformed_verts = 0;
|
||||
bool isPrevDeform = false;
|
||||
|
|
|
@ -1115,16 +1115,15 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
|
|||
int tree_type,
|
||||
int axis)
|
||||
{
|
||||
BVHTree *tree = nullptr;
|
||||
tree = bvhtree_from_mesh_looptri_create_tree(epsilon,
|
||||
tree_type,
|
||||
axis,
|
||||
positions,
|
||||
mloop,
|
||||
looptri,
|
||||
looptri_num,
|
||||
looptri_mask,
|
||||
looptri_num_active);
|
||||
BVHTree *tree = bvhtree_from_mesh_looptri_create_tree(epsilon,
|
||||
tree_type,
|
||||
axis,
|
||||
positions,
|
||||
mloop,
|
||||
looptri,
|
||||
looptri_num,
|
||||
looptri_mask,
|
||||
looptri_num_active);
|
||||
|
||||
bvhtree_balance(tree, false);
|
||||
|
||||
|
@ -1224,15 +1223,14 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
|
|||
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
||||
looptri_len = BKE_mesh_runtime_looptri_len(mesh);
|
||||
}
|
||||
const Span<float3> positions = mesh->positions();
|
||||
const float(*c_positions)[3] = reinterpret_cast<const float(*)[3]>(positions.data());
|
||||
const float(*positions)[3] = reinterpret_cast<const float(*)[3]>(mesh->positions().data());
|
||||
const Span<MEdge> edges = mesh->edges();
|
||||
const Span<MLoop> loops = mesh->loops();
|
||||
|
||||
/* Setup BVHTreeFromMesh */
|
||||
bvhtree_from_mesh_setup_data(nullptr,
|
||||
bvh_cache_type,
|
||||
c_positions,
|
||||
positions,
|
||||
edges.data(),
|
||||
(const MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE),
|
||||
loops.data(),
|
||||
|
@ -1260,7 +1258,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
|
|||
ATTR_FALLTHROUGH;
|
||||
case BVHTREE_FROM_VERTS:
|
||||
data->tree = bvhtree_from_mesh_verts_create_tree(
|
||||
0.0f, tree_type, 6, c_positions, mesh->totvert, mask, mask_bits_act_len);
|
||||
0.0f, tree_type, 6, positions, mesh->totvert, mask, mask_bits_act_len);
|
||||
break;
|
||||
|
||||
case BVHTREE_FROM_LOOSEEDGES:
|
||||
|
@ -1268,7 +1266,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
|
|||
ATTR_FALLTHROUGH;
|
||||
case BVHTREE_FROM_EDGES:
|
||||
data->tree = bvhtree_from_mesh_edges_create_tree(
|
||||
c_positions, edges.data(), mesh->totedge, mask, mask_bits_act_len, 0.0f, tree_type, 6);
|
||||
positions, edges.data(), mesh->totedge, mask, mask_bits_act_len, 0.0f, tree_type, 6);
|
||||
break;
|
||||
|
||||
case BVHTREE_FROM_FACES:
|
||||
|
@ -1277,7 +1275,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
|
|||
0.0f,
|
||||
tree_type,
|
||||
6,
|
||||
c_positions,
|
||||
positions,
|
||||
(const MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE),
|
||||
mesh->totface,
|
||||
{},
|
||||
|
@ -1297,7 +1295,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
|
|||
data->tree = bvhtree_from_mesh_looptri_create_tree(0.0f,
|
||||
tree_type,
|
||||
6,
|
||||
c_positions,
|
||||
positions,
|
||||
loops.data(),
|
||||
looptri,
|
||||
looptri_len,
|
||||
|
|
|
@ -247,6 +247,7 @@ static bool do_init_cloth(Object *ob, ClothModifierData *clmd, Mesh *result, int
|
|||
static int do_step_cloth(
|
||||
Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
|
||||
{
|
||||
using namespace blender;
|
||||
/* simulate 1 frame forward */
|
||||
ClothVertex *verts = nullptr;
|
||||
Cloth *cloth;
|
||||
|
@ -257,7 +258,7 @@ static int do_step_cloth(
|
|||
|
||||
cloth = clmd->clothObject;
|
||||
verts = cloth->verts;
|
||||
const float(*positions)[3] = BKE_mesh_positions(result);
|
||||
const Span<float3> positions = result->positions();
|
||||
vert_mass_changed = verts->mass != clmd->sim_parms->mass;
|
||||
|
||||
/* force any pinned verts to their constrained location. */
|
||||
|
@ -714,6 +715,7 @@ static float cloth_shrink_factor(ClothModifierData *clmd, ClothVertex *verts, in
|
|||
static bool cloth_from_object(
|
||||
Object *ob, ClothModifierData *clmd, Mesh *mesh, float UNUSED(framenr), int first)
|
||||
{
|
||||
using namespace blender;
|
||||
int i = 0;
|
||||
ClothVertex *verts = nullptr;
|
||||
const float(*shapekey_rest)[3] = nullptr;
|
||||
|
@ -757,7 +759,7 @@ static bool cloth_from_object(
|
|||
CustomData_get_layer(&mesh->vdata, CD_CLOTH_ORCO));
|
||||
}
|
||||
|
||||
const float(*positions)[3] = BKE_mesh_positions(mesh);
|
||||
const Span<float3> positions = mesh->positions();
|
||||
|
||||
verts = clmd->clothObject->verts;
|
||||
|
||||
|
@ -1151,8 +1153,9 @@ static void cloth_update_springs(ClothModifierData *clmd)
|
|||
/* Update rest verts, for dynamically deformable cloth */
|
||||
static void cloth_update_verts(Object *ob, ClothModifierData *clmd, Mesh *mesh)
|
||||
{
|
||||
using namespace blender;
|
||||
uint i = 0;
|
||||
const float(*positions)[3] = BKE_mesh_positions(mesh);
|
||||
const Span<float3> positions = mesh->positions();
|
||||
ClothVertex *verts = clmd->clothObject->verts;
|
||||
|
||||
/* vertex count is already ensured to match */
|
||||
|
@ -1165,9 +1168,10 @@ static void cloth_update_verts(Object *ob, ClothModifierData *clmd, Mesh *mesh)
|
|||
/* Write rest vert locations to a copy of the mesh. */
|
||||
static Mesh *cloth_make_rest_mesh(ClothModifierData *clmd, Mesh *mesh)
|
||||
{
|
||||
using namespace blender;
|
||||
Mesh *new_mesh = BKE_mesh_copy_for_eval(mesh, false);
|
||||
ClothVertex *verts = clmd->clothObject->verts;
|
||||
float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
|
||||
MutableSpan<float3> positions = mesh->positions_for_write();
|
||||
|
||||
/* vertex count is already ensured to match */
|
||||
for (int i = 0; i < mesh->totvert; i++, verts++) {
|
||||
|
@ -1388,7 +1392,7 @@ static bool find_internal_spring_target_vertex(BVHTreeFromMesh *treedata,
|
|||
float radius;
|
||||
|
||||
copy_v3_v3(co, treedata->positions[v_idx]);
|
||||
negate_v3_v3(no, treedata->vert_normals[v_idx]);
|
||||
negate_v3_v3(no, vert_normals[v_idx]);
|
||||
|
||||
float vec_len = sin(max_diversion);
|
||||
float offset[3];
|
||||
|
|
|
@ -94,57 +94,6 @@ void BKE_mesh_calc_poly_normal(const MPoly *mpoly,
|
|||
r_no[2] = 1.0;
|
||||
}
|
||||
}
|
||||
/* duplicate of function above _but_ takes coords rather than mverts */
|
||||
static void mesh_calc_ngon_normal_coords(const MPoly *mpoly,
|
||||
const MLoop *loopstart,
|
||||
const float (*vertex_coords)[3],
|
||||
float r_normal[3])
|
||||
{
|
||||
const int nverts = mpoly->totloop;
|
||||
const float *v_prev = vertex_coords[loopstart[nverts - 1].v];
|
||||
const float *v_curr;
|
||||
|
||||
zero_v3(r_normal);
|
||||
|
||||
/* Newell's Method */
|
||||
for (int i = 0; i < nverts; i++) {
|
||||
v_curr = vertex_coords[loopstart[i].v];
|
||||
add_newell_cross_v3_v3v3(r_normal, v_prev, v_curr);
|
||||
v_prev = v_curr;
|
||||
}
|
||||
|
||||
if (UNLIKELY(normalize_v3(r_normal) == 0.0f)) {
|
||||
r_normal[2] = 1.0f; /* other axis set to 0.0 */
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_mesh_calc_poly_normal_coords(const MPoly *mpoly,
|
||||
const MLoop *loopstart,
|
||||
const float (*vertex_coords)[3],
|
||||
float r_no[3])
|
||||
{
|
||||
if (mpoly->totloop > 4) {
|
||||
mesh_calc_ngon_normal_coords(mpoly, loopstart, vertex_coords, r_no);
|
||||
}
|
||||
else if (mpoly->totloop == 3) {
|
||||
normal_tri_v3(r_no,
|
||||
vertex_coords[loopstart[0].v],
|
||||
vertex_coords[loopstart[1].v],
|
||||
vertex_coords[loopstart[2].v]);
|
||||
}
|
||||
else if (mpoly->totloop == 4) {
|
||||
normal_quad_v3(r_no,
|
||||
vertex_coords[loopstart[0].v],
|
||||
vertex_coords[loopstart[1].v],
|
||||
vertex_coords[loopstart[2].v],
|
||||
vertex_coords[loopstart[3].v]);
|
||||
}
|
||||
else { /* horrible, two sided face! */
|
||||
r_no[0] = 0.0;
|
||||
r_no[1] = 0.0;
|
||||
r_no[2] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
static void mesh_calc_ngon_center(const MPoly *mpoly,
|
||||
const MLoop *loopstart,
|
||||
|
|
|
@ -802,7 +802,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
const MEdge *e_src = &edges_src[*eidx_src];
|
||||
const float *other_co_src = vcos_src[BKE_mesh_edge_other_vert(e_src, vidx_src)];
|
||||
const float *other_co_dst =
|
||||
positions_dst[BKE_mesh_edge_other_vert(e_dst, int(vidx_dst)];
|
||||
positions_dst[BKE_mesh_edge_other_vert(e_dst, int(vidx_dst))];
|
||||
const float totdist = first_dist + len_v3v3(other_co_src, other_co_dst);
|
||||
|
||||
if (totdist < best_totdist) {
|
||||
|
|
|
@ -119,7 +119,7 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
|
|||
float(*fake_co)[3];
|
||||
float no[3];
|
||||
|
||||
/* Set up poly, loops, and coords in order to call BKE_mesh_calc_poly_normal_coords(). */
|
||||
/* Set up poly, loops, and coords in order to call BKE_mesh_calc_poly_normal(). */
|
||||
fake_poly.totloop = p->totloop;
|
||||
fake_poly.loopstart = 0;
|
||||
fake_loops = MEM_malloc_arrayN(p->totloop, sizeof(MLoop), "fake_loops");
|
||||
|
@ -138,7 +138,7 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
|
|||
}
|
||||
}
|
||||
|
||||
BKE_mesh_calc_poly_normal_coords(&fake_poly, fake_loops, (const float(*)[3])fake_co, no);
|
||||
BKE_mesh_calc_poly_normal(&fake_poly, fake_loops, (const float(*)[3])fake_co, no);
|
||||
MEM_freeN(fake_loops);
|
||||
MEM_freeN(fake_co);
|
||||
|
||||
|
|
|
@ -641,7 +641,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
|||
|
||||
Mesh *subdiv_mesh = subdivide_edit_mesh(ob, em, &smd);
|
||||
|
||||
float(*subsurfedPositions)[3] = BKE_mesh_positions(subdiv_mesh);
|
||||
const float(*subsurfedPositions)[3] = BKE_mesh_positions(subdiv_mesh);
|
||||
const MEdge *subsurfedEdges = BKE_mesh_edges(subdiv_mesh);
|
||||
const MPoly *subsurfedPolys = BKE_mesh_polys(subdiv_mesh);
|
||||
const MLoop *subsurfedLoops = BKE_mesh_loops(subdiv_mesh);
|
||||
|
|
|
@ -235,8 +235,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd,
|
|||
float best_dot;
|
||||
|
||||
/* get the untransformed face normal */
|
||||
BKE_mesh_calc_poly_normal_coords(
|
||||
mp, loops + mp->loopstart, (const float(*)[3])coords, face_no);
|
||||
BKE_mesh_calc_poly_normal(mp, loops + mp->loopstart, (const float(*)[3])coords, face_no);
|
||||
|
||||
/* find the projector which the face points at most directly
|
||||
* (projector normal with largest dot product is best)
|
||||
|
|
Loading…
Reference in New Issue