* Implemented the 3 functions needed by the Object module:

For  Camera and Lamp
* Minor updates, NMesh is not finished yet.
This commit is contained in:
2003-05-20 03:56:41 +00:00
parent 1a87f3a4aa
commit 4ca6f542a2
8 changed files with 192 additions and 46 deletions

View File

@@ -224,5 +224,6 @@ void M_Blender_Init (void)
PyDict_SetItemString (dict, "Draw", M_Draw_Init()); PyDict_SetItemString (dict, "Draw", M_Draw_Init());
PyDict_SetItemString (dict, "BGL", M_BGL_Init()); PyDict_SetItemString (dict, "BGL", M_BGL_Init());
PyDict_SetItemString (dict, "Text", M_Text_Init()); PyDict_SetItemString (dict, "Text", M_Text_Init());
// PyDict_SetItemString (dict, "Effect", M_Text_Init());
} }

View File

@@ -35,7 +35,7 @@
/* Function: M_Camera_New */ /* Function: M_Camera_New */
/* Python equivalent: Blender.Camera.New */ /* Python equivalent: Blender.Camera.New */
/*****************************************************************************/ /*****************************************************************************/
static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *keywords) static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *kwords)
{ {
char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */ char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */
char *name_str = "CamData"; char *name_str = "CamData";
@@ -46,7 +46,7 @@ static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *keywords
printf ("In Camera_New()\n"); printf ("In Camera_New()\n");
if (!PyArg_ParseTupleAndKeywords(args, keywords, "|ss", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwords, "|ss", kwlist,
&type_str, &name_str)) &type_str, &name_str))
/* We expected string(s) (or nothing) as argument, but we didn't get that. */ /* We expected string(s) (or nothing) as argument, but we didn't get that. */
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
@@ -155,6 +155,7 @@ static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
/*****************************************************************************/ /*****************************************************************************/
/* Function: M_Camera_Init */ /* Function: M_Camera_Init */
/*****************************************************************************/ /*****************************************************************************/
/* Needed by the Blender module, to register the Blender.Camera submodule */
PyObject *M_Camera_Init (void) PyObject *M_Camera_Init (void)
{ {
PyObject *submodule; PyObject *submodule;
@@ -166,6 +167,48 @@ PyObject *M_Camera_Init (void)
return (submodule); return (submodule);
} }
/* Three Python Camera_Type helper functions needed by the Object module: */
/*****************************************************************************/
/* Function: Camera_createPyObject */
/* Description: This function will create a new C_Camera from an existing */
/* Blender camera structure. */
/*****************************************************************************/
PyObject *Camera_createPyObject (Camera *cam)
{
C_Camera *pycam;
pycam = (C_Camera *)PyObject_NEW (C_Camera, &Camera_Type);
if (!pycam)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create C_Camera object");
pycam->camera = cam;
return (PyObject *)pycam;
}
/*****************************************************************************/
/* Function: Camera_checkPyObject */
/* Description: This function returns true when the given PyObject is of the */
/* type Camera. Otherwise it will return false. */
/*****************************************************************************/
int Camera_checkPyObject (PyObject *pyobj)
{
return (pyobj->ob_type == &Camera_Type);
}
/*****************************************************************************/
/* Function: Camera_fromPyObject */
/* Description: This function returns the Blender camera from the given */
/* PyObject. */
/*****************************************************************************/
Camera *Camera_fromPyObject (PyObject *pyobj)
{
return ((C_Camera *)pyobj)->camera;
}
/*****************************************************************************/ /*****************************************************************************/
/* Python C_Camera methods: */ /* Python C_Camera methods: */
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -43,7 +43,6 @@
#include "constant.h" #include "constant.h"
#include "gen_utils.h" #include "gen_utils.h"
#include "modules.h"
/*****************************************************************************/ /*****************************************************************************/
/* Python C_Camera defaults: */ /* Python C_Camera defaults: */
@@ -195,6 +194,15 @@ static int CameraSetAttr (C_Camera *self, char *name, PyObject *v);
static PyObject *CameraGetAttr (C_Camera *self, char *name); static PyObject *CameraGetAttr (C_Camera *self, char *name);
static PyObject *CameraRepr (C_Camera *self); static PyObject *CameraRepr (C_Camera *self);
/*****************************************************************************/
/* Python Camera_Type helper functions needed by Blender (the Init function) */
/* and Object modules. */
/*****************************************************************************/
PyObject *M_Camera_Init (void);
PyObject *CameraCreatePyObject (Camera *cam);
Camera *CameraFromPyObject (PyObject *pyobj);
int CameraCheckPyObject (PyObject *pyobj);
/*****************************************************************************/ /*****************************************************************************/
/* Python Camera_Type structure definition: */ /* Python Camera_Type structure definition: */
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -157,6 +157,7 @@ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
/*****************************************************************************/ /*****************************************************************************/
/* Function: M_Lamp_Init */ /* Function: M_Lamp_Init */
/*****************************************************************************/ /*****************************************************************************/
/* Needed by the Blender module, to register the Blender.Lamp submodule */
PyObject *M_Lamp_Init (void) PyObject *M_Lamp_Init (void)
{ {
PyObject *submodule; PyObject *submodule;
@@ -168,6 +169,48 @@ PyObject *M_Lamp_Init (void)
return (submodule); return (submodule);
} }
/* Three Python Lamp_Type helper functions needed by the Object module: */
/*****************************************************************************/
/* Function: Lamp_createPyObject */
/* Description: This function will create a new C_Lamp from an existing */
/* Blender camera structure. */
/*****************************************************************************/
PyObject *Lamp_createPyObject (Lamp *lamp)
{
C_Lamp *pylamp;
pylamp = (C_Lamp *)PyObject_NEW (C_Lamp, &Lamp_Type);
if (!pylamp)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create C_Lamp object");
pylamp->lamp = lamp;
return (PyObject *)pylamp;
}
/*****************************************************************************/
/* Function: Lamp_checkPyObject */
/* Description: This function returns true when the given PyObject is of the */
/* type Lamp. Otherwise it will return false. */
/*****************************************************************************/
int Lamp_checkPyObject (PyObject *pyobj)
{
return (pyobj->ob_type == &Lamp_Type);
}
/*****************************************************************************/
/* Function: Lamp_fromPyObject */
/* Description: This function returns the Blender lamp from the given */
/* PyObject. */
/*****************************************************************************/
Lamp *Lamp_fromPyObject (PyObject *pyobj)
{
return ((C_Lamp *)pyobj)->lamp;
}
/*****************************************************************************/ /*****************************************************************************/
/* Python C_Lamp methods: */ /* Python C_Lamp methods: */
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -49,7 +49,6 @@
/*****************************************************************************/ /*****************************************************************************/
/* Python C_Lamp defaults: */ /* Python C_Lamp defaults: */
/*****************************************************************************/ /*****************************************************************************/
#define EXPP_LAMP_MAX 256
/* Lamp types */ /* Lamp types */
@@ -294,6 +293,15 @@ static int LampSetAttr (C_Lamp *lamp, char *name, PyObject *v);
static PyObject *LampRepr (C_Lamp *lamp); static PyObject *LampRepr (C_Lamp *lamp);
static int LampPrint (C_Lamp *lamp, FILE *fp, int flags); static int LampPrint (C_Lamp *lamp, FILE *fp, int flags);
/*****************************************************************************/
/* Python Lamp_Type helper functions needed by Blender (the Init function) */
/* and Object modules. */
/*****************************************************************************/
PyObject *M_Lamp_Init (void);
PyObject *LampCreatePyObject (Lamp *lamp);
Lamp *LampFromPyObject (PyObject *pyobj);
int LampCheckPyObject (PyObject *pyobj);
/*****************************************************************************/ /*****************************************************************************/
/* Python TypeLamp structure definition: */ /* Python TypeLamp structure definition: */
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -236,7 +236,7 @@ static PyObject *NMFace_getattr(PyObject *self, char *name)
static int NMFace_setattr(PyObject *self, char *name, PyObject *v) static int NMFace_setattr(PyObject *self, char *name, PyObject *v)
{ {
C_NMFace *mf = (C_NMFace *) self; C_NMFace *mf = (C_NMFace *)self;
short ival; short ival;
if (strcmp(name, "v") == 0) { if (strcmp(name, "v") == 0) {
@@ -259,14 +259,12 @@ static int NMFace_setattr(PyObject *self, char *name, PyObject *v)
} }
else if (!strcmp(name, "mat") || !strcmp(name, "materialIndex")) { else if (!strcmp(name, "mat") || !strcmp(name, "materialIndex")) {
PyArg_Parse(v, "h", &ival); PyArg_Parse(v, "h", &ival);
mf->mat_nr= ival; mf->mat_nr= ival;
return 0; return 0;
} }
else if (strcmp(name, "smooth") == 0) { else if (strcmp(name, "smooth") == 0) {
PyArg_Parse(v, "h", &ival); PyArg_Parse(v, "h", &ival);
mf->smooth = ival?1:0; mf->smooth = ival?1:0;
return 0; return 0;
@@ -275,7 +273,7 @@ static int NMFace_setattr(PyObject *self, char *name, PyObject *v)
if(PySequence_Check(v)) { if(PySequence_Check(v)) {
Py_DECREF(mf->uv); Py_DECREF(mf->uv);
mf->uv= EXPP_incr_ret(v); mf->uv = EXPP_incr_ret(v);
return 0; return 0;
} }
@@ -371,7 +369,7 @@ PyTypeObject NMFace_Type =
static C_NMVert *newvert(float *co) static C_NMVert *newvert(float *co)
{ {
C_NMVert *mv= PyObject_NEW(C_NMVert, &NMVert_Type); C_NMVert *mv = PyObject_NEW(C_NMVert, &NMVert_Type);
mv->co[0] = co[0]; mv->co[1] = co[1]; mv->co[2] = co[2]; mv->co[0] = co[0]; mv->co[1] = co[1]; mv->co[2] = co[2];
@@ -540,7 +538,7 @@ PyTypeObject NMVert_Type =
static void NMesh_dealloc(PyObject *self) static void NMesh_dealloc(PyObject *self)
{ {
C_NMesh *me= (C_NMesh *) self; C_NMesh *me = (C_NMesh *)self;
Py_DECREF(me->name); Py_DECREF(me->name);
Py_DECREF(me->verts); Py_DECREF(me->verts);
@@ -551,13 +549,13 @@ static void NMesh_dealloc(PyObject *self)
static PyObject *NMesh_getSelectedFaces(PyObject *self, PyObject *args) static PyObject *NMesh_getSelectedFaces(PyObject *self, PyObject *args)
{ {
C_NMesh *nm= (C_NMesh *) self; C_NMesh *nm = (C_NMesh *)self;
Mesh *me = nm->mesh; Mesh *me = nm->mesh;
int flag = 0; int flag = 0;
TFace *tf; TFace *tf;
int i; int i;
PyObject *l= PyList_New(0); PyObject *l = PyList_New(0);
if (me == NULL) return NULL; if (me == NULL) return NULL;
@@ -566,19 +564,18 @@ static PyObject *NMesh_getSelectedFaces(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|i", &flag)) if (!PyArg_ParseTuple(args, "|i", &flag))
return NULL; return NULL;
if (flag) { if (flag) {
for (i =0 ; i < me->totface; i++) { for (i = 0 ; i < me->totface; i++) {
if (tf[i].flag & TF_SELECT ) { if (tf[i].flag & TF_SELECT )
PyList_Append(l, PyInt_FromLong(i)); PyList_Append(l, PyInt_FromLong(i));
} }
}
} else { } else {
for (i =0 ; i < me->totface; i++) { for (i = 0 ; i < me->totface; i++) {
if (tf[i].flag & TF_SELECT ) { if (tf[i].flag & TF_SELECT )
PyList_Append(l, PyList_GetItem(nm->faces, i)); PyList_Append(l, PyList_GetItem(nm->faces, i));
} }
} }
}
return l; return l;
} }
@@ -610,7 +607,7 @@ static PyObject *NMesh_hasVertexUV(PyObject *self, PyObject *args)
static PyObject *NMesh_hasFaceUV(PyObject *self, PyObject *args) static PyObject *NMesh_hasFaceUV(PyObject *self, PyObject *args)
{ {
C_NMesh *me= (C_NMesh *) self; C_NMesh *me = (C_NMesh *)self;
int flag = -1; int flag = -1;
if (!PyArg_ParseTuple(args, "|i", &flag)) if (!PyArg_ParseTuple(args, "|i", &flag))
@@ -704,7 +701,7 @@ Mesh *Mesh_fromNMesh(C_NMesh *nmesh)
return mesh; return mesh;
} }
PyObject * NMesh_link(PyObject *self, PyObject *args) PyObject *NMesh_link(PyObject *self, PyObject *args)
{ {
// XXX return DataBlock_link(self, args); // XXX return DataBlock_link(self, args);
return EXPP_incr_ret(Py_None); return EXPP_incr_ret(Py_None);
@@ -1363,12 +1360,12 @@ static int convert_NMeshToMesh(Mesh *mesh, C_NMesh *nmesh)
* index. - Zr * index. - Zr
*/ */
for (i = 0; i < mesh->totface; i++) { for (i = 0; i < mesh->totface; i++) {
C_NMFace *mf= (C_NMFace *) PySequence_GetItem(nmesh->faces, i); C_NMFace *mf = (C_NMFace *)PySequence_GetItem(nmesh->faces, i);
j= PySequence_Length(mf->v); j = PySequence_Length(mf->v);
while (j--) { while (j--) {
C_NMVert *mv = (C_NMVert *)PySequence_GetItem(mf->v, j); C_NMVert *mv = (C_NMVert *)PySequence_GetItem(mf->v, j);
if (C_NMVert_Check(mv)) mv->index= -1; if (C_NMVert_Check(mv)) mv->index = -1;
Py_DECREF(mv); Py_DECREF(mv);
} }

View File

@@ -32,6 +32,9 @@
/* Most of this file comes from opy_nmesh.[ch] in the old bpython dir */ /* Most of this file comes from opy_nmesh.[ch] in the old bpython dir */
#ifndef EXPP_NMESH_H
#define EXPP_NMESH_H
#include "Python.h" #include "Python.h"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@@ -197,8 +200,10 @@ static int convert_NMeshToMesh(Mesh *mesh, C_NMesh *nmesh);
void mesh_update(Mesh *mesh); void mesh_update(Mesh *mesh);
PyObject *new_NMesh(Mesh *oldmesh); PyObject *new_NMesh(Mesh *oldmesh);
Mesh *Mesh_fromNMesh(C_NMesh *nmesh); Mesh *Mesh_fromNMesh(C_NMesh *nmesh);
// XXX change NMesh *ob below to Object, void to Material
PyObject *NMesh_assignMaterials_toObject(C_NMesh *nmesh, Object *ob); PyObject *NMesh_assignMaterials_toObject(C_NMesh *nmesh, Object *ob);
Material **nmesh_updateMaterials(C_NMesh *nmesh); Material **nmesh_updateMaterials(C_NMesh *nmesh);
Material **newMaterialList_fromPyList (PyObject *list); Material **newMaterialList_fromPyList (PyObject *list);
void mesh_update(Mesh *mesh); void mesh_update(Mesh *mesh);
#endif /* EXPP_NMESH_H */

View File

@@ -24,33 +24,74 @@
* *
* This is a new part of Blender. * This is a new part of Blender.
* *
* Contributor(s): Michel Selten * Contributor(s): Michel Selten, Willian P. Germano
* *
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/ */
#ifndef EXPP_modules_h
#define EXPP_modules_h
#include <Python.h> #include <Python.h>
#include <DNA_object_types.h> #include <DNA_object_types.h>
#include <DNA_camera_types.h> #include <DNA_camera_types.h>
#include <DNA_lamp_types.h> #include <DNA_lamp_types.h>
#include <DNA_image_types.h> #include <DNA_curve_types.h>
#include <DNA_effect_types.h>
/*****************************************************************************/ /*****************************************************************************/
/* Global variables */ /* Global variables */
/*****************************************************************************/ /*****************************************************************************/
extern PyObject *g_blenderdict; extern PyObject *g_blenderdict;
/*****************************************************************************/
/* Module Init functions and Data Object helper functions (used by the */
/* Object module to work with its .data field for the various Data objs */
/*****************************************************************************/
void M_Blender_Init (void); void M_Blender_Init (void);
/* Object itself */
PyObject * M_Object_Init (void); PyObject * M_Object_Init (void);
PyObject * M_ObjectCreatePyObject (struct Object *obj); PyObject * M_ObjectCreatePyObject (struct Object *obj);
int M_ObjectCheckPyObject (PyObject *py_obj); int M_ObjectCheckPyObject (PyObject *py_obj);
struct Object * M_ObjectFromPyObject (PyObject *py_obj); struct Object * M_ObjectFromPyObject (PyObject *py_obj);
/* NMesh Data */
PyObject * M_NMesh_Init (void); PyObject * M_NMesh_Init (void);
/* Camera Data */
PyObject * M_Camera_Init (void); PyObject * M_Camera_Init (void);
PyObject * Camera_createPyObject (struct Camera *cam);
Camera * Camera_fromPyObject (PyObject *pyobj);
int Camera_checkPyObject (PyObject *pyobj);
/* Lamp Data */
PyObject * M_Lamp_Init (void); PyObject * M_Lamp_Init (void);
PyObject * Lamp_createPyObject (struct Lamp *lamp);
Lamp * Lamp_fromPyObject (PyObject *pyobj);
int Lamp_checkPyObject (PyObject *pyobj);
/* Curve Data */
PyObject * M_Curve_Init (void); PyObject * M_Curve_Init (void);
PyObject * M_Image_Init (void); PyObject * CurveCreatePyObject (struct Curve *curve);
struct Curve * CurveFromPyObject (PyObject *py_obj);
int CurveCheckPyObject (PyObject *py_obj);
/* Particle Effects Data */
/*
PyObject * M_Effect_Init (void);
PyObject * EffectCreatePyObject (struct Effect *effect);
int EffectCheckPyObject (PyObject *py_obj);
struct Effect * EffectFromPyObject (PyObject *py_obj);
*/
/* Init functions for other modules */
PyObject * M_Window_Init (void); PyObject * M_Window_Init (void);
PyObject * M_Image_Init (void);
PyObject * M_Draw_Init (void); PyObject * M_Draw_Init (void);
PyObject * M_BGL_Init (void); PyObject * M_BGL_Init (void);
PyObject * M_Text_Init (void); PyObject * M_Text_Init (void);
#endif /* EXPP_modules_h */