Vertex.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. require "Polycode/Vector3"
  2. class "Vertex" (Vector3)
  3. function Vertex:__index__(name)
  4. if name == "restNormal" then
  5. retVal = Polycore.Vertex_get_restNormal(self.__ptr)
  6. if Polycore.__ptr_lookup[retVal] ~= nil then
  7. return Polycore.__ptr_lookup[retVal]
  8. else
  9. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  10. Polycore.__ptr_lookup[retVal].__ptr = retVal
  11. return Polycore.__ptr_lookup[retVal]
  12. end
  13. elseif name == "restPosition" then
  14. retVal = Polycore.Vertex_get_restPosition(self.__ptr)
  15. if Polycore.__ptr_lookup[retVal] ~= nil then
  16. return Polycore.__ptr_lookup[retVal]
  17. else
  18. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  19. Polycore.__ptr_lookup[retVal].__ptr = retVal
  20. return Polycore.__ptr_lookup[retVal]
  21. end
  22. elseif name == "normal" then
  23. retVal = Polycore.Vertex_get_normal(self.__ptr)
  24. if Polycore.__ptr_lookup[retVal] ~= nil then
  25. return Polycore.__ptr_lookup[retVal]
  26. else
  27. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  28. Polycore.__ptr_lookup[retVal].__ptr = retVal
  29. return Polycore.__ptr_lookup[retVal]
  30. end
  31. elseif name == "vertexColor" then
  32. retVal = Polycore.Vertex_get_vertexColor(self.__ptr)
  33. if Polycore.__ptr_lookup[retVal] ~= nil then
  34. return Polycore.__ptr_lookup[retVal]
  35. else
  36. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  37. Polycore.__ptr_lookup[retVal].__ptr = retVal
  38. return Polycore.__ptr_lookup[retVal]
  39. end
  40. elseif name == "useVertexColor" then
  41. return Polycore.Vertex_get_useVertexColor(self.__ptr)
  42. end
  43. end
  44. function Vertex:__set_callback(name,value)
  45. if name == "useVertexColor" then
  46. Polycore.Vertex_set_useVertexColor(self.__ptr, value)
  47. return true
  48. end
  49. return false
  50. end
  51. function Vertex:Vertex(...)
  52. if type(arg[1]) == "table" and count(arg) == 1 then
  53. if ""..arg[1]:class() == "Vector3" then
  54. self.__ptr = arg[1].__ptr
  55. return
  56. end
  57. end
  58. for k,v in pairs(arg) do
  59. if type(v) == "table" then
  60. if v.__ptr ~= nil then
  61. arg[k] = v.__ptr
  62. end
  63. end
  64. end
  65. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  66. self.__ptr = Polycore.Vertex(unpack(arg))
  67. Polycore.__ptr_lookup[self.__ptr] = self
  68. end
  69. end
  70. function Vertex:addBoneAssignment(boneID, boneWeight)
  71. local retVal = Polycore.Vertex_addBoneAssignment(self.__ptr, boneID, boneWeight)
  72. end
  73. function Vertex:getNumBoneAssignments()
  74. local retVal = Polycore.Vertex_getNumBoneAssignments(self.__ptr)
  75. return retVal
  76. end
  77. function Vertex:getBoneAssignment(index)
  78. local retVal = Polycore.Vertex_getBoneAssignment(self.__ptr, index)
  79. if retVal == nil then return nil end
  80. if Polycore.__ptr_lookup[retVal] ~= nil then
  81. return Polycore.__ptr_lookup[retVal]
  82. else
  83. Polycore.__ptr_lookup[retVal] = BoneAssignment("__skip_ptr__")
  84. Polycore.__ptr_lookup[retVal].__ptr = retVal
  85. return Polycore.__ptr_lookup[retVal]
  86. end
  87. end
  88. function Vertex:normalizeWeights()
  89. local retVal = Polycore.Vertex_normalizeWeights(self.__ptr)
  90. end
  91. function Vertex:getTexCoord()
  92. local retVal = Polycore.Vertex_getTexCoord(self.__ptr)
  93. if retVal == nil then return nil end
  94. if Polycore.__ptr_lookup[retVal] ~= nil then
  95. return Polycore.__ptr_lookup[retVal]
  96. else
  97. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  98. Polycore.__ptr_lookup[retVal].__ptr = retVal
  99. return Polycore.__ptr_lookup[retVal]
  100. end
  101. end
  102. function Vertex:setTexCoord(u, v)
  103. local retVal = Polycore.Vertex_setTexCoord(self.__ptr, u, v)
  104. end
  105. function Vertex:setNormal(x, y, z)
  106. local retVal = Polycore.Vertex_setNormal(self.__ptr, x, y, z)
  107. end
  108. function Vertex:__delete()
  109. Polycore.__ptr_lookup[self.__ptr] = nil
  110. Polycore.delete_Vertex(self.__ptr)
  111. end