~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Bone.c

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 * $Id: Bone.c,v 1.46 2006/07/06 18:53:36 khughes Exp $
 
2
 * $Id: Bone.c 14444 2008-04-16 22:40:48Z hos $
3
3
 *
4
 
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU General Public License
8
8
 * as published by the Free Software Foundation; either version 2
9
 
 * of the License, or (at your option) any later version. The Blender
10
 
 * Foundation also sells licenses for use in proprietary software under
11
 
 * the Blender License.  See http://www.blender.org/BL/ for information
12
 
 * about this.
 
9
 * of the License, or (at your option) any later version.
13
10
 *
14
11
 * This program is distributed in the hope that it will be useful,
15
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
22
 *
26
23
 * Contributor(s): Joseph Gilbert
27
24
 *
28
 
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 
25
 * ***** END GPL LICENSE BLOCK *****
29
26
*/
30
27
 
31
28
#include "Bone.h"
69
66
        Mat3Inv(imat, postmat);                                 
70
67
        Mat3MulMat3(difmat, imat, premat);      
71
68
 
72
 
        roll = atan(difmat[2][0] / difmat[2][2]); 
 
69
        roll = atan2(difmat[2][0], difmat[2][2]); 
73
70
        if (difmat[0][0] < 0.0){
74
71
                roll += M_PI;
75
72
        }
88
85
{
89
86
        if (self->editbone){
90
87
                if (self->editbone->parent)
91
 
                        return EXPP_incr_ret(Py_True);
 
88
                        Py_RETURN_TRUE;
92
89
                else
93
 
                        return EXPP_incr_ret(Py_False);
 
90
                        Py_RETURN_FALSE;
94
91
        }else{
95
92
                goto AttributeError;
96
93
        }
105
102
        if (self->editbone){
106
103
                if (self->editbone->parent)
107
104
                        self->editbone->parent = NULL;
108
 
                return EXPP_incr_ret(Py_None);
 
105
                Py_RETURN_NONE;
109
106
        }else{
110
107
                goto AttributeError;
111
108
        }
406
403
                                goto RuntimeError;
407
404
        }
408
405
 
409
 
        return EXPP_incr_ret(list);
 
406
        return list;
410
407
 
411
408
RuntimeError:
 
409
        Py_XDECREF( list );
412
410
        return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
413
411
                sEditBoneError, ".options: ", "Internal failure!");
414
412
}
515
513
                if (self->editbone->parent)
516
514
                        return PyEditBone_FromEditBone(self->editbone->parent);
517
515
                else
518
 
                        return EXPP_incr_ret(Py_None);
 
516
                        Py_RETURN_NONE;
519
517
        }else{
520
 
                return EXPP_incr_ret(Py_None); //not in the list yet can't have a parent
 
518
                Py_RETURN_NONE; //not in the list yet can't have a parent
521
519
        }
522
520
}
523
521
//------------------------EditBone.parent (set)
639
637
        printf("Sorry this isn't implemented yet.... :/");
640
638
        return 1;
641
639
}
 
640
 
 
641
 
 
642
//------------------------Bone.headRadius (get)
 
643
static PyObject *EditBone_getHeadRadius(BPy_EditBone *self, void *closure)
 
644
{
 
645
        if (self->editbone)
 
646
                if (self->editbone->parent && self->editbone->flag & BONE_CONNECTED)
 
647
                        return PyFloat_FromDouble(self->editbone->parent->rad_tail);
 
648
                else
 
649
                        return PyFloat_FromDouble(self->editbone->rad_head);
 
650
        else
 
651
                if (self->parent && self->flag & BONE_CONNECTED)
 
652
                        return PyFloat_FromDouble(self->parent->rad_tail);
 
653
                else
 
654
                        return PyFloat_FromDouble(self->rad_head);
 
655
}
 
656
//------------------------Bone.headRadius (set)
 
657
static int EditBone_setHeadRadius(BPy_EditBone *self, PyObject *value, void *closure)
 
