Scene.lua 5.9 KB

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