Cleanup: Deduplicate Alembic procedural bounding box mesh creation
This removes the manual construction of a box mesh in the mesh sequence cache modifier when the Alembic procedural is enabled. It also removes the use of `BKE_object_boundbox_get` which doesn't make sense on a non-evaluated object. Differential Revision: https://developer.blender.org/D14958
This commit is contained in:
parent
51195c17ac
commit
f11401d32a
|
@ -16,4 +16,6 @@ namespace blender::geometry {
|
|||
Mesh *create_cuboid_mesh(
|
||||
const float3 &size, int verts_x, int verts_y, int verts_z, const bke::AttributeIDRef &uv_id);
|
||||
|
||||
Mesh *create_cuboid_mesh(const float3 &size, int verts_x, int verts_y, int verts_z);
|
||||
|
||||
} // namespace blender::geometry
|
||||
|
|
|
@ -420,4 +420,12 @@ Mesh *create_cuboid_mesh(const float3 &size,
|
|||
return mesh;
|
||||
}
|
||||
|
||||
Mesh *create_cuboid_mesh(const float3 &size,
|
||||
const int verts_x,
|
||||
const int verts_y,
|
||||
const int verts_z)
|
||||
{
|
||||
return create_cuboid_mesh(size, verts_x, verts_y, verts_z, {});
|
||||
}
|
||||
|
||||
} // namespace blender::geometry
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
|
||||
#include "BLI_math_vector.h"
|
||||
#include "BLI_math_vector.hh"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
|
@ -15,7 +16,6 @@
|
|||
#include "DNA_cachefile_types.h"
|
||||
#include "DNA_defaults.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
@ -42,6 +42,8 @@
|
|||
#include "DEG_depsgraph_build.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "GEO_mesh_primitive_cuboid.hh"
|
||||
|
||||
#include "MOD_modifiertypes.h"
|
||||
#include "MOD_ui_common.h"
|
||||
|
||||
|
@ -104,40 +106,17 @@ static bool isDisabled(const struct Scene *UNUSED(scene),
|
|||
return (mcmd->cache_file == nullptr) || (mcmd->object_path[0] == '\0');
|
||||
}
|
||||
|
||||
static Mesh *generate_bounding_box_mesh(Object *object, Mesh *org_mesh)
|
||||
static Mesh *generate_bounding_box_mesh(const Mesh *org_mesh)
|
||||
{
|
||||
const BoundBox *bb = BKE_object_boundbox_get(object);
|
||||
Mesh *result = BKE_mesh_new_nomain_from_template(org_mesh, 8, 0, 0, 24, 6);
|
||||
|
||||
MVert *mvert = result->mvert;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
copy_v3_v3(mvert[i].co, bb->vec[i]);
|
||||
using namespace blender;
|
||||
float3 min(std::numeric_limits<float>::max());
|
||||
float3 max(-std::numeric_limits<float>::max());
|
||||
if (!BKE_mesh_minmax(org_mesh, min, max)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* See DNA_object_types.h for the diagram showing the order of the vertices for a BoundBox. */
|
||||
static unsigned int loops_v[6][4] = {
|
||||
{0, 4, 5, 1},
|
||||
{4, 7, 6, 5},
|
||||
{7, 3, 2, 6},
|
||||
{3, 0, 1, 2},
|
||||
{1, 5, 6, 2},
|
||||
{3, 7, 4, 0},
|
||||
};
|
||||
|
||||
MLoop *mloop = result->mloop;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
for (int j = 0; j < 4; ++j, ++mloop) {
|
||||
mloop->v = loops_v[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
MPoly *mpoly = result->mpoly;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
mpoly[i].loopstart = i * 4;
|
||||
mpoly[i].totloop = 4;
|
||||
}
|
||||
|
||||
BKE_mesh_calc_edges(result, false, false);
|
||||
Mesh *result = geometry::create_cuboid_mesh(max - min, 2, 2, 2);
|
||||
BKE_mesh_translate(result, math::midpoint(min, max), false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -170,7 +149,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
|||
/* Do not process data if using a render procedural, return a box instead for displaying in the
|
||||
* viewport. */
|
||||
if (BKE_cache_file_uses_render_procedural(cache_file, scene)) {
|
||||
return generate_bounding_box_mesh(ctx->object, org_mesh);
|
||||
return generate_bounding_box_mesh(org_mesh);
|
||||
}
|
||||
|
||||
/* If this invocation is for the ORCO mesh, and the mesh hasn't changed topology, we
|
||||
|
|
Loading…
Reference in New Issue