658
{  
 
659
        float radius;
 
660
        if (!PyArg_Parse(value, "f", &radius))
 
661
                goto AttributeError;
 
662
        CLAMP(radius, 0.0f, 10000.0f);
 
663
 
 
664
        if (self->editbone)
 
665
                if (self->editbone->parent && self->editbone->flag & BONE_CONNECTED)
 
666
                        self->editbone->parent->rad_tail= radius;
 
667
                else
 
668
                        self->editbone->rad_head= radius;
 
669
        else
 
670
                if (self->parent && self->flag & BONE_CONNECTED)
 
671
                        self->parent->rad_tail= radius;
 
672
                else
 
673
                        self->rad_head= radius;
 
674
        return 0;
 
675
 
 
676
AttributeError:
 
677
        return EXPP_intError(PyExc_AttributeError, "%s%s%s",
 
678
                sEditBoneError, ".headRadius: ", "expects a float");
 
679
}
 
680
 
 
681
 
 
682
//------------------------Bone.tailRadius (get)
 
683
static PyObject *EditBone_getTailRadius(BPy_EditBone *self, void *closure)
 
684
{
 
685
        if (self->editbone)
 
686
                return PyFloat_FromDouble(self->editbone->rad_tail);
 
687
        else
 
688
                return PyFloat_FromDouble(self->rad_tail);
 
689
}
 
690
//------------------------Bone.tailRadius (set)
 
691
static int EditBone_setTailRadius(BPy_EditBone *self, PyObject *value, void *closure)
 
692
{  
 
693
        float radius;
 
694
        if (!PyArg_Parse(value, "f", &radius))
 
695
                goto AttributeError;
 
696
        CLAMP(radius, 0.0f, 10000.0f);
 
697
 
 
698
        if (self->editbone)
 
699
                self->editbone->rad_tail = radius;
 
700
        else
 
701
                self->rad_tail = radius;
 
702
        return 0;
 
703
 
 
704
AttributeError:
 
705
        return EXPP_intError(PyExc_AttributeError, "%s%s%s",
 
706
                sEditBoneError, ".tailRadius: ", "expects a float");
 
707
}
 
708
 
 
709
//------------------------Bone.layerMask (get)
 
710
static PyObject *EditBone_getLayerMask(BPy_EditBone *self)
 
711
{
 
712
        /* do this extra stuff because the short's bits can be negative values */
 
713
        unsigned short laymask = 0;
 
714
        if (self->editbone)     laymask |= self->editbone->layer;
 
715
        else                            laymask |= self->layer;
 
716
        return PyInt_FromLong((int)laymask);
 
717
}
 
718
//------------------------Bone.layerMask (set)
 
719
static int EditBone_setLayerMask(BPy_EditBone *self, PyObject *value)
 
720
{
 
721
        int laymask;
 
722
        if (!PyInt_Check(value)) {
 
723
                return EXPP_ReturnIntError( PyExc_AttributeError,
 
724
                                                                        "expected an integer (bitmask) as argument" );
 
725
        }
 
726
        
 
727
        laymask = PyInt_AsLong(value);
 
728
 
 
729
        if (laymask <= 0 || laymask > (1<<16) - 1)
 
730
                return EXPP_ReturnIntError( PyExc_AttributeError,
 
731
                                                                        "bitmask must have from 1 up to 16 bits set");
 
732
        
 
733
        if (self->editbone) {
 
734
                self->editbone->layer = 0;
 
735
                self->editbone->layer |= laymask;
 
736
        } else {
 
737
                self->layer = 0;
 
738
                self->layer |= laymask;
 
739
        }
 
740
        
 
741
        return 0;
 
742
}
 
743
 
642
744
//------------------TYPE_OBECT IMPLEMENTATION--------------------------
643
745
//------------------------tp_methods
644
746
//This contains a list of all methods the object contains
674
776
                "The parent bone of this bone", NULL},
675
777
        {"length", (getter)EditBone_getLength, (setter)EditBone_setLength, 
676
778
                "The length of this bone", NULL},
 
779
        {"tailRadius", (getter)EditBone_getTailRadius, (setter)EditBone_setTailRadius, 
 
780
                "Set the radius of this bones tip", NULL},
 
