[Bf-blender-cvs] [bd3bce16d77] temp-modifiers-instancing: render instances component
Jacques Lucke
noreply at git.blender.org
Tue Nov 10 16:39:15 CET 2020
Commit: bd3bce16d771d8c449e5e3295a5e103f20c33453
Author: Jacques Lucke
Date: Tue Nov 10 13:21:12 2020 +0100
Branches: temp-modifiers-instancing
https://developer.blender.org/rBbd3bce16d771d8c449e5e3295a5e103f20c33453
render instances component
===================================================================
M source/blender/blenkernel/BKE_geometry_set.hh
M source/blender/blenkernel/intern/geometry_set.cc
M source/blender/depsgraph/DEG_depsgraph_query.h
M source/blender/depsgraph/intern/depsgraph_query_iter.cc
M source/blender/modifiers/intern/MOD_nodes.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index dedbe9c9731..a88736b8c3e 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -197,13 +197,16 @@ class PointCloudComponent : public GeometryComponent {
class InstancesComponent : public GeometryComponent {
private:
Vector<float3> positions_;
- Object *instanced_object_ = nullptr;
+ const Object *instanced_object_ = nullptr;
public:
~InstancesComponent() = default;
GeometryComponent *copy() const override;
- void replace(Vector<float3> positions, Object *instanced_object);
+ void replace(Vector<float3> positions, const Object *instanced_object);
+
+ const Object *instanced_object() const;
+ Span<float3> positions() const;
static constexpr inline GeometryComponentType type = GeometryComponentType::Instances;
};
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index f096e624d52..48ffa0631ab 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -390,12 +390,22 @@ GeometryComponent *InstancesComponent::copy() const
return new_component;
}
-void InstancesComponent::replace(Vector<float3> positions, Object *instanced_object)
+void InstancesComponent::replace(Vector<float3> positions, const Object *instanced_object)
{
positions_ = std::move(positions);
instanced_object_ = instanced_object;
}
+const Object *InstancesComponent::instanced_object() const
+{
+ return instanced_object_;
+}
+
+Span<float3> InstancesComponent::positions() const
+{
+ return positions_;
+}
+
/** \} */
} // namespace blender::bke
diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h
index cdf1548d1a6..48b7c60a9f8 100644
--- a/source/blender/depsgraph/DEG_depsgraph_query.h
+++ b/source/blender/depsgraph/DEG_depsgraph_query.h
@@ -161,8 +161,7 @@ typedef struct DEGObjectIterData {
struct Object temp_dupli_object;
/* **** Iteration over Geometry Set. ****/
-
- bool geometry_set_finished;
+ int instances_component_index;
/* **** Iteration over ID nodes **** */
size_t id_node_index;
diff --git a/source/blender/depsgraph/intern/depsgraph_query_iter.cc b/source/blender/depsgraph/intern/depsgraph_query_iter.cc
index 7347d30cfac..0d049f1d410 100644
--- a/source/blender/depsgraph/intern/depsgraph_query_iter.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query_iter.cc
@@ -237,7 +237,7 @@ void deg_iterator_objects_step(BLI_Iterator *iter, deg::IDNode *id_node)
if (ob_visibility & (OB_VISIBLE_SELF | OB_VISIBLE_PARTICLES)) {
iter->current = object;
iter->skip = false;
- data->geometry_set_finished = false;
+ data->instances_component_index = 0;
}
}
@@ -264,7 +264,7 @@ 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_set_finished = true;
+ data->instances_component_index = 0;
deg_invalidate_iterator_work_data(data);
deg::IDNode *id_node = deg_graph->id_nodes[data->id_node_index];
@@ -300,15 +300,29 @@ void DEG_iterator_objects_next(BLI_Iterator *iter)
if (GS(current_id->name) == ID_OB) {
Object *current_object = (Object *)current_id;
if (current_object->runtime.geometry_set_eval != nullptr) {
- if (!data->geometry_set_finished) {
- bke::GeometrySet *geometry_set = bke::unwrap(current_object->runtime.geometry_set_eval);
- PointCloud *pointcloud = (PointCloud *)geometry_set->get_pointcloud_for_read();
- Object *temp_object = &data->temp_dupli_object;
- *temp_object = *current_object;
- temp_object->data = pointcloud;
- iter->current = temp_object;
- data->geometry_set_finished = true;
- return;
+ bke::GeometrySet *geometry_set = bke::unwrap(current_object->runtime.geometry_set_eval);
+ const bke::InstancesComponent *component =
+ geometry_set->get_component_for_read<bke::InstancesComponent>();
+ if (component != nullptr) {
+ blender::Span<blender::float3> positions = component->positions();
+ const Object *object_to_instance = component->instanced_object();
+ if (data->instances_component_index < positions.size()) {
+ blender::float3 position = positions[data->instances_component_index];
+ if (object_to_instance != nullptr) {
+ float mat[4][4];
+ copy_m4_m4(mat, current_object->obmat);
+ translate_m4(mat, position.x, position.y, position.z);
+
+ Object *temp_object = &data->temp_dupli_object;
+ *temp_object = *object_to_instance;
+ mul_m4_m4_post(mat, object_to_instance->obmat);
+ copy_m4_m4(temp_object->obmat, mat);
+ iter->current = temp_object;
+
+ data->instances_component_index++;
+ return;
+ }
+ }
}
}
}
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index a2dbcc1ce8b..1e1bbfb55f1 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -91,7 +91,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
if (nmd->instance_object_temp) {
DEG_add_object_relation(
- ctx->node, nmd->instance_object_temp, DEG_OB_COMP_ANY, "nodes modifier");
+ ctx->node, nmd->instance_object_temp, DEG_OB_COMP_GEOMETRY, "nodes modifier");
}
/* TODO: Add relations for IDs in settings. */
More information about the Bf-blender-cvs
mailing list