Scene.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. require "Polycode/EventDispatcher"
  2. class "Scene" (EventDispatcher)
  3. ENTITY_MESH = 0
  4. ENTITY_LIGHT = 1
  5. ENTITY_CAMERA = 2
  6. ENTITY_ENTITY = 3
  7. ENTITY_COLLMESH = 4
  8. function Scene:__index__(name)
  9. if name == "clearColor" then
  10. retVal = Polycore.Scene_get_clearColor(self.__ptr)
  11. if Polycore.__ptr_lookup[retVal] ~= nil then
  12. return Polycore.__ptr_lookup[retVal]
  13. else
  14. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  15. Polycore.__ptr_lookup[retVal].__ptr = retVal
  16. return Polycore.__ptr_lookup[retVal]
  17. end
  18. elseif name == "useClearColor" then
  19. return Polycore.Scene_get_useClearColor(self.__ptr)
  20. elseif name == "ambientColor" then
  21. retVal = Polycore.Scene_get_ambientColor(self.__ptr)
  22. if Polycore.__ptr_lookup[retVal] ~= nil then
  23. return Polycore.__ptr_lookup[retVal]
  24. else
  25. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  26. Polycore.__ptr_lookup[retVal].__ptr = retVal
  27. return Polycore.__ptr_lookup[retVal]
  28. end
  29. elseif name == "fogColor" then
  30. retVal = Polycore.Scene_get_fogColor(self.__ptr)
  31. if Polycore.__ptr_lookup[retVal] ~= nil then
  32. return Polycore.__ptr_lookup[retVal]
  33. else
  34. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  35. Polycore.__ptr_lookup[retVal].__ptr = retVal
  36. return Polycore.__ptr_lookup[retVal]
  37. end
  38. elseif name == "enabled" then
  39. return Polycore.Scene_get_enabled(self.__ptr)
  40. end
  41. end
  42. function Scene:__set_callback(name,value)
  43. if name == "useClearColor" then
  44. Polycore.Scene_set_useClearColor(self.__ptr, value)
  45. return true
  46. elseif name == "enabled" then
  47. Polycore.Scene_set_enabled(self.__ptr, value)
  48. return true
  49. end
  50. return false
  51. end
  52. function Scene:Scene(...)
  53. if type(arg[1]) == "table" and count(arg) == 1 then
  54. if ""..arg[1]:class() == "EventDispatcher" then
  55. self.__ptr = arg[1].__ptr
  56. return
  57. end
  58. end
  59. for k,v in pairs(arg) do
  60. if type(v) == "table" then
  61. if v.__ptr ~= nil then
  62. arg[k] = v.__ptr
  63. end
  64. end
  65. end
  66. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  67. self.__ptr = Polycore.Scene(unpack(arg))
  68. Polycore.__ptr_lookup[self.__ptr] = self
  69. end
  70. end
  71. function Scene:addEntity(entity)
  72. local retVal = Polycore.Scene_addEntity(self.__ptr, entity.__ptr)
  73. end
  74. function Scene:removeEntity(entity)
  75. local retVal = Polycore.Scene_removeEntity(self.__ptr, entity.__ptr)
  76. end
  77. function Scene:getDefaultCamera()
  78. local retVal = Polycore.Scene_getDefaultCamera(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] = Camera("__skip_ptr__")
  84. Polycore.__ptr_lookup[retVal].__ptr = retVal
  85. return Polycore.__ptr_lookup[retVal]
  86. end
  87. end
  88. function Scene:enableLighting(enable)
  89. local retVal = Polycore.Scene_enableLighting(self.__ptr, enable)
  90. end
  91. function Scene:enableFog(enable)
  92. local retVal = Polycore.Scene_enableFog(self.__ptr, enable)
  93. end
  94. function Scene:setFogProperties(fogMode, color, density, startDepth, _endDepth)
  95. local retVal = Polycore.Scene_setFogProperties(self.__ptr, fogMode, color.__ptr, density, startDepth, _endDepth)
  96. end
  97. function Scene:Update()
  98. local retVal = Polycore.Scene_Update(self.__ptr)
  99. end
  100. function Scene:setVirtual(val)
  101. local retVal = Polycore.Scene_setVirtual(self.__ptr, val)
  102. end
  103. function Scene:isVirtual()
  104. local retVal = Polycore.Scene_isVirtual(self.__ptr)
  105. return retVal
  106. end
  107. function Scene:isEnabled()
  108. local retVal = Polycore.Scene_isEnabled(self.__ptr)
  109. return retVal
  110. end
  111. function Scene:setEnabled(enabled)
  112. local retVal = Polycore.Scene_setEnabled(self.__ptr, enabled)
  113. end
  114. function Scene:getNumEntities()
  115. local retVal = Polycore.Scene_getNumEntities(self.__ptr)
  116. return retVal
  117. end
  118. function Scene:getEntity(index)
  119. local retVal = Polycore.Scene_getEntity(self.__ptr, index)
  120. if retVal == nil then return nil end
  121. if Polycore.__ptr_lookup[retVal] ~= nil then
  122. return Polycore.__ptr_lookup[retVal]
  123. else
  124. Polycore.__ptr_lookup[retVal] = SceneEntity("__skip_ptr__")
  125. Polycore.__ptr_lookup[retVal].__ptr = retVal
  126. return Polycore.__ptr_lookup[retVal]
  127. end
  128. end
  129. function Scene:getEntityAtScreenPosition(x, y)
  130. local retVal = Polycore.Scene_getEntityAtScreenPosition(self.__ptr, x, y)
  131. if retVal == nil then return nil end
  132. if Polycore.__ptr_lookup[retVal] ~= nil then
  133. return Polycore.__ptr_lookup[retVal]
  134. else
  135. Polycore.__ptr_lookup[retVal] = SceneEntity("__skip_ptr__")
  136. Polycore.__ptr_lookup[retVal].__ptr = retVal
  137. return Polycore.__ptr_lookup[retVal]
  138. end
  139. end
  140. function Scene:Render(targetCamera)
  141. local retVal = Polycore.Scene_Render(self.__ptr, targetCamera.__ptr)
  142. end
  143. function Scene:RenderDepthOnly(targetCamera)
  144. local retVal = Polycore.Scene_RenderDepthOnly(self.__ptr, targetCamera.__ptr)
  145. end
  146. function Scene:readString(inFile)
  147. local retVal = Polycore.Scene_readString(inFile.__ptr)
  148. return retVal
  149. end
  150. function Scene:loadScene(fileName)
  151. local retVal = Polycore.Scene_loadScene(self.__ptr, fileName)
  152. end
  153. function Scene:generateLightmaps(lightMapRes, lightMapQuality, numRadPasses)
  154. local retVal = Polycore.Scene_generateLightmaps(self.__ptr, lightMapRes, lightMapQuality, numRadPasses)
  155. end
  156. function Scene:addLight(light)
  157. local retVal = Polycore.Scene_addLight(self.__ptr, light.__ptr)
  158. end
  159. function Scene:removeLight(light)
  160. local retVal = Polycore.Scene_removeLight(self.__ptr, light.__ptr)
  161. end
  162. function Scene:getNearestLight(pos)
  163. local retVal = Polycore.Scene_getNearestLight(self.__ptr, pos.__ptr)
  164. if retVal == nil then return nil end
  165. if Polycore.__ptr_lookup[retVal] ~= nil then
  166. return Polycore.__ptr_lookup[retVal]
  167. else
  168. Polycore.__ptr_lookup[retVal] = SceneLight("__skip_ptr__")
  169. Polycore.__ptr_lookup[retVal].__ptr = retVal
  170. return Polycore.__ptr_lookup[retVal]
  171. end
  172. end
  173. function Scene:writeEntityMatrix(entity, outFile)
  174. local retVal = Polycore.Scene_writeEntityMatrix(self.__ptr, entity.__ptr, outFile.__ptr)
  175. end
  176. function Scene:writeString(str, outFile)
  177. local retVal = Polycore.Scene_writeString(self.__ptr, str, outFile.__ptr)
  178. end
  179. function Scene:saveScene(fileName)
  180. local retVal = Polycore.Scene_saveScene(self.__ptr, fileName)
  181. end
  182. function Scene:getNumStaticGeometry()
  183. local retVal = Polycore.Scene_getNumStaticGeometry(self.__ptr)
  184. return retVal
  185. end
  186. function Scene:getStaticGeometry(index)
  187. local retVal = Polycore.Scene_getStaticGeometry(self.__ptr, index)
  188. if retVal == nil then return nil end
  189. if Polycore.__ptr_lookup[retVal] ~= nil then
  190. return Polycore.__ptr_lookup[retVal]
  191. else
  192. Polycore.__ptr_lookup[retVal] = SceneMesh("__skip_ptr__")
  193. Polycore.__ptr_lookup[retVal].__ptr = retVal
  194. return Polycore.__ptr_lookup[retVal]
  195. end
  196. end
  197. function Scene:loadCollisionChild(entity, autoCollide, type)
  198. local retVal = Polycore.Scene_loadCollisionChild(self.__ptr, entity.__ptr, autoCollide, type)
  199. end
  200. function Scene:getNumLights()
  201. local retVal = Polycore.Scene_getNumLights(self.__ptr)
  202. return retVal
  203. end
  204. function Scene:getLight(index)
  205. local retVal = Polycore.Scene_getLight(self.__ptr, index)
  206. if retVal == nil then return nil end
  207. if Polycore.__ptr_lookup[retVal] ~= nil then
  208. return Polycore.__ptr_lookup[retVal]
  209. else
  210. Polycore.__ptr_lookup[retVal] = SceneLight("__skip_ptr__")
  211. Polycore.__ptr_lookup[retVal].__ptr = retVal
  212. return Polycore.__ptr_lookup[retVal]
  213. end
  214. end
  215. function Scene:getCustomEntityByType(type)
  216. local retVal = Polycore.Scene_getCustomEntityByType(self.__ptr, type)
  217. if retVal == nil then return nil end
  218. if Polycore.__ptr_lookup[retVal] ~= nil then
  219. return Polycore.__ptr_lookup[retVal]
  220. else
  221. Polycore.__ptr_lookup[retVal] = SceneEntity("__skip_ptr__")
  222. Polycore.__ptr_lookup[retVal].__ptr = retVal
  223. return Polycore.__ptr_lookup[retVal]
  224. end
  225. end
  226. function Scene:__delete()
  227. Polycore.__ptr_lookup[self.__ptr] = nil
  228. Polycore.delete_Scene(self.__ptr)
  229. end