~ubuntu-branches/ubuntu/utopic/blender/utopic-proposed

« back to all changes in this revision

Viewing changes to source/blender/editors/object/object_relations.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
#include "BLI_listbase.h"
56
56
#include "BLI_linklist.h"
57
57
#include "BLI_string.h"
 
58
#include "BLI_kdtree.h"
58
59
#include "BLI_utildefines.h"
59
60
 
60
61
#include "BLF_translation.h"
136
137
                BMEditMesh *em;
137
138
 
138
139
                EDBM_mesh_load(obedit);
139
 
                EDBM_mesh_make(scene->toolsettings, scene, obedit);
 
140
                EDBM_mesh_make(scene->toolsettings, obedit);
140
141
 
141
142
                em = me->edit_btmesh;
142
143
 
494
495
                        
495
496
                        /* clear parenting relationship completely */
496
497
                        ob->parent = NULL;
 
498
                        break;
497
499
                }
498
 
                break;
499
 
                
500
500
                case CLEAR_PARENT_KEEP_TRANSFORM:
501
501
                {
502
502
                        /* remove parent, and apply the parented transform result as object's local transforms */
503
503
                        ob->parent = NULL;
504
504
                        BKE_object_apply_mat4(ob, ob->obmat, TRUE, FALSE);
 
505
                        break;
505
506
                }
506
 
                break;
507
 
                
508
507
                case CLEAR_PARENT_INVERSE:
509
508
                {
510
509
                        /* object stays parented, but the parent inverse (i.e. offset from parent to retain binding state) is cleared */
511
510
                        unit_m4(ob->parentinv);
 
511
                        break;
512
512
                }
513
 
                break;
514
513
        }
515
514
        
516
515
        DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
586
585
        {PAR_PATH_CONST, "PATH_CONST", 0, "Path Constraint", ""},
587
586
        {PAR_LATTICE, "LATTICE", 0, "Lattice Deform", ""},
588
587
        {PAR_VERTEX, "VERTEX", 0, "Vertex", ""},
589
 
        {PAR_TRIA, "TRIA", 0, "Triangle", ""},
 
588
        {PAR_VERTEX_TRI, "VERTEX_TRI", 0, "Vertex (Triangle)", ""},
590
589
        {0, NULL, 0, NULL, NULL}
591
590
};
592
591
 
593
592
int ED_object_parent_set(ReportList *reports, Main *bmain, Scene *scene, Object *ob, Object *par,
594
 
                         int partype, int xmirror, int keep_transform)
 
593
                         int partype, bool xmirror, bool keep_transform, const int vert_par[3])
595
594
{
596
595
        bPoseChannel *pchan = NULL;
597
596
        int pararm = ELEM4(partype, PAR_ARMATURE, PAR_ARMATURE_NAME, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO);
720
719
                                if (pchan->bone)
721
720
                                        pchan->bone->flag |= BONE_RELATIVE_PARENTING;
722
721
                        }
723
 
                        else
 
722
                        else if (partype == PAR_VERTEX) {
 
723
                                ob->partype = PARVERT1;
 
724
                                ob->par1 = vert_par[0];
 
725
                        }
 
726
                        else if (partype == PAR_VERTEX_TRI) {
 
727
                                ob->partype = PARVERT3;
 
728
                                copy_v3_v3_int(&ob->par1, vert_par);
 
729
                        }
 
730
                        else {
724
731
                                ob->partype = PAROBJECT;  /* note, dna define, not operator property */
 
732
                        }
725
733
                        
726
734
                        /* constraint */
727
735
                        if (partype == PAR_PATH_CONST) {
768
776
        return 1;
769
777
}
770
778
 
 
779
 
 
780
 
 
781
static void parent_set_vert_find(KDTree *tree, Object *child, int vert_par[3], bool is_tri)
 