781
        {"headRadius", (getter)EditBone_getHeadRadius, (setter)EditBone_setHeadRadius, 
 
782
                "Set the radius of this bones head", NULL},
 
783
        {"layerMask", (getter)EditBone_getLayerMask, (setter)EditBone_setLayerMask, 
 
784
                "Layer bitmask", NULL },
677
785
        {NULL, NULL, NULL, NULL,NULL}
678
786
};
679
787
 
687
795
                return PyString_FromFormat( "[EditBone \"%s\"]", self->name ); 
688
796
}
689
797
 
 
798
static int EditBone_compare( BPy_EditBone * a, BPy_EditBone * b )
 
799
{
 
800
        /* if they are not wrapped, then they cant be the same */
 
801
        if (a->editbone==NULL && b->editbone==NULL) return -1;
 
802
        return ( a->editbone == b->editbone ) ? 0 : -1;
 
803
}
 
804
 
 
805
 
690
806
//------------------------tp_doc
691
807
//The __doc__ string for this object
692
808
static char BPy_EditBone_doc[] = "This is an internal subobject of armature\
708
824
        //otherwise this will act as a py_object
709
825
        py_editBone->editbone = NULL;
710
826
 
711
 
        unique_editbone_name(name);
 
827
        unique_editbone_name(NULL, name);
712
828
        BLI_strncpy(py_editBone->name, name, 32);
713
829
        py_editBone->parent = NULL;
714
830
        py_editBone->weight= 1.0f;
720
836
        py_editBone->rad_head= 0.10f;
721
837
        py_editBone->rad_tail= 0.05f;
722
838
        py_editBone->segments= 1;
 
839
        py_editBone->layer= 1;
723
840
        py_editBone->flag = 0;
724
841
        py_editBone->roll = 0.0f;
725
842
 
754
871
        0,                                                                                      //tp_print
755
872
        0,                                                                                      //tp_getattr
756
873
        0,                                                                                      //tp_setattr
757
 
        0,                                                                                      //tp_compare
 
874
        (cmpfunc)EditBone_compare,                                      //tp_compare
758
875
        (reprfunc)EditBone_repr,                        //tp_repr
759
876
        0,                                                                                      //tp_as_number
760
877
        0,                                                                                      //tp_as_sequence
804
921
                py_bone = PyBone_FromBone(bone);
805
922
                if (py_bone == NULL)
806
923
                        return 0;
807
 
 
 
924
                
808
925
                if(PyList_Append(list, py_bone) == -1){
809
 
                        goto RuntimeError;
 
926
                        return 0;
810
927
                }
 
928
                Py_DECREF(py_bone);
811
929
                if (bone->childbase.first) 
812
 
                        PyBone_ChildrenAsList(list, &bone->childbase);
 
930
                        if (!PyBone_ChildrenAsList(list, &bone->childbase))
 
931
                                return 0;
813
932
        }
814
933
        return 1;
815
 
 
816
 
RuntimeError:
817
 
        return EXPP_intError(PyExc_RuntimeError, "%s%s", 
818
 
                sBoneError, "Internal error trying to wrap blender bones!");
