45 return this->kinds.
size();
266 for (const int i : range) {
267 dst[i] = transform * src[i];
277 src.type().copy_construct_n(src.slice(range).data(), dst.slice(range).data(), range.size());
285 value.type()->fill_construct_n(value.get(), dst.slice(range).data(), range.size());
290 const Span<std::optional<GVArraySpan>> src_attributes,
298 for (const int attribute_index : attribute_range) {
299 const eAttrDomain domain = ordered_attributes.kinds[attribute_index].domain;
300 const IndexRange element_slice = range_fn(domain);
302 GMutableSpan dst_span = dst_attribute_writers[attribute_index].span.slice(element_slice);
303 if (src_attributes[attribute_index].has_value()) {
304 threaded_copy(*src_attributes[attribute_index], dst_span);
307 const CPPType &cpp_type = dst_span.type();
308 const void *fallback = attribute_fallbacks.array[attribute_index] == nullptr ?
309 cpp_type.default_value() :
310 attribute_fallbacks.array[attribute_index];
311 threaded_fill({cpp_type, fallback}, dst_span);
322 if (
options.keep_original_ids) {
333 for (const int i : range) {
334 dst_ids[i] = noise::hash(task_id, i);
340 for (const int i : range) {
341 dst_ids[i] = noise::hash(task_id, stored_ids[i]);
356 const InstanceContext &base_instance_context);
372 const int attribute_index = ordered_attributes.
ids.index_of_try(attribute_id);
373 if (attribute_index == -1) {
379 if (meta_data.
data_type != expected_type) {
380 const CPPType &from_type = span.type();
381 const CPPType &to_type = *custom_data_type_to_cpp_type(expected_type);
382 const bke::DataTypeConversions &conversions = bke::get_implicit_type_conversions();
383 if (!conversions.is_convertible(from_type, to_type)) {
390 conversions.convert_to_initialized_n(span, temporary_array->as_mutable_span());
391 span = temporary_array->as_span();
394 attributes_to_override.
append({attribute_index, span});
398 return attributes_to_override;
411 switch (reference.
type()) {
415 fn(object_geometry_set, base_transform,
id);
420 float4x4 offset_matrix = float4x4::identity();
425 const float4x4 matrix = base_transform * offset_matrix *
object->obmat;
427 fn(object_geometry_set, matrix, sub_id);
435 fn(instance_geometry_set, base_transform,
id);
456 if (ids.has_value()) {
457 stored_instance_ids = ids->typed<
int>();
477 for (
const std::pair<int, GSpan> &pair : pointcloud_attributes_to_override) {
480 for (
const std::pair<int, GSpan> &pair : mesh_attributes_to_override) {
481 instance_context.
meshes.
array[pair.first] = pair.second[i];
483 for (
const std::pair<int, GSpan> &pair : curve_attributes_to_override) {
484 instance_context.
curves.
array[pair.first] = pair.second[i];
489 if (stored_instance_ids.
is_empty()) {
493 local_instance_id = (
uint32_t)stored_instance_ids[i];
505 instance_context.
id =
id;
507 instance_geometry_set,
534 base_instance_context.
meshes,
535 base_instance_context.
id});
547 if (pointcloud !=
nullptr && pointcloud->
totpoint > 0) {
555 base_instance_context.
id});
563 if (
curves !=
nullptr &&
curves->geometry.curve_num > 0) {
569 base_instance_context.
curves,
570 base_instance_context.
id});
580 gather_info, instances_component, base_transform, base_instance_context);
615 if (
options.realize_instance_attributes) {
622 attributes_to_propagate.
remove(
"position");
623 r_create_id = attributes_to_propagate.
pop_try(
"id").has_value();
625 for (
const auto item : attributes_to_propagate.
items()) {
626 ordered_attributes.
ids.add_new(item.key);
627 ordered_attributes.
kinds.append(item.value);
629 return ordered_attributes;
636 if (pointcloud->totpoint > 0) {
637 r_pointclouds.
add(pointcloud);
642 instances->foreach_referenced_geometry([&](
const GeometrySet &instance_geometry_set) {
657 for (
const int pointcloud_index : info.
realize_info.index_range()) {
669 if (attributes.
contains(attribute_id)) {
710 task.attribute_fallbacks,
713 BLI_assert(domain == ATTR_DOMAIN_POINT);
714 UNUSED_VARS_NDEBUG(domain);
717 dst_attribute_writers);
738 dst_component.
replace(dst_pointcloud);
753 for (
const int attribute_index : ordered_attributes.
index_range()) {
762 for (const int task_index : task_range) {
763 const RealizePointCloudTask &task = tasks[task_index];
764 execute_realize_pointcloud_task(options,
767 dst_attribute_writers,
774 for (GSpanAttributeWriter &dst_attribute : dst_attribute_writers) {
775 dst_attribute.finish();
794 if (
options.realize_instance_attributes) {
801 attributes_to_propagate.
remove(
"position");
802 attributes_to_propagate.
remove(
"normal");
803 attributes_to_propagate.
remove(
"material_index");
804 attributes_to_propagate.
remove(
"shade_smooth");
805 attributes_to_propagate.
remove(
"crease");
806 r_create_id = attributes_to_propagate.
pop_try(
"id").has_value();
808 for (
const auto item : attributes_to_propagate.
items()) {
809 ordered_attributes.
ids.add_new(item.key);
810 ordered_attributes.
kinds.append(item.value);
812 return ordered_attributes;
825 instances->foreach_referenced_geometry([&](
const GeometrySet &instance_geometry_set) {
846 for (
const int mesh_index : info.
realize_info.index_range()) {
866 if (attributes.
contains(attribute_id)) {
904 for (const int i : vert_range) {
905 const MVert &src_vert = src_verts[i];
906 MVert &dst_vert = dst_verts[i];
908 copy_v3_v3(dst_vert.co, task.transform * float3(src_vert.co));
912 for (const int i : edge_range) {
913 const MEdge &src_edge = src_edges[i];
914 MEdge &dst_edge = dst_edges[i];
916 dst_edge.v1 += task.start_indices.vertex;
917 dst_edge.v2 += task.start_indices.vertex;
921 for (const int i : loop_range) {
922 const MLoop &src_loop = src_loops[i];
923 MLoop &dst_loop = dst_loops[i];
925 dst_loop.v += task.start_indices.vertex;
926 dst_loop.e += task.start_indices.edge;
930 for (const int i : poly_range) {
931 const MPoly &src_poly = src_polys[i];
932 MPoly &dst_poly = dst_polys[i];
934 dst_poly.loopstart += task.start_indices.loop;
935 if (src_poly.mat_nr >= 0 && src_poly.mat_nr < mesh.totcol) {
936 dst_poly.mat_nr = material_index_map[src_poly.mat_nr];
945 if (!all_dst_vertex_ids.is_empty()) {
947 mesh_info.stored_vertex_ids,
953 mesh_info.attributes,
954 task.attribute_fallbacks,
958 case ATTR_DOMAIN_POINT:
959 return IndexRange(task.start_indices.vertex, mesh.totvert);
960 case ATTR_DOMAIN_EDGE:
961 return IndexRange(task.start_indices.edge, mesh.totedge);
962 case ATTR_DOMAIN_CORNER:
963 return IndexRange(task.start_indices.loop, mesh.totloop);
964 case ATTR_DOMAIN_FACE:
965 return IndexRange(task.start_indices.poly, mesh.totpoly);
967 BLI_assert_unreachable();
971 dst_attribute_writers);
994 dst_component.
replace(dst_mesh);
1019 for (
const int attribute_index : ordered_attributes.
index_range()) {
1021 const eAttrDomain domain = ordered_attributes.
kinds[attribute_index].domain;
1023 dst_attribute_writers.
append(
1029 for (const int task_index : task_range) {
1030 const RealizeMeshTask &task = tasks[task_index];
1031 execute_realize_mesh_task(
1032 options, task, ordered_attributes, *dst_mesh, dst_attribute_writers, vertex_ids.span);
1037 for (GSpanAttributeWriter &dst_attribute : dst_attribute_writers) {
1038 dst_attribute.finish();
1041 vertex_ids.finish();
1056 if (
options.realize_instance_attributes) {
1063 attributes_to_propagate.
remove(
"position");
1064 attributes_to_propagate.
remove(
"radius");
1065 attributes_to_propagate.
remove(
"resolution");
1066 attributes_to_propagate.
remove(
"handle_right");
1067 attributes_to_propagate.
remove(
"handle_left");
1068 r_create_id = attributes_to_propagate.
pop_try(
"id").has_value();
1070 for (
const auto item : attributes_to_propagate.
items()) {
1071 ordered_attributes.
ids.add_new(item.key);
1072 ordered_attributes.
kinds.append(item.value);
1074 return ordered_attributes;
1081 if (
curves->geometry.curve_num != 0) {
1087 instances->foreach_referenced_geometry([&](
const GeometrySet &instance_geometry_set) {
1102 for (
const int curve_index : info.
realize_info.index_range()) {
1104 const Curves *curves_id = info.
order[curve_index];
1106 curve_info.
curves = curves_id;
1115 if (attributes.
contains(attribute_id)) {
1128 if (attributes.
contains(
"radius")) {
1136 if (attributes.
contains(
"resolution")) {
1141 if (attributes.
contains(
"handle_right")) {
1195 all_radii.
slice(dst_point_range).
fill(1.0f);
1210 for (const int i : range) {
1211 dst_offsets[i] = task.start_indices.point + src_offsets[i];
1215 if (!all_dst_ids.is_empty()) {
1217 options, curves_info.stored_ids,
task.id, all_dst_ids.slice(dst_point_range));
1221 curves_info.attributes,
1222 task.attribute_fallbacks,
1226 case ATTR_DOMAIN_POINT:
1227 return IndexRange(task.start_indices.point, curves.points_num());
1228 case ATTR_DOMAIN_CURVE:
1229 return IndexRange(task.start_indices.curve, curves.curves_num());
1231 BLI_assert_unreachable();
1232 return IndexRange();
1235 dst_attribute_writers);
1258 dst_component.
replace(dst_curves_id);
1274 for (
const int attribute_index : ordered_attributes.
index_range()) {
1276 const eAttrDomain domain = ordered_attributes.
kinds[attribute_index].domain;
1278 dst_attribute_writers.
append(
1307 for (const int task_index : task_range) {
1308 const RealizeCurveTask &task = tasks[task_index];
1309 execute_realize_curve_task(options,
1314 dst_attribute_writers,
1324 dst_curves.runtime->type_counts.fill(0);
1325 for (
const RealizeCurveTask &
task : tasks) {
1327 dst_curves.runtime->type_counts[i] +=
1328 task.curve_info->curves->geometry.runtime->type_counts[i];
1333 for (GSpanAttributeWriter &dst_attribute : dst_attribute_writers) {
1334 dst_attribute.finish();
1343 resolution.finish();
1345 if (all_curves_info.create_handle_postion_attributes) {
1346 handle_left.finish();
1347 handle_right.finish();
1361 InstancesComponent &component = sub_geometry.get_component_for_write<InstancesComponent>();
1362 component.instance_attributes().remove(
"id");
1377 return geometry_set;
1380 if (
options.keep_original_ids) {
1395 create_id_attribute,
1403 all_pointclouds_info,
1426 return new_geometry_set;
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
Low-level operations for curves.
@ GEO_COMPONENT_TYPE_MESH
@ GEO_COMPONENT_TYPE_POINT_CLOUD
@ GEO_COMPONENT_TYPE_INSTANCES
@ GEO_COMPONENT_TYPE_EDIT
@ GEO_COMPONENT_TYPE_CURVE
@ GEO_COMPONENT_TYPE_VOLUME
General operations, lookup, etc. for materials.
void BKE_id_material_eval_assign(struct ID *id, int slot, struct Material *material)
void BKE_mesh_copy_parameters_for_eval(struct Mesh *me_dst, const struct Mesh *me_src)
struct Mesh * BKE_mesh_new_nomain(int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len)
General operations for point clouds.
struct PointCloud * BKE_pointcloud_new_nomain(int totpoint)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
MINLINE void sub_v3_v3(float r[3], const float a[3])
static uint8 component(Color32 c, uint i)
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color attribute
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
const Curves * get_for_read() const
void replace(Curves *curve, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Collection & collection() const
const GeometrySet & geometry_set() const
blender::Span< int > instance_reference_handles() const
blender::bke::CustomDataAttributes & instance_attributes()
blender::Span< InstanceReference > references() const
blender::MutableSpan< blender::float4x4 > instance_transforms()
int instances_num() const
const Mesh * get_for_read() const
void replace(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void replace(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const PointCloud * get_for_read() const
void reinitialize(const int64_t new_size)
const CPPType & type() const
const CPPType * type() const
GSpan get_internal_span() const
bool remove(const Key &key)
ItemIterator items() const
std::optional< Value > pop_try(const Key &key)
constexpr void fill(const T &value)
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr bool is_empty() const
constexpr void copy_from(Span< T > values)
constexpr IndexRange index_range() const
constexpr const T & first() const
constexpr const T & last(const int64_t n=0) const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
void materialize(MutableSpan< T > r_span) const
Span< T > get_internal_span() const
int64_t index_of(const Key &key) const
void append(const T &value)
IndexRange index_range() const
bool contains(const AttributeIDRef &attribute_id) const
GAttributeReader lookup(const AttributeIDRef &attribute_id) const
GVArray lookup_or_default(const AttributeIDRef &attribute_id, const eAttrDomain domain, const eCustomDataType data_type, const void *default_value=nullptr) const
MutableSpan< float3 > positions_for_write()
MutableAttributeAccessor attributes_for_write()
MutableSpan< int > offsets_for_write()
std::optional< blender::GSpan > get_for_read(const AttributeIDRef &attribute_id) const
bool foreach_attribute(const AttributeForeachCallback callback, eAttrDomain domain) const
GSpanAttributeWriter lookup_or_add_for_write_only_span(const AttributeIDRef &attribute_id, const eAttrDomain domain, const eCustomDataType data_type)
CCL_NAMESPACE_BEGIN struct Options options
SyclQueue void void * src
static struct PartialUpdateUser * wrap(PartialUpdateUserImpl *user)
const blender::CPPType * custom_data_type_to_cpp_type(const eCustomDataType type)
void curves_copy_parameters(const Curves &src, Curves &dst)
GeometrySet object_get_evaluated_geometry_set(const Object &object)
AttributeAccessor pointcloud_attributes(const PointCloud &pointcloud)
MutableAttributeAccessor pointcloud_attributes_for_write(PointCloud &pointcloud)
AttributeAccessor mesh_attributes(const Mesh &mesh)
MutableAttributeAccessor mesh_attributes_for_write(Mesh &mesh)
Curves * curves_new_nomain(int points_num, int curves_num)
struct blender::compositor::@179::@181 task
static void execute_realize_pointcloud_tasks(const RealizeInstancesOptions &options, const AllPointCloudsInfo &all_pointclouds_info, const Span< RealizePointCloudTask > tasks, const OrderedAttributes &ordered_attributes, GeometrySet &r_realized_geometry)
static void gather_realize_tasks_recursive(GatherTasksInfo &gather_info, const GeometrySet &geometry_set, const float4x4 &base_transform, const InstanceContext &base_instance_context)
static AllCurvesInfo preprocess_curves(const GeometrySet &geometry_set, const RealizeInstancesOptions &options)
static OrderedAttributes gather_generic_curve_attributes_to_propagate(const GeometrySet &in_geometry_set, const RealizeInstancesOptions &options, bool &r_create_id)
static AllMeshesInfo preprocess_meshes(const GeometrySet &geometry_set, const RealizeInstancesOptions &options)
static void execute_realize_pointcloud_task(const RealizeInstancesOptions &options, const RealizePointCloudTask &task, const OrderedAttributes &ordered_attributes, MutableSpan< GSpanAttributeWriter > dst_attribute_writers, MutableSpan< int > all_dst_ids, MutableSpan< float3 > all_dst_positions)
static void execute_realize_mesh_tasks(const RealizeInstancesOptions &options, const AllMeshesInfo &all_meshes_info, const Span< RealizeMeshTask > tasks, const OrderedAttributes &ordered_attributes, const VectorSet< Material * > &ordered_materials, GeometrySet &r_realized_geometry)
static void foreach_geometry_in_reference(const InstanceReference &reference, const float4x4 &base_transform, const uint32_t id, FunctionRef< void(const GeometrySet &geometry_set, const float4x4 &transform, uint32_t id)> fn)
static void threaded_copy(const GSpan src, GMutableSpan dst)
static void create_result_ids(const RealizeInstancesOptions &options, Span< int > stored_ids, const int task_id, MutableSpan< int > dst_ids)
static void remove_id_attribute_from_instances(GeometrySet &geometry_set)
static AllPointCloudsInfo preprocess_pointclouds(const GeometrySet &geometry_set, const RealizeInstancesOptions &options)
static void gather_meshes_to_realize(const GeometrySet &geometry_set, VectorSet< const Mesh * > &r_meshes)
static void gather_curves_to_realize(const GeometrySet &geometry_set, VectorSet< const Curves * > &r_curves)
static void execute_realize_curve_task(const RealizeInstancesOptions &options, const AllCurvesInfo &all_curves_info, const RealizeCurveTask &task, const OrderedAttributes &ordered_attributes, bke::CurvesGeometry &dst_curves, MutableSpan< GSpanAttributeWriter > dst_attribute_writers, MutableSpan< int > all_dst_ids, MutableSpan< float3 > all_handle_left, MutableSpan< float3 > all_handle_right, MutableSpan< float > all_radii, MutableSpan< int > all_resolutions)
static void gather_realize_tasks_for_instances(GatherTasksInfo &gather_info, const InstancesComponent &instances_component, const float4x4 &base_transform, const InstanceContext &base_instance_context)
GeometrySet realize_instances(GeometrySet geometry_set, const RealizeInstancesOptions &options)
static void threaded_fill(const GPointer value, GMutableSpan dst)
static void copy_generic_attributes_to_result(const Span< std::optional< GVArraySpan >> src_attributes, const AttributeFallbacksArray &attribute_fallbacks, const OrderedAttributes &ordered_attributes, const FunctionRef< IndexRange(eAttrDomain)> &range_fn, MutableSpan< GSpanAttributeWriter > dst_attribute_writers)
static Vector< std::pair< int, GSpan > > prepare_attribute_fallbacks(GatherTasksInfo &gather_info, const InstancesComponent &instances_component, const OrderedAttributes &ordered_attributes)
static void gather_pointclouds_to_realize(const GeometrySet &geometry_set, VectorSet< const PointCloud * > &r_pointclouds)
static OrderedAttributes gather_generic_mesh_attributes_to_propagate(const GeometrySet &in_geometry_set, const RealizeInstancesOptions &options, bool &r_create_id)
static OrderedAttributes gather_generic_pointcloud_attributes_to_propagate(const GeometrySet &in_geometry_set, const RealizeInstancesOptions &options, bool &r_create_id)
static void execute_realize_mesh_task(const RealizeInstancesOptions &options, const RealizeMeshTask &task, const OrderedAttributes &ordered_attributes, Mesh &dst_mesh, MutableSpan< GSpanAttributeWriter > dst_attribute_writers, MutableSpan< int > all_dst_vertex_ids)
static void copy_transformed_positions(const Span< float3 > src, const float4x4 &transform, MutableSpan< float3 > dst)
static void execute_realize_curve_tasks(const RealizeInstancesOptions &options, const AllCurvesInfo &all_curves_info, const Span< RealizeCurveTask > tasks, const OrderedAttributes &ordered_attributes, GeometrySet &r_realized_geometry)
static Type to_type(const eGPUType type)
void parallel_for(IndexRange range, int64_t grain_size, const Function &function)
MutableSpan< float3 > positions
const PointCloud * get_pointcloud_for_read() const
GeometryComponent & get_component_for_write(GeometryComponentType component_type)
blender::Vector< const GeometryComponent * > get_components_for_read() const
bool has(const GeometryComponentType component_type) const
const GeometryComponent * get_component_for_read(GeometryComponentType component_type) const
const Mesh * get_mesh_for_read() const
const Curves * get_curves_for_read() const
void gather_attributes_for_propagation(blender::Span< GeometryComponentType > component_types, GeometryComponentType dst_component_type, bool include_instances, blender::Map< blender::bke::AttributeIDRef, blender::bke::AttributeKind > &r_attributes) const
void add(const GeometryComponent &component)
bool has_instances() const
void modify_geometry_sets(ForeachSubGeometryCallback callback)
ListBase vertex_group_names
bool create_handle_postion_attributes
OrderedAttributes attributes
bool create_radius_attribute
VectorSet< const Curves * > order
Array< RealizeCurveInfo > realize_info
bool create_resolution_attribute
VectorSet< Material * > materials
VectorSet< const Mesh * > order
OrderedAttributes attributes
Array< MeshRealizeInfo > realize_info
Array< PointCloudRealizeInfo > realize_info
VectorSet< const PointCloud * > order
OrderedAttributes attributes
AttributeFallbacksArray(int size)
Array< const void * > array
MeshElementStartIndices mesh_offsets
CurvesElementStartIndices curves_offsets
const AllPointCloudsInfo & pointclouds
const AllCurvesInfo & curves
const AllMeshesInfo & meshes
bool create_id_attribute_on_any_component
Vector< std::unique_ptr< GArray<> > > & r_temporary_arrays
Vector< RealizeMeshTask > mesh_tasks
Vector< RealizePointCloudTask > pointcloud_tasks
UserCounter< const VolumeComponent > first_volume
Vector< RealizeCurveTask > curve_tasks
UserCounter< const GeometryComponentEditData > first_edit_data
InstanceContext(const GatherTasksInfo &gather_info)
AttributeFallbacksArray meshes
AttributeFallbacksArray pointclouds
AttributeFallbacksArray curves
Span< int > stored_vertex_ids
Array< std::optional< GVArraySpan > > attributes
Array< int > material_index_map
IndexRange index_range() const
VectorSet< AttributeIDRef > ids
Vector< AttributeKind > kinds
Array< std::optional< GVArraySpan > > attributes
const PointCloud * pointcloud
Span< float3 > handle_left
Span< float3 > handle_right
Array< std::optional< GVArraySpan > > attributes
const RealizeCurveInfo * curve_info
AttributeFallbacksArray attribute_fallbacks
CurvesElementStartIndices start_indices
AttributeFallbacksArray attribute_fallbacks
const MeshRealizeInfo * mesh_info
MeshElementStartIndices start_indices
AttributeFallbacksArray attribute_fallbacks
const PointCloudRealizeInfo * pointcloud_info