From b69aad60bda23a53482b2c2ae98715c23a715bc8 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 7 Jun 2022 15:03:38 +0200 Subject: Curves: use root/tip radius of the first curve in the viewport Viewport drawing does not support a per point radius attribute yet. Instead, it has a fixed set of radius parameters that are used for all curves in the same object. Now those radii are retrieved from the radius attribute of the points on the first curve. This allows users to control the radius of curves to some degree until proper per-point radius is supported. --- source/blender/draw/intern/draw_curves.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source/blender/draw') diff --git a/source/blender/draw/intern/draw_curves.cc b/source/blender/draw/intern/draw_curves.cc index 39d4845994f..749383edc6d 100644 --- a/source/blender/draw/intern/draw_curves.cc +++ b/source/blender/draw/intern/draw_curves.cc @@ -13,6 +13,9 @@ #include "DNA_curves_types.h" #include "DNA_customdata_types.h" +#include "BKE_curves.hh" +#include "BKE_geometry_set.hh" + #include "GPU_batch.h" #include "GPU_capabilities.h" #include "GPU_compute.h" @@ -325,6 +328,21 @@ DRWShadingGroup *DRW_shgroup_curves_create_sub(Object *object, float hair_rad_tip = 0.0f; bool hair_close_tip = true; + /* Use the radius of the root and tip of the first curve for now. This is a workaround that we + * use for now because we can't use a per-point radius yet. */ + Curves &curves_id = *static_cast(object->data); + const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap( + curves_id.geometry); + if (curves.curves_num() >= 1) { + CurveComponent curves_component; + curves_component.replace(&curves_id, GeometryOwnershipType::ReadOnly); + blender::VArray radii = curves_component.attribute_get_for_read( + "radius", ATTR_DOMAIN_POINT, 0.005f); + const blender::IndexRange first_curve_points = curves.points_for_curve(0); + hair_rad_root = radii[first_curve_points.first()]; + hair_rad_tip = radii[first_curve_points.last()]; + } + DRW_shgroup_uniform_texture(shgrp, "hairPointBuffer", curves_cache->final[subdiv].proc_tex); if (curves_cache->length_tex) { DRW_shgroup_uniform_texture(shgrp, "hairLen", curves_cache->length_tex); -- cgit v1.2.3