JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
MaterialParam.h
Go to the documentation of this file.
1#ifndef __JBXL_MATERIAL_PARAM_H_
2#define __JBXL_MATERIAL_PARAM_H_
3
8#include "Vector.h"
9#include "Rotation.h"
10#include "buffer.h"
11
12// アルファチャンネル モード
13#define MATERIAL_ALPHA_NONE 0
14#define MATERIAL_ALPHA_BLENDING 1
15#define MATERIAL_ALPHA_MASKING 2
16#define MATERIAL_ALPHA_EMISSIVE 3 // 未実装
17
18// テクスチャのマッピング方法
19#define MATERIAL_MAPPING_DEFAULT 0
20#define MATERIAL_MAPPING_PLANAR 2
21#define MATERIAL_MAPPING_SPHERICAL 4 // 未実装
22#define MATERIAL_MAPPING_CYLINDRICAL 6 // 未実装
23
24//
25#define MATERIAL_ATTR_LEN 24 // Base64 string len = 32
26
27#define MATERIAL_ATTR_COLOR_RED 0
28#define MATERIAL_ATTR_COLOR_GREEN 1
29#define MATERIAL_ATTR_COLOR_BLUE 2
30#define MATERIAL_ATTR_TRANSPARENT 3
31#define MATERIAL_ATTR_ALPHACUTOFF 4
32#define MATERIAL_ATTR_SHININESS 5
33#define MATERIAL_ATTR_GLOW 6
34#define MATERIAL_ATTR_BRIGHT 7
35#define MATERIAL_ATTR_LIGHT 8
36#define MATERIAL_ATTR_ALPHAMODE 9
37// 10-12 予備
38#define MATERIAL_ATTR_SHIFT_U 13 // short 2Byte
39#define MATERIAL_ATTR_SHIFT_V 15 // short 2Byte
40#define MATERIAL_ATTR_SCALE_U 17 // short 2Byte
41#define MATERIAL_ATTR_SCALE_V 19 // short 2Byte
42#define MATERIAL_ATTR_ROTATE 21 // short 2Byte
43//
44#define MATERIAL_ATTR_OBJECT 23 //
45
46
47namespace jbxl {
48
49
51// TextureParam テクスチャ用パラメータ
52//
53
55{
56private:
58 double color[4];
59
62 double alphaCutoff;
63
64 double shiftU;
65 double shiftV;
66 double scaleU;
67 double scaleV;
68 double rotate;
69
70 bool flipU;
71 bool flipV;
72
73public:
74 TextureParam(void) { init();}
75 virtual ~TextureParam(void) {}
76
77 void init (void);
78 void free (void);
79 void clear(void) { free(); init();}
80
81 void dup(TextureParam m);
82
83 bool hasAlphaChannel(void) { return alphaChannel;}
84 bool isSetTexture(void) { return (name.buf!=NULL);}
85 bool isSetColor (void) { return (color[0]!=1.0 || color[1]!=1.0 || color[2]!=1.0 || color[3]!=1.0);}
86 //bool isSetAlpha (void) { return (alphaChannel && (alphaMode==MATERIAL_ALPHA_BLENDING || alphaMode==MATERIAL_ALPHA_MASKING));}
87 //bool isSetParams (void) { return (isSetColor() || isSetAlpha());}
88
89 bool isSetShift (void) { return (shiftU!=0.0 || shiftV!=0.0);}
90 bool isSetScale (void) { return (scaleU!=1.0 || scaleV!=1.0);}
91 bool isSetRotate (void) { return (rotate!=0.0);}
92
93 void setName(const char* nm) { free_Buffer(&name); if(nm!=NULL) name = make_Buffer_bystr(nm);}
94 char* getName(void) { return (char*)name.buf;}
95 void addName(const char* nm) { if(nm!=NULL) cat_s2Buffer(nm, &name);}
96
97 void setColor(double r, double g, double b, double a=1.0) { color[0] = r; color[1] = g; color[2] = b; color[3] = a;}
98 void setColor(double v, int c) { if(c<0) c = 0; else if(c>3) c = 3; color[c] = v;}
99 void setShiftU(double u) { shiftU = u;}
100 void setShiftV(double v) { shiftV = v;}
101 void setScaleU(double u) { scaleU = u;}
102 void setScaleV(double v) { scaleV = v;}
103 void setRotate(double r) { rotate = r;}
104 void setFlipU (bool f) { flipU = f;}
105 void setFlipV (bool f) { flipV = f;}
106 void setShift (double u, double v) { shiftU = u; shiftV = v;}
107 void setScale (double u, double v) { scaleU = u; scaleV = v;}
108
109 void setAlphaChannel(bool h) { alphaChannel = h;}
110 void setAlphaMode(int m) { alphaMode = m;}
111 void setAlphaCutoff(double m) { alphaCutoff = m;}
112
114 double getColor(int c) { if(c<0) c = 0; else if(c>3) c = 3; return color[c];}
115 double getTransparent(void) { return color[3];}
116 double getShiftU(void) { return shiftU;}
117 double getShiftV(void) { return shiftV;}
118 double getScaleU(void) { return scaleU;}
119 double getScaleV(void) { return scaleV;}
120 double getRotate(void) { return rotate;}
121
122 //bool getAlphaChannel(void) { return alphaChannel;}
123 int getAlphaMode(void) { if (color[3]<0.99) return MATERIAL_ALPHA_BLENDING; else return alphaMode;}
124 //int getAlphaMode(void) { return alphaMode;}
125 double getAlphaCutoff(void) { return alphaCutoff;}
126
127 void execTrans (UVMap<double>* uv, int n);
128 void execShift (UVMap<double>* uv, int n);
129 void execScale (UVMap<double>* uv, int n);
130 void execRotate(UVMap<double>* uv, int n);
131
132 void execInvTrans (UVMap<double>* uv, int n);
133 void execInvShift (UVMap<double>* uv, int n);
134 void execInvScale (UVMap<double>* uv, int n);
135 void execInvRotate(UVMap<double>* uv, int n);
136
137 void execFlipU(UVMap<double>* uv, int n) { for(int i=0; i<n; i++) uv[i].u = 1.0 - uv[i].u;}
138 void execFlipV(UVMap<double>* uv, int n) { for(int i=0; i<n; i++) uv[i].v = 1.0 - uv[i].v;}
139
140 void printParam(FILE* fp);
141};
142
143
144bool isSameTexture(TextureParam a, TextureParam b);
145
146
147
149// MaterialParam マテリアル用パラメータ
150//
151
153{
154private:
156
157 char kind;
158// double transparent; ///< テクスチャのアルファチャンネルの係数.
159 double shininess;
160 double glow;
161 double bright;
162
163 double glossiness;
165 double environment;
166 double light;
167
168public:
169 bool enable;
170
172 int mflags;
173 int others;
174
178
179public:
180 MaterialParam(void) { init();}
181 virtual ~MaterialParam(void) {}
182
183public:
184 void init (void);
185 void free (void);
186 void clear(void) { free(); init();}
187
188 void dup(MaterialParam m);
189
190 bool isSetTexture(void) { return texture.isSetTexture();}
191 bool isSetBumpMap(void) { return bumpmap.isSetTexture();}
192 bool isSetSpecMap(void) { return specmap.isSetTexture();}
193
194 //bool isSetTextureParams(void) { return (texture.isSetColor() || bumpmap.isSetColor() || specmap.isSetColor());}
195 //bool isSetParams (void) { return (isSetTransparent() || isSetGlow() || isSetShininess() || isSetBright());}
196
197 bool isSetGlow (void) { return (glow!=0.0);}
198 bool isSetBright (void) { return (bright!=0.0);}
199 bool isSetShininess (void) { return (shininess!=0.0);}
200 bool isSetTransparent(void) { return (texture.getColor(3)<0.99);}
201
203
204 void setTextureName(const char* name) { texture.setName(name);}
205 void setBumpMapName(const char* name) { bumpmap.setName(name);}
206 void setSpecMapName(const char* name) { specmap.setName(name);}
207
208 char* getTextureName(void) { return texture.getName();} // 禁 free
209 char* getBumpMapName(void) { return bumpmap.getName();} // 禁 free
210 char* getSpecMapName(void) { return specmap.getName();} // 禁 free
211 char* getName(void); // 禁 free
212
213 void setFullName(const char* extname);
214 void setParamString(const char* param) { if(param!=NULL) copy_s2Buffer(param, &paramstr);}
215 void addParamString(const char* param) { if(param!=NULL) cat_s2Buffer (param, &paramstr);}
216 char* getParamString(void) { return (char*)paramstr.buf;} // 禁 free
217
218 void setKind(char c) { kind = c;}
219// void setTransparent(double a) { if(a>1.0) a = 1.0; else if(a<0.0) a = 0.0; transparent = a;}
220 void setShininess(double s) { /*if(s>1.0) s = 1.0; else if(s<0.0) s = 0.0;*/ shininess = s;}
221 void setGlow(double g) { /*if(g>1.0) g = 1.0; else if(g<0.0) g = 0.0;*/ glow = g;}
222 void setBright(double b) { /*if(b>1.0) b = 1.0; else if(b<0.0) b = 0.0;*/ bright = b;}
223 void setGlossiness (double g) { /*if(g>1.0) g = 1.0; else if(g<0.0) g = 0.0;*/ glossiness = g;}
224 void setEnvironment(double e) { /*if(e>1.0) e = 1.0; else if(e<0.0) e = 0.0;*/ environment = e;}
225 void setSpecExp(double s) { /*if(s>1.0) l = 1.0; else if(s<0.0) l = 0.0;*/ speclightexp = s;}
226 void setLight(double l) { /*if(l>1.0) l = 1.0; else if(l<0.0) l = 0.0;*/ light = l;}
227
228 char getKind(void) { return kind;}
229 //double getTransparent(void);
230 double getShininess(void) { return shininess;}
231 double getGlow(void) { return glow;}
232 double getBright(void) { return bright;}
233 double getGlossiness (void) { return glossiness;}
234 double getEnvironment(void) { return environment;}
235 double getSpecExp(void ) { return speclightexp;}
236 double getLight(void) { return light;}
237
238 void printParam(FILE* fp);
239 char* getBase64Params(unsigned char cc='-');
240};
241
242
244
245bool isSameMaterial(MaterialParam a, MaterialParam b);
246
247
248} // namespace
249
250#endif
251
#define MATERIAL_ALPHA_BLENDING
回転・クォータニオン ライブラリ ヘッダ
ベクトルライブラリ for C++
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Definition buffer.cpp:128
Buffer型サポートヘッダ
#define copy_s2Buffer(src, dst)
copy_b2Buffer()
Definition buffer.h:108
#define cat_s2Buffer(src, dst)
cat_b2Buffer()
Definition buffer.h:122
#define make_Buffer_bystr(str)
set_Buffer()
Definition buffer.h:57
TextureParam bumpmap
Bumpmap テクスチャ
double bright
明るさ
double getSpecExp(void)
double glossiness
滑らかさ
double getGlossiness(void)
int mapping
マッピング方法
char * getBase64Params(unsigned char cc='-')
char kind
オブジェクトの種類.'O', 'T', 'G', 'E'
char * getParamString(void)
bool isTransparency(void)
bool isSetShininess(void)
void printParam(FILE *fp)
void setEnvironment(double e)
int mflags
メディアフラグ
double shininess
輝き
void setGlow(double g)
void setFullName(const char *extname)
void setParamString(const char *param)
void setTextureName(const char *name)
void setSpecMapName(const char *name)
double getLight(void)
void addParamString(const char *param)
void setLight(double l)
char * getBumpMapName(void)
double getBright(void)
double speclightexp
SpecularLightExponents.
double getEnvironment(void)
void setSpecExp(double s)
double light
周りを照らすライト
int others
その他のフラグ
void setBumpMapName(const char *name)
char * getTextureName(void)
Buffer paramstr
パラメータ文字列 (Base64文字列)
TextureParam texture
テクスチャ
bool isSetTransparent(void)
double getShininess(void)
void setGlossiness(double g)
virtual ~MaterialParam(void)
void setBright(double b)
double environment
環境光
char * getSpecMapName(void)
void dup(MaterialParam m)
void setShininess(double s)
TextureParam specmap
Specular マップ テクスチャ
double alphaCutoff
アルファチャンネルの Cutoff値.alphaMode==MATERIAL_ALPHA_MASKING の場合に有効
void execFlipV(UVMap< double > *uv, int n)
double scaleV
UVマップのスケール (V方向)
bool isSetRotate(void)
char * getName(void)
double color[4]
RGBA.
void addName(const char *nm)
void setScaleU(double u)
void setScaleV(double v)
int alphaMode
アルファチャンネルのモード
void execInvShift(UVMap< double > *uv, int n)
void setColor(double r, double g, double b, double a=1.0)
void setColor(double v, int c)
void setScale(double u, double v)
void printParam(FILE *fp)
bool alphaChannel
テクスチャデータがアルファチャンネルを持っているかどうか.
bool flipV
UVマップで V方向の反転を行うか
void setShiftV(double v)
double shiftV
UVマップのシフト (V方向)
void setName(const char *nm)
void execShift(UVMap< double > *uv, int n)
double scaleU
UVマップのスケール (U方向)
void setAlphaCutoff(double m)
virtual ~TextureParam(void)
double getShiftU(void)
bool isSetColor(void)
void setShiftU(double u)
void setShift(double u, double v)
void setAlphaChannel(bool h)
bool isSetScale(void)
Buffer name
テクスチャ名
bool isSetTexture(void)
double getAlphaCutoff(void)
double getRotate(void)
bool hasAlphaChannel(void)
void setAlphaMode(int m)
double rotate
UVマップの回転
bool isSetShift(void)
void execInvTrans(UVMap< double > *uv, int n)
Shift -> Scale -> Rotate.
Vector< double > getColor(void)
void dup(TextureParam m)
void execFlipU(UVMap< double > *uv, int n)
void execInvScale(UVMap< double > *uv, int n)
void setFlipU(bool f)
double getScaleU(void)
void execInvRotate(UVMap< double > *uv, int n)
void setFlipV(bool f)
void execRotate(UVMap< double > *uv, int n)
void setRotate(double r)
double getShiftV(void)
double getColor(int c)
double getScaleV(void)
void execTrans(UVMap< double > *uv, int n)
Rotate -> Scale -> Shift.
double shiftU
UVマップのシフト (U方向)
bool flipU
UVマップで U方向の反転を行うか
double getTransparent(void)
void execScale(UVMap< double > *uv, int n)
Definition Brep.h:29
MaterialParam * newMaterialParam(MaterialParam p)
bool isSameMaterial(MaterialParam a, MaterialParam b)
compare each texture names and colors
bool isSameTexture(TextureParam a, TextureParam b)
compare texture ma,e and color
unsigned char * buf
バッファの先頭へのポインタ.str[bufsz]は必ず 0x00となる.
Definition buffer.h:39