Material.lua 4.0 KB

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