| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- -- write into "outfile" the selected OgreMaterial
- -- precondition: iskindof material OgreMAterial == true.
- -- Use export OgreMaterial.
- function writeOgreMaterial material outname =
- (
- local t, matname, mat, ext ;
- mat = material ;
- local outFile ;
-
- if (mat != undefined) then
- (
- matname = material.name ;
- ext = ".material" ;
- fname = outname +"_"+ matname + ext ;
- outFile = createfile fname ;
- format "<material>\n" to:outFile ;
-
- local tname="NoTexture" ;
-
- if ((material.diffusemap != undefined) and (iskindof material.diffusemap Bitmaptexture)) then
- (
- tname = "Diff" ;
-
- if ((material.bumpMap != undefined) and (iskindof material.bumpMap Bitmaptexture)) then
- (
- tname = tname + "Normal" ;
-
- if (material.specularLevel != 0.0) then
- (
- tname = tname + "Spec" ;
- )
-
- if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
- (
- tname = tname + "AlphaMask" ;
- )
- )
- else
- (
- if (material.specularLevel != 0.0) then
- (
- tname = tname + "Spec" ;
- )
- if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
- (
- tname = tname + "AlphaMask" ;
- )
- )
-
- format " <technique name=\"Techniques/%.xml\" />\n" (tname) to:outFile ;
- )
- else
- (
- if (material.opacity != 100.0) then
- (
- tname = tname + "Alpha" ;
- )
-
- format " <technique name=\"Techniques/%.xml\" />\n" (tname) to:outFile ;
- )
-
- format " <parameter name=\"MatDiffColor\" value=\"% % % %\" />\n" (material.diffuse.r/255.0) (material.diffuse.g/255.0) (material.diffuse.b/255.0) ((100-material.opacity)/100.0) to:outFile ;
- format " <parameter name=\"MatSpecColor\" value=\"% % % %\" />\n" (material.specular.r/255.0) (material.specular.g/255.0) (material.specular.b/255.0) (material.specularLevel*100.0) to:outFile ;
-
- if ((material.diffusemap != undefined) and (iskindof material.diffusemap Bitmaptexture)) then
- (
- t = filterstring material.diffusemap.filename "\\" ;
- format " <texture unit=\"diffuse\" name=\"textures/%\" />\n" t[arrayLength t] to:outFile ;
- )
-
- if ((material.bumpMap != undefined) and (iskindof material.bumpMap Bitmaptexture)) then
- (
- t = filterstring material.diffusemap.filename "\\" ;
- format " <texture unit=\"normal\" name=\"textures/%\" />\n" t[arrayLength t] to:outFile ;
- )
-
- if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
- (
- tname = tname + "AlphaMask" ;
- )
-
- if (material.twoSided == true) then
- (
- format " <cull value=\"none\" />\n" to:outFile ;
- )
-
- format "</material>\n" to:outFile ;
- close outFile ;
- )
- )
- function exportOgreMaterial material outName =
- (
- local outFile ;
- if (classof material == OgreMaterial or classof material == ogreMaterial) then
- (
- --outFile = createfile outName ;
- writeOgreMaterial material outname ;
- --close outFile ;
- )
- else
- (
- messageBox "You have to choose an OgreMaterial." ;
- )
- )
- ---------------------------------------------------------------
- -- Writes a standard material in a material script
- -- prefix will be before material name. (prefix+name)
- -- used for multi material
- ---------------------------------------------------------------
- function writeStandardMaterial material outname =
- (
- local outFile ;
- local t, matname, mat, ext, fname ;
-
- matname = replaceSpaces material.name ;
- ext = ".material" ;
- fname = outname + "_" + matname + ext ;
- outFile = createfile fname ;
-
- format "<material>\n" to:outFile ;
-
- local tname="NoTexture" ;
-
- if ((material.diffusemap != undefined) and (iskindof material.diffusemap Bitmaptexture)) then
- (
- tname = "Diff" ;
-
- if ((material.bumpMap != undefined) and (iskindof material.bumpMap Bitmaptexture)) then
- (
- tname = tname + "Normal" ;
-
- if (material.specularLevel != 0.0) then
- (
- tname = tname + "Spec" ;
- )
-
- if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
- (
- tname = tname + "AlphaMask" ;
- )
- )
- else
- (
- if (material.specularLevel != 0.0) then
- (
- tname = tname + "Spec" ;
- )
- if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
- (
- tname = tname + "AlphaMask" ;
- )
- )
-
- format " <technique name=\"Techniques/%.xml\" />\n" (tname) to:outFile ;
- )
- else
- (
- if (material.opacity != 100.0) then
- (
- tname = tname + "Alpha" ;
- )
-
- format " <technique name=\"Techniques/%.xml\" />\n" (tname) to:outFile ;
- )
-
- format " <parameter name=\"MatDiffColor\" value=\"% % % %\" />\n" (material.diffuse.r/255.0) (material.diffuse.g/255.0) (material.diffuse.b/255.0) ((100-material.opacity)/100.0) to:outFile ;
- format " <parameter name=\"MatSpecColor\" value=\"% % % %\" />\n" (material.specular.r/255.0) (material.specular.g/255.0) (material.specular.b/255.0) (material.specularLevel*100.0) to:outFile ;
-
- if ((material.diffusemap != undefined) and (iskindof material.diffusemap Bitmaptexture)) then
- (
- t = filterstring material.diffusemap.filename "\\" ;
- format " <texture unit=\"diffuse\" name=\"textures/%\" />\n" t[arrayLength t] to:outFile ;
- )
-
- if ((material.bumpMap != undefined) and (iskindof material.bumpMap Bitmaptexture)) then
- (
- t = filterstring material.diffusemap.filename "\\" ;
- format " <texture unit=\"normal\" name=\"textures/%\" />\n" t[arrayLength t] to:outFile ;
- )
-
- if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
- (
- tname = tname + "AlphaMask" ;
- )
-
- if (material.twoSided == true) then
- (
- format " <cull value=\"none\" />\n" to:outFile ;
- )
-
- format "</material>\n" to:outFile ;
- close outFile ;
- )
- ---------------------------------------------------------------
- -- Exports a standard material
- -- PRE: material is a standard material
- -- Use exportMaterial function.
- ---------------------------------------------------------------
- function exportStandardMaterial material outname =
- (
- local sub,i,matname ;
- matname = replaceSpaces material.name ;
- writeStandardMaterial material outname ;
- )
- ---------------------------------------------------------------
- -- Exports a multi material
- -- PRE: material is a multi material
- -- Use exportMaterial function.
- ---------------------------------------------------------------
- function exportMultiMaterial material outname=
- (
- local sub,i,matname ;
- matname = replaceSpaces material.name ;
-
- i=0 ;
- for sub in material.materiallist do
- (
- i+=1 ;
- writeStandardMaterial sub outname ;
- --format "\n" to:outFile ;
- )
- )
- ---------------------------------------------------------------
- -- Exports a material
- -- call the fonction linked to the material type
- ---------------------------------------------------------------
- function exportMaterial material outname =
- (
- local outFile ;
-
- if (material!=undefined and classof material == MultiMaterial) then
- (
- exportMultiMaterial material outname ;
- )
- else
- (
- if (material!=undefined and classof material == StandardMaterial) then
- (
- exportStandardMaterial material outname ;
- )
- else
- (
- messageBox "You have to choose a Standard Material or a MultiMaterial." ;
- return 0 ;
- )
- )
- --messageBox "Exporting material successful !" ;
- )
- ---------------------------------------------------------------
- -- Exports all the materials used in the scene
- ---------------------------------------------------------------
- function exportAllSceneMaterials outname =
- (
- for material in sceneMaterials do
- (
- if (material!=undefined and classof material == MultiMaterial) then
- exportMultiMaterial material outname ;
- else (
- if (material!=undefined and classof material == StandardMaterial) then
- exportStandardMaterial material outname ;
- )
- format "\n" to:outFile ;
- )
- -- messageBox "Exporting all materials in the scene successful !" ;
- )
|