Initial Grease Pencil 3.0 stage #106848

Merged
Falk David merged 224 commits from filedescriptor/blender:grease-pencil-v3 into main 2023-05-30 11:14:22 +02:00
4 changed files with 91 additions and 6 deletions
Showing only changes of commit 429018a3a8 - Show all commits

View File

@ -1,6 +0,0 @@
#include "BKE_grease_pencil.hh"
Span<GreasePencilDrawing> blender::bke::GreasePencil::drawings() const
{
return Span<GreasePencilDrawing>{this->drawing_array, this->drawing_array_size};
}

View File

@ -8,6 +8,7 @@
*/
#include "BLI_map.hh"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_grease_pencil_types.h"
namespace blender::bke {
@ -17,6 +18,11 @@ class GreasePencilLayerRuntime {
Map<int, int> frames;
};
namespace gpencil::convert {
CurvesGeometry &legacy_gpencil_frame_to_curves_geometry(bGPDframe &gpf);
filedescriptor marked this conversation as resolved Outdated

Decide on the namespace here. Should it maybe be just gp?

Decide on the namespace here. Should it maybe be just `gp`?
} // namespace gpencil::convert
} // namespace blender::bke

View File

@ -148,6 +148,7 @@ set(SRC
intern/gpencil_geom_legacy.cc
intern/gpencil_modifier_legacy.c
intern/gpencil_update_cache_legacy.c
intern/grease_pencil_convert_legacy.cc
intern/grease_pencil.cc
intern/icons.cc
intern/icons_rasterize.c
@ -389,6 +390,7 @@ set(SRC
BKE_gpencil_geom_legacy.h
BKE_gpencil_modifier_legacy.h
BKE_gpencil_update_cache_legacy.h
BKE_grease_pencil.hh
BKE_icons.h
BKE_idprop.h
BKE_idprop.hh

View File

@ -0,0 +1,83 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup bke
*/
#include "BKE_curves.hh"
#include "BKE_grease_pencil.hh"
#include "BLI_listbase.h"
#include "BLI_math_vector_types.hh"
#include "BLI_vector.hh"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_grease_pencil_types.h"
namespace blender::bke::gpencil::convert {
CurvesGeometry &legacy_gpencil_frame_to_curves_geometry(bGPDframe &gpf)
filedescriptor marked this conversation as resolved Outdated

legacy_gpencil_frame_to_grease_pencil_drawing

`legacy_gpencil_frame_to_grease_pencil_drawing`
{
/* Get the number of points, number of strokes and the offsets for each stroke. */
Vector<int> offsets;

Order return argument last, make the gpf argument const

Order return argument last, make the `gpf` argument const
offsets.append(0);
int num_strokes = 0;
int num_points = 0;
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf.strokes) {
num_points += gps->totpoints;
offsets.append(num_points);
num_strokes++;
}
/* Create a new CurvesGeometry. */
CurvesGeometry curves{num_points, num_strokes};
curves.offsets_for_write().copy_from(offsets);
OffsetIndices<int> points_by_curve = curves.points_by_curve();
MutableAttributeAccessor attributes = curves.attributes_for_write();
/* All strokes are poly curves. */
curves.curve_types_for_write().fill(CURVE_TYPE_POLY);
/* Point Attributes. */
MutableSpan<float3> positions = curves.positions_for_write();
MutableSpan<float> radii =
attributes.lookup_or_add_for_write_span<float>("radius", ATTR_DOMAIN_POINT).span;
MutableSpan<float> opacities =
attributes.lookup_or_add_for_write_span<float>("opacity", ATTR_DOMAIN_POINT).span;
MutableSpan<bool> selection =
attributes.lookup_or_add_for_write_span<bool>(".selection", ATTR_DOMAIN_POINT).span;
/* Curve Attributes. */
MutableSpan<bool> curve_cyclic =
attributes.lookup_or_add_for_write_span<bool>("cyclic", ATTR_DOMAIN_CURVE).span;
MutableSpan<int> curve_materials =
attributes.lookup_or_add_for_write_span<int>("material_index", ATTR_DOMAIN_CURVE).span;
int i = 0;
LISTBASE_FOREACH_INDEX (bGPDstroke *, gps, &gpf.strokes, i) {
/* Write curve attributes. */
curve_cyclic[i] = (gps->flag & GP_STROKE_CYCLIC) != 0;
curve_materials[i] = gps->mat_nr;
/* Write point attributes. */
IndexRange curve_points = points_by_curve[i];
Span<bGPDspoint> stroke_points{gps->points, gps->totpoints};
MutableSpan<float3> curve_positions = positions.slice(curve_points);
MutableSpan<float> curve_radii = radii.slice(curve_points);
MutableSpan<float> curve_opacities = opacities.slice(curve_points);
MutableSpan<bool> curve_selections = selection.slice(curve_points);
for (const int j : stroke_points.index_range()) {
const bGPDspoint &pt = stroke_points[j];
curve_positions[j] = float3(pt.x, pt.y, pt.z);
curve_radii[j] = pt.pressure;
curve_opacities[j] = pt.strength;
curve_selections[j] = (pt.flag & GP_SPOINT_SELECT) != 0;
}
}
return curves;
}
} // namespace blender::bke::gpencil::convert