Newer
Older
*
* ***** 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): Jacques Guignot
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* \file World.c
* \ingroup scripts
* \brief Blender.World Module and World Data PyObject implementation.
*
* Note: Parameters between "<" and ">" are optional. But if one of them is
* given, all preceding ones must be given, too. Of course, this only relates
* to the Python functions and methods described here and only inside Python
* code. [ This will go to another file later, probably the main exppython
* doc file]. XXX Better: put optional args with their default value:
* (self, name = "MyName")
*/
#include <BKE_main.h>
#include <BKE_global.h>
#include <BKE_object.h>
#include <BKE_library.h>
#include <BLI_blenlib.h>
#include <DNA_scene_types.h> /* for G.scene */
#include "Ipo.h"
#include "constant.h"
#include "gen_utils.h"
/*****************************************************************************/
/* Python BPy_World methods declarations: */
/*****************************************************************************/
static PyObject *World_getRange( BPy_World * self );
static PyObject *World_setRange( BPy_World * self, PyObject * args );
static PyObject *World_getIpo( BPy_World * self );
static PyObject *World_setIpo( BPy_World * self, PyObject * args );
static PyObject *World_clearIpo( BPy_World * self );
static PyObject *World_getName( BPy_World * self );
static PyObject *World_setName( BPy_World * self, PyObject * args );
static PyObject *World_getSkytype( BPy_World * self );
static PyObject *World_setSkytype( BPy_World * self, PyObject * args );
static PyObject *World_getMistype( BPy_World * self );
static PyObject *World_setMistype( BPy_World * self, PyObject * args );
static PyObject *World_getHor( BPy_World * self );
static PyObject *World_setHor( BPy_World * self, PyObject * args );
static PyObject *World_getZen( BPy_World * self );
static PyObject *World_setZen( BPy_World * self, PyObject * args );
static PyObject *World_getAmb( BPy_World * self );
static PyObject *World_setAmb( BPy_World * self, PyObject * args );
static PyObject *World_getStar( BPy_World * self );
static PyObject *World_setStar( BPy_World * self, PyObject * args );
static PyObject *World_getMist( BPy_World * self );
static PyObject *World_setMist( BPy_World * self, PyObject * args );
static PyObject *World_getScriptLinks( BPy_World * self, PyObject * args );
static PyObject *World_addScriptLink( BPy_World * self, PyObject * args );
static PyObject *World_clearScriptLinks( BPy_World * self );
static PyObject *World_setCurrent( BPy_World * self );
/*****************************************************************************/
/* Python API function prototypes for the World module. */
/*****************************************************************************/
static PyObject *M_World_New( PyObject * self, PyObject * args,
PyObject * keywords );
static PyObject *M_World_Get( PyObject * self, PyObject * args );
static PyObject *M_World_GetCurrent( PyObject * self );
/*****************************************************************************/
/* Python World_Type callback function prototypes: */
/*****************************************************************************/
static void World_DeAlloc( BPy_World * self );
//static int World_Print (BPy_World *self, FILE *fp, int flags);
static int World_SetAttr( BPy_World * self, char *name, PyObject * v );
static int World_Compare( BPy_World * a, BPy_World * b );
static PyObject *World_GetAttr( BPy_World * self, char *name );
static PyObject *World_Repr( BPy_World * self );
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.World.__doc__ */
/*****************************************************************************/
static char M_World_doc[] = "The Blender World module\n\n\
This module provides access to **World Data** objects in Blender\n\n";
static char M_World_New_doc[] = "() - return a new World object";
static char M_World_Get_doc[] =
"(name) - return the world with the name 'name', \
returns None if not found.\n If 'name' is not specified, \
it returns a list of all worlds in the\ncurrent scene.";
static char M_World_GetCurrent_doc[] = "() - returns the current world, or \
None if the Scene has no world";
/*****************************************************************************/
/* Python method structure definition for Blender.World module: */
/*****************************************************************************/
struct PyMethodDef M_World_methods[] = {
{"New", ( PyCFunction ) M_World_New, METH_VARARGS | METH_KEYWORDS,
M_World_New_doc},
{"Get", M_World_Get, METH_VARARGS, M_World_Get_doc},
{"GetActive", ( PyCFunction ) M_World_GetCurrent, METH_NOARGS,
M_World_GetCurrent_doc},
{"GetCurrent", ( PyCFunction ) M_World_GetCurrent, METH_NOARGS,
M_World_GetCurrent_doc},
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
{"get", M_World_Get, METH_VARARGS, M_World_Get_doc},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python BPy_World methods table: */
/*****************************************************************************/
static PyMethodDef BPy_World_methods[] = {
{"getRange", ( PyCFunction ) World_getRange, METH_NOARGS,
"() - Return World Range"},
{"setRange", ( PyCFunction ) World_setRange, METH_VARARGS,
"() - Change this World's range"},
{"getIpo", ( PyCFunction ) World_getIpo, METH_NOARGS,
"() - Return World Ipo"},
{"setIpo", ( PyCFunction ) World_setIpo, METH_VARARGS,
"() - Change this World's ipo"},
{"clearIpo", ( PyCFunction ) World_clearIpo, METH_VARARGS,
"() - Unlink Ipo from this World"},
{"getName", ( PyCFunction ) World_getName, METH_NOARGS,
"() - Return World Data name"},
{"setName", ( PyCFunction ) World_setName, METH_VARARGS,
"() - Return World Data name"},
{"getSkytype", ( PyCFunction ) World_getSkytype, METH_NOARGS,
"() - Return World Data skytype"},
{"setSkytype", ( PyCFunction ) World_setSkytype, METH_VARARGS,
"() - Return World Data skytype"},
{"getMistype", ( PyCFunction ) World_getMistype, METH_NOARGS,
"() - Return World Data mistype"},
{"setMistype", ( PyCFunction ) World_setMistype, METH_VARARGS,
"() - Return World Data mistype"},
{"getHor", ( PyCFunction ) World_getHor, METH_NOARGS,
"() - Return World Data hor"},
{"setHor", ( PyCFunction ) World_setHor, METH_VARARGS,
"() - Return World Data hor"},
{"getZen", ( PyCFunction ) World_getZen, METH_NOARGS,
"() - Return World Data zen"},
{"setZen", ( PyCFunction ) World_setZen, METH_VARARGS,
"() - Return World Data zen"},
{"getAmb", ( PyCFunction ) World_getAmb, METH_NOARGS,
"() - Return World Data amb"},
{"setAmb", ( PyCFunction ) World_setAmb, METH_VARARGS,
"() - Return World Data amb"},
{"getStar", ( PyCFunction ) World_getStar, METH_NOARGS,
"() - Return World Data star"},
{"setStar", ( PyCFunction ) World_setStar, METH_VARARGS,
"() - Return World Data star"},
{"getMist", ( PyCFunction ) World_getMist, METH_NOARGS,
"() - Return World Data mist"},
{"setMist", ( PyCFunction ) World_setMist, METH_VARARGS,
"() - Return World Data mist"},
{"getScriptLinks", ( PyCFunction ) World_getScriptLinks, METH_VARARGS,
"(eventname) - Get a list of this world's scriptlinks (Text names) "
"of the given type\n"
"(eventname) - string: FrameChanged or Redraw."},
{"addScriptLink", ( PyCFunction ) World_addScriptLink, METH_VARARGS,
"(text, evt) - Add a new world scriptlink.\n"
"(text) - string: an existing Blender Text name;\n"
"(evt) string: FrameChanged or Redraw."},
{"clearScriptLinks", ( PyCFunction ) World_clearScriptLinks,
METH_NOARGS,
"() - Delete all scriptlinks from this world :)."},
{"setCurrent", ( PyCFunction ) World_setCurrent, METH_NOARGS,
"() - Makes this world the active world for the current scene."},
{"makeActive", ( PyCFunction ) World_setCurrent, METH_NOARGS,
"please use setCurrent instead, this alias will be removed."},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python World_Type structure definition: */
/*****************************************************************************/
PyTypeObject World_Type = {
PyObject_HEAD_INIT( NULL )
0, /* ob_size */
"World", /* tp_name */
sizeof( BPy_World ), /* tp_basicsize */
0, /* tp_itemsize */
( destructor ) World_DeAlloc, /* tp_dealloc */
0, /* tp_print */
( getattrfunc ) World_GetAttr, /* tp_getattr */
( setattrfunc ) World_SetAttr, /* tp_setattr */
( cmpfunc ) World_Compare, /* tp_compare */
( reprfunc ) World_Repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_as_hash */
0, 0, 0, 0, 0, 0,
0, /* tp_doc */
0, 0, 0, 0, 0, 0,
BPy_World_methods, /* tp_methods */
0, /* tp_members */
};
/**
* \defgroup World_Module Blender.World module functions
*
*/
/*@{*/
/**
* \brief Python module function: Blender.World.New()
*
* This is the .New() function of the Blender.World submodule. It creates
* new World Data in Blender and returns its Python wrapper object. The
* name parameter is mandatory.
* \param <name> - string: The World Data name.
* \return A new World PyObject.
*/
static PyObject *M_World_New( PyObject * self, PyObject * args,
PyObject * kwords )
World *add_world( char *name );
char *name = NULL;
BPy_World *pyworld;
World *blworld;
if( !PyArg_ParseTuple( args, "s", &name ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected int argument" ) );
if( blworld ) {
/* return user count to zero because add_world() inc'd it */
blworld->id.us = 0;
/* create python wrapper obj */
pyworld =
( BPy_World * ) PyObject_NEW( BPy_World, &World_Type );
} else
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't create World Data in Blender" ) );
if( pyworld == NULL )
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create World Data object" ) );
}
/**
* \brief Python module function: Blender.World.Get()
*
* This is the .Get() function of the Blender.World submodule. It searches
* the list of current World Data objects and returns a Python wrapper for
* the one with the name provided by the user. If called with no arguments,
* it returns a list of all current World Data object names in Blender.
* \param <name> - string: The name of an existing Blender World Data object.
* \return () - A list with the names of all current World Data objects;\n
* \return (name) - A Python wrapper for the World Data called 'name'
* in Blender.
*/
static PyObject *M_World_Get( PyObject * self, PyObject * args )
World *world_iter;
PyObject *worldlist;
BPy_World *wanted_world = NULL;
char error_msg[64];
if( !PyArg_ParseTuple( args, "|s", &name ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected string argument (or nothing)" ) );
if( name ) { /* (name) - Search world by name */
while( ( world_iter ) && ( wanted_world == NULL ) ) {
if( strcmp( name, world_iter->id.name + 2 ) == 0 ) {
wanted_world =
( BPy_World * )
PyObject_NEW( BPy_World, &World_Type );
if( wanted_world )
wanted_world->world = world_iter;
if( wanted_world == NULL ) { /* Requested world doesn't exist */
PyOS_snprintf( error_msg, sizeof( error_msg ),
"World \"%s\" not found", name );
return ( EXPP_ReturnPyObjError
( PyExc_NameError, error_msg ) );
return ( PyObject * ) wanted_world;
else { /* return a list of all worlds in the scene */
worldlist = PyList_New( 0 );
if( worldlist == NULL )
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create PyList" ) );
while( world_iter ) {
BPy_World *found_world =
( BPy_World * ) PyObject_NEW( BPy_World,
&World_Type );
PyList_Append( worldlist, ( PyObject * ) found_world );
Jacques Guignot
committed
static PyObject *M_World_GetCurrent( PyObject * self )
Jacques Guignot
committed
{
BPy_World *w = NULL;
if( !G.scene->world ) {
Py_INCREF( Py_None );
return Py_None;
}
w = ( BPy_World * ) PyObject_NEW( BPy_World, &World_Type );
Jacques Guignot
committed
w->world = G.scene->world;
Jacques Guignot
committed
}
/*@}*/
/**
* \brief Initializes the Blender.World submodule
*
* This function is used by Blender_Init() in Blender.c to register the
* Blender.World submodule in the main Blender module.
* \return PyObject*: The initialized submodule.
*/
submodule = Py_InitModule3( "Blender.World",
M_World_methods, M_World_doc );
}
/*****************************************************************************/
/* Python BPy_World methods: */
/*****************************************************************************/
static PyObject *World_getRange( BPy_World * self )
return PyFloat_FromDouble( self->world->range );
static PyObject *World_setRange( BPy_World * self, PyObject * args )
float range = 0.f;
if( !PyArg_ParseTuple( args, "f", &range ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected a float argument" ) );
self->world->range = range;
Py_INCREF( Py_None );
return Py_None;
static PyObject *World_getIpo( BPy_World * self )
if( !ipo ) {
Py_INCREF( Py_None );
return Ipo_CreatePyObject( ipo );
static PyObject *World_setIpo( BPy_World * self, PyObject * args )
{
PyObject *pyipo = 0;
Ipo *ipo = NULL;
Ipo *oldipo;
if( !PyArg_ParseTuple( args, "O!", &Ipo_Type, &pyipo ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected Ipo as argument" );
ipo = Ipo_FromPyObject( pyipo );
if( !ipo )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"null ipo!" );
if( ipo->blocktype != ID_WO )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"this ipo is not a World type ipo" );
static PyObject *World_clearIpo( BPy_World * self )
Ipo *ipo = ( Ipo * ) world->ipo;
Py_INCREF( Py_False ); /* no ipo found */
/**
* \brief World PyMethod getName
*
* \return string: The World Data name.
*/
static PyObject *World_getName( BPy_World * self )
PyObject *attr = PyString_FromString( self->world->id.name + 2 );
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get World.name attribute" ) );
/**
* \brief World PyMethod setName
* \param name - string: The new World Data name.
*/
static PyObject *World_setName( BPy_World * self, PyObject * args )
if( !PyArg_ParseTuple( args, "s", &name ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected string argument" ) );
snprintf( buf, sizeof( buf ), "%s", name );
rename_id( &self->world->id, buf );
}
/**
* \brief World PyMethod getSkytype
*
* \return int : The World Data skytype.
*/
static PyObject *World_getSkytype( BPy_World * self )
PyObject *attr = PyInt_FromLong( ( long ) self->world->skytype );
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get World.skytype attribute" ) );
}
/**
* \brief World PyMethod setSkytype
*
* \return int : The World Data skytype.
*/
static PyObject *World_setSkytype( BPy_World * self, PyObject * args )
if( !PyArg_ParseTuple( args, "i", &skytype ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected int argument" ) );
}
/**
* \brief World PyMethod getMode
*
* \return int : The World Data mode.
*/
static PyObject *World_getMode( BPy_World * self )
PyObject *attr = PyInt_FromLong( ( long ) self->world->mode );
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get World.mode attribute" ) );
}
/**
* \brief World PyMethod setMode
*
* \return int : The World Data mode.
*/
static PyObject *World_setMode( BPy_World * self, PyObject * args )
if( !PyArg_ParseTuple( args, "i", &mode ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected int argument" ) );
}
/**
* \brief World PyMethod getMistype
*
* \return int : The World Data mistype.
*/
static PyObject *World_getMistype( BPy_World * self )
PyObject *attr = PyInt_FromLong( ( long ) self->world->mistype );
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't get World.mistype attribute" ) );
}
/**
* \brief World PyMethod setMistype
*
* \return int : The World Data mistype.
*/
static PyObject *World_setMistype( BPy_World * self, PyObject * args )
if( !PyArg_ParseTuple( args, "i", &mistype ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected int argument" ) );
static PyObject *World_getHor( BPy_World * self )
PyObject *attr = PyList_New( 0 );
if( !attr )
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't create list" ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->horr ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->horg ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->horb ) );
static PyObject *World_setHor( BPy_World * self, PyObject * args )
PyObject *listargs = 0;
if( !PyArg_ParseTuple( args, "O", &listargs ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected list argument" ) );
self->world->horr = PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
self->world->horg = PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
self->world->horb = PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
Py_INCREF( Py_None );
static PyObject *World_getZen( BPy_World * self )
PyObject *attr = PyList_New( 0 );
if( !attr )
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't create list" ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->zenr ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->zeng ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->zenb ) );
static PyObject *World_setZen( BPy_World * self, PyObject * args )
PyObject *listargs = 0;
if( !PyArg_ParseTuple( args, "O", &listargs ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected list argument" ) );
self->world->zenr = PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
self->world->zeng = PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
self->world->zenb = PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
Py_INCREF( Py_None );
static PyObject *World_getAmb( BPy_World * self )
PyObject *attr = PyList_New( 0 );
if( !attr )
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"couldn't create list" ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->ambr ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->ambg ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->ambb ) );
static PyObject *World_setAmb( BPy_World * self, PyObject * args )
PyObject *listargs = 0;
if( !PyArg_ParseTuple( args, "O", &listargs ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected list argument" ) );
if( !PyList_Check( listargs ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected list argument" ) );
if( PyList_Size( listargs ) != 3 )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "wrong list size" ) );
self->world->ambr = PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
self->world->ambg = PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
self->world->ambb = PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
Py_INCREF( Py_None );
static PyObject *World_getStar( BPy_World * self )
PyObject *attr = PyList_New( 0 );
if( !attr )
return ( EXPP_ReturnPyObjError
( PyExc_RuntimeError, "couldn't create list" ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->starr ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->starg ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->starb ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->starsize ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->starmindist ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->stardist ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->starcolnoise ) );
static PyObject *World_setStar( BPy_World * self, PyObject * args )
{
PyObject *listargs = 0;
if( !PyArg_ParseTuple( args, "O", &listargs ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected list argument" ) );
if( !PyList_Check( listargs ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected list argument" ) );
if( PyList_Size( listargs ) != 7 )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "wrong list size" ) );
self->world->starr = PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
self->world->starg = PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
self->world->starb = PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
self->world->starsize =
PyFloat_AsDouble( PyList_GetItem( listargs, 3 ) );
self->world->starmindist =
PyFloat_AsDouble( PyList_GetItem( listargs, 4 ) );
self->world->stardist =
PyFloat_AsDouble( PyList_GetItem( listargs, 5 ) );
self->world->starcolnoise =
PyFloat_AsDouble( PyList_GetItem( listargs, 6 ) );
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *World_getMist( BPy_World * self )
PyObject *attr = PyList_New( 0 );
if( !attr )
return ( EXPP_ReturnPyObjError
( PyExc_RuntimeError, "couldn't create list" ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->misi ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->miststa ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->mistdist ) );
PyList_Append( attr, PyFloat_FromDouble( self->world->misthi ) );
static PyObject *World_setMist( BPy_World * self, PyObject * args )
{
PyObject *listargs = 0;
if( !PyArg_ParseTuple( args, "O", &listargs ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected list argument" ) );
if( !PyList_Check( listargs ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected list argument" ) );
if( PyList_Size( listargs ) != 4 )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "wrong list size" ) );
self->world->misi = PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
self->world->miststa =
PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
self->world->mistdist =
PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
self->world->misthi =
PyFloat_AsDouble( PyList_GetItem( listargs, 3 ) );
Py_INCREF( Py_None );
static PyObject *World_addScriptLink( BPy_World * self, PyObject * args )
{
World *world = self->world;
ScriptLink *slink = NULL;
slink = &( world )->scriptlink;
if( !EXPP_addScriptLink( slink, args, 0 ) )
return EXPP_incr_ret( Py_None );
else
return NULL;
static PyObject *World_clearScriptLinks( BPy_World * self )
{
World *world = self->world;
ScriptLink *slink = NULL;
slink = &( world )->scriptlink;
return EXPP_incr_ret( Py_BuildValue
( "i", EXPP_clearScriptLinks( slink ) ) );
static PyObject *World_getScriptLinks( BPy_World * self, PyObject * args )
{
World *world = self->world;
ScriptLink *slink = NULL;
PyObject *ret = NULL;
slink = &( world )->scriptlink;
ret = EXPP_getScriptLinks( slink, args, 0 );
if( ret )
return ret;
else
return NULL;
/* world.setCurrent */
static PyObject *World_setCurrent( BPy_World * self )
{
World *world = self->world;
/* If there is a world then it now has one less user */
G.scene->world->id.us--;
world->id.us++;
G.scene->world = world;
return Py_None;
}
/*@{*/
/**
* \brief The World PyType destructor
*/
static void World_DeAlloc( BPy_World * self )
}
/**
* \brief The World PyType attribute getter
*
* This is the callback called when a user tries to retrieve the contents of
* World PyObject data members. Ex. in Python: "print myworld.lens".
*/
static PyObject *World_GetAttr( BPy_World * self, char *name )
{
if( strcmp( name, "name" ) == 0 )
return World_getName( self );
if( strcmp( name, "skytype" ) == 0 )
return World_getSkytype( self );
if( strcmp( name, "mode" ) == 0 )
return World_getMode( self );
if( strcmp( name, "mistype" ) == 0 )
return World_getMistype( self );
if( strcmp( name, "hor" ) == 0 )
return World_getHor( self );
if( strcmp( name, "zen" ) == 0 )
return World_getZen( self );
if( strcmp( name, "amb" ) == 0 )
return World_getAmb( self );
if( strcmp( name, "star" ) == 0 )
return World_getStar( self );
if( strcmp( name, "mist" ) == 0 )
return World_getMist( self );
return Py_FindMethod( BPy_World_methods, ( PyObject * ) self, name );
}
/**
* \brief The World PyType attribute setter
*
* This is the callback called when the user tries to change the value of some
* World data member. Ex. in Python: "myworld.lens = 45.0".
*/
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
static int World_SetAttr( BPy_World * self, char *name, PyObject * value )
{
PyObject *valtuple = Py_BuildValue( "(O)", value );
if( !valtuple )
return EXPP_ReturnIntError( PyExc_MemoryError,
"WorldSetAttr: couldn't parse args" );
if( strcmp( name, "name" ) == 0 )
World_setName( self, valtuple );
if( strcmp( name, "skytype" ) == 0 )
World_setSkytype( self, valtuple );
if( strcmp( name, "mode" ) == 0 )
World_setMode( self, valtuple );
if( strcmp( name, "mistype" ) == 0 )
World_setMistype( self, valtuple );
if( strcmp( name, "hor" ) == 0 )
World_setHor( self, valtuple );
if( strcmp( name, "zen" ) == 0 )
World_setZen( self, valtuple );
if( strcmp( name, "amb" ) == 0 )
World_setAmb( self, valtuple );
if( strcmp( name, "star" ) == 0 )
World_setStar( self, valtuple );
if( strcmp( name, "mist" ) == 0 )
World_setMist( self, valtuple );
return 0; /* normal exit */
}
/**
* \brief The World PyType compare function
*
* This function compares two given World PyObjects, returning 0 for equality
* and -1 otherwise. In Python it becomes 1 if they are equal and 0 case not.
* The comparison is done with their pointers to Blender World Data objects,
* so any two wrappers pointing to the same Blender World Data will be
* considered the same World PyObject. Currently, only the "==" and "!="
* comparisons are meaninful -- the "<", "<=", ">" or ">=" are not.
*/
static int World_Compare( BPy_World * a, BPy_World * b )
}
/**
* \brief The World PyType print callback
*
* This function is called when the user tries to print a PyObject of type
* World. It builds a string with the name of the wrapped Blender World.
*/
Jacques Guignot
committed
/*
static int World_Print(BPy_World *self, FILE *fp, int flags)
fprintf(fp, "[World \"%s\"]", self->world->id.name+2);
return 0;
Jacques Guignot
committed
*/
/**
* \brief The World PyType repr callback
*
* This function is called when the statement "repr(myworld)" is executed in
* Python. Repr gives a string representation of a PyObject.