diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-09-20 14:11:42 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-09-20 14:11:42 +0400 |
commit | 224607982ad664eaccfd703cff105eb6393b2d3e (patch) | |
tree | 84e9be425456ff192535b1caf992fd51daa2b842 /source/blender | |
parent | c282178411a07fbca859885bd3e674e186756695 (diff) |
Python api access to obcolor
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
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_arithb.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/arithb.c | 13 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 32 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Object.py | 2 | ||||
-rw-r--r-- | source/blender/src/editobject.c | 5 | ||||
-rw-r--r-- | source/blender/src/space.c | 24 |
6 files changed, 74 insertions, 3 deletions
diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h index 6e54fae58d0..4b858dcb503 100644 --- a/source/blender/blenlib/BLI_arithb.h +++ b/source/blender/blenlib/BLI_arithb.h @@ -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); diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c index f89f90f7045..c6634eb7707 100644 --- a/source/blender/blenlib/intern/arithb.c +++ b/source/blender/blenlib/intern/arithb.c @@ -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; diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 0d5af06377c..e8f45b82da4 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -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", diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py index 07942d58093..49cb14d1e66 100644 --- a/source/blender/python/api2_2x/doc/Object.py +++ b/source/blender/python/api2_2x/doc/Object.py @@ -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 diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index 2459f7ed23c..ef909a1e810 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -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"); diff --git a/source/blender/src/space.c b/source/blender/src/space.c index 64b5742dc54..198d8140ace 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -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 */ |