819
934
}
820
935
//-------------------------Bone.hasParent()
821
936
static PyObject *Bone_hasParent(BPy_Bone *self)
822
937
{
823
938
        if (self->bone->parent)
824
 
                return EXPP_incr_ret(Py_True);
 
939
                Py_RETURN_TRUE;
825
940
        else
826
 
                return EXPP_incr_ret(Py_False);
 
941
                Py_RETURN_FALSE;
827
942
}
828
943
//-------------------------Bone.hasChildren()
829
944
static PyObject *Bone_hasChildren(BPy_Bone *self)
830
945
{
831
946
        if (self->bone->childbase.first)
832
 
                return EXPP_incr_ret(Py_True);
 
947
                Py_RETURN_TRUE;
833
948
        else
834
 
                return EXPP_incr_ret(Py_False);
 
949
                Py_RETURN_FALSE;
835
950
}
836
951
//-------------------------Bone.getAllChildren()
837
952
static PyObject *Bone_getAllChildren(BPy_Bone *self)
838
953
{
839
 
        PyObject *list = NULL;
840
 
 
841
 
        if (self->bone->childbase.first){
842
 
                list = PyList_New(0);
843
 
                if (!PyBone_ChildrenAsList(list, &self->bone->childbase))
844
 
                        return NULL;
845
 
                return EXPP_incr_ret(list);
846
 
        }else{
847
 
                return EXPP_incr_ret(Py_None);
 
954
        PyObject *list = PyList_New(0);
 
955
        if (!self->bone->childbase.first) {
 
956
                /* do nothing */
 
957
        } else if (!PyBone_ChildrenAsList(list, &self->bone->childbase)) {
 
958
                Py_XDECREF(list);
 
959
                EXPP_objError(PyExc_RuntimeError, "%s%s", 
 
960
                                sBoneError, "Internal error trying to wrap blender bones!");
848
961
        }
 
962
        return list;
849
963
}
 
964
 
850
965
//------------------ATTRIBUTE IMPLEMENTATIONS-----------------------------
851
966
//------------------------Bone.name (get)
852
967
static PyObject *Bone_getName(BPy_Bone *self, void *closure)
862
977
}
863
978
//------------------------Bone.roll (get)
864
979
static PyObject *Bone_getRoll(BPy_Bone *self, void *closure)
865
 
{
866
 
        return Py_BuildValue("{s:O, s:O}", 
867
 
                "BONESPACE", PyFloat_FromDouble((self->bone->roll * (180/Py_PI))),
868
 
                "ARMATURESPACE", PyFloat_FromDouble((boneRoll_ToArmatureSpace(self->bone) * (180/Py_PI))));
 
980
{       
 
981
        return Py_BuildValue("{s:f, s:f}", 
 
982
                "BONESPACE", self->bone->roll * (180/Py_PI),
 
983
                "ARMATURESPACE", boneRoll_ToArmatureSpace(self->bone) * (180/Py_PI));
869
984
}
870
985
//------------------------Bone.roll (set)
871
986
static int Bone_setRoll(BPy_Bone *self, PyObject *value, void *closure)
876
991
//------------------------Bone.head (get)
877
992
static PyObject *Bone_getHead(BPy_Bone *self, void *closure)
878
993
{
879
 
        return Py_BuildValue("{s:O, s:O}", 
880
 
                "BONESPACE", newVectorObject(self->bone->head, 3, Py_WRAP),
881
 
                "ARMATURESPACE", newVectorObject(self->bone->arm_head, 3, Py_WRAP));
 
994
        PyObject *val1 = newVectorObject(self->bone->head, 3, Py_WRAP);
 
995
        PyObject *val2 = newVectorObject(self->bone->arm_head, 3, Py_WRAP);
 
996
        PyObject *ret = Py_BuildValue(
 
997
                        "{s:O, s:O}", "BONESPACE", val1, "ARMATURESPACE", val2);
 
998
        
 
999
        Py_DECREF(val1);
 
1000
        Py_DECREF(val2);
 
1001
        return ret;
882
1002
}
883
1003
//------------------------Bone.head (set)
884
1004
static int Bone_setHead(BPy_Bone *self, PyObject *value, void *closure)
889
1009
//------------------------Bone.tail (get)
890
1010
static PyObject *Bone_getTail(BPy_Bone *self, void *closure)
891
1011
{
892
 
    return Py_BuildValue("{s:O, s:O}", 
893
 
                "BONESPACE", newVectorObject(self->bone->tail, 3, Py_WRAP),
894
 
                "ARMATURESPACE", newVectorObject(self->bone->arm_tail, 3, Py_WRAP));
 
1012
        PyObject *val1 = newVectorObject(self->bone->tail, 3, Py_WRAP);
 
1013
        PyObject *val2 = newVectorObject(self->bone->arm_tail, 3, Py_WRAP);
 
1014
        PyObject *ret = Py_BuildValue("{s:O, s:O}", 
 
1015
                "BONESPACE", val1, "ARMATURESPACE", val2);
 
1016
        
 
1017
        Py_DECREF(val1);
 
1018
        Py_DECREF(val2);
 
1019
        return ret;
895
1020
}
896
1021
//------------------------Bone.tail (set)
897
1022
static int Bone_setTail(BPy_Bone *self, PyObject *value, void *closure)
974
1099
                        EXPP_GetModuleConstant("Blender.Armature", "TIP_SELECTED")) == -1)
