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-02-12 19:41:28 +0300
committerJacques Lucke <jacques@blender.org>2021-02-12 19:44:27 +0300
commit98db4cc6391df8c8b21516bbdbc0af8f493a15b3 (patch)
treed267c2e78947d07e85a58e386b260357b86acf85 /source/blender/blenkernel/intern/object_dupli.c
parentccea44e76bbd06309e0012ed3213a9028e8cb32c (diff)
Fix T84899: instance ids are not unique in common cases
Ids stored in the `id` attribute cannot be assumed to be unique. While they might be unique in some cases, this is not something that can be guaranteed in general. For some use cases (e.g. generating "stable randomness" on points) uniqueness is not important. To support features like motion blur, unique ids are important though. This patch implements a simple algorithm that turns non-unique ids into unique ones. It might fail to do so under very unlikely circumstances, in which it returns non-unique ids instead of possibly going into an endless loop. Here are some requirements I set for the algorithm: * Ids that are unique already, must not be changed. * The same input should generate the same output. * Handle cases when all ids are different and when all ids are the same equally well (in expected linear time). * Small changes in the input id array should ideally only have a small impact on the output id array. The reported bug happened because cycles found multiple objects with the same id and thought that it was a single object that moved on every check. Differential Revision: https://developer.blender.org/D10402
Diffstat (limited to 'source/blender/blenkernel/intern/object_dupli.c')
-rw-r--r--source/blender/blenkernel/intern/object_dupli.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 6c8a57f8599..632e7519f05 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -814,15 +814,17 @@ static const DupliGenerator gen_dupli_verts_pointcloud = {
static void make_duplis_instances_component(const DupliContext *ctx)
{
float(*instance_offset_matrices)[4][4];
- int *ids;
InstancedData *instanced_data;
- const int amount = BKE_geometry_set_instances(
- ctx->object->runtime.geometry_set_eval, &instance_offset_matrices, &ids, &instanced_data);
+ const int *almost_unique_ids;
+ const int amount = BKE_geometry_set_instances(ctx->object->runtime.geometry_set_eval,
+ &instance_offset_matrices,
+ &almost_unique_ids,
+ &instanced_data);
for (int i = 0; i < amount; i++) {
InstancedData *data = &instanced_data[i];
- const int id = ids[i] != -1 ? ids[i] : i;
+ const int id = almost_unique_ids[i];
if (data->type == INSTANCE_DATA_TYPE_OBJECT) {
Object *object = data->data.object;