Fix [#37085] Hook modifier work when created with Ctrl+H, but not when created via modifier panel
"transform matrix" of the hook was not inited (reset) when assinging and object to it, now use same code for both OBJECT_OT_hook_reset operator and RNA object assignement. Reviewed by Brecht, thanks.
This commit is contained in:
@@ -51,6 +51,7 @@ struct Main;
|
||||
struct Mesh;
|
||||
struct MetaElem;
|
||||
struct ModifierData;
|
||||
struct HookModifierData;
|
||||
struct Nurb;
|
||||
struct Object;
|
||||
struct ReportList;
|
||||
@@ -218,6 +219,9 @@ struct EnumPropertyItem *ED_object_vgroup_selection_itemf_helper(
|
||||
int *free,
|
||||
const unsigned int selection_mask);
|
||||
|
||||
/* object_hook.c */
|
||||
void ED_object_hook_reset_do(struct Object *ob, struct HookModifierData *hmd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
#include "ED_curve.h"
|
||||
#include "ED_mesh.h"
|
||||
#include "ED_screen.h"
|
||||
#include "ED_object.h"
|
||||
|
||||
#include "WM_types.h"
|
||||
#include "WM_api.h"
|
||||
@@ -689,19 +690,8 @@ void OBJECT_OT_hook_remove(wmOperatorType *ot)
|
||||
ot->prop = prop;
|
||||
}
|
||||
|
||||
static int object_hook_reset_exec(bContext *C, wmOperator *op)
|
||||
void ED_object_hook_reset_do(Object *ob, HookModifierData *hmd)
|
||||
{
|
||||
PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier);
|
||||
int num = RNA_enum_get(op->ptr, "modifier");
|
||||
Object *ob = NULL;
|
||||
HookModifierData *hmd = NULL;
|
||||
|
||||
object_hook_from_context(C, &ptr, num, &ob, &hmd);
|
||||
if (hmd == NULL) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* reset functionality */
|
||||
if (hmd->object) {
|
||||
bPoseChannel *pchan = BKE_pose_channel_find_name(hmd->object->pose, hmd->subtarget);
|
||||
@@ -720,7 +710,23 @@ static int object_hook_reset_exec(bContext *C, wmOperator *op)
|
||||
mul_m4_m4m4(hmd->parentinv, hmd->object->imat, ob->obmat);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int object_hook_reset_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier);
|
||||
int num = RNA_enum_get(op->ptr, "modifier");
|
||||
Object *ob = NULL;
|
||||
HookModifierData *hmd = NULL;
|
||||
|
||||
object_hook_from_context(C, &ptr, num, &ob, &hmd);
|
||||
if (hmd == NULL) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
ED_object_hook_reset_do(ob, hmd);
|
||||
|
||||
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
|
||||
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
|
||||
|
||||
|
||||
@@ -120,6 +120,8 @@ EnumPropertyItem modifier_type_items[] = {
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_particle.h"
|
||||
|
||||
#include "ED_object.h"
|
||||
|
||||
static void rna_UVProject_projectors_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
|
||||
{
|
||||
UVProjectModifierData *uvp = (UVProjectModifierData *)ptr->data;
|
||||
@@ -536,6 +538,14 @@ static int rna_MultiresModifier_filepath_length(PointerRNA *ptr)
|
||||
return strlen((external) ? external->filename : "");
|
||||
}
|
||||
|
||||
static void rna_HookModifier_object_set(PointerRNA *ptr, PointerRNA value)
|
||||
{
|
||||
HookModifierData *hmd = ptr->data;
|
||||
|
||||
hmd->object = (Object *)value.data;
|
||||
ED_object_hook_reset_do((Object *)ptr->id.data, hmd);
|
||||
}
|
||||
|
||||
static void modifier_object_set(Object *self, Object **ob_p, int type, PointerRNA value)
|
||||
{
|
||||
Object *ob = value.data;
|
||||
@@ -1434,6 +1444,7 @@ static void rna_def_modifier_hook(BlenderRNA *brna)
|
||||
prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_ui_text(prop, "Object", "Parent Object for hook, also recalculates and clears offset");
|
||||
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
|
||||
RNA_def_property_pointer_funcs(prop, NULL, "rna_HookModifier_object_set", NULL, NULL);
|
||||
RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
|
||||
|
||||
prop = RNA_def_property(srna, "subtarget", PROP_STRING, PROP_NONE);
|
||||
|
||||
Reference in New Issue
Block a user