ogreMaterialLib.ms 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. -- write into "outfile" the selected OgreMaterial
  2. -- precondition: iskindof material OgreMAterial == true.
  3. -- Use export OgreMaterial.
  4. function writeOgreMaterial material outname =
  5. (
  6. local t, matname, mat, ext ;
  7. mat = material ;
  8. local outFile ;
  9. if (mat != undefined) then
  10. (
  11. matname = material.name ;
  12. ext = ".material" ;
  13. fname = outname +"_"+ matname + ext ;
  14. outFile = createfile fname ;
  15. format "<material>\n" to:outFile ;
  16. local tname="NoTexture" ;
  17. if ((material.diffusemap != undefined) and (iskindof material.diffusemap Bitmaptexture)) then
  18. (
  19. tname = "Diff" ;
  20. if ((material.bumpMap != undefined) and (iskindof material.bumpMap Bitmaptexture)) then
  21. (
  22. tname = tname + "Normal" ;
  23. if (material.specularLevel != 0.0) then
  24. (
  25. tname = tname + "Spec" ;
  26. )
  27. if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
  28. (
  29. tname = tname + "AlphaMask" ;
  30. )
  31. )
  32. else
  33. (
  34. if (material.specularLevel != 0.0) then
  35. (
  36. tname = tname + "Spec" ;
  37. )
  38. if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
  39. (
  40. tname = tname + "AlphaMask" ;
  41. )
  42. )
  43. format " <technique name=\"Techniques/%.xml\" />\n" (tname) to:outFile ;
  44. )
  45. else
  46. (
  47. if (material.opacity != 100.0) then
  48. (
  49. tname = tname + "Alpha" ;
  50. )
  51. format " <technique name=\"Techniques/%.xml\" />\n" (tname) to:outFile ;
  52. )
  53. 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 ;
  54. 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 ;
  55. if ((material.diffusemap != undefined) and (iskindof material.diffusemap Bitmaptexture)) then
  56. (
  57. t = filterstring material.diffusemap.filename "\\" ;
  58. format " <texture unit=\"diffuse\" name=\"textures/%\" />\n" t[arrayLength t] to:outFile ;
  59. )
  60. if ((material.bumpMap != undefined) and (iskindof material.bumpMap Bitmaptexture)) then
  61. (
  62. t = filterstring material.diffusemap.filename "\\" ;
  63. format " <texture unit=\"normal\" name=\"textures/%\" />\n" t[arrayLength t] to:outFile ;
  64. )
  65. if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
  66. (
  67. tname = tname + "AlphaMask" ;
  68. )
  69. if (material.twoSided == true) then
  70. (
  71. format " <cull value=\"none\" />\n" to:outFile ;
  72. )
  73. format "</material>\n" to:outFile ;
  74. close outFile ;
  75. )
  76. )
  77. function exportOgreMaterial material outName =
  78. (
  79. local outFile ;
  80. if (classof material == OgreMaterial or classof material == ogreMaterial) then
  81. (
  82. --outFile = createfile outName ;
  83. writeOgreMaterial material outname ;
  84. --close outFile ;
  85. )
  86. else
  87. (
  88. messageBox "You have to choose an OgreMaterial." ;
  89. )
  90. )
  91. ---------------------------------------------------------------
  92. -- Writes a standard material in a material script
  93. -- prefix will be before material name. (prefix+name)
  94. -- used for multi material
  95. ---------------------------------------------------------------
  96. function writeStandardMaterial material outname =
  97. (
  98. local outFile ;
  99. local t, matname, mat, ext, fname ;
  100. matname = replaceSpaces material.name ;
  101. ext = ".material" ;
  102. fname = outname + "_" + matname + ext ;
  103. outFile = createfile fname ;
  104. format "<material>\n" to:outFile ;
  105. local tname="NoTexture" ;
  106. if ((material.diffusemap != undefined) and (iskindof material.diffusemap Bitmaptexture)) then
  107. (
  108. tname = "Diff" ;
  109. if ((material.bumpMap != undefined) and (iskindof material.bumpMap Bitmaptexture)) then
  110. (
  111. tname = tname + "Normal" ;
  112. if (material.specularLevel != 0.0) then
  113. (
  114. tname = tname + "Spec" ;
  115. )
  116. if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
  117. (
  118. tname = tname + "AlphaMask" ;
  119. )
  120. )
  121. else
  122. (
  123. if (material.specularLevel != 0.0) then
  124. (
  125. tname = tname + "Spec" ;
  126. )
  127. if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
  128. (
  129. tname = tname + "AlphaMask" ;
  130. )
  131. )
  132. format " <technique name=\"Techniques/%.xml\" />\n" (tname) to:outFile ;
  133. )
  134. else
  135. (
  136. if (material.opacity != 100.0) then
  137. (
  138. tname = tname + "Alpha" ;
  139. )
  140. format " <technique name=\"Techniques/%.xml\" />\n" (tname) to:outFile ;
  141. )
  142. 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 ;
  143. 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 ;
  144. if ((material.diffusemap != undefined) and (iskindof material.diffusemap Bitmaptexture)) then
  145. (
  146. t = filterstring material.diffusemap.filename "\\" ;
  147. format " <texture unit=\"diffuse\" name=\"textures/%\" />\n" t[arrayLength t] to:outFile ;
  148. )
  149. if ((material.bumpMap != undefined) and (iskindof material.bumpMap Bitmaptexture)) then
  150. (
  151. t = filterstring material.diffusemap.filename "\\" ;
  152. format " <texture unit=\"normal\" name=\"textures/%\" />\n" t[arrayLength t] to:outFile ;
  153. )
  154. if ((material.opacityMap != undefined) and (iskindof material.opacityMap Bitmaptexture)) then
  155. (
  156. tname = tname + "AlphaMask" ;
  157. )
  158. if (material.twoSided == true) then
  159. (
  160. format " <cull value=\"none\" />\n" to:outFile ;
  161. )
  162. format "</material>\n" to:outFile ;
  163. close outFile ;
  164. )
  165. ---------------------------------------------------------------
  166. -- Exports a standard material
  167. -- PRE: material is a standard material
  168. -- Use exportMaterial function.
  169. ---------------------------------------------------------------
  170. function exportStandardMaterial material outname =
  171. (
  172. local sub,i,matname ;
  173. matname = replaceSpaces material.name ;
  174. writeStandardMaterial material outname ;
  175. )
  176. ---------------------------------------------------------------
  177. -- Exports a multi material
  178. -- PRE: material is a multi material
  179. -- Use exportMaterial function.
  180. ---------------------------------------------------------------
  181. function exportMultiMaterial material outname=
  182. (
  183. local sub,i,matname ;
  184. matname = replaceSpaces material.name ;
  185. i=0 ;
  186. for sub in material.materiallist do
  187. (
  188. i+=1 ;
  189. writeStandardMaterial sub outname ;
  190. --format "\n" to:outFile ;
  191. )
  192. )
  193. ---------------------------------------------------------------
  194. -- Exports a material
  195. -- call the fonction linked to the material type
  196. ---------------------------------------------------------------
  197. function exportMaterial material outname =
  198. (
  199. local outFile ;
  200. if (material!=undefined and classof material == MultiMaterial) then
  201. (
  202. exportMultiMaterial material outname ;
  203. )
  204. else
  205. (
  206. if (material!=undefined and classof material == StandardMaterial) then
  207. (
  208. exportStandardMaterial material outname ;
  209. )
  210. else
  211. (
  212. messageBox "You have to choose a Standard Material or a MultiMaterial." ;
  213. return 0 ;
  214. )
  215. )
  216. --messageBox "Exporting material successful !" ;
  217. )
  218. ---------------------------------------------------------------
  219. -- Exports all the materials used in the scene
  220. ---------------------------------------------------------------
  221. function exportAllSceneMaterials outname =
  222. (
  223. for material in sceneMaterials do
  224. (
  225. if (material!=undefined and classof material == MultiMaterial) then
  226. exportMultiMaterial material outname ;
  227. else (
  228. if (material!=undefined and classof material == StandardMaterial) then
  229. exportStandardMaterial material outname ;
  230. )
  231. format "\n" to:outFile ;
  232. )
  233. -- messageBox "Exporting all materials in the scene successful !" ;
  234. )