* Added submodule NMesh:
Partially implemented. Most of it comes from opy_nmesh.c, plus needed changes to integrate in into exppython. * Added helper submodule vector, needed by NMesh. * Minor changes in other files.
This commit is contained in:
@@ -338,7 +338,6 @@ static PyObject *Buffer_repr(PyObject *self)
|
||||
|
||||
/* BGL_Wrap defined in BGL.h */
|
||||
|
||||
/* Let's try to take away this ifndef: */
|
||||
/* #ifndef __APPLE__ */
|
||||
|
||||
BGL_Wrap(2, Accum, void, (GLenum, GLfloat))
|
||||
|
@@ -215,8 +215,10 @@ void initBlender (void)
|
||||
dict = PyModule_GetDict (module);
|
||||
g_blenderdict = dict;
|
||||
PyDict_SetItemString (dict, "Object", initObject());
|
||||
PyDict_SetItemString (dict, "NMesh", M_NMesh_Init());
|
||||
PyDict_SetItemString (dict, "Camera", M_Camera_Init());
|
||||
PyDict_SetItemString (dict, "Lamp", M_Lamp_Init());
|
||||
/* PyDict_SetItemString (dict, "Curve", M_Curve_Init());*/
|
||||
PyDict_SetItemString (dict, "Image", M_Image_Init());
|
||||
PyDict_SetItemString (dict, "Window", M_Window_Init());
|
||||
PyDict_SetItemString (dict, "Draw", M_Draw_Init());
|
||||
|
@@ -239,7 +239,7 @@ static PyObject *Camera_getDrawSize(C_Camera *self)
|
||||
"couldn't get Camera.drawSize attribute"));
|
||||
}
|
||||
|
||||
static PyObject *Camera_rename(C_Camera *self, PyObject *args)
|
||||
static PyObject *Camera_setName(C_Camera *self, PyObject *args)
|
||||
{
|
||||
char *name;
|
||||
char buf[21];
|
||||
@@ -500,7 +500,7 @@ static int CameraSetAttr (C_Camera *self, char *name, PyObject *value)
|
||||
|
||||
/* Now we just compare "name" with all possible C_Camera member variables */
|
||||
if (strcmp (name, "name") == 0)
|
||||
error = Camera_rename (self, valtuple);
|
||||
error = Camera_setName (self, valtuple);
|
||||
else if (strcmp (name, "type") == 0)
|
||||
error = Camera_setIntType (self, valtuple); /* special case */
|
||||
else if (strcmp (name, "mode") == 0)
|
||||
|
@@ -33,7 +33,6 @@
|
||||
#define EXPP_CAMERA_H
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_global.h>
|
||||
@@ -140,7 +139,7 @@ static PyObject *Camera_getLens(C_Camera *self);
|
||||
static PyObject *Camera_getClipStart(C_Camera *self);
|
||||
static PyObject *Camera_getClipEnd(C_Camera *self);
|
||||
static PyObject *Camera_getDrawSize(C_Camera *self);
|
||||
static PyObject *Camera_rename(C_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setName(C_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setType(C_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setIntType(C_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setMode(C_Camera *self, PyObject *args);
|
||||
@@ -170,7 +169,7 @@ static PyMethodDef C_Camera_methods[] = {
|
||||
"() - Return Camera clip end value"},
|
||||
{"getDrawSize", (PyCFunction)Camera_getDrawSize, METH_NOARGS,
|
||||
"() - Return Camera draw size value"},
|
||||
{"rename", (PyCFunction)Camera_rename, METH_VARARGS,
|
||||
{"setName", (PyCFunction)Camera_setName, METH_VARARGS,
|
||||
"(str) - Change Camera Data name"},
|
||||
{"setType", (PyCFunction)Camera_setType, METH_VARARGS,
|
||||
"(str) - Change Camera type, which can be 'persp' or 'ortho'"},
|
||||
@@ -190,11 +189,11 @@ static PyMethodDef C_Camera_methods[] = {
|
||||
/*****************************************************************************/
|
||||
/* Python Camera_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static void CameraDeAlloc (C_Camera *cam);
|
||||
static int CameraPrint (C_Camera *cam, FILE *fp, int flags);
|
||||
static int CameraSetAttr (C_Camera *cam, char *name, PyObject *v);
|
||||
static PyObject *CameraGetAttr (C_Camera *cam, char *name);
|
||||
static PyObject *CameraRepr (C_Camera *cam);
|
||||
static void CameraDeAlloc (C_Camera *self);
|
||||
static int CameraPrint (C_Camera *self, FILE *fp, int flags);
|
||||
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 structure definition: */
|
||||
|
@@ -178,7 +178,7 @@ static PyObject *Image_getFilename(C_Image *self)
|
||||
"couldn't get Image.filename attribute"));
|
||||
}
|
||||
|
||||
static PyObject *Image_rename(C_Image *self, PyObject *args)
|
||||
static PyObject *Image_setName(C_Image *self, PyObject *args)
|
||||
{
|
||||
char *name;
|
||||
char buf[21];
|
||||
@@ -297,7 +297,7 @@ static int ImageSetAttr (C_Image *self, char *name, PyObject *value)
|
||||
"ImageSetAttr: couldn't create PyTuple");
|
||||
|
||||
if (strcmp (name, "name") == 0)
|
||||
error = Image_rename (self, valtuple);
|
||||
error = Image_setName (self, valtuple);
|
||||
else if (strcmp (name, "xrep") == 0)
|
||||
error = Image_setXRep (self, valtuple);
|
||||
else if (strcmp (name, "yrep") == 0)
|
||||
|
@@ -105,7 +105,7 @@ typedef struct {
|
||||
/*****************************************************************************/
|
||||
static PyObject *Image_getName(C_Image *self);
|
||||
static PyObject *Image_getFilename(C_Image *self);
|
||||
static PyObject *Image_rename(C_Image *self, PyObject *args);
|
||||
static PyObject *Image_setName(C_Image *self, PyObject *args);
|
||||
static PyObject *Image_setXRep(C_Image *self, PyObject *args);
|
||||
static PyObject *Image_setYRep(C_Image *self, PyObject *args);
|
||||
|
||||
@@ -118,7 +118,7 @@ static PyMethodDef C_Image_methods[] = {
|
||||
"() - Return Image Data name"},
|
||||
{"getFilename", (PyCFunction)Image_getFilename, METH_VARARGS,
|
||||
"() - Return Image Data filename"},
|
||||
{"rename", (PyCFunction)Image_rename, METH_VARARGS,
|
||||
{"setName", (PyCFunction)Image_setName, METH_VARARGS,
|
||||
"(str) - Change Image Data name"},
|
||||
{"setXRep", (PyCFunction)Image_setXRep, METH_VARARGS,
|
||||
"(int) - Change Image Data x repetition value"},
|
||||
|
@@ -341,7 +341,7 @@ static PyObject *Lamp_getQuad2(C_Lamp *self)
|
||||
"couldn't get Lamp.quad2 attribute"));
|
||||
}
|
||||
|
||||
static PyObject *Lamp_rename(C_Lamp *self, PyObject *args)
|
||||
static PyObject *Lamp_setName(C_Lamp *self, PyObject *args)
|
||||
{
|
||||
char *name;
|
||||
char buf[21];
|
||||
@@ -831,7 +831,7 @@ static int LampSetAttr (C_Lamp *self, char *name, PyObject *value)
|
||||
"LampSetAttr: couldn't create tuple");
|
||||
|
||||
if (strcmp (name, "name") == 0)
|
||||
error = Lamp_rename (self, valtuple);
|
||||
error = Lamp_setName (self, valtuple);
|
||||
else if (strcmp (name, "type") == 0)
|
||||
error = Lamp_setIntType (self, valtuple); /* special case */
|
||||
else if (strcmp (name, "mode") == 0)
|
||||
|
@@ -188,7 +188,7 @@ static PyObject *Lamp_getSoftness(C_Lamp *self);
|
||||
static PyObject *Lamp_getHaloInt(C_Lamp *self);
|
||||
static PyObject *Lamp_getQuad1(C_Lamp *self);
|
||||
static PyObject *Lamp_getQuad2(C_Lamp *self);
|
||||
static PyObject *Lamp_rename(C_Lamp *self, PyObject *args);
|
||||
static PyObject *Lamp_setName(C_Lamp *self, PyObject *args);
|
||||
static PyObject *Lamp_setType(C_Lamp *self, PyObject *args);
|
||||
static PyObject *Lamp_setIntType(C_Lamp *self, PyObject *args);
|
||||
static PyObject *Lamp_setMode(C_Lamp *self, PyObject *args);
|
||||
@@ -250,7 +250,7 @@ static PyMethodDef C_Lamp_methods[] = {
|
||||
"() - return light intensity value #1 for a Quad Lamp"},
|
||||
{"getQuad2", (PyCFunction)Lamp_getQuad2, METH_NOARGS,
|
||||
"() - return light intensity value #2 for a Quad Lamp"},
|
||||
{"rename", (PyCFunction)Lamp_rename, METH_VARARGS,
|
||||
{"setName", (PyCFunction)Lamp_setName, METH_VARARGS,
|
||||
"(str) - rename Lamp"},
|
||||
{"setType", (PyCFunction)Lamp_setType, METH_VARARGS,
|
||||
"(str) - change Lamp type, which can be 'persp' or 'ortho'"},
|
||||
|
1584
source/blender/python/api2_2x/NMesh.c
Normal file
1584
source/blender/python/api2_2x/NMesh.c
Normal file
File diff suppressed because it is too large
Load Diff
204
source/blender/python/api2_2x/NMesh.h
Normal file
204
source/blender/python/api2_2x/NMesh.h
Normal file
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano.
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* Most of this file comes from opy_nmesh.[ch] in the old bpython dir */
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
#include "BIF_editmesh.h" /* vertexnormals_mesh() */
|
||||
#include "BDR_editface.h" /* make_tfaces */
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_screen.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BIF_space.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "mydevice.h"
|
||||
|
||||
#include "gen_utils.h"
|
||||
#include "vector.h"
|
||||
#include "constant.h"
|
||||
|
||||
/* EXPP PyType Objects */
|
||||
|
||||
PyTypeObject NMesh_Type;
|
||||
PyTypeObject NMFace_Type;
|
||||
PyTypeObject NMVert_Type;
|
||||
PyTypeObject NMCol_Type;
|
||||
|
||||
/* Globals */
|
||||
|
||||
static PyObject *g_nmeshmodule = NULL;
|
||||
|
||||
/* Type checking for EXPP PyTypes */
|
||||
|
||||
#define C_NMesh_Check(v) ((v)->ob_type == &NMesh_Type)
|
||||
#define C_NMFace_Check(v) ((v)->ob_type == &NMFace_Type)
|
||||
#define C_NMVert_Check(v) ((v)->ob_type == &NMVert_Type)
|
||||
#define C_NMCol_Check(v) ((v)->ob_type == &NMCol_Type)
|
||||
|
||||
static char M_NMesh_Col_doc[]=
|
||||
"([r, g, b, a]) - Get a new mesh color\n\n\
|
||||
[r=255, g=255, b=255, a=255] Specify the color components";
|
||||
|
||||
static char M_NMesh_Face_doc[] =
|
||||
"(vertexlist = None) - Get a new face, and pass optional vertex list";
|
||||
|
||||
static char NMFace_append_doc[] =
|
||||
"(vert) - appends Vertex 'vert' to face vertex list";
|
||||
|
||||
static char M_NMesh_Vert_doc[] =
|
||||
"([x, y, z]) - Get a new vertice\n\n\
|
||||
[x, y, z] Specify new coordinates";
|
||||
|
||||
static char NMesh_getSelectedFaces_doc[] =
|
||||
"(flag = None) - returns list of selected Faces\n\
|
||||
If flag = 1, return indices instead";
|
||||
|
||||
static char NMesh_getActiveFace_doc[] =
|
||||
"returns the index of the active face ";
|
||||
|
||||
static char NMesh_hasVertexUV_doc[] =
|
||||
"(flag = None) - returns 1 if Mesh has per vertex UVs ('Sticky')\n\
|
||||
The optional argument sets the Sticky flag";
|
||||
|
||||
static char NMesh_hasFaceUV_doc[] =
|
||||
"(flag = None) - returns 1 if Mesh has textured faces\n\
|
||||
The optional argument sets the textured faces flag";
|
||||
|
||||
static char NMesh_hasVertexColours_doc[] =
|
||||
"(flag = None) - returns 1 if Mesh has vertex colours.\n\
|
||||
The optional argument sets the vertex colour flag";
|
||||
|
||||
static char NMesh_update_doc[] = "updates the Mesh";
|
||||
/*
|
||||
static char NMesh_asMesh_doc[] = "returns free Mesh datablock object from NMesh";
|
||||
|
||||
static char NMesh_link_doc[] = "(object) - Links NMesh data with Object 'object'";
|
||||
*/
|
||||
static char M_NMesh_New_doc[] =
|
||||
"() - returns a new, empty NMesh mesh object\n";
|
||||
|
||||
static char M_NMesh_GetRaw_doc[] =
|
||||
"([name]) - Get a raw mesh from Blender\n\n\
|
||||
[name] Name of the mesh to be returned\n\n\
|
||||
If name is not specified a new empty mesh is\n\
|
||||
returned, otherwise Blender returns an existing\n\
|
||||
mesh.";
|
||||
|
||||
static char M_NMesh_GetRawFromObject_doc[] =
|
||||
"(name) - Get the raw mesh used by a Blender object\n\n\
|
||||
(name) Name of the object to get the mesh from\n\n\
|
||||
This returns the mesh as used by the object, which\n\
|
||||
means it contains all deformations and modifications.";
|
||||
|
||||
static char M_NMesh_PutRaw_doc[] =
|
||||
"(mesh, [name, renormal]) - Return a raw mesh to Blender\n\n\
|
||||
(mesh) The NMesh object to store\n\
|
||||
[name] The mesh to replace\n\
|
||||
[renormal=1] Flag to control vertex normal recalculation\n\n\
|
||||
If the name of a mesh to replace is not given a new\n\
|
||||
object is created and returned.";
|
||||
|
||||
/* the color, vertex, face and mesh types below have their own variables
|
||||
* because they don't need to be linked to real Blender data -- e.g.: they
|
||||
* can be created with .New() methods */
|
||||
|
||||
/* Typedefs for the new types */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned char r, g, b, a;
|
||||
|
||||
} C_NMCol; /* an NMesh color: [r,g,b,a] */
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
float co[3];
|
||||
float no[3];
|
||||
float uvco[3];
|
||||
int index;
|
||||
|
||||
} C_NMVert; /* an NMesh vertex */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *v;
|
||||
PyObject *uv;
|
||||
PyObject *col;
|
||||
short mode;
|
||||
short flag;
|
||||
unsigned char transp;
|
||||
PyObject *image; /* Image; was DataBlock *tpage */
|
||||
char mat_nr, smooth;
|
||||
|
||||
} C_NMFace; /* an NMesh face */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Mesh *mesh;
|
||||
PyObject *name;
|
||||
PyObject *materials;
|
||||
PyObject *verts;
|
||||
PyObject *faces;
|
||||
int sel_face; /*@ XXX remove */
|
||||
char flags;
|
||||
|
||||
#define NMESH_HASMCOL 1<<0
|
||||
#define NMESH_HASVERTUV 1<<1
|
||||
#define NMESH_HASFACEUV 1<<2
|
||||
|
||||
} C_NMesh;
|
||||
|
||||
/* PROTOS */
|
||||
extern void test_object_materials(ID *id); /* declared in BKE_material.h */
|
||||
static int unlink_existingMeshData(Mesh *mesh);
|
||||
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);
|
@@ -258,7 +258,7 @@ static PyObject *Text_getNLines(C_Text *self)
|
||||
"couldn't get Text.nlines attribute");
|
||||
}
|
||||
|
||||
static PyObject *Text_rename(C_Text *self, PyObject *args)
|
||||
static PyObject *Text_setName(C_Text *self, PyObject *args)
|
||||
{
|
||||
char *name;
|
||||
char buf[21];
|
||||
@@ -426,7 +426,7 @@ static int TextSetAttr (C_Text *self, char *name, PyObject *value)
|
||||
"TextSetAttr: couldn't create PyTuple");
|
||||
|
||||
if (strcmp (name, "name") == 0)
|
||||
error = Text_rename (self, valtuple);
|
||||
error = Text_setName (self, valtuple);
|
||||
else { /* Error: no such member in the Text Data structure */
|
||||
Py_DECREF(value);
|
||||
Py_DECREF(valtuple);
|
||||
|
@@ -109,7 +109,7 @@ typedef struct {
|
||||
static PyObject *Text_getName(C_Text *self);
|
||||
static PyObject *Text_getFilename(C_Text *self);
|
||||
static PyObject *Text_getNLines(C_Text *self);
|
||||
static PyObject *Text_rename(C_Text *self, PyObject *args);
|
||||
static PyObject *Text_setName(C_Text *self, PyObject *args);
|
||||
static PyObject *Text_clear(C_Text *self, PyObject *args);
|
||||
static PyObject *Text_write(C_Text *self, PyObject *args);
|
||||
static PyObject *Text_set(C_Text *self, PyObject *args);
|
||||
@@ -126,7 +126,7 @@ static PyMethodDef C_Text_methods[] = {
|
||||
"() - Return Text Object filename"},
|
||||
{"getNLines", (PyCFunction)Text_getNLines, METH_VARARGS,
|
||||
"() - Return number of lines in text buffer"},
|
||||
{"rename", (PyCFunction)Text_rename, METH_VARARGS,
|
||||
{"setName", (PyCFunction)Text_setName, METH_VARARGS,
|
||||
"(str) - Change Text Object name"},
|
||||
{"clear", (PyCFunction)Text_clear, METH_VARARGS,
|
||||
"() - Clear Text buffer"},
|
||||
|
@@ -88,13 +88,13 @@ PyTypeObject constant_Type =
|
||||
/*****************************************************************************/
|
||||
static PyObject *new_const(void);
|
||||
|
||||
PyObject *constant_New(void) /* can't be static, we call it in other files */
|
||||
PyObject *M_constant_New(void) /* can't be static, we call it in other files */
|
||||
{
|
||||
return new_const();
|
||||
}
|
||||
|
||||
static PyObject *new_const(void)
|
||||
{ /* ... but this function needs to be static */
|
||||
{ /* this is the static one */
|
||||
C_constant *constant;
|
||||
|
||||
printf ("In constant_New()\n");
|
||||
|
@@ -43,7 +43,7 @@
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the constant module. */
|
||||
/*****************************************************************************/
|
||||
PyObject *constant_New (void);
|
||||
PyObject *M_constant_New (void);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_constant structure definition: */
|
||||
|
@@ -24,20 +24,23 @@
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten
|
||||
* Contributor(s): Michel Selten, Willian P. Germano
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <Python.h>
|
||||
#include "gen_utils.h"
|
||||
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_main.h>
|
||||
#include <DNA_ID.h>
|
||||
#include <DNA_object_types.h>
|
||||
#include <DNA_scriptlink_types.h>
|
||||
/*****************************************************************************/
|
||||
/* Description: This function clamps an int to the given interval */
|
||||
/* [min, max]. */
|
||||
/*****************************************************************************/
|
||||
int EXPP_ClampInt (int value, int min, int max)
|
||||
{
|
||||
if (value < min) return min;
|
||||
else if (value > max) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: This function clamps a float to the given interval */
|
||||
@@ -68,6 +71,22 @@ char * GetIdName (ID *id)
|
||||
return ((id->name)+2);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: This function returns the ID of the object with given name */
|
||||
/* from a given list. */
|
||||
/*****************************************************************************/
|
||||
ID *GetIdFromList(ListBase *list, char *name)
|
||||
{
|
||||
ID *id = list->first;
|
||||
|
||||
while (id) {
|
||||
if(strcmp(name, id->name+2) == 0) break;
|
||||
id= id->next;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: These functions set an internal string with the given type */
|
||||
/* and error_msg arguments. */
|
||||
@@ -149,3 +168,24 @@ struct Object * GetObjectByName (char * name)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Checks whether all objects in a PySequence are of a same */
|
||||
/* given type. Returns 0 if not, 1 on success. */
|
||||
/*****************************************************************************/
|
||||
int EXPP_check_sequence_consistency(PyObject *seq, PyTypeObject *against)
|
||||
{
|
||||
PyObject *ob;
|
||||
int len = PySequence_Length(seq);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
ob = PySequence_GetItem(seq, i);
|
||||
if (ob->ob_type != against) {
|
||||
Py_DECREF(ob);
|
||||
return 0;
|
||||
}
|
||||
Py_DECREF(ob);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@@ -24,27 +24,47 @@
|
||||
*
|
||||
* 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_gen_utils_h
|
||||
#define EXPP_gen_utils_h
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <Python.h>
|
||||
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_main.h>
|
||||
#include <DNA_ID.h>
|
||||
#include <DNA_object_types.h>
|
||||
#include <DNA_scriptlink_types.h>
|
||||
#include <DNA_listBase.h>
|
||||
|
||||
int StringEqual (char * string1, char * string2);
|
||||
char * GetIdName (ID *id);
|
||||
ID *GetIdFromList(ListBase *list, char *name);
|
||||
|
||||
PyObject * PythonReturnErrorObject (PyObject * type, char * error_msg);
|
||||
PyObject * PythonIncRef (PyObject *object);
|
||||
PyObject * EXPP_incr_ret (PyObject *object);
|
||||
|
||||
char * event_to_name (short event);
|
||||
|
||||
float EXPP_ClampFloat (float value, float min, float max);
|
||||
int EXPP_ClampInt (int value, int min, int max);
|
||||
|
||||
int EXPP_ReturnIntError (PyObject *type, char *error_msg);
|
||||
PyObject *EXPP_ReturnPyObjError (PyObject * type, char * error_msg);
|
||||
|
||||
int EXPP_check_sequence_consistency (PyObject *seq, PyTypeObject *against);
|
||||
|
||||
/* The following functions may need to be moved to the respective BKE or */
|
||||
/* DNA modules. */
|
||||
|
||||
struct Object * GetObjectByName (char * name);
|
||||
|
||||
|
||||
#endif /* EXPP_gen_utils_h */
|
||||
|
@@ -43,8 +43,10 @@ extern PyObject *g_blenderdict;
|
||||
void initBlender (void);
|
||||
PyObject *initObject (void);
|
||||
PyObject *ObjectCreatePyObject (struct Object *obj);
|
||||
PyObject *M_NMesh_Init (void);
|
||||
PyObject *M_Camera_Init (void);
|
||||
PyObject *M_Lamp_Init (void);
|
||||
/*PyObject *M_Curve_Init (void);*/
|
||||
PyObject *M_Image_Init (void);
|
||||
PyObject *M_Window_Init (void);
|
||||
PyObject *M_Draw_Init (void);
|
||||
|
222
source/blender/python/api2_2x/vector.c
Normal file
222
source/blender/python/api2_2x/vector.c
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* This file is the old bpython opy_vector.c with minor modifications */
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
/*****************************/
|
||||
/* Vector Python Object */
|
||||
/*****************************/
|
||||
#define VectorObject_Check(v) ((v)->ob_type == &Vector_Type)
|
||||
|
||||
static void Vector_dealloc(VectorObject *self)
|
||||
{
|
||||
PyMem_DEL(self);
|
||||
}
|
||||
|
||||
static PyObject *Vector_getattr(VectorObject *self, char *name)
|
||||
{
|
||||
if (self->size==3 && ELEM3(name[0], 'x', 'y', 'z') && name[1]==0)
|
||||
return PyFloat_FromDouble(self->vec[ name[0]-'x' ]);
|
||||
|
||||
return EXPP_ReturnPyObjError(PyExc_AttributeError, "attribute not found");
|
||||
}
|
||||
|
||||
static int Vector_setattr(VectorObject *self, char *name, PyObject *v)
|
||||
{
|
||||
float val;
|
||||
|
||||
if (!PyArg_Parse(v, "f", &val))
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"expected float argument");
|
||||
|
||||
if (self->size==3 && ELEM3(name[0], 'x', 'y', 'z') && name[1]==0)
|
||||
self->vec[ name[0]-'x' ]= val;
|
||||
else
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Vectors Sequence methods */
|
||||
|
||||
static int Vector_len(VectorObject *self)
|
||||
{
|
||||
return self->size;
|
||||
}
|
||||
|
||||
static PyObject *Vector_item(VectorObject *self, int i)
|
||||
{
|
||||
if (i < 0 || i >= self->size)
|
||||
return EXPP_ReturnPyObjError (PyExc_IndexError,
|
||||
"array index out of range");
|
||||
|
||||
return Py_BuildValue("f", self->vec[i]);
|
||||
}
|
||||
|
||||
static PyObject *Vector_slice(VectorObject *self, int begin, int end)
|
||||
{
|
||||
PyObject *list;
|
||||
int count;
|
||||
|
||||
if (begin < 0) begin= 0;
|
||||
if (end > self->size) end= self->size;
|
||||
if (begin > end) begin= end;
|
||||
|
||||
list= PyList_New(end-begin);
|
||||
|
||||
for (count = begin; count < end; count++)
|
||||
PyList_SetItem(list, count-begin, PyFloat_FromDouble(self->vec[count]));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static int Vector_ass_item(VectorObject *self, int i, PyObject *ob)
|
||||
{
|
||||
if (i < 0 || i >= self->size)
|
||||
return EXPP_ReturnIntError(PyExc_IndexError,
|
||||
"array assignment index out of range");
|
||||
|
||||
if (!PyNumber_Check(ob))
|
||||
return EXPP_ReturnIntError(PyExc_IndexError,
|
||||
"vector member must be a number");
|
||||
|
||||
self->vec[i]= PyFloat_AsDouble(ob);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *seq)
|
||||
{
|
||||
int count;
|
||||
|
||||
if (begin < 0) begin= 0;
|
||||
if (end > self->size) end= self->size;
|
||||
if (begin > end) begin= end;
|
||||
|
||||
if (!PySequence_Check(seq))
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"illegal argument type for built-in operation");
|
||||
|
||||
if (PySequence_Length(seq) != (end - begin))
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"size mismatch in slice assignment");
|
||||
|
||||
for (count = begin; count < end; count++) {
|
||||
PyObject *ob = PySequence_GetItem(seq, count);
|
||||
|
||||
if (!PyArg_Parse(ob, "f", &self->vec[count])) {
|
||||
Py_DECREF(ob);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py_DECREF(ob);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *EXPP_tuple_repr(PyObject *self, int size)
|
||||
{
|
||||
PyObject *repr, *comma, *item;
|
||||
int i;
|
||||
|
||||
/*@ note: a value must be built because the list is decrefed!
|
||||
* otherwise we have nirvana pointers inside python.. */
|
||||
|
||||
repr = PyString_FromString("(");
|
||||
if (!repr) return 0;
|
||||
|
||||
item = PySequence_GetItem(self, 0);
|
||||
PyString_ConcatAndDel(&repr, PyObject_Repr(item));
|
||||
Py_DECREF(item);
|
||||
|
||||
comma = PyString_FromString(", ");
|
||||
|
||||
for (i = 1; i < size; i++) {
|
||||
PyString_Concat(&repr, comma);
|
||||
item = PySequence_GetItem(self, i);
|
||||
PyString_ConcatAndDel(&repr, PyObject_Repr(item));
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
PyString_ConcatAndDel(&repr, PyString_FromString(")"));
|
||||
Py_DECREF(comma);
|
||||
|
||||
return repr;
|
||||
|
||||
}
|
||||
|
||||
static PyObject *Vector_repr (VectorObject *self)
|
||||
{
|
||||
return EXPP_tuple_repr((PyObject *) self, self->size);
|
||||
}
|
||||
|
||||
static PySequenceMethods Vector_SeqMethods =
|
||||
{
|
||||
(inquiry) Vector_len, /* sq_length */
|
||||
(binaryfunc) 0, /* sq_concat */
|
||||
(intargfunc) 0, /* sq_repeat */
|
||||
(intargfunc) Vector_item, /* sq_item */
|
||||
(intintargfunc) Vector_slice, /* sq_slice */
|
||||
(intobjargproc) Vector_ass_item, /* sq_ass_item */
|
||||
(intintobjargproc) Vector_ass_slice, /* sq_ass_slice */
|
||||
};
|
||||
|
||||
PyTypeObject Vector_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"Vector", /*tp_name*/
|
||||
sizeof(VectorObject), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor) Vector_dealloc, /*tp_dealloc*/
|
||||
(printfunc) 0, /*tp_print*/
|
||||
(getattrfunc) Vector_getattr, /*tp_getattr*/
|
||||
(setattrfunc) Vector_setattr, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
(reprfunc) Vector_repr, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
&Vector_SeqMethods, /*tp_as_sequence*/
|
||||
};
|
||||
|
||||
PyObject *newVectorObject(float *vec, int size)
|
||||
{
|
||||
VectorObject *self;
|
||||
|
||||
self= PyObject_NEW(VectorObject, &Vector_Type);
|
||||
|
||||
self->vec= vec;
|
||||
self->size= size;
|
||||
|
||||
return (PyObject*) self;
|
||||
}
|
78
source/blender/python/api2_2x/vector.h
Normal file
78
source/blender/python/api2_2x/vector.h
Normal file
@@ -0,0 +1,78 @@
|
||||
|
||||
|
||||
/* Matrix and vector objects in Python */
|
||||
|
||||
/* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*
|
||||
*/
|
||||
#ifndef EXPP_vector_h
|
||||
#define EXPP_vector_h
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
#include "BKE_utildefines.h"
|
||||
|
||||
#include "gen_utils.h"
|
||||
#include "vector.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
/*****************************/
|
||||
/* Matrix Python Object */
|
||||
/*****************************/
|
||||
/* temporar hack for typecasts */
|
||||
|
||||
typedef float (*Matrix4Ptr)[4];
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
float *vec;
|
||||
int size;
|
||||
|
||||
} VectorObject;
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
PyObject *rows[4];
|
||||
Matrix4Ptr mat;
|
||||
|
||||
} MatrixObject;
|
||||
|
||||
|
||||
/* PROTOS */
|
||||
|
||||
PyObject *newVectorObject(float *vec, int size);
|
||||
PyObject *newMatrixObject(Matrix4Ptr mat);
|
||||
void init_py_matrix(void);
|
||||
|
||||
#endif /* EXPP_vector_h */
|
Reference in New Issue
Block a user