975
1100
                        goto RuntimeError;
976
1101
 
977
 
        return EXPP_incr_ret(list);
978
 
 
 
1102
        return list;
 
1103
        
979
1104
RuntimeError:
 
1105
        Py_XDECREF(list);
980
1106
        return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
981
1107
                sBoneError, "getOptions(): ", "Internal failure!");
982
1108
}
992
1118
        if (self->bone->parent)
993
1119
                return PyBone_FromBone(self->bone->parent);
994
1120
        else
995
 
                return EXPP_incr_ret(Py_None);
 
1121
                Py_RETURN_NONE;
996
1122
}
997
1123
//------------------------Bone.parent (set)
998
1124
static int Bone_setParent(BPy_Bone *self, PyObject *value, void *closure)
1003
1129
//------------------------Bone.children (get)
1004
1130
static PyObject *Bone_getChildren(BPy_Bone *self, void *closure)
1005
1131
{
1006
 
        PyObject *list = NULL;
 
1132
        PyObject *list = PyList_New(0);
1007
1133
        Bone *bone = NULL;
1008
1134
        PyObject *py_bone = NULL;
1009
1135
 
1010
1136
        if (self->bone->childbase.first){
1011
 
                list = PyList_New(0);
1012
1137
                for (bone = self->bone->childbase.first; bone; bone = bone->next){
1013
1138
                        py_bone = PyBone_FromBone(bone);
1014
1139
                        if (py_bone == NULL)
1015
 
                                return 0;
1016
 
                        if(PyList_Append(list, py_bone) == -1){
1017
 
                                goto RuntimeError;
1018
 
                        }
 
1140
                                goto RuntimeError;
 
1141
                        if (PyList_Append(list, py_bone) == -1)
 
1142
                                goto RuntimeError;
 
1143
                        Py_DECREF(py_bone);
1019
1144
                }
1020
 
                return EXPP_incr_ret(list);
1021
 
        }else{
1022
 
                return EXPP_incr_ret(Py_None);
1023
1145
        }
1024
 
 
 
1146
        return list;
 
1147
        
1025
1148
RuntimeError:
 
1149
        Py_XDECREF(list);
 
1150
        Py_XDECREF(py_bone);
1026
1151
        return EXPP_objError(PyExc_RuntimeError, "%s%s", 
1027
1152
                sBoneError, "Internal error trying to wrap blender bones!");
1028
1153
}
1035
1160
//------------------------Bone.matrix (get)
1036
1161
static PyObject *Bone_getMatrix(BPy_Bone *self, void *closure)
1037
1162
{
1038
 
    return Py_BuildValue("{s:O, s:O}", 
1039
 
                "BONESPACE", newMatrixObject((float*)self->bone->bone_mat, 3,3, Py_WRAP),
1040
 
                "ARMATURESPACE", newMatrixObject((float*)self->bone->arm_mat, 4,4, Py_WRAP));
 
1163
        PyObject *val1 = newMatrixObject((float*)self->bone->bone_mat, 3,3, Py_WRAP);
 
1164
        PyObject *val2 = newMatrixObject((float*)self->bone->arm_mat, 4,4, Py_WRAP);
 
1165
        PyObject *ret = Py_BuildValue("{s:O, s:O}", 
 
1166
                "BONESPACE", val1, "ARMATURESPACE", val2);
 
1167
        Py_DECREF(val1);
 
1168
        Py_DECREF(val2);
 
1169
        return ret;
 
1170
    
 
1171
    
1041
1172
}
1042
1173
//------------------------Bone.matrix (set)
1043
1174
static int Bone_setMatrix(BPy_Bone *self, PyObject *value, void *closure)
1048
1179
//------------------------Bone.length (get)
1049
1180
static PyObject *Bone_getLength(BPy_Bone *self, void *closure)
1050
1181
{
1051
 
    return Py_BuildValue("f", self->bone->length);
 
1182
    return PyFloat_FromDouble(self->bone->length);
1052
1183
}
1053
1184
//------------------------Bone.length (set)
1054
1185
static int Bone_setLength(BPy_Bone *self, PyObject *value, void *closure)
1056
1187
  return EXPP_intError(PyExc_ValueError, "%s%s", 
1057
1188
                sBoneError, "You must first call .makeEditable() to edit the armature");
