1 /********************************************************************** 2 *< 3 FILE: Wood.cpp 4 5 DESCRIPTION: Wood 3D Texture map Class Decl. 6 7 CREATED BY: Suryan Stalin 8 9 HISTORY: Modified from Marble.cpp by adding IPAS wood stuff 10 11 *> Copyright (c) 1994, All Rights Reserved. 12 **********************************************************************/ 13 14 #ifndef __WOOD__H 15 #define __WOOD__H 16 17 #include "iparamm2.h" 18 19 // defines 20 #define WOOD_CLASS_ID 0x0000214 21 #define NSUBTEX 2 22 #define NCOLS 2 23 #define WOOD_VERSION 1 24 25 #define WOOD_VERS 0x3AE2 26 #define MTL_HDR_CHUNK 0x4000 27 #define WOODVERS1_CHUNK 0x4001 28 #define WOOD_NOISE_CHUNK 0x4002 29 #define WD .02f 30 #define FACT 500.0f 31 #define SZ 1.0f //50.0 32 33 34 #define LIM255(c) (((c)>=255)?255:(c)) 35 #define SIZE 1 36 #define R1 2 37 #define R2 3 38 #define COL1 10 39 #define COL2 11 40 #define NOISE_DIM 20 41 #define FNOISE_DIM 20.0 42 43 #define SHOW_3DMAPS_WITH_2D 44 45 // C Prototypes 46 ClassDesc* GetWoodDesc(); 47 class Wood: public Tex3D 48 { 49 friend class WoodPostLoad; 50 static ParamDlg *xyzGenDlg; 51 XYZGen *xyzGen; // ref #0 52 Texmap* subTex[NSUBTEX]; // More refs 53 Interval ivalid; 54 int rollScroll; 55 #ifdef SHOW_3DMAPS_WITH_2D 56 TexHandle *texHandle; 57 Interval texHandleValid; 58 #endif 59 60 float WoodFunc(Point3 p); 61 62 public: 63 BOOL Param1; 64 Color col[NCOLS]; 65 float r1,r2,size; 66 BOOL mapOn[NSUBTEX]; 67 int vers; 68 int seed; 69 IParamBlock2 *pblock; // ref #1 70 Wood(); ~Wood()71 ~Wood() { 72 #ifdef SHOW_3DMAPS_WITH_2D 73 DiscardTexHandle(); 74 #endif 75 } 76 ParamDlg* CreateParamDlg(HWND hwMtlEdit, IMtlParams *imp); 77 void Update(TimeValue t, Interval& valid); 78 void Init(); 79 void Reset(); Validity(TimeValue t)80 Interval Validity(TimeValue t) { Interval v; Update(t,v); return ivalid; } 81 82 void SetColor(int i, Color c, TimeValue t); 83 void SetSize(float f, TimeValue t); 84 void SetR1(float f, TimeValue t); 85 void SetR2(float f, TimeValue t); 86 void NotifyChanged(); 87 void SwapInputs(); 88 89 void ReadSXPData(TCHAR *name, void *sxpdata); 90 GetTheXYZGen()91 XYZGen *GetTheXYZGen() { return xyzGen; } 92 93 // Wood noise functions 94 void InitNoise(); 95 float WoodNoise(float x); 96 void LerpColor(RGBA *c, RGBA *a, RGBA *b, float f); 97 float SmoothStep(float x0, float x1, float v); 98 99 // Evaluate the color of map for the context. 100 RGBA EvalColor(ShadeContext& sc); 101 102 // For Bump mapping, need a perturbation to apply to a normal. 103 // Leave it up to the Texmap to determine how to do this. 104 Point3 EvalNormalPerturb(ShadeContext& sc); 105 106 // Requirements LocalRequirements(int subMtlNum)107 ULONG LocalRequirements(int subMtlNum) { return xyzGen->Requirements(subMtlNum); } LocalMappingsRequired(int subMtlNum,BitArray & mapreq,BitArray & bumpreq)108 void LocalMappingsRequired(int subMtlNum, BitArray & mapreq, BitArray &bumpreq) { 109 xyzGen->MappingsRequired(subMtlNum,mapreq,bumpreq); 110 } 111 112 // Methods to access texture maps of material NumSubTexmaps()113 int NumSubTexmaps() { return NSUBTEX; } GetSubTexmap(int i)114 Texmap* GetSubTexmap(int i) { return subTex[i]; } 115 void SetSubTexmap(int i, Texmap *m); 116 TSTR GetSubTexmapSlotName(int i); 117 118 Class_ID ClassID(); SuperClassID()119 SClass_ID SuperClassID() { return TEXMAP_CLASS_ID; } GetClassName(TSTR & s)120 void GetClassName(TSTR& s) { s= GetString(IDS_DS_WOOD); } DeleteThis()121 void DeleteThis() { delete this; } 122 NumSubs()123 int NumSubs() { return 2+NSUBTEX; } 124 Animatable* SubAnim(int i); 125 TSTR SubAnimName(int i); SubNumToRefNum(int subNum)126 int SubNumToRefNum(int subNum) { return subNum; } 127 128 // From ref NumRefs()129 int NumRefs() { return 2+NSUBTEX; } 130 RefTargetHandle GetReference(int i); 131 void SetReference(int i, RefTargetHandle rtarg); 132 133 RefTargetHandle Clone(RemapDir &remap = DefaultRemapDir()); 134 RefResult NotifyRefChanged( Interval changeInt, RefTargetHandle hTarget, 135 PartID& partID, RefMessage message ); 136 137 #ifdef SHOW_3DMAPS_WITH_2D DiscardTexHandle()138 void DiscardTexHandle() { 139 if (texHandle) { 140 texHandle->DeleteThis(); 141 texHandle = NULL; 142 } 143 } SupportTexDisplay()144 BOOL SupportTexDisplay() { return TRUE; } ActivateTexDisplay(BOOL onoff)145 void ActivateTexDisplay(BOOL onoff) { 146 if (!onoff) DiscardTexHandle(); 147 } 148 DWORD_PTR GetActiveTexHandle(TimeValue t, TexHandleMaker& thmaker); 149 #endif SHOW_3DMAPS_WITH_2D 150 151 152 // IO 153 IOResult Save(ISave *isave); 154 IOResult Load(ILoad *iload); 155 // JBW: direct ParamBlock access is added NumParamBlocks()156 int NumParamBlocks() { return 1; } // return number of ParamBlocks in this instance GetParamBlock(int i)157 IParamBlock2* GetParamBlock(int i) { return pblock; } // return i'th ParamBlock GetParamBlockByID(BlockID id)158 IParamBlock2* GetParamBlockByID(BlockID id) { return (pblock->ID() == id) ? pblock : NULL; } // return id'd ParamBlock 159 BOOL SetDlgThing(ParamDlg* dlg); 160 161 // Same as Marble IsLocalOutputMeaningful(ShadeContext & sc)162 bool IsLocalOutputMeaningful( ShadeContext& sc ) { return true; } 163 164 }; 165 166 class WoodClassDesc:public ClassDesc2 167 { 168 public: IsPublic()169 int IsPublic() { return GetAppID() != kAPP_VIZR; } Create(BOOL loading)170 void * Create(BOOL loading) { return new Wood; } ClassName()171 const TCHAR * ClassName() { return GetString(IDS_DS_WOOD_CDESC); } // mjm - 2.10.99 SuperClassID()172 SClass_ID SuperClassID() { return TEXMAP_CLASS_ID; } 173 Class_ID ClassID(); Category()174 const TCHAR* Category() { return TEXMAP_CAT_3D; } 175 // PW: new descriptor data accessors added. Note that the 176 // internal name is hardwired since it must not be localized. InternalName()177 const TCHAR* InternalName() { return _T("wood"); } // returns fixed parsable name (scripter-visible name) HInstance()178 HINSTANCE HInstance() { return hInstance; } // returns owning module handle 179 }; 180 181 182 183 #pragma pack(1) 184 struct WoodState 185 { 186 ulong version; 187 float size; 188 float dx, dy, dz; 189 float r1; 190 float r2; 191 Col24 col1,col2; 192 }; 193 #pragma pack() 194 195 #endif 196