GPv3: Initial Geometry Nodes support #112535

Merged
Falk David merged 61 commits from filedescriptor/blender:gpv3-geometry-nodes into main 2023-10-10 16:49:39 +02:00
2 changed files with 70 additions and 6 deletions
Showing only changes of commit c77feee2d3 - Show all commits

View File

@ -72,17 +72,28 @@ class PointCloudFieldContext : public fn::FieldContext {
}
};
class GreasePencilFieldContext : public fn::FieldContext {
class GreasePencilLayerFieldContext : public fn::FieldContext {
private:
const GreasePencil &grease_pencil_;
const eAttrDomain domain_;
const int layer_index_;
public:
GreasePencilFieldContext(const GreasePencil &pointcloud) : grease_pencil_(pointcloud) {}
GreasePencilLayerFieldContext(const GreasePencil &grease_pencil,
eAttrDomain domain,
int layer_index)
: grease_pencil_(grease_pencil), domain_(domain), layer_index_(layer_index)
{
}
const GreasePencil &grease_pencil() const
{
return grease_pencil_;
}
GVArray get_varray_for_input(const fn::FieldInput &field_input,
const IndexMask &mask,
ResourceScope & /*scope*/) const;
};
class InstancesFieldContext : public fn::FieldContext {

View File

@ -35,6 +35,59 @@ CurvesFieldContext::CurvesFieldContext(const CurvesGeometry &curves, const eAttr
BLI_assert(curves.attributes().domain_supported(domain));
}
GVArray GreasePencilLayerFieldContext::get_varray_for_input(const fn::FieldInput &field_input,
const IndexMask &mask,
ResourceScope &scope) const
{
if (const AttributeFieldInput *field = dynamic_cast<const AttributeFieldInput *>(&field_input)) {
if (domain_ == ATTR_DOMAIN_GREASE_PENCIL_LAYER) {
return *grease_pencil_.attributes().lookup(field->attribute_name());
}
const bke::greasepencil::Layer &layer = *grease_pencil_.layers()[layer_index_];
const int drawing_index = layer.drawing_index_at(grease_pencil_.runtime->eval_frame);
if (drawing_index == -1) {
return {};
}
GreasePencilDrawingBase *drawing_base = grease_pencil_.drawings(drawing_index);
if (drawing_base->type != GP_DRAWING) {
return {};
}
const bke::greasepencil::Drawing &drawing =
reinterpret_cast<GreasePencilDrawing *>(drawing_base)->wrap();
const CurvesGeometry &curves = drawing.strokes();
filedescriptor marked this conversation as resolved
Review

This seems to be missing the default case which is just field_input.get_array_for_context(*this).

I think this could be simplified. We just have do check if the field_input is a CurvesFieldInput. Then we do the conversion to CurvesFieldContext. Otherwise, we can just do the default operation mentioned above. The conversion to GeometryFieldContext is done in GeometryFieldInput::get_varray_for_context already.

This seems to be missing the default case which is just `field_input.get_array_for_context(*this)`. I think this could be simplified. We just have do check if the `field_input` is a `CurvesFieldInput`. Then we do the conversion to `CurvesFieldContext`. Otherwise, we can just do the default operation mentioned above. The conversion to `GeometryFieldContext` is done in `GeometryFieldInput::get_varray_for_context` already.
if (GVArray varray = *curves.attributes().lookup(field->attribute_name(), domain_)) {
return varray;
}
if (GVArray varray = *grease_pencil_.attributes().lookup(field->attribute_name())) {
BUFFER_FOR_CPP_TYPE_VALUE(varray.type(), value);
BLI_SCOPED_DEFER([&]() { varray.type().destruct(value); });
varray.get_internal_single(value);
const int domain_size = drawing.strokes().attributes().domain_size(domain_);
return GVArray::ForSingle(varray.type(), domain_size, value);
}
}
else if (dynamic_cast<const CurvesFieldInput *>(&field_input)) {
if (domain_ == ATTR_DOMAIN_GREASE_PENCIL_LAYER) {
return {};
}
const bke::greasepencil::Layer &layer = *grease_pencil_.layers()[layer_index_];
const int drawing_index = layer.drawing_index_at(grease_pencil_.runtime->eval_frame);
if (drawing_index == -1) {
return {};
}
GreasePencilDrawingBase *drawing_base = grease_pencil_.drawings(drawing_index);
if (drawing_base->type != GP_DRAWING) {
return {};
}
const bke::greasepencil::Drawing &drawing =
reinterpret_cast<GreasePencilDrawing *>(drawing_base)->wrap();
const CurvesGeometry &curves = drawing.strokes();
CurvesFieldContext field_context{curves, domain_};
return field_context.get_varray_for_input(field_input, mask, scope);
}
return {};
}
GeometryFieldContext::GeometryFieldContext(const void *geometry,
const GeometryComponent::Type type,
const eAttrDomain domain)
@ -185,8 +238,8 @@ GVArray GeometryFieldInput::get_varray_for_context(const fn::FieldContext &conte
{
return this->get_varray_for_context({point_context->pointcloud()}, mask);
}
if (const GreasePencilFieldContext *grease_pencil_context =
dynamic_cast<const GreasePencilFieldContext *>(&context))
if (const GreasePencilLayerFieldContext *grease_pencil_context =
dynamic_cast<const GreasePencilLayerFieldContext *>(&context))
{
return this->get_varray_for_context({grease_pencil_context->grease_pencil()}, mask);
}
@ -280,8 +333,8 @@ GVArray GreasePencilFieldInput::get_varray_for_context(const fn::FieldContext &c
return this->get_varray_for_context(*grease_pencil, mask);
}
}
if (const GreasePencilFieldContext *grease_pencil_context =
dynamic_cast<const GreasePencilFieldContext *>(&context))
if (const GreasePencilLayerFieldContext *grease_pencil_context =
dynamic_cast<const GreasePencilLayerFieldContext *>(&context))
{
return this->get_varray_for_context(grease_pencil_context->grease_pencil(), mask);
}