1058
1189
}
 
1190
 
 
1191
//------------------------Bone.headRadius (get)
 
1192
static PyObject *Bone_getHeadRadius(BPy_Bone *self, void *closure)
 
1193
{
 
1194
 
 
1195
        if (self->bone->parent && self->bone->flag & BONE_CONNECTED)
 
1196
                return PyFloat_FromDouble(self->bone->parent->rad_tail);
 
1197
        else
 
1198
                return PyFloat_FromDouble(self->bone->rad_head);
 
1199
}
 
1200
//------------------------Bone.headRadius (set)
 
1201
static int Bone_setHeadRadius(BPy_Bone *self, PyObject *value, void *closure)
 
1202
{  
 
1203
        float radius;
 
1204
        if (!PyArg_Parse(value, "f", &radius))
 
1205
                goto AttributeError;
 
1206
        CLAMP(radius, 0.0f, 10000.0f);
 
1207
 
 
1208
        if (self->bone->parent && self->bone->flag & BONE_CONNECTED)
 
1209
                self->bone->parent->rad_tail= radius;
 
1210
        else
 
1211
                self->bone->rad_head= radius;
 
1212
        return 0;
 
1213
 
 
1214
AttributeError:
 
1215
        return EXPP_intError(PyExc_AttributeError, "%s%s%s",
 
1216
                sEditBoneError, ".headRadius: ", "expects a float");
 
1217
}
 
1218
 
 
1219
//------------------------Bone.tailRadius (get)
 
1220
static PyObject *Bone_getTailRadius(BPy_Bone *self, void *closure)
 
1221
{
 
1222
        return PyFloat_FromDouble(self->bone->rad_tail);
 
1223
}
 
1224
 
 
1225
//------------------------Bone.headRadius (set)
 
1226
static int Bone_setTailRadius(BPy_Bone *self, PyObject *value, void *closure)
 
1227
{  
 
1228
        float radius;
 
1229
        if (!PyArg_Parse(value, "f", &radius))
 
1230
                goto AttributeError;
 
1231
        CLAMP(radius, 0.0f, 10000.0f);
 
1232
        self->bone->rad_tail= radius;
 
1233
        return 0;
 
1234
 
 
1235
AttributeError:
 
1236
        return EXPP_intError(PyExc_AttributeError, "%s%s%s",
 
1237
                sEditBoneError, ".headRadius: ", "expects a float");
 
1238
}
 
1239
 
 
1240
//------------------------Bone.layerMask (get)
 
1241
static PyObject *Bone_getLayerMask(BPy_Bone *self)
 
1242
{
 
1243
        /* do this extra stuff because the short's bits can be negative values */
 
1244
        unsigned short laymask = 0;
 
1245
        laymask |= self->bone->layer;
 
1246
        return PyInt_FromLong((int)laymask);
 
1247
}
 
1248
//------------------------Bone.layerMask (set)
 
1249
static int Bone_setLayerMask(BPy_Bone *self, PyObject *value)
 
1250
{
 
1251
        int laymask;
 
1252
        if (!PyInt_Check(value)) {
 
1253
                return EXPP_ReturnIntError( PyExc_AttributeError,
 
1254
                                                                        "expected an integer (bitmask) as argument" );
 
1255
        }
 
1256
        
 
1257
        laymask = PyInt_AsLong(value);
 
1258
 
 
1259
        if (laymask <= 0 || laymask > (1<<16) - 1)
 
1260
                return EXPP_ReturnIntError( PyExc_AttributeError,
 
1261
                                                                        "bitmask must have from 1 up to 16 bits set");
 
1262
 
 
1263
        self->bone->layer = 0;
 
1264
        self->bone->layer |= laymask;
 
1265
 
 
1266
        return 0;
 
1267
}
 
