Geometry Nodes: move geometry component type enum to C

This allows us to use it in rna for the spreadsheet editor.
This commit is contained in:
Jacques Lucke 2021-03-10 11:53:17 +01:00
parent 122fefcc85
commit 368647bd25
10 changed files with 35 additions and 35 deletions

View File

@ -28,6 +28,16 @@ struct Collection;
struct GeometrySet;
struct Object;
/* Each geometry component has a specific type. The type determines what kind of data the component
* stores. Functions modifying a geometry will usually just modify a subset of the component types.
*/
typedef enum GeometryComponentType {
GEO_COMPONENT_TYPE_MESH = 0,
GEO_COMPONENT_TYPE_POINT_CLOUD = 1,
GEO_COMPONENT_TYPE_INSTANCES = 2,
GEO_COMPONENT_TYPE_VOLUME = 3,
} GeometryComponentType;
void BKE_geometry_set_free(struct GeometrySet *geometry_set);
bool BKE_geometry_set_has_instances(const struct GeometrySet *geometry_set);

View File

@ -40,16 +40,6 @@ struct Object;
struct PointCloud;
struct Volume;
/* Each geometry component has a specific type. The type determines what kind of data the component
* stores. Functions modifying a geometry will usually just modify a subset of the component types.
*/
enum class GeometryComponentType {
Mesh = 0,
PointCloud = 1,
Instances = 2,
Volume = 3,
};
enum class GeometryOwnershipType {
/* The geometry is owned. This implies that it can be changed. */
Owned = 0,
@ -392,7 +382,7 @@ class MeshComponent : public GeometryComponent {
bool is_empty() const final;
static constexpr inline GeometryComponentType static_type = GeometryComponentType::Mesh;
static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_MESH;
private:
const blender::bke::ComponentAttributeProviders *get_attribute_providers() const final;
@ -422,7 +412,7 @@ class PointCloudComponent : public GeometryComponent {
bool is_empty() const final;
static constexpr inline GeometryComponentType static_type = GeometryComponentType::PointCloud;
static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_POINT_CLOUD;
private:
const blender::bke::ComponentAttributeProviders *get_attribute_providers() const final;
@ -462,7 +452,7 @@ class InstancesComponent : public GeometryComponent {
bool is_empty() const final;
static constexpr inline GeometryComponentType static_type = GeometryComponentType::Instances;
static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_INSTANCES;
};
/** A geometry component that stores volume grids. */
@ -484,5 +474,5 @@ class VolumeComponent : public GeometryComponent {
const Volume *get_for_read() const;
Volume *get_for_write();
static constexpr inline GeometryComponentType static_type = GeometryComponentType::Volume;
static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_VOLUME;
};

View File

@ -35,7 +35,7 @@ using blender::Span;
/** \name Geometry Component Implementation
* \{ */
InstancesComponent::InstancesComponent() : GeometryComponent(GeometryComponentType::Instances)
InstancesComponent::InstancesComponent() : GeometryComponent(GEO_COMPONENT_TYPE_INSTANCES)
{
}

View File

@ -39,7 +39,7 @@ using blender::bke::ReadAttributePtr;
/** \name Geometry Component Implementation
* \{ */
MeshComponent::MeshComponent() : GeometryComponent(GeometryComponentType::Mesh)
MeshComponent::MeshComponent() : GeometryComponent(GEO_COMPONENT_TYPE_MESH)
{
}
@ -466,14 +466,14 @@ ReadAttributePtr MeshComponent::attribute_try_adapt_domain(ReadAttributePtr attr
static Mesh *get_mesh_from_component_for_write(GeometryComponent &component)
{
BLI_assert(component.type() == GeometryComponentType::Mesh);
BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH);
MeshComponent &mesh_component = static_cast<MeshComponent &>(component);
return mesh_component.get_for_write();
}
static const Mesh *get_mesh_from_component_for_read(const GeometryComponent &component)
{
BLI_assert(component.type() == GeometryComponentType::Mesh);
BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH);
const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
return mesh_component.get_for_read();
}
@ -713,7 +713,7 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider {
ReadAttributePtr try_get_for_read(const GeometryComponent &component,
const StringRef attribute_name) const final
{
BLI_assert(component.type() == GeometryComponentType::Mesh);
BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH);
const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
const Mesh *mesh = mesh_component.get_for_read();
const int vertex_group_index = mesh_component.vertex_group_names().lookup_default_as(
@ -733,7 +733,7 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider {
WriteAttributePtr try_get_for_write(GeometryComponent &component,
const StringRef attribute_name) const final
{
BLI_assert(component.type() == GeometryComponentType::Mesh);
BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH);
MeshComponent &mesh_component = static_cast<MeshComponent &>(component);
Mesh *mesh = mesh_component.get_for_write();
if (mesh == nullptr) {
@ -758,7 +758,7 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider {
bool try_delete(GeometryComponent &component, const StringRef attribute_name) const final
{
BLI_assert(component.type() == GeometryComponentType::Mesh);
BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH);
MeshComponent &mesh_component = static_cast<MeshComponent &>(component);
const int vertex_group_index = mesh_component.vertex_group_names().pop_default_as(
@ -783,7 +783,7 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider {
bool foreach_attribute(const GeometryComponent &component,
const AttributeForeachCallback callback) const final
{
BLI_assert(component.type() == GeometryComponentType::Mesh);
BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH);
const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
for (const auto item : mesh_component.vertex_group_names().items()) {
const StringRefNull name = item.key;

View File

@ -27,7 +27,7 @@
/** \name Geometry Component Implementation
* \{ */
PointCloudComponent::PointCloudComponent() : GeometryComponent(GeometryComponentType::PointCloud)
PointCloudComponent::PointCloudComponent() : GeometryComponent(GEO_COMPONENT_TYPE_POINT_CLOUD)
{
}

View File

@ -24,7 +24,7 @@
/** \name Geometry Component Implementation
* \{ */
VolumeComponent::VolumeComponent() : GeometryComponent(GeometryComponentType::Volume)
VolumeComponent::VolumeComponent() : GeometryComponent(GEO_COMPONENT_TYPE_VOLUME)
{
}

View File

@ -56,13 +56,13 @@ GeometryComponent ::~GeometryComponent()
GeometryComponent *GeometryComponent::create(GeometryComponentType component_type)
{
switch (component_type) {
case GeometryComponentType::Mesh:
case GEO_COMPONENT_TYPE_MESH:
return new MeshComponent();
case GeometryComponentType::PointCloud:
case GEO_COMPONENT_TYPE_POINT_CLOUD:
return new PointCloudComponent();
case GeometryComponentType::Instances:
case GEO_COMPONENT_TYPE_INSTANCES:
return new InstancesComponent();
case GeometryComponentType::Volume:
case GEO_COMPONENT_TYPE_VOLUME:
return new VolumeComponent();
}
BLI_assert(false);

View File

@ -371,9 +371,9 @@ static void join_instance_groups_mesh(Span<GeometryInstanceGroup> set_groups,
dst_component.replace(new_mesh);
Vector<GeometryComponentType> component_types;
component_types.append(GeometryComponentType::Mesh);
component_types.append(GEO_COMPONENT_TYPE_MESH);
if (convert_points_to_vertices) {
component_types.append(GeometryComponentType::PointCloud);
component_types.append(GEO_COMPONENT_TYPE_POINT_CLOUD);
}
/* Don't copy attributes that are stored directly in the mesh data structs. */
@ -402,9 +402,9 @@ static void join_instance_groups_pointcloud(Span<GeometryInstanceGroup> set_grou
PointCloud *pointcloud = BKE_pointcloud_new_nomain(totpoint);
dst_component.replace(pointcloud);
Map<std::string, AttributeKind> attributes;
gather_attribute_info(attributes, {GeometryComponentType::PointCloud}, set_groups, {});
gather_attribute_info(attributes, {GEO_COMPONENT_TYPE_POINT_CLOUD}, set_groups, {});
join_attributes(set_groups,
{GeometryComponentType::PointCloud},
{GEO_COMPONENT_TYPE_POINT_CLOUD},
attributes,
static_cast<GeometryComponent &>(dst_component));
}

View File

@ -408,7 +408,7 @@ std::unique_ptr<SpreadsheetDrawer> spreadsheet_drawer_from_geometry_attributes(c
"geometry set");
const AttributeDomain domain = ATTR_DOMAIN_POINT;
const GeometryComponentType component_type = GeometryComponentType::Mesh;
const GeometryComponentType component_type = GEO_COMPONENT_TYPE_MESH;
const GeometryComponent *component = geometry_set.get_component_for_read(component_type);
if (component == nullptr) {
return {};
@ -425,7 +425,7 @@ std::unique_ptr<SpreadsheetDrawer> spreadsheet_drawer_from_geometry_attributes(c
}
/* The filter below only works for mesh vertices currently. */
BLI_assert(domain == ATTR_DOMAIN_POINT && component_type == GeometryComponentType::Mesh);
BLI_assert(domain == ATTR_DOMAIN_POINT && component_type == GEO_COMPONENT_TYPE_MESH);
Span<int64_t> visible_rows = filter_visible_mesh_vertex_rows(
C, object_eval, static_cast<const MeshComponent *>(component), *resources);

View File

@ -695,7 +695,7 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
Map<std::string, AttributeKind> attributes;
bke::gather_attribute_info(
attributes, {GeometryComponentType::Mesh}, set_groups, {"position", "normal", "id"});
attributes, {GEO_COMPONENT_TYPE_MESH}, set_groups, {"position", "normal", "id"});
add_remaining_point_attributes(set_groups,
instance_start_offsets,
attributes,