Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_BlenderMaterial.h
| Context not available. | |||||
| #ifndef __KX_BLENDERMATERIAL_H__ | #ifndef __KX_BLENDERMATERIAL_H__ | ||||
| #define __KX_BLENDERMATERIAL_H__ | #define __KX_BLENDERMATERIAL_H__ | ||||
| #include <vector> | |||||
| #include "RAS_IPolygonMaterial.h" | #include "RAS_IPolygonMaterial.h" | ||||
| #include "BL_Material.h" | |||||
| #include "BL_Texture.h" | #include "BL_Texture.h" | ||||
| #include "BL_Shader.h" | |||||
| #include "BL_BlenderShader.h" | |||||
| #include "EXP_PyObjectPlus.h" | #include "EXP_Value.h" | ||||
| #include "MT_Vector3.h" | #include "MT_Vector3.h" | ||||
| #include "MT_Vector4.h" | #include "MT_Vector4.h" | ||||
| Context not available. | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #endif | #endif | ||||
| #include "SCA_IScene.h" /* only for Replace_IScene */ | class SCA_IScene; | ||||
| #include "KX_Scene.h" | |||||
| struct MTFace; | |||||
| class KX_Scene; | class KX_Scene; | ||||
| class BL_BlenderShader; | |||||
| class BL_Shader; | |||||
| struct Material; | |||||
| struct MTFace; | |||||
| #ifdef USE_MATHUTILS | #ifdef USE_MATHUTILS | ||||
| void KX_BlenderMaterial_Mathutils_Callback_Init(void); | void KX_BlenderMaterial_Mathutils_Callback_Init(void); | ||||
| #endif | #endif | ||||
| class KX_BlenderMaterial : public PyObjectPlus, public RAS_IPolyMaterial | class KX_BlenderMaterial : public CValue, public RAS_IPolyMaterial | ||||
| { | { | ||||
| Py_Header | Py_Header | ||||
| public: | public: | ||||
| // -------------------------------- | KX_BlenderMaterial( | ||||
| KX_BlenderMaterial(); | KX_Scene *scene, | ||||
| void Initialize( | Material *mat, | ||||
| class KX_Scene* scene, | GameSettings *game, | ||||
| BL_Material* mat, | MTFace *mtface, | ||||
| GameSettings* game, | int lightlayer); | ||||
| int lightlayer | |||||
| ); | |||||
| virtual ~KX_BlenderMaterial(); | virtual ~KX_BlenderMaterial(); | ||||
| // -------------------------------- | virtual void Activate(RAS_IRasterizer *rasty); | ||||
| virtual TCachingInfo GetCachingInfo(void) const { | virtual void Desactivate(RAS_IRasterizer *rasty); | ||||
| return (void*) this; | virtual void ActivateInstancing(RAS_IRasterizer *rasty, void *matrixoffset, void *positionoffset, void *coloroffset, unsigned int stride); | ||||
| } | virtual void DesactivateInstancing(); | ||||
| virtual void ActivateMeshSlot(RAS_MeshSlot *ms, RAS_IRasterizer *rasty); | |||||
| virtual | |||||
| bool Activate( | void ActivateShaders(RAS_IRasterizer *rasty); | ||||
| RAS_IRasterizer* rasty, | |||||
| TCachingInfo& cachingInfo | void ActivateBlenderShaders(RAS_IRasterizer *rasty); | ||||
| ) const; | |||||
| virtual bool UseInstancing() const; | |||||
| virtual | virtual const std::string GetTextureName() const; | ||||
| void ActivateMeshSlot( | virtual Material *GetBlenderMaterial() const; | ||||
| const RAS_MeshSlot & ms, | virtual Image *GetBlenderImage() const; | ||||
| RAS_IRasterizer* rasty | virtual MTexPoly *GetMTexPoly() const; | ||||
| ) const; | virtual bool UsesLighting(RAS_IRasterizer *rasty) const; | ||||
| virtual void GetRGBAColor(unsigned char *rgba) const; | |||||
| void ActivateMat( | virtual Scene *GetBlenderScene() const; | ||||
| RAS_IRasterizer* rasty, | virtual SCA_IScene *GetScene() const; | ||||
| TCachingInfo& cachingInfo | virtual void ReleaseMaterial(); | ||||
| )const; | |||||
| unsigned int *GetBlendFunc() | |||||
| void ActivatShaders( | { | ||||
| RAS_IRasterizer* rasty, | return m_blendFunc; | ||||
| TCachingInfo& cachingInfo | |||||
| )const; | |||||
| void ActivateBlenderShaders( | |||||
| RAS_IRasterizer* rasty, | |||||
| TCachingInfo& cachingInfo | |||||
| )const; | |||||
| Material* GetBlenderMaterial() const; | |||||
| Image* GetBlenderImage() const; | |||||
| MTexPoly *GetMTexPoly() const; | |||||
| unsigned int* GetMCol() const; | |||||
| BL_Texture * getTex (unsigned int idx) { | |||||
| return (idx < MAXTEX) ? mTextures + idx : NULL; | |||||
| } | |||||
| Image * getImage (unsigned int idx) { | |||||
| return (idx < MAXTEX && mMaterial) ? mMaterial->img[idx] : NULL; | |||||
| } | |||||
| unsigned int* getBlendFunc() { | |||||
| return mBlendFunc; | |||||
| } | } | ||||
| // for ipos | // for ipos | ||||
| void UpdateIPO( | virtual void UpdateIPO(MT_Vector4 rgba, MT_Vector3 specrgb, MT_Scalar hard, MT_Scalar spec, MT_Scalar ref, | ||||
| MT_Vector4 rgba, MT_Vector3 specrgb, | MT_Scalar emit, MT_Scalar ambient, MT_Scalar alpha, MT_Scalar specalpha); | ||||
| MT_Scalar hard, MT_Scalar spec, | |||||
| MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha | virtual const RAS_IRasterizer::AttribLayerList GetAttribLayers(const RAS_MeshObject::LayersInfo& layersInfo) const; | ||||
| ); | |||||
| virtual void Replace_IScene(SCA_IScene *val); | virtual void Replace_IScene(SCA_IScene *val); | ||||
| BL_Material *GetBLMaterial(); | // Stuff for cvalue related things. | ||||
| virtual std::string GetName(); | |||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| // -------------------------------- | |||||
| virtual PyObject *py_repr(void) { return PyUnicode_From_STR_String(mMaterial->matname); } | |||||
| static PyObject *pyattr_get_shader(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_shader(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static PyObject *pyattr_get_materialIndex(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_materialIndex(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static PyObject *pyattr_get_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static int pyattr_set_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | static PyObject *pyattr_get_textures(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static int pyattr_set_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | |||||
| static PyObject *pyattr_get_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static int pyattr_set_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | static int pyattr_set_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | ||||
| static PyObject *pyattr_get_hardness(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_hardness(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static int pyattr_set_hardness(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | static int pyattr_set_hardness(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | ||||
| static PyObject *pyattr_get_specular_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_specular_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static int pyattr_set_specular_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | static int pyattr_set_specular_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | ||||
| static PyObject *pyattr_get_specular_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_specular_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static int pyattr_set_specular_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | static int pyattr_set_specular_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | ||||
| static PyObject *pyattr_get_diffuse_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_diffuse_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static int pyattr_set_diffuse_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | static int pyattr_set_diffuse_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | ||||
| static PyObject *pyattr_get_diffuse_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_diffuse_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static int pyattr_set_diffuse_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | static int pyattr_set_diffuse_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | ||||
| static PyObject *pyattr_get_emit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | static PyObject *pyattr_get_emit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | ||||
| static int pyattr_set_emit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | static int pyattr_set_emit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | ||||
| static PyObject *pyattr_get_ambient(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | |||||
| static int pyattr_set_ambient(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | |||||
| static PyObject *pyattr_get_specular_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); | |||||
| static int pyattr_set_specular_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); | |||||
| KX_PYMETHOD_DOC(KX_BlenderMaterial, getShader); | KX_PYMETHOD_DOC(KX_BlenderMaterial, getShader); | ||||
| KX_PYMETHOD_DOC(KX_BlenderMaterial, getMaterialIndex); | |||||
| KX_PYMETHOD_DOC(KX_BlenderMaterial, getTexture); | |||||
| KX_PYMETHOD_DOC(KX_BlenderMaterial, setTexture); | |||||
| KX_PYMETHOD_DOC(KX_BlenderMaterial, getTextureBindcode); | KX_PYMETHOD_DOC(KX_BlenderMaterial, getTextureBindcode); | ||||
| KX_PYMETHOD_DOC(KX_BlenderMaterial, setBlending); | KX_PYMETHOD_DOC(KX_BlenderMaterial, setBlending); | ||||
| #endif /* WITH_PYTHON */ | |||||
| // -------------------------------- | #endif // WITH_PYTHON | ||||
| // pre calculate to avoid pops/lag at startup | // pre calculate to avoid pops/lag at startup | ||||
| virtual void OnConstruction(); | virtual void OnConstruction(); | ||||
| static void EndFrame(); | static void EndFrame(RAS_IRasterizer *rasty); | ||||
| private: | private: | ||||
| BL_Material* mMaterial; | Material *m_material; | ||||
| BL_Shader* mShader; | MTexPoly *m_mtexPoly; | ||||
| BL_BlenderShader* mBlenderShader; | BL_Shader *m_shader; | ||||
| KX_Scene* mScene; | BL_BlenderShader *m_blenderShader; | ||||
| BL_Texture mTextures[MAXTEX]; // texture array | KX_Scene *m_scene; | ||||
| bool mUserDefBlend; | bool m_userDefBlend; | ||||
| unsigned int mBlendFunc[2]; | unsigned int m_blendFunc[2]; | ||||
| bool mModified; | bool m_constructed; // if false, don't clean on exit | ||||
| bool mConstructed; // if false, don't clean on exit | int m_lightLayer; | ||||
| int mLightLayer; | |||||
| struct { | struct { | ||||
| float r, g, b, a; | float r, g, b, a; | ||||
| Context not available. | |||||
| float ref; | float ref; | ||||
| float hardness; | float hardness; | ||||
| float emit; | float emit; | ||||
| } mSavedData; | float ambient; | ||||
| float specularalpha; | |||||
| } m_savedData; | |||||
| void InitTextures(); | void InitTextures(); | ||||
| void SetBlenderGLSLShader(); | void SetBlenderGLSLShader(); | ||||
| void ActivatGLMaterials( RAS_IRasterizer* rasty )const; | void ActivateGLMaterials(RAS_IRasterizer *rasty) const; | ||||
| void ActivateTexGen( RAS_IRasterizer *ras ) const; | void ActivateTexGen(RAS_IRasterizer *ras) const; | ||||
| bool UsesLighting(RAS_IRasterizer *rasty) const; | |||||
| void GetMaterialRGBAColor(unsigned char *rgba) const; | |||||
| Scene* GetBlenderScene() const; | |||||
| void ReleaseMaterial(); | |||||
| // message centers | void SetBlenderShaderData(RAS_IRasterizer *ras); | ||||
| void setTexData( bool enable,RAS_IRasterizer *ras); | void SetShaderData(RAS_IRasterizer *ras); | ||||
| void setBlenderShaderData( bool enable, RAS_IRasterizer *ras); | |||||
| void setShaderData( bool enable, RAS_IRasterizer *ras); | |||||
| void setObjectMatrixData(int i, RAS_IRasterizer *ras); | |||||
| void setTexMatrixData(int i); | |||||
| void setLightData(); | |||||
| // cleanup stuff | // cleanup stuff | ||||
| void OnExit(); | void OnExit(); | ||||
| // shader chacing | |||||
| static BL_BlenderShader *mLastBlenderShader; | |||||
| static BL_Shader *mLastShader; | |||||
| mutable int mPass; | |||||
| }; | }; | ||||
| #ifdef WITH_PYTHON | |||||
| bool ConvertPythonToMaterial(PyObject *value, KX_BlenderMaterial **material, bool py_none_ok, const char *error_prefix); | |||||
| #endif // WITH_PYTHON | |||||
| #endif | #endif | ||||
| Context not available. | |||||