1268
 
1059
1269
//------------------TYPE_OBECT IMPLEMENTATION--------------------------
1060
1270
//------------------------tp_methods
1061
1271
//This contains a list of all methods the object contains
1095
1305
                "The child bones of this bone", NULL},
1096
1306
        {"length", (getter)Bone_getLength, (setter)Bone_setLength, 
1097
1307
                "The length of this bone", NULL},
 
1308
        {"tailRadius", (getter)Bone_getTailRadius, (setter)Bone_setTailRadius, 
 
1309
                "Set the radius of this bones tip", NULL},
 
1310
        {"headRadius", (getter)Bone_getHeadRadius, (setter)Bone_setHeadRadius, 
 
1311
                "Set the radius of this bones head", NULL},
 
1312
        {"layerMask", (getter)Bone_getLayerMask, (setter)Bone_setLayerMask, 
 
1313
                "Layer bitmask", NULL },
1098
1314
        {NULL, NULL, NULL, NULL,NULL}
1099
1315
};
1100
1316
//------------------------tp_repr
1103
1319
{
1104
1320
        return PyString_FromFormat( "[Bone \"%s\"]", self->bone->name ); 
1105
1321
}
 
1322
static int Bone_compare( BPy_Bone * a, BPy_Bone * b )
 
1323
{
 
1324
        return ( a->bone == b->bone ) ? 0 : -1;
 
1325
}
1106
1326
//------------------------tp_dealloc
1107
1327
//This tells how to 'tear-down' our object when ref count hits 0
1108
1328
static void Bone_dealloc(BPy_Bone * self)
1119
1339
PyTypeObject Bone_Type = {
1120
1340
        PyObject_HEAD_INIT(NULL)   //tp_head
1121
1341
        0,                                                                              //tp_internal
1122
 
        "Bone",                                                         //tp_name
1123
 
        sizeof(BPy_Bone),                                       //tp_basicsize
 
1342
        "Bone",                                                                 //tp_name
 
1343
        sizeof(BPy_Bone),                                               //tp_basicsize
1124
1344
        0,                                                                              //tp_itemsize
1125
 
        (destructor)Bone_dealloc,               //tp_dealloc
 
1345
        (destructor)Bone_dealloc,                               //tp_dealloc
1126
1346
        0,                                                                              //tp_print
1127
1347
        0,                                                                              //tp_getattr
1128
1348
        0,                                                                              //tp_setattr
1129
 
        0,                                                                              //tp_compare
1130
 
        (reprfunc) Bone_repr,                   //tp_repr
 
1349
        (cmpfunc) Bone_compare,                                 //tp_compare
 
1350
        (reprfunc) Bone_repr,                                   //tp_repr
1131
1351
        0,                                                                              //tp_as_number
1132
1352
        0,                                                                              //tp_as_sequence
1133
1353
        0,                                                                              //tp_as_mapping
1188
1408
//Converts a struct Bone to a BPy_Bone
1189
1409
PyObject *PyBone_FromBone(struct Bone *bone)
1190
1410
{
1191
 
        BPy_Bone *py_Bone = NULL;
1192
 
 
1193
 
        py_Bone = (BPy_Bone*)Bone_Type.tp_alloc(&Bone_Type, 0); //*new*
1194
 
        if (py_Bone == NULL)
1195
 
                goto RuntimeError;
1196
 
 
 
1411
        BPy_Bone *py_Bone = ( BPy_Bone * ) PyObject_NEW( BPy_Bone, &Bone_Type );
 
1412
        
1197
1413
        py_Bone->bone = bone;
1198
1414
 
1199
1415
        return (PyObject *) py_Bone;
1200
 
 
1201
 
RuntimeError:
1202
 
        return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
1203
 
                sBoneError, "PyBone_FromBone: ", "Internal Error Ocurred");
1204
1416
}
1205
1417
//-----------------(internal)
1206
1418
//Converts a PyBone to a bBone