forked from blender/blender
realize-depth #5
@ -253,54 +253,6 @@ static AttributeIDRef attribute_id_from_custom_data_layer(const CustomDataLayer
|
||||
return layer.name;
|
||||
}
|
||||
|
||||
static bool add_builtin_type_custom_data_layer_from_init(CustomData &custom_data,
|
||||
const eCustomDataType data_type,
|
||||
const int domain_num,
|
||||
const AttributeInit &initializer)
|
||||
{
|
||||
switch (initializer.type) {
|
||||
case AttributeInit::Type::Construct: {
|
||||
void *data = CustomData_add_layer(&custom_data, data_type, CD_CONSTRUCT, domain_num);
|
||||
return data != nullptr;
|
||||
}
|
||||
case AttributeInit::Type::DefaultValue: {
|
||||
void *data = CustomData_add_layer(&custom_data, data_type, CD_SET_DEFAULT, domain_num);
|
||||
return data != nullptr;
|
||||
}
|
||||
case AttributeInit::Type::VArray: {
|
||||
void *data = CustomData_add_layer(&custom_data, data_type, CD_CONSTRUCT, domain_num);
|
||||
if (data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
const GVArray &varray = static_cast<const AttributeInitVArray &>(initializer).varray;
|
||||
varray.materialize_to_uninitialized(varray.index_range(), data);
|
||||
return true;
|
||||
}
|
||||
case AttributeInit::Type::MoveArray: {
|
||||
void *src_data = static_cast<const AttributeInitMoveArray &>(initializer).data;
|
||||
const void *stored_data = CustomData_add_layer_with_data(
|
||||
&custom_data, data_type, src_data, domain_num, nullptr);
|
||||
if (stored_data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (stored_data != src_data) {
|
||||
MEM_freeN(src_data);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case AttributeInit::Type::Shared: {
|
||||
const AttributeInitShared &init = static_cast<const AttributeInitShared &>(initializer);
|
||||
const void *stored_data = CustomData_add_layer_with_data(
|
||||
&custom_data, data_type, const_cast<void *>(init.data), domain_num, init.sharing_info);
|
||||
return stored_data != nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
BLI_assert_unreachable();
|
||||
return false;
|
||||
}
|
||||
|
||||
static void *add_generic_custom_data_layer(CustomData &custom_data,
|
||||
const eCustomDataType data_type,
|
||||
const eCDAllocType alloctype,
|
||||
@ -393,10 +345,7 @@ static bool custom_data_layer_matches_attribute_id(const CustomDataLayer &layer,
|
||||
|
||||
bool BuiltinCustomDataLayerProvider::layer_exists(const CustomData &custom_data) const
|
||||
{
|
||||
if (stored_as_named_attribute_) {
|
||||
return CustomData_get_named_layer_index(&custom_data, stored_type_, name_) != -1;
|
||||
}
|
||||
return CustomData_has_layer(&custom_data, stored_type_);
|
||||
return CustomData_get_named_layer_index(&custom_data, data_type_, name_) != -1;
|
||||
}
|
||||
|
||||
GAttributeReader BuiltinCustomDataLayerProvider::try_get_for_read(const void *owner) const
|
||||
@ -416,13 +365,7 @@ GAttributeReader BuiltinCustomDataLayerProvider::try_get_for_read(const void *ow
|
||||
return {};
|
||||
}
|
||||
|
||||
int index;
|
||||
if (stored_as_named_attribute_) {
|
||||
index = CustomData_get_named_layer_index(custom_data, stored_type_, name_);
|
||||
}
|
||||
else {
|
||||
index = CustomData_get_layer_index(custom_data, stored_type_);
|
||||
}
|
||||
const int index = CustomData_get_named_layer_index(custom_data, data_type_, name_);
|
||||
if (index == -1) {
|
||||
return {};
|
||||
}
|
||||
@ -452,13 +395,7 @@ GAttributeWriter BuiltinCustomDataLayerProvider::try_get_for_write(void *owner)
|
||||
return {};
|
||||
}
|
||||
|
||||
void *data = nullptr;
|
||||
if (stored_as_named_attribute_) {
|
||||
data = CustomData_get_layer_named_for_write(custom_data, stored_type_, name_, element_num);
|
||||
}
|
||||
else {
|
||||
data = CustomData_get_layer_for_write(custom_data, stored_type_, element_num);
|
||||
}
|
||||
void *data = CustomData_get_layer_named_for_write(custom_data, data_type_, name_, element_num);
|
||||
if (data == nullptr) {
|
||||
return {};
|
||||
}
|
||||
@ -475,27 +412,13 @@ bool BuiltinCustomDataLayerProvider::try_delete(void *owner) const
|
||||
return {};
|
||||
}
|
||||
|
||||
auto update = [&]() {
|
||||
const int element_num = custom_data_access_.get_element_num(owner);
|
||||
if (CustomData_free_layer_named(custom_data, name_, element_num)) {
|
||||
if (update_on_change_ != nullptr) {
|
||||
update_on_change_(owner);
|
||||
}
|
||||
};
|
||||
|
||||
const int element_num = custom_data_access_.get_element_num(owner);
|
||||
if (stored_as_named_attribute_) {
|
||||
if (CustomData_free_layer_named(custom_data, name_, element_num)) {
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const int layer_index = CustomData_get_layer_index(custom_data, stored_type_);
|
||||
if (CustomData_free_layer(custom_data, stored_type_, element_num, layer_index)) {
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -510,35 +433,17 @@ bool BuiltinCustomDataLayerProvider::try_create(void *owner,
|
||||
return false;
|
||||
}
|
||||
|
||||
auto update = [&]() {
|
||||
if (update_on_change_ != nullptr) {
|
||||
update_on_change_(owner);
|
||||
}
|
||||
};
|
||||
|
||||
const int element_num = custom_data_access_.get_element_num(owner);
|
||||
if (stored_as_named_attribute_) {
|
||||
if (CustomData_has_layer_named(custom_data, data_type_, name_)) {
|
||||
/* Exists already. */
|
||||
return false;
|
||||
}
|
||||
if (add_custom_data_layer_from_attribute_init(
|
||||
name_, *custom_data, stored_type_, element_num, initializer))
|
||||
name_, *custom_data, data_type_, element_num, initializer))
|
||||
{
|
||||
update();
|
||||
return true;
|
||||
if (update_on_change_ != nullptr) {
|
||||
update_on_change_(owner);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CustomData_get_layer(custom_data, stored_type_) != nullptr) {
|
||||
/* Exists already. */
|
||||
return false;
|
||||
}
|
||||
if (add_builtin_type_custom_data_layer_from_init(
|
||||
*custom_data, stored_type_, element_num, initializer))
|
||||
{
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -550,10 +455,7 @@ bool BuiltinCustomDataLayerProvider::exists(const void *owner) const
|
||||
if (custom_data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (stored_as_named_attribute_) {
|
||||
return CustomData_has_layer_named(custom_data, stored_type_, name_);
|
||||
}
|
||||
return CustomData_get_layer(custom_data, stored_type_) != nullptr;
|
||||
return CustomData_has_layer_named(custom_data, data_type_, name_);
|
||||
}
|
||||
|
||||
GAttributeReader CustomDataAttributeProvider::try_get_for_read(
|
||||
|
@ -174,27 +174,22 @@ class CustomDataAttributeProvider final : public DynamicAttributesProvider {
|
||||
*/
|
||||
class BuiltinCustomDataLayerProvider final : public BuiltinAttributeProvider {
|
||||
using UpdateOnChange = void (*)(void *owner);
|
||||
const eCustomDataType stored_type_;
|
||||
const CustomDataAccessInfo custom_data_access_;
|
||||
const UpdateOnChange update_on_change_;
|
||||
bool stored_as_named_attribute_;
|
||||
|
||||
public:
|
||||
BuiltinCustomDataLayerProvider(std::string attribute_name,
|
||||
const AttrDomain domain,
|
||||
const eCustomDataType attribute_type,
|
||||
const eCustomDataType stored_type,
|
||||
const eCustomDataType data_type,
|
||||
const CreatableEnum creatable,
|
||||
const DeletableEnum deletable,
|
||||
const CustomDataAccessInfo custom_data_access,
|
||||
const UpdateOnChange update_on_write,
|
||||
const UpdateOnChange update_on_change,
|
||||
const AttributeValidator validator = {})
|
||||
: BuiltinAttributeProvider(
|
||||
std::move(attribute_name), domain, attribute_type, creatable, deletable, validator),
|
||||
stored_type_(stored_type),
|
||||
std::move(attribute_name), domain, data_type, creatable, deletable, validator),
|
||||
custom_data_access_(custom_data_access),
|
||||
update_on_change_(update_on_write),
|
||||
stored_as_named_attribute_(data_type_ == stored_type_)
|
||||
update_on_change_(update_on_change)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -476,7 +476,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider position("position",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT3,
|
||||
CD_PROP_FLOAT3,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::NonDeletable,
|
||||
point_access,
|
||||
@ -485,7 +484,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider radius("radius",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT,
|
||||
CD_PROP_FLOAT,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -494,7 +492,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider id("id",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_INT32,
|
||||
CD_PROP_INT32,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -503,7 +500,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider tilt("tilt",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT,
|
||||
CD_PROP_FLOAT,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -512,7 +508,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider handle_right("handle_right",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT3,
|
||||
CD_PROP_FLOAT3,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -521,7 +516,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider handle_left("handle_left",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT3,
|
||||
CD_PROP_FLOAT3,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -536,7 +530,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider handle_type_right("handle_type_right",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_INT8,
|
||||
CD_PROP_INT8,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -546,7 +539,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider handle_type_left("handle_type_left",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_INT8,
|
||||
CD_PROP_INT8,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -556,7 +548,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider nurbs_weight("nurbs_weight",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT,
|
||||
CD_PROP_FLOAT,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -569,7 +560,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider nurbs_order("nurbs_order",
|
||||
AttrDomain::Curve,
|
||||
CD_PROP_INT8,
|
||||
CD_PROP_INT8,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
curve_access,
|
||||
@ -585,7 +575,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider normal_mode("normal_mode",
|
||||
AttrDomain::Curve,
|
||||
CD_PROP_INT8,
|
||||
CD_PROP_INT8,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
curve_access,
|
||||
@ -595,7 +584,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider custom_normal("custom_normal",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT3,
|
||||
CD_PROP_FLOAT3,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -610,7 +598,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider nurbs_knots_mode("knots_mode",
|
||||
AttrDomain::Curve,
|
||||
CD_PROP_INT8,
|
||||
CD_PROP_INT8,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
curve_access,
|
||||
@ -626,7 +613,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider curve_type("curve_type",
|
||||
AttrDomain::Curve,
|
||||
CD_PROP_INT8,
|
||||
CD_PROP_INT8,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
curve_access,
|
||||
@ -640,7 +626,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider resolution("resolution",
|
||||
AttrDomain::Curve,
|
||||
CD_PROP_INT32,
|
||||
CD_PROP_INT32,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
curve_access,
|
||||
@ -650,7 +635,6 @@ static ComponentAttributeProviders create_attribute_providers_for_curve()
|
||||
static BuiltinCustomDataLayerProvider cyclic("cyclic",
|
||||
AttrDomain::Curve,
|
||||
CD_PROP_BOOL,
|
||||
CD_PROP_BOOL,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
curve_access,
|
||||
|
@ -133,7 +133,6 @@ static ComponentAttributeProviders create_attribute_providers_for_instances()
|
||||
static BuiltinCustomDataLayerProvider id("id",
|
||||
AttrDomain::Instance,
|
||||
CD_PROP_INT32,
|
||||
CD_PROP_INT32,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
instance_custom_data_access,
|
||||
@ -142,7 +141,6 @@ static ComponentAttributeProviders create_attribute_providers_for_instances()
|
||||
static BuiltinCustomDataLayerProvider instance_transform("instance_transform",
|
||||
AttrDomain::Instance,
|
||||
CD_PROP_FLOAT4X4,
|
||||
CD_PROP_FLOAT4X4,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::NonDeletable,
|
||||
instance_custom_data_access,
|
||||
@ -152,7 +150,6 @@ static ComponentAttributeProviders create_attribute_providers_for_instances()
|
||||
static BuiltinCustomDataLayerProvider reference_index(".reference_index",
|
||||
AttrDomain::Instance,
|
||||
CD_PROP_INT32,
|
||||
CD_PROP_INT32,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::NonDeletable,
|
||||
instance_custom_data_access,
|
||||
|
@ -1010,7 +1010,6 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
|
||||
static BuiltinCustomDataLayerProvider position("position",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT3,
|
||||
CD_PROP_FLOAT3,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::NonDeletable,
|
||||
point_access,
|
||||
@ -1019,7 +1018,6 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
|
||||
static BuiltinCustomDataLayerProvider id("id",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_INT32,
|
||||
CD_PROP_INT32,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -1035,7 +1033,6 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
|
||||
static BuiltinCustomDataLayerProvider material_index("material_index",
|
||||
AttrDomain::Face,
|
||||
CD_PROP_INT32,
|
||||
CD_PROP_INT32,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
face_access,
|
||||
@ -1049,7 +1046,6 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
|
||||
static BuiltinCustomDataLayerProvider edge_verts(".edge_verts",
|
||||
AttrDomain::Edge,
|
||||
CD_PROP_INT32_2D,
|
||||
CD_PROP_INT32_2D,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::NonDeletable,
|
||||
edge_access,
|
||||
@ -1065,7 +1061,6 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
|
||||
static BuiltinCustomDataLayerProvider corner_vert(".corner_vert",
|
||||
AttrDomain::Corner,
|
||||
CD_PROP_INT32,
|
||||
CD_PROP_INT32,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::NonDeletable,
|
||||
corner_access,
|
||||
@ -1074,7 +1069,6 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
|
||||
static BuiltinCustomDataLayerProvider corner_edge(".corner_edge",
|
||||
AttrDomain::Corner,
|
||||
CD_PROP_INT32,
|
||||
CD_PROP_INT32,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::NonDeletable,
|
||||
corner_access,
|
||||
@ -1084,7 +1078,6 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
|
||||
static BuiltinCustomDataLayerProvider sharp_face("sharp_face",
|
||||
AttrDomain::Face,
|
||||
CD_PROP_BOOL,
|
||||
CD_PROP_BOOL,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
face_access,
|
||||
@ -1093,7 +1086,6 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
|
||||
static BuiltinCustomDataLayerProvider sharp_edge("sharp_edge",
|
||||
AttrDomain::Edge,
|
||||
CD_PROP_BOOL,
|
||||
CD_PROP_BOOL,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
edge_access,
|
||||
|
@ -147,7 +147,6 @@ static ComponentAttributeProviders create_attribute_providers_for_point_cloud()
|
||||
static BuiltinCustomDataLayerProvider position("position",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT3,
|
||||
CD_PROP_FLOAT3,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::NonDeletable,
|
||||
point_access,
|
||||
@ -155,7 +154,6 @@ static ComponentAttributeProviders create_attribute_providers_for_point_cloud()
|
||||
static BuiltinCustomDataLayerProvider radius("radius",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_FLOAT,
|
||||
CD_PROP_FLOAT,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
@ -163,7 +161,6 @@ static ComponentAttributeProviders create_attribute_providers_for_point_cloud()
|
||||
static BuiltinCustomDataLayerProvider id("id",
|
||||
AttrDomain::Point,
|
||||
CD_PROP_INT32,
|
||||
CD_PROP_INT32,
|
||||
BuiltinAttributeProvider::Creatable,
|
||||
BuiltinAttributeProvider::Deletable,
|
||||
point_access,
|
||||
|
Loading…
Reference in New Issue
Block a user