Scene.lua 6.2 KB

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