Python api access to obcolor
authorCampbell Barton <ideasman42@gmail.com>
Sat, 20 Sep 2008 10:11:42 +0000 (10:11 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 20 Sep 2008 10:11:42 +0000 (10:11 +0000)
Option to copy obcolor in the copy menu
Option to select same color in select grouped menu
console.py - mistake in last commit caused a python error

release/scripts/console.py
source/blender/blenlib/BLI_arithb.h
source/blender/blenlib/intern/arithb.c
source/blender/python/api2_2x/Object.c
source/blender/python/api2_2x/doc/Object.py
source/blender/src/editobject.c
source/blender/src/space.c

index cc1788ce24ce99b83d870c60a2eb3ecade0b9c92..0e46f41f581be7cee12bf2a5e6f8d9123c6ec3b5 100644 (file)
@@ -417,8 +417,8 @@ def handle_event(evt, val):
                        histIndex = -1
                        
                        # When wrapping allow 1 plank lines
-                       if cmdBuffer[-1].cmd != '':
-                               cmdBuffer[-1].cmd = ''
+                       if cmdBuffer[-1].cmd != ' ':
+                               cmdBuffer[-1].cmd = ' '
                                return
                
                histIndex_orig = histIndex
@@ -437,8 +437,8 @@ def handle_event(evt, val):
                        histIndex = -len(cmdBuffer)
                        
                        # When wrapping allow 1 plank lines
-                       if cmdBuffer[-1].cmd != '':
-                               cmdBuffer[-1].cmd = ''
+                       if cmdBuffer[-1].cmd != ' ':
+                               cmdBuffer[-1].cmd = ' '
                                return
                        
                histIndex_orig = histIndex
index 6e54fae58d0eace41f87af0e4fea48dbbc3a84b8..4b858dcb50304928b48517952b1edf04a0faac5c 100644 (file)
@@ -91,6 +91,7 @@ float saasin(float fac);
 float sasqrt(float fac);
 
 int FloatCompare(float *v1, float *v2, float limit);
+int FloatCompare4(float *v1, float *v2, float limit);
 float FloatLerpf(float target, float origin, float fac);
 
 float CalcNormFloat(float *v1, float *v2, float *v3, float *n);
index f89f90f70455f5dccbfd05e56bb825871524f63c..c6634eb77079a65d1b3793433c12a7984795354e 100644 (file)
@@ -1026,6 +1026,19 @@ int FloatCompare( float *v1,  float *v2, float limit)
        return 0;
 }
 
+int FloatCompare4( float *v1,  float *v2, float limit)
+{
+
+       if( fabs(v1[0]-v2[0])<limit ) {
+               if( fabs(v1[1]-v2[1])<limit ) {
+                       if( fabs(v1[2]-v2[2])<limit ) {
+                               if( fabs(v1[3]-v2[3])<limit ) return 1;
+                       }
+               }
+       }
+       return 0;
+}
+
 float FloatLerpf( float target, float origin, float fac)
 {
        return (fac*target) + (1.0f-fac)*origin;
index 0d5af06377c112c08483fa7021912aad0fb508e0..e8f45b82da4c3bb39a006089eb9f40057d76b451 100644 (file)
@@ -3305,6 +3305,33 @@ static PyObject *Object_insertShapeKey(BPy_Object * self)
        Py_RETURN_NONE;
 }
 
