Mesh.lua 4.2 KB

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