Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/geometry_set.cc
| Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | return components_.add_or_modify( | ||||
| /* If the referenced component is shared, make a copy. The copy is not shared and is | /* If the referenced component is shared, make a copy. The copy is not shared and is | ||||
| * therefore mutable. */ | * therefore mutable. */ | ||||
| GeometryComponent *copied_component = value->copy(); | GeometryComponent *copied_component = value->copy(); | ||||
| value = GeometryComponentPtr{copied_component}; | value = GeometryComponentPtr{copied_component}; | ||||
| return *copied_component; | return *copied_component; | ||||
| }); | }); | ||||
| } | } | ||||
| /** | |||||
| * Retrieve the pointer to a component without creating it if it does not exist, | |||||
| * unlike #get_component_for_write. | |||||
| */ | |||||
| GeometryComponent *GeometrySet::get_component_ptr(GeometryComponentType type) | |||||
| { | |||||
| GeometryComponentPtr *component_ptr = components_.lookup_ptr(type); | |||||
JacquesLucke: `lookup_ptr` can return `nullptr`. | |||||
| return component_ptr == nullptr ? nullptr : component_ptr->get(); | |||||
| } | |||||
| /* Get the component of the given type. Might return null if the component does not exist yet. */ | /* Get the component of the given type. Might return null if the component does not exist yet. */ | ||||
| const GeometryComponent *GeometrySet::get_component_for_read( | const GeometryComponent *GeometrySet::get_component_for_read( | ||||
| GeometryComponentType component_type) const | GeometryComponentType component_type) const | ||||
| { | { | ||||
| const GeometryComponentPtr *component = components_.lookup_ptr(component_type); | const GeometryComponentPtr *component = components_.lookup_ptr(component_type); | ||||
| if (component != nullptr) { | if (component != nullptr) { | ||||
| return component->get(); | return component->get(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | bool GeometrySet::is_empty() const | ||||
| return !(this->has_mesh() || this->has_curve() || this->has_pointcloud() || | return !(this->has_mesh() || this->has_curve() || this->has_pointcloud() || | ||||
| this->has_instances()); | this->has_instances()); | ||||
| } | } | ||||
| /* Create a new geometry set that only contains the given mesh. */ | /* Create a new geometry set that only contains the given mesh. */ | ||||
| GeometrySet GeometrySet::create_with_mesh(Mesh *mesh, GeometryOwnershipType ownership) | GeometrySet GeometrySet::create_with_mesh(Mesh *mesh, GeometryOwnershipType ownership) | ||||
| { | { | ||||
| GeometrySet geometry_set; | GeometrySet geometry_set; | ||||
| if (mesh != nullptr) { | |||||
| MeshComponent &component = geometry_set.get_component_for_write<MeshComponent>(); | MeshComponent &component = geometry_set.get_component_for_write<MeshComponent>(); | ||||
| component.replace(mesh, ownership); | component.replace(mesh, ownership); | ||||
| } | |||||
| return geometry_set; | return geometry_set; | ||||
| } | } | ||||
| /* Create a new geometry set that only contains the given point cloud. */ | /* Create a new geometry set that only contains the given point cloud. */ | ||||
| GeometrySet GeometrySet::create_with_pointcloud(PointCloud *pointcloud, | GeometrySet GeometrySet::create_with_pointcloud(PointCloud *pointcloud, | ||||
| GeometryOwnershipType ownership) | GeometryOwnershipType ownership) | ||||
| { | { | ||||
| GeometrySet geometry_set; | GeometrySet geometry_set; | ||||
| if (pointcloud != nullptr) { | |||||
| PointCloudComponent &component = geometry_set.get_component_for_write<PointCloudComponent>(); | PointCloudComponent &component = geometry_set.get_component_for_write<PointCloudComponent>(); | ||||
| component.replace(pointcloud, ownership); | component.replace(pointcloud, ownership); | ||||
| } | |||||
| return geometry_set; | return geometry_set; | ||||
| } | } | ||||
| /* Create a new geometry set that only contains the given curve. */ | /* Create a new geometry set that only contains the given curve. */ | ||||
| GeometrySet GeometrySet::create_with_curve(CurveEval *curve, GeometryOwnershipType ownership) | GeometrySet GeometrySet::create_with_curve(CurveEval *curve, GeometryOwnershipType ownership) | ||||
| { | { | ||||
| GeometrySet geometry_set; | GeometrySet geometry_set; | ||||
| if (curve != nullptr) { | |||||
| CurveComponent &component = geometry_set.get_component_for_write<CurveComponent>(); | CurveComponent &component = geometry_set.get_component_for_write<CurveComponent>(); | ||||
| component.replace(curve, ownership); | component.replace(curve, ownership); | ||||
| } | |||||
| return geometry_set; | return geometry_set; | ||||
| } | } | ||||
| /* Clear the existing mesh and replace it with the given one. */ | /* Clear the existing mesh and replace it with the given one. */ | ||||
| void GeometrySet::replace_mesh(Mesh *mesh, GeometryOwnershipType ownership) | void GeometrySet::replace_mesh(Mesh *mesh, GeometryOwnershipType ownership) | ||||
| { | { | ||||
| if (mesh == nullptr) { | |||||
| this->remove<MeshComponent>(); | |||||
| } | |||||
| else { | |||||
| MeshComponent &component = this->get_component_for_write<MeshComponent>(); | MeshComponent &component = this->get_component_for_write<MeshComponent>(); | ||||
| component.replace(mesh, ownership); | component.replace(mesh, ownership); | ||||
| } | } | ||||
| } | |||||
| /* Clear the existing curve and replace it with the given one. */ | /* Clear the existing curve and replace it with the given one. */ | ||||
| void GeometrySet::replace_curve(CurveEval *curve, GeometryOwnershipType ownership) | void GeometrySet::replace_curve(CurveEval *curve, GeometryOwnershipType ownership) | ||||
| { | { | ||||
| if (curve == nullptr) { | |||||
| this->remove<CurveComponent>(); | |||||
| } | |||||
| else { | |||||
| CurveComponent &component = this->get_component_for_write<CurveComponent>(); | CurveComponent &component = this->get_component_for_write<CurveComponent>(); | ||||
| component.replace(curve, ownership); | component.replace(curve, ownership); | ||||
| } | } | ||||
| } | |||||
| /* Clear the existing point cloud and replace with the given one. */ | /* Clear the existing point cloud and replace with the given one. */ | ||||
| void GeometrySet::replace_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership) | void GeometrySet::replace_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership) | ||||
| { | { | ||||
| PointCloudComponent &pointcloud_component = this->get_component_for_write<PointCloudComponent>(); | if (pointcloud == nullptr) { | ||||
| pointcloud_component.replace(pointcloud, ownership); | this->remove<PointCloudComponent>(); | ||||
| } | |||||
| else { | |||||
| PointCloudComponent &component = this->get_component_for_write<PointCloudComponent>(); | |||||
| component.replace(pointcloud, ownership); | |||||
| } | |||||
| } | } | ||||
| /* Clear the existing volume and replace with the given one. */ | /* Clear the existing volume and replace with the given one. */ | ||||
| void GeometrySet::replace_volume(Volume *volume, GeometryOwnershipType ownership) | void GeometrySet::replace_volume(Volume *volume, GeometryOwnershipType ownership) | ||||
| { | { | ||||
| VolumeComponent &volume_component = this->get_component_for_write<VolumeComponent>(); | if (volume == nullptr) { | ||||
| volume_component.replace(volume, ownership); | this->remove<VolumeComponent>(); | ||||
| } | |||||
| else { | |||||
| VolumeComponent &component = this->get_component_for_write<VolumeComponent>(); | |||||
| component.replace(volume, ownership); | |||||
| } | |||||
| } | } | ||||
| /* Returns a mutable mesh or null. No ownership is transferred. */ | /* Returns a mutable mesh or null. No ownership is transferred. */ | ||||
| Mesh *GeometrySet::get_mesh_for_write() | Mesh *GeometrySet::get_mesh_for_write() | ||||
| { | { | ||||
| MeshComponent &component = this->get_component_for_write<MeshComponent>(); | MeshComponent *component = this->get_component_ptr<MeshComponent>(); | ||||
| return component.get_for_write(); | return component == nullptr ? nullptr : component->get_for_write(); | ||||
| } | } | ||||
| /* Returns a mutable point cloud or null. No ownership is transferred. */ | /* Returns a mutable point cloud or null. No ownership is transferred. */ | ||||
| PointCloud *GeometrySet::get_pointcloud_for_write() | PointCloud *GeometrySet::get_pointcloud_for_write() | ||||
| { | { | ||||
| PointCloudComponent &component = this->get_component_for_write<PointCloudComponent>(); | PointCloudComponent *component = this->get_component_ptr<PointCloudComponent>(); | ||||
| return component.get_for_write(); | return component == nullptr ? nullptr : component->get_for_write(); | ||||
| } | } | ||||
| /* Returns a mutable volume or null. No ownership is transferred. */ | /* Returns a mutable volume or null. No ownership is transferred. */ | ||||
| Volume *GeometrySet::get_volume_for_write() | Volume *GeometrySet::get_volume_for_write() | ||||
| { | { | ||||
| VolumeComponent &component = this->get_component_for_write<VolumeComponent>(); | VolumeComponent *component = this->get_component_ptr<VolumeComponent>(); | ||||
| return component.get_for_write(); | return component == nullptr ? nullptr : component->get_for_write(); | ||||
| } | } | ||||
| /* Returns a mutable curve or null. No ownership is transferred. */ | /* Returns a mutable curve or null. No ownership is transferred. */ | ||||
| CurveEval *GeometrySet::get_curve_for_write() | CurveEval *GeometrySet::get_curve_for_write() | ||||
| { | { | ||||
| CurveComponent &component = this->get_component_for_write<CurveComponent>(); | CurveComponent *component = this->get_component_ptr<CurveComponent>(); | ||||
| return component.get_for_write(); | return component == nullptr ? nullptr : component->get_for_write(); | ||||
| } | } | ||||
| void GeometrySet::attribute_foreach(const Span<GeometryComponentType> component_types, | void GeometrySet::attribute_foreach(const Span<GeometryComponentType> component_types, | ||||
| const bool include_instances, | const bool include_instances, | ||||
| const AttributeForeachCallback callback) const | const AttributeForeachCallback callback) const | ||||
| { | { | ||||
| using namespace blender; | using namespace blender; | ||||
| using namespace blender::bke; | using namespace blender::bke; | ||||
| ▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines | |||||
lookup_ptr can return nullptr.