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:
authorThomas Szepe <HG1_public@gmx.net>2015-03-24 02:23:40 +0300
committerThomas Szepe <HG1_public@gmx.net>2015-03-24 02:23:40 +0300
commitfd22a92939dc937216f50d1350a63de872e0a6be (patch)
treeb0b2c22078c347ec0e033d48f02e7e878e817864
parent6c9502a6c1e8637922991171680986f1c9a17f6e (diff)
BGE: Add new world API KX_WorldInfo (KX_Scene)
This Patch will add a the world API (mist, background, ambient) to KX_WorldInfo. The new API uses now attributes. Reviewers: campbellbarton, moguri Reviewed By: moguri Subscribers: klauser, brecht Differential Revision: https://developer.blender.org/D157
-rw-r--r--doc/python_api/rst/bge.render.rst35
-rw-r--r--doc/python_api/rst/bge_types/bge.types.KX_Scene.rst6
-rw-r--r--doc/python_api/rst/bge_types/bge.types.KX_WorldInfo.rst87
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp10
-rw-r--r--source/gameengine/Ketsji/KX_PythonInitTypes.cpp3
-rw-r--r--source/gameengine/Ketsji/KX_Scene.cpp14
-rw-r--r--source/gameengine/Ketsji/KX_Scene.h1
-rw-r--r--source/gameengine/Ketsji/KX_WorldInfo.cpp303
-rw-r--r--source/gameengine/Ketsji/KX_WorldInfo.h26
9 files changed, 463 insertions, 22 deletions
diff --git a/doc/python_api/rst/bge.render.rst b/doc/python_api/rst/bge.render.rst
index 09d16f4b2ed..2d47244bf7a 100644
--- a/doc/python_api/rst/bge.render.rst
+++ b/doc/python_api/rst/bge.render.rst
@@ -89,15 +89,15 @@ Constants
.. data:: KX_MIST_QUADRATIC
- Type of quadratic attenuation used to fade mist.
+ Type of quadratic attenuation used to fade mist. (Deprecated: use KX_WorldInfo.KX_MIST_QUADRATIC)
.. data:: KX_MIST_LINEAR
- Type of linear attenuation used to fade mist.
+ Type of linear attenuation used to fade mist. (Deprecated: use KX_WorldInfo.KX_MIST_LINEAR)
.. data:: KX_MIST_INV_QUADRATIC
- Type of inverse quadratic attenuation used to fade mist.
+ Type of inverse quadratic attenuation used to fade mist. (Deprecated: use KX_WorldInfo.KX_MIST_INV_QUADRATIC)
*********
@@ -173,50 +173,51 @@ Functions
.. function:: setBackgroundColor(rgba)
- Sets the window background color.
-
+ Sets the window background color. (Deprecated: use KX_WorldInfo.background_color)
+
:type rgba: list [r, g, b, a]
.. function:: setAmbientColor(rgb)
- Sets the color of ambient light.
-
+ Sets the color of ambient light. (Deprecated: use KX_WorldInfo.ambient_color)
+
:type rgb: list [r, g, b]
.. function:: setMistColor(rgb)
- Sets the mist color.
-
+ Sets the mist color. (Deprecated: use KX_WorldInfo.mist_color)
+
:type rgb: list [r, g, b]
.. function:: setMistType(mode)
- Sets the mist attenuation type.
+ Sets the mist attenuation type. (Deprecated: use KX_WorldInfo.mist_type)
:type mode: KX_MIST_QUADRATIC, KX_MIST_LINEAR, KX_MIST_INV_QUADRATIC
.. function:: setMistStart(start)
- Sets the mist start value. Objects further away than start will have mist applied to them.
-
+ Sets the mist start value. Objects further away than start will have mist applied to them.
+ (Deprecated: use KX_WorldInfo.mist_start)
+
:type start: float
.. function:: setMistEnd(end)
Sets the mist end value. Objects further away from this will be colored solid with
- the color set by setMistColor().
-
+ the color set by setMistColor(). (Deprecated: use KX_WorldInfo.mist_distance)
+
:type end: float
.. function:: setMistIntensity(intensity)
- Sets the mist intensity value.
+ Sets the mist intensity value. (Deprecated: use KX_WorldInfo.mist_intensity)
:type start: float
@@ -225,12 +226,12 @@ Functions
Disables mist.
- .. note:: Deprecated use setUseMist().
+ .. note:: Deprecated: use KX_WorldInfo.mist_enable.
.. function:: setUseMist(enable)
- Disable or enable the mist.
+ Disable or enable the mist. (Deprecated: use KX_WorldInfo.mist_enable)
:type enable: boolean
diff --git a/doc/python_api/rst/bge_types/bge.types.KX_Scene.rst b/doc/python_api/rst/bge_types/bge.types.KX_Scene.rst
index fc5ba357add..255ff95ad37 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_Scene.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_Scene.rst
@@ -83,6 +83,12 @@ base class --- :class:`PyObjectPlus`
This can be set directly from python to avoid using the :class:`KX_SceneActuator`.
+ .. attribute:: world
+
+ The current active world, (read-only).
+
+ :type: :class:`KX_WorldInfo`
+
.. attribute:: suspended
True if the scene is suspended, (read-only).
diff --git a/doc/python_api/rst/bge_types/bge.types.KX_WorldInfo.rst b/doc/python_api/rst/bge_types/bge.types.KX_WorldInfo.rst
new file mode 100644
index 00000000000..ffc24b4e6c5
--- /dev/null
+++ b/doc/python_api/rst/bge_types/bge.types.KX_WorldInfo.rst
@@ -0,0 +1,87 @@
+KX_WordlInfo(PyObjectPlus)
+=============================
+
+.. module:: bge.types
+
+base class --- :class:`PyObjectPlus`
+
+.. class:: KX_WorldInfo(PyObjectPlus)
+
+ A wolrd object.
+
+ .. code-block:: python
+
+ # Set the mist color to red.
+ import bge
+
+ sce = bge.logic.getCurrentScene()
+
+ sce.world.mist_color = [1.0, 0.0, 0.0]
+
+*********
+Constants
+*********
+
+ .. data:: KX_MIST_QUADRATIC
+
+ Type of quadratic attenuation used to fade mist.
+
+ .. data:: KX_MIST_LINEAR
+
+ Type of linear attenuation used to fade mist.
+
+ .. data:: KX_MIST_INV_QUADRATIC
+
+ Type of inverse quadratic attenuation used to fade mist.
+
+**********
+Attributes
+**********
+
+ .. attribute:: mist_enable
+
+ Return the state of the mist.
+
+ :type: bool
+
+ .. attribute:: mist_start
+
+ The mist start point.
+
+ :type: float
+
+ .. attribute:: mist_distance
+
+ The mist distance fom the start point to reach 100% mist.
+
+ :type: float
+
+ .. attribute:: mist_intensity
+
+ The mist intensity.
+
+ :type: float
+
+ .. attribute:: mist_type
+
+ The type of mist - must be KX_MIST_QUADRATIC, KX_MIST_LINEAR or KX_MIST_INV_QUADRATIC
+
+ .. attribute:: mist_color
+
+ The color of the mist. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0].
+ Mist and background color sould always set to the same color.
+
+ :type: :class:`mathutils.Vector`
+
+ .. attribute:: background_color
+
+ The color of the background. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0].
+ Mist and background color sould always set to the same color.
+
+ :type: :class:`mathutils.Vector`
+
+ .. attribute:: ambient_color
+
+ The color of the ambient light. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0].
+
+ :type: :class:`mathutils.Vector`
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 8fd38db4a2a..b3fba745e96 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -1039,6 +1039,7 @@ static PyObject *gPySetBackgroundColor(PyObject *, PyObject *value)
return NULL;
}
+ ShowDeprecationWarning("setBackgroundColor()", "KX_WorldInfo.background_color");
wi->setBackColor((float)vec[0], (float)vec[1], (float)vec[2]);
Py_RETURN_NONE;
@@ -1056,6 +1057,7 @@ static PyObject *gPySetMistColor(PyObject *, PyObject *value)
return NULL;
}
+ ShowDeprecationWarning("setMistColor()", "KX_WorldInfo.mist_color");
wi->setMistColor((float)vec[0], (float)vec[1], (float)vec[2]);
Py_RETURN_NONE;
@@ -1068,7 +1070,7 @@ static PyObject *gPyDisableMist(PyObject *)
PyErr_SetString(PyExc_RuntimeError, "bge.render.DisableMist(), World not available");
return NULL;
}
- ShowDeprecationWarning("DisableMist()", "setUseMist(false)");
+ ShowDeprecationWarning("DisableMist()", "KX_WorldInfo.mist_enable = False");
wi->setUseMist(false);
Py_RETURN_NONE;
@@ -1086,6 +1088,7 @@ static PyObject *gPySetUseMist(PyObject *, PyObject *args)
return NULL;
}
+ ShowDeprecationWarning("setUseMist()", "KX_WorldInfo.mist_enable");
wi->setUseMist(enable);
Py_RETURN_NONE;
@@ -1109,6 +1112,7 @@ static PyObject *gPySetMistType(PyObject *, PyObject *args)
return NULL;
}
+ ShowDeprecationWarning("setMistType()", "KX_WorldInfo.mist_type");
wi->setMistType(type);
Py_RETURN_NONE;
@@ -1126,6 +1130,7 @@ static PyObject *gPySetMistStart(PyObject *, PyObject *args)
return NULL;
}
+ ShowDeprecationWarning("setMistStart()", "KX_WorldInfo.mist_start");
wi->setMistStart(miststart);
Py_RETURN_NONE;
@@ -1143,6 +1148,7 @@ static PyObject *gPySetMistEnd(PyObject *, PyObject *args)
return NULL;
}
+ ShowDeprecationWarning("setMistEnd()", "KX_WorldInfo.mist_distance");
wi->setMistDistance(mistdist);
Py_RETURN_NONE;
@@ -1161,6 +1167,7 @@ static PyObject *gPySetMistIntensity(PyObject *, PyObject *args)
return NULL;
}
+ ShowDeprecationWarning("setMistIntensity()", "KX_WorldInfo.mist_intensity");
wi->setMistIntensity(intensity);
Py_RETURN_NONE;
@@ -1178,6 +1185,7 @@ static PyObject *gPySetAmbientColor(PyObject *, PyObject *value)
return NULL;
}
+ ShowDeprecationWarning("setAmbientColor()", "KX_WorldInfo.ambient_color");
wi->setAmbientColor((float)vec[0], (float)vec[1], (float)vec[2]);
Py_RETURN_NONE;
diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
index 828fd62f205..b3511e4e61a 100644
--- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
@@ -40,6 +40,7 @@
#include "BL_ArmatureConstraint.h"
#include "BL_ArmatureObject.h"
#include "BL_ArmatureChannel.h"
+#include "KX_WorldInfo.h"
#include "KX_ArmatureSensor.h"
#include "KX_BlenderMaterial.h"
#include "KX_CameraActuator.h"
@@ -231,6 +232,7 @@ PyMODINIT_FUNC initGameTypesPythonBinding(void)
PyType_Ready_Attr(dict, KX_SCA_EndObjectActuator, init_getset);
PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator, init_getset);
PyType_Ready_Attr(dict, KX_Scene, init_getset);
+ PyType_Ready_Attr(dict, KX_WorldInfo, init_getset);
PyType_Ready_Attr(dict, KX_NavMeshObject, init_getset);
PyType_Ready_Attr(dict, KX_SceneActuator, init_getset);
PyType_Ready_Attr(dict, KX_SoundActuator, init_getset);
@@ -279,6 +281,7 @@ PyMODINIT_FUNC initGameTypesPythonBinding(void)
/* Init mathutils callbacks */
KX_GameObject_Mathutils_Callback_Init();
KX_ObjectActuator_Mathutils_Callback_Init();
+ KX_WorldInfo_Mathutils_Callback_Init();
#endif
return m;
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
index e26fdaa4898..193a72ebd2a 100644
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ b/source/gameengine/Ketsji/KX_Scene.cpp
@@ -2341,6 +2341,19 @@ PyObject *KX_Scene::pyattr_get_lights(void *self_v, const KX_PYATTRIBUTE_DEF *at
return self->GetLightList()->GetProxy();
}
+PyObject *KX_Scene::pyattr_get_world(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_Scene* self = static_cast<KX_Scene*>(self_v);
+ KX_WorldInfo *world = self->GetWorldInfo();
+
+ if (world->GetName() != "") {
+ return world->GetProxy();
+ }
+ else {
+ Py_RETURN_NONE;
+ }
+}
+
PyObject *KX_Scene::pyattr_get_cameras(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
/* With refcounts in this case...
@@ -2464,6 +2477,7 @@ PyAttributeDef KX_Scene::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("objectsInactive", KX_Scene, pyattr_get_objects_inactive),
KX_PYATTRIBUTE_RO_FUNCTION("lights", KX_Scene, pyattr_get_lights),
KX_PYATTRIBUTE_RO_FUNCTION("cameras", KX_Scene, pyattr_get_cameras),
+ KX_PYATTRIBUTE_RO_FUNCTION("world", KX_Scene, pyattr_get_world),
KX_PYATTRIBUTE_RW_FUNCTION("active_camera", KX_Scene, pyattr_get_active_camera, pyattr_set_active_camera),
KX_PYATTRIBUTE_RW_FUNCTION("pre_draw", KX_Scene, pyattr_get_drawing_callback_pre, pyattr_set_drawing_callback_pre),
KX_PYATTRIBUTE_RW_FUNCTION("post_draw", KX_Scene, pyattr_get_drawing_callback_post, pyattr_set_drawing_callback_post),
diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h
index a031be78e92..93e764851a9 100644
--- a/source/gameengine/Ketsji/KX_Scene.h
+++ b/source/gameengine/Ketsji/KX_Scene.h
@@ -624,6 +624,7 @@ public:
static PyObject* pyattr_get_objects_inactive(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_lights(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_cameras(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_world(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_active_camera(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_drawing_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
diff --git a/source/gameengine/Ketsji/KX_WorldInfo.cpp b/source/gameengine/Ketsji/KX_WorldInfo.cpp
index a094bffd77a..b07aa26cf91 100644
--- a/source/gameengine/Ketsji/KX_WorldInfo.cpp
+++ b/source/gameengine/Ketsji/KX_WorldInfo.cpp
@@ -32,6 +32,8 @@
#include "KX_WorldInfo.h"
#include "KX_PythonInit.h"
+#include "KX_PyMath.h"
+#include "RAS_IRasterizer.h"
#include "GPU_material.h"
/* This little block needed for linking to Blender... */
@@ -53,6 +55,7 @@
KX_WorldInfo::KX_WorldInfo(Scene *blenderscene, World *blenderworld)
{
if (blenderworld) {
+ m_name = blenderworld->id.name + 2;
m_do_color_management = BKE_scene_check_color_management_enabled(blenderscene);
m_hasworld = true;
m_hasmist = ((blenderworld->mode) & WO_MIST ? true : false);
@@ -73,6 +76,11 @@ KX_WorldInfo::~KX_WorldInfo()
{
}
+const STR_String& KX_WorldInfo::GetName()
+{
+ return m_name;
+}
+
bool KX_WorldInfo::hasWorld()
{
return m_hasworld;
@@ -248,3 +256,298 @@ void KX_WorldInfo::UpdateWorldSettings()
}
}
}
+
+#ifdef WITH_PYTHON
+
+/* -------------------------------------------------------------------------
+ * Python functions
+ * ------------------------------------------------------------------------- */
+PyObject *KX_WorldInfo::py_repr(void)
+{
+ return PyUnicode_From_STR_String(GetName());
+}
+
+/* -------------------------------------------------------------------------
+ * Python Integration Hooks
+ * ------------------------------------------------------------------------- */
+PyTypeObject KX_WorldInfo::Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "KX_WorldInfo",
+ sizeof(PyObjectPlus_Proxy),
+ 0,
+ py_base_dealloc,
+ 0,
+ 0,
+ 0,
+ 0,
+ py_base_repr,
+ 0,0,0,0,0,0,0,0,0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ 0,0,0,0,0,0,0,
+ Methods,
+ 0,
+ 0,
+ &PyObjectPlus::Type,
+ 0,0,0,0,0,0,
+ py_base_new
+};
+
+PyMethodDef KX_WorldInfo::Methods[] = {
+ {NULL,NULL} /* Sentinel */
+};
+
+PyAttributeDef KX_WorldInfo::Attributes[] = {
+ KX_PYATTRIBUTE_BOOL_RW("mist_enable", KX_WorldInfo, m_hasmist),
+ KX_PYATTRIBUTE_FLOAT_RW("mist_start", 0.0f, 10000.0f, KX_WorldInfo, m_miststart),
+ KX_PYATTRIBUTE_FLOAT_RW("mist_distance", 0.001f, 10000.0f, KX_WorldInfo, m_mistdistance),
+ KX_PYATTRIBUTE_FLOAT_RW("mist_intensity", 0.0f, 1.0f, KX_WorldInfo, m_mistintensity),
+ KX_PYATTRIBUTE_SHORT_RW("mist_type", 0, 2, true, KX_WorldInfo, m_misttype),
+ KX_PYATTRIBUTE_RO_FUNCTION("KX_MIST_QUADRATIC", KX_WorldInfo, pyattr_get_mist_typeconst),
+ KX_PYATTRIBUTE_RO_FUNCTION("KX_MIST_LINEAR", KX_WorldInfo, pyattr_get_mist_typeconst),
+ KX_PYATTRIBUTE_RO_FUNCTION("KX_MIST_INV_QUADRATIC", KX_WorldInfo, pyattr_get_mist_typeconst),
+ KX_PYATTRIBUTE_RW_FUNCTION("mist_color", KX_WorldInfo, pyattr_get_mist_color, pyattr_set_mist_color),
+ KX_PYATTRIBUTE_RW_FUNCTION("background_color", KX_WorldInfo, pyattr_get_back_color, pyattr_set_back_color),
+ KX_PYATTRIBUTE_RW_FUNCTION("ambient_color", KX_WorldInfo, pyattr_get_ambient_color, pyattr_set_ambient_color),
+ { NULL } /* Sentinel */
+};
+
+/* Attribute get/set functions */
+
+#ifdef USE_MATHUTILS
+
+/*----------------------mathutils callbacks ----------------------------*/
+
+/* subtype */
+#define MATHUTILS_VEC_CB_MIST_COLOR 1
+#define MATHUTILS_VEC_CB_BACK_COLOR 2
+#define MATHUTILS_VEC_CB_AMBIENT_COLOR 3
+
+static unsigned char mathutils_world_vector_cb_index = -1; /* index for our callbacks */
+
+static int mathutils_world_generic_check(BaseMathObject *bmo)
+{
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
+ if (self == NULL)
+ return -1;
+
+ return 0;
+}
+
+static int mathutils_world_vector_get(BaseMathObject *bmo, int subtype)
+{
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
+ if (self == NULL)
+ return -1;
+
+ switch (subtype) {
+ case MATHUTILS_VEC_CB_MIST_COLOR:
+ copy_v3_v3(bmo->data, self->m_mistcolor);
+ break;
+ case MATHUTILS_VEC_CB_BACK_COLOR:
+ copy_v3_v3(bmo->data, self->m_backgroundcolor);
+ break;
+ case MATHUTILS_VEC_CB_AMBIENT_COLOR:
+ copy_v3_v3(bmo->data, self->m_ambientcolor);
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static int mathutils_world_vector_set(BaseMathObject *bmo, int subtype)
+{
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
+
+ if (self == NULL)
+ return -1;
+
+ switch (subtype) {
+ case MATHUTILS_VEC_CB_MIST_COLOR:
+ self->setMistColor(bmo->data[0], bmo->data[1], bmo->data[2]);
+ break;
+ case MATHUTILS_VEC_CB_BACK_COLOR:
+ self->setBackColor(bmo->data[0], bmo->data[1], bmo->data[2]);
+ break;
+ case MATHUTILS_VEC_CB_AMBIENT_COLOR:
+ self->setAmbientColor(bmo->data[0], bmo->data[1], bmo->data[2]);
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static int mathutils_world_vector_get_index(BaseMathObject *bmo, int subtype, int index)
+{
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
+
+ if (self == NULL)
+ return -1;
+
+ switch (subtype) {
+ case MATHUTILS_VEC_CB_MIST_COLOR:
+ {
+ const float *color = self->m_mistcolor;
+ bmo->data[index] = color[index];
+ }
+ break;
+ case MATHUTILS_VEC_CB_BACK_COLOR:
+ {
+ const float *color = self->m_backgroundcolor;
+ bmo->data[index] = color[index];
+ }
+ break;
+ case MATHUTILS_VEC_CB_AMBIENT_COLOR:
+ {
+ const float *color = self->m_ambientcolor;
+ bmo->data[index] = color[index];
+ }
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static int mathutils_world_vector_set_index(BaseMathObject *bmo, int subtype, int index)
+{
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
+
+ if (self == NULL)
+ return -1;
+
+ float color[4];
+ switch (subtype) {
+ case MATHUTILS_VEC_CB_MIST_COLOR:
+ copy_v3_v3(color, self->m_mistcolor);
+ color[index] = bmo->data[index];
+ self->setMistColor(color[0], color[1], color[2]);
+ break;
+ case MATHUTILS_VEC_CB_BACK_COLOR:
+ copy_v3_v3(color, self->m_backgroundcolor);
+ color[index] = bmo->data[index];
+ self->setBackColor(color[0], color[1], color[2]);
+ break;
+ case MATHUTILS_VEC_CB_AMBIENT_COLOR:
+ copy_v3_v3(color, self->m_ambientcolor);
+ color[index] = bmo->data[index];
+ self->setAmbientColor(color[0], color[1], color[2]);
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static Mathutils_Callback mathutils_world_vector_cb = {
+ mathutils_world_generic_check,
+ mathutils_world_vector_get,
+ mathutils_world_vector_set,
+ mathutils_world_vector_get_index,
+ mathutils_world_vector_set_index
+};
+
+void KX_WorldInfo_Mathutils_Callback_Init()
+{
+ // register mathutils callbacks, ok to run more than once.
+ mathutils_world_vector_cb_index = Mathutils_RegisterCallback(&mathutils_world_vector_cb);
+}
+#endif // USE_MATHUTILS
+
+
+PyObject *KX_WorldInfo::pyattr_get_mist_typeconst(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ PyObject *retvalue;
+
+ const char* type = attrdef->m_name;
+
+ if (!strcmp(type, "KX_MIST_QUADRATIC")) {
+ retvalue = PyLong_FromLong(KX_MIST_QUADRATIC);
+ }
+ else if (!strcmp(type, "KX_MIST_LINEAR")) {
+ retvalue = PyLong_FromLong(KX_MIST_LINEAR);
+ }
+ else if (!strcmp(type, "KX_MIST_INV_QUADRATIC")) {
+ retvalue = PyLong_FromLong(KX_MIST_INV_QUADRATIC);
+ }
+ else {
+ /* should never happen */
+ PyErr_SetString(PyExc_TypeError, "invalid mist type");
+ retvalue = NULL;
+ }
+
+ return retvalue;
+}
+
+PyObject *KX_WorldInfo::pyattr_get_mist_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+#ifdef USE_MATHUTILS
+ return Vector_CreatePyObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_world_vector_cb_index, MATHUTILS_VEC_CB_MIST_COLOR);
+#else
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
+ return PyObjectFrom(MT_Vector3(self->m_mistcolor));
+#endif
+}
+
+int KX_WorldInfo::pyattr_set_mist_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
+
+ MT_Vector3 color;
+ if (PyVecTo(value, color))
+ {
+ self->setMistColor(color[0], color[1], color[2]);
+ return PY_SET_ATTR_SUCCESS;
+ }
+ return PY_SET_ATTR_FAIL;
+}
+
+PyObject *KX_WorldInfo::pyattr_get_back_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+
+#ifdef USE_MATHUTILS
+ return Vector_CreatePyObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_world_vector_cb_index, MATHUTILS_VEC_CB_BACK_COLOR);
+#else
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
+ return PyObjectFrom(MT_Vector3(self->m_backgroundcolor));
+#endif
+}
+
+int KX_WorldInfo::pyattr_set_back_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
+
+ MT_Vector3 color;
+ if (PyVecTo(value, color))
+ {
+ self->setBackColor(color[0], color[1], color[2]);
+ return PY_SET_ATTR_SUCCESS;
+ }
+ return PY_SET_ATTR_FAIL;
+}
+
+PyObject *KX_WorldInfo::pyattr_get_ambient_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+#ifdef USE_MATHUTILS
+ return Vector_CreatePyObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_world_vector_cb_index, MATHUTILS_VEC_CB_AMBIENT_COLOR);
+#else
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
+ return PyObjectFrom(MT_Vector3(self->m_ambientcolor));
+#endif
+}
+
+int KX_WorldInfo::pyattr_set_ambient_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
+
+ MT_Vector3 color;
+ if (PyVecTo(value, color))
+ {
+ self->setAmbientColor(color[0], color[1], color[2]);
+ return PY_SET_ATTR_SUCCESS;
+ }
+ return PY_SET_ATTR_FAIL;
+}
+
+#endif /* WITH_PYTHON */
diff --git a/source/gameengine/Ketsji/KX_WorldInfo.h b/source/gameengine/Ketsji/KX_WorldInfo.h
index 4abcfb98892..830f12de6b0 100644
--- a/source/gameengine/Ketsji/KX_WorldInfo.h
+++ b/source/gameengine/Ketsji/KX_WorldInfo.h
@@ -34,19 +34,24 @@
#include "MT_Scalar.h"
#include "KX_KetsjiEngine.h"
-#include "RAS_IRasterizer.h"
+#include "PyObjectPlus.h"
#ifdef WITH_CXX_GUARDEDALLOC
#include "MEM_guardedalloc.h"
#endif
+#ifdef USE_MATHUTILS
+void KX_WorldInfo_Mathutils_Callback_Init(void);
+#endif
+
struct Scene;
struct World;
-const class KX_KetsjiEngine;
-const class RAS_IRasterizer;
-class KX_WorldInfo
+class KX_WorldInfo : public PyObjectPlus
{
+ Py_Header
+
+ STR_String m_name;
bool m_do_color_management;
bool m_hasworld;
bool m_hasmist;
@@ -74,6 +79,7 @@ public:
KX_WorldInfo(Scene *blenderscene, World *blenderworld);
~KX_WorldInfo();
+ const STR_String &GetName();
bool hasWorld();
bool hasMist();
short getMistType();
@@ -100,6 +106,18 @@ public:
void UpdateBackGround();
void UpdateWorldSettings();
+#ifdef WITH_PYTHON
+ /* attributes */
+ static PyObject *pyattr_get_mist_typeconst(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject *pyattr_get_mist_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_mist_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+ static PyObject *pyattr_get_back_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_back_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+ static PyObject *pyattr_get_ambient_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_ambient_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+ virtual PyObject *py_repr(void);
+#endif
+
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_WorldInfo")
#endif