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
3 changed files with 43 additions and 10 deletions
Showing only changes of commit 8e34b57ebe - Show all commits

View File

@ -405,4 +405,9 @@ bool try_capture_field_on_geometry(GeometryComponent &component,
std::optional<eAttrDomain> try_detect_field_domain(const GeometryComponent &component,
const fn::GField &field);
filedescriptor marked this conversation as resolved Outdated

These seem unrelated to "geometry fields." Maybe they should go in the GP headers?

These seem unrelated to "geometry fields." Maybe they should go in the GP headers?
const greasepencil::Drawing *get_eval_grease_pencil_layer_drawing(
const GreasePencil &grease_pencil, int layer_index);
greasepencil::Drawing *get_eval_grease_pencil_layer_drawing_for_write(GreasePencil &grease_pencil,
int layer_index);
} // namespace blender::bke

View File

@ -35,7 +35,7 @@ CurvesFieldContext::CurvesFieldContext(const CurvesGeometry &curves, const eAttr
BLI_assert(curves.attributes().domain_supported(domain));
}
static const greasepencil::Drawing *get_eval_drawing_from_grease_pencil_layer(
const greasepencil::Drawing *get_eval_grease_pencil_layer_drawing(
const GreasePencil &grease_pencil, const int layer_index)
{
BLI_assert(layer_index >= 0 && layer_index < grease_pencil.layers().size());
@ -53,11 +53,11 @@ static const greasepencil::Drawing *get_eval_drawing_from_grease_pencil_layer(
return &drawing;
}
static greasepencil::Drawing *get_eval_drawing_from_grease_pencil_layer_for_write(
GreasePencil &grease_pencil, const int layer)
greasepencil::Drawing *get_eval_grease_pencil_layer_drawing_for_write(GreasePencil &grease_pencil,
const int layer)
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.
{
return const_cast<greasepencil::Drawing *>(
get_eval_drawing_from_grease_pencil_layer(grease_pencil, layer));
get_eval_grease_pencil_layer_drawing(grease_pencil, layer));
}
GeometryFieldContext::GeometryFieldContext(const void *geometry,
@ -163,7 +163,7 @@ std::optional<AttributeAccessor> GeometryFieldContext::attributes() const
if (domain_ == ATTR_DOMAIN_GREASE_PENCIL_LAYER) {
return grease_pencil->attributes();
}
else if (const greasepencil::Drawing *drawing = get_eval_drawing_from_grease_pencil_layer(
else if (const greasepencil::Drawing *drawing = get_eval_grease_pencil_layer_drawing(
*grease_pencil, grease_pencil_layer_index_))
{
return drawing->strokes().attributes();
@ -202,8 +202,8 @@ const greasepencil::Drawing *GeometryFieldContext::grease_pencil_layer_drawing()
{
return this->type() == GeometryComponent::Type::GreasePencil &&
ELEM(domain_, ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT) ?
get_eval_drawing_from_grease_pencil_layer(*this->grease_pencil(),
grease_pencil_layer_index_) :
get_eval_grease_pencil_layer_drawing(*this->grease_pencil(),
grease_pencil_layer_index_) :
nullptr;
}
const Instances *GeometryFieldContext::instances() const
@ -698,9 +698,8 @@ bool try_capture_field_on_geometry(GeometryComponent &component,
threading::parallel_for(
grease_pencil->layers().index_range(), 64, [&](const IndexRange range) {
for (const int layer_index : range) {
filedescriptor marked this conversation as resolved Outdated

Should use a much smaller grain size here, layers will usually be large enough for that

Should use a much smaller grain size here, layers will usually be large enough for that
if (greasepencil::Drawing *drawing =
get_eval_drawing_from_grease_pencil_layer_for_write(*grease_pencil,
layer_index))
if (greasepencil::Drawing *drawing = get_eval_grease_pencil_layer_drawing_for_write(
*grease_pencil, layer_index))
{
const GeometryFieldContext field_context{*grease_pencil, domain, layer_index};
const bool success = try_capture_field_on_geometry(

View File

@ -16,6 +16,7 @@
#include "DNA_volume_types.h"
#include "BKE_curves.hh"
#include "BKE_grease_pencil.hh"
#include "BKE_instances.hh"
#include "BKE_mesh.hh"
#include "BKE_pointcloud.h"
@ -98,6 +99,28 @@ static void transform_pointcloud(PointCloud &pointcloud, const float4x4 &transfo
position.finish();
}
static void translate_greasepencil(GreasePencil &grease_pencil, const float3 translation)
{
for (const int layer_index : grease_pencil.layers().index_range()) {
if (bke::greasepencil::Drawing *drawing = bke::get_eval_grease_pencil_layer_drawing_for_write(
grease_pencil, layer_index))
{
drawing->strokes_for_write().translate(translation);
}
}
}
static void transform_greasepencil(GreasePencil &grease_pencil, const float4x4 &transform)
{
for (const int layer_index : grease_pencil.layers().index_range()) {
if (bke::greasepencil::Drawing *drawing = bke::get_eval_grease_pencil_layer_drawing_for_write(
grease_pencil, layer_index))
{
drawing->strokes_for_write().transform(transform);
}
}
}
static void translate_instances(bke::Instances &instances, const float3 translation)
{
MutableSpan<float4x4> transforms = instances.transforms();
@ -216,6 +239,9 @@ static void translate_geometry_set(GeoNodeExecParams &params,
if (PointCloud *pointcloud = geometry.get_pointcloud_for_write()) {
translate_pointcloud(*pointcloud, translation);
}
if (GreasePencil *grease_pencil = geometry.get_grease_pencil_for_write()) {
translate_greasepencil(*grease_pencil, translation);
}
if (Volume *volume = geometry.get_volume_for_write()) {
translate_volume(params, *volume, translation, depsgraph);
}
@ -241,6 +267,9 @@ void transform_geometry_set(GeoNodeExecParams &params,
if (PointCloud *pointcloud = geometry.get_pointcloud_for_write()) {
transform_pointcloud(*pointcloud, transform);
}
if (GreasePencil *grease_pencil = geometry.get_grease_pencil_for_write()) {
transform_greasepencil(*grease_pencil, transform);
}
if (Volume *volume = geometry.get_volume_for_write()) {
transform_volume(params, *volume, transform, depsgraph);
}