* 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:
parent
1a87f3a4aa
commit
4ca6f542a2
@ -224,5 +224,6 @@ void M_Blender_Init (void)
|
||||
PyDict_SetItemString (dict, "Draw", M_Draw_Init());
|
||||
PyDict_SetItemString (dict, "BGL", M_BGL_Init());
|
||||
PyDict_SetItemString (dict, "Text", M_Text_Init());
|
||||
// PyDict_SetItemString (dict, "Effect", M_Text_Init());
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
/* Function: M_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 *name_str = "CamData";
|
||||
@ -46,7 +46,7 @@ static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *keywords
|
||||
|
||||
printf ("In Camera_New()\n");
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywords, "|ss", kwlist,
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwords, "|ss", kwlist,
|
||||
&type_str, &name_str))
|
||||
/* We expected string(s) (or nothing) as argument, but we didn't get that. */
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
@ -155,6 +155,7 @@ static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Camera_Init */
|
||||
/*****************************************************************************/
|
||||
/* Needed by the Blender module, to register the Blender.Camera submodule */
|
||||
PyObject *M_Camera_Init (void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
@ -166,6 +167,48 @@ PyObject *M_Camera_Init (void)
|
||||
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: */
|
||||
/*****************************************************************************/
|
||||
|
@ -43,7 +43,6 @@
|
||||
|
||||
#include "constant.h"
|
||||
#include "gen_utils.h"
|
||||
#include "modules.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 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 *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: */
|
||||
/*****************************************************************************/
|
||||
|
@ -157,6 +157,7 @@ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Lamp_Init */
|
||||
/*****************************************************************************/
|
||||
/* Needed by the Blender module, to register the Blender.Lamp submodule */
|
||||
PyObject *M_Lamp_Init (void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
@ -168,6 +169,48 @@ PyObject *M_Lamp_Init (void)
|
||||
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: */
|
||||
/*****************************************************************************/
|
||||
|
@ -49,7 +49,6 @@
|
||||
/*****************************************************************************/
|
||||
/* Python C_Lamp defaults: */
|
||||
/*****************************************************************************/
|
||||
#define EXPP_LAMP_MAX 256
|
||||
|
||||
/* Lamp types */
|
||||
|
||||
@ -294,6 +293,15 @@ static int LampSetAttr (C_Lamp *lamp, char *name, PyObject *v);
|
||||
static PyObject *LampRepr (C_Lamp *lamp);
|
||||
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: */
|
||||
/*****************************************************************************/
|
||||
|
@ -236,7 +236,7 @@ static PyObject *NMFace_getattr(PyObject *self, char *name)
|
||||
|
||||
static int NMFace_setattr(PyObject *self, char *name, PyObject *v)
|
||||
{
|
||||
C_NMFace *mf = (C_NMFace *) self;
|
||||
C_NMFace *mf = (C_NMFace *)self;
|
||||
short ival;
|
||||
|
||||
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")) {
|
||||
PyArg_Parse(v, "h", &ival);
|
||||
|
||||
mf->mat_nr= ival;
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (strcmp(name, "smooth") == 0) {
|
||||
PyArg_Parse(v, "h", &ival);
|
||||
|
||||
mf->smooth = ival?1:0;
|
||||
|
||||
return 0;
|
||||
@ -275,7 +273,7 @@ static int NMFace_setattr(PyObject *self, char *name, PyObject *v)
|
||||
|
||||
if(PySequence_Check(v)) {
|
||||
Py_DECREF(mf->uv);
|
||||
mf->uv= EXPP_incr_ret(v);
|
||||
mf->uv = EXPP_incr_ret(v);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -352,10 +350,10 @@ static PySequenceMethods NMFace_SeqMethods =
|
||||
PyTypeObject NMFace_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"NMFace", /*tp_name*/
|
||||
sizeof(C_NMFace), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
0, /*ob_size*/
|
||||
"NMFace", /*tp_name*/
|
||||
sizeof(C_NMFace), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor) NMFace_dealloc, /*tp_dealloc*/
|
||||
(printfunc) 0, /*tp_print*/
|
||||
@ -371,7 +369,7 @@ PyTypeObject NMFace_Type =
|
||||
|
||||
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];
|
||||
|
||||
@ -384,7 +382,7 @@ static C_NMVert *newvert(float *co)
|
||||
static PyObject *M_NMesh_Vert(PyObject *self, PyObject *args)
|
||||
{
|
||||
float co[3]= {0.0, 0.0, 0.0};
|
||||
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|fff", &co[0], &co[1], &co[2]))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected three floats (or nothing) as arguments");
|
||||
@ -404,8 +402,8 @@ static PyObject *NMVert_getattr(PyObject *self, char *name)
|
||||
if (!strcmp(name, "co") || !strcmp(name, "loc"))
|
||||
return newVectorObject(mv->co, 3);
|
||||
|
||||
else if (strcmp(name, "no") == 0) return newVectorObject(mv->no, 3);
|
||||
else if (strcmp(name, "uvco") == 0) return newVectorObject(mv->uvco, 3);
|
||||
else if (strcmp(name, "no") == 0) return newVectorObject(mv->no, 3);
|
||||
else if (strcmp(name, "uvco") == 0) return newVectorObject(mv->uvco, 3);
|
||||
else if (strcmp(name, "index") == 0) return PyInt_FromLong(mv->index);
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError, name);
|
||||
@ -540,7 +538,7 @@ PyTypeObject NMVert_Type =
|
||||
|
||||
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->verts);
|
||||
@ -551,13 +549,13 @@ static void NMesh_dealloc(PyObject *self)
|
||||
|
||||
static PyObject *NMesh_getSelectedFaces(PyObject *self, PyObject *args)
|
||||
{
|
||||
C_NMesh *nm= (C_NMesh *) self;
|
||||
C_NMesh *nm = (C_NMesh *)self;
|
||||
Mesh *me = nm->mesh;
|
||||
int flag = 0;
|
||||
|
||||
TFace *tf;
|
||||
int i;
|
||||
PyObject *l= PyList_New(0);
|
||||
PyObject *l = PyList_New(0);
|
||||
|
||||
if (me == NULL) return NULL;
|
||||
|
||||
@ -566,17 +564,16 @@ static PyObject *NMesh_getSelectedFaces(PyObject *self, PyObject *args)
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|i", &flag))
|
||||
return NULL;
|
||||
if (flag) {
|
||||
for (i =0 ; i < me->totface; i++) {
|
||||
if (tf[i].flag & TF_SELECT ) {
|
||||
PyList_Append(l, PyInt_FromLong(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
for (i = 0 ; i < me->totface; i++) {
|
||||
if (tf[i].flag & TF_SELECT )
|
||||
PyList_Append(l, PyInt_FromLong(i));
|
||||
}
|
||||
} else {
|
||||
for (i =0 ; i < me->totface; i++) {
|
||||
if (tf[i].flag & TF_SELECT ) {
|
||||
for (i = 0 ; i < me->totface; i++) {
|
||||
if (tf[i].flag & TF_SELECT )
|
||||
PyList_Append(l, PyList_GetItem(nm->faces, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
return l;
|
||||
@ -610,7 +607,7 @@ static PyObject *NMesh_hasVertexUV(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;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|i", &flag))
|
||||
@ -704,7 +701,7 @@ Mesh *Mesh_fromNMesh(C_NMesh *nmesh)
|
||||
return mesh;
|
||||
}
|
||||
|
||||
PyObject * NMesh_link(PyObject *self, PyObject *args)
|
||||
PyObject *NMesh_link(PyObject *self, PyObject *args)
|
||||
{
|
||||
// XXX return DataBlock_link(self, args);
|
||||
return EXPP_incr_ret(Py_None);
|
||||
@ -1363,18 +1360,18 @@ static int convert_NMeshToMesh(Mesh *mesh, C_NMesh *nmesh)
|
||||
* index. - Zr
|
||||
*/
|
||||
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--) {
|
||||
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(mf);
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < mesh->totvert; i++) {
|
||||
C_NMVert *mv = (C_NMVert *)PySequence_GetItem(nmesh->verts, i);
|
||||
mv->index = i;
|
||||
@ -1492,7 +1489,7 @@ static PyObject *M_NMesh_PutRaw(PyObject *self, PyObject *args)
|
||||
// Materials can be assigned two ways:
|
||||
// a) to the object data (in this case, the mesh)
|
||||
// b) to the Object
|
||||
//
|
||||
//
|
||||
// Case a) is wanted, if Mesh data should be shared among objects,
|
||||
// as well as its materials (up to 16)
|
||||
// Case b) is wanted, when Mesh data should be shared, but not the
|
||||
|
@ -32,6 +32,9 @@
|
||||
|
||||
/* 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"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@ -197,8 +200,10 @@ static int convert_NMeshToMesh(Mesh *mesh, C_NMesh *nmesh);
|
||||
void mesh_update(Mesh *mesh);
|
||||
PyObject *new_NMesh(Mesh *oldmesh);
|
||||
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);
|
||||
Material **nmesh_updateMaterials(C_NMesh *nmesh);
|
||||
Material **newMaterialList_fromPyList (PyObject *list);
|
||||
void mesh_update(Mesh *mesh);
|
||||
|
||||
|
||||
#endif /* EXPP_NMESH_H */
|
||||
|
@ -24,33 +24,74 @@
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten
|
||||
* Contributor(s): Michel Selten, Willian P. Germano
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_modules_h
|
||||
#define EXPP_modules_h
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <DNA_object_types.h>
|
||||
#include <DNA_camera_types.h>
|
||||
#include <DNA_lamp_types.h>
|
||||
#include <DNA_image_types.h>
|
||||
#include <DNA_curve_types.h>
|
||||
#include <DNA_effect_types.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global variables */
|
||||
/*****************************************************************************/
|
||||
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);
|
||||
|
||||
/* Object itself */
|
||||
PyObject * M_Object_Init (void);
|
||||
PyObject * M_ObjectCreatePyObject (struct Object *obj);
|
||||
int M_ObjectCheckPyObject (PyObject *py_obj);
|
||||
struct Object * M_ObjectFromPyObject (PyObject *py_obj);
|
||||
|
||||
/* NMesh Data */
|
||||
PyObject * M_NMesh_Init (void);
|
||||
PyObject * M_Camera_Init (void);
|
||||
PyObject * M_Lamp_Init (void);
|
||||
|
||||
/* Camera Data */
|
||||
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 * Lamp_createPyObject (struct Lamp *lamp);
|
||||
Lamp * Lamp_fromPyObject (PyObject *pyobj);
|
||||
int Lamp_checkPyObject (PyObject *pyobj);
|
||||
|
||||
/* Curve Data */
|
||||
PyObject * M_Curve_Init (void);
|
||||
PyObject * M_Image_Init (void);
|
||||
PyObject * M_Window_Init (void);
|
||||
PyObject * M_Draw_Init (void);
|
||||
PyObject * M_BGL_Init (void);
|
||||
PyObject * M_Text_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_Image_Init (void);
|
||||
PyObject * M_Draw_Init (void);
|
||||
PyObject * M_BGL_Init (void);
|
||||
PyObject * M_Text_Init (void);
|
||||
|
||||
#endif /* EXPP_modules_h */
|
||||
|
Loading…
Reference in New Issue
Block a user