Modifiers: return empty mesh in case of error in Volume to Mesh modifier
Passing on the original mesh does not really make sense. For that one should simply disable the modifier.
This commit is contained in:
parent
cfcdae5549
commit
27648ed537
|
@ -262,23 +262,30 @@ static Mesh *new_mesh_from_openvdb_data(Span<openvdb::Vec3s> verts,
|
|||
}
|
||||
#endif
|
||||
|
||||
static Mesh *create_empty_mesh(const Mesh *input_mesh)
|
||||
{
|
||||
Mesh *new_mesh = BKE_mesh_new_nomain(0, 0, 0, 0, 0);
|
||||
BKE_mesh_copy_settings(new_mesh, input_mesh);
|
||||
return new_mesh;
|
||||
}
|
||||
|
||||
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *input_mesh)
|
||||
{
|
||||
#ifdef WITH_OPENVDB
|
||||
VolumeToMeshModifierData *vmmd = reinterpret_cast<VolumeToMeshModifierData *>(md);
|
||||
if (vmmd->object == nullptr) {
|
||||
return input_mesh;
|
||||
return create_empty_mesh(input_mesh);
|
||||
}
|
||||
if (vmmd->object->type != OB_VOLUME) {
|
||||
return input_mesh;
|
||||
return create_empty_mesh(input_mesh);
|
||||
}
|
||||
if (vmmd->resolution_mode == VOLUME_TO_MESH_RESOLUTION_MODE_VOXEL_SIZE &&
|
||||
vmmd->voxel_size == 0.0f) {
|
||||
return input_mesh;
|
||||
return create_empty_mesh(input_mesh);
|
||||
}
|
||||
if (vmmd->resolution_mode == VOLUME_TO_MESH_RESOLUTION_MODE_VOXEL_AMOUNT &&
|
||||
vmmd->voxel_amount == 0) {
|
||||
return input_mesh;
|
||||
return create_empty_mesh(input_mesh);
|
||||
}
|
||||
|
||||
Volume *volume = static_cast<Volume *>(vmmd->object->data);
|
||||
|
@ -287,7 +294,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
|||
VolumeGrid *volume_grid = BKE_volume_grid_find(volume, vmmd->grid_name);
|
||||
if (volume_grid == nullptr) {
|
||||
BKE_modifier_set_error(md, "Cannot find '%s' grid", vmmd->grid_name);
|
||||
return input_mesh;
|
||||
return create_empty_mesh(input_mesh);
|
||||
}
|
||||
|
||||
const openvdb::GridBase::ConstPtr grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid);
|
||||
|
@ -296,7 +303,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
|||
VolumeToMeshOp to_mesh_op{*grid, *vmmd, *ctx};
|
||||
if (!BKE_volume_grid_type_operation(grid_type, to_mesh_op)) {
|
||||
BKE_modifier_set_error(md, "Expected a scalar grid");
|
||||
return input_mesh;
|
||||
return create_empty_mesh(input_mesh);
|
||||
}
|
||||
|
||||
Mesh *mesh = new_mesh_from_openvdb_data(to_mesh_op.verts, to_mesh_op.tris, to_mesh_op.quads);
|
||||
|
@ -308,7 +315,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
|||
#else
|
||||
UNUSED_VARS(md, ctx);
|
||||
BKE_modifier_set_error(md, "Compiled without OpenVDB");
|
||||
return input_mesh;
|
||||
return create_empty_mesh(input_mesh);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue