382
396
PropertyRNA *prop;
384
398
/* identifiers */
385
ot->name= "Make Proxy";
386
ot->idname= "OBJECT_OT_proxy_make";
387
ot->description= "Add empty object to become local replacement data of a library-linked object";
399
ot->name = "Make Proxy";
400
ot->idname = "OBJECT_OT_proxy_make";
401
ot->description = "Add empty object to become local replacement data of a library-linked object";
390
ot->invoke= make_proxy_invoke;
391
ot->exec= make_proxy_exec;
392
ot->poll= ED_operator_object_active;
404
ot->invoke = make_proxy_invoke;
405
ot->exec = make_proxy_exec;
406
ot->poll = ED_operator_object_active;
395
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
409
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
398
RNA_def_string(ot->srna, "object", "", 19, "Proxy Object", "Name of lib-linked/grouped object to make a proxy for.");
399
prop= RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Type", "Group object"); /* XXX, relies on hard coded ID at the moment */
412
prop= RNA_def_enum(ot->srna, "object", DummyRNA_DEFAULT_items, 0, "Proxy Object", "Name of lib-linked/grouped object to make a proxy for"); /* XXX, relies on hard coded ID at the moment */
400
413
RNA_def_enum_funcs(prop, proxy_group_object_itemf);
404
417
/********************** Clear Parent Operator ******************* */
406
static EnumPropertyItem prop_clear_parent_types[] = {
419
EnumPropertyItem prop_clear_parent_types[] = {
407
420
{0, "CLEAR", 0, "Clear Parent", ""},
408
421
{1, "CLEAR_KEEP_TRANSFORM", 0, "Clear and Keep Transformation", ""},
409
422
{2, "CLEAR_INVERSE", 0, "Clear Parent Inverse", ""},
410
423
{0, NULL, 0, NULL, NULL}
426
void ED_object_parent_clear(bContext *C, int type)
428
Main *bmain= CTX_data_main(C);
429
Scene *scene= CTX_data_scene(C);
431
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects)
433
if (ob->parent == NULL)
439
else if (type == 1) {
441
object_apply_mat4(ob, ob->obmat, TRUE, FALSE);
444
unit_m4(ob->parentinv);
446
ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
450
DAG_scene_sort(bmain, scene);
451
DAG_ids_flush_update(bmain, 0);
452
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
453
WM_event_add_notifier(C, NC_OBJECT|ND_PARENT, NULL);
413
456
/* note, poll should check for editable scene */
414
457
static int parent_clear_exec(bContext *C, wmOperator *op)
416
int type= RNA_enum_get(op->ptr, "type");
418
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
425
object_apply_mat4(ob, ob->obmat);
428
unit_m4(ob->parentinv);
430
ob->recalc |= OB_RECALC_ALL;
434
DAG_scene_sort(CTX_data_scene(C));
435
DAG_ids_flush_update(0);
436
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
459
ED_object_parent_clear(C, RNA_enum_get(op->ptr, "type"));
438
461
return OPERATOR_FINISHED;
488
516
{0, NULL, 0, NULL, NULL}
491
static int test_parent_loop(Object *par, Object *ob)
493
/* test if 'ob' is a parent somewhere in par's parents */
495
if(par == NULL) return 0;
496
if(ob == par) return 1;
498
return test_parent_loop(par->parent, ob);
501
void ED_object_parent(Object *ob, Object *par, int type, const char *substr)
503
if(!par || test_parent_loop(par, ob)) {
505
ob->partype= PAROBJECT;
510
/* this could use some more checks */
513
ob->partype &= ~PARTYPE;
515
BLI_strncpy(ob->parsubstr, substr, sizeof(ob->parsubstr));
518
static int parent_set_exec(bContext *C, wmOperator *op)
520
Scene *scene= CTX_data_scene(C);
521
Object *par= CTX_data_active_object(C);
519
int ED_object_parent_set(ReportList *reports, Main *bmain, Scene *scene, Object *ob, Object *par, int partype)
522
521
bPoseChannel *pchan= NULL;
523
int partype= RNA_enum_get(op->ptr, "type");
524
522
int pararm= ELEM4(partype, PAR_ARMATURE, PAR_ARMATURE_NAME, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO);
526
524
par->recalc |= OB_RECALC_OB;
528
526
/* preconditions */
529
if(partype==PAR_FOLLOW || partype==PAR_PATH_CONST) {
530
if(par->type!=OB_CURVE)
531
return OPERATOR_CANCELLED;
527
if (partype==PAR_FOLLOW || partype==PAR_PATH_CONST) {
528
if (par->type!=OB_CURVE)
533
531
Curve *cu= par->data;
535
if((cu->flag & CU_PATH)==0) {
533
if ((cu->flag & CU_PATH)==0) {
536
534
cu->flag |= CU_PATH|CU_FOLLOW;
537
535
makeDispListCurveTypes(scene, par, 0); /* force creation of path data */
539
537
else cu->flag |= CU_FOLLOW;
539
/* if follow, add F-Curve for ctime (i.e. "eval_time") so that path-follow works */
540
if (partype == PAR_FOLLOW) {
541
/* get or create F-Curve */
542
bAction *act = verify_adt_action(&cu->id, 1);
543
FCurve *fcu = verify_fcurve(act, NULL, "eval_time", 0, 1);
545
/* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
546
if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first)
547
add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_GENERATOR);
541
550
/* fall back on regular parenting now (for follow only) */
542
if(partype == PAR_FOLLOW)
551
if (partype == PAR_FOLLOW)
543
552
partype= PAR_OBJECT;
546
else if(partype==PAR_BONE) {
555
else if (partype==PAR_BONE) {
547
556
pchan= get_active_posechannel(par);
550
BKE_report(op->reports, RPT_ERROR, "No active Bone");
551
return OPERATOR_CANCELLED;
559
BKE_report(reports, RPT_ERROR, "No active Bone");
555
/* context itterator */
556
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
560
if( test_parent_loop(par, ob) ) {
561
BKE_report(op->reports, RPT_ERROR, "Loop in parents");
565
if (BKE_object_parent_loop_check(par, ob)) {
566
BKE_report(reports, RPT_ERROR, "Loop in parents");
572
/* apply transformation of previous parenting */
573
/* object_apply_mat4(ob, ob->obmat); */ /* removed because of bug [#23577] */
575
/* set the parent (except for follow-path constraint option) */
576
if (partype != PAR_PATH_CONST) {
582
BLI_strncpy(ob->parsubstr, pchan->name, sizeof(ob->parsubstr));
586
if (partype == PAR_PATH_CONST) {
587
/* don't do anything here, since this is not technically "parenting" */
589
else if (ELEM(partype, PAR_CURVE, PAR_LATTICE) || (pararm)) {
590
/* partype is now set to PAROBJECT so that invisible 'virtual' modifiers don't need to be created
591
* NOTE: the old (2.4x) method was to set ob->partype = PARSKEL, creating the virtual modifiers
593
ob->partype= PAROBJECT; /* note, dna define, not operator property */
594
//ob->partype= PARSKEL; /* note, dna define, not operator property */
596
/* BUT, to keep the deforms, we need a modifier, and then we need to set the object that it uses */
597
// XXX currently this should only happen for meshes, curves, surfaces, and lattices - this stuff isn't available for metas yet
598
if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
602
case PAR_CURVE: /* curve deform */
603
md= ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Curve);
604
((CurveModifierData *)md)->object= par;
606
case PAR_LATTICE: /* lattice deform */
607
md= ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Lattice);
608
((LatticeModifierData *)md)->object= par;
610
default: /* armature deform */
611
md= ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Armature);
612
((ArmatureModifierData *)md)->object= par;
617
else if (partype == PAR_BONE)
618
ob->partype= PARBONE; /* note, dna define, not operator property */
620
ob->partype= PAROBJECT; /* note, dna define, not operator property */
623
if (partype == PAR_PATH_CONST) {
625
bFollowPathConstraint *data;
626
float cmat[4][4], vec[3];
628
con = add_ob_constraint(ob, "AutoPath", CONSTRAINT_TYPE_FOLLOWPATH);
633
get_constraint_target_matrix(scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra);
634
sub_v3_v3v3(vec, ob->obmat[3], cmat[3]);
640
else if (pararm && ob->type==OB_MESH && par->type == OB_ARMATURE) {
641
if (partype == PAR_ARMATURE_NAME)
642
create_vgroups_from_armature(reports, scene, ob, par, ARM_GROUPS_NAME, 0);
643
else if (partype == PAR_ARMATURE_ENVELOPE)
644
create_vgroups_from_armature(reports, scene, ob, par, ARM_GROUPS_ENVELOPE, 0);
645
else if (partype == PAR_ARMATURE_AUTO) {
647
create_vgroups_from_armature(reports, scene, ob, par, ARM_GROUPS_AUTO, 0);
650
/* get corrected inverse */
651
ob->partype= PAROBJECT;
652
what_does_parent(scene, ob, &workob);
654
invert_m4_m4(ob->parentinv, workob.obmat);
566
/* apply transformation of previous parenting */
567
object_apply_mat4(ob, ob->obmat);
569
/* set the parent (except for follow-path constraint option) */
570
if(partype != PAR_PATH_CONST)
575
strcpy(ob->parsubstr, pchan->name);
579
if(partype == PAR_PATH_CONST)
580
; /* don't do anything here, since this is not technically "parenting" */
581
else if( ELEM(partype, PAR_CURVE, PAR_LATTICE) || pararm )
583
/* partype is now set to PAROBJECT so that invisible 'virtual' modifiers don't need to be created
584
* NOTE: the old (2.4x) method was to set ob->partype = PARSKEL, creating the virtual modifiers
586
ob->partype= PAROBJECT; /* note, dna define, not operator property */
587
//ob->partype= PARSKEL; /* note, dna define, not operator property */
589
/* BUT, to keep the deforms, we need a modifier, and then we need to set the object that it uses */
590
// XXX currently this should only happen for meshes, curves, surfaces, and lattices - this stuff isn't available for metas yet
591
if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE))
596
case PAR_CURVE: /* curve deform */
597
md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Curve);
598
((CurveModifierData *)md)->object= par;
600
case PAR_LATTICE: /* lattice deform */
601
md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Lattice);
602
((LatticeModifierData *)md)->object= par;
604
default: /* armature deform */
605
md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Armature);
606
((ArmatureModifierData *)md)->object= par;
611
else if (partype == PAR_BONE)
612
ob->partype= PARBONE; /* note, dna define, not operator property */
614
ob->partype= PAROBJECT; /* note, dna define, not operator property */
617
if(partype == PAR_PATH_CONST) {
619
bFollowPathConstraint *data;
620
float cmat[4][4], vec[3];
622
con = add_ob_constraint(ob, "AutoPath", CONSTRAINT_TYPE_FOLLOWPATH);
627
get_constraint_target_matrix(scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra - give_timeoffset(ob));
628
sub_v3_v3v3(vec, ob->obmat[3], cmat[3]);
634
else if(pararm && ob->type==OB_MESH && par->type == OB_ARMATURE) {
635
if(partype == PAR_ARMATURE_NAME)
636
create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_NAME, 0);
637
else if(partype == PAR_ARMATURE_ENVELOPE)
638
create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_ENVELOPE, 0);
639
else if(partype == PAR_ARMATURE_AUTO)
640
create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_AUTO, 0);
642
/* get corrected inverse */
643
ob->partype= PAROBJECT;
644
what_does_parent(scene, ob, &workob);
646
invert_m4_m4(ob->parentinv, workob.obmat);
649
/* calculate inverse parent matrix */
650
what_does_parent(scene, ob, &workob);
651
invert_m4_m4(ob->parentinv, workob.obmat);
654
ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
657
/* calculate inverse parent matrix */
658
what_does_parent(scene, ob, &workob);
659
invert_m4_m4(ob->parentinv, workob.obmat);
662
ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
669
static int parent_set_exec(bContext *C, wmOperator *op)
671
Main *bmain= CTX_data_main(C);
672
Scene *scene= CTX_data_scene(C);
673
Object *par= ED_object_active_context(C);
674
int partype= RNA_enum_get(op->ptr, "type");
677
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects)
679
if (!ED_object_parent_set(op->reports, bmain, scene, ob, par, partype)) {
660
DAG_scene_sort(scene);
661
DAG_ids_flush_update(0);
687
return OPERATOR_CANCELLED;
689
DAG_scene_sort(bmain, scene);
690
DAG_ids_flush_update(bmain, 0);
662
691
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
692
WM_event_add_notifier(C, NC_OBJECT|ND_PARENT, NULL);
664
694
return OPERATOR_FINISHED;
667
static int parent_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
698
static int parent_set_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event))
669
Object *ob= CTX_data_active_object(C);
670
uiPopupMenu *pup= uiPupMenuBegin(C, "Set Parent To", 0);
700
Object *ob= ED_object_active_context(C);
701
uiPopupMenu *pup= uiPupMenuBegin(C, "Set Parent To", ICON_NONE);
671
702
uiLayout *layout= uiPupMenuLayout(pup);
673
704
uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
674
705
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_OBJECT);
676
707
/* ob becomes parent, make the associated menus */
677
if(ob->type==OB_ARMATURE) {
708
if (ob->type==OB_ARMATURE) {
678
709
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_ARMATURE);
679
710
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_ARMATURE_NAME);
680
711
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_ARMATURE_ENVELOPE);
681
712
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_ARMATURE_AUTO);
682
713
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_BONE);
684
else if(ob->type==OB_CURVE) {
715
else if (ob->type==OB_CURVE) {
685
716
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_CURVE);
686
717
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_FOLLOW);
687
718
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_PATH_CONST);
689
else if(ob->type == OB_LATTICE) {
720
else if (ob->type == OB_LATTICE) {
690
721
uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_LATTICE);
1861
1865
{0, NULL, 0, NULL, NULL}};
1863
1867
/* identifiers */
1864
ot->name= "Make Single User";
1868
ot->name = "Make Single User";
1865
1869
ot->description = "Make linked data local to each object";
1866
ot->idname= "OBJECT_OT_make_single_user";
1870
ot->idname = "OBJECT_OT_make_single_user";
1868
1872
/* api callbacks */
1869
ot->invoke= WM_menu_invoke;
1870
ot->exec= make_single_user_exec;
1871
ot->poll= ED_operator_scene_editable;
1873
ot->invoke = WM_menu_invoke;
1874
ot->exec = make_single_user_exec;
1875
ot->poll = ED_operator_objectmode;
1874
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1878
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1876
1880
/* properties */
1877
ot->prop= RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
1881
ot->prop = RNA_def_enum(ot->srna, "type", type_items, SELECT, "Type", "");
1879
1883
RNA_def_boolean(ot->srna, "object", 0, "Object", "Make single user objects");
1880
1884
RNA_def_boolean(ot->srna, "obdata", 0, "Object Data", "Make single user object data");
1881
1885
RNA_def_boolean(ot->srna, "material", 0, "Materials", "Make materials local to each datablock");
1882
1886
RNA_def_boolean(ot->srna, "texture", 0, "Textures", "Make textures local to each material");
1883
RNA_def_boolean(ot->srna, "animation", 0, "Animation Data", "Make animation data local to each object");
1887
RNA_def_boolean(ot->srna, "animation", 0, "Object Animation", "Make animation data local to each object");
1886
1890
static int drop_named_material_invoke(bContext *C, wmOperator *op, wmEvent *event)
1892
Main *bmain= CTX_data_main(C);
1888
1893
Base *base= ED_view3d_give_base_under_cursor(C, event->mval);
1895
char name[MAX_ID_NAME-2];
1892
1897
RNA_string_get(op->ptr, "name", name);
1893
1898
ma= (Material *)find_id("MA", name);
1894
if(base==NULL || ma==NULL)
1899
if (base==NULL || ma==NULL)
1895
1900
return OPERATOR_CANCELLED;
1897
1902
assign_material(base->object, ma, 1);
1899
DAG_ids_flush_update(0);
1904
DAG_ids_flush_update(bmain, 0);
1900
1905
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
1902
1907
return OPERATOR_FINISHED;