LEFT | RIGHT |
1 | 1 |
2 /** \file KX_BlenderMaterial.h | 2 /** \file KX_BlenderMaterial.h |
3 * \ingroup ketsji | 3 * \ingroup ketsji |
4 */ | 4 */ |
5 | 5 |
6 #ifndef __KX_BLENDER_MATERIAL_H__ | 6 #ifndef __KX_BLENDERMATERIAL_H__ |
7 #define __KX_BLENDER_MATERIAL_H__ | 7 #define __KX_BLENDERMATERIAL_H__ |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 | 11 |
12 #include "RAS_IPolygonMaterial.h" | 12 #include "RAS_IPolygonMaterial.h" |
13 #include "BL_Material.h" | 13 #include "BL_Material.h" |
14 #include "BL_Texture.h" | 14 #include "BL_Texture.h" |
15 #include "BL_Shader.h" | 15 #include "BL_Shader.h" |
16 #include "BL_BlenderShader.h" | 16 #include "BL_BlenderShader.h" |
17 | 17 |
18 #include "PyObjectPlus.h" | 18 #include "PyObjectPlus.h" |
19 | 19 |
20 #include "MT_Vector3.h" | 20 #include "MT_Vector3.h" |
21 #include "MT_Vector4.h" | 21 #include "MT_Vector4.h" |
22 | 22 |
23 #ifdef WITH_CXX_GUARDEDALLOC | 23 #ifdef WITH_CXX_GUARDEDALLOC |
24 #include "MEM_guardedalloc.h" | 24 #include "MEM_guardedalloc.h" |
25 #endif | 25 #endif |
26 | 26 |
27 #include "SCA_IScene.h" /* only for Replace_IScene */ | 27 #include "SCA_IScene.h" /* only for Replace_IScene */ |
28 #include "KX_Scene.h" | 28 #include "KX_Scene.h" |
29 | 29 |
30 struct MTFace; | 30 struct MTFace; |
31 class KX_Scene; | 31 class KX_Scene; |
32 | 32 |
33 class KX_BlenderMaterial : public PyObjectPlus, public RAS_IPolyMaterial | 33 class KX_BlenderMaterial : public PyObjectPlus, public RAS_IPolyMaterial |
34 { | 34 { |
35 » Py_Header; | 35 » Py_Header |
36 public: | 36 public: |
37 // -------------------------------- | 37 // -------------------------------- |
38 KX_BlenderMaterial(); | 38 KX_BlenderMaterial(); |
39 void Initialize( | 39 void Initialize( |
40 class KX_Scene* scene, | 40 class KX_Scene* scene, |
41 » » BL_Material*» mat, | 41 » » BL_Material*» mat |
42 » » GameSettings*» game | |
43 ); | 42 ); |
44 | 43 |
45 virtual ~KX_BlenderMaterial(); | 44 virtual ~KX_BlenderMaterial(); |
46 | |
47 // -------------------------------- | |
48 virtual TCachingInfo GetCachingInfo(void) const { | |
49 return (void*) this; | |
50 } | |
51 | |
52 virtual· | |
53 bool Activate( | |
54 RAS_IRasterizer* rasty,· | |
55 TCachingInfo& cachingInfo | |
56 ) const; | |
57 ········ | |
58 virtual· | |
59 void ActivateMeshSlot( | |
60 const RAS_MeshSlot & ms,· | |
61 RAS_IRasterizer* rasty· | |
62 ) const; | |
63 ········ | |
64 void ActivateMat( | |
65 RAS_IRasterizer* rasty, | |
66 TCachingInfo& cachingInfo | |
67 )const; | |
68 | |
69 void ActivatShaders( | |
70 RAS_IRasterizer* rasty,· | |
71 TCachingInfo& cachingInfo | |
72 )const; | |
73 | |
74 void ActivateBlenderShaders( | |
75 RAS_IRasterizer* rasty,· | |
76 TCachingInfo& cachingInfo | |
77 )const; | |
78 | |
79 Material* GetBlenderMaterial() const; | |
80 MTFace* GetMTFace(void) const; | |
81 unsigned int* GetMCol(void) const; | |
82 BL_Texture * getTex (unsigned int idx) {· | |
83 return (idx < MAXTEX) ? mTextures + idx : NULL;· | |
84 } | |
85 Image * getImage (unsigned int idx) {· | |
86 return (idx < MAXTEX && mMaterial) ? mMaterial->img[idx] : NULL;······· | |
87 } | |
88 unsigned int* getBlendFunc() { | |
89 return mBlendFunc; | |
90 } | |
91 // for ipos | |
92 void UpdateIPO( | |
93 MT_Vector4 rgba, MT_Vector3 specrgb, | |
94 MT_Scalar hard, MT_Scalar spec, | |
95 MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha | |
96 ); | |
97 ········ | |
98 virtual void Replace_IScene(SCA_IScene *val) | |
99 { | |
100 mScene= static_cast<KX_Scene *>(val); | |
101 if (mBlenderShader) | |
102 { | |
103 mBlenderShader->SetScene(mScene); | |
104 } | |
105 }; | |
106 | |
107 #ifdef WITH_PYTHON | |
108 // -------------------------------- | |
109 virtual PyObject* py_repr(void) { return PyUnicode_FromString(mMaterial-
>matname.ReadPtr()); } | |
110 | |
111 static PyObject* pyattr_get_shader(void *self_v, const KX_PYATTRIBUTE_DE
F *attrdef); | |
112 static PyObject* pyattr_get_materialIndex(void *self_v, const KX_PYATTRI
BUTE_DEF *attrdef); | |
113 static PyObject* pyattr_get_blending(void *self_v, const KX_PYATTRIBUTE_
DEF *attrdef); | |
114 static int pyattr_set_blending(void *self_v, const KX_PYATTRIBUTE_
DEF *attrdef, PyObject *value); | |
115 | |
116 KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader ); | |
117 KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex ); | |
118 KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture ); | |
119 KX_PYMETHOD_DOC( KX_BlenderMaterial, setTexture ); | |
120 | |
121 KX_PYMETHOD_DOC( KX_BlenderMaterial, setBlending ); | |
122 #endif // WITH_PYTHON | |
123 | |
124 // -------------------------------- | |
125 // pre calculate to avoid pops/lag at startup | |
126 virtual void OnConstruction(int layer); | |
127 | |
128 static void EndFrame(); | |
129 | |
130 private: | |
131 BL_Material* mMaterial; | |
132 BL_Shader* mShader; | |
133 BL_BlenderShader* mBlenderShader; | |
134 KX_Scene* mScene; | |
135 BL_Texture mTextures[MAXTEX]; // texture array | |
136 bool mUserDefBlend; | |
137 unsigned int mBlendFunc[2]; | |
138 bool mModified; | |
139 bool mConstructed; // if false, don
't clean on exit | |
140 | |
141 void SetBlenderGLSLShader(int layer); | |
142 | |
143 void ActivatGLMaterials( RAS_IRasterizer* rasty )const; | |
144 void ActivateTexGen( RAS_IRasterizer *ras ) const; | |
145 | |
146 bool UsesLighting(RAS_IRasterizer *rasty) const; | |
147 void GetMaterialRGBAColor(unsigned char *rgba) const; | |
148 Scene* GetBlenderScene() const; | |
149 void ReleaseMaterial(); | |
150 | |
151 // message centers | |
152 void setTexData( bool enable,RAS_IRasterizer *ras); | |
153 void setBlenderShaderData( bool enable, RAS_IRasterizer *ras); | |
154 void setShaderData( bool enable, RAS_IRasterizer *ras); | |
155 | |
156 void setObjectMatrixData(int i, RAS_IRasterizer *ras); | |
157 void setTexMatrixData(int i); | |
158 | |
159 void setLightData(); | |
160 | |
161 // cleanup stuff | |
162 void OnExit(); | |
163 | |
164 // shader chacing | |
165 static BL_BlenderShader *mLastBlenderShader; | |
166 static BL_Shader *mLastShader; | |
167 | |
168 mutable int mPass; | |
169 }; | |
170 | |
171 | |
172 #endif | |
LEFT | RIGHT |