1 #pragma once
2 
3 // max stuff
4 #include "Max.h"
5 #include "istdplug.h"
6 #include "iparamb2.h"
7 #include "iparamm2.h"
8 
9 // xrFSL stuff
10 #include "XRMtlResource.h"
11 #include "CompilerShadersLib.h"
12 #include "EngineShadersLib.h"
13 #include "GameMaterialsLib.h"
14 
15 // mtl stuff
16 #include "texmaps.h"
17 
18 
19 extern TCHAR *GetString(int id);
20 
21 extern HINSTANCE hInstance;
22 
23 #define xrFSLMaterial_CLASS_ID	Class_ID(0x9fd6ac09, 0x8f860bc8)
24 
25 #define NSUBMTL		1 // TODO: number of sub-materials supported by this plugin
26 #define NTEXMAPS	1	// number of texmaps
27 
28 #define PBLOCK_REF	NSUBMTL
29 
30 /**
31  *
32  */
33 class xrFSLMaterial : public Mtl {
34 public:
35 
36 
37 	// Parameter block
38 	IParamBlock2* pblock;			//ref 0
39 	Texmaps* m_texMaps;				// ref 1
40 
41 
42 	Mtl				*submtl[NSUBMTL];  //array of sub-materials
43 	BOOL			mapOn[NSUBMTL];
44 	float			spin;
45 	Interval		ivalid;
46 
47 	// xr parameters
48 	BOOL m_bDblSided;
49 
50 	// xr shaders
51 	static xrFSL::CompilerShadersLib m_CShadersLib;
52 	static xrFSL::EngineShadersLib m_EShadersLib;
53 	static xrFSL::GameMaterialsLib m_GMaterialsLib;
54 
55 
56 
57 	ParamDlg *CreateParamDlg(HWND hwMtlEdit, IMtlParams *imp);
58 	void Update(TimeValue t, Interval& valid);
59 	Interval Validity(TimeValue t);
60 	void Reset();
61 
62 	void NotifyChanged();
63 
64 	// From MtlBase and Mtl
65 	void SetAmbient(Color c, TimeValue t);
66 	void SetDiffuse(Color c, TimeValue t);
67 	void SetSpecular(Color c, TimeValue t);
68 	void SetShininess(float v, TimeValue t);
69 	Color GetAmbient(int mtlNum=0, BOOL backFace=FALSE);
70 	Color GetDiffuse(int mtlNum=0, BOOL backFace=FALSE);
71 	Color GetSpecular(int mtlNum=0, BOOL backFace=FALSE);
72 	float GetXParency(int mtlNum=0, BOOL backFace=FALSE);
73 	float GetShininess(int mtlNum=0, BOOL backFace=FALSE);
74 	float GetShinStr(int mtlNum=0, BOOL backFace=FALSE);
75 	float WireSize(int mtlNum=0, BOOL backFace=FALSE);
76 
77 
78 	// Shade and displacement calculation
79 	void Shade(ShadeContext& sc);
80 	float EvalDisplacement(ShadeContext& sc);
81 	Interval DisplacementValidity(TimeValue t);
82 
83 	// SubMaterial access methods
NumSubMtls()84 	int NumSubMtls() {return NSUBMTL;}
85 	Mtl* GetSubMtl(int i);
86 	void SetSubMtl(int i, Mtl *m);
87 	TSTR GetSubMtlSlotName(int i);
88 	TSTR GetSubMtlTVName(int i);
89 
90 	/*+++++++++ SubTexmap access methods +++++++++++*/
NumSubTexmaps()91 	int NumSubTexmaps() {return NTEXMAPS;}
GetSubTexmap(int i)92 	Texmap* GetSubTexmap(int i) { return (*m_texMaps)[i].map; };
93 	void SetSubTexmap(int i, Texmap *m);
94 	TSTR GetSubTexmapSlotName(int i);
95 	TSTR GetSubTexmapTVName(int i);
96 	/*++++++++++ end SubTexmap ++++++++++++++++++++++*/
97 
98 	BOOL SetDlgThing(ParamDlg* dlg);
99 	xrFSLMaterial(BOOL loading);
100 
101 
102 	// Loading/Saving
103 	IOResult Load(ILoad *iload);
104 	IOResult Save(ISave *isave);
105 
106 	//From Animatable
ClassID()107 	Class_ID ClassID() {return xrFSLMaterial_CLASS_ID;}
SuperClassID()108 	SClass_ID SuperClassID() { return MATERIAL_CLASS_ID; }
GetClassName(TSTR & s)109 	void GetClassName(TSTR& s) {s = GetString(IDS_CLASS_NAME);}
110 
111 	RefTargetHandle Clone( RemapDir &remap );
112 	RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget,
113 		PartID& partID,  RefMessage message);
114 
115 
NumSubs()116 	int NumSubs() { return 1+NSUBMTL; }
117 	Animatable* SubAnim(int i);
118 	TSTR SubAnimName(int i);
119 
120 	// TODO: Maintain the number or references here
NumRefs()121 	int NumRefs() { return 1+NSUBMTL; }
122 	RefTargetHandle GetReference(int i);
123 	void SetReference(int i, RefTargetHandle rtarg);
124 
125 
126 
NumParamBlocks()127 	int	NumParamBlocks() { return 1; }					// return number of ParamBlocks in this instance
GetParamBlock(int i)128 	IParamBlock2* GetParamBlock(int i) { return pblock; } // return i'th ParamBlock
GetParamBlockByID(BlockID id)129 	IParamBlock2* GetParamBlockByID(BlockID id) { return (pblock->ID() == id) ? pblock : NULL; } // return id'd ParamBlock
130 
DeleteThis()131 	void DeleteThis() { delete this; }
132 };
133 
134 
135 
136 class xrFSLMaterialClassDesc : public ClassDesc2 {
137 public:
IsPublic()138 	int 			IsPublic() { return TRUE; }
139 	void *			Create(BOOL loading = FALSE) { return new xrFSLMaterial(loading); }
ClassName()140 	const TCHAR *	ClassName() { return GetString(IDS_CLASS_NAME); }
SuperClassID()141 	SClass_ID		SuperClassID() { return MATERIAL_CLASS_ID; }
ClassID()142 	Class_ID		ClassID() { return xrFSLMaterial_CLASS_ID; }
Category()143 	const TCHAR* 	Category() { return GetString(IDS_CATEGORY); }
144 
InternalName()145 	const TCHAR*	InternalName() { return _T("xrFSLMaterial"); }	// returns fixed parsable name (scripter-visible name)
HInstance()146 	HINSTANCE		HInstance() { return hInstance; }					// returns owning module handle
147 
148 
149 };