This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/geometry/GEO_realize_instances.hh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
1.5 KiB
C++
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0-or-later */
Geometry Nodes: support instance attributes when realizing instances This patch refactors the instance-realization code and adds new functionality. * Named and anonymous attributes are propagated from instances to the realized geometry. If the same attribute exists on the geometry and on an instance, the attribute on the geometry has precedence. * The id attribute has special handling to avoid creating the same id on many output points. This is necessary to make e.g. the Random Value node work as expected afterwards. Realizing instance attributes has an effect on existing files, especially due to the id attribute. To avoid breaking existing files, the Realize Instances node now has a legacy option that is enabled for all already existing Realize Instances nodes. Removing this legacy behavior does affect some existing files (although not many). We can decide whether it's worth to remove the old behavior as a separate step. This refactor also improves performance when realizing instances. That is mainly due to multi-threading. See D13446 to get the file used for benchmarking. The curve code is not as optimized as it could be yet. That's mainly because the storage for these attributes might change soonish and it wasn't worth optimizing for the current storage format right now. ``` 1,000,000 x mesh vertex: 530 ms -> 130 ms 1,000,000 x simple cube: 1290 ms -> 190 ms 1,000,000 x point: 1000 ms -> 150 ms 1,000,000 x curve spiral: 1740 ms -> 330 ms 1,000,000 x curve line: 1110 ms -> 210 ms 10,000 x subdivided cylinder: 170 ms -> 40 ms 10 x subdivided spiral: 180 ms -> 180 ms ``` Differential Revision: https://developer.blender.org/D13446
2021-12-14 15:57:58 +01:00
#pragma once
#include "BKE_geometry_set.hh"
namespace blender::geometry {
struct RealizeInstancesOptions {
/**
* The default is to generate new ids for every element (when there was any id attribute in the
* input). This avoids having a geometry that contains the same id many times.
* When this is `true` the ids on the original geometries are kept unchanged and ids on instances
* are ignored. Ids are zero initialized when the original geometry did not have an id.
*/
bool keep_original_ids = false;
/**
* When `true` the output geometry will contain all the generic attributes that existed on
* instances. Otherwise, instance attributes are ignored.
*/
bool realize_instance_attributes = true;
};
/**
* Join all instances into a single geometry component for each geometry type. For example, all
* mesh instances (including the already realized mesh) are joined into a single mesh. The output
* geometry set does not contain any instances. If the input did not contain any instances, it is
* returned directly.
*
* The `id` attribute has special handling. If there is an id attribute on any component, the
* output will contain an `id` attribute as well. The output id is generated by mixing/hashing ids
* of instances and of the instanced geometry data.
*/
GeometrySet realize_instances(GeometrySet geometry_set, const RealizeInstancesOptions &options);
} // namespace blender::geometry