Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-09-06 19:22:24 +0300
committerJacques Lucke <jacques@blender.org>2021-09-06 19:31:25 +0300
commit5a9a16334c573c4566dc9b2a314cf0d0ccdcb54f (patch)
tree35f765d48f478c04c2bbc92df77d388efa3ac1c8 /source/blender/depsgraph/intern
parentd9ad77fa58eb6301e3fedc709c946b7349c057b2 (diff)
Geometry Nodes: support for geometry instancing
Previously, the Point Instance node in geometry nodes could only instance existing objects or collections. The reason was that large parts of Blender worked under the assumption that objects are the main unit of instancing. Now we also want to instance geometry within an object, so a slightly larger refactor was necessary. This should not affect files that do not use the new kind of instances. The main change is a redefinition of what "instanced data" is. Now, an instances is a cow-object + object-data (the geometry). This can be nicely seen in `struct DupliObject`. This allows the same object to generate multiple geometries of different types which can be instanced individually. A nice side effect of this refactor is that having multiple geometry components is not a special case in the depsgraph object iterator anymore, because those components are integrated with the `DupliObject` system. Unfortunately, different systems that work with instances in Blender (e.g. render engines and exporters) often work under the assumption that objects are the main unit of instancing. So those have to be updated as well to be able to handle the new instances. This patch updates Cycles, EEVEE and other viewport engines. Exporters have not been updated yet. Some minimal (not master-ready) changes to update the obj and alembic exporters can be found in P2336 and P2335. Different file formats may want to handle these new instances in different ways. For users, the only thing that changed is that the Point Instance node now has a geometry mode. This also fixes T88454. Differential Revision: https://developer.blender.org/D11841
Diffstat (limited to 'source/blender/depsgraph/intern')
-rw-r--r--source/blender/depsgraph/intern/depsgraph_query_iter.cc138
1 files changed, 9 insertions, 129 deletions
diff --git a/source/blender/depsgraph/intern/depsgraph_query_iter.cc b/source/blender/depsgraph/intern/depsgraph_query_iter.cc
index 770d9775dd3..7af3d03d478 100644
--- a/source/blender/depsgraph/intern/depsgraph_query_iter.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query_iter.cc
@@ -120,130 +120,6 @@ bool deg_object_hide_original(eEvaluationMode eval_mode, Object *ob, DupliObject
return false;
}
-void deg_iterator_components_init(DEGObjectIterData *data, Object *object)
-{
- data->geometry_component_owner = object;
- data->geometry_component_id = 0;
-}
-
-/* Returns false when iterator is exhausted. */
-bool deg_iterator_components_step(BLI_Iterator *iter)
-{
- DEGObjectIterData *data = (DEGObjectIterData *)iter->data;
- if (data->geometry_component_owner == nullptr) {
- return false;
- }
-
- if (data->geometry_component_owner->runtime.geometry_set_eval == nullptr) {
- /* Return the object itself, if it does not have a geometry set yet. */
- iter->current = data->geometry_component_owner;
- data->geometry_component_owner = nullptr;
- return true;
- }
-
- GeometrySet *geometry_set = data->geometry_component_owner->runtime.geometry_set_eval;
- if (geometry_set == nullptr) {
- data->geometry_component_owner = nullptr;
- return false;
- }
-
- /* The mesh component. */
- if (data->geometry_component_id == 0) {
- data->geometry_component_id++;
-
- /* Don't use a temporary object for this component, when the owner is a mesh object. */
- if (data->geometry_component_owner->type == OB_MESH) {
- iter->current = data->geometry_component_owner;
- return true;
- }
-
- const Mesh *mesh = geometry_set->get_mesh_for_read();
- if (mesh != nullptr) {
- Object *temp_object = &data->temp_geometry_component_object;
- *temp_object = *data->geometry_component_owner;
- temp_object->type = OB_MESH;
- temp_object->data = (void *)mesh;
- temp_object->runtime.select_id = data->geometry_component_owner->runtime.select_id;
- iter->current = temp_object;
- return true;
- }
- }
-
- /* The pointcloud component. */
- if (data->geometry_component_id == 1) {
- data->geometry_component_id++;
-
- /* Don't use a temporary object for this component, when the owner is a point cloud object. */
- if (data->geometry_component_owner->type == OB_POINTCLOUD) {
- iter->current = data->geometry_component_owner;
- return true;
- }
-
- const PointCloud *pointcloud = geometry_set->get_pointcloud_for_read();
- if (pointcloud != nullptr) {
- Object *temp_object = &data->temp_geometry_component_object;
- *temp_object = *data->geometry_component_owner;
- temp_object->type = OB_POINTCLOUD;
- temp_object->data = (void *)pointcloud;
- temp_object->runtime.select_id = data->geometry_component_owner->runtime.select_id;
- iter->current = temp_object;
- return true;
- }
- }
-
- /* The volume component. */
- if (data->geometry_component_id == 2) {
- data->geometry_component_id++;
-
- /* Don't use a temporary object for this component, when the owner is a volume object. */
- if (data->geometry_component_owner->type == OB_VOLUME) {
- iter->current = data->geometry_component_owner;
- return true;
- }
-
- const VolumeComponent *component = geometry_set->get_component_for_read<VolumeComponent>();
- if (component != nullptr) {
- const Volume *volume = component->get_for_read();
-
- if (volume != nullptr) {
- Object *temp_object = &data->temp_geometry_component_object;
- *temp_object = *data->geometry_component_owner;
- temp_object->type = OB_VOLUME;
- temp_object->data = (void *)volume;
- temp_object->runtime.select_id = data->geometry_component_owner->runtime.select_id;
- iter->current = temp_object;
- return true;
- }
- }
- }
-
- /* The curve component. */
- if (data->geometry_component_id == 3) {
- data->geometry_component_id++;
-
- const CurveComponent *component = geometry_set->get_component_for_read<CurveComponent>();
- if (component != nullptr) {
- const Curve *curve = component->get_curve_for_render();
-
- if (curve != nullptr) {
- Object *temp_object = &data->temp_geometry_component_object;
- *temp_object = *data->geometry_component_owner;
- temp_object->type = OB_CURVE;
- temp_object->data = (void *)curve;
- /* Assign data_eval here too, because curve rendering code tries
- * to use a mesh if it can find one in this pointer. */
- temp_object->runtime.data_eval = (ID *)curve;
- temp_object->runtime.select_id = data->geometry_component_owner->runtime.select_id;
- iter->current = temp_object;
- return true;
- }
- }
- }
-
- data->geometry_component_owner = nullptr;
- return false;
-}
-
void deg_iterator_duplis_init(DEGObjectIterData *data, Object *object)
{
if ((data->flag & DEG_ITER_OBJECT_FLAG_DUPLI) &&
@@ -292,6 +168,9 @@ bool deg_iterator_duplis_step(DEGObjectIterData *data)
temp_dupli_object->dt = MIN2(temp_dupli_object->dt, dupli_parent->dt);
copy_v4_v4(temp_dupli_object->color, dupli_parent->color);
temp_dupli_object->runtime.select_id = dupli_parent->runtime.select_id;
+ if (dob->ob->data != dob->ob_data) {
+ BKE_object_replace_data_on_shallow_copy(temp_dupli_object, dob->ob_data);
+ }
/* Duplicated elements shouldn't care whether their original collection is visible or not. */
temp_dupli_object->base_flag |= BASE_VISIBLE_DEPSGRAPH;
@@ -308,7 +187,7 @@ bool deg_iterator_duplis_step(DEGObjectIterData *data)
copy_m4_m4(data->temp_dupli_object.obmat, dob->mat);
invert_m4_m4(data->temp_dupli_object.imat, data->temp_dupli_object.obmat);
- deg_iterator_components_init(data, &data->temp_dupli_object);
+ data->next_object = &data->temp_dupli_object;
BLI_assert(deg::deg_validate_copy_on_write_datablock(&data->temp_dupli_object.id));
return true;
}
@@ -377,7 +256,7 @@ bool deg_iterator_objects_step(DEGObjectIterData *data)
}
if (ob_visibility & (OB_VISIBLE_SELF | OB_VISIBLE_PARTICLES)) {
- deg_iterator_components_init(data, object);
+ data->next_object = object;
}
data->id_node_index++;
return true;
@@ -400,6 +279,7 @@ void DEG_iterator_objects_begin(BLI_Iterator *iter, DEGObjectIterData *data)
return;
}
+ data->next_object = nullptr;
data->dupli_parent = nullptr;
data->dupli_list = nullptr;
data->dupli_object_next = nullptr;
@@ -408,8 +288,6 @@ void DEG_iterator_objects_begin(BLI_Iterator *iter, DEGObjectIterData *data)
data->id_node_index = 0;
data->num_id_nodes = num_id_nodes;
data->eval_mode = DEG_get_mode(depsgraph);
- data->geometry_component_id = 0;
- data->geometry_component_owner = nullptr;
deg_invalidate_iterator_work_data(data);
DEG_iterator_objects_next(iter);
@@ -419,7 +297,9 @@ void DEG_iterator_objects_next(BLI_Iterator *iter)
{
DEGObjectIterData *data = (DEGObjectIterData *)iter->data;
while (true) {
- if (deg_iterator_components_step(iter)) {
+ if (data->next_object != nullptr) {
+ iter->current = data->next_object;
+ data->next_object = nullptr;
return;
}
if (deg_iterator_duplis_step(data)) {