Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tools/3dsmaxExport/MaxscriptExport/scripts/ogre/lib/ogreMaterialLib.ms @ 6

Last change on this file since 6 was 6, checked in by anonymous, 17 years ago

=…

File size: 6.3 KB
Line 
1-- write into "outfile" the selected OgreMaterial
2-- precondition: iskindof material OgreMAterial == true.
3-- Use export OgreMaterial.
4function writeOgreMaterial material outFile =
5(
6        local t, matname, mat;
7
8        mat = material ;
9       
10        if (mat != undefined) then
11        (
12                matname = material.name ;       
13                format "material %\n" matname to:outFile ;
14                format "{\n" to:outFile ;
15                format "    technique\n" to:outFile ;
16                format "    {\n" to:outFile ;
17                format "        pass\n" to:outFile ;
18                format "        {\n" to:outFile ;
19                format("            ambient % % %\n") (mat.ambient.r/255.0) (mat.ambient.g/255.0) (mat.ambient.b/255.0) to:outFile ;
20            format("            diffuse % % %\n") (mat.diffuse.r/255.0) (mat.diffuse.g/255.0) (mat.diffuse.b/255.0) to:outFile ;
21        format("            specular % % % %\n") (mat.specular.r/255.0) (mat.specular.g/255.0) (mat.specular.b/255.0) (mat.specularLevel*100.0) to:outFile ;
22                format("            emissive % % %\n") (mat.selfIllumColor.r/255.0) (mat.selfIllumColor.g/255.0) (mat.selfIllumColor.b/255.0) to:outFile ;
23                )
24                if ((mat.diffusemap != undefined) and (iskindof mat.diffusemap Bitmaptexture)) then
25                (       
26                        t = filterstring mat.diffusemap.filename "\\" ;
27                        format "            texture_unit\n" to:outFile ;
28                        format "            {\n" to:outFile ;
29                        format "                texture % \n" t[arrayLength t] to:outFile ;
30                        format "            }\n" to:outFile ;
31                )
32                format "        }\n" to:outFile ;
33                format "    }\n" to:outFile ;
34                format "}\n" to:outFile ;
35)
36
37function exportOgreMaterial material outName =
38(
39    local outFile ;
40        if (classof material == OgreMaterial or classof material == ogreMaterial) then
41        (
42            outFile = createfile outName ;
43                writeOgreMaterial material outFile ;
44                close outFile ;
45                messageBox "Exporting material successful !" ;
46        )
47        else
48        (
49                messageBox "You have to choose an OgreMaterial." ;
50        )
51)
52
53---------------------------------------------------------------
54-- Writes a standard material in a material script
55-- prefix will be before material name. (prefix+name)
56-- used for multi material
57---------------------------------------------------------------
58function writeStandardMaterial material prefix outFile =
59(
60        local t ;
61        matname = replaceSpaces material.name ;
62        -- writes header       
63        format "material %\n" (prefix+matname) to:outFile ;
64        format "{\n" to:outFile ;
65        format "    technique\n" to:outFile ;
66        format "    {\n" to:outFile ;
67        format "        pass\n" to:outFile ;
68        format "        {\n" to:outFile ;
69
70        format("            ambient % % %\n") (material.ambient.r/255.0) (material.ambient.g/255.0) (material.ambient.b/255.0) to:outFile ;
71    format("            diffuse % % %\n") (material.diffuse.r/255.0) (material.diffuse.g/255.0) (material.diffuse.b/255.0) to:outFile ;
72    format("            specular % % % %\n") (material.specular.r/255.0) (material.specular.g/255.0) (material.specular.b/255.0) (material.specularLevel*100.0) to:outFile ;
73        format("            emissive % % %\n") (material.selfIllumColor.r/255.0) (material.selfIllumColor.g/255.0) (material.selfIllumColor.b/255.0) to:outFile ;
74        -- tests if there is (or not) a diffuse map.
75        if ((material.diffusemap != undefined) and (iskindof material.diffusemap Bitmaptexture)) then
76        (       
77                t = filterstring material.diffusemap.filename "\\" ;
78                format "            texture_unit\n" to:outFile ;
79                format "            {\n" to:outFile ;
80                format "                texture % \n" t[arrayLength t] to:outFile ;
81                format "            }\n" to:outFile ;
82        )
83        format "        }\n" to:outFile ;
84        format "    }\n" to:outFile ;
85        format "}\n" to:outFile ;
86
87)
88
89---------------------------------------------------------------
90-- Exports a standard material
91-- PRE: material is a standard material
92-- Use exportMaterial function.
93---------------------------------------------------------------
94function exportStandardMaterial material outFile =
95(
96        local sub,i,matname ;
97        matname = replaceSpaces material.name ;
98        writeStandardMaterial material "" outFile ;
99)
100
101
102---------------------------------------------------------------
103-- Exports a multi material
104-- PRE: material is a multi material
105-- Use exportMaterial function.
106---------------------------------------------------------------
107function exportMultiMaterial material outFile=
108(
109        local sub,i,matname ;
110
111        matname = replaceSpaces material.name ;
112       
113        i=0 ;
114        for sub in material.materiallist do (
115                i+=1 ;
116                writeStandardMaterial sub (material.name+"/") outFile ;
117                format "\n" to:outFile ;
118        )
119)
120
121
122
123---------------------------------------------------------------
124-- Exports a material
125-- call the fonction linked to the material type
126---------------------------------------------------------------
127function exportMaterial material outname =
128(
129        local outFile ;
130        if (not g_MAX) then
131        (
132                outFile = createfile outName ;
133        )
134        else
135        (
136                ClearListener();
137                if (g_MAX_use_listener) then
138                        format("<ogrestartfile>%</ogrestartfile><ogrestartdata>\n") (outName);
139                outFile = listener;
140        )
141               
142        if (material!=undefined and classof material == MultiMaterial) then
143        (
144                exportMultiMaterial material outFile ;
145        )
146        else
147        (
148                if (material!=undefined and classof material == StandardMaterial) then
149                (
150                        exportStandardMaterial material outFile ;
151                )
152                else
153                (
154                        messageBox "You have to choose a Standard Material or a MultiMaterial." ;
155                        return 0;
156                )
157        )
158       
159        if (not g_MAX) then
160        (
161            close outFile ;
162        )
163        else
164        (
165                if (g_MAX_use_listener) then
166                        format("</ogrestartdata>\n") to: outFile;
167        )
168       
169        messageBox "Exporting material successful !" ;
170)
171
172
173---------------------------------------------------------------
174-- Exports all the materials used in the scene
175---------------------------------------------------------------
176function exportAllSceneMaterials outname =
177(
178        local outFile ;
179        if (not g_MAX) then
180        (
181                outFile = createfile outName ;
182        )
183        else
184        (
185                ClearListener();
186                if (g_MAX_use_listener) then
187                        format("<ogrestartfile>%</ogrestartfile><ogrestartdata>\n") (outName);
188                outFile = listener;
189        )
190       
191        for material in sceneMaterials do
192        (                       
193                if (material!=undefined and classof material == MultiMaterial) then
194                        exportMultiMaterial material outFile ;
195                else (
196                        if (material!=undefined and classof material == StandardMaterial) then
197                                exportStandardMaterial material outFile ;
198                )
199                format "\n" to:outFile ;
200        )               
201
202        if (not g_MAX) then
203        (
204            close outFile ;
205        )
206        else
207        (
208                if (g_MAX_use_listener) then
209                        format("</ogrestartdata>\n") to: outFile;
210        )
211
212        messageBox "Exporting all materials in the scene successful !" ;
213)
214
Note: See TracBrowser for help on using the repository browser.