Polygon.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. end
  25. end
  26. function Polygon:getVertexCount()
  27. local retVal = Polycore.Polygon_getVertexCount(self.__ptr)
  28. return retVal
  29. end
  30. function Polygon:getVertex(index)
  31. local retVal = Polycore.Polygon_getVertex(self.__ptr, index)
  32. if Polycore.__ptr_lookup[retVal] ~= nil then
  33. return Polycore.__ptr_lookup[retVal]
  34. else
  35. Polycore.__ptr_lookup[retVal] = Vertex("__skip_ptr__")
  36. Polycore.__ptr_lookup[retVal].__ptr = retVal
  37. return Polycore.__ptr_lookup[retVal]
  38. end
  39. end
  40. function Polygon:addVertex(x, y, z)
  41. local retVal = Polycore.Polygon_addVertex(self.__ptr, x, y, z)
  42. if Polycore.__ptr_lookup[retVal] ~= nil then
  43. return Polycore.__ptr_lookup[retVal]
  44. else
  45. Polycore.__ptr_lookup[retVal] = Vertex("__skip_ptr__")
  46. Polycore.__ptr_lookup[retVal].__ptr = retVal
  47. return Polycore.__ptr_lookup[retVal]
  48. end
  49. end
  50. function Polygon:removeVertex(index)
  51. local retVal = Polycore.Polygon_removeVertex(self.__ptr, index)
  52. end
  53. function Polygon:calculateNormal()
  54. local retVal = Polycore.Polygon_calculateNormal(self.__ptr)
  55. end
  56. function Polygon:getFaceNormal()
  57. local retVal = Polycore.Polygon_getFaceNormal(self.__ptr)
  58. if Polycore.__ptr_lookup[retVal] ~= nil then
  59. return Polycore.__ptr_lookup[retVal]
  60. else
  61. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  62. Polycore.__ptr_lookup[retVal].__ptr = retVal
  63. return Polycore.__ptr_lookup[retVal]
  64. end
  65. end
  66. function Polygon:getBounds2D()
  67. local retVal = Polycore.Polygon_getBounds2D(self.__ptr)
  68. if Polycore.__ptr_lookup[retVal] ~= nil then
  69. return Polycore.__ptr_lookup[retVal]
  70. else
  71. Polycore.__ptr_lookup[retVal] = Rectangle("__skip_ptr__")
  72. Polycore.__ptr_lookup[retVal].__ptr = retVal
  73. return Polycore.__ptr_lookup[retVal]
  74. end
  75. end
  76. function Polygon:setNormal(normal)
  77. local retVal = Polycore.Polygon_setNormal(self.__ptr, normal.__ptr)
  78. end
  79. function Polygon:flipUVY()
  80. local retVal = Polycore.Polygon_flipUVY(self.__ptr)
  81. end