00001 #ifndef __JBXL_MATERIAL_PARAM_H_
00002 #define __JBXL_MATERIAL_PARAM_H_
00003
00009 #include "Vector.h"
00010 #include "Rotation.h"
00011 #include "buffer.h"
00012
00013
00014
00015 #define MATERIAL_ALPHA_NONE 0
00016 #define MATERIAL_ALPHA_BLENDING 1
00017 #define MATERIAL_ALPHA_MASKING 2
00018 #define MATERIAL_ALPHA_EMISSIVE 3 // 未実装
00019
00020
00021
00022 #define MATERIAL_MAPPING_DEFAULT 0
00023 #define MATERIAL_MAPPING_PLANAR 2
00024 #define MATERIAL_MAPPING_SPHERICAL 4 // 未実装
00025 #define MATERIAL_MAPPING_CYLINDRICAL 6 // 未実装
00026
00027
00028
00029 #define MATERIAL_ATTR_LEN 24 // Base64 string len = 32
00030
00031 #define MATERIAL_ATTR_COLOR_RED 0
00032 #define MATERIAL_ATTR_COLOR_GREEN 1
00033 #define MATERIAL_ATTR_COLOR_BLUE 2
00034 #define MATERIAL_ATTR_TRANSPARENT 3
00035 #define MATERIAL_ATTR_ALPHACUTOFF 4
00036 #define MATERIAL_ATTR_SHININESS 5
00037 #define MATERIAL_ATTR_GLOW 6
00038 #define MATERIAL_ATTR_BRIGHT 7
00039 #define MATERIAL_ATTR_LIGHT 8
00040
00041 #define MATERIAL_ATTR_SHIFT_U 13 // short 2Byte
00042 #define MATERIAL_ATTR_SHIFT_V 15 // short 2Byte
00043 #define MATERIAL_ATTR_SCALE_U 17 // short 2Byte
00044 #define MATERIAL_ATTR_SCALE_V 19 // short 2Byte
00045 #define MATERIAL_ATTR_ROTATE 21 // short 2Byte
00046 #define MATERIAL_ATTR_OBJECT 23 //
00047
00048
00049
00050 namespace jbxl {
00051
00052
00054
00055
00056
00057 class TextureParam
00058 {
00059 private:
00060 Buffer name;
00061
00062 double color[4];
00063
00064 bool alphaChannel;
00065 int alphaMode;
00066 double alphaCutoff;
00067
00068 double shiftU;
00069 double shiftV;
00070 double scaleU;
00071 double scaleV;
00072 double rotate;
00073
00074 bool flipU;
00075 bool flipV;
00076
00077 public:
00078 TextureParam(void) {}
00079 virtual ~TextureParam(void) {}
00080
00081 void init (void);
00082 void free (void);
00083 void clear(void) { free(); init();}
00084
00085 void dup(TextureParam m);
00086
00087 bool isSetTexture(void) { return (name.buf!=NULL);}
00088 bool isSetColor (void) { return (color[0]!=1.0 || color[1]!=1.0 || color[2]!=1.0 || color[3]!=1.0);}
00089 bool isSetAlpha (void) { return (alphaChannel && (alphaMode==MATERIAL_ALPHA_BLENDING||alphaMode==MATERIAL_ALPHA_MASKING));}
00090 bool isSetParams (void) { return (isSetColor() || isSetAlpha());}
00091
00092 bool isSetShift (void) { return (shiftU!=0.0 || shiftV!=0.0);}
00093 bool isSetScale (void) { return (scaleU!=1.0 || scaleV!=1.0);}
00094 bool isSetRotate (void) { return (rotate!=0.0);}
00095
00096 void setName(const char* nm) { free_Buffer(&name); if(nm!=NULL) name = make_Buffer_bystr(nm);}
00097 char* getName(void) { return (char*)name.buf;}
00098 void addName(const char* nm) { if(nm!=NULL) cat_s2Buffer(nm, &name);}
00099
00100 void setColor(double r, double g, double b, double a=1.0) { color[0] = r; color[1] = g; color[2] = b; color[3] = a;}
00101 void setColor(double v, int c) { if(c<0) c = 0; else if(c>3) c = 3; color[c] = v;}
00102 void setShiftU(double u) { shiftU = u;}
00103 void setShiftV(double v) { shiftV = v;}
00104 void setScaleU(double u) { scaleU = u;}
00105 void setScaleV(double v) { scaleV = v;}
00106 void setRotate(double r) { rotate = r;}
00107 void setFlipU (bool f) { flipU = f;}
00108 void setFlipV (bool f) { flipV = f;}
00109 void setShift (double u, double v) { shiftU = u; shiftV = v;}
00110 void setScale (double u, double v) { scaleU = u; scaleV = v;}
00111
00112 void setAlphaChannel(bool h) { alphaChannel = h;}
00113 void setAlphaMode(int m) { alphaMode = m;}
00114 void setAlphaCutoff(double m) { alphaCutoff = m;}
00115
00116 double getColor(int c) { if(c<0) c = 0; else if(c>3) c = 3; return color[c];}
00117 double getShiftU(void) { return shiftU;}
00118 double getShiftV(void) { return shiftV;}
00119 double getScaleU(void) { return scaleU;}
00120 double getScaleV(void) { return scaleV;}
00121 double getRotate(void) { return rotate;}
00122
00123 bool getAlphaChannel(void) { return alphaChannel;}
00124 int getAlphaMode(void) { if (color[3]<0.99) return MATERIAL_ALPHA_BLENDING; else return alphaMode;}
00125 double getAlphaCutoff(void) { return alphaCutoff;}
00126
00127 void execTrans (UVMap<double>* uv, int n);
00128 void execShift (UVMap<double>* uv, int n);
00129 void execScale (UVMap<double>* uv, int n);
00130 void execRotate(UVMap<double>* uv, int n);
00131
00132 void execInvTrans (UVMap<double>* uv, int n);
00133 void execInvShift (UVMap<double>* uv, int n);
00134 void execInvScale (UVMap<double>* uv, int n);
00135 void execInvRotate(UVMap<double>* uv, int n);
00136
00137 void execFlipU(UVMap<double>* uv, int n) { for(int i=0; i<n; i++) uv[i].u = 1.0 - uv[i].u;}
00138 void execFlipV(UVMap<double>* uv, int n) { for(int i=0; i<n; i++) uv[i].v = 1.0 - uv[i].v;}
00139
00140 void printParam(FILE* fp);
00141 };
00142
00143
00144 bool isSameTexture(TextureParam a, TextureParam b);
00145
00146
00147
00148
00150
00151
00152
00153 class MaterialParam
00154 {
00155 private:
00156 Buffer addname;
00157
00158 double transparent;
00159 double shininess;
00160 double glow;
00161 double bright;
00162 double glossiness;
00163 double environment;
00164 double light;
00165
00166 public:
00167 bool enable;
00168
00169 int mapping;
00170 int mflags;
00171 int others;
00172
00173 TextureParam texture;
00174 TextureParam bumpmap;
00175 TextureParam specmap;
00176
00177 public:
00178 MaterialParam(void) { init();}
00179 virtual ~MaterialParam(void) {}
00180
00181 public:
00182 void init (void);
00183 void free (void);
00184 void clear(void) { free(); init();}
00185
00186 void dup(MaterialParam m);
00187
00188 bool isSetTexture(void) { return texture.isSetTexture();}
00189 bool isSetBumpMap(void) { return bumpmap.isSetTexture();}
00190 bool isSetSpecMap(void) { return specmap.isSetTexture();}
00191
00192 bool isSetTextureParams(void) { return (texture.isSetParams() || bumpmap.isSetParams() || specmap.isSetParams());}
00193 bool isSetParams (void) { return (isSetTransparent() || isSetGlow() || isSetShininess() || isSetBright());}
00194
00195 bool isSetGlow (void) { return (glow!=0.0);}
00196 bool isSetBright (void) { return (bright!=0.0);}
00197 bool isSetShininess (void) { return (shininess!=0.0);}
00198 bool isSetTransparent(void) { return (transparent<0.99);}
00199
00200 bool isTransparency(void) { return (isSetAlpha() || isSetTransparent() || getColor(3)<0.99);}
00201
00202 void setTextureName(const char* name) { texture.setName(name);}
00203 void setBumpMapName(const char* name) { bumpmap.setName(name);}
00204 void setSpecMapName(const char* name) { specmap.setName(name);}
00205
00206 char* getTextureName(void) { return texture.getName();}
00207 char* getBumpMapName(void) { return bumpmap.getName();}
00208 char* getSpecMapName(void) { return specmap.getName();}
00209
00210 void setAdditionalName(const char* name) { if(name!=NULL) copy_s2Buffer(name, &addname);}
00211 void addAdditionalName(const char* name) { if(name!=NULL) cat_s2Buffer (name, &addname);}
00212 char* getAdditionalName(void) { return (char*)addname.buf;}
00213 void setupFullName(const char* extname);
00214
00215 void setTransparent(double a) { if(a>1.0) a = 1.0; else if(a<0.0) a = 0.0; transparent = a;}
00216 void setShininess(double s) { if(s>1.0) s = 1.0; else if(s<0.0) s = 0.0; shininess = s;}
00217 void setGlow(double g) { if(g>1.0) g = 1.0; else if(g<0.0) g = 0.0; glow = g;}
00218 void setBright(double b) { if(b>1.0) b = 1.0; else if(b<0.0) b = 0.0; bright = b;}
00219 void setGlossiness (double g) { if(g>1.0) g = 1.0; else if(g<0.0) g = 0.0; glossiness = g;}
00220 void setEnvironment(double e) { if(e>1.0) e = 1.0; else if(e<0.0) e = 0.0; environment = e;}
00221 void setLight(double l) { if(l>1.0) l = 1.0; else if(l<0.0) l = 0.0; light = l;}
00222
00223 double getTransparent(void) { return transparent;}
00224 double getShininess(void) { return shininess;}
00225 double getGlow(void) { return glow;}
00226 double getBright(void) { return bright;}
00227 double getGlossiness (void) { return glossiness;}
00228 double getEnvironment(void) { return environment;}
00229 double getLight(void) { return light;}
00230
00231 void printParam(FILE* fp);
00232
00233
00234 public:
00235 bool isSetColor(void) { return texture.isSetColor();}
00236 bool isSetAlpha(void) { return texture.isSetAlpha();}
00237
00238 void setColor(double r, double g, double b, double a=1.0) { texture.setColor(r, g, b, a);}
00239 void setColor(double v, int c) { texture.setColor(v, c);}
00240 void setShiftU(double u) { texture.setShiftU(u);}
00241 void setShiftV(double v) { texture.setShiftV(v);}
00242 void setScaleU(double u) { texture.setScaleU(u);}
00243 void setScaleV(double v) { texture.setScaleV(v);}
00244 void setRotate(double r) { texture.setRotate(r);}
00245 void setFlipU (bool h) { texture.setFlipU(h); }
00246 void setFlipV (bool h) { texture.setFlipV(h); }
00247 void setShift (double u, double v) { texture.setShiftU(u); texture.setShiftV(v);}
00248 void setScale (double u, double v) { texture.setScaleU(u); texture.setScaleV(v);}
00249
00250 void setAlphaChannel(bool h) { texture.setAlphaChannel(h);}
00251 void setAlphaMode(int m) { texture.setAlphaMode(m);}
00252 void setAlphaCutoff(double m) { texture.setAlphaCutoff(m);}
00253
00254 double getColor(int c) { return texture.getColor(c);}
00255 double getShiftU(void) { return texture.getShiftU();}
00256 double getShiftV(void) { return texture.getShiftV();}
00257 double getScaleU(void) { return texture.getScaleU();}
00258 double getScaleV(void) { return texture.getScaleV();}
00259 double getRotate(void) { return texture.getRotate();}
00260
00261 bool getAlphaChannel(void) { return texture.getAlphaChannel();}
00262 int getAlphaMode(void) { return texture.getAlphaMode();}
00263 double getAlphaCutoff(void) { return texture.getAlphaCutoff();}
00264
00265 void execTrans (UVMap<double>* uv, int n) { texture.execTrans (uv, n);}
00266 void execShift (UVMap<double>* uv, int n) { texture.execShift (uv, n);}
00267 void execScale (UVMap<double>* uv, int n) { texture.execScale (uv, n);}
00268 void execRotate(UVMap<double>* uv, int n) { texture.execRotate(uv, n);}
00269
00270 void execInvTrans (UVMap<double>* uv, int n) { texture.execInvTrans (uv, n);}
00271 void execInvShift (UVMap<double>* uv, int n) { texture.execInvShift (uv, n);}
00272 void execInvScale (UVMap<double>* uv, int n) { texture.execInvScale (uv, n);}
00273 void execInvRotate(UVMap<double>* uv, int n) { texture.execInvRotate(uv, n);}
00274
00275 void execFlipU(UVMap<double>* uv, int n) { texture.execFlipU(uv, n);}
00276 void execFlipV(UVMap<double>* uv, int n) { texture.execFlipV(uv, n);}
00277
00278 char* getBase64Params(char obj='\0');
00279
00280 };
00281
00282
00283
00284 inline MaterialParam* newMaterialParam(MaterialParam p) { MaterialParam* m = new MaterialParam(); m->dup(p); return m;}
00285
00286 bool isSameMaterial(MaterialParam a, MaterialParam b);
00287
00288
00289
00290
00291 }
00292
00293 #endif
00294
00295