WIP: Brush assets project #106303

Draft
Julian Eisel wants to merge 381 commits from brush-assets-project into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
10 changed files with 43 additions and 40 deletions
Showing only changes of commit 62f27e4612 - Show all commits

View File

@ -235,8 +235,8 @@ def enum_preview_denoiser(self, context):
items = [ items = [
('AUTO', ('AUTO',
"Automatic", "Automatic",
("Use the fastest available denoiser for viewport rendering " ("Use GPU accelerated denoising if supported, for the best performance. "
"(OptiX if available, OpenImageDenoise otherwise)"), "Prefer OpenImageDenoise over OptiX"),
0)] 0)]
else: else:
items = [('AUTO', "None", "Blender was compiled without a viewport denoiser", 0)] items = [('AUTO', "None", "Blender was compiled without a viewport denoiser", 0)]

View File

@ -16,6 +16,7 @@ extern "C" {
struct Collection; struct Collection;
struct Depsgraph; struct Depsgraph;
struct ListBase; struct ListBase;
struct RNG;
struct Object; struct Object;
struct ParticleData; struct ParticleData;
struct ParticleKey; struct ParticleKey;
@ -78,6 +79,9 @@ typedef struct EffectorCache {
struct PartDeflect *pd; struct PartDeflect *pd;
/** Random noise generator for e.g. wind. */
struct RNG *rng;
/* precalculated for guides */ /* precalculated for guides */
struct GuideEffectorData *guide_data; struct GuideEffectorData *guide_data;
float guide_loc[4], guide_dir[3], guide_radius; float guide_loc[4], guide_dir[3], guide_radius;

View File

@ -113,9 +113,6 @@ PartDeflect *BKE_partdeflect_copy(const PartDeflect *pd_src)
return nullptr; return nullptr;
} }
PartDeflect *pd_dst = static_cast<PartDeflect *>(MEM_dupallocN(pd_src)); PartDeflect *pd_dst = static_cast<PartDeflect *>(MEM_dupallocN(pd_src));
if (pd_dst->rng != nullptr) {
pd_dst->rng = BLI_rng_copy(pd_dst->rng);
}
return pd_dst; return pd_dst;
} }
@ -124,9 +121,6 @@ void BKE_partdeflect_free(PartDeflect *pd)
if (!pd) { if (!pd) {
return; return;
} }
if (pd->rng) {
BLI_rng_free(pd->rng);
}
MEM_freeN(pd); MEM_freeN(pd);
} }
@ -136,12 +130,8 @@ static void precalculate_effector(Depsgraph *depsgraph, EffectorCache *eff)
{ {
float ctime = DEG_get_ctime(depsgraph); float ctime = DEG_get_ctime(depsgraph);
uint cfra = uint(ctime >= 0 ? ctime : -ctime); uint cfra = uint(ctime >= 0 ? ctime : -ctime);
if (!eff->pd->rng) {
eff->pd->rng = BLI_rng_new(eff->pd->seed + cfra); eff->rng = BLI_rng_new(eff->pd->seed + cfra);
}
else {
BLI_rng_srandom(eff->pd->rng, eff->pd->seed + cfra);
}
if (eff->pd->forcefield == PFIELD_GUIDE && eff->ob->type == OB_CURVES_LEGACY) { if (eff->pd->forcefield == PFIELD_GUIDE && eff->ob->type == OB_CURVES_LEGACY) {
Curve *cu = static_cast<Curve *>(eff->ob->data); Curve *cu = static_cast<Curve *>(eff->ob->data);
@ -375,6 +365,9 @@ void BKE_effectors_free(ListBase *lb)
{ {
if (lb) { if (lb) {
LISTBASE_FOREACH (EffectorCache *, eff, lb) { LISTBASE_FOREACH (EffectorCache *, eff, lb) {
if (eff->rng) {
BLI_rng_free(eff->rng);
}
if (eff->guide_data) { if (eff->guide_data) {
MEM_freeN(eff->guide_data); MEM_freeN(eff->guide_data);
} }
@ -960,7 +953,7 @@ static void do_physical_effector(EffectorCache *eff,
float *total_force) float *total_force)
{ {
PartDeflect *pd = eff->pd; PartDeflect *pd = eff->pd;
RNG *rng = pd->rng; RNG *rng = eff->rng;
float force[3] = {0, 0, 0}; float force[3] = {0, 0, 0};
float temp[3]; float temp[3];
float fac; float fac;

View File

@ -245,9 +245,6 @@ static void object_copy_data(Main *bmain,
if (ob_src->pd) { if (ob_src->pd) {
ob_dst->pd = (PartDeflect *)MEM_dupallocN(ob_src->pd); ob_dst->pd = (PartDeflect *)MEM_dupallocN(ob_src->pd);
if (ob_dst->pd->rng) {
ob_dst->pd->rng = (RNG *)MEM_dupallocN(ob_src->pd->rng);
}
} }
BKE_rigidbody_object_copy(bmain, ob_dst, ob_src, flag_subdata); BKE_rigidbody_object_copy(bmain, ob_dst, ob_src, flag_subdata);

View File

@ -313,11 +313,8 @@ static void particle_settings_blend_write(BlendWriter *writer, ID *id, const voi
} }
} }
void BKE_particle_partdeflect_blend_read_data(BlendDataReader * /*reader*/, PartDeflect *pd) void BKE_particle_partdeflect_blend_read_data(BlendDataReader * /*reader*/, PartDeflect * /*pd*/)
{ {
if (pd) {
pd->rng = nullptr;
}
} }
static void particle_settings_blend_read_data(BlendDataReader *reader, ID *id) static void particle_settings_blend_read_data(BlendDataReader *reader, ID *id)

View File

@ -47,15 +47,9 @@ static bool active_attribute_poll(bContext *C)
if (!editable_curves_in_edit_mode_poll(C)) { if (!editable_curves_in_edit_mode_poll(C)) {
return false; return false;
} }
Object *object = CTX_data_active_object(C); const Object *object = CTX_data_active_object(C);
Curves &curves_id = *static_cast<Curves *>(object->data); const ID &object_data = *static_cast<const ID *>(object->data);
const CustomDataLayer *layer = BKE_id_attributes_active_get(&const_cast<ID &>(curves_id.id)); if (!geometry::attribute_set_poll(*C, object_data)) {
if (!layer) {
CTX_wm_operator_poll_msg_set(C, "No active attribute");
return false;
}
if (layer->type == CD_PROP_STRING) {
CTX_wm_operator_poll_msg_set(C, "Active string attribute not supported");
return false; return false;
} }
return true; return true;

View File

@ -66,6 +66,8 @@ StringRefNull rna_property_name_for_type(const eCustomDataType type)
case CD_PROP_INT8: case CD_PROP_INT8:
case CD_PROP_INT32: case CD_PROP_INT32:
return "value_int"; return "value_int";
case CD_PROP_INT32_2D:
return "value_int_vector_2d";
default: default:
BLI_assert_unreachable(); BLI_assert_unreachable();
return ""; return "";
@ -103,6 +105,8 @@ void register_rna_properties_for_attribute_types(StructRNA &srna)
-FLT_MAX, -FLT_MAX,
FLT_MAX); FLT_MAX);
RNA_def_int(&srna, "value_int", 0, INT_MIN, INT_MAX, "Value", "", INT_MIN, INT_MAX); RNA_def_int(&srna, "value_int", 0, INT_MIN, INT_MAX, "Value", "", INT_MIN, INT_MAX);
RNA_def_int_array(
&srna, "value_int_vector_2d", 2, nullptr, INT_MIN, INT_MAX, "Value", "", INT_MIN, INT_MAX);
RNA_def_float_color( RNA_def_float_color(
&srna, "value_color", 4, color_default, -FLT_MAX, FLT_MAX, "Value", "", 0.0f, 1.0f); &srna, "value_color", 4, color_default, -FLT_MAX, FLT_MAX, "Value", "", 0.0f, 1.0f);
RNA_def_boolean(&srna, "value_bool", false, "Value", ""); RNA_def_boolean(&srna, "value_bool", false, "Value", "");
@ -140,8 +144,12 @@ GPointer rna_property_for_attribute_type_retrieve_value(PointerRNA &ptr,
case CD_PROP_INT32: case CD_PROP_INT32:
*static_cast<int32_t *>(buffer) = RNA_int_get(&ptr, prop_name.c_str()); *static_cast<int32_t *>(buffer) = RNA_int_get(&ptr, prop_name.c_str());
break; break;
case CD_PROP_INT32_2D:
RNA_int_get_array(&ptr, prop_name.c_str(), static_cast<int *>(buffer));
break;
default: default:
BLI_assert_unreachable(); BLI_assert_unreachable();
return {};
} }
return GPointer(bke::custom_data_type_to_cpp_type(type), buffer); return GPointer(bke::custom_data_type_to_cpp_type(type), buffer);
} }
@ -175,11 +183,28 @@ void rna_property_for_attribute_type_set_value(PointerRNA &ptr,
case CD_PROP_INT32: case CD_PROP_INT32:
RNA_property_int_set(&ptr, &prop, *value.get<int32_t>()); RNA_property_int_set(&ptr, &prop, *value.get<int32_t>());
break; break;
case CD_PROP_INT32_2D:
RNA_property_int_set_array(&ptr, &prop, *value.get<int2>());
break;
default: default:
BLI_assert_unreachable(); BLI_assert_unreachable();
} }
} }
bool attribute_set_poll(bContext &C, const ID &object_data)
{
const CustomDataLayer *layer = BKE_id_attributes_active_get(&const_cast<ID &>(object_data));
if (!layer) {
CTX_wm_operator_poll_msg_set(&C, "No active attribute");
return false;
}
if (ELEM(layer->type, CD_PROP_STRING, CD_PROP_FLOAT4X4, CD_PROP_QUATERNION)) {
CTX_wm_operator_poll_msg_set(&C, "The active attribute has an unsupported type");
return false;
}
return true;
}
/*********************** Attribute Operators ************************/ /*********************** Attribute Operators ************************/
static bool geometry_attributes_poll(bContext *C) static bool geometry_attributes_poll(bContext *C)

View File

@ -39,6 +39,7 @@ GPointer rna_property_for_attribute_type_retrieve_value(PointerRNA &ptr,
const eCustomDataType type, const eCustomDataType type,
void *buffer); void *buffer);
void rna_property_for_attribute_type_set_value(PointerRNA &ptr, PropertyRNA &prop, GPointer value); void rna_property_for_attribute_type_set_value(PointerRNA &ptr, PropertyRNA &prop, GPointer value);
bool attribute_set_poll(bContext &C, const ID &object_data);
/** \} */ /** \} */

View File

@ -77,13 +77,7 @@ static bool mesh_active_attribute_poll(bContext *C)
return false; return false;
} }
const Mesh *mesh = ED_mesh_context(C); const Mesh *mesh = ED_mesh_context(C);
const CustomDataLayer *layer = BKE_id_attributes_active_get(&const_cast<ID &>(mesh->id)); if (!geometry::attribute_set_poll(*C, mesh->id)) {
if (!layer) {
CTX_wm_operator_poll_msg_set(C, "No active attribute");
return false;
}
if (layer->type == CD_PROP_STRING) {
CTX_wm_operator_poll_msg_set(C, "Active string attribute not supported");
return false; return false;
} }
return true; return true;

View File

@ -131,8 +131,6 @@ typedef struct PartDeflect {
struct Tex *tex; struct Tex *tex;
/* effector noise */ /* effector noise */
/** Random noise generator for e.g. wind. */
struct RNG *rng;
/** Noise of force. */ /** Noise of force. */
float f_noise; float f_noise;
/** Noise random seed. */ /** Noise random seed. */