OgreSkeletonLib_meshfns.ms 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. include "ogre/lib/ogreSkeletonLib_usefulfns.ms"
  2. include "ogre/lib/ogrebipedlib.ms"
  3. ----------------------------------------------------------------------------------------
  4. -- ----------------------------------- WRITE MESH ----------------------------------- --
  5. ----------------------------------------------------------------------------------------
  6. -----------------------------------------------------------------
  7. -- Global 'variables'
  8. -- There is an array with vertices datas for each submesh
  9. -- There is also an array made up of faces.
  10. -----------------------------------------------------------------
  11. verticesArrays=#() ;
  12. facesArrays=#() ;
  13. boneAssignments=#() ;
  14. submeshesId=#() ;
  15. materialName = "" ;
  16. -- verticesArrays[i] will describe the subMesh number i and its elements will be ogreVertices where
  17. -- ogreVert = #(x,y,z,nx,ny,nz,r,g,b,a,u1,v1,u2,v2....)
  18. -- ----- -------- ------- ---------------
  19. -- Pos Nmal RGBA UVs sets
  20. -- RGBA being the vertex color when relevant (Optional)
  21. -- A vertex can contain multiple UVs sets (Optional)
  22. -- facesArrays[i] is an array of Point3 describing the subMesh i. Each Point3 contains vertices indices for a face that is gonna be exported
  23. -- boneAssignments[i] describes the bones assignements for subMesh i. It is an array of triplets like #(vertexIndex,boneIndex,weight)
  24. -- submeshesId is the list of material Ids
  25. -- materialName is the name that Ogre will use
  26. ----------------------------------------------------------------
  27. -- exploreMesh returns a string which is "OK" or an error message
  28. -- if there are warnings, it displays message boxes.
  29. -----------------------------------------------------------------
  30. function exploreMesh pmesh exportUV exportColours=
  31. (
  32. local material, answer, m ;
  33. answer = "" ;
  34. m = snapShotAsMesh pmesh ;
  35. -- first, is a material defined ?
  36. material = pmesh.material ;
  37. if (material == undefined) then
  38. answer = "This mesh doesn't have any material, please apply one\n" ;
  39. else
  40. -- then, are UVW coords set up ?
  41. if (exportUV and getNumTVerts m == 0) then
  42. answer = "This mesh must have UVW coords in order to be exported" ;
  43. if (answer == "") then
  44. answer = "OK" ;
  45. delete m ;
  46. answer ;
  47. )
  48. ----------------------------------------------------------------
  49. -- returns the correct normal for the vertex
  50. -- according to smoothing groups
  51. -----------------------------------------------------------------
  52. function getVertexNormalAccordingToSmoothingGroups selectedMesh faceIndex vertexIndex =
  53. (
  54. local normal;
  55. local faceSmoothingGroup = getFaceSmoothGroup selectedMesh faceIndex
  56. if faceSmoothingGroup == 0 then
  57. (
  58. -- if not smooth use face normal
  59. normal = getFaceNormal selectedMesh faceIndex
  60. )
  61. else
  62. (
  63. local vertexIndexes = getFace selectedMesh faceIndex;
  64. local vI = vertexIndexes[vertexIndex]
  65. local n = [0, 0, 0] -- point3
  66. for adjoiningFaceIndex in (meshop.getFacesUsingVert selectedMesh vI) do
  67. (
  68. sg = getFaceSmoothGroup selectedMesh adjoiningFaceIndex;
  69. and_sg = bit.and sg faceSmoothingGroup ;
  70. if (and_sg != 0) then
  71. n += getFaceNormal selectedMesh adjoiningFaceIndex ;
  72. )
  73. normal = normalize n;
  74. )
  75. normal;
  76. )
  77. function tabEquals tab1 tab2 =
  78. (
  79. if (tab1.count != tab2.count) then
  80. return false;
  81. for i=1 to tab1.count do
  82. if (tab1[i] != tab2[i]) then
  83. return false;
  84. return true;
  85. )
  86. function doesVertexExistAlready searchTable vertexIndex vertexNormal vertexColorIndex vertexAlphaIndex UVs exportUV exportColor =
  87. (
  88. local start_uvs;
  89. vertex = #();
  90. --format "vertex a tester % % \n" vertexIndex vertexNormal;
  91. if (searchTable[vertexIndex]==undefined) then
  92. return 0;
  93. for vertex in searchTable[vertexIndex] do
  94. (
  95. if (vertex[2]!=vertexNormal) then
  96. continue;
  97. if (exportColor) then
  98. (
  99. if (vertex[3]!=vertexColorIndex) then
  100. continue;
  101. if (vertex[4]!=vertexAlphaIndex) then
  102. continue;
  103. start_uvs = 4;
  104. )
  105. else
  106. (
  107. start_uvs = 2;
  108. )
  109. if (exportUV) then
  110. (
  111. local equal = true;
  112. for i=1 to UVs.count do
  113. (
  114. if (vertex[start_uvs+i]!=UVs[i]) then
  115. (
  116. equal = false;
  117. exit;
  118. )
  119. )
  120. if (not equal) then
  121. continue;
  122. )
  123. return vertex[1] ;
  124. )
  125. return 0;
  126. )
  127. ----------------------------------------------------------------------------
  128. -- Retrieves al the datas which wil be used
  129. -- tmesh is the mesh object
  130. -- flipyz = true if you want coords to fit in OGRE.
  131. -- flipNormal = true if you want to flip normals
  132. -- scale : the scale factor
  133. -- exportUV = true if you want to export texture
  134. -- numUVsets : number of texture coordinates to export (if exportUV is true, the minimum is 1. if exportUV is false, this parameter is irrelevant)
  135. -- exportColor = true if you want to export vertices colors
  136. -- sk : the skin modifier (may be undefined)
  137. -- phy : the physique modifier (may be undefined)
  138. -- stores datas in verticesArrays and facesArrays.
  139. ----------------------------------------------------------------------------
  140. function getDatas tmesh flipyz scale flipNormal exportUV numUVsets exportColours exportHelpers sk phy =
  141. (
  142. local face; --index of the current face
  143. local localVertexIndex; --index of the current vertex (relative to the current face) ie : 1, 2 or 3
  144. local vertexNormal; --normal of the current vertex (Point3)
  145. local vertexPosition; --position of the current vertex (Point3)
  146. local faceVerticesIndices; --indices of the vertex for the current face (Point3)
  147. local vertexIndex; --index of the current vertex (in the mesh)
  148. local matId; --material Id of the current face
  149. local numFaces; --number of faces in the mesh
  150. local faceVertexColorIndices; --indices of the vertices for the current face in the vertex color table of the mesh (Point3)
  151. local vertexColorIndex; --index of the current vertex in the vertex color table of the mesh
  152. local vertexColor; --vertex color for the current vertex (color)
  153. local faceVertexAlphaIndices; --indices of the vertices for the current face in the vertex alpha table of the mesh (Point3)
  154. local vertexAlpha; --vertex alpha of the current alpha
  155. local vertexAlphaIndex; --index of the current vertex in the vertex alpha map channel (-2)
  156. local ogreFace; --indices of the vertices for the current face (references the list of vertices that is gonna be exported, not the vertices of the original mesh)
  157. local vertexWeightCount; --number of bones influencing the current vertex
  158. local vertexWeight; --current weight
  159. local searchTable ;
  160. local k ;
  161. local rootId ;
  162. local UVcoords; -- will contain the texture coordinates for the current vertex. its size will be numUVsets*2 if exportUV is true.
  163. -- searchTables will contain a searchTable for every subMesh.
  164. -- searchTable will be the current table for the current subMesh.
  165. -- Every vertex will be stored here to check for duplicates.
  166. searchTable=#() ;
  167. searchTables=#() ;
  168. -- initialisation of the current ogre face as a vector
  169. ogreFace=Point3 12 12 12 ;
  170. -- Data arrays init.
  171. verticesArrays=#() ;
  172. facesArrays=#() ;
  173. boneAssignments = #() ;
  174. submeshesId = #() ;
  175. UVcoords=#() ;
  176. -- compute bones list for the model.
  177. BonesList=#()
  178. computeBonesList phy sk exportHelpers ;
  179. numFaces = (getNumFaces tmesh);
  180. -- For each face
  181. for face = 1 to numFaces do -- LOOP on FACES --
  182. (
  183. OgreExportObject.exportProgress.value = (100.0*face/numFaces);
  184. faceVerticesIndices = getFace tmesh face ;
  185. matId = getFaceMatId tmesh face ;
  186. -- Vertex Color Face
  187. if (exportColours) then
  188. (
  189. faceVertexColorIndices = meshOp.getMapFace tmesh 0 face ; -- 0 is the vertex color channel
  190. faceVertexAlphaIndices = meshOp.getMapFace tmesh -2 face ; -- -2 is the vertex alpha channel
  191. )
  192. else
  193. (
  194. faceVertexColorIndices = Point3 1 1 1 ;
  195. faceVertexAlphaIndices = Point3 1 1 1 ;
  196. )
  197. -- For each vertex whose face is made up of.
  198. for localVertexIndex=1 to 3 do -- LOOP on VERTICES --
  199. (
  200. vertexIndex = (int) (faceVerticesIndices[localVertexIndex]) ;
  201. vertexColorIndex = (int) (faceVertexColorIndices[localVertexIndex]) ;
  202. vertexAlphaIndex = (int) (faceVertexAlphaIndices[localVertexIndex]);
  203. vertexNormal = getVertexNormalAccordingToSmoothingGroups tmesh face localVertexIndex;
  204. -- flip normal capability
  205. if (flipNormal) then
  206. (
  207. vertexNormal = vertexNormal * -1
  208. )
  209. -- we retrieve datas. it depends on options.
  210. -- UV face
  211. if (exportUV) then
  212. (
  213. UVcoords=#();
  214. for ch=1 to numUVsets do
  215. (
  216. local vertInds = meshOp.getMapFace tmesh ch face ;
  217. local UVW = meshOp.getMapVert tmesh ch vertInds[localVertexIndex] ; -- retrieve the UV for the corresponding channel.
  218. append UVcoords UVW[1];
  219. append UVcoords UVW[2]; -- don't care about the W coordinate
  220. )
  221. )
  222. else
  223. (
  224. UVcoords=#();
  225. )
  226. -- we try to find the corresponding searchtable.
  227. if (searchTables[matId] == undefined ) then
  228. searchTables[matId]=#() ; -- we found a new subMesh, create the searchTable for it
  229. searchTable = searchTables[matId] ; -- set the searchTable to the current subMesh
  230. newVertex = 1 ;
  231. ogreVertNum = 1;
  232. -- Maybe this vertex has already been found.
  233. -- So we use searchTable.
  234. res = doesVertexExistAlready searchTable vertexIndex vertexNormal vertexColorIndex vertexAlphaIndex UVcoords exportUV exportColours;
  235. if (res==0) then
  236. (
  237. newVertex = 1 ;
  238. --format "nouveau vertex % % %\n" vertexIndex vertexNormal UVcoords;
  239. )
  240. else
  241. (
  242. newVertex = 0;
  243. ogreVertNum = res;
  244. )
  245. if (newVertex == 1) then -- That is to say it has not been found.
  246. (
  247. -- Maybe the material found defines a new submesh...
  248. if (verticesArrays[matId] == undefined) then
  249. (
  250. format "- Submesh detected: material ID = %\n" matId
  251. verticesArrays[matId] = #() ;
  252. boneAssignments[matId] = #() ;
  253. append submeshesId matId ;
  254. )
  255. -- the vertex number for the current submesh must be updated
  256. -- vertex number is increased
  257. ogreVertNum = verticesArrays[matId].count + 1;
  258. -- it is added to the searchTable
  259. if (searchTable[vertexIndex]==undefined) then
  260. (
  261. searchTable[vertexIndex] = #() ;
  262. )
  263. local data = #();
  264. append data ogreVertNum ;
  265. n = copy vertexNormal ;
  266. append data n ;
  267. if (exportColours) then
  268. (
  269. append data VertexColorIndex ;
  270. append data VertexAlphaIndex ;
  271. )
  272. if (exportUV) then
  273. (
  274. if (UVcoords.count > 0) then
  275. (
  276. for uv=1 to UVcoords.count do
  277. append data UVcoords[uv];
  278. )
  279. )
  280. append searchTable[vertexIndex] data ;
  281. -- we retrieve data
  282. vertexPosition = getVert tmesh faceVerticesIndices[localVertexIndex] ;
  283. vertexColor = Point3 0 0 0;
  284. vertexAlpha = 255;
  285. if (exportColours) then
  286. (
  287. vertexColor = (meshOp.getMapVert tmesh 0 vertexColorIndex);
  288. vertexAlpha = (meshOp.getMapVert tmesh -2 vertexAlphaIndex)[1];
  289. )
  290. -- change scale
  291. vertexPosition = vertexPosition * scale ;
  292. -- flip axes
  293. if (flipyz) then
  294. (
  295. vertTmp = copy vertexPosition ;
  296. vertexPosition[2] = vertTmp[3] ;
  297. vertexPosition[3] = -vertTmp[2] ;
  298. nmalTmp = copy vertexNormal ;
  299. vertexNormal[2] = nmalTmp[3] ;
  300. vertexNormal[3] = -nmalTmp[2] ;
  301. )
  302. -- store the vertex in verticesArrays
  303. vertexData = #(vertexPosition[1],vertexPosition[2],vertexPosition[3],vertexNormal[1],vertexNormal[2],vertexNormal[3],vertexColor[1],vertexColor[2],vertexColor[3],vertexAlpha) ;
  304. if (exportUV) then
  305. (
  306. for ch=1 to numUVsets do
  307. (
  308. append vertexData UVcoords[1+(ch-1)*2];
  309. append vertexData UVcoords[2+(ch-1)*2];
  310. )
  311. )
  312. append verticesArrays[matId] vertexData ; -- Vertex is added to datas
  313. -- And now, bone assignments. (if a skin modifier is present)
  314. -- It seems that there are issues when just few vertices have bone assignments.
  315. -- So there is at least the root assignment.
  316. if (sk != undefined) then
  317. (
  318. vertexWeightCount = skinOps.getVertexWeightCount sk vertexIndex ;
  319. if (vertexWeightCount > 4) then
  320. (
  321. if (not g_MAX) then
  322. (
  323. format "*** vertex % has more than 4 bones assigned...\n" vertexIndex;
  324. )
  325. )
  326. for k=1 to vertexWeightCount do
  327. (
  328. bid = skinOps.getVertexWeightBoneID sk vertexIndex k ;
  329. bname = skinOps.getBoneName sk bid 1 ;
  330. bname = replaceSpaces bname;
  331. vertexWeight = skinOps.getVertexWeight sk vertexIndex k ;
  332. id_bone = findItem BonesList bname;
  333. if (id_bone != 0) then
  334. append boneAssignments[matId] #(ogreVertNum-1,id_bone-1,vertexWeight) ;
  335. )
  336. -- assignment to the root bone.
  337. if (vertexWeightCount==0) then
  338. (
  339. -- gets the root Id:
  340. rootId=getRootsId sk
  341. rootname = skinOps.getBoneName sk rootId[1] 1 ;
  342. id_bone = findItem BonesList rootname ;
  343. if (id_bone != 0) then
  344. append boneAssignments[matId] #(ogreVertNum-1,id_bone-1,1) ;
  345. )
  346. )
  347. -- same thing with physique modifier if defined
  348. if (phy != undefined) then
  349. (
  350. vertexWeightCount = physiqueOps.getVertexBoneCount $ vertexIndex ;
  351. if (vertexWeightCount > 4) then
  352. (
  353. if (not g_MAX) then
  354. (
  355. format "*** vertex % has more than 4 bones assigned...\n" vertexIndex;
  356. )
  357. )
  358. for k=1 to vertexWeightCount do
  359. (
  360. bone = physiqueOps.getVertexBone $ vertexIndex k
  361. vertexWeight = physiqueOps.getVertexWeight $ vertexIndex k
  362. -- search the bone number
  363. bname = replaceSpaces bone.name;
  364. id_bone = findItem BonesList bname ;
  365. if (id_bone!=0) then
  366. append boneAssignments[matId] #(ogreVertNum-1,id_bone-1,vertexWeight) ;
  367. )
  368. -- assignment to the first bone if the vertex was not assigned.
  369. if (vertexWeightCount==0) then
  370. (
  371. -- gets the root Id:
  372. append boneAssignments[matId] #(ogreVertNum-1,0,1) ;
  373. )
  374. )
  375. )
  376. ogreFace[localVertexIndex] = ogreVertNum - 1;
  377. )
  378. -- flip normal capability
  379. if (flipNormal) then
  380. (
  381. faceTmp = copy ogreFace ;
  382. ogreFace[2] = faceTmp[3] ;
  383. ogreFace[3] = faceTmp[2] ;
  384. )
  385. if (facesArrays[matId] == undefined) then
  386. facesArrays[matId] = #() ;
  387. append facesArrays[matId] #(ogreFace[1],ogreFace[2],ogreFace[3]) ; -- Face is added to datas
  388. )
  389. )
  390. -------------------------------------------------
  391. -- writes in the mesh.xml file
  392. -- outName : filename
  393. -- exportUV = true if you want to export texture
  394. -- numUVsets : number of UVs sets per vertex to be exported (only relevant if exportUV = true)
  395. -- exportColor = true if you want to export vertices colors
  396. -- material : material used by the mesh
  397. -- Uses the arrays verticesArrays and facesArrays
  398. -------------------------------------------------
  399. function writeM exportUV numUVsets exportColours material outName =
  400. (
  401. local a,v,f,submatname,hasSkeleton,outFile,hasColours,matId ;
  402. hasSkeleton = false ;
  403. texCoordString = "" ;
  404. if (exportUV) then
  405. (
  406. texCoordString = "texture_coords=\"" + (numUVsets as string) + "\" " ;
  407. for num=1 to numUVsets do
  408. (
  409. texCoordString = texCoordString + "texture_coords_dimensions_" + ((num-1) as string) + "=\"2\" "; -- I really don't care about the W coordinates
  410. )
  411. )
  412. hasColours = "false" ;
  413. if (exportColours) then
  414. hasColours = "true" ;
  415. -- the final file is created
  416. if (g_MAX) then
  417. (
  418. ClearListener();
  419. if (g_MAX_use_listener) then
  420. format("<ogrestartfile>%</ogrestartfile><ogrestartdata>\n") (outName + ".mesh.xml");
  421. outFile = listener;
  422. )
  423. else
  424. (
  425. outFile = createfile (outName + ".mesh.xml") ;
  426. )
  427. -- writes the header
  428. format("<mesh>\n") to:outFile ;
  429. -- submeshes start
  430. format("\t<submeshes>\n") to:outFile ;
  431. -- for each submesh
  432. for matId in submeshesId do
  433. (
  434. -- Do we need 32-bit indexes?
  435. use32bitindexes = "false";
  436. if arrayLength verticesArrays[matId] > 65535 then
  437. use32bitindexes = "true";
  438. -- get the name of the sub material if needed.
  439. submatname = replacespaces material.name ;
  440. if (classof material == MultiMaterial) then
  441. (
  442. if (material.materialList[matId]==undefined) then
  443. (
  444. msg = "";
  445. format "You are using in your mesh a material Id (%) that does not exist in your MultiMaterial (%)\nMaterial information won't be properly exported." matId submatname to:msg ;
  446. messageBox msg;
  447. )
  448. else
  449. (
  450. submatname += "/" + replacespaces material.materiallist[matId].name ;
  451. )
  452. )
  453. -- HELLO ! --
  454. ---------------------------------------------------------------------------------
  455. -- IF YOU COME HERE BECAUSE YOUR OBJECT FAILED EXPORTING, MAYBE THAT'S BECAUSE --
  456. -- YOU USE MATERIAL ID IN YOUR MESH THAT DOESN'T EXIST IN YOUR MULTIMATERIAL --
  457. ---------------------------------------------------------------------------------
  458. format("\t\t<submesh material = \"%\" usesharedvertices=\"false\" use32bitindexes=\"%\">\n") submatname use32bitindexes to:outFile ;
  459. if (not g_MAX) then
  460. format "- writing faces...\n"
  461. format("\t\t\t<faces count=\"%\">\n") (arraylength facesArrays[matId]) to:outFile;
  462. -- for each face
  463. for f in facesArrays[matId] do
  464. (
  465. format("\t\t\t\t<face ") to:outFile ;
  466. format("v1=\"%\" v2=\"%\" v3=\"%\" />\n") ((int)f[1]) ((int)f[2]) ((int)f[3]) to:outFile ;
  467. )
  468. format("\t\t\t</faces>\n") to:outFile ;
  469. if (not g_MAX) then
  470. format "- writing vertices...\n"
  471. format("\t\t\t<geometry vertexcount=\"%\">\n") (arrayLength verticesArrays[matId] ) to:outFile;
  472. format("\t\t\t\t<vertexbuffer positions=\"true\" normals=\"true\" colours_diffuse=\"%\" %>\n") hasColours TexCoordString to:outFile ;
  473. -- for each vertex
  474. for v in verticesArrays[matId] do
  475. (
  476. format("\t\t\t\t\t<vertex>\n") to:outFile ;
  477. format("\t\t\t\t\t\t<position x=\"%\" y=\"%\" z=\"%\" />\n") v[1] v[2] v[3] to:outFile ;
  478. format("\t\t\t\t\t\t<normal x=\"%\" y=\"%\" z=\"%\" />\n") v[4] v[5] v[6] to:outFile ;
  479. if (exportUV) then
  480. (
  481. for ch=1 to numUVsets do
  482. format("\t\t\t\t\t\t<texcoord u=\"%\" v=\"%\" />\n") v[11+((ch-1)*2)] (1 - v[12+((ch-1)*2)]) to:outFile ;
  483. )
  484. if (exportColours) then
  485. (
  486. color_string = (v[7] as string) + " " + (v[8] as string) + " " + (v[9] as string) + " " +(v[10] as string);
  487. format("\t\t\t\t\t\t<colour_diffuse value=\"%\" />\n") color_string to:outFile ;
  488. )
  489. format("\t\t\t\t\t</vertex>\n") to:outFile ;
  490. )
  491. format("\t\t\t\t</vertexbuffer>\n") to:outFile ;
  492. format("\t\t\t</geometry>\n") to:outFile ;
  493. -- and now bone assignments (and skeleton), if there is at least one element in boneAssignments array.
  494. if ((arrayLength boneAssignments[matId]) != 0) then
  495. (
  496. hasSkeleton = true ;
  497. if (not g_MAX) then
  498. format "- writing bone assignments...\n"
  499. format("\t\t\t<boneassignments>\n") to:outFile ;
  500. for a in boneAssignments[matId] do
  501. (
  502. format("\t\t\t\t<vertexboneassignment vertexindex=\"%\" boneindex=\"%\" weight=\"%\" />\n") a[1] a[2] a[3] to:outFile ;
  503. )
  504. format("\t\t\t</boneassignments>\n") to:outFile ;
  505. )
  506. -- submesh end
  507. format("\t\t</submesh>\n") to:outFile ;
  508. )
  509. -- submeshes end
  510. format("\t</submeshes>\n") to:outFile ;
  511. -- Skeleton link if there is at least one bone assignement.
  512. if (hasSkeleton) then
  513. (
  514. t = filterstring outName "\\" ;
  515. format ("\t<skeletonlink name=\"%\"/>\n") (t[arrayLength t] + ".skeleton") to:outFile ;
  516. )
  517. format("</mesh>\n") to: outFile ;
  518. if (not g_MAX) then
  519. (
  520. close outFile ;
  521. )
  522. else
  523. (
  524. if (g_MAX_use_listener) then
  525. format("</ogrestartdata>\n") to: outFile;
  526. )
  527. )
  528. ---------------------------------
  529. -- writes the mesh: main function
  530. ---------------------------------
  531. function writeMesh pmesh exportOptions out_name =
  532. (
  533. local m,sk,outFile,message,phy ;
  534. m = snapshotAsMesh pmesh ;
  535. -- tries to find errors
  536. message = exploreMesh pmesh exportOptions.exportUV exportOptions.exportColours;
  537. if (message != "OK") then
  538. (
  539. MessageBox ("\n There is a problem with your mesh:\n" + message + "\n\nOperation aborted") ;
  540. delete m ;
  541. return false ;
  542. )
  543. else
  544. (
  545. format "\n\n"
  546. format "------------------------------------------\n"
  547. format "------- OGRE Mesh Exporter Log -------\n"
  548. format "----- -----\n"
  549. -- get the skin modifier ( may be undefined )
  550. -- and physique modifier
  551. phy = getPhysique pmesh ;
  552. sk = getSkin pmesh;
  553. if (sk != undefined) then
  554. format "Skin modifier detected.\n"
  555. if (phy != undefined) then
  556. format "Physique modifier detected.\n"
  557. -- if not undefined, skin modifier is selected in modifier tab. Or there will be an error.
  558. if (sk != undefined) then
  559. (
  560. -- in order to perform, skin should be opened
  561. max modify mode ;
  562. modPanel.setCurrentObject pmesh.modifiers[#Skin] ;
  563. )
  564. -- physique
  565. if (phy != undefined) then
  566. (
  567. -- in order to perform, skin should be opened
  568. max modify mode ;
  569. modPanel.setCurrentObject pmesh.modifiers[#Physique] ;
  570. --physiqueOps.setInitialPose pmesh true ;
  571. )
  572. OgreExportObject.exportProgress.value = 0;
  573. -- retieving material
  574. if (pmesh.material != undefined) then (
  575. materialName = pmesh.material.name ;
  576. replaceSpaces materialName ;
  577. )
  578. else materialName = pmesh.name + "Material" ;
  579. format "Material name exported : \n- %/*** \n" materialName ;
  580. -- retrieving all datas
  581. format "Retrieving vertices and faces data : \n" ;
  582. getDatas m exportOptions.flipyz exportOptions.scale exportOptions.flipNormal exportOptions.exportUV exportOptions.UVchannels exportOptions.exportColours exportOptions.exportHelpers sk phy;
  583. -- writing in the file
  584. format "Writing in file %.mesh.xml : \n" out_name ;
  585. WriteM exportOptions.exportUV exportOptions.UVchannels exportOptions.exportColours pmesh.material out_name ;
  586. if (not g_MAX) then
  587. format "Export successful.\n"
  588. delete m ;
  589. if (not g_MAX) then
  590. (
  591. format "----- -----\n"
  592. format "---------- END ---------\n"
  593. format "------------------------------------------\n"
  594. )
  595. --MessageBox ("Exporting mesh successful !") ;
  596. OgreExportObject.exportProgress.value = 100;
  597. )
  598. return true ;
  599. )