57 #define DEFAULT_RATIO 0.10f
58 #define DEFAULT_DECAY 0.8f
123 if (
data->heat &&
data->armob->pose &&
134 for (
a = 0;
a < segments;
a++) {
196 if (
data->heat &&
data->armob->pose &&
217 for (
a = 0;
a < segments;
a++) {
229 static float get_weight(
float dist,
float decay_rad,
float dif_rad)
232 if (dist < decay_rad) {
236 weight =
interpf(0.0f, 0.9f, (dist - decay_rad) / dif_rad);
247 Bone **bonelist, *bone;
254 float(*root)[3], (*tip)[3], (*verts)[3];
258 int numbones, i, j, segments = 0;
265 looper_data.armob = ob_arm;
266 looper_data.heat =
true;
267 looper_data.list =
NULL;
279 looper_data.list = bonelist;
287 looper_data.list = dgrouplist;
292 root =
MEM_callocN(
sizeof(
float[3]) * numbones,
"root");
293 tip =
MEM_callocN(
sizeof(
float[3]) * numbones,
"tip");
294 selected =
MEM_callocN(
sizeof(
int) * numbones,
"selected");
295 radsqr =
MEM_callocN(
sizeof(
float) * numbones,
"radsqr");
297 for (j = 0; j < numbones; j++) {
319 if ((segments + 1) < bone->
segments) {
342 bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
346 if ((gpf == gpl->actframe) || ((gpf->flag &
GP_FRAME_SELECT) && (is_multiedit))) {
364 for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
370 for (j = 0; j < numbones; j++) {
376 float decay_rad = radsqr[j] - (radsqr[j] * decay);
377 float dif_rad = radsqr[j] - decay_rad;
379 for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
382 if (dist > radsqr[j]) {
386 if (dist < radsqr[j]) {
387 weight =
get_weight(dist, decay_rad, dif_rad);
391 if (dist < radsqr[j]) {
392 weight =
get_weight(dist, decay_rad, dif_rad);
398 weight =
get_weight(dist, decay_rad, dif_rad);
492 if (ob_arm != mmd->
object) {
495 "The existing Armature modifier is already using a different Armature object");
590 if (ob_arm ==
NULL) {
621 item_tmp.name =
"Default";
627 Object *ob = base->object;
629 item_tmp.identifier = item_tmp.
name = ob->
id.
name + 2;
653 ot->
name =
"Generate Automatic Weights";
654 ot->
idname =
"GPENCIL_OT_generate_weights";
655 ot->
description =
"Generate automatic weights for armatures (requires armature modifier)";
675 "Ratio between bone length and influence radius",
685 "Factor to reduce influence depending of distance to bone axis",
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_find_name(const struct bPose *pose, const char *name)
void BKE_pchan_bbone_spline_setup(struct bPoseChannel *pchan, bool rest, bool for_deform, Mat4 *result_array)
struct Scene * CTX_data_scene(const bContext *C)
struct ViewLayer * CTX_data_view_layer(const bContext *C)
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
struct Object * CTX_data_active_object(const bContext *C)
struct Main * CTX_data_main(const bContext *C)
void BKE_gpencil_dvert_ensure(struct bGPDstroke *gps)
struct GpencilModifierData * BKE_gpencil_modifiers_findby_type(struct Object *ob, GpencilModifierType type)
void BKE_report(ReportList *reports, eReportType type, const char *message)
#define LISTBASE_FOREACH(type, var, list)
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float interpf(float a, float b, float t)
float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3])
void mul_m4_v3(const float M[4][4], float r[3])
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_v3(float r[3], const float a[3])
struct Depsgraph Depsgraph
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
@ eGpencilModifierType_Armature
#define GPENCIL_MULTIEDIT_SESSIONS_ON(gpd)
void ED_vgroup_data_clamp_range(struct ID *id, int total)
struct GpencilModifierData * ED_object_gpencil_modifier_add(struct ReportList *reports, struct Main *bmain, struct Scene *scene, struct Object *ob, const char *name, int type)
Read Guarded memory(de)allocation.
const Depsgraph * depsgraph
static void gpencil_object_vgroup_calc_from_armature(const bContext *C, Object *ob, Object *ob_arm, const int mode, const float ratio, const float decay)
static int gpencil_bone_looper(Object *ob, Bone *bone, void *data, int(*bone_func)(Object *, Bone *, void *))
static int gpencil_generate_weights_exec(bContext *C, wmOperator *op)
static float get_weight(float dist, float decay_rad, float dif_rad)
static void gpencil_add_verts_to_dgroups(const bContext *C, Object *ob, Object *ob_arm, const float ratio, const float decay)
static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
bool ED_gpencil_add_armature_weights(const bContext *C, ReportList *reports, Object *ob, Object *ob_arm, int mode)
void GPENCIL_OT_generate_weights(wmOperatorType *ot)
static const EnumPropertyItem * gpencil_armatures_enum_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
bool ED_gpencil_add_armature(const bContext *C, ReportList *reports, Object *ob, Object *ob_arm)
static bool gpencil_generate_weights_poll(bContext *C)
static int vgroup_add_unique_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr))
static int gpencil_bone_skinnable_cb(Object *UNUSED(ob), Bone *bone, void *datap)
bool ED_gpencil_stroke_can_use(const bContext *C, const bGPDstroke *gps)
void *(* MEM_callocN)(size_t len, const char *str)
float RNA_float_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
const EnumPropertyItem DummyRNA_DEFAULT_items[]
ListBase vertex_group_names
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
void WM_event_add_notifier(const bContext *C, uint type, void *reference)