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
This commit is contained in:
Campbell Barton 2008-09-20 10:11:42 +00:00
parent c282178411
commit 224607982a
7 changed files with 78 additions and 7 deletions

@ -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

@ -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);

@ -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;

@ -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",

@ -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

@ -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");

@ -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 */