Cleanup: Use curves wrapper

This commit is contained in:
Hans Goudey 2022-02-21 17:06:17 -05:00
parent 24ddb4b1ad
commit dde5cc6670
3 changed files with 19 additions and 19 deletions

View File

@ -358,16 +358,16 @@ static Curves *curves_evaluate_modifiers(struct Depsgraph *depsgraph,
curves = BKE_curves_copy_for_eval(curves, true);
}
/* Ensure we are not overwriting referenced data. */
CustomData_duplicate_referenced_layer_named(&curves->geometry.point_data,
CD_PROP_FLOAT3,
ATTR_POSITION,
curves->geometry.point_size);
update_custom_data_pointers(*curves);
/* Created deformed coordinates array on demand. */
mti->deformVerts(
md, &mectx, nullptr, curves->geometry.position, curves->geometry.point_size);
blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(
curves->geometry);
MutableSpan<float3> positions = geometry.positions();
mti->deformVerts(md,
&mectx,
nullptr,
reinterpret_cast<float(*)[3]>(positions.data()),
curves->geometry.point_size);
}
}

View File

@ -142,8 +142,8 @@ MutableSpan<int8_t> CurvesGeometry::curve_types()
MutableSpan<float3> CurvesGeometry::positions()
{
CustomData_duplicate_referenced_layer(&this->point_data, CD_PROP_FLOAT3, this->point_size);
this->update_customdata_pointers();
this->position = (float(*)[3])CustomData_duplicate_referenced_layer_named(
&this->point_data, CD_PROP_FLOAT3, ATTR_POSITION.c_str(), this->point_size);
return {(float3 *)this->position, this->point_size};
}
Span<float3> CurvesGeometry::positions() const

View File

@ -133,12 +133,12 @@ static void curves_batch_cache_fill_segments_proc_pos(Curves *curves,
{
/* TODO: use hair radius layer if available. */
const int curve_size = curves->geometry.curve_size;
Span<int> offsets{curves->geometry.curve_offsets, curves->geometry.curve_size + 1};
Span<float3> positions{(float3 *)curves->geometry.position, curves->geometry.point_size};
const blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(
curves->geometry);
Span<float3> positions = geometry.positions();
for (const int i : IndexRange(curve_size)) {
const IndexRange curve_range(offsets[i], offsets[i + 1] - offsets[i]);
const IndexRange curve_range = geometry.range_for_curve(i);
Span<float3> spline_positions = positions.slice(curve_range);
float total_len = 0.0f;
@ -215,11 +215,11 @@ static void curves_batch_cache_fill_strands_data(Curves *curves,
GPUVertBufRaw *data_step,
GPUVertBufRaw *seg_step)
{
const int curve_size = curves->geometry.curve_size;
Span<int> offsets{curves->geometry.curve_offsets, curves->geometry.curve_size + 1};
const blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(
curves->geometry);
for (const int i : IndexRange(curve_size)) {
const IndexRange curve_range(offsets[i], offsets[i + 1] - offsets[i]);
for (const int i : IndexRange(geometry.curves_size())) {
const IndexRange curve_range = geometry.range_for_curve(i);
*(uint *)GPU_vertbuf_raw_step(data_step) = curve_range.start();
*(ushort *)GPU_vertbuf_raw_step(seg_step) = curve_range.size() - 1;