1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/** \file KX_BlenderMaterial.h
* \ingroup ketsji
*/
#ifndef __KX_BLENDERMATERIAL_H__
#define __KX_BLENDERMATERIAL_H__
#include <vector>
#include "RAS_IPolygonMaterial.h"
#include "BL_Material.h"
#include "BL_Texture.h"
#include "BL_Shader.h"
#include "BL_BlenderShader.h"
#include "EXP_PyObjectPlus.h"
#include "MT_Vector3.h"
#include "MT_Vector4.h"
#ifdef WITH_CXX_GUARDEDALLOC
#include "MEM_guardedalloc.h"
#endif
#include "SCA_IScene.h" /* only for Replace_IScene */
#include "KX_Scene.h"
struct MTFace;
class KX_Scene;
#ifdef USE_MATHUTILS
void KX_BlenderMaterial_Mathutils_Callback_Init(void);
#endif
class KX_BlenderMaterial : public PyObjectPlus, public RAS_IPolyMaterial
{
Py_Header
public:
// --------------------------------
KX_BlenderMaterial();
void Initialize(
class KX_Scene* scene,
BL_Material* mat,
GameSettings* game,
int lightlayer
);
virtual ~KX_BlenderMaterial();
// --------------------------------
virtual TCachingInfo GetCachingInfo(void) const {
return (void*) this;
}
virtual
bool Activate(
RAS_IRasterizer* rasty,
TCachingInfo& cachingInfo
) const;
virtual
void ActivateMeshSlot(
const RAS_MeshSlot & ms,
RAS_IRasterizer* rasty
) const;
void ActivateMat(
RAS_IRasterizer* rasty,
TCachingInfo& cachingInfo
)const;
void ActivatShaders(
RAS_IRasterizer* rasty,
TCachingInfo& cachingInfo
)const;
void ActivateBlenderShaders(
RAS_IRasterizer* rasty,
TCachingInfo& cachingInfo
)const;
Material* GetBlenderMaterial() const;
Image* GetBlenderImage() const;
MTFace* GetMTFace() 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
void UpdateIPO(
MT_Vector4 rgba, MT_Vector3 specrgb,
MT_Scalar hard, MT_Scalar spec,
MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha
);
virtual void Replace_IScene(SCA_IScene *val);
BL_Material *GetBLMaterial();
#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_materialIndex(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_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 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 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 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 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 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 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);
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, setBlending);
#endif /* WITH_PYTHON */
// --------------------------------
// pre calculate to avoid pops/lag at startup
virtual void OnConstruction();
static void EndFrame();
private:
BL_Material* mMaterial;
BL_Shader* mShader;
BL_BlenderShader* mBlenderShader;
KX_Scene* mScene;
BL_Texture mTextures[MAXTEX]; // texture array
bool mUserDefBlend;
unsigned int mBlendFunc[2];
bool mModified;
bool mConstructed; // if false, don't clean on exit
int mLightLayer;
struct {
float r, g, b, a;
float specr, specg, specb;
float spec;
float ref;
float hardness;
float emit;
} mSavedData;
void InitTextures();
void SetBlenderGLSLShader();
void ActivatGLMaterials( RAS_IRasterizer* rasty )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 setTexData( bool enable,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
void OnExit();
// shader chacing
static BL_BlenderShader *mLastBlenderShader;
static BL_Shader *mLastShader;
mutable int mPass;
};
#endif
|