Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_WorldInfo.cpp
| Show All 26 Lines | |||||
| /** \file gameengine/Ketsji/KX_WorldInfo.cpp | /** \file gameengine/Ketsji/KX_WorldInfo.cpp | ||||
| * \ingroup ketsji | * \ingroup ketsji | ||||
| */ | */ | ||||
| #include "KX_WorldInfo.h" | #include "KX_WorldInfo.h" | ||||
| #include "KX_PythonInit.h" | #include "KX_PythonInit.h" | ||||
| #include "KX_PyMath.h" | |||||
| #include "RAS_IRasterizer.h" | |||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| /* This little block needed for linking to Blender... */ | /* This little block needed for linking to Blender... */ | ||||
| #ifdef WIN32 | #ifdef WIN32 | ||||
| #include "BLI_winstuff.h" | #include "BLI_winstuff.h" | ||||
| #endif | #endif | ||||
| /* This list includes only data type definitions */ | /* This list includes only data type definitions */ | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_world_types.h" | #include "DNA_world_types.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| /* end of blender include block */ | /* end of blender include block */ | ||||
| KX_WorldInfo::KX_WorldInfo(Scene *blenderscene, World *blenderworld) | KX_WorldInfo::KX_WorldInfo(Scene *blenderscene, World *blenderworld) | ||||
| { | { | ||||
| if (blenderworld) { | if (blenderworld) { | ||||
| m_name = blenderworld->id.name + 2; | |||||
| m_do_color_management = BKE_scene_check_color_management_enabled(blenderscene); | m_do_color_management = BKE_scene_check_color_management_enabled(blenderscene); | ||||
| m_hasworld = true; | m_hasworld = true; | ||||
| m_hasmist = ((blenderworld->mode) & WO_MIST ? true : false); | m_hasmist = ((blenderworld->mode) & WO_MIST ? true : false); | ||||
| m_misttype = blenderworld->mistype; | m_misttype = blenderworld->mistype; | ||||
| m_miststart = blenderworld->miststa; | m_miststart = blenderworld->miststa; | ||||
| m_mistdistance = blenderworld->mistdist; | m_mistdistance = blenderworld->mistdist; | ||||
| m_mistintensity = blenderworld->misi; | m_mistintensity = blenderworld->misi; | ||||
| setMistColor(blenderworld->horr, blenderworld->horg, blenderworld->horb); | setMistColor(blenderworld->horr, blenderworld->horg, blenderworld->horb); | ||||
| setBackColor(blenderworld->horr, blenderworld->horg, blenderworld->horb); | setBackColor(blenderworld->horr, blenderworld->horg, blenderworld->horb); | ||||
| setAmbientColor(blenderworld->ambr, blenderworld->ambg, blenderworld->ambb); | setAmbientColor(blenderworld->ambr, blenderworld->ambg, blenderworld->ambb); | ||||
| } | } | ||||
| else { | else { | ||||
| m_hasworld = false; | m_hasworld = false; | ||||
| } | } | ||||
| } | } | ||||
| KX_WorldInfo::~KX_WorldInfo() | KX_WorldInfo::~KX_WorldInfo() | ||||
| { | { | ||||
| } | } | ||||
| const STR_String& KX_WorldInfo::GetName() | |||||
| { | |||||
| return m_name; | |||||
| } | |||||
| bool KX_WorldInfo::hasWorld() | bool KX_WorldInfo::hasWorld() | ||||
| { | { | ||||
| return m_hasworld; | return m_hasworld; | ||||
| } | } | ||||
| bool KX_WorldInfo::hasMist() | bool KX_WorldInfo::hasMist() | ||||
| { | { | ||||
| return m_hasmist; | return m_hasmist; | ||||
| ▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | if (m_rasterizer->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID) { | ||||
| } | } | ||||
| else { | else { | ||||
| m_rasterizer->EnableFog(false); | m_rasterizer->EnableFog(false); | ||||
| GPU_mist_update_enable(false); | GPU_mist_update_enable(false); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #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 */ | |||||