Material.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. require "Polycode/Resource"
  2. class "Material" (Resource)
  3. function Material:__index__(name)
  4. if name == "specularValue" then
  5. return Polycore.Material_get_specularValue(self.__ptr)
  6. elseif name == "specularColor" then
  7. retVal = Polycore.Material_get_specularColor(self.__ptr)
  8. if Polycore.__ptr_lookup[retVal] ~= nil then
  9. return Polycore.__ptr_lookup[retVal]
  10. else
  11. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  12. Polycore.__ptr_lookup[retVal].__ptr = retVal
  13. return Polycore.__ptr_lookup[retVal]
  14. end
  15. elseif name == "diffuseColor" then
  16. retVal = Polycore.Material_get_diffuseColor(self.__ptr)
  17. if Polycore.__ptr_lookup[retVal] ~= nil then
  18. return Polycore.__ptr_lookup[retVal]
  19. else
  20. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  21. Polycore.__ptr_lookup[retVal].__ptr = retVal
  22. return Polycore.__ptr_lookup[retVal]
  23. end
  24. end
  25. end
  26. function Material:__set_callback(name,value)
  27. if name == "specularValue" then
  28. Polycore.Material_set_specularValue(self.__ptr, value)
  29. return true
  30. end
  31. return false
  32. end
  33. function Material:Material(...)
  34. if type(arg[1]) == "table" and count(arg) == 1 then
  35. if ""..arg[1]:class() == "Resource" then
  36. self.__ptr = arg[1].__ptr
  37. return
  38. end
  39. end
  40. for k,v in pairs(arg) do
  41. if type(v) == "table" then
  42. if v.__ptr ~= nil then
  43. arg[k] = v.__ptr
  44. end
  45. end
  46. end
  47. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  48. self.__ptr = Polycore.Material(unpack(arg))
  49. Polycore.__ptr_lookup[self.__ptr] = self
  50. end
  51. end
  52. function Material:addShader(shader, shaderBinding)
  53. local retVal = Polycore.Material_addShader(self.__ptr, shader.__ptr, shaderBinding.__ptr)
  54. end
  55. function Material:getNumShaders()
  56. local retVal = Polycore.Material_getNumShaders(self.__ptr)
  57. return retVal
  58. end
  59. function Material:addShaderRenderTarget(newTarget)
  60. local retVal = Polycore.Material_addShaderRenderTarget(self.__ptr, newTarget.__ptr)
  61. end
  62. function Material:getNumShaderRenderTargets()
  63. local retVal = Polycore.Material_getNumShaderRenderTargets(self.__ptr)
  64. return retVal
  65. end
  66. function Material:getShaderRenderTarget(index)
  67. local retVal = Polycore.Material_getShaderRenderTarget(self.__ptr, index)
  68. if retVal == nil then return nil end
  69. if Polycore.__ptr_lookup[retVal] ~= nil then
  70. return Polycore.__ptr_lookup[retVal]
  71. else
  72. Polycore.__ptr_lookup[retVal] = ShaderRenderTarget("__skip_ptr__")
  73. Polycore.__ptr_lookup[retVal].__ptr = retVal
  74. return Polycore.__ptr_lookup[retVal]
  75. end
  76. end
  77. function Material:getName()
  78. local retVal = Polycore.Material_getName(self.__ptr)
  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] = String("__skip_ptr__")
  84. Polycore.__ptr_lookup[retVal].__ptr = retVal
  85. return Polycore.__ptr_lookup[retVal]
  86. end
  87. end
  88. function Material:getShader(index)
  89. local retVal = Polycore.Material_getShader(self.__ptr, index)
  90. if retVal == nil then return nil end
  91. if Polycore.__ptr_lookup[retVal] ~= nil then
  92. return Polycore.__ptr_lookup[retVal]
  93. else
  94. Polycore.__ptr_lookup[retVal] = Shader("__skip_ptr__")
  95. Polycore.__ptr_lookup[retVal].__ptr = retVal
  96. return Polycore.__ptr_lookup[retVal]
  97. end
  98. end
  99. function Material:getShaderBinding(index)
  100. local retVal = Polycore.Material_getShaderBinding(self.__ptr, index)
  101. if retVal == nil then return nil end
  102. if Polycore.__ptr_lookup[retVal] ~= nil then
  103. return Polycore.__ptr_lookup[retVal]
  104. else
  105. Polycore.__ptr_lookup[retVal] = ShaderBinding("__skip_ptr__")
  106. Polycore.__ptr_lookup[retVal].__ptr = retVal
  107. return Polycore.__ptr_lookup[retVal]
  108. end
  109. end
  110. function Material:loadMaterial(fileName)
  111. local retVal = Polycore.Material_loadMaterial(self.__ptr, fileName.__ptr)
  112. end
  113. function Material:__delete()
  114. Polycore.__ptr_lookup[self.__ptr] = nil
  115. Polycore.delete_Material(self.__ptr)
  116. end