+static PyObject *Object_getColor( BPy_Object *self, void *type )
+{
+       return Py_BuildValue( "(ffff)", self->object->col[0], self->object->col[1], self->object->col[2], self->object->col[3] );
+}
+
+static int Object_setColor( BPy_Object *self, PyObject *value )
+{
+       int i;
+       float color[4];
+       struct Object *object = self->object;
+
+       value = PySequence_Tuple( value );
+
+       if( !value || !PyArg_ParseTuple( value, "ffff", &color[0], &color[1], &color[2], &color[3] ) ) {
+               Py_XDECREF( value );
+               return EXPP_ReturnIntError( PyExc_TypeError,
+                                       "expected a list or tuple of 3 floats" );
+       }
+
+       Py_DECREF( value );
+       
+       for( i = 0; i < 4; ++i ) {
+               object->col[i] = MAX2(MIN2(color[i], 1.0), 0);
+       }
+       return 0;
+}
+
 /* __copy__() */
 static  PyObject *Object_copy(BPy_Object * self)
 {
@@ -5189,7 +5216,10 @@ static PyGetSetDef BPy_Object_getseters[] = {
         (getter)Object_getDrawModeBits, (setter)Object_setDrawModeBits,
         "Transparent materials for the active object (mesh only) enabled",
         (void *)OB_DRAWTRANSP},
-
+       {"color",
+        (getter)Object_getColor, (setter)Object_setColor,
+        "Object color used by the game engine and optionally for materials",
+        NULL},
        {"enableNLAOverride",
         (getter)Object_getNLAflagBits, (setter)Object_setNLAflagBits,
         "Toggles Action-NLA based animation",
index 07942d580937c46b0954fa14fd8a2f6333160812..49cb14d1e664d5ce9b9ecaf9d384e6432d72d03f 100644 (file)
@@ -552,6 +552,8 @@ class Object:
        @ivar transp: Enable transparent materials for the active object
                (mesh only).  Also see B{TRANSP} bit in L{drawMode} attribute.
        @type transp: boolean
+       @ivar color: Object color used by the game engine and optionally for materials, 4 floats for RGBA object color.
+       @type color: tuple of 4 floats between 0 and 1
        @ivar drawMode: The object's drawing mode bitfield.
                See L{DrawModes} constant dict for values.
        @type drawMode: int
index 2459f7ed23c8f22270e83a884e0e75f41baa72f3..ef909a1e810bd11b0175869adf8fac1376d405e7 100644 (file)
@@ -3672,6 +3672,9 @@ void copy_attr(short event)
                                else if(event==30) { /* index object */
                                        base->object->index= ob->index;
                                }
+                               else if(event==31) { /* object color */
+                                       QUATCOPY(base->object->col, ob->col);
+                               }
                        }
                }
                base= base->next;
@@ -3710,7 +3713,7 @@ void copy_attr_menu()
         * view3d_edit_object_copyattrmenu() and in toolbox.c
         */
        
-       strcpy(str, "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Draw Options%x4|Time Offset%x5|Dupli%x6|%l|Mass%x7|Damping%x8|All Physical Attributes%x11|Properties%x9|Logic Bricks%x10|Protected Transform%x29|%l");
+       strcpy(str, "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Draw Options%x4|Time Offset%x5|Dupli%x6|Object Color%x31|%l|Mass%x7|Damping%x8|All Physical Attributes%x11|Properties%x9|Logic Bricks%x10|Protected Transform%x29|%l");
        
        strcat (str, "|Object Constraints%x22");
        strcat (str, "|NLA Strips%x26");
index 64b5742dc54fb9d84fa18844d3f9ef7dd3dbd22c..198d8140aceb3c96ab7d8d8b7f37ddcc239bd474 100644 (file)
@@ -897,6 +897,25 @@ static short select_same_index_object(Object *ob)
        return changed;
 }
 
+static short select_same_color(Object *ob)
+{
+       char changed = 0;
+       Base *base = FIRSTBASE;
+       
+       if (!ob)
+               return 0;
+       
+       while(base) {
+               if (BASE_SELECTABLE(base) && !(base->flag & SELECT) && (FloatCompare(base->object->col, ob->col, 0.005))) {
+                       base->flag |= SELECT;
+                       base->object->flag |= SELECT;
+                       changed = 1;
+               }
+               base= base->next;
+       }
+       return changed;
+}
+
 void select_object_grouped(short nr)
 {
        short changed = 0;
@@ -909,6 +928,7 @@ void select_object_grouped(short nr)
        else if(nr==7)  changed = select_same_group(OBACT);
        else if(nr==8)  changed = select_object_hooks(OBACT);
        else if(nr==9)  changed = select_same_index_object(OBACT);
+       else if(nr==10) changed = select_same_color(OBACT);
        
        if (changed) {
                countall();
@@ -934,7 +954,9 @@ static void select_object_grouped_menu(void)
                    "Objects of Same Type%x5|"
                                "Objects on Shared Layers%x6|"
                 "Objects in Same Group%x7|"
-                "Object Hooks%x8|Object PassIndex%x9");
+                "Object Hooks%x8|"
+                               "Object PassIndex%x9|"
+                               "Object Color%x10");
 
        /* here we go */