GPv3: Initial Geometry Nodes support #112535
|
@ -6,6 +6,10 @@
|
|||
#include "BKE_grease_pencil.hh"
|
||||
#include "BKE_lib_id.h"
|
||||
|
||||
#include "DNA_grease_pencil_types.h"
|
||||
|
||||
#include "attribute_access_intern.hh"
|
||||
|
||||
namespace blender::bke {
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@ -95,4 +99,101 @@ void GreasePencilComponent::ensure_owns_direct_data()
|
|||
}
|
||||
}
|
||||
|
||||
static ComponentAttributeProviders create_attribute_providers_for_grease_pencil()
|
||||
{
|
||||
static CustomDataAccessInfo layers_access = {
|
||||
[](void *owner) -> CustomData * {
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(owner);
|
||||
return &grease_pencil.layers_data;
|
||||
},
|
||||
[](const void *owner) -> const CustomData * {
|
||||
const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
|
||||
return &grease_pencil.layers_data;
|
||||
},
|
||||
[](const void *owner) -> int {
|
||||
const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
|
||||
return grease_pencil.layers().size();
|
||||
}};
|
||||
|
||||
static CustomDataAttributeProvider layer_custom_data(ATTR_DOMAIN_GREASE_PENCIL_LAYER,
|
||||
layers_access);
|
||||
|
||||
return ComponentAttributeProviders({}, {&layer_custom_data});
|
||||
}
|
||||
|
||||
static GVArray adapt_grease_pencil_attribute_domain(const GreasePencil &grease_pencil,
|
||||
const GVArray &varray,
|
||||
const eAttrDomain from,
|
||||
const eAttrDomain to)
|
||||
{
|
||||
if (!varray) {
|
||||
return {};
|
||||
}
|
||||
if (varray.is_empty()) {
|
||||
return {};
|
||||
}
|
||||
if (from == to) {
|
||||
return varray;
|
||||
}
|
||||
if (varray.is_single()) {
|
||||
BUFFER_FOR_CPP_TYPE_VALUE(varray.type(), value);
|
||||
varray.get_internal_single(value);
|
||||
return GVArray::ForSingle(varray.type(), grease_pencil.attributes().domain_size(to), value);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static AttributeAccessorFunctions get_grease_pencil_accessor_functions()
|
||||
{
|
||||
static const ComponentAttributeProviders providers =
|
||||
create_attribute_providers_for_grease_pencil();
|
||||
AttributeAccessorFunctions fn =
|
||||
attribute_accessor_functions::accessor_functions_for_providers<providers>();
|
||||
fn.domain_size = [](const void *owner, const eAttrDomain domain) {
|
||||
if (owner == nullptr) {
|
||||
filedescriptor marked this conversation as resolved
Outdated
|
||||
return 0;
|
||||
}
|
||||
const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
|
||||
switch (domain) {
|
||||
case ATTR_DOMAIN_GREASE_PENCIL_LAYER:
|
||||
return int(grease_pencil.layers().size());
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
fn.domain_supported = [](const void * /*owner*/, const eAttrDomain domain) {
|
||||
return ELEM(domain, ATTR_DOMAIN_GREASE_PENCIL_LAYER);
|
||||
};
|
||||
fn.adapt_domain = [](const void *owner,
|
||||
const GVArray &varray,
|
||||
const eAttrDomain from_domain,
|
||||
const eAttrDomain to_domain) -> GVArray {
|
||||
if (owner == nullptr) {
|
||||
return {};
|
||||
}
|
||||
const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
|
||||
return adapt_grease_pencil_attribute_domain(grease_pencil, varray, from_domain, to_domain);
|
||||
};
|
||||
return fn;
|
||||
}
|
||||
|
||||
static const AttributeAccessorFunctions &get_grease_pencil_accessor_functions_ref()
|
||||
{
|
||||
static const AttributeAccessorFunctions fn = get_grease_pencil_accessor_functions();
|
||||
return fn;
|
||||
}
|
||||
|
||||
} // namespace blender::bke
|
||||
|
||||
blender::bke::AttributeAccessor GreasePencil::attributes() const
|
||||
{
|
||||
return blender::bke::AttributeAccessor(this,
|
||||
blender::bke::get_grease_pencil_accessor_functions_ref());
|
||||
}
|
||||
|
||||
blender::bke::MutableAttributeAccessor GreasePencil::attributes_for_write()
|
||||
{
|
||||
return blender::bke::MutableAttributeAccessor(
|
||||
this, blender::bke::get_grease_pencil_accessor_functions_ref());
|
||||
}
|
||||
|
|
|
@ -174,18 +174,18 @@ static void grease_pencil_blend_write(BlendWriter *writer, ID *id, const void *i
|
|||
GreasePencil *grease_pencil = reinterpret_cast<GreasePencil *>(id);
|
||||
|
||||
blender::Vector<CustomDataLayer, 16> layers_data_layers;
|
||||
CustomData_blend_write_prepare(&grease_pencil->layers_data, layers_data_layers);
|
||||
CustomData_blend_write_prepare(grease_pencil->layers_data, layers_data_layers);
|
||||
|
||||
/* Write LibData */
|
||||
BLO_write_id_struct(writer, GreasePencil, id_address, &grease_pencil->id);
|
||||
BKE_id_blend_write(writer, &grease_pencil->id);
|
||||
|
||||
CustomData_blend_write(&writer,
|
||||
CustomData_blend_write(writer,
|
||||
&grease_pencil->layers_data,
|
||||
layers_data_layers,
|
||||
grease_pencil->layers().size(),
|
||||
CD_MASK_ALL,
|
||||
&id);
|
||||
id);
|
||||
|
||||
/* Write drawings. */
|
||||
write_drawing_array(*grease_pencil, writer);
|
||||
|
@ -207,7 +207,7 @@ static void grease_pencil_blend_read_data(BlendDataReader *reader, ID *id)
|
|||
/* Read layer tree. */
|
||||
read_layer_tree(*grease_pencil, reader);
|
||||
|
||||
CustomData_blend_read(&reader, &grease_pencil->layers_data, grease_pencil->layers().size());
|
||||
CustomData_blend_read(reader, &grease_pencil->layers_data, grease_pencil->layers().size());
|
||||
|
||||
/* Read materials. */
|
||||
BLO_read_pointer_array(reader, reinterpret_cast<void **>(&grease_pencil->material_array));
|
||||
|
@ -1999,7 +1999,7 @@ void GreasePencil::remove_layer(blender::bke::greasepencil::Layer &layer)
|
|||
}
|
||||
|
||||
/* Remove all the layer attributes and shrink the `CustomData`. */
|
||||
const int64_t layer_index = this->layers().first_index(layer);
|
||||
const int64_t layer_index = this->layers().first_index(&layer);
|
||||
CustomData_free_elem_and_shift(&this->layers_data, layer_index, 1, this->layers().size());
|
||||
filedescriptor marked this conversation as resolved
Iliya Katushenock
commented
`!range_before.is_empty()`
Iliya Katushenock
commented
There is still also few other There is still also few other `.size() > 0`..
|
||||
CustomData_realloc(&this->layers_data, this->layers().size(), this->layers().size() - 1);
|
||||
|
||||
|
|
|
@ -94,6 +94,14 @@ class GeometryDataSetTreeView : public ui::AbstractTreeView {
|
|||
curve.add_tree_item<GeometryDataSetTreeViewItem>(
|
||||
bke::GeometryComponent::Type::Curve, ATTR_DOMAIN_CURVE, IFACE_("Spline"), ICON_CURVE_PATH);
|
||||
|
||||
GeometryDataSetTreeViewItem &grease_pencil = this->add_tree_item<GeometryDataSetTreeViewItem>(
|
||||
bke::GeometryComponent::Type::GreasePencil, IFACE_("Grease Pencil"), ICON_GREASEPENCIL);
|
||||
grease_pencil.add_tree_item<GeometryDataSetTreeViewItem>(
|
||||
bke::GeometryComponent::Type::GreasePencil,
|
||||
ATTR_DOMAIN_GREASE_PENCIL_LAYER,
|
||||
IFACE_("Layer"),
|
||||
ICON_OUTLINER_DATA_GP_LAYER);
|
||||
|
||||
GeometryDataSetTreeViewItem &pointcloud = this->add_tree_item<GeometryDataSetTreeViewItem>(
|
||||
bke::GeometryComponent::Type::PointCloud, IFACE_("Point Cloud"), ICON_POINTCLOUD_DATA);
|
||||
pointcloud.add_tree_item<GeometryDataSetTreeViewItem>(bke::GeometryComponent::Type::PointCloud,
|
||||
|
|
|
@ -16,10 +16,13 @@
|
|||
#ifdef __cplusplus
|
||||
# include "BLI_bounds_types.hh"
|
||||
# include "BLI_function_ref.hh"
|
||||
# include "BLI_generic_virtual_array.hh"
|
||||
# include "BLI_map.hh"
|
||||
# include "BLI_math_vector_types.hh"
|
||||
# include "BLI_span.hh"
|
||||
namespace blender::bke {
|
||||
class AttributeAccessor;
|
||||
class MutableAttributeAccessor;
|
||||
class GreasePencilRuntime;
|
||||
class GreasePencilDrawingRuntime;
|
||||
namespace greasepencil {
|
||||
|
@ -564,6 +567,9 @@ typedef struct GreasePencil {
|
|||
|
||||
std::optional<blender::Bounds<blender::float3>> bounds_min_max() const;
|
||||
|
||||
blender::bke::AttributeAccessor attributes() const;
|
||||
blender::bke::MutableAttributeAccessor attributes_for_write();
|
||||
|
||||
/* For debugging purposes. */
|
||||
void print_layer_tree();
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
return domain == ATTR_DOMAIN_GREASE_PENCIL_LAYER;