Mesh.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. end
  31. end
  32. function Mesh:addPolygon(newPolygon)
  33. local retVal = Polycore.Mesh_addPolygon(self.__ptr, newPolygon.__ptr)
  34. end
  35. function Mesh:loadMesh(fileName)
  36. local retVal = Polycore.Mesh_loadMesh(self.__ptr, fileName)
  37. end
  38. function Mesh:loadFromFile(inFile)
  39. local retVal = Polycore.Mesh_loadFromFile(self.__ptr, inFile.__ptr)
  40. end
  41. function Mesh:saveToFile(outFile)
  42. local retVal = Polycore.Mesh_saveToFile(self.__ptr, outFile.__ptr)
  43. end
  44. function Mesh:getPolygonCount()
  45. local retVal = Polycore.Mesh_getPolygonCount(self.__ptr)
  46. return retVal
  47. end
  48. function Mesh:getPolygon(index)
  49. local retVal = Polycore.Mesh_getPolygon(self.__ptr, index)
  50. if Polycore.__ptr_lookup[retVal] ~= nil then
  51. return Polycore.__ptr_lookup[retVal]
  52. else
  53. Polycore.__ptr_lookup[retVal] = Polygon("__skip_ptr__")
  54. Polycore.__ptr_lookup[retVal].__ptr = retVal
  55. return Polycore.__ptr_lookup[retVal]
  56. end
  57. end
  58. function Mesh:createPlane(w, h)
  59. local retVal = Polycore.Mesh_createPlane(self.__ptr, w, h)
  60. end
  61. function Mesh:createBox(w, d, h)
  62. local retVal = Polycore.Mesh_createBox(self.__ptr, w, d, h)
  63. end
  64. function Mesh:createSphere(radius, numRings, numSegments)
  65. local retVal = Polycore.Mesh_createSphere(self.__ptr, radius, numRings, numSegments)
  66. end
  67. function Mesh:addVertex(vertex)
  68. local retVal = Polycore.Mesh_addVertex(self.__ptr, vertex.__ptr)
  69. end
  70. function Mesh:getVertex(index)
  71. local retVal = Polycore.Mesh_getVertex(self.__ptr, index)
  72. if Polycore.__ptr_lookup[retVal] ~= nil then
  73. return Polycore.__ptr_lookup[retVal]
  74. else
  75. Polycore.__ptr_lookup[retVal] = Vertex("__skip_ptr__")
  76. Polycore.__ptr_lookup[retVal].__ptr = retVal
  77. return Polycore.__ptr_lookup[retVal]
  78. end
  79. end
  80. function Mesh:getNumVertices()
  81. local retVal = Polycore.Mesh_getNumVertices(self.__ptr)
  82. return retVal
  83. end
  84. function Mesh:recenterMesh()
  85. local retVal = Polycore.Mesh_recenterMesh(self.__ptr)
  86. if Polycore.__ptr_lookup[retVal] ~= nil then
  87. return Polycore.__ptr_lookup[retVal]
  88. else
  89. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  90. Polycore.__ptr_lookup[retVal].__ptr = retVal
  91. return Polycore.__ptr_lookup[retVal]
  92. end
  93. end
  94. function Mesh:useVertexNormals(val)
  95. local retVal = Polycore.Mesh_useVertexNormals(self.__ptr, val)
  96. end
  97. function Mesh:getVertexIndex(vertex)
  98. local retVal = Polycore.Mesh_getVertexIndex(self.__ptr, vertex.__ptr)
  99. return retVal
  100. end
  101. function Mesh:setVertexBuffer(buffer)
  102. local retVal = Polycore.Mesh_setVertexBuffer(self.__ptr, buffer.__ptr)
  103. end
  104. function Mesh:getVertexBuffer()
  105. local retVal = Polycore.Mesh_getVertexBuffer(self.__ptr)
  106. if Polycore.__ptr_lookup[retVal] ~= nil then
  107. return Polycore.__ptr_lookup[retVal]
  108. else
  109. Polycore.__ptr_lookup[retVal] = VertexBuffer("__skip_ptr__")
  110. Polycore.__ptr_lookup[retVal].__ptr = retVal
  111. return Polycore.__ptr_lookup[retVal]
  112. end
  113. end
  114. function Mesh:usesFaceUV()
  115. local retVal = Polycore.Mesh_usesFaceUV(self.__ptr)
  116. return retVal
  117. end
  118. function Mesh:getRadius()
  119. local retVal = Polycore.Mesh_getRadius(self.__ptr)
  120. return retVal
  121. end
  122. function Mesh:calculateNormals()
  123. local retVal = Polycore.Mesh_calculateNormals(self.__ptr)
  124. end
  125. function Mesh:getMeshType()
  126. local retVal = Polycore.Mesh_getMeshType(self.__ptr)
  127. return retVal
  128. end
  129. function Mesh:setMeshType(newType)
  130. local retVal = Polycore.Mesh_setMeshType(self.__ptr, newType)
  131. end
  132. function Mesh:calculateBBox()
  133. local retVal = Polycore.Mesh_calculateBBox(self.__ptr)
  134. if Polycore.__ptr_lookup[retVal] ~= nil then
  135. return Polycore.__ptr_lookup[retVal]
  136. else
  137. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  138. Polycore.__ptr_lookup[retVal].__ptr = retVal
  139. return Polycore.__ptr_lookup[retVal]
  140. end
  141. end
  142. function Mesh:hasVertexBuffer()
  143. local retVal = Polycore.Mesh_hasVertexBuffer(self.__ptr)
  144. return retVal
  145. end