Scene.lua 5.9 KB

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