[Bf-blender-cvs] [e0c8d0913b9] master: Curves: remove Test1 brush

Jacques Lucke noreply at git.blender.org
Wed Apr 13 09:28:06 CEST 2022


Commit: e0c8d0913b96922844912d6c07aba099b42edd79
Author: Jacques Lucke
Date:   Wed Apr 13 09:27:54 2022 +0200
Branches: master
https://developer.blender.org/rBe0c8d0913b96922844912d6c07aba099b42edd79

Curves: remove Test1 brush

This was one of multiple placeholder brushes to simplify development.
Having it is not necessary anymore.

It was a brush that could add new curves according to a specific density.
This functionality will be brought back as a new brush later.

Ref T97255.

===================================================================

M	source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesrna/intern/rna_brush.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
index dcfda658bbd..992ac77803a 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
@@ -74,431 +74,6 @@ using blender::bke::CurvesGeometry;
 /** \name * SCULPT_CURVES_OT_brush_stroke
  * \{ */
 
-class DensityAddOperation : public CurvesSculptStrokeOperation {
- private:
-  /** Contains the root points of the curves that existed before this operation started. */
-  KDTree_3d *old_kdtree_ = nullptr;
-  /** Number of points in the kdtree above. */
-  int old_kdtree_size_ = 0;
-
-  /**
-   * Indicates that the corresponding curve has already been created and can't be changed by this
-   * operation anymore.
-   */
-  static constexpr int ExistsAlreadyIndex = INT32_MAX;
-
-  struct NewPointsData {
-    Vector<float3> bary_coords;
-    Vector<int> looptri_indices;
-    Vector<float3> positions;
-    Vector<float3> normals;
-  };
-
- public:
-  ~DensityAddOperation() override
-  {
-    if (old_kdtree_ != nullptr) {
-      BLI_kdtree_3d_free(old_kdtree_);
-    }
-  }
-
-  void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) override
-  {
-    Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
-    Scene &scene = *CTX_data_scene(C);
-    Object &object = *CTX_data_active_object(C);
-    ARegion *region = CTX_wm_region(C);
-    View3D *v3d = CTX_wm_view3d(C);
-
-    Curves &curves_id = *static_cast<Curves *>(object.data);
-    CurvesGeometry &curves = CurvesGeometry::wrap(curves_id.geometry);
-
-    if (curves_id.surface == nullptr || curves_id.surface->type != OB_MESH) {
-      return;
-    }
-
-    const Object &surface_ob = *curves_id.surface;
-    const Mesh &surface = *static_cast<const Mesh *>(surface_ob.data);
-    const float4x4 surface_ob_mat = surface_ob.obmat;
-    const float4x4 surface_ob_imat = surface_ob_mat.inverted();
-
-    ToolSettings &tool_settings = *scene.toolsettings;
-    CurvesSculpt &curves_sculpt = *tool_settings.curves_sculpt;
-    Brush &brush = *BKE_paint_brush(&curves_sculpt.paint);
-    const float brush_radius_screen = BKE_brush_size_get(&scene, &brush);
-    const float strength = BKE_brush_alpha_get(&scene, &brush);
-    const float minimum_distance = curves_sculpt.distance;
-
-    /* This is the main ray that is used to determine the brush position in 3D space. */
-    float3 ray_start, ray_end;
-    ED_view3d_win_to_segment_clipped(
-        &depsgraph, region, v3d, stroke_extension.mouse_position, ray_start, ray_end, true);
-    ray_start = surface_ob_imat * ray_start;
-    ray_end = surface_ob_imat * ray_end;
-    const float3 ray_direction = math::normalize(ray_end - ray_start);
-
-    /* This ray is used to determine the brush radius in 3d space. */
-    float3 offset_ray_start, offset_ray_end;
-    ED_view3d_win_to_segment_clipped(&depsgraph,
-                                     region,
-                                     v3d,
-                                     stroke_extension.mouse_position +
-                                         float2(0, brush_radius_screen),
-                                     offset_ray_start,
-                                     offset_ray_end,
-                                     true);
-    offset_ray_start = surface_ob_imat * offset_ray_start;
-    offset_ray_end = surface_ob_imat * offset_ray_end;
-
-    float4x4 ob_imat;
-    invert_m4_m4(ob_imat.values, object.obmat);
-
-    const float4x4 transform = ob_imat * surface_ob_mat;
-
-    BVHTreeFromMesh bvhtree;
-    BKE_bvhtree_from_mesh_get(&bvhtree, &surface, BVHTREE_FROM_LOOPTRI, 2);
-
-    /* Do a raycast against the surface object to find the brush position. */
-    BVHTreeRayHit ray_hit;
-    ray_hit.dist = FLT_MAX;
-    ray_hit.index = -1;
-    BLI_bvhtree_ray_cast(bvhtree.tree,
-                         ray_start,
-                         ray_direction,
-                         0.0f,
-                         &ray_hit,
-                         bvhtree.raycast_callback,
-                         &bvhtree);
-
-    if (ray_hit.index == -1) {
-      /* The ray did not hit the surface. */
-      free_bvhtree_from_mesh(&bvhtree);
-      return;
-    }
-    /* Brush position in the space of the surface object. */
-    const float3 brush_pos_3d_surface = ray_hit.co;
-    const float brush_radius_3d_surface = dist_to_line_v3(
-        brush_pos_3d_surface, offset_ray_start, offset_ray_end);
-
-    /* Brush position in the space of the curves object. */
-    const float3 brush_pos_3d_curves = transform * brush_pos_3d_surface;
-    const float brush_radius_3d_curves = dist_to_line_v3(
-        brush_pos_3d_curves, transform * offset_ray_start, transform * offset_ray_end);
-
-    Vector<int> looptri_indices = this->find_looptri_indices_to_consider(
-        bvhtree, brush_pos_3d_surface, brush_radius_3d_surface);
-
-    free_bvhtree_from_mesh(&bvhtree);
-
-    if (old_kdtree_ == nullptr && minimum_distance > 0.0f) {
-      old_kdtree_ = this->kdtree_from_curve_roots_and_positions(curves, curves.curves_range(), {});
-      old_kdtree_size_ = curves.curves_num();
-    }
-
-    float density;
-    if (minimum_distance > 0.0f) {
-      /* Estimate the sampling density based on the target minimum distance. */
-      density = strength * pow2f(1.0f / minimum_distance);
-    }
-    else {
-      /* Sample a somewhat constant amount of points based on the strength. */
-      const float brush_circle_area_3d = M_PI * pow2f(brush_radius_3d_curves);
-      density = strength * 100.0f / brush_circle_area_3d;
-    }
-
-    NewPointsData new_points = this->sample_new_points(density,
-                                                       minimum_distance,
-                                                       brush_radius_3d_curves,
-                                                       brush_pos_3d_curves,
-                                                       looptri_indices,
-                                                       transform,
-                                                       surface);
-    if (minimum_distance > 0.0f) {
-      this->eliminate_too_close_points(new_points, curves, minimum_distance);
-    }
-    this->insert_new_curves(new_points, curves);
-
-    DEG_id_tag_update(&curves_id.id, ID_RECALC_GEOMETRY);
-    ED_region_tag_redraw(region);
-  }
-
- private:
-  Vector<int> find_looptri_indices_to_consider(BVHTreeFromMesh &bvhtree,
-                                               const float3 &brush_pos,
-                                               const float brush_radius_3d)
-  {
-    Vector<int> looptri_indices;
-
-    struct RangeQueryUserData {
-      Vector<int> &indices;
-    } range_query_user_data = {looptri_indices};
-
-    BLI_bvhtree_range_query(
-        bvhtree.tree,
-        brush_pos,
-        brush_radius_3d,
-        [](void *userdata, int index, const float co[3], float dist_sq) {
-          UNUSED_VARS(co, dist_sq);
-          RangeQueryUserData &data = *static_cast<RangeQueryUserData *>(userdata);
-          data.indices.append(index);
-        },
-        &range_query_user_data);
-
-    return looptri_indices;
-  }
-
-  KDTree_3d *kdtree_from_curve_roots_and_positions(const CurvesGeometry &curves,
-                                                   const IndexRange curves_range,
-                                                   Span<float3> extra_positions)
-  {
-    const int tot_points = curves_range.size() + extra_positions.size();
-    KDTree_3d *kdtree = BLI_kdtree_3d_new(tot_points);
-    for (const int curve_i : curves_range) {
-      const int first_point_i = curves.offsets()[curve_i];
-      const float3 root_position = curves.positions()[first_point_i];
-      BLI_kdtree_3d_insert(kdtree, ExistsAlreadyIndex, root_position);
-    }
-    for (const int i : extra_positions.index_range()) {
-      BLI_kdtree_3d_insert(kdtree, i, extra_positions[i]);
-    }
-    BLI_kdtree_3d_balance(kdtree);
-    return kdtree;
-  }
-
-  bool is_too_close_to_existing_point(const float3 position, const float minimum_distance) const
-  {
-    if (old_kdtree_ == nullptr) {
-      return false;
-    }
-    KDTreeNearest_3d nearest;
-    nearest.index = -1;
-    BLI_kdtree_3d_find_nearest(old_kdtree_, position, &nearest);
-    if (nearest.index >= 0 && nearest.dist < minimum_distance) {
-      return true;
-    }
-    return false;
-  }
-
-  NewPointsData sample_new_points(const float density,
-                                  const float minimum_distance,
-                                  const float brush_radius_3d,
-                                  const float3 &brush_pos,
-                                  const Span<int> looptri_indices,
-                                  const float4x4 &transform,
-                                  const Mesh &surface)
-  {
-    const float brush_radius_3d_sq = brush_radius_3d * brush_radius_3d;
-    const float area_threshold = M_PI * brush_radius_3d_sq;
-
-    const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&surface),
-                                  BKE_mesh_runtime_looptri_len(&surface)};
-
-    threading::EnumerableThreadSpecific<NewPointsData> new_points_per_thread;
-
-    const double time = PIL_check_seconds_timer();
-    const uint64_t time_as_int = *reinterpret_cast<const uint64_t *>(&time);
-    const uint32_t rng_base_seed = time_as_int ^ (time_as_int >> 32);
-
-    RandomNumberGenerator rng{rng_base_seed};
-
-    threading::parallel_for(looptri_indices.index_range(), 512, [&](const IndexRange range) {
-      RandomNumberGenerator looptri_rng{rng_base_seed + (uint32_t)range.start()};
-
-      for (const int looptri_index : looptri_indices.slice(range)) {
-        const MLoopTri &looptri = looptris[looptri_index];
-        const float3 &v0 = transform * float3(surface.mvert[surface.mloop[looptri.tri[0]].v].co);
-        const float3 &v1 = transform * float3(surface.mvert[surface.mloop[looptri.tri[1]].v].co);
-        const float3 &v2 = transform * float3(surface.mvert[surface.mloop[looptri.tri[2]].v].co);
-        const float looptri_area = area_tri_v3(v0, v1, v2);
-
-        float3 normal;


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list