[Bf-blender-cvs] [912b38001f6] geometry-nodes: Geometry Nodes: use GeometrySet when evaluating pointcloud modifiers
Jacques Lucke
noreply at git.blender.org
Thu Nov 12 13:31:01 CET 2020
Commit: 912b38001f685e30b64a7bb34bb0b56535cad9ed
Author: Jacques Lucke
Date: Thu Nov 12 12:57:52 2020 +0100
Branches: geometry-nodes
https://developer.blender.org/rB912b38001f685e30b64a7bb34bb0b56535cad9ed
Geometry Nodes: use GeometrySet when evaluating pointcloud modifiers
This changes the signature of the modifyPointCloud function.
I'm doing that instead of making a new callback, because it requires
changes to significantly fewer files. Eventually it would be good
combine modifyMesh, modifyHair, modifyPointCloud and modifyVolume
into one modifyGeometrySet.
I temporarily disabled the displacement only modifiers for point clouds.
Support can be added back a bit later. I assume those have not been
used anywhere anyway.
The output of point cloud modifiers can not only be another point cloud,
but also a mesh and/or some instances. I added a new geometry_set_eval
field to Object_Runtime. For point cloud objects, the final geometry is
now referenced by that pointer instead of data_eval. The data_eval field
is still initialized after modifier evaluation to make some other code happy.
The evaluated geometry set is not yet passed to the renderer, so a point
cloud is currently rendered empty.
===================================================================
M source/blender/blenkernel/BKE_modifier.h
M source/blender/blenkernel/intern/object.c
M source/blender/blenkernel/intern/pointcloud.cc
M source/blender/makesdna/DNA_object_types.h
M source/blender/modifiers/intern/MOD_nodes.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index a2c3787bcd2..868f13e3488 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -43,6 +43,7 @@ struct ModifierData;
struct Object;
struct Scene;
struct bArmature;
+struct GeometrySetC;
typedef enum {
/* Should not be used, only for None modifier type */
@@ -246,9 +247,9 @@ typedef struct ModifierTypeInfo {
struct Hair *(*modifyHair)(struct ModifierData *md,
const struct ModifierEvalContext *ctx,
struct Hair *hair);
- struct PointCloud *(*modifyPointCloud)(struct ModifierData *md,
- const struct ModifierEvalContext *ctx,
- struct PointCloud *pointcloud);
+ struct GeometrySetC *(*modifyPointCloud)(struct ModifierData *md,
+ const struct ModifierEvalContext *ctx,
+ struct GeometrySetC *geometry_set_c);
struct Volume *(*modifyVolume)(struct ModifierData *md,
const struct ModifierEvalContext *ctx,
struct Volume *volume);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 5b0b1f333f4..2b6355f4b1d 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -94,6 +94,7 @@
#include "BKE_fcurve.h"
#include "BKE_fcurve_driver.h"
#include "BKE_font.h"
+#include "BKE_geometry_set.h"
#include "BKE_global.h"
#include "BKE_gpencil.h"
#include "BKE_gpencil_geom.h"
@@ -1284,8 +1285,7 @@ bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
return (mti->modifyHair != NULL) || (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly);
}
if (ob->type == OB_POINTCLOUD) {
- return (mti->modifyPointCloud != NULL) ||
- (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly);
+ return (mti->modifyPointCloud != NULL);
}
if (ob->type == OB_VOLUME) {
return (mti->modifyVolume != NULL);
@@ -1507,6 +1507,9 @@ void BKE_object_eval_assign_data(Object *object_eval, ID *data_eval, bool is_own
object_eval->data = data_eval;
}
}
+
+ /* Is set separately currently. */
+ object_eval->runtime.geometry_set_eval = NULL;
}
/**
@@ -1551,6 +1554,11 @@ void BKE_object_free_derived_caches(Object *ob)
BKE_gpencil_eval_delete(ob->runtime.gpd_eval);
ob->runtime.gpd_eval = NULL;
}
+
+ if (ob->runtime.geometry_set_eval != NULL) {
+ BKE_geometry_set_user_remove(ob->runtime.geometry_set_eval);
+ ob->runtime.geometry_set_eval = NULL;
+ }
}
void BKE_object_free_caches(Object *object)
@@ -1771,6 +1779,10 @@ int BKE_object_visibility(const Object *ob, const int dag_eval_mode)
visibility |= OB_VISIBLE_INSTANCES;
}
+ if (ob->runtime.geometry_set_eval != NULL) {
+ visibility |= OB_VISIBLE_INSTANCES;
+ }
+
/* Optional hiding of self if there are particles or instancers. */
if (visibility & (OB_VISIBLE_PARTICLES | OB_VISIBLE_INSTANCES)) {
switch ((eEvaluationMode)dag_eval_mode) {
@@ -4872,6 +4884,7 @@ void BKE_object_runtime_reset_on_copy(Object *object, const int UNUSED(flag))
runtime->mesh_deform_eval = NULL;
runtime->curve_cache = NULL;
runtime->object_as_temp_mesh = NULL;
+ runtime->geometry_set_eval = NULL;
}
/**
diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc
index f6a2beb9767..df88b3ad7d4 100644
--- a/source/blender/blenkernel/intern/pointcloud.cc
+++ b/source/blender/blenkernel/intern/pointcloud.cc
@@ -33,6 +33,7 @@
#include "BKE_anim_data.h"
#include "BKE_customdata.h"
+#include "BKE_geometry_set.hh"
#include "BKE_global.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
@@ -86,6 +87,8 @@ static void pointcloud_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_s
alloc_type,
pointcloud_dst->totpoint);
BKE_pointcloud_update_customdata_pointers(pointcloud_dst);
+
+ pointcloud_dst->batch_cache = NULL;
}
static void pointcloud_free_data(ID *id)
@@ -329,12 +332,13 @@ PointCloud *BKE_pointcloud_copy_for_eval(struct PointCloud *pointcloud_src, bool
return result;
}
-static PointCloud *pointcloud_evaluate_modifiers(struct Depsgraph *depsgraph,
- struct Scene *scene,
- Object *object,
- PointCloud *pointcloud_input)
+static blender::bke::GeometrySetPtr pointcloud_evaluate_modifiers(
+ struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ Object *object,
+ blender::bke::GeometrySetPtr geometry_set)
{
- PointCloud *pointcloud = pointcloud_input;
+ using namespace blender::bke;
/* Modifier evaluation modes. */
const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
@@ -355,55 +359,35 @@ static PointCloud *pointcloud_evaluate_modifiers(struct Depsgraph *depsgraph,
continue;
}
- if ((mti->type == eModifierTypeType_OnlyDeform) &&
- (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) {
- /* Ensure we are not modifying the input. */
- if (pointcloud == pointcloud_input) {
- pointcloud = BKE_pointcloud_copy_for_eval(pointcloud, true);
- }
-
- /* Ensure we are not overwriting referenced data. */
- CustomData_duplicate_referenced_layer_named(
- &pointcloud->pdata, CD_PROP_FLOAT3, POINTCLOUD_ATTR_POSITION, pointcloud->totpoint);
- BKE_pointcloud_update_customdata_pointers(pointcloud);
-
- /* Created deformed coordinates array on demand. */
- mti->deformVerts(md, &mectx, nullptr, pointcloud->co, pointcloud->totpoint);
- }
- else if (mti->modifyPointCloud) {
- /* Ensure we are not modifying the input. */
- if (pointcloud == pointcloud_input) {
- pointcloud = BKE_pointcloud_copy_for_eval(pointcloud, true);
- }
-
- PointCloud *pointcloud_next = mti->modifyPointCloud(md, &mectx, pointcloud);
-
- if (pointcloud_next && pointcloud_next != pointcloud) {
- /* If the modifier returned a new pointcloud, release the old one. */
- if (pointcloud != pointcloud_input) {
- BKE_id_free(nullptr, pointcloud);
- }
- pointcloud = pointcloud_next;
- }
+ if (mti->modifyPointCloud) {
+ GeometrySetC *modifier_input_geometry_set = wrap(geometry_set.release());
+ GeometrySetC *modifier_output_geometry_set = mti->modifyPointCloud(
+ md, &mectx, modifier_input_geometry_set);
+ geometry_set = unwrap(modifier_output_geometry_set);
}
}
- return pointcloud;
+ return geometry_set;
}
void BKE_pointcloud_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Object *object)
{
+ using namespace blender::bke;
+
/* Free any evaluated data and restore original data. */
BKE_object_free_derived_caches(object);
/* Evaluate modifiers. */
PointCloud *pointcloud = static_cast<PointCloud *>(object->data);
- PointCloud *pointcloud_eval = pointcloud_evaluate_modifiers(
- depsgraph, scene, object, pointcloud);
+ GeometrySetPtr input_geometry_set = GeometrySet::create_with_pointcloud(
+ pointcloud, GeometryOwnershipType::ReadOnly);
+ GeometrySetPtr geometry_set_eval = pointcloud_evaluate_modifiers(
+ depsgraph, scene, object, std::move(input_geometry_set));
/* Assign evaluated object. */
- const bool is_owned = (pointcloud != pointcloud_eval);
- BKE_object_eval_assign_data(object, &pointcloud_eval->id, is_owned);
+ PointCloud *dummy_pointcloud = BKE_pointcloud_new_nomain(0);
+ BKE_object_eval_assign_data(object, &dummy_pointcloud->id, true);
+ object->runtime.geometry_set_eval = wrap(geometry_set_eval.release());
}
/* Draw Cache */
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 345d1287ab1..63886a81acb 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -51,6 +51,7 @@ struct RigidBodyOb;
struct SculptSession;
struct SoftBody;
struct bGPdata;
+struct GeometrySetC;
/* Vertex Groups - Name Info */
typedef struct bDeformGroup {
@@ -150,6 +151,13 @@ typedef struct Object_Runtime {
* It has all modifiers applied.
*/
struct ID *data_eval;
+
+ /**
+ * Some objects support evaluating to a geometry set instead of a single ID. In those cases the
+ * evaluated geometry will be stored here instead of in #data_eval.
+ */
+ struct GeometrySetC *geometry_set_eval;
+
/**
* Mesh structure created during object evaluation.
* It has deformation only modifiers applied on it.
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 082067d365b..4aa17936caa 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -169,22 +169,6 @@ static bool isDisabled(const struct Scene *UNUSED(scene),
return false;
}
-static PointCloud *modifyPointCloud(ModifierData *md,
- const ModifierEvalContext *UNUSED(ctx),
- PointCloud *pointcloud)
-{
- NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
- UNUSED_VARS(nmd);
- std::cout << __func__ << "\n";
- return pointcloud;
-}
-
-/* To be replaced soon. */
-using namespace blender;
-using namespace blender::nodes;
-using namespace blender::fn;
-using namespace blender::bke;
-
class GeometryNodesEvaluator {
private:
LinearAllocator<> allocator_;
@@ -816,27 +800,28 @@ static void check_property_socket_sync(const Object *ob, ModifierData *md)
}
}
-static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
+static GeometrySetPtr modifyGeometry(ModifierData *md,
+ const ModifierEvalContext *ctx,
+ GeometrySetPtr input_geometry_set)
{
NodesModifierDa
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list