Polygon.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 retVal == nil then return nil end
  34. if Polycore.__ptr_lookup[retVal] ~= nil then
  35. return Polycore.__ptr_lookup[retVal]
  36. else
  37. Polycore.__ptr_lookup[retVal] = Vertex("__skip_ptr__")
  38. Polycore.__ptr_lookup[retVal].__ptr = retVal
  39. return Polycore.__ptr_lookup[retVal]
  40. end
  41. end
  42. function Polygon:addVertex(x, y, z)
  43. local retVal = Polycore.Polygon_addVertex(self.__ptr, x, y, z)
  44. if retVal == nil then return nil end
  45. if Polycore.__ptr_lookup[retVal] ~= nil then
  46. return Polycore.__ptr_lookup[retVal]
  47. else
  48. Polycore.__ptr_lookup[retVal] = Vertex("__skip_ptr__")
  49. Polycore.__ptr_lookup[retVal].__ptr = retVal
  50. return Polycore.__ptr_lookup[retVal]
  51. end
  52. end
  53. function Polygon:removeVertex(index)
  54. local retVal = Polycore.Polygon_removeVertex(self.__ptr, index)
  55. end
  56. function Polygon:calculateNormal()
  57. local retVal = Polycore.Polygon_calculateNormal(self.__ptr)
  58. end
  59. function Polygon:calculateTangent()
  60. local retVal = Polycore.Polygon_calculateTangent(self.__ptr)
  61. end
  62. function Polygon:getFaceNormal()
  63. local retVal = Polycore.Polygon_getFaceNormal(self.__ptr)
  64. if retVal == nil then return nil end
  65. if Polycore.__ptr_lookup[retVal] ~= nil then
  66. return Polycore.__ptr_lookup[retVal]
  67. else
  68. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  69. Polycore.__ptr_lookup[retVal].__ptr = retVal
  70. return Polycore.__ptr_lookup[retVal]
  71. end
  72. end
  73. function Polygon:getFaceTangent()
  74. local retVal = Polycore.Polygon_getFaceTangent(self.__ptr)
  75. if retVal == nil then return nil end
  76. if Polycore.__ptr_lookup[retVal] ~= nil then
  77. return Polycore.__ptr_lookup[retVal]
  78. else
  79. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  80. Polycore.__ptr_lookup[retVal].__ptr = retVal
  81. return Polycore.__ptr_lookup[retVal]
  82. end
  83. end
  84. function Polygon:getBounds2D()
  85. local retVal = Polycore.Polygon_getBounds2D(self.__ptr)
  86. if retVal == nil then return nil end
  87. if Polycore.__ptr_lookup[retVal] ~= nil then
  88. return Polycore.__ptr_lookup[retVal]
  89. else
  90. Polycore.__ptr_lookup[retVal] = Rectangle("__skip_ptr__")
  91. Polycore.__ptr_lookup[retVal].__ptr = retVal
  92. return Polycore.__ptr_lookup[retVal]
  93. end
  94. end
  95. function Polygon:setNormal(normal)
  96. local retVal = Polycore.Polygon_setNormal(self.__ptr, normal.__ptr)
  97. end
  98. function Polygon:flipUVY()
  99. local retVal = Polycore.Polygon_flipUVY(self.__ptr)
  100. end
  101. function Polygon:__delete()
  102. Polycore.__ptr_lookup[self.__ptr] = nil
  103. Polycore.delete_Polygon(self.__ptr)
  104. end