Commit: fd22a92939dc937216f50d1350a63de872e0a6be Author: Thomas Szepe Date: Tue Mar 24 00:23:40 2015 +0100 Branches: master https://developer.blender.org/rBfd22a92939dc937216f50d1350a63de872e0a6be
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 =================================================================== M doc/python_api/rst/bge.render.rst M doc/python_api/rst/bge_types/bge.types.KX_Scene.rst A doc/python_api/rst/bge_types/bge.types.KX_WorldInfo.rst M source/gameengine/Ketsji/KX_PythonInit.cpp M source/gameengine/Ketsji/KX_PythonInitTypes.cpp M source/gameengine/Ketsji/KX_Scene.cpp M source/gameengine/Ketsji/KX_Scene.h M source/gameengine/Ketsji/KX_WorldInfo.cpp M source/gameengine/Ketsji/KX_WorldInfo.h =================================================================== diff --git a/doc/python_api/rst/bge.render.rst b/doc/python_api/rst/bge.render.rst index 09d16f4..2d47244 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 fc5ba35..255ff95 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 0000000..ffc24b4 --- /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 8fd38db..b3fba74 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 828fd62..b3511e4 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 e26fdaa..193a72e 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_FUNC @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-blender-cvs
