Mesh.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. class "Mesh"
  2. QUAD_MESH = 0
  3. TRI_MESH = 1
  4. TRIFAN_MESH = 2
  5. TRISTRIP_MESH = 3
  6. LINE_MESH = 4
  7. POINT_MESH = 5
  8. function Mesh:__index__(name)
  9. if name == "useVertexColors" then
  10. return Polycore.Mesh_get_useVertexColors(self.__ptr)
  11. end
  12. end
  13. function Mesh:__set_callback(name,value)
  14. if name == "useVertexColors" then
  15. Polycore.Mesh_set_useVertexColors(self.__ptr, value)
  16. return true
  17. end
  18. return false
  19. end
  20. function Mesh:Mesh(...)
  21. for k,v in pairs(arg) do
  22. if type(v) == "table" then
  23. if v.__ptr ~= nil then
  24. arg[k] = v.__ptr
  25. end
  26. end
  27. end
  28. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  29. self.__ptr = Polycore.Mesh(unpack(arg))
  30. Polycore.__ptr_lookup[self.__ptr] = self
  31. end
  32. end
  33. function Mesh:addPolygon(newPolygon)
  34. local retVal = Polycore.Mesh_addPolygon(self.__ptr, newPolygon.__ptr)
  35. end
  36. function Mesh:loadMesh(fileName)
  37. local retVal = Polycore.Mesh_loadMesh(self.__ptr, fileName)
  38. end
  39. function Mesh:clearMesh()
  40. local retVal = Polycore.Mesh_clearMesh(self.__ptr)
  41. end
  42. function Mesh:saveToFile(fileName)
  43. local retVal = Polycore.Mesh_saveToFile(self.__ptr, fileName)
  44. end
  45. function Mesh:loadFromFile(inFile)
  46. local retVal = Polycore.Mesh_loadFromFile(self.__ptr, inFile.__ptr)
  47. end
  48. function Mesh:getPolygonCount()
  49. local retVal = Polycore.Mesh_getPolygonCount(self.__ptr)
  50. return retVal
  51. end
  52. function Mesh:getVertexCount()
  53. local retVal = Polycore.Mesh_getVertexCount(self.__ptr)
  54. return retVal
  55. end
  56. function Mesh:getPolygon(index)
  57. local retVal = Polycore.Mesh_getPolygon(self.__ptr, index)
  58. if retVal == nil then return nil end
  59. if Polycore.__ptr_lookup[retVal] ~= nil then
  60. return Polycore.__ptr_lookup[retVal]
  61. else
  62. Polycore.__ptr_lookup[retVal] = Polygon("__skip_ptr__")
  63. Polycore.__ptr_lookup[retVal].__ptr = retVal
  64. return Polycore.__ptr_lookup[retVal]
  65. end
  66. end
  67. function Mesh:createPlane(w, h)
  68. local retVal = Polycore.Mesh_createPlane(self.__ptr, w, h)
  69. end
  70. function Mesh:createVPlane(w, h)
  71. local retVal = Polycore.Mesh_createVPlane(self.__ptr, w, h)
  72. end
  73. function Mesh:createTorus(radius, tubeRadius, rSegments, tSegments)
  74. local retVal = Polycore.Mesh_createTorus(self.__ptr, radius, tubeRadius, rSegments, tSegments)
  75. end
  76. function Mesh:createBox(w, d, h)
  77. local retVal = Polycore.Mesh_createBox(self.__ptr, w, d, h)
  78. end
  79. function Mesh:createSphere(radius, numRings, numSegments)
  80. local retVal = Polycore.Mesh_createSphere(self.__ptr, radius, numRings, numSegments)
  81. end
  82. function Mesh:createCylinder(height, radius, numSegments)
  83. local retVal = Polycore.Mesh_createCylinder(self.__ptr, height, radius, numSegments)
  84. end
  85. function Mesh:createCone(height, radius, numSegments)
  86. local retVal = Polycore.Mesh_createCone(self.__ptr, height, radius, numSegments)
  87. end
  88. function Mesh:recenterMesh()
  89. local retVal = Polycore.Mesh_recenterMesh(self.__ptr)
  90. if retVal == nil then return nil end
  91. if Polycore.__ptr_lookup[retVal] ~= nil then
  92. return Polycore.__ptr_lookup[retVal]
  93. else
  94. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  95. Polycore.__ptr_lookup[retVal].__ptr = retVal
  96. return Polycore.__ptr_lookup[retVal]
  97. end
  98. end
  99. function Mesh:useVertexNormals(val)
  100. local retVal = Polycore.Mesh_useVertexNormals(self.__ptr, val)
  101. end
  102. function Mesh:setVertexBuffer(buffer)
  103. local retVal = Polycore.Mesh_setVertexBuffer(self.__ptr, buffer.__ptr)
  104. end
  105. function Mesh:getVertexBuffer()
  106. local retVal = Polycore.Mesh_getVertexBuffer(self.__ptr)
  107. if retVal == nil then return nil end
  108. if Polycore.__ptr_lookup[retVal] ~= nil then
  109. return Polycore.__ptr_lookup[retVal]
  110. else
  111. Polycore.__ptr_lookup[retVal] = VertexBuffer("__skip_ptr__")
  112. Polycore.__ptr_lookup[retVal].__ptr = retVal
  113. return Polycore.__ptr_lookup[retVal]
  114. end
  115. end
  116. function Mesh:getRadius()
  117. local retVal = Polycore.Mesh_getRadius(self.__ptr)
  118. return retVal
  119. end
  120. function Mesh:calculateNormals(smooth, smoothAngle)
  121. local retVal = Polycore.Mesh_calculateNormals(self.__ptr, smooth, smoothAngle)
  122. end
  123. function Mesh:calculateTangents()
  124. local retVal = Polycore.Mesh_calculateTangents(self.__ptr)
  125. end
  126. function Mesh:getMeshType()
  127. local retVal = Polycore.Mesh_getMeshType(self.__ptr)
  128. return retVal
  129. end
  130. function Mesh:setMeshType(newType)
  131. local retVal = Polycore.Mesh_setMeshType(self.__ptr, newType)
  132. end
  133. function Mesh:calculateBBox()
  134. local retVal = Polycore.Mesh_calculateBBox(self.__ptr)
  135. if retVal == nil then return nil end
  136. if Polycore.__ptr_lookup[retVal] ~= nil then
  137. return Polycore.__ptr_lookup[retVal]
  138. else
  139. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  140. Polycore.__ptr_lookup[retVal].__ptr = retVal
  141. return Polycore.__ptr_lookup[retVal]
  142. end
  143. end
  144. function Mesh:hasVertexBuffer()
  145. local retVal = Polycore.Mesh_hasVertexBuffer(self.__ptr)
  146. return retVal
  147. end
  148. function Mesh:__delete()
  149. Polycore.__ptr_lookup[self.__ptr] = nil
  150. Polycore.delete_Mesh(self.__ptr)
  151. end