Mesh.lua 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. require "Polycode/Resource"
  2. class "Mesh" (Resource)
  3. Mesh.TRISTRIP_MESH = 0
  4. Mesh.TRI_MESH = 1
  5. Mesh.TRIFAN_MESH = 2
  6. Mesh.LINE_MESH = 4
  7. Mesh.POINT_MESH = 5
  8. Mesh.LINE_STRIP_MESH = 6
  9. Mesh.LINE_LOOP_MESH = 7
  10. function Mesh:__getvar(name)
  11. if name == "indexedMesh" then
  12. return Polycode.Mesh_get_indexedMesh(self.__ptr)
  13. end
  14. if Resource["__getvar"] ~= nil then
  15. return Resource.__getvar(self, name)
  16. end
  17. end
  18. function Mesh:__setvar(name,value)
  19. if name == "indexedMesh" then
  20. Polycode.Mesh_set_indexedMesh(self.__ptr, value)
  21. return true
  22. end
  23. if Resource["__setvar"] ~= nil then
  24. return Resource.__setvar(self, name, value)
  25. else
  26. return false
  27. end
  28. end
  29. function Mesh:Mesh(...)
  30. local arg = {...}
  31. if type(arg[1]) == "table" and count(arg) == 1 then
  32. if ""..arg[1].__classname == "Resource" then
  33. self.__ptr = arg[1].__ptr
  34. return
  35. end
  36. end
  37. for k,v in pairs(arg) do
  38. if type(v) == "table" then
  39. if v.__ptr ~= nil then
  40. arg[k] = v.__ptr
  41. end
  42. end
  43. end
  44. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  45. self.__ptr = Polycode.Mesh(unpack(arg))
  46. end
  47. end
  48. function Mesh:MeshFromFileName(fileName)
  49. local retVal = Polycode.Mesh_MeshFromFileName(self.__ptr, fileName)
  50. if retVal == nil then return nil end
  51. local __c = _G["Mesh"]("__skip_ptr__")
  52. __c.__ptr = retVal
  53. return __c
  54. end
  55. function Mesh:loadMesh(fileName)
  56. local retVal = Polycode.Mesh_loadMesh(self.__ptr, fileName)
  57. end
  58. function Mesh:clearMesh()
  59. local retVal = Polycode.Mesh_clearMesh(self.__ptr)
  60. end
  61. function Mesh:saveToFile(fileName, writeNormals, writeTangents, writeColors, writeBoneWeights, writeUVs, writeSecondaryUVs)
  62. local retVal = Polycode.Mesh_saveToFile(self.__ptr, fileName, writeNormals, writeTangents, writeColors, writeBoneWeights, writeUVs, writeSecondaryUVs)
  63. end
  64. function Mesh:loadFromFile(inFile)
  65. local retVal = Polycode.Mesh_loadFromFile(self.__ptr, inFile.__ptr)
  66. end
  67. function Mesh:getVertexCount()
  68. local retVal = Polycode.Mesh_getVertexCount(self.__ptr)
  69. return retVal
  70. end
  71. function Mesh:createPlane(w, h, tilingValue)
  72. local retVal = Polycode.Mesh_createPlane(self.__ptr, w, h, tilingValue)
  73. end
  74. function Mesh:createVPlane(w, h, tilingValue)
  75. local retVal = Polycode.Mesh_createVPlane(self.__ptr, w, h, tilingValue)
  76. end
  77. function Mesh:createCircle(w, h, numSegments, tilingValue)
  78. local retVal = Polycode.Mesh_createCircle(self.__ptr, w, h, numSegments, tilingValue)
  79. end
  80. function Mesh:createLineCircle(w, h, numSegments, tilingValue)
  81. local retVal = Polycode.Mesh_createLineCircle(self.__ptr, w, h, numSegments, tilingValue)
  82. end
  83. function Mesh:createTorus(radius, tubeRadius, segmentsW, segmentsH, tilingValue)
  84. local retVal = Polycode.Mesh_createTorus(self.__ptr, radius, tubeRadius, segmentsW, segmentsH, tilingValue)
  85. end
  86. function Mesh:createBox(w, d, h, tilingValue)
  87. local retVal = Polycode.Mesh_createBox(self.__ptr, w, d, h, tilingValue)
  88. end
  89. function Mesh:createSphere(radius, numRings, numSegments, tilingValue)
  90. local retVal = Polycode.Mesh_createSphere(self.__ptr, radius, numRings, numSegments, tilingValue)
  91. end
  92. function Mesh:createIcosphere(radius, subdivisions)
  93. local retVal = Polycode.Mesh_createIcosphere(self.__ptr, radius, subdivisions)
  94. end
  95. function Mesh:createOctosphere(radius, subdivisions)
  96. local retVal = Polycode.Mesh_createOctosphere(self.__ptr, radius, subdivisions)
  97. end
  98. function Mesh:createCylinder(height, radius, numSegments, capped, tilingValue)
  99. local retVal = Polycode.Mesh_createCylinder(self.__ptr, height, radius, numSegments, capped, tilingValue)
  100. end
  101. function Mesh:createCone(height, radius, numSegments, tilingValue)
  102. local retVal = Polycode.Mesh_createCone(self.__ptr, height, radius, numSegments, tilingValue)
  103. end
  104. function Mesh:recenterMesh()
  105. local retVal = Polycode.Mesh_recenterMesh(self.__ptr)
  106. if retVal == nil then return nil end
  107. local __c = _G["Vector3"]("__skip_ptr__")
  108. __c.__ptr = retVal
  109. return __c
  110. end
  111. function Mesh:setVertexAtOffset(offset, x, y, z)
  112. local retVal = Polycode.Mesh_setVertexAtOffset(self.__ptr, offset, x, y, z)
  113. end
  114. function Mesh:addVertexWithUVAndNormal(x, y, z, u, v, nx, ny, nz)
  115. local retVal = Polycode.Mesh_addVertexWithUVAndNormal(self.__ptr, x, y, z, u, v, nx, ny, nz)
  116. end
  117. function Mesh:addTexCoord(u, v)
  118. local retVal = Polycode.Mesh_addTexCoord(self.__ptr, u, v)
  119. end
  120. function Mesh:addTexCoord2(u, v)
  121. local retVal = Polycode.Mesh_addTexCoord2(self.__ptr, u, v)
  122. end
  123. function Mesh:addTangent(x, y, z)
  124. local retVal = Polycode.Mesh_addTangent(self.__ptr, x, y, z)
  125. end
  126. function Mesh:addVertexWithUV(x, y, z, u, v)
  127. local retVal = Polycode.Mesh_addVertexWithUV(self.__ptr, x, y, z, u, v)
  128. end
  129. function Mesh:addVertex(x, y, z)
  130. local retVal = Polycode.Mesh_addVertex(self.__ptr, x, y, z)
  131. end
  132. function Mesh:addNormal(nx, ny, nz)
  133. local retVal = Polycode.Mesh_addNormal(self.__ptr, nx, ny, nz)
  134. end
  135. function Mesh:addBoneAssignments(b1Weight, b1Index, b2Weight, b2Index, b3Weight, b3Index, b4Weight, b4Index)
  136. local retVal = Polycode.Mesh_addBoneAssignments(self.__ptr, b1Weight, b1Index, b2Weight, b2Index, b3Weight, b3Index, b4Weight, b4Index)
  137. end
  138. function Mesh:addColor(r, g, b, a)
  139. local retVal = Polycode.Mesh_addColor(self.__ptr, r, g, b, a)
  140. end
  141. function Mesh:getVertexPosition(vertexOffset)
  142. local retVal = Polycode.Mesh_getVertexPosition(self.__ptr, vertexOffset)
  143. if retVal == nil then return nil end
  144. local __c = _G["Vector3"]("__skip_ptr__")
  145. __c.__ptr = retVal
  146. return __c
  147. end
  148. function Mesh:getVertexPositionAtIndex(index)
  149. local retVal = Polycode.Mesh_getVertexPositionAtIndex(self.__ptr, index)
  150. if retVal == nil then return nil end
  151. local __c = _G["Vector3"]("__skip_ptr__")
  152. __c.__ptr = retVal
  153. return __c
  154. end
  155. function Mesh:getVertexTexCoord(vertexOffset)
  156. local retVal = Polycode.Mesh_getVertexTexCoord(self.__ptr, vertexOffset)
  157. if retVal == nil then return nil end
  158. local __c = _G["Vector2"]("__skip_ptr__")
  159. __c.__ptr = retVal
  160. return __c
  161. end
  162. function Mesh:getVertexTexCoordAtIndex(index)
  163. local retVal = Polycode.Mesh_getVertexTexCoordAtIndex(self.__ptr, index)
  164. if retVal == nil then return nil end
  165. local __c = _G["Vector2"]("__skip_ptr__")
  166. __c.__ptr = retVal
  167. return __c
  168. end
  169. function Mesh:Copy()
  170. local retVal = Polycode.Mesh_Copy(self.__ptr)
  171. if retVal == nil then return nil end
  172. local __c = _G["Mesh"]("__skip_ptr__")
  173. __c.__ptr = retVal
  174. return __c
  175. end
  176. function Mesh:getRadius()
  177. local retVal = Polycode.Mesh_getRadius(self.__ptr)
  178. return retVal
  179. end
  180. function Mesh:calculateNormals()
  181. local retVal = Polycode.Mesh_calculateNormals(self.__ptr)
  182. end
  183. function Mesh:calculateTangents()
  184. local retVal = Polycode.Mesh_calculateTangents(self.__ptr)
  185. end
  186. function Mesh:getMeshType()
  187. local retVal = Polycode.Mesh_getMeshType(self.__ptr)
  188. return retVal
  189. end
  190. function Mesh:setMeshType(newType)
  191. local retVal = Polycode.Mesh_setMeshType(self.__ptr, newType)
  192. end
  193. function Mesh:getIndexGroupSize()
  194. local retVal = Polycode.Mesh_getIndexGroupSize(self.__ptr)
  195. return retVal
  196. end
  197. function Mesh:calculateBBox()
  198. local retVal = Polycode.Mesh_calculateBBox(self.__ptr)
  199. if retVal == nil then return nil end
  200. local __c = _G["Vector3"]("__skip_ptr__")
  201. __c.__ptr = retVal
  202. return __c
  203. end
  204. function Mesh:hasVertexBuffer()
  205. local retVal = Polycode.Mesh_hasVertexBuffer(self.__ptr)
  206. return retVal
  207. end
  208. function Mesh:addIndexedFace(i1, i2)
  209. local retVal = Polycode.Mesh_addIndexedFace(self.__ptr, i1, i2)
  210. end
  211. function Mesh:addIndex(index)
  212. local retVal = Polycode.Mesh_addIndex(self.__ptr, index)
  213. end
  214. function Mesh:removeVertexRange(beginRemoveVertex, vertexRemovalCount)
  215. local retVal = Polycode.Mesh_removeVertexRange(self.__ptr, beginRemoveVertex, vertexRemovalCount)
  216. end
  217. function Mesh:removeFace(faceIndex)
  218. local retVal = Polycode.Mesh_removeFace(self.__ptr, faceIndex)
  219. end
  220. function Mesh:removeUnusedVertices()
  221. local retVal = Polycode.Mesh_removeUnusedVertices(self.__ptr)
  222. return retVal
  223. end
  224. function Mesh:getIndexCount()
  225. local retVal = Polycode.Mesh_getIndexCount(self.__ptr)
  226. return retVal
  227. end
  228. function Mesh:subdivideToRadius(radius, subdivisions)
  229. local retVal = Polycode.Mesh_subdivideToRadius(self.__ptr, radius, subdivisions)
  230. end
  231. function Mesh:calculateFaceTangent(v1, v2, v3, texCoord1, texCoord2, texCoord3)
  232. local retVal = Polycode.Mesh_calculateFaceTangent(self.__ptr, v1.__ptr, v2.__ptr, v3.__ptr, texCoord1.__ptr, texCoord2.__ptr, texCoord3.__ptr)
  233. if retVal == nil then return nil end
  234. local __c = _G["Vector3"]("__skip_ptr__")
  235. __c.__ptr = retVal
  236. return __c
  237. end
  238. function Mesh:saveAsOBJ(fileName)
  239. local retVal = Polycode.Mesh_saveAsOBJ(self.__ptr, fileName)
  240. end
  241. function Mesh:normalizeBoneWeights()
  242. local retVal = Polycode.Mesh_normalizeBoneWeights(self.__ptr)
  243. end
  244. function Mesh:__delete()
  245. if self then Polycode.delete_Mesh(self.__ptr) end
  246. end