===Python API===
Internal code clean-up: make M_Object_New use existing code instead of duplicating the steps of object initialization/creation.
This commit is contained in:
@@ -731,29 +731,24 @@ static char *get_obdata_defname(int type)
|
||||
}
|
||||
}
|
||||
|
||||
/* general add: to G.scene, with layer from area and default name */
|
||||
/* creates minimum required data, but without vertices etc. */
|
||||
Object *add_object(int type)
|
||||
/* more general add: creates minimum required data, but without vertices etc. */
|
||||
Object *add_only_object(int type, char *name)
|
||||
{
|
||||
Object *ob;
|
||||
Base *base;
|
||||
char name[32];
|
||||
|
||||
strcpy(name, get_obdata_defname(type));
|
||||
|
||||
ob= alloc_libblock(&G.main->object, ID_OB, name);
|
||||
G.totobj++;
|
||||
|
||||
|
||||
/* default object vars */
|
||||
ob->type= type;
|
||||
/* ob->transflag= OB_QUAT; */
|
||||
|
||||
|
||||
QuatOne(ob->quat);
|
||||
QuatOne(ob->dquat);
|
||||
|
||||
ob->col[0]= ob->col[1]= ob->col[2]= 0.0;
|
||||
ob->col[3]= 1.0;
|
||||
|
||||
|
||||
ob->loc[0]= ob->loc[1]= ob->loc[2]= 0.0;
|
||||
ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
|
||||
ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
|
||||
@@ -764,7 +759,7 @@ Object *add_object(int type)
|
||||
if(U.flag & USER_MAT_ON_OB) ob->colbits= -1;
|
||||
ob->empty_drawtype= OB_ARROWS;
|
||||
ob->empty_drawsize= 1.0;
|
||||
|
||||
|
||||
if(type==OB_CAMERA || type==OB_LAMP) {
|
||||
ob->trackflag= OB_NEGZ;
|
||||
ob->upflag= OB_POSY;
|
||||
@@ -791,15 +786,29 @@ Object *add_object(int type)
|
||||
/* NT fluid sim defaults */
|
||||
ob->fluidsimFlag = 0;
|
||||
ob->fluidsimSettings = NULL;
|
||||
|
||||
|
||||
return ob;
|
||||
}
|
||||
|
||||
/* general add: to G.scene, with layer from area and default name */
|
||||
/* creates minimum required data, but without vertices etc. */
|
||||
Object *add_object(int type)
|
||||
{
|
||||
Object *ob;
|
||||
Base *base;
|
||||
char name[32];
|
||||
|
||||
strcpy(name, get_obdata_defname(type));
|
||||
ob = add_only_object(type, name);
|
||||
|
||||
ob->data= add_obdata_from_type(type);
|
||||
|
||||
|
||||
ob->lay= G.scene->lay;
|
||||
|
||||
base= scene_add_base(G.scene, ob);
|
||||
scene_select_base(G.scene, base);
|
||||
ob->recalc |= OB_RECALC;
|
||||
|
||||
|
||||
return ob;
|
||||
}
|
||||
|
||||
|
||||
@@ -769,6 +769,7 @@ PyObject *M_Object_New( PyObject * self_unused, PyObject * args )
|
||||
int type;
|
||||
char *str_type;
|
||||
char *name = NULL;
|
||||
Object *add_only_object(int type, char *name);
|
||||
|
||||
if( !PyArg_ParseTuple( args, "s|s", &str_type, &name ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
@@ -804,64 +805,13 @@ PyObject *M_Object_New( PyObject * self_unused, PyObject * args )
|
||||
/* No name is specified, set the name to the type of the object. */
|
||||
name = str_type;
|
||||
}
|
||||
object = alloc_libblock( &( G.main->object ), ID_OB, name );
|
||||
object = add_only_object(type, name);
|
||||
|
||||
object->flag = 0;
|
||||
object->type = (short)type;
|
||||
|
||||
|
||||
/* transforms */
|
||||
QuatOne( object->quat );
|
||||
QuatOne( object->dquat );
|
||||
|
||||
object->col[3] = 1.0; /* alpha */
|
||||
|
||||
object->size[0] = object->size[1] = object->size[2] = 1.0;
|
||||
object->loc[0] = object->loc[1] = object->loc[2] = 0.0;
|
||||
Mat4One( object->parentinv );
|
||||
Mat4One( object->obmat );
|
||||
object->dt = OB_SHADED; /* drawtype*/
|
||||
object->empty_drawsize= 1.0;
|
||||
object->empty_drawtype= OB_ARROWS;
|
||||
|
||||
if( U.flag & USER_MAT_ON_OB ) {
|
||||
object->colbits = -1;
|
||||
}
|
||||
switch ( object->type ) {
|
||||
case OB_CAMERA: /* fall through. */
|
||||
case OB_LAMP:
|
||||
object->trackflag = OB_NEGZ;
|
||||
object->upflag = OB_POSY;
|
||||
break;
|
||||
default:
|
||||
object->trackflag = OB_POSY;
|
||||
object->upflag = OB_POSZ;
|
||||
}
|
||||
object->ipoflag = OB_OFFS_OB + OB_OFFS_PARENT;
|
||||
|
||||
/* duplivert settings */
|
||||
object->dupon = 1;
|
||||
object->dupoff = 0;
|
||||
object->dupsta = 1;
|
||||
object->dupend = 100;
|
||||
|
||||
/* Gameengine defaults */
|
||||
object->mass = 1.0;
|
||||
object->inertia = 1.0;
|
||||
object->formfactor = 0.4f;
|
||||
object->damping = 0.04f;
|
||||
object->rdamping = 0.1f;
|
||||
object->anisotropicFriction[0] = 1.0;
|
||||
object->anisotropicFriction[1] = 1.0;
|
||||
object->anisotropicFriction[2] = 1.0;
|
||||
object->gameflag = OB_PROP;
|
||||
|
||||
object->lay = 1; /* Layer, by default visible*/
|
||||
G.totobj++;
|
||||
|
||||
object->data = NULL;
|
||||
|
||||
/* user count be incremented in Object_CreatePyObject */
|
||||
/* user count is incremented in Object_CreatePyObject */
|
||||
object->id.us = 0;
|
||||
|
||||
/* Create a Python object from it. */
|
||||
@@ -3092,7 +3042,11 @@ Object *GetObjectByName( char *name )
|
||||
/*****************************************************************************/
|
||||
static void Object_dealloc( BPy_Object * obj )
|
||||
{
|
||||
#if 1 /* this just adjust the ID but doesn't delete zero-user objects */
|
||||
obj->object->id.us--;
|
||||
#else /* this will adjust the ID and if zero delete the object */
|
||||
free_libblock_us( &G.main->object, obj->object );
|
||||
#endif
|
||||
PyObject_DEL( obj );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user