Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Hughes <khughes@pacific.edu>2005-10-04 19:17:27 +0400
committerKen Hughes <khughes@pacific.edu>2005-10-04 19:17:27 +0400
commitac668ea561bfc70e37079d9f0bf19c60803daa64 (patch)
tree66c02e3e3e720869657b51c2e3a42fb0471ebb14 /source/blender/python/api2_2x
parent772459f15c054ae88c06da6209871f6749e8040a (diff)
Added Mesh.New() method; can now create new meshes within the module
Changed Object.link() to allow link objects with both BPython-type meshes Changed Object.getData() to allow retrieving both types of BPython-type meshes Added new mesh types to Types module
Diffstat (limited to 'source/blender/python/api2_2x')
-rw-r--r--source/blender/python/api2_2x/Mesh.c55
-rw-r--r--source/blender/python/api2_2x/Mesh.h1
-rw-r--r--source/blender/python/api2_2x/NMesh.c2
-rw-r--r--source/blender/python/api2_2x/NMesh.h2
-rw-r--r--source/blender/python/api2_2x/Object.c32
-rw-r--r--source/blender/python/api2_2x/Types.c15
-rw-r--r--source/blender/python/api2_2x/Types.h1
-rw-r--r--source/blender/python/api2_2x/doc/Mesh.py9
-rw-r--r--source/blender/python/api2_2x/doc/Object.py19
-rw-r--r--source/blender/python/api2_2x/doc/Types.py16
10 files changed, 130 insertions, 22 deletions
diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c
index 8e76864b78f..336a4c87de6 100644
--- a/source/blender/python/api2_2x/Mesh.c
+++ b/source/blender/python/api2_2x/Mesh.c
@@ -2878,9 +2878,11 @@ static PyObject *Mesh_calcNormals( BPy_Mesh * self )
static PyObject *Mesh_vertexShade( BPy_Mesh * self )
{
Base *base = FIRSTBASE;
+
if( G.obedit )
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
"can't shade vertices while in edit mode" );
+
while( base ) {
if( base->object->type == OB_MESH &&
base->object->data == self->mesh ) {
@@ -3368,6 +3370,10 @@ PyTypeObject Mesh_Type = {
NULL
};
+/*
+ * get one or all mesh data objects
+ */
+
static PyObject *M_Mesh_Get( PyObject * self, PyObject * args )
{
char *name = NULL;
@@ -3412,6 +3418,45 @@ static PyObject *M_Mesh_Get( PyObject * self, PyObject * args )
}
}
+/*
+ * create a new mesh data object
+ */
+
+static PyObject *M_Mesh_New( PyObject * self, PyObject * args )
+{
+ char *name = "Mesh";
+ PyObject *ret = NULL;
+ Mesh *mesh;
+ BPy_Mesh *obj;
+ char buf[21];
+
+ if( !PyArg_ParseTuple( args, "|s", &name ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected nothing or a string as argument" );
+
+ obj = (BPy_Mesh *)PyObject_NEW( BPy_Mesh, &Mesh_Type );
+
+ if( !obj )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "PyObject_New() failed" );
+
+ mesh = add_mesh(); /* doesn't return NULL now, but might someday */
+
+ if( !mesh ) {
+ Py_DECREF ( obj );
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "FATAL: could not create mesh object" );
+ }
+ mesh->id.us = 0;
+ G.totmesh++;
+
+ PyOS_snprintf( buf, sizeof( buf ), "%s", name );
+ rename_id( &mesh->id, buf );
+
+ obj->mesh = mesh;
+ return (PyObject *)obj;
+}
+
#define SUBDIVIDE_EXPERIMENT
#undef SUBDIVIDE_EXPERIMENT
@@ -3466,6 +3511,8 @@ static PyObject *M_Mesh_Subdivide( PyObject * self, PyObject * args )
#endif
static struct PyMethodDef M_Mesh_methods[] = {
+ {"New", (PyCFunction)M_Mesh_New, METH_VARARGS,
+ "Create a new mesh"},
{"Get", (PyCFunction)M_Mesh_Get, METH_VARARGS,
"Get a mesh by name"},
#ifdef SUBDIVIDE_EXPERIMENT
@@ -3524,3 +3571,11 @@ int Mesh_CheckPyObject( PyObject * pyobj )
return ( pyobj->ob_type == &Mesh_Type );
}
+Mesh *Mesh_FromPyObject( PyObject * pyobj )
+{
+ BPy_Mesh *blen_obj;
+
+ blen_obj = ( BPy_Mesh * ) pyobj;
+ return blen_obj->mesh;
+
+}
diff --git a/source/blender/python/api2_2x/Mesh.h b/source/blender/python/api2_2x/Mesh.h
index d9b1f68800a..4cd68e72f12 100644
--- a/source/blender/python/api2_2x/Mesh.h
+++ b/source/blender/python/api2_2x/Mesh.h
@@ -119,5 +119,6 @@ typedef struct {
PyObject *Mesh_Init( void );
PyObject *Mesh_CreatePyObject( Mesh * me );
int Mesh_CheckPyObject( PyObject * pyobj );
+Mesh *Mesh_FromPyObject( PyObject * pyobj );
#endif /* EXPP_MESH_H */
diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c
index ec1badfef14..f6ed4fd5bbd 100644
--- a/source/blender/python/api2_2x/NMesh.c
+++ b/source/blender/python/api2_2x/NMesh.c
@@ -3374,7 +3374,7 @@ int NMesh_CheckPyObject( PyObject * pyobj )
return ( pyobj->ob_type == &NMesh_Type );
}
-Mesh *Mesh_FromPyObject( PyObject * pyobj, Object * ob )
+Mesh *NMesh_FromPyObject( PyObject * pyobj, Object * ob )
{
if( pyobj->ob_type == &NMesh_Type ) {
Mesh *mesh;
diff --git a/source/blender/python/api2_2x/NMesh.h b/source/blender/python/api2_2x/NMesh.h
index 50d3bcbf3c0..57d029b5d26 100644
--- a/source/blender/python/api2_2x/NMesh.h
+++ b/source/blender/python/api2_2x/NMesh.h
@@ -139,7 +139,7 @@ extern void test_object_materials( ID * id ); /* declared in BKE_material.h */
PyObject *NMesh_Init( void );
PyObject *NMesh_CreatePyObject( Mesh * me, Object * ob );
-Mesh *Mesh_FromPyObject( PyObject * pyobj, Object * ob );
+Mesh *NMesh_FromPyObject( PyObject * pyobj, Object * ob );
int NMesh_CheckPyObject( PyObject * pyobj );
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c
index 6ed844a698a..888cab2bc92 100644
--- a/source/blender/python/api2_2x/Object.c
+++ b/source/blender/python/api2_2x/Object.c
@@ -72,6 +72,7 @@ struct rctf;
#include "blendef.h"
#include "Scene.h"
#include "Mathutils.h"
+#include "Mesh.h"
#include "NMesh.h"
#include "Curve.h"
#include "Ipo.h"
@@ -280,7 +281,7 @@ hierarchy (faster)"},
mode\n\t2: Keep object transform\nfast\n\t>0: Don't update scene \
hierarchy (faster)"},
{"getData", ( PyCFunction ) Object_getData, METH_VARARGS | METH_KEYWORDS,
- "(name_only = 0) - Returns the datablock object containing the object's \
+ "(name_only = 0, mesh = 0) - Returns the datablock object containing the object's \
data, e.g. Mesh.\n\
If 'name_only' is nonzero or True, only the name of the datablock is returned"},
{"getDeltaLocation", ( PyCFunction ) Object_getDeltaLocation,
@@ -989,9 +990,10 @@ static PyObject *Object_getData( BPy_Object *self, PyObject *args, PyObject *kwd
PyObject *data_object;
Object *object = self->object;
int name_only = 0;
- static char *kwlist[] = {"name_only", NULL};
+ int mesh = 0; /* default mesh type = NMesh */
+ static char *kwlist[] = {"name_only", "mesh", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwd, "|i", kwlist, &name_only))
+ if (!PyArg_ParseTupleAndKeywords(args, kwd, "|ii", kwlist, &name_only, &mesh))
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected nothing or bool keyword 'name_only' as argument" );
@@ -1041,7 +1043,10 @@ static PyObject *Object_getData( BPy_Object *self, PyObject *args, PyObject *kwd
case ID_MA:
break;
case OB_MESH:
- data_object = NMesh_CreatePyObject( object->data, object );
+ if( !mesh ) /* get as NMesh (default) */
+ data_object = NMesh_CreatePyObject( object->data, object );
+ else /* else get as Mesh */
+ data_object = Mesh_CreatePyObject( object->data );
break;
case ID_OB:
data_object = Object_CreatePyObject( object->data );
@@ -1472,21 +1477,24 @@ static PyObject *Object_link( BPy_Object * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected an object as argument" ) );
}
+
if( Armature_CheckPyObject( py_data ) )
data = ( void * ) Armature_FromPyObject( py_data );
- if( Camera_CheckPyObject( py_data ) )
+ else if( Camera_CheckPyObject( py_data ) )
data = ( void * ) Camera_FromPyObject( py_data );
- if( Lamp_CheckPyObject( py_data ) )
+ else if( Lamp_CheckPyObject( py_data ) )
data = ( void * ) Lamp_FromPyObject( py_data );
- if( Curve_CheckPyObject( py_data ) )
+ else if( Curve_CheckPyObject( py_data ) )
data = ( void * ) Curve_FromPyObject( py_data );
- if( NMesh_CheckPyObject( py_data ) )
- data = ( void * ) Mesh_FromPyObject( py_data, self->object );
- if( Lattice_CheckPyObject( py_data ) )
+ else if( NMesh_CheckPyObject( py_data ) )
+ data = ( void * ) NMesh_FromPyObject( py_data, self->object );
+ else if( Mesh_CheckPyObject( py_data ) )
+ data = ( void * ) Mesh_FromPyObject( py_data );
+ else if( Lattice_CheckPyObject( py_data ) )
data = ( void * ) Lattice_FromPyObject( py_data );
- if( Metaball_CheckPyObject( py_data ) )
+ else if( Metaball_CheckPyObject( py_data ) )
data = ( void * ) Metaball_FromPyObject( py_data );
- if( Text3d_CheckPyObject( py_data ) )
+ else if( Text3d_CheckPyObject( py_data ) )
data = ( void * ) Text3d_FromPyObject( py_data );
/* have we set data to something good? */
diff --git a/source/blender/python/api2_2x/Types.c b/source/blender/python/api2_2x/Types.c
index f8b24468a14..1a770844e68 100644
--- a/source/blender/python/api2_2x/Types.c
+++ b/source/blender/python/api2_2x/Types.c
@@ -68,6 +68,12 @@ void types_InitAll( void )
NMFace_Type.ob_type = &PyType_Type;
NMVert_Type.ob_type = &PyType_Type;
NMesh_Type.ob_type = &PyType_Type;
+ Mesh_Type.ob_type = &PyType_Type;
+ MFace_Type.ob_type = &PyType_Type;
+ MVert_Type.ob_type = &PyType_Type;
+ MEdge_Type.ob_type = &PyType_Type;
+ MCol_Type.ob_type = &PyType_Type;
+ Mesh_Type.ob_type = &PyType_Type;
Object_Type.ob_type = &PyType_Type;
Particle_Type.ob_type = &PyType_Type;
RenderData_Type.ob_type = &PyType_Type;
@@ -117,6 +123,15 @@ PyObject *Types_Init( void )
( PyObject * ) &NMVert_Type );
PyDict_SetItemString( dict, "NMColType", ( PyObject * ) &NMCol_Type );
+ PyDict_SetItemString( dict, "MeshType", ( PyObject * ) &Mesh_Type );
+ PyDict_SetItemString( dict, "MFaceType",
+ ( PyObject * ) &MFace_Type );
+ PyDict_SetItemString( dict, "MEdgeType",
+ ( PyObject * ) &MEdge_Type );
+ PyDict_SetItemString( dict, "MVertType",
+ ( PyObject * ) &MVert_Type );
+ PyDict_SetItemString( dict, "MColType", ( PyObject * ) &MCol_Type );
+
PyDict_SetItemString( dict, "ArmatureType",
( PyObject * ) &Armature_Type );
PyDict_SetItemString( dict, "BoneType", ( PyObject * ) &Bone_Type );
diff --git a/source/blender/python/api2_2x/Types.h b/source/blender/python/api2_2x/Types.h
index ede21369fe0..d4ac545dbb2 100644
--- a/source/blender/python/api2_2x/Types.h
+++ b/source/blender/python/api2_2x/Types.h
@@ -45,6 +45,7 @@ extern PyTypeObject Image_Type, Ipo_Type, IpoCurve_Type;
extern PyTypeObject Lamp_Type, Lattice_Type;
extern PyTypeObject Material_Type, Metaball_Type, MTex_Type;
extern PyTypeObject NMFace_Type, NMVert_Type, NMCol_Type, NMesh_Type;
+extern PyTypeObject MFace_Type, MVert_Type, MEdge_Type, MCol_Type, Mesh_Type;
extern PyTypeObject Object_Type;
extern PyTypeObject Particle_Type;
extern PyTypeObject Scene_Type, RenderData_Type;
diff --git a/source/blender/python/api2_2x/doc/Mesh.py b/source/blender/python/api2_2x/doc/Mesh.py
index 8fe9c7fa444..69d557fe6d0 100644
--- a/source/blender/python/api2_2x/doc/Mesh.py
+++ b/source/blender/python/api2_2x/doc/Mesh.py
@@ -47,6 +47,15 @@ def Get(name=None):
If no parameter is given, it returns all the meshs in the current scene.
"""
+def New(name='Mesh'):
+ """
+ Create a new mesh data object called I{name}.
+ @type name: string
+ @param name: The name of the mesh data object.
+ @rtype: Mesh
+ @return: a new Blender mesh.
+ """
+
class MCol:
"""
The MCol object
diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py
index 57448428597..54a6114c509 100644
--- a/source/blender/python/api2_2x/doc/Object.py
+++ b/source/blender/python/api2_2x/doc/Object.py
@@ -4,8 +4,9 @@
The Blender.Object submodule
B{New}:
- - L{Object.getData} now accepts an optional bool keyword argument to
- define if the user wants the data object or just its name.
+ - L{Object.getData} now accepts two optional bool keyword argument to
+ define (1) if the user wants the data object or just its name
+ and (2) if a mesh object should use NMesh or Mesh.
- L{Object.clearScriptLinks} accepts a parameter now.
- Object attributes: renamed Layer to L{Layers<Object.Object.Layers>} and
added the easier L{layers<Object.Object.layers>}. The old form "Layer"
@@ -206,11 +207,19 @@ class Object:
other value, or no value at all will update the scene hierarchy.
"""
- def getData(name_only = False):
+ def getData(name_only=False, mesh=False):
"""
- Returns the Datablock object (Mesh, Lamp, Camera, etc.) linked to this Object. If the keyword parameter 'name_only' is True, only the Datablock name is returned as a string.
+ Returns the Datablock object (Mesh, Lamp, Camera, etc.) linked to this
+ Object. If the keyword parameter 'name_only' is True, only the Datablock
+ name is returned as a string. It the object is of type Mesh, then the
+ 'mesh' keyword can also be used; the data return is a Mesh object if
+ True, otherwise it is an NMesh object (the default).
@type name_only: bool
- @param name_only: This is a keyword parameter. if True (or nonzero), only the name of the data object is returned. The default value is False.
+ @param name_only: This is a keyword parameter. If True (or nonzero),
+ only the name of the data object is returned.
+ @type mesh: bool
+ @param mesh: This is a keyword parameter. If True (or nonzero),
+ a Mesh data object is returned.
@rtype: specific Object type or string
@return: Depends on the type of Datablock linked to the Object. If name_only is True, it returns a string.
"""
diff --git a/source/blender/python/api2_2x/doc/Types.py b/source/blender/python/api2_2x/doc/Types.py
index c8a2ebb87c0..145a26b20ab 100644
--- a/source/blender/python/api2_2x/doc/Types.py
+++ b/source/blender/python/api2_2x/doc/Types.py
@@ -31,7 +31,13 @@ Example::
@var NMFaceType: Blender NMFace. A mesh face, with one (a point), two (an edge),
three (a triangular face) or four (a quad face) vertices.
@var NMVertType: Blender NMVert. A mesh vertex.
-@var NMColType: Blender NMCol. A mesh rgba colour.
+@var NMColType: Blender NMCol. A mesh rgba color.
+@var MeshType: Blender Mesh. The mesh structure.
+@var MFaceType: Blender MFace. A mesh face, with
+ three (a triangular face) or four (a quad face) vertices.
+@var MEdgeType: Blender MEdge. A mesh edge, with two vertices
+@var MVertType: Blender MVert. A mesh vertex.
+@var MColType: Blender MCol. A mesh rgba color.
@var ArmatureType: Blender Armature. The "skeleton", for animating and deforming
objects.
@var BoneType: Blender Bone. Bones are, obviously, the "pieces" of an Armature.
@@ -42,13 +48,17 @@ objects.
@var ImageType: Blender Image.
@var LampType: Blender Lamp.
@var TextType: Blender Text.
+@var Text3dType: Blender Text3d.
@var MaterialType: Blender Material.
@var SceneType: A Blender Scene. Container of all other objects.
@var ButtonType: Blender Button. One of the Draw widgets.
-@var vectorType: Blender vector. Used in NMesh.
+@var vectorType: Blender vector. Used in NMesh, Mesh and elsewhere.
+@var matrix_Type: Blender matrix.
+@var quaternionType: Blender quaternion. Used in armatures.
+@var eulerType: Blender euler.
@var bufferType: Blender buffer. A contiguous piece of storage, used in BGL.
@var constantType: Blender constant. A constant dictionary.
@var rgbTupleType: Blender rgbTuple. A (red, green, blue) triplet.
@var TextureType: Blender Texture.
-@var MTexType: Blender MTex -- it links materials to a texture.
+@var MTexType: Blender MTex. Links materials to a texture.
"""