Curves: cage overlay for sculpt mode #104467

Merged
Jacques Lucke merged 44 commits from JacquesLucke/blender:sculpt-edit-overlay into main 2023-02-14 18:10:24 +01:00
3 changed files with 20 additions and 38 deletions
Showing only changes of commit ca20af7884 - Show all commits

View File

@ -324,35 +324,38 @@ void BKE_curves_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Ob
Curves *curves = static_cast<Curves *>(object->data);
GeometrySet geometry_set = GeometrySet::create_with_curves(curves,
GeometryOwnershipType::ReadOnly);
if (object->mode == OB_MODE_SCULPT_CURVES) {
const bool generate_cage = ELEM(object->mode, OB_MODE_EDIT, OB_MODE_SCULPT_CURVES);
const Curves &curves_id_orig = *static_cast<const Curves *>(
DEG_get_original_object(object)->data);
if (generate_cage) {
/* Try to propagate deformation data through modifier evaluation, so that sculpt mode can work
* on evaluated curves. */
GeometryComponentEditData &edit_component =
geometry_set.get_component_for_write<GeometryComponentEditData>();
edit_component.curves_edit_hints_ = std::make_unique<blender::bke::CurvesEditHints>(
*static_cast<const Curves *>(DEG_get_original_object(object)->data));
curves_id_orig);
}
curves_evaluate_modifiers(depsgraph, scene, object, geometry_set);
/* Create cage curves geometry for drawing. */
if (const blender::bke::CurvesEditHints *curve_edit_hints =
geometry_set.get_curve_edit_hints_for_read()) {
const Curves &curves_id_orig = curve_edit_hints->curves_id_orig;
if (generate_cage) {
const blender::bke::CurvesGeometry &curves_orig = blender::bke::CurvesGeometry::wrap(
curves_id_orig.geometry);
Curves *curves_id_cage = blender::bke::curves_new_nomain(curves_id_orig.geometry.point_num,
curves_id_orig.geometry.curve_num);
blender::bke::CurvesGeometry &curves_cage = blender::bke::CurvesGeometry::wrap(
curves_id_cage->geometry);
if (curve_edit_hints->positions.has_value()) {
curves_cage.offsets_for_write().copy_from(curves_orig.offsets());
curves_cage.fill_curve_types(CURVE_TYPE_POLY);
object->runtime.editcurves_eval_cage = curves_id_cage;
const blender::bke::CurvesEditHints *curve_edit_hints =
geometry_set.get_curve_edit_hints_for_read();
if (curve_edit_hints && curve_edit_hints->positions.has_value()) {
curves_cage.positions_for_write().copy_from(*curve_edit_hints->positions);
}
else {
curves_cage.positions_for_write().copy_from(curves_orig.positions());
}
curves_cage.offsets_for_write().copy_from(curves_orig.offsets());
curves_cage.fill_curve_types(CURVE_TYPE_POLY);
object->runtime.editcurves_eval_cage = curves_id_cage;
}
/* Assign evaluated object. */

View File

@ -54,14 +54,17 @@ void OVERLAY_edit_curves_cache_init(OVERLAY_Data *vedata)
static void overlay_edit_curves_add_ob_to_pass(OVERLAY_PrivateData *pd, Object *ob, bool in_front)
{
Curves *curves = static_cast<Curves *>(ob->data);
Curves *curves_id_cage = ob->runtime.editcurves_eval_cage;
if (curves_id_cage == nullptr) {
return;
}
DRWShadingGroup *point_shgrp = pd->edit_curves_points_grp[in_front];
struct GPUBatch *geom_points = DRW_curves_batch_cache_get_edit_points(curves);
struct GPUBatch *geom_points = DRW_curves_batch_cache_get_edit_points(curves_id_cage);
DRW_shgroup_call_no_cull(point_shgrp, geom_points, ob);
DRWShadingGroup *lines_shgrp = pd->edit_curves_lines_grp[in_front];
struct GPUBatch *geom_lines = DRW_curves_batch_cache_get_edit_lines(curves);
struct GPUBatch *geom_lines = DRW_curves_batch_cache_get_edit_lines(curves_id_cage);
DRW_shgroup_call_no_cull(lines_shgrp, geom_lines, ob);
}

View File

@ -55,7 +55,7 @@ struct CurvesBatchCache {
GPUBatch *edit_points;
GPUBatch *edit_lines;
/* Editmode (original) point positions. */
/* Positions edited in edit/sculpt mode. */
GPUVertBuf *edit_points_pos;
/* Editmode data (such as selection). */
@ -750,15 +750,10 @@ GPUVertBuf **DRW_curves_texture_for_evaluated_attribute(Curves *curves,
void DRW_curves_batch_cache_create_requested(Object *ob)
{
Curves *curves = static_cast<Curves *>(ob->data);
Object *orig = DEG_get_original_object(ob);
Curves *curves_orig = static_cast<Curves *>(orig->data);
Curves *curves_cage = ob->runtime.editcurves_eval_cage;
CurvesBatchCache &cache = curves_batch_cache_get(*curves);
if (curves_cage) {
CurvesBatchCache &cage_cache = curves_batch_cache_get(*curves_cage);
if (DRW_batch_requested(cage_cache.edit_points, GPU_PRIM_POINTS)) {
DRW_vbo_request(cage_cache.edit_points, &cage_cache.edit_points_pos);
DRW_vbo_request(cage_cache.edit_points, &cage_cache.edit_points_data);
@ -778,23 +773,4 @@ void DRW_curves_batch_cache_create_requested(Object *ob)
curves_batch_cache_ensure_edit_lines(*curves_cage, cage_cache);
}
}
if (DRW_batch_requested(cache.edit_points, GPU_PRIM_POINTS)) {
DRW_vbo_request(cache.edit_points, &cache.edit_points_pos);
DRW_vbo_request(cache.edit_points, &cache.edit_points_data);
}
if (DRW_batch_requested(cache.edit_lines, GPU_PRIM_LINE_STRIP)) {
DRW_ibo_request(cache.edit_lines, &cache.edit_lines_ibo);
DRW_vbo_request(cache.edit_lines, &cache.edit_points_pos);
DRW_vbo_request(cache.edit_lines, &cache.edit_points_data);
}
if (DRW_vbo_requested(cache.edit_points_pos)) {
curves_batch_cache_ensure_edit_points_pos(*curves_orig, cache);
}
if (DRW_vbo_requested(cache.edit_points_data)) {
curves_batch_cache_ensure_edit_points_data(*curves_orig, cache);
}
if (DRW_ibo_requested(cache.edit_lines_ibo)) {
curves_batch_cache_ensure_edit_lines(*curves_orig, cache);
}
}