2
0

Polygon.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. class "Polygon"
  2. function Polygon:__index__(name)
  3. if name == "useVertexNormals" then
  4. return Polycore.Polygon_get_useVertexNormals(self.__ptr)
  5. end
  6. end
  7. function Polygon:__set_callback(name,value)
  8. if name == "useVertexNormals" then
  9. Polycore.Polygon_set_useVertexNormals(self.__ptr, value)
  10. return true
  11. end
  12. return false
  13. end
  14. function Polygon:Polygon(...)
  15. for k,v in pairs(arg) do
  16. if type(v) == "table" then
  17. if v.__ptr ~= nil then
  18. arg[k] = v.__ptr
  19. end
  20. end
  21. end
  22. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  23. self.__ptr = Polycore.Polygon(unpack(arg))
  24. Polycore.__ptr_lookup[self.__ptr] = self
  25. end
  26. end
  27. function Polygon:getVertexCount()
  28. local retVal = Polycore.Polygon_getVertexCount(self.__ptr)
  29. return retVal
  30. end
  31. function Polygon:getVertex(index)
  32. local retVal = Polycore.Polygon_getVertex(self.__ptr, index)
  33. if Polycore.__ptr_lookup[retVal] ~= nil then
  34. return Polycore.__ptr_lookup[retVal]
  35. else
  36. Polycore.__ptr_lookup[retVal] = Vertex("__skip_ptr__")
  37. Polycore.__ptr_lookup[retVal].__ptr = retVal
  38. return Polycore.__ptr_lookup[retVal]
  39. end
  40. end
  41. function Polygon:addVertex(x, y, z)
  42. local retVal = Polycore.Polygon_addVertex(self.__ptr, x, y, z)
  43. if Polycore.__ptr_lookup[retVal] ~= nil then
  44. return Polycore.__ptr_lookup[retVal]
  45. else
  46. Polycore.__ptr_lookup[retVal] = Vertex("__skip_ptr__")
  47. Polycore.__ptr_lookup[retVal].__ptr = retVal
  48. return Polycore.__ptr_lookup[retVal]
  49. end
  50. end
  51. function Polygon:removeVertex(index)
  52. local retVal = Polycore.Polygon_removeVertex(self.__ptr, index)
  53. end
  54. function Polygon:calculateNormal()
  55. local retVal = Polycore.Polygon_calculateNormal(self.__ptr)
  56. end
  57. function Polygon:getFaceNormal()
  58. local retVal = Polycore.Polygon_getFaceNormal(self.__ptr)
  59. if Polycore.__ptr_lookup[retVal] ~= nil then
  60. return Polycore.__ptr_lookup[retVal]
  61. else
  62. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  63. Polycore.__ptr_lookup[retVal].__ptr = retVal
  64. return Polycore.__ptr_lookup[retVal]
  65. end
  66. end
  67. function Polygon:getBounds2D()
  68. local retVal = Polycore.Polygon_getBounds2D(self.__ptr)
  69. if Polycore.__ptr_lookup[retVal] ~= nil then
  70. return Polycore.__ptr_lookup[retVal]
  71. else
  72. Polycore.__ptr_lookup[retVal] = Rectangle("__skip_ptr__")
  73. Polycore.__ptr_lookup[retVal].__ptr = retVal
  74. return Polycore.__ptr_lookup[retVal]
  75. end
  76. end
  77. function Polygon:setNormal(normal)
  78. local retVal = Polycore.Polygon_setNormal(self.__ptr, normal.__ptr)
  79. end
  80. function Polygon:flipUVY()
  81. local retVal = Polycore.Polygon_flipUVY(self.__ptr)
  82. end