Vertex.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 == "tangent" then
  32. retVal = Polycore.Vertex_get_tangent(self.__ptr)
  33. if Polycore.__ptr_lookup[retVal] ~= nil then
  34. return Polycore.__ptr_lookup[retVal]
  35. else
  36. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  37. Polycore.__ptr_lookup[retVal].__ptr = retVal
  38. return Polycore.__ptr_lookup[retVal]
  39. end
  40. elseif name == "vertexColor" then
  41. retVal = Polycore.Vertex_get_vertexColor(self.__ptr)
  42. if Polycore.__ptr_lookup[retVal] ~= nil then
  43. return Polycore.__ptr_lookup[retVal]
  44. else
  45. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  46. Polycore.__ptr_lookup[retVal].__ptr = retVal
  47. return Polycore.__ptr_lookup[retVal]
  48. end
  49. elseif name == "texCoord" then
  50. retVal = Polycore.Vertex_get_texCoord(self.__ptr)
  51. if Polycore.__ptr_lookup[retVal] ~= nil then
  52. return Polycore.__ptr_lookup[retVal]
  53. else
  54. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  55. Polycore.__ptr_lookup[retVal].__ptr = retVal
  56. return Polycore.__ptr_lookup[retVal]
  57. end
  58. elseif name == "useVertexColor" then
  59. return Polycore.Vertex_get_useVertexColor(self.__ptr)
  60. end
  61. end
  62. function Vertex:__set_callback(name,value)
  63. if name == "useVertexColor" then
  64. Polycore.Vertex_set_useVertexColor(self.__ptr, value)
  65. return true
  66. end
  67. return false
  68. end
  69. function Vertex:Vertex(...)
  70. if type(arg[1]) == "table" and count(arg) == 1 then
  71. if ""..arg[1]:class() == "Vector3" then
  72. self.__ptr = arg[1].__ptr
  73. return
  74. end
  75. end
  76. for k,v in pairs(arg) do
  77. if type(v) == "table" then
  78. if v.__ptr ~= nil then
  79. arg[k] = v.__ptr
  80. end
  81. end
  82. end
  83. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  84. self.__ptr = Polycore.Vertex(unpack(arg))
  85. Polycore.__ptr_lookup[self.__ptr] = self
  86. end
  87. end
  88. function Vertex:addBoneAssignment(boneID, boneWeight)
  89. local retVal = Polycore.Vertex_addBoneAssignment(self.__ptr, boneID, boneWeight)
  90. end
  91. function Vertex:getNumBoneAssignments()
  92. local retVal = Polycore.Vertex_getNumBoneAssignments(self.__ptr)
  93. return retVal
  94. end
  95. function Vertex:getBoneAssignment(index)
  96. local retVal = Polycore.Vertex_getBoneAssignment(self.__ptr, index)
  97. if retVal == nil then return nil end
  98. if Polycore.__ptr_lookup[retVal] ~= nil then
  99. return Polycore.__ptr_lookup[retVal]
  100. else
  101. Polycore.__ptr_lookup[retVal] = BoneAssignment("__skip_ptr__")
  102. Polycore.__ptr_lookup[retVal].__ptr = retVal
  103. return Polycore.__ptr_lookup[retVal]
  104. end
  105. end
  106. function Vertex:normalizeWeights()
  107. local retVal = Polycore.Vertex_normalizeWeights(self.__ptr)
  108. end
  109. function Vertex:getTexCoord()
  110. local retVal = Polycore.Vertex_getTexCoord(self.__ptr)
  111. if retVal == nil then return nil end
  112. if Polycore.__ptr_lookup[retVal] ~= nil then
  113. return Polycore.__ptr_lookup[retVal]
  114. else
  115. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  116. Polycore.__ptr_lookup[retVal].__ptr = retVal
  117. return Polycore.__ptr_lookup[retVal]
  118. end
  119. end
  120. function Vertex:setTexCoord(u, v)
  121. local retVal = Polycore.Vertex_setTexCoord(self.__ptr, u, v)
  122. end
  123. function Vertex:setNormal(x, y, z)
  124. local retVal = Polycore.Vertex_setNormal(self.__ptr, x, y, z)
  125. end
  126. function Vertex:__delete()
  127. Polycore.__ptr_lookup[self.__ptr] = nil
  128. Polycore.delete_Vertex(self.__ptr)
  129. end