782
{
 
783
        const float *co_find = child->obmat[3];
 
784
        if (is_tri) {
 
785
                KDTreeNearest nearest[3];
 
786
                int tot;
 
787
 
 
788
                tot = BLI_kdtree_find_nearest_n(tree, co_find, NULL, nearest, 3);
 
789
                BLI_assert(tot == 3);
 
790
 
 
791
                vert_par[0] = nearest[0].index;
 
792
                vert_par[1] = nearest[1].index;
 
793
                vert_par[2] = nearest[2].index;
 
794
 
 
795
                BLI_assert(min_iii(UNPACK3(vert_par)) >= 0);
 
796
        }
 
797
        else {
 
798
                vert_par[0] = BLI_kdtree_find_nearest(tree, co_find, NULL, NULL);
 
799
                BLI_assert(vert_par[0] >= 0);
 
800
                vert_par[1] = 0;
 
801
                vert_par[2] = 0;
 
802
        }
 
803
}
 
804
 
771
805
static int parent_set_exec(bContext *C, wmOperator *op)
772
806
{
773
807
        Main *bmain = CTX_data_main(C);
774
808
        Scene *scene = CTX_data_scene(C);
775
809
        Object *par = ED_object_active_context(C);
776
810
        int partype = RNA_enum_get(op->ptr, "type");
777
 
        int xmirror = RNA_boolean_get(op->ptr, "xmirror");
778
 
        int keep_transform = RNA_boolean_get(op->ptr, "keep_transform");
779
 
        int ok = 1;
780
 
 
 
811
        bool xmirror = RNA_boolean_get(op->ptr, "xmirror");
 
812
        bool keep_transform = RNA_boolean_get(op->ptr, "keep_transform");
 
813
        bool ok = true;
 
814
 
 
815
        /* vertex parent (kdtree) */
 
816
        const bool is_vert_par = ELEM(partype, PAR_VERTEX, PAR_VERTEX_TRI);
 
817
        const bool is_tri = partype == PAR_VERTEX_TRI;
 
818
        int tree_tot;
 
819
        struct KDTree *tree = NULL;
 
820
        int vert_par[3] = {0, 0, 0};
 
821
        int *vert_par_p = is_vert_par ? vert_par : NULL;
 
822
 
 
823
 
 
824
        if (is_vert_par) {
 
825
                tree = BKE_object_as_kdtree(par, &tree_tot);
 
826
                BLI_assert(tree != NULL);
 
827
 
 
828
                if (tree_tot < (is_tri ? 3 : 1)) {
 
829
                        BKE_report(op->reports, RPT_ERROR, "Not enough vertices for vertex-parent");
 
830
                        ok = false;
 
831
                        goto cleanup;
 
832
                }
 
833
        }
 
834
 
 
835
 
 
836
        /* Non vertex-parent */
781
837
        CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
782
838
        {
783
 
                if (!ED_object_parent_set(op->reports, bmain, scene, ob, par, partype, xmirror, keep_transform)) {
784
 
                        ok = 0;
 
839
                if (is_vert_par) {
 
840
                        parent_set_vert_find(tree, ob, vert_par, is_tri);
 
841
                }
 
842
 
 
843
                if (!ED_object_parent_set(op->reports, bmain, scene, ob, par, partype, xmirror, keep_transform, vert_par_p)) {
 
844
                        ok = false;
785
845
                        break;
786
846
                }
787
847
        }
788
848
        CTX_DATA_END;
789
849
 
 
850
 
 
851
cleanup:
 
852
        if (is_vert_par) {
 
853
                BLI_kdtree_free(tree);
 
854
        }
 
855
 
790
856
        if (!ok)
791
857
                return OPERATOR_CANCELLED;
792
858
 
837
903
                uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_LATTICE);
838
904
        }
839
905
        
 
906
        /* vertex parenting */
 
907
        if (OB_TYPE_SUPPORT_PARVERT(ob->type)) {
 
908
                uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_VERTEX);
 
909
                uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_VERTEX_TRI);
 
910
        }
 
911
 
840
912
        uiPupMenuEnd(C, pup);
841
913
        
842
914
        return OPERATOR_CANCELLED;
2051
2123
                        if (adt) BKE_animdata_make_local(adt);
2052
2124
                        
2053
2125
                        /* tag indirect data direct */
2054
 
                        matarar = (Material ***)give_matarar(ob);
 
2126
                        matarar = give_matarar(ob);
2055
2127
                        if (matarar) {
2056
2128
                                for (a = 0; a < ob->totcol; a++) {
2057
2129
                                        ma = (*matarar)[a];