Scene.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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:getActiveCamera()
  89. local retVal = Polycore.Scene_getActiveCamera(self.__ptr)
  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] = Camera("__skip_ptr__")
  95. Polycore.__ptr_lookup[retVal].__ptr = retVal
  96. return Polycore.__ptr_lookup[retVal]
  97. end
  98. end
  99. function Scene:setActiveCamera(camera)
  100. local retVal = Polycore.Scene_setActiveCamera(self.__ptr, camera.__ptr)
  101. end
  102. function Scene:enableLighting(enable)
  103. local retVal = Polycore.Scene_enableLighting(self.__ptr, enable)
  104. end
  105. function Scene:enableFog(enable)
  106. local retVal = Polycore.Scene_enableFog(self.__ptr, enable)
  107. end
  108. function Scene:setFogProperties(fogMode, color, density, startDepth, _endDepth)
  109. local retVal = Polycore.Scene_setFogProperties(self.__ptr, fogMode, color.__ptr, density, startDepth, _endDepth)
  110. end
  111. function Scene:Update()
  112. local retVal = Polycore.Scene_Update(self.__ptr)
  113. end
  114. function Scene:setVirtual(val)
  115. local retVal = Polycore.Scene_setVirtual(self.__ptr, val)
  116. end
  117. function Scene:isVirtual()
  118. local retVal = Polycore.Scene_isVirtual(self.__ptr)
  119. return retVal
  120. end
  121. function Scene:isEnabled()
  122. local retVal = Polycore.Scene_isEnabled(self.__ptr)
  123. return retVal
  124. end
  125. function Scene:setEnabled(enabled)
  126. local retVal = Polycore.Scene_setEnabled(self.__ptr, enabled)
  127. end
  128. function Scene:getNumEntities()
  129. local retVal = Polycore.Scene_getNumEntities(self.__ptr)
  130. return retVal
  131. end
  132. function Scene:getEntity(index)
  133. local retVal = Polycore.Scene_getEntity(self.__ptr, index)
  134. if retVal == nil then return nil end
  135. if Polycore.__ptr_lookup[retVal] ~= nil then
  136. return Polycore.__ptr_lookup[retVal]
  137. else
  138. Polycore.__ptr_lookup[retVal] = SceneEntity("__skip_ptr__")
  139. Polycore.__ptr_lookup[retVal].__ptr = retVal
  140. return Polycore.__ptr_lookup[retVal]
  141. end
  142. end
  143. function Scene:getEntityAtScreenPosition(x, y)
  144. local retVal = Polycore.Scene_getEntityAtScreenPosition(self.__ptr, x, y)
  145. if retVal == nil then return nil end
  146. if Polycore.__ptr_lookup[retVal] ~= nil then
  147. return Polycore.__ptr_lookup[retVal]
  148. else
  149. Polycore.__ptr_lookup[retVal] = SceneEntity("__skip_ptr__")
  150. Polycore.__ptr_lookup[retVal].__ptr = retVal
  151. return Polycore.__ptr_lookup[retVal]
  152. end
  153. end
  154. function Scene:Render(targetCamera)
  155. local retVal = Polycore.Scene_Render(self.__ptr, targetCamera.__ptr)
  156. end
  157. function Scene:RenderDepthOnly(targetCamera)
  158. local retVal = Polycore.Scene_RenderDepthOnly(self.__ptr, targetCamera.__ptr)
  159. end
  160. function Scene:readString(inFile)
  161. local retVal = Polycore.Scene_readString(inFile.__ptr)
  162. return retVal
  163. end
  164. function Scene:loadScene(fileName)
  165. local retVal = Polycore.Scene_loadScene(self.__ptr, fileName)
  166. end
  167. function Scene:generateLightmaps(lightMapRes, lightMapQuality, numRadPasses)
  168. local retVal = Polycore.Scene_generateLightmaps(self.__ptr, lightMapRes, lightMapQuality, numRadPasses)
  169. end
  170. function Scene:addLight(light)
  171. local retVal = Polycore.Scene_addLight(self.__ptr, light.__ptr)
  172. end
  173. function Scene:removeLight(light)
  174. local retVal = Polycore.Scene_removeLight(self.__ptr, light.__ptr)
  175. end
  176. function Scene:getNearestLight(pos)
  177. local retVal = Polycore.Scene_getNearestLight(self.__ptr, pos.__ptr)
  178. if retVal == nil then return nil end
  179. if Polycore.__ptr_lookup[retVal] ~= nil then
  180. return Polycore.__ptr_lookup[retVal]
  181. else
  182. Polycore.__ptr_lookup[retVal] = SceneLight("__skip_ptr__")
  183. Polycore.__ptr_lookup[retVal].__ptr = retVal
  184. return Polycore.__ptr_lookup[retVal]
  185. end
  186. end
  187. function Scene:writeEntityMatrix(entity, outFile)
  188. local retVal = Polycore.Scene_writeEntityMatrix(self.__ptr, entity.__ptr, outFile.__ptr)
  189. end
  190. function Scene:writeString(str, outFile)
  191. local retVal = Polycore.Scene_writeString(self.__ptr, str, outFile.__ptr)
  192. end
  193. function Scene:saveScene(fileName)
  194. local retVal = Polycore.Scene_saveScene(self.__ptr, fileName)
  195. end
  196. function Scene:getNumStaticGeometry()
  197. local retVal = Polycore.Scene_getNumStaticGeometry(self.__ptr)
  198. return retVal
  199. end
  200. function Scene:getStaticGeometry(index)
  201. local retVal = Polycore.Scene_getStaticGeometry(self.__ptr, index)
  202. if retVal == nil then return nil end
  203. if Polycore.__ptr_lookup[retVal] ~= nil then
  204. return Polycore.__ptr_lookup[retVal]
  205. else
  206. Polycore.__ptr_lookup[retVal] = SceneMesh("__skip_ptr__")
  207. Polycore.__ptr_lookup[retVal].__ptr = retVal
  208. return Polycore.__ptr_lookup[retVal]
  209. end
  210. end
  211. function Scene:loadCollisionChild(entity, autoCollide, type)
  212. local retVal = Polycore.Scene_loadCollisionChild(self.__ptr, entity.__ptr, autoCollide, type)
  213. end
  214. function Scene:getNumLights()
  215. local retVal = Polycore.Scene_getNumLights(self.__ptr)
  216. return retVal
  217. end
  218. function Scene:getLight(index)
  219. local retVal = Polycore.Scene_getLight(self.__ptr, index)
  220. if retVal == nil then return nil end
  221. if Polycore.__ptr_lookup[retVal] ~= nil then
  222. return Polycore.__ptr_lookup[retVal]
  223. else
  224. Polycore.__ptr_lookup[retVal] = SceneLight("__skip_ptr__")
  225. Polycore.__ptr_lookup[retVal].__ptr = retVal
  226. return Polycore.__ptr_lookup[retVal]
  227. end
  228. end
  229. function Scene:getCustomEntityByType(type)
  230. local retVal = Polycore.Scene_getCustomEntityByType(self.__ptr, type)
  231. if retVal == nil then return nil end
  232. if Polycore.__ptr_lookup[retVal] ~= nil then
  233. return Polycore.__ptr_lookup[retVal]
  234. else
  235. Polycore.__ptr_lookup[retVal] = SceneEntity("__skip_ptr__")
  236. Polycore.__ptr_lookup[retVal].__ptr = retVal
  237. return Polycore.__ptr_lookup[retVal]
  238. end
  239. end
  240. function Scene:__delete()
  241. Polycore.__ptr_lookup[self.__ptr] = nil
  242. Polycore.delete_Scene(self.__ptr)
  243. end