Cleanup: Store BVH and shrinkwrap data with C++ types
This commit is contained in:
@@ -11,9 +11,10 @@
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "BLI_bit_vector.hh"
|
||||
#include "BLI_bit_span.hh"
|
||||
#include "BLI_kdopbvh.h"
|
||||
#include "BLI_threads.h"
|
||||
#include "BLI_math_vector_types.hh"
|
||||
#include "BLI_span.hh"
|
||||
|
||||
struct BMEditMesh;
|
||||
struct BVHCache;
|
||||
@@ -49,11 +50,12 @@ struct BVHTreeFromMesh {
|
||||
BVHTree_RayCastCallback raycast_callback;
|
||||
|
||||
/* Vertex array, so that callbacks have instant access to data. */
|
||||
const float (*vert_positions)[3];
|
||||
const vec2i *edge;
|
||||
blender::Span<blender::float3> vert_positions;
|
||||
blender::Span<blender::int2> edges;
|
||||
blender::Span<int> corner_verts;
|
||||
blender::Span<MLoopTri> looptris;
|
||||
|
||||
const MFace *face;
|
||||
const int *corner_verts;
|
||||
const MLoopTri *looptri;
|
||||
|
||||
/* Private data */
|
||||
bool cached;
|
||||
@@ -110,8 +112,7 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data,
|
||||
* (else will be computed from mask).
|
||||
*/
|
||||
BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
|
||||
const float (*vert_positions)[3],
|
||||
int verts_num,
|
||||
blender::Span<blender::float3> vert_positions,
|
||||
blender::BitSpan verts_mask,
|
||||
int verts_num_active,
|
||||
float epsilon,
|
||||
@@ -141,9 +142,8 @@ BVHTree *bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data,
|
||||
* (else will be computed from mask).
|
||||
*/
|
||||
BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
|
||||
const float (*vert_positions)[3],
|
||||
const blender::int2 *edge,
|
||||
int edges_num,
|
||||
blender::Span<blender::float3> vert_positions,
|
||||
blender::Span<blender::int2> edges,
|
||||
blender::BitSpan edges_mask,
|
||||
int edges_num_active,
|
||||
float epsilon,
|
||||
@@ -168,10 +168,9 @@ BVHTree *bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data,
|
||||
* Builds a BVH-tree where nodes are the looptri faces of the given mesh.
|
||||
*/
|
||||
BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
|
||||
const float (*vert_positions)[3],
|
||||
const int *corner_verts,
|
||||
const MLoopTri *looptri,
|
||||
int looptri_num,
|
||||
blender::Span<blender::float3> vert_positions,
|
||||
blender::Span<int> corner_verts,
|
||||
blender::Span<MLoopTri> looptris,
|
||||
blender::BitSpan mask,
|
||||
int looptri_num_active,
|
||||
float epsilon,
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
#include "BKE_bvhutils.hh"
|
||||
#include "BLI_bitmap.h"
|
||||
|
||||
#include "BLI_math_vector_types.hh"
|
||||
#include "BLI_offset_indices.hh"
|
||||
#include "BLI_span.hh"
|
||||
|
||||
/*
|
||||
* Shrinkwrap is composed by a set of functions and options that define the type of shrink.
|
||||
*
|
||||
@@ -70,12 +74,13 @@ struct ShrinkwrapTreeData {
|
||||
BVHTree *bvh;
|
||||
BVHTreeFromMesh treeData;
|
||||
|
||||
const int *face_offsets;
|
||||
const float (*vert_normals)[3];
|
||||
const int *corner_edges;
|
||||
const float (*face_normals)[3];
|
||||
blender::OffsetIndices<int> faces;
|
||||
blender::Span<int> corner_edges;
|
||||
|
||||
blender::Span<blender::float3> face_normals;
|
||||
blender::Span<blender::float3> vert_normals;
|
||||
blender::Span<blender::float3> corner_normals;
|
||||
const bool *sharp_faces;
|
||||
const float (*clnors)[3];
|
||||
ShrinkwrapBoundaryData *boundary;
|
||||
};
|
||||
|
||||
|
||||
@@ -241,14 +241,13 @@ static void mesh_faces_nearest_point(void *userdata,
|
||||
BVHTreeNearest *nearest)
|
||||
{
|
||||
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
|
||||
const float(*positions)[3] = data->vert_positions;
|
||||
const MFace *face = data->face + index;
|
||||
|
||||
const float *t0, *t1, *t2, *t3;
|
||||
t0 = positions[face->v1];
|
||||
t1 = positions[face->v2];
|
||||
t2 = positions[face->v3];
|
||||
t3 = face->v4 ? positions[face->v4] : nullptr;
|
||||
t0 = data->vert_positions[face->v1];
|
||||
t1 = data->vert_positions[face->v2];
|
||||
t2 = data->vert_positions[face->v3];
|
||||
t3 = face->v4 ? &data->vert_positions[face->v4].x : nullptr;
|
||||
|
||||
do {
|
||||
float nearest_tmp[3], dist_sq;
|
||||
@@ -276,12 +275,11 @@ static void mesh_looptri_nearest_point(void *userdata,
|
||||
BVHTreeNearest *nearest)
|
||||
{
|
||||
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
|
||||
const float(*positions)[3] = data->vert_positions;
|
||||
const MLoopTri *lt = &data->looptri[index];
|
||||
const MLoopTri *lt = &data->looptris[index];
|
||||
const float *vtri_co[3] = {
|
||||
positions[data->corner_verts[lt->tri[0]]],
|
||||
positions[data->corner_verts[lt->tri[1]]],
|
||||
positions[data->corner_verts[lt->tri[2]]],
|
||||
data->vert_positions[data->corner_verts[lt->tri[0]]],
|
||||
data->vert_positions[data->corner_verts[lt->tri[1]]],
|
||||
data->vert_positions[data->corner_verts[lt->tri[2]]],
|
||||
};
|
||||
float nearest_tmp[3], dist_sq;
|
||||
|
||||
@@ -336,14 +334,13 @@ static void mesh_faces_spherecast(void *userdata,
|
||||
BVHTreeRayHit *hit)
|
||||
{
|
||||
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
|
||||
const float(*positions)[3] = data->vert_positions;
|
||||
const MFace *face = &data->face[index];
|
||||
|
||||
const float *t0, *t1, *t2, *t3;
|
||||
t0 = positions[face->v1];
|
||||
t1 = positions[face->v2];
|
||||
t2 = positions[face->v3];
|
||||
t3 = face->v4 ? positions[face->v4] : nullptr;
|
||||
t0 = data->vert_positions[face->v1];
|
||||
t1 = data->vert_positions[face->v2];
|
||||
t2 = data->vert_positions[face->v3];
|
||||
t3 = face->v4 ? &data->vert_positions[face->v4].x : nullptr;
|
||||
|
||||
do {
|
||||
float dist;
|
||||
@@ -375,8 +372,8 @@ static void mesh_looptri_spherecast(void *userdata,
|
||||
BVHTreeRayHit *hit)
|
||||
{
|
||||
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
|
||||
const float(*positions)[3] = data->vert_positions;
|
||||
const MLoopTri *lt = &data->looptri[index];
|
||||
const Span<float3> positions = data->vert_positions;
|
||||
const MLoopTri *lt = &data->looptris[index];
|
||||
const float *vtri_co[3] = {
|
||||
positions[data->corner_verts[lt->tri[0]]],
|
||||
positions[data->corner_verts[lt->tri[1]]],
|
||||
@@ -444,8 +441,8 @@ static void mesh_edges_nearest_point(void *userdata,
|
||||
BVHTreeNearest *nearest)
|
||||
{
|
||||
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
|
||||
const float(*positions)[3] = data->vert_positions;
|
||||
const blender::int2 &edge = reinterpret_cast<const blender::int2 *>(data->edge)[index];
|
||||
const Span<float3> positions = data->vert_positions;
|
||||
const blender::int2 edge = data->edges[index];
|
||||
float nearest_tmp[3], dist_sq;
|
||||
|
||||
const float *t0, *t1;
|
||||
@@ -526,8 +523,8 @@ static void mesh_edges_spherecast(void *userdata,
|
||||
BVHTreeRayHit *hit)
|
||||
{
|
||||
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
|
||||
const float(*positions)[3] = data->vert_positions;
|
||||
const blender::int2 &edge = reinterpret_cast<const blender::int2 *>(data->edge)[index];
|
||||
const Span<float3> positions = data->vert_positions;
|
||||
const blender::int2 edge = data->edges[index];
|
||||
|
||||
const float radius_sq = square_f(ray->radius);
|
||||
float dist;
|
||||
@@ -577,22 +574,22 @@ static void mesh_edges_spherecast(void *userdata,
|
||||
|
||||
static void bvhtree_from_mesh_setup_data(BVHTree *tree,
|
||||
const BVHCacheType bvh_cache_type,
|
||||
const float (*positions)[3],
|
||||
const blender::int2 *edge,
|
||||
const MFace *face,
|
||||
const int *corner_verts,
|
||||
const Span<float3> positions,
|
||||
const Span<blender::int2> edges,
|
||||
const Span<int> corner_verts,
|
||||
const Span<MLoopTri> looptris,
|
||||
const MFace *face,
|
||||
BVHTreeFromMesh *r_data)
|
||||
{
|
||||
memset(r_data, 0, sizeof(*r_data));
|
||||
*r_data = {};
|
||||
|
||||
r_data->tree = tree;
|
||||
|
||||
r_data->vert_positions = positions;
|
||||
r_data->edge = reinterpret_cast<const vec2i *>(edge);
|
||||
r_data->edges = edges;
|
||||
r_data->face = face;
|
||||
r_data->corner_verts = corner_verts;
|
||||
r_data->looptri = looptris.data();
|
||||
r_data->looptris = looptris;
|
||||
|
||||
switch (bvh_cache_type) {
|
||||
case BVHTREE_FROM_VERTS:
|
||||
@@ -715,17 +712,16 @@ static BVHTree *bvhtree_from_editmesh_verts_create_tree(float epsilon,
|
||||
static BVHTree *bvhtree_from_mesh_verts_create_tree(float epsilon,
|
||||
int tree_type,
|
||||
int axis,
|
||||
const float (*positions)[3],
|
||||
const int verts_num,
|
||||
const Span<float3> positions,
|
||||
const BitSpan verts_mask,
|
||||
int verts_num_active)
|
||||
{
|
||||
BVHTree *tree = bvhtree_new_common(epsilon, tree_type, axis, verts_num, verts_num_active);
|
||||
BVHTree *tree = bvhtree_new_common(epsilon, tree_type, axis, positions.size(), verts_num_active);
|
||||
if (!tree) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (int i = 0; i < verts_num; i++) {
|
||||
for (const int i : positions.index_range()) {
|
||||
if (!verts_mask.is_empty() && !verts_mask[i]) {
|
||||
continue;
|
||||
}
|
||||
@@ -763,8 +759,7 @@ BVHTree *bvhtree_from_editmesh_verts(
|
||||
}
|
||||
|
||||
BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
|
||||
const float (*vert_positions)[3],
|
||||
const int verts_num,
|
||||
const Span<float3> vert_positions,
|
||||
const BitSpan verts_mask,
|
||||
int verts_num_active,
|
||||
float epsilon,
|
||||
@@ -772,14 +767,13 @@ BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
|
||||
int axis)
|
||||
{
|
||||
BVHTree *tree = bvhtree_from_mesh_verts_create_tree(
|
||||
epsilon, tree_type, axis, vert_positions, verts_num, verts_mask, verts_num_active);
|
||||
epsilon, tree_type, axis, vert_positions, verts_mask, verts_num_active);
|
||||
|
||||
bvhtree_balance(tree, false);
|
||||
|
||||
if (data) {
|
||||
/* Setup BVHTreeFromMesh */
|
||||
bvhtree_from_mesh_setup_data(
|
||||
tree, BVHTREE_FROM_VERTS, vert_positions, nullptr, nullptr, nullptr, {}, data);
|
||||
bvhtree_from_mesh_setup_data(tree, BVHTREE_FROM_VERTS, vert_positions, {}, {}, {}, {}, data);
|
||||
}
|
||||
|
||||
return tree;
|
||||
@@ -825,8 +819,8 @@ static BVHTree *bvhtree_from_editmesh_edges_create_tree(float epsilon,
|
||||
return tree;
|
||||
}
|
||||
|
||||
static BVHTree *bvhtree_from_mesh_edges_create_tree(const float (*positions)[3],
|
||||
blender::Span<blender::int2> edges,
|
||||
static BVHTree *bvhtree_from_mesh_edges_create_tree(const Span<float3> positions,
|
||||
const blender::Span<blender::int2> edges,
|
||||
const BitSpan edges_mask,
|
||||
int edges_num_active,
|
||||
float epsilon,
|
||||
@@ -879,9 +873,8 @@ BVHTree *bvhtree_from_editmesh_edges(
|
||||
}
|
||||
|
||||
BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
|
||||
const float (*vert_positions)[3],
|
||||
const blender::int2 *edge,
|
||||
const int edges_num,
|
||||
const Span<float3> vert_positions,
|
||||
const Span<blender::int2> edges,
|
||||
const BitSpan edges_mask,
|
||||
int edges_num_active,
|
||||
float epsilon,
|
||||
@@ -889,14 +882,14 @@ BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
|
||||
int axis)
|
||||
{
|
||||
BVHTree *tree = bvhtree_from_mesh_edges_create_tree(
|
||||
vert_positions, {edge, edges_num}, edges_mask, edges_num_active, epsilon, tree_type, axis);
|
||||
vert_positions, edges, edges_mask, edges_num_active, epsilon, tree_type, axis);
|
||||
|
||||
bvhtree_balance(tree, false);
|
||||
|
||||
if (data) {
|
||||
/* Setup BVHTreeFromMesh */
|
||||
bvhtree_from_mesh_setup_data(
|
||||
tree, BVHTREE_FROM_EDGES, vert_positions, edge, nullptr, nullptr, {}, data);
|
||||
tree, BVHTREE_FROM_EDGES, vert_positions, edges, {}, {}, {}, data);
|
||||
}
|
||||
|
||||
return tree;
|
||||
@@ -911,7 +904,7 @@ BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
|
||||
static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon,
|
||||
int tree_type,
|
||||
int axis,
|
||||
const float (*positions)[3],
|
||||
const Span<float3> positions,
|
||||
const MFace *face,
|
||||
const int faces_num,
|
||||
const BitSpan faces_mask,
|
||||
@@ -922,7 +915,7 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (positions && face) {
|
||||
if (!positions.is_empty() && face) {
|
||||
for (int i = 0; i < faces_num; i++) {
|
||||
float co[4][3];
|
||||
if (!faces_mask.is_empty() && !faces_mask[i]) {
|
||||
@@ -992,13 +985,13 @@ static BVHTree *bvhtree_from_editmesh_looptri_create_tree(float epsilon,
|
||||
static BVHTree *bvhtree_from_mesh_looptri_create_tree(float epsilon,
|
||||
int tree_type,
|
||||
int axis,
|
||||
const float (*positions)[3],
|
||||
const int *corner_verts,
|
||||
const Span<float3> positions,
|
||||
const Span<int> corner_verts,
|
||||
const Span<MLoopTri> looptris,
|
||||
const BitSpan looptri_mask,
|
||||
int looptri_num_active)
|
||||
{
|
||||
if (positions == nullptr) {
|
||||
if (positions.is_empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -1055,10 +1048,9 @@ BVHTree *bvhtree_from_editmesh_looptri(
|
||||
}
|
||||
|
||||
BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
|
||||
const float (*vert_positions)[3],
|
||||
const int *corner_verts,
|
||||
const MLoopTri *looptri,
|
||||
const int looptri_num,
|
||||
const Span<float3> vert_positions,
|
||||
const Span<int> corner_verts,
|
||||
const Span<MLoopTri> looptris,
|
||||
const BitSpan looptri_mask,
|
||||
int looptri_num_active,
|
||||
float epsilon,
|
||||
@@ -1070,7 +1062,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
|
||||
axis,
|
||||
vert_positions,
|
||||
corner_verts,
|
||||
{looptri, looptri_num},
|
||||
looptris,
|
||||
looptri_mask,
|
||||
looptri_num_active);
|
||||
|
||||
@@ -1078,14 +1070,8 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
|
||||
|
||||
if (data) {
|
||||
/* Setup BVHTreeFromMesh */
|
||||
bvhtree_from_mesh_setup_data(tree,
|
||||
BVHTREE_FROM_LOOPTRI,
|
||||
vert_positions,
|
||||
nullptr,
|
||||
nullptr,
|
||||
corner_verts,
|
||||
{looptri, looptri_num},
|
||||
data);
|
||||
bvhtree_from_mesh_setup_data(
|
||||
tree, BVHTREE_FROM_LOOPTRI, vert_positions, {}, corner_verts, looptris, nullptr, data);
|
||||
}
|
||||
|
||||
return tree;
|
||||
@@ -1134,7 +1120,8 @@ BVHTree *BKE_bvhtree_from_mesh_get(BVHTreeFromMesh *data,
|
||||
if (ELEM(bvh_cache_type, BVHTREE_FROM_LOOPTRI, BVHTREE_FROM_LOOPTRI_NO_HIDDEN)) {
|
||||
looptris = mesh->looptris();
|
||||
}
|
||||
const float(*positions)[3] = reinterpret_cast<const float(*)[3]>(mesh->vert_positions().data());
|
||||
|
||||
const Span<float3> positions = mesh->vert_positions();
|
||||
const Span<blender::int2> edges = mesh->edges();
|
||||
const Span<int> corner_verts = mesh->corner_verts();
|
||||
|
||||
@@ -1142,10 +1129,10 @@ BVHTree *BKE_bvhtree_from_mesh_get(BVHTreeFromMesh *data,
|
||||
bvhtree_from_mesh_setup_data(nullptr,
|
||||
bvh_cache_type,
|
||||
positions,
|
||||
edges.data(),
|
||||
(const MFace *)CustomData_get_layer(&mesh->fdata_legacy, CD_MFACE),
|
||||
corner_verts.data(),
|
||||
edges,
|
||||
corner_verts,
|
||||
looptris,
|
||||
(const MFace *)CustomData_get_layer(&mesh->fdata_legacy, CD_MFACE),
|
||||
data);
|
||||
|
||||
bool lock_started = false;
|
||||
@@ -1164,18 +1151,12 @@ BVHTree *BKE_bvhtree_from_mesh_get(BVHTreeFromMesh *data,
|
||||
switch (bvh_cache_type) {
|
||||
case BVHTREE_FROM_LOOSEVERTS: {
|
||||
const blender::bke::LooseVertCache &loose_verts = mesh->loose_verts();
|
||||
data->tree = bvhtree_from_mesh_verts_create_tree(0.0f,
|
||||
tree_type,
|
||||
6,
|
||||
positions,
|
||||
mesh->totvert,
|
||||
loose_verts.is_loose_bits,
|
||||
loose_verts.count);
|
||||
data->tree = bvhtree_from_mesh_verts_create_tree(
|
||||
0.0f, tree_type, 6, positions, loose_verts.is_loose_bits, loose_verts.count);
|
||||
break;
|
||||
}
|
||||
case BVHTREE_FROM_VERTS: {
|
||||
data->tree = bvhtree_from_mesh_verts_create_tree(
|
||||
0.0f, tree_type, 6, positions, mesh->totvert, {}, -1);
|
||||
data->tree = bvhtree_from_mesh_verts_create_tree(0.0f, tree_type, 6, positions, {}, -1);
|
||||
break;
|
||||
}
|
||||
case BVHTREE_FROM_LOOSEEDGES: {
|
||||
@@ -1211,12 +1192,12 @@ BVHTree *BKE_bvhtree_from_mesh_get(BVHTreeFromMesh *data,
|
||||
looptris.size(),
|
||||
&mask_bits_act_len);
|
||||
data->tree = bvhtree_from_mesh_looptri_create_tree(
|
||||
0.0f, tree_type, 6, positions, corner_verts.data(), looptris, mask, mask_bits_act_len);
|
||||
0.0f, tree_type, 6, positions, corner_verts, looptris, mask, mask_bits_act_len);
|
||||
break;
|
||||
}
|
||||
case BVHTREE_FROM_LOOPTRI: {
|
||||
data->tree = bvhtree_from_mesh_looptri_create_tree(
|
||||
0.0f, tree_type, 6, positions, corner_verts.data(), looptris, {}, -1);
|
||||
0.0f, tree_type, 6, positions, corner_verts, looptris, {}, -1);
|
||||
break;
|
||||
}
|
||||
case BVHTREE_FROM_EM_LOOSEVERTS:
|
||||
@@ -1361,7 +1342,7 @@ void free_bvhtree_from_mesh(BVHTreeFromMesh *data)
|
||||
BLI_bvhtree_free(data->tree);
|
||||
}
|
||||
|
||||
memset(data, 0, sizeof(*data));
|
||||
*data = {};
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -1420,7 +1420,7 @@ static bool find_internal_spring_target_vertex(BVHTreeFromMesh *treedata,
|
||||
treedata->tree, new_co, no, radius, &rayhit, treedata->raycast_callback, treedata);
|
||||
|
||||
int vert_idx = -1;
|
||||
const int *corner_verts = treedata->corner_verts;
|
||||
const int *corner_verts = treedata->corner_verts.data();
|
||||
const MLoopTri *lt = nullptr;
|
||||
|
||||
if (rayhit.index != -1 && rayhit.dist <= max_length) {
|
||||
@@ -1430,7 +1430,7 @@ static bool find_internal_spring_target_vertex(BVHTreeFromMesh *treedata,
|
||||
}
|
||||
|
||||
float min_len = FLT_MAX;
|
||||
lt = &treedata->looptri[rayhit.index];
|
||||
lt = &treedata->looptris[rayhit.index];
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int tmp_vert_idx = corner_verts[lt->tri[i]];
|
||||
|
||||
@@ -3448,9 +3448,9 @@ static void mesh_tris_spherecast_dp(void *userdata,
|
||||
BVHTreeRayHit *hit)
|
||||
{
|
||||
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
|
||||
const float(*positions)[3] = data->vert_positions;
|
||||
const MLoopTri *looptris = data->looptri;
|
||||
const int *corner_verts = data->corner_verts;
|
||||
const blender::Span<blender::float3> positions = data->vert_positions;
|
||||
const MLoopTri *looptris = data->looptris.data();
|
||||
const int *corner_verts = data->corner_verts.data();
|
||||
|
||||
const float *t0, *t1, *t2;
|
||||
float dist;
|
||||
@@ -3480,9 +3480,9 @@ static void mesh_tris_nearest_point_dp(void *userdata,
|
||||
BVHTreeNearest *nearest)
|
||||
{
|
||||
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
|
||||
const float(*positions)[3] = data->vert_positions;
|
||||
const MLoopTri *looptris = data->looptri;
|
||||
const int *corner_verts = data->corner_verts;
|
||||
const blender::Span<blender::float3> positions = data->vert_positions;
|
||||
const MLoopTri *looptris = data->looptris.data();
|
||||
const int *corner_verts = data->corner_verts.data();
|
||||
float nearest_tmp[3], dist_sq;
|
||||
|
||||
const float *t0, *t1, *t2;
|
||||
|
||||
@@ -670,8 +670,8 @@ bool closest_point_on_surface(SurfaceModifierData *surmd,
|
||||
}
|
||||
|
||||
if (surface_vel) {
|
||||
const int *corner_verts = bvhtree->corner_verts;
|
||||
const MLoopTri *lt = &bvhtree->looptri[nearest.index];
|
||||
const int *corner_verts = bvhtree->corner_verts.data();
|
||||
const MLoopTri *lt = &bvhtree->looptris[nearest.index];
|
||||
|
||||
copy_v3_v3(surface_vel, surmd->runtime.vert_velocities[corner_verts[lt->tri[0]]]);
|
||||
add_v3_v3(surface_vel, surmd->runtime.vert_velocities[corner_verts[lt->tri[1]]]);
|
||||
|
||||
@@ -1431,14 +1431,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
||||
}
|
||||
}
|
||||
}
|
||||
bvhtree_from_mesh_verts_ex(&treedata[tindex],
|
||||
reinterpret_cast<const float(*)[3]>(positions_src.data()),
|
||||
num_verts_src,
|
||||
verts_active,
|
||||
num_verts_active,
|
||||
0.0,
|
||||
2,
|
||||
6);
|
||||
bvhtree_from_mesh_verts_ex(
|
||||
&treedata[tindex], positions_src, verts_active, num_verts_active, 0.0, 2, 6);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1463,10 +1457,9 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
||||
}
|
||||
}
|
||||
bvhtree_from_mesh_looptri_ex(&treedata[tindex],
|
||||
reinterpret_cast<const float(*)[3]>(positions_src.data()),
|
||||
corner_verts_src.data(),
|
||||
looptris_src.data(),
|
||||
int(looptris_src.size()),
|
||||
positions_src,
|
||||
corner_verts_src,
|
||||
looptris_src,
|
||||
looptri_active,
|
||||
num_looptri_active,
|
||||
0.0,
|
||||
|
||||
@@ -102,7 +102,7 @@ bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode)
|
||||
bool BKE_shrinkwrap_init_tree(
|
||||
ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals)
|
||||
{
|
||||
memset(data, 0, sizeof(*data));
|
||||
*data = {};
|
||||
|
||||
if (mesh == nullptr) {
|
||||
return false;
|
||||
@@ -118,11 +118,11 @@ bool BKE_shrinkwrap_init_tree(
|
||||
}
|
||||
|
||||
data->mesh = mesh;
|
||||
data->face_offsets = mesh->face_offsets().data();
|
||||
data->corner_edges = mesh->corner_edges().data();
|
||||
data->vert_normals = reinterpret_cast<const float(*)[3]>(mesh->vert_normals().data());
|
||||
data->faces = mesh->faces();
|
||||
data->corner_edges = mesh->corner_edges();
|
||||
data->vert_normals = mesh->vert_normals();
|
||||
data->sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&mesh->edge_data, CD_PROP_BOOL, "sharp_face"));
|
||||
CustomData_get_layer_named(&mesh->face_data, CD_PROP_BOOL, "sharp_face"));
|
||||
|
||||
if (shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX) {
|
||||
data->bvh = BKE_bvhtree_from_mesh_get(&data->treeData, mesh, BVHTREE_FROM_VERTS, 2);
|
||||
@@ -141,9 +141,9 @@ bool BKE_shrinkwrap_init_tree(
|
||||
}
|
||||
|
||||
if (force_normals || BKE_shrinkwrap_needs_normals(shrinkType, shrinkMode)) {
|
||||
data->face_normals = reinterpret_cast<const float(*)[3]>(mesh->face_normals().data());
|
||||
data->face_normals = mesh->face_normals();
|
||||
if (mesh->normals_domain() == blender::bke::MeshNormalDomain::Corner) {
|
||||
data->clnors = reinterpret_cast<const float(*)[3]>(mesh->corner_normals().data());
|
||||
data->corner_normals = mesh->corner_normals();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -947,7 +947,7 @@ static void target_project_edge(const ShrinkwrapTreeData *tree,
|
||||
int eidx)
|
||||
{
|
||||
const BVHTreeFromMesh *data = &tree->treeData;
|
||||
const blender::int2 &edge = reinterpret_cast<const blender::int2 *>(data->edge)[eidx];
|
||||
const blender::int2 &edge = data->edges[eidx];
|
||||
const float *vedge_co[2] = {data->vert_positions[edge[0]], data->vert_positions[edge[1]]};
|
||||
|
||||
#ifdef TRACE_TARGET_PROJECT
|
||||
@@ -1021,9 +1021,10 @@ static void mesh_looptri_target_project(void *userdata,
|
||||
const float co[3],
|
||||
BVHTreeNearest *nearest)
|
||||
{
|
||||
using namespace blender;
|
||||
const ShrinkwrapTreeData *tree = (ShrinkwrapTreeData *)userdata;
|
||||
const BVHTreeFromMesh *data = &tree->treeData;
|
||||
const MLoopTri *lt = &data->looptri[index];
|
||||
const MLoopTri *lt = &data->looptris[index];
|
||||
const int tri_verts[3] = {data->corner_verts[lt->tri[0]],
|
||||
data->corner_verts[lt->tri[1]],
|
||||
data->corner_verts[lt->tri[2]]};
|
||||
@@ -1064,11 +1065,8 @@ static void mesh_looptri_target_project(void *userdata,
|
||||
const BLI_bitmap *is_boundary = tree->boundary->edge_is_boundary;
|
||||
int edges[3];
|
||||
|
||||
BKE_mesh_looptri_get_real_edges(reinterpret_cast<const blender::int2 *>(data->edge),
|
||||
data->corner_verts,
|
||||
tree->corner_edges,
|
||||
lt,
|
||||
edges);
|
||||
BKE_mesh_looptri_get_real_edges(
|
||||
data->edges.data(), data->corner_verts.data(), tree->corner_edges.data(), lt, edges);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (edges[i] >= 0 && BLI_BITMAP_TEST(is_boundary, edges[i])) {
|
||||
@@ -1190,8 +1188,7 @@ void BKE_shrinkwrap_compute_smooth_normal(const ShrinkwrapTreeData *tree,
|
||||
float r_no[3])
|
||||
{
|
||||
const BVHTreeFromMesh *treeData = &tree->treeData;
|
||||
const MLoopTri *tri = &treeData->looptri[looptri_idx];
|
||||
const float(*vert_normals)[3] = tree->vert_normals;
|
||||
const MLoopTri *tri = &treeData->looptris[looptri_idx];
|
||||
const int face_i = tree->mesh->looptri_faces()[looptri_idx];
|
||||
|
||||
/* Interpolate smooth normals if enabled. */
|
||||
@@ -1202,16 +1199,16 @@ void BKE_shrinkwrap_compute_smooth_normal(const ShrinkwrapTreeData *tree,
|
||||
float w[3], no[3][3], tmp_co[3];
|
||||
|
||||
/* Custom and auto smooth split normals. */
|
||||
if (tree->clnors) {
|
||||
copy_v3_v3(no[0], tree->clnors[tri->tri[0]]);
|
||||
copy_v3_v3(no[1], tree->clnors[tri->tri[1]]);
|
||||
copy_v3_v3(no[2], tree->clnors[tri->tri[2]]);
|
||||
if (!tree->corner_normals.is_empty()) {
|
||||
copy_v3_v3(no[0], tree->corner_normals[tri->tri[0]]);
|
||||
copy_v3_v3(no[1], tree->corner_normals[tri->tri[1]]);
|
||||
copy_v3_v3(no[2], tree->corner_normals[tri->tri[2]]);
|
||||
}
|
||||
/* Ordinary vertex normals. */
|
||||
else {
|
||||
copy_v3_v3(no[0], vert_normals[vert_indices[0]]);
|
||||
copy_v3_v3(no[1], vert_normals[vert_indices[1]]);
|
||||
copy_v3_v3(no[2], vert_normals[vert_indices[2]]);
|
||||
copy_v3_v3(no[0], tree->vert_normals[vert_indices[0]]);
|
||||
copy_v3_v3(no[1], tree->vert_normals[vert_indices[1]]);
|
||||
copy_v3_v3(no[2], tree->vert_normals[vert_indices[2]]);
|
||||
}
|
||||
|
||||
/* Barycentric weights from hit point. */
|
||||
@@ -1238,7 +1235,7 @@ void BKE_shrinkwrap_compute_smooth_normal(const ShrinkwrapTreeData *tree,
|
||||
}
|
||||
}
|
||||
/* Use the face normal if flat. */
|
||||
else if (tree->face_normals != nullptr) {
|
||||
else if (!tree->face_normals.is_empty()) {
|
||||
copy_v3_v3(r_no, tree->face_normals[face_i]);
|
||||
}
|
||||
/* Finally fallback to the looptri normal. */
|
||||
|
||||
@@ -497,7 +497,7 @@ struct PEData {
|
||||
|
||||
static void PE_set_data(bContext *C, PEData *data)
|
||||
{
|
||||
memset(data, 0, sizeof(*data));
|
||||
*data = {};
|
||||
|
||||
data->context = C;
|
||||
data->bmain = CTX_data_main(C);
|
||||
@@ -529,7 +529,7 @@ static bool PE_create_shape_tree(PEData *data, Object *shapeob)
|
||||
Object *shapeob_eval = DEG_get_evaluated_object(data->depsgraph, shapeob);
|
||||
const Mesh *mesh = BKE_object_get_evaluated_mesh(shapeob_eval);
|
||||
|
||||
memset(&data->shape_bvh, 0, sizeof(data->shape_bvh));
|
||||
data->shape_bvh = {};
|
||||
|
||||
if (!mesh) {
|
||||
return false;
|
||||
|
||||
@@ -55,12 +55,12 @@ static void mesh_looptri_raycast_backface_culling_cb(void *userdata,
|
||||
BVHTreeRayHit *hit)
|
||||
{
|
||||
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
|
||||
const float(*vert_positions)[3] = data->vert_positions;
|
||||
const MLoopTri *lt = &data->looptri[index];
|
||||
const blender::Span<blender::float3> positions = data->vert_positions;
|
||||
const MLoopTri *lt = &data->looptris[index];
|
||||
const float *vtri_co[3] = {
|
||||
vert_positions[data->corner_verts[lt->tri[0]]],
|
||||
vert_positions[data->corner_verts[lt->tri[1]]],
|
||||
vert_positions[data->corner_verts[lt->tri[2]]],
|
||||
positions[data->corner_verts[lt->tri[0]]],
|
||||
positions[data->corner_verts[lt->tri[1]]],
|
||||
positions[data->corner_verts[lt->tri[2]]],
|
||||
};
|
||||
float dist = bvhtree_ray_tri_intersection(ray, hit->dist, UNPACK3(vtri_co));
|
||||
|
||||
|
||||
@@ -566,7 +566,6 @@ bool RE_bake_pixels_populate_from_objects(Mesh *me_low,
|
||||
|
||||
Mesh *me_eval_low = nullptr;
|
||||
Mesh **me_highpoly;
|
||||
BVHTreeFromMesh *treeData;
|
||||
|
||||
/* NOTE: all coordinates are in local space. */
|
||||
TriTessFace *tris_low = nullptr;
|
||||
@@ -579,7 +578,7 @@ bool RE_bake_pixels_populate_from_objects(Mesh *me_low,
|
||||
/* Assume all high-poly tessfaces are triangles. */
|
||||
me_highpoly = static_cast<Mesh **>(
|
||||
MEM_mallocN(sizeof(Mesh *) * tot_highpoly, "Highpoly Derived Meshes"));
|
||||
treeData = MEM_cnew_array<BVHTreeFromMesh>(tot_highpoly, "Highpoly BVH Trees");
|
||||
blender::Array<BVHTreeFromMesh> treeData(tot_highpoly);
|
||||
|
||||
if (!is_cage) {
|
||||
me_eval_low = BKE_mesh_copy_for_eval(me_low);
|
||||
@@ -646,7 +645,7 @@ bool RE_bake_pixels_populate_from_objects(Mesh *me_low,
|
||||
}
|
||||
|
||||
/* cast ray */
|
||||
if (!cast_ray_highpoly(treeData,
|
||||
if (!cast_ray_highpoly(treeData.data(),
|
||||
tri_low,
|
||||
tris_high,
|
||||
pixel_array_from,
|
||||
@@ -675,7 +674,6 @@ cleanup:
|
||||
}
|
||||
|
||||
MEM_freeN(tris_high);
|
||||
MEM_freeN(treeData);
|
||||
MEM_freeN(me_highpoly);
|
||||
|
||||
if (me_eval_low) {
|
||||
|
||||
Reference in New Issue
Block a user