ris-framework 0.1.0 → 0.2.0-dev.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (383) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/README.md +27 -4
  3. package/dist/Framework.d.ts +34 -10
  4. package/dist/Framework.d.ts.map +1 -1
  5. package/dist/api/IFramework.d.ts +50 -6
  6. package/dist/api/IFramework.d.ts.map +1 -1
  7. package/dist/api/_export.d.ts +3 -1
  8. package/dist/api/_export.d.ts.map +1 -1
  9. package/dist/api/camera/CameraFactory.d.ts +3 -2
  10. package/dist/api/camera/CameraFactory.d.ts.map +1 -1
  11. package/dist/api/camera/ICamera.d.ts +5 -0
  12. package/dist/api/camera/ICamera.d.ts.map +1 -1
  13. package/dist/api/camera/ICameraFactory.d.ts +5 -6
  14. package/dist/api/camera/ICameraFactory.d.ts.map +1 -1
  15. package/dist/api/camera/OrthographicCamera.d.ts +7 -0
  16. package/dist/api/camera/OrthographicCamera.d.ts.map +1 -1
  17. package/dist/api/camera/PerspectiveCamera.d.ts +30 -6
  18. package/dist/api/camera/PerspectiveCamera.d.ts.map +1 -1
  19. package/dist/api/content/ContentManager.d.ts +15 -2
  20. package/dist/api/content/ContentManager.d.ts.map +1 -1
  21. package/dist/api/content/IContentManager.d.ts +35 -1
  22. package/dist/api/content/IContentManager.d.ts.map +1 -1
  23. package/dist/api/content/ShaderModuleContent.d.ts.map +1 -1
  24. package/dist/api/data/Color.d.ts +5 -0
  25. package/dist/api/data/Color.d.ts.map +1 -1
  26. package/dist/api/geometry/BaseGeometry.d.ts +9 -0
  27. package/dist/api/geometry/BaseGeometry.d.ts.map +1 -1
  28. package/dist/api/geometry/GeometryBuilder.d.ts +3 -1
  29. package/dist/api/geometry/GeometryBuilder.d.ts.map +1 -1
  30. package/dist/api/geometry/IGeometryBuilder.d.ts +24 -0
  31. package/dist/api/geometry/IGeometryBuilder.d.ts.map +1 -1
  32. package/dist/api/geometry/_export-geometry.d.ts +1 -0
  33. package/dist/api/geometry/_export-geometry.d.ts.map +1 -1
  34. package/dist/api/input/InputManager.d.ts +4 -0
  35. package/dist/api/input/InputManager.d.ts.map +1 -1
  36. package/dist/api/lights/AmbientLight.d.ts +35 -0
  37. package/dist/api/lights/AmbientLight.d.ts.map +1 -0
  38. package/dist/api/lights/DirectionalLight.d.ts +40 -0
  39. package/dist/api/lights/DirectionalLight.d.ts.map +1 -0
  40. package/dist/api/lights/LightFactory.d.ts +18 -0
  41. package/dist/api/lights/LightFactory.d.ts.map +1 -0
  42. package/dist/api/lights/LightId.d.ts +6 -0
  43. package/dist/api/lights/LightId.d.ts.map +1 -0
  44. package/dist/api/lights/LightsBuffer.d.ts +77 -0
  45. package/dist/api/lights/LightsBuffer.d.ts.map +1 -0
  46. package/dist/api/lights/PointLight.d.ts +59 -0
  47. package/dist/api/lights/PointLight.d.ts.map +1 -0
  48. package/dist/api/lights/_export.d.ts +6 -0
  49. package/dist/api/lights/_export.d.ts.map +1 -0
  50. package/dist/api/loaders/ObjGeometryMapper.d.ts +19 -0
  51. package/dist/api/loaders/ObjGeometryMapper.d.ts.map +1 -0
  52. package/dist/api/loaders/ObjLoader.d.ts +61 -0
  53. package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
  54. package/dist/api/loaders/_export.d.ts +2 -0
  55. package/dist/api/loaders/_export.d.ts.map +1 -1
  56. package/dist/api/loaders/obj/ObjParser.d.ts +44 -0
  57. package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
  58. package/dist/api/loaders/obj/ObjTypes.d.ts +119 -0
  59. package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -0
  60. package/dist/api/loaders/obj/index.d.ts +3 -0
  61. package/dist/api/loaders/obj/index.d.ts.map +1 -0
  62. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +138 -0
  63. package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -0
  64. package/dist/api/material/ICameraMaterial.d.ts +18 -0
  65. package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
  66. package/dist/api/material/ILightsMaterial.d.ts +26 -0
  67. package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
  68. package/dist/api/material/IMaterial.d.ts +13 -10
  69. package/dist/api/material/IMaterial.d.ts.map +1 -1
  70. package/dist/api/material/IMaterialFactory.d.ts +17 -2
  71. package/dist/api/material/IMaterialFactory.d.ts.map +1 -1
  72. package/dist/api/material/InspectTextureMipsMaterial.d.ts +18 -9
  73. package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
  74. package/dist/api/material/MaterialFactory.d.ts +6 -0
  75. package/dist/api/material/MaterialFactory.d.ts.map +1 -1
  76. package/dist/api/material/SpriteMaterial.d.ts +51 -0
  77. package/dist/api/material/SpriteMaterial.d.ts.map +1 -0
  78. package/dist/api/material/UnlitMaterial.d.ts +32 -13
  79. package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
  80. package/dist/api/material/_export.d.ts +4 -0
  81. package/dist/api/material/_export.d.ts.map +1 -1
  82. package/dist/api/meshes/IMesh.d.ts +31 -6
  83. package/dist/api/meshes/IMesh.d.ts.map +1 -1
  84. package/dist/api/meshes/IMeshFactory.d.ts +30 -4
  85. package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
  86. package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
  87. package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
  88. package/dist/api/meshes/Mesh.d.ts +14 -8
  89. package/dist/api/meshes/Mesh.d.ts.map +1 -1
  90. package/dist/api/meshes/MeshFactory.d.ts +10 -3
  91. package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
  92. package/dist/api/meshes/QuadMesh.d.ts +5 -3
  93. package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
  94. package/dist/api/meshes/RenderableMesh.d.ts +95 -0
  95. package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
  96. package/dist/api/meshes/_export.d.ts +2 -0
  97. package/dist/api/meshes/_export.d.ts.map +1 -1
  98. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
  99. package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
  100. package/dist/api/rendering/IRenderer.d.ts +28 -1
  101. package/dist/api/rendering/IRenderer.d.ts.map +1 -1
  102. package/dist/api/rendering/enums.d.ts +7 -0
  103. package/dist/api/rendering/enums.d.ts.map +1 -1
  104. package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts +56 -0
  105. package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts.map +1 -0
  106. package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts +3 -0
  107. package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts.map +1 -1
  108. package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts +29 -0
  109. package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts.map +1 -1
  110. package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts +1 -0
  111. package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts.map +1 -1
  112. package/dist/api/rendering/renderer-interface.d.ts +1 -31
  113. package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
  114. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
  115. package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
  116. package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
  117. package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
  118. package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
  119. package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
  120. package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
  121. package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
  122. package/dist/api/scene/Scene.d.ts +113 -0
  123. package/dist/api/scene/Scene.d.ts.map +1 -0
  124. package/dist/api/scene/SceneMesh.d.ts +27 -0
  125. package/dist/api/scene/SceneMesh.d.ts.map +1 -0
  126. package/dist/api/shader/IShaderModuleLoader.d.ts +4 -1
  127. package/dist/api/shader/IShaderModuleLoader.d.ts.map +1 -1
  128. package/dist/api/shader/{shader-loader.d.ts → ShaderLoader.d.ts} +1 -1
  129. package/dist/api/shader/ShaderLoader.d.ts.map +1 -0
  130. package/dist/api/sprites/SpriteBatchDrawable.d.ts +1 -1
  131. package/dist/api/sprites/SpriteBatchDrawable.d.ts.map +1 -1
  132. package/dist/api/sprites/SpriteBatchMesh.d.ts +14 -1
  133. package/dist/api/sprites/SpriteBatchMesh.d.ts.map +1 -1
  134. package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
  135. package/dist/api/utilities/GeometryUtilities.d.ts.map +1 -1
  136. package/dist/api/window/WindowManager.d.ts +4 -0
  137. package/dist/api/window/WindowManager.d.ts.map +1 -1
  138. package/dist/core/rendering/ARenderer.d.ts +5 -5
  139. package/dist/core/rendering/ARenderer.d.ts.map +1 -1
  140. package/dist/core/rendering/vertex-buffer-layout.d.ts +1 -0
  141. package/dist/core/rendering/vertex-buffer-layout.d.ts.map +1 -1
  142. package/dist/index.d.ts +0 -1
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.js +9238 -4595
  145. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
  146. package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
  147. package/dist/webgl/WebGlGraphicsDevice.d.ts.map +1 -1
  148. package/dist/webgl/WebGlRenderer.d.ts +1 -3
  149. package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
  150. package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts +17 -0
  151. package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts.map +1 -0
  152. package/dist/webgl/lights/WebGlLightsBuffer.d.ts +59 -0
  153. package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -0
  154. package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts +3 -1
  155. package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts.map +1 -1
  156. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +5 -0
  157. package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
  158. package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts +3 -1
  159. package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts.map +1 -1
  160. package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts +3 -1
  161. package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts.map +1 -1
  162. package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts +88 -0
  163. package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts.map +1 -0
  164. package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts +3 -1
  165. package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts.map +1 -1
  166. package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts +3 -1
  167. package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts.map +1 -1
  168. package/dist/webgl/shader/WebGlShaderModule.d.ts +4 -1
  169. package/dist/webgl/shader/WebGlShaderModule.d.ts.map +1 -1
  170. package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts +16 -5
  171. package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts.map +1 -1
  172. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
  173. package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
  174. package/dist/webgl/texture/WebGlTexture2D.d.ts +8 -1
  175. package/dist/webgl/texture/WebGlTexture2D.d.ts.map +1 -1
  176. package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
  177. package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
  178. package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
  179. package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
  180. package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
  181. package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
  182. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
  183. package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
  184. package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
  185. package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
  186. package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
  187. package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts +0 -1
  188. package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts.map +1 -1
  189. package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
  190. package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
  191. package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
  192. package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
  193. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
  194. package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
  195. package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
  196. package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
  197. package/dist/webgpu/WebGpuTypes.d.ts +355 -0
  198. package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
  199. package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
  200. package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
  201. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
  202. package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
  203. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
  204. package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
  205. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
  206. package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
  207. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
  208. package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
  209. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
  210. package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
  211. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
  212. package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
  213. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
  214. package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
  215. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
  216. package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
  217. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
  218. package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
  219. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
  220. package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
  221. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
  222. package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
  223. package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
  224. package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
  225. package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
  226. package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
  227. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
  228. package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
  229. package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
  230. package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
  231. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
  232. package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
  233. package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
  234. package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
  235. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
  236. package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
  237. package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
  238. package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
  239. package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
  240. package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
  241. package/package.json +4 -4
  242. package/shaders/glsl/forward_blinn_phong_material_fs.glsl +110 -0
  243. package/shaders/glsl/forward_blinn_phong_material_vs.glsl +32 -0
  244. package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
  245. package/shaders/glsl/sprite_fs.glsl +1 -1
  246. package/shaders/glsl/unlit_material_fs.glsl +1 -1
  247. package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
  248. package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
  249. package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
  250. package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
  251. package/shaders/wgsl/sprite.wgsl +40 -0
  252. package/shaders/wgsl/unlit_material.wgsl +49 -0
  253. package/src/Framework.ts +156 -48
  254. package/src/api/IFramework.ts +63 -6
  255. package/src/api/_export.ts +3 -1
  256. package/src/api/camera/CameraFactory.ts +6 -6
  257. package/src/api/camera/ICamera.ts +6 -0
  258. package/src/api/camera/ICameraFactory.ts +5 -10
  259. package/src/api/camera/OrthographicCamera.ts +23 -1
  260. package/src/api/camera/PerspectiveCamera.ts +60 -15
  261. package/src/api/content/ContentManager.ts +78 -16
  262. package/src/api/content/IContentManager.ts +37 -1
  263. package/src/api/content/ShaderModuleContent.ts +9 -0
  264. package/src/api/data/Color.ts +7 -1
  265. package/src/api/geometry/BaseGeometry.ts +23 -0
  266. package/src/api/geometry/GeometryBuilder.ts +14 -2
  267. package/src/api/geometry/IGeometryBuilder.ts +31 -1
  268. package/src/api/geometry/_export-geometry.ts +2 -1
  269. package/src/api/input/InputManager.ts +14 -5
  270. package/src/api/lights/AmbientLight.ts +53 -0
  271. package/src/api/lights/DirectionalLight.ts +60 -0
  272. package/src/api/lights/LightFactory.ts +21 -0
  273. package/src/api/lights/LightId.ts +9 -0
  274. package/src/api/lights/LightsBuffer.ts +94 -0
  275. package/src/api/lights/PointLight.ts +91 -0
  276. package/src/api/lights/_export.ts +5 -0
  277. package/src/api/loaders/ObjGeometryMapper.ts +28 -0
  278. package/src/api/loaders/ObjLoader.ts +126 -0
  279. package/src/api/loaders/_export.ts +3 -1
  280. package/src/api/loaders/obj/ObjParser.ts +301 -0
  281. package/src/api/loaders/obj/ObjTypes.ts +142 -0
  282. package/src/api/loaders/obj/index.ts +5 -0
  283. package/src/api/material/ForwardBlinnPhongMaterial.ts +328 -0
  284. package/src/api/material/ICameraMaterial.ts +22 -0
  285. package/src/api/material/ILightsMaterial.ts +32 -0
  286. package/src/api/material/IMaterial.ts +13 -10
  287. package/src/api/material/IMaterialFactory.ts +19 -2
  288. package/src/api/material/InspectTextureMipsMaterial.ts +65 -26
  289. package/src/api/material/MaterialFactory.ts +12 -0
  290. package/src/api/material/SpriteMaterial.ts +83 -0
  291. package/src/api/material/UnlitMaterial.ts +105 -32
  292. package/src/api/material/_export.ts +5 -1
  293. package/src/api/meshes/IMesh.ts +40 -6
  294. package/src/api/meshes/IMeshFactory.ts +33 -4
  295. package/src/api/meshes/IRenderableMesh.ts +58 -0
  296. package/src/api/meshes/Mesh.ts +50 -43
  297. package/src/api/meshes/MeshFactory.ts +37 -4
  298. package/src/api/meshes/QuadMesh.ts +6 -4
  299. package/src/api/meshes/RenderableMesh.ts +207 -0
  300. package/src/api/meshes/_export.ts +6 -4
  301. package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
  302. package/src/api/rendering/IRenderer.ts +34 -1
  303. package/src/api/rendering/enums.ts +10 -0
  304. package/src/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.ts +66 -0
  305. package/src/api/rendering/render-pipelines/IRenderPipeline.ts +4 -0
  306. package/src/api/rendering/render-pipelines/IRenderPipelineFactory.ts +39 -0
  307. package/src/api/rendering/render-pipelines/_export-render-pipelines.ts +2 -1
  308. package/src/api/rendering/renderer-interface.ts +1 -36
  309. package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
  310. package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
  311. package/src/api/rendering/texture/TextureFormat.ts +128 -14
  312. package/src/api/rendering/texture/TextureUtilities.ts +225 -10
  313. package/src/api/scene/Scene.ts +297 -0
  314. package/src/api/scene/SceneMesh.ts +61 -0
  315. package/src/api/shader/IShaderModuleLoader.ts +2 -1
  316. package/src/api/sprites/SpriteBatchDrawable.ts +12 -16
  317. package/src/api/sprites/SpriteBatchMesh.ts +22 -3
  318. package/src/api/utilities/AlignUtilities.ts +2 -1
  319. package/src/api/utilities/GeometryUtilities.ts +2 -0
  320. package/src/api/window/WindowManager.ts +23 -3
  321. package/src/core/rendering/ARenderer.ts +24 -15
  322. package/src/core/rendering/vertex-buffer-layout.ts +32 -1
  323. package/src/index.ts +0 -1
  324. package/src/main.ts +2 -4
  325. package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
  326. package/src/webgl/WebGlGpuInfo.ts +1 -1
  327. package/src/webgl/WebGlGraphicsDevice.ts +0 -1
  328. package/src/webgl/WebGlRenderer.ts +2 -5
  329. package/src/webgl/lights/WebGlAmbientLightFactory.ts +35 -0
  330. package/src/webgl/lights/WebGlLightsBuffer.ts +225 -0
  331. package/src/webgl/render-pipelines/AWebGlRenderPipeline.ts +7 -1
  332. package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +21 -1
  333. package/src/webgl/render-pipelines/WebGlRenderPipelineFactory.ts +24 -2
  334. package/src/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.ts +16 -6
  335. package/src/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.ts +300 -0
  336. package/src/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.ts +16 -6
  337. package/src/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.ts +11 -7
  338. package/src/webgl/shader/WebGlShaderModule.ts +11 -4
  339. package/src/webgl/shader/WebGlShaderModuleLoader.ts +29 -10
  340. package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
  341. package/src/webgl/texture/WebGlTexture2D.ts +19 -5
  342. package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
  343. package/src/webgl/utilities/WebGlConstants.ts +136 -0
  344. package/src/webgl/utilities/WebGlConverter.ts +91 -22
  345. package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
  346. package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
  347. package/src/webgl/utilities/WebGlUtilities.ts +4 -0
  348. package/src/webgl/utilities/webgl-filter-anisotropic-utilities.ts +9 -6
  349. package/src/webgpu/WebGpuGpuInfo.ts +61 -0
  350. package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
  351. package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
  352. package/src/webgpu/WebGpuRenderer.ts +49 -0
  353. package/src/webgpu/WebGpuTypes.ts +288 -0
  354. package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
  355. package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
  356. package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
  357. package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
  358. package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
  359. package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
  360. package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
  361. package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
  362. package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
  363. package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
  364. package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
  365. package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
  366. package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
  367. package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
  368. package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
  369. package/src/webgpu/shader/WgslShaderContent.ts +20 -0
  370. package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
  371. package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
  372. package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
  373. package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
  374. package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
  375. package/src/wgsl-raw.d.ts +4 -0
  376. package/dist/api/FrameworkConfiguration.d.ts +0 -23
  377. package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
  378. package/dist/api/IFrameworkConfiguration.d.ts +0 -25
  379. package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
  380. package/dist/api/shader/shader-loader.d.ts.map +0 -1
  381. package/src/api/FrameworkConfiguration.ts +0 -29
  382. package/src/api/IFrameworkConfiguration.ts +0 -30
  383. /package/src/api/shader/{shader-loader.ts → ShaderLoader.ts} +0 -0
@@ -5,6 +5,34 @@ import {MathHelper} from "../utilities/MathHelper.ts";
5
5
  import {BufferUsage} from "../rendering/buffers/BufferUsage.ts";
6
6
  import type { IUniformBuffer } from "../rendering/buffers/IUniformBuffer.ts";
7
7
  import {GameTime} from "../time/GameTime.ts";
8
+ import type {Scene} from "../scene/Scene.ts";
9
+
10
+ /**
11
+ * The descriptor for a perspective camera. Every field is optional.
12
+ */
13
+ export interface PerspectiveCameraDescriptor {
14
+
15
+ /** The vertical field of view in degrees. By default, 60. */
16
+ fov?: number;
17
+
18
+ /** The aspect ratio (width / height). By default, 1. */
19
+ aspectRatio?: number;
20
+
21
+ /** The near plane. By default, 0.01. */
22
+ near?: number;
23
+
24
+ /** The far plane. By default, 100. */
25
+ far?: number;
26
+
27
+ /** The eye position. Copied. By default, (0, 0, 3). */
28
+ eye?: vec3;
29
+
30
+ /** The point the camera looks at. Copied. By default, the origin. */
31
+ target?: vec3;
32
+
33
+ /** The up vector. Copied. By default, (0, 1, 0). */
34
+ up?: vec3;
35
+ }
8
36
 
9
37
  /**
10
38
  * The perspective camera.
@@ -26,24 +54,33 @@ export class PerspectiveCamera implements ICamera {
26
54
  private _projectionBuffer: IUniformBuffer = null!;
27
55
 
28
56
  /**
29
- * The constructor.
57
+ * The constructor. Call `initialize()` before use (the camera factory does).
30
58
  * @param framework The framework.
31
- * @param fov The field of view in radians.
32
- * @param aspectRatio The aspect ratio.
33
- * @param nearPlane The near plane.
34
- * @param farPlane The far plane.
59
+ * @param descriptor The optional descriptor; omitted fields use the defaults documented on {@link PerspectiveCameraDescriptor}.
60
+ * `fov` is in degrees; {@link fieldOfView} holds it in radians. Vectors are copied.
61
+ * @param scene The optional scene; the camera assigns itself as `scene.camera`.
35
62
  */
36
63
  public constructor(
37
64
  framework: IFramework,
38
- fov: number,
39
- aspectRatio: number,
40
- nearPlane: number,
41
- farPlane: number) {
65
+ descriptor?: PerspectiveCameraDescriptor,
66
+ scene?: Scene) {
42
67
  this._framework = framework;
43
- this.fieldOfView = fov;
44
- this.aspectRatio = aspectRatio;
45
- this.nearPlane = nearPlane;
46
- this.farPlane = farPlane;
68
+ this.fieldOfView = MathHelper.toRadians(descriptor?.fov ?? 60);
69
+ this.aspectRatio = descriptor?.aspectRatio ?? 1;
70
+ this.nearPlane = descriptor?.near ?? 0.01;
71
+ this.farPlane = descriptor?.far ?? 100;
72
+ if (descriptor?.eye) {
73
+ vec3.copy(this.eye, descriptor.eye);
74
+ }
75
+ if (descriptor?.target) {
76
+ vec3.copy(this.target, descriptor.target);
77
+ }
78
+ if (descriptor?.up) {
79
+ vec3.copy(this.up, descriptor.up);
80
+ }
81
+ if (scene) {
82
+ scene.add(this);
83
+ }
47
84
 
48
85
  this._updateMatrices();
49
86
  }
@@ -159,12 +196,20 @@ export class PerspectiveCamera implements ICamera {
159
196
  */
160
197
  public initialize(): void {
161
198
  const bufferUsage = BufferUsage.UNIFORM | BufferUsage.COPY_DST;
162
- this._positionBuffer = this._framework.bufferFactory.createUniformBuffer(this.eye, bufferUsage);
199
+ this._positionBuffer = this._framework.bufferFactory.createUniformBuffer(this._worldEye(), bufferUsage);
163
200
  this._projectionViewBuffer = this._framework.bufferFactory.createUniformBuffer(this.projectionViewMatrix, bufferUsage);
164
201
  this._projectionBuffer = this._framework.bufferFactory.createUniformBuffer(this.projectionMatrix, bufferUsage);
165
202
  this._viewBuffer = this._framework.bufferFactory.createUniformBuffer(this.viewMatrix, bufferUsage);
166
203
  }
167
204
 
205
+ /**
206
+ * The eye in world space, as used by the view matrix: z is flipped for the right-handed look-at.
207
+ * This is what {@link positionBuffer} holds, std140 `vec3` (padded to 16 bytes).
208
+ */
209
+ private _worldEye(): number[] {
210
+ return [this.eye[0], this.eye[1], -this.eye[2], 0];
211
+ }
212
+
168
213
  /**
169
214
  * Updates the camera matrices.
170
215
  */
@@ -190,7 +235,7 @@ export class PerspectiveCamera implements ICamera {
190
235
 
191
236
  /** @inheritDoc */
192
237
  public updateBuffers(): void {
193
- this._positionBuffer.update(this.eye);
238
+ this._positionBuffer.update(this._worldEye());
194
239
  this._projectionBuffer.update(this.projectionMatrix);
195
240
  this._viewBuffer.update(this.viewMatrix);
196
241
  this._projectionViewBuffer.update(this.projectionViewMatrix);
@@ -3,11 +3,24 @@ import {
3
3
  type IContentManager,
4
4
  type IShaderModuleLoader,
5
5
  type ITexture2D,
6
- type IFramework, TextureDescriptor, TextureFormat, ContentConfig, TextureUsage
6
+ type IFramework,
7
+ TextureDescriptor,
8
+ TextureFormat,
9
+ ContentConfig,
10
+ TextureUsage,
11
+ type IMesh,
12
+ type IRenderableMesh,
13
+ type GeometryFormat,
14
+ Color,
15
+ type ICamera,
16
+ type IDisposable,
7
17
  } from "../index.ts";
18
+ import {ObjGeometryMapper} from "../loaders/ObjGeometryMapper.ts";
19
+ import {ObjLoader} from "../loaders/ObjLoader.ts";
8
20
  import {Ktx2Factory} from "ris-ktx2";
9
21
  import type {IKtx2Texture} from "ris-ktx2";
10
22
 
23
+ const KTX2_EXTENSION = ".ktx2";
11
24
 
12
25
  /**
13
26
  * The content manager.
@@ -16,7 +29,7 @@ import type {IKtx2Texture} from "ris-ktx2";
16
29
  export class ContentManager implements IContentManager {
17
30
 
18
31
  private readonly _ktx2Factory = new Ktx2Factory();
19
- private readonly _ktx2TextureCache: {[key: string]: IKtx2Texture} = {};
32
+ private readonly _ktx2TextureCache: { [key: string]: IKtx2Texture } = {};
20
33
 
21
34
  /**
22
35
  * The constructor.
@@ -29,53 +42,75 @@ export class ContentManager implements IContentManager {
29
42
  /** @inheritDoc */
30
43
  public async loadKtx2Async(path: string, contentConfig?: ContentConfig): Promise<IKtx2Texture> {
31
44
 
45
+ // it's fine to call it, handled internally if called multiple times.
46
+ await this._ktx2Factory.initializeAsync();
47
+
32
48
  let ktx2Texture = this._ktx2TextureCache[path];
33
- if(ktx2Texture) {
49
+ if (ktx2Texture) {
34
50
  return ktx2Texture;
35
51
  }
36
52
 
37
53
  ktx2Texture = await this._ktx2Factory.loadAsync(path);
38
- if(contentConfig?.keepDataCached == true){
54
+ if (contentConfig?.keepDataCached == true) {
39
55
  this._ktx2TextureCache[path] = ktx2Texture;
40
56
  }
41
57
  return ktx2Texture;
42
58
  }
43
59
 
60
+ /**
61
+ * Disposes the cached shader modules (their GL programs) and forgets cached KTX2 data.
62
+ * Called from `Framework.dispose()`.
63
+ */
64
+ public dispose(): void {
65
+ (this.shaderModuleLoader as Partial<IDisposable>).dispose?.();
66
+ for (const key of Object.keys(this._ktx2TextureCache)) {
67
+ this._ktx2TextureCache[key].delete();
68
+ delete this._ktx2TextureCache[key];
69
+ }
70
+ }
71
+
44
72
  /** @inheritDoc */
45
- public loadShaderModule(shaderModuleId: string): IShaderModule {
46
- return this.shaderModuleLoader.load(shaderModuleId);
73
+ public loadShaderModule(shaderModuleId: string, keyValueDictionary?: { [id: string]: number }): IShaderModule {
74
+ return this.shaderModuleLoader.load(shaderModuleId, keyValueDictionary);
47
75
  }
48
76
 
49
77
  /** @inheritDoc */
50
78
  public async loadTexture2DAsync(path: string,
51
79
  textureDescriptor?: TextureDescriptor,
52
80
  contentConfig?: ContentConfig,
53
- ): Promise<ITexture2D> {
81
+ ): Promise<ITexture2D> {
82
+
83
+ // TODO: check texture cache
84
+ if (path.endsWith(KTX2_EXTENSION)) {
54
85
 
55
- if(path.endsWith(".ktx2")) {
56
- const ktx2Texture = await this.loadKtx2Async(path, contentConfig);
86
+ const ktx2Texture = await this.loadKtx2Async(path);
57
87
  textureDescriptor = textureDescriptor ?? new TextureDescriptor();
58
- return this._framework.textureFactory.createFromKtx2(ktx2Texture, textureDescriptor);
88
+ const tex = this._framework.textureFactory.createFromKtx2(ktx2Texture, textureDescriptor);
89
+ if (contentConfig?.keepDataCached !== true) {
90
+ ktx2Texture.delete();
91
+ }
92
+ return tex;
59
93
  }
60
94
 
61
- let format = this._framework.renderer.preferredTextureFormat;
95
+ let format = this._framework.renderer.preferredTextureFormat;
62
96
 
63
- if(textureDescriptor && textureDescriptor.textureFormat != TextureFormat.UNDEFINED) {
97
+ if (textureDescriptor && textureDescriptor.textureFormat != TextureFormat.UNDEFINED) {
64
98
  format = textureDescriptor.textureFormat;
65
99
  }
66
100
 
67
- // TODO: pass texture descriptor
68
101
  const imageLoader = this._framework.imageLoader;
69
102
  const data = await imageLoader.loadAsync(path, contentConfig?.keepDataCached);
103
+
104
+ // TODO: pass texture descriptor
70
105
  return this._framework.textureFactory.create(
71
106
  data.baseWidth, data.baseHeight,
72
107
  data.getData(0) as Uint8Array,
73
108
  data.channels,
74
- undefined,
109
+ path,
75
110
  TextureUsage.TEXTURE_BINDING | TextureUsage.COPY_SRC,
76
111
  format,
77
112
  textureDescriptor?.generateMipmaps
78
- );
113
+ );
79
114
  }
80
115
 
81
116
  /** @inheritDoc */
@@ -84,4 +119,31 @@ export class ContentManager implements IContentManager {
84
119
  return this._framework.textureFactory.create(width, height, view);
85
120
  }
86
121
 
87
- }
122
+ /** @inheritDoc */
123
+ public async loadMeshAsync(path: string, geometryFormat: GeometryFormat): Promise<IMesh> {
124
+ const model = await ObjLoader.parseAsync(path, {ignoreMaterials: true});
125
+ const geometry = this._framework.geometryBuilder.create(ObjGeometryMapper.toDescriptor(model.geometry));
126
+ return this._framework.meshFactory.createMesh(geometry, geometryFormat);
127
+ }
128
+
129
+ /** @inheritDoc */
130
+ public loadUnlitMeshAsync(path: string, camera?: ICamera): Promise<IRenderableMesh> {
131
+ return this._framework.objLoader.loadAsync(path, subMesh => {
132
+ const material = this._framework.materialFactory.createUnlitMaterial({camera});
133
+ const diffuse = subMesh.material?.diffuseColor ?? [1, 1, 1];
134
+ material.diffuseColor = new Color(diffuse[0], diffuse[1], diffuse[2], subMesh.material?.opacity ?? 1);
135
+ return material;
136
+ });
137
+ }
138
+
139
+ /** @inheritDoc */
140
+ public loadBlinnPhongMeshAsync(path: string, camera: ICamera): Promise<IRenderableMesh> {
141
+ if (!camera?.projectionViewBuffer || !camera?.positionBuffer) {
142
+ throw new Error(`loadBlinnPhongMeshAsync("${path}"): the camera has no projectionViewBuffer/positionBuffer. Pass an initialized camera (the camera factory initializes it).`);
143
+ }
144
+ return this._framework.objLoader.loadAsync(path, {
145
+ projectionViewBuffer: camera.projectionViewBuffer,
146
+ cameraPositionBuffer: camera.positionBuffer,
147
+ });
148
+ }
149
+ }
@@ -1,9 +1,13 @@
1
+ import type { ICamera } from "../camera/ICamera.ts";
2
+ import type { GeometryFormat } from "../geometry/GeometryFormat.ts";
3
+ import type { IRenderableMesh } from "../meshes/IRenderableMesh.ts";
1
4
  import type { IShaderModuleLoader } from "../shader/IShaderModuleLoader.ts";
2
5
  import type { IShaderModule } from "../shader/IShaderModule.ts";
3
6
  import type { ITexture2D } from "../rendering/texture/ITexture2D.ts";
4
7
  import {TextureDescriptor} from "../rendering/texture/TextureDescriptor.ts";
5
8
  import {ContentConfig} from "./ContentConfig.ts";
6
9
  import type { IKtx2Texture } from "ris-ktx2";
10
+ import type {IMesh} from "../meshes/IMesh.ts";
7
11
 
8
12
  /**
9
13
  * The content manager.
@@ -26,9 +30,10 @@ export interface IContentManager {
26
30
  /**
27
31
  * Loads a shader module.
28
32
  * @param shaderAssetId - The id of a shader asset.
33
+ * @param keyValueDictionary - If present, tries to find key in shader such that it replaced ##DIRECTIONAL_LIGHT_COUNT## by given value for key DIRECTIONAL_LIGHST_COUNT.
29
34
  * @returns The shader module.
30
35
  */
31
- loadShaderModule(shaderAssetId: string): IShaderModule;
36
+ loadShaderModule(shaderAssetId: string, keyValueDictionary?: { [id:string]: number}): IShaderModule;
32
37
 
33
38
  /**
34
39
  * Loads a texture2D.
@@ -38,4 +43,35 @@ export interface IContentManager {
38
43
  * @returns The Texture2D.
39
44
  */
40
45
  loadTexture2DAsync(path: string, desc?: TextureDescriptor, contentConfig?: ContentConfig): Promise<ITexture2D>;
46
+
47
+ /**
48
+ * Loads a plain mesh (geometry and buffers only, no material or transform) from an OBJ (Wavefront) file,
49
+ * like C# `ContentManager.LoadMesh`. Materials (.mtl) are not loaded.
50
+ * @param path The path or url to the .obj file.
51
+ * @param geometryFormat The vertex layout of the buffers, e.g. the format of the material it will be drawn with.
52
+ * @return The mesh.
53
+ */
54
+ loadMeshAsync(path: string, geometryFormat: GeometryFormat): Promise<IMesh>;
55
+
56
+ /**
57
+ * Loads an OBJ mesh with unlit materials, through `framework.objLoader`.
58
+ * The root mesh has no material; each `usemtl` range is a sub mesh with an unlit material
59
+ * (`Kd` as diffuse colour, `d` as alpha, white when missing). Add it with `scene.add(mesh)`.
60
+ * @param path The path or url to the .obj file.
61
+ * @param camera The optional camera; `scene.update()` assigns the scene camera anyway.
62
+ * @return The root mesh.
63
+ */
64
+ loadUnlitMeshAsync(path: string, camera?: ICamera): Promise<IRenderableMesh>;
65
+
66
+ /**
67
+ * Loads an OBJ mesh with Blinn-Phong materials: shorthand for
68
+ * `framework.objLoader.loadAsync(path, {projectionViewBuffer: camera.projectionViewBuffer, cameraPositionBuffer: camera.positionBuffer})`.
69
+ * See `ObjLoader.loadAsync` for the .mtl mapping. Add it with `scene.add(mesh)`; the scene assigns its camera and lights.
70
+ * @param path The path or url to the .obj file. A relative `mtllib` is resolved against it.
71
+ * @param camera An initialized camera (e.g. `scene.camera`).
72
+ * @return The root mesh.
73
+ * @throws Error when the camera has no buffers.
74
+ */
75
+ loadBlinnPhongMeshAsync(path: string, camera: ICamera): Promise<IRenderableMesh>;
76
+
41
77
  }
@@ -6,6 +6,9 @@ import inspectTextureMipsVS from "../../../shaders/glsl/inspect_texture_mips_vs.
6
6
  import inspectTextureMipsFS from "../../../shaders/glsl/inspect_texture_mips_fs.glsl?raw";
7
7
  import unlitMaterialVS from "../../../shaders/glsl/unlit_material_vs.glsl?raw";
8
8
  import unlitMaterialFS from "../../../shaders/glsl/unlit_material_fs.glsl?raw";
9
+ import forwardBlinnPhongVS from "../../../shaders/glsl/forward_blinn_phong_material_vs.glsl?raw";
10
+ import forwardBlinnPhongFS from "../../../shaders/glsl/forward_blinn_phong_material_fs.glsl?raw";
11
+
9
12
 
10
13
  /**
11
14
  * The api should look something like this for internal ones.
@@ -43,5 +46,11 @@ export const ShaderModuleContent : {[id: string]: any} = {
43
46
  "vertex": unlitMaterialVS,
44
47
  "fragment": unlitMaterialFS,
45
48
  "reflection": {}
49
+ },
50
+
51
+ "forward_blinn_phong_material": {
52
+ "vertex": forwardBlinnPhongVS,
53
+ "fragment": forwardBlinnPhongFS,
54
+ "reflection": {}
46
55
  }
47
56
  }
@@ -222,7 +222,13 @@ export class Color implements Iterable<number>{
222
222
  o
223
223
  }
224
224
 
225
-
225
+ /**
226
+ * Copy self and return new instance with same values.
227
+ * @return Color
228
+ * */
229
+ public copy(): Color {
230
+ return new Color(this.r, this.g, this.b, this.a);
231
+ }
226
232
  }
227
233
 
228
234
 
@@ -2,11 +2,34 @@ import { GeometryFormat } from "./GeometryFormat.ts";
2
2
  import {VertexFormat} from "./VertexFormat.ts";
3
3
  import type {IGeometry} from "../index.ts";
4
4
 
5
+
5
6
  /**
6
7
  * The default IGeometry implementation. GeometryBuilder fills it with vertex data.
7
8
  */
8
9
  export class BaseGeometry implements IGeometry {
9
10
 
11
+ /**
12
+ * Initializes a new instance of the BaseGeometry class.
13
+ * @param positions The optional positions of the geometry.
14
+ * @param indices The optional indices of the geometry.
15
+ * @param normals The optional normals of the geometry.
16
+ * @param textureCoords The optional texture coordinates of the geometry.
17
+ * @param colors The optional colors of the geometry.
18
+ */
19
+ constructor(positions?: number[], indices?: number[], normals?: number[], textureCoords?: number[], colors?: number[]) {
20
+ this.positions = positions;
21
+ this.indices = indices;
22
+ this.normals = normals;
23
+ this.textureCoords = textureCoords;
24
+ this.colors = colors;
25
+
26
+ if(this.indices && this.indices.length > 0) {
27
+ this.vertexCount = this.indices.length / 3;
28
+ } else if(this.positions && this.positions.length > 0) {
29
+ this.vertexCount = this.positions.length / 3;
30
+ }
31
+ }
32
+
10
33
  /** @inheritdoc */
11
34
  public vertexCount: number = 0;
12
35
 
@@ -1,6 +1,6 @@
1
1
  import { vec2 } from "gl-matrix"
2
2
  import { BaseGeometry } from "./BaseGeometry.ts";
3
- import type {IGeometry, IGeometryBuilder} from "../index.ts";
3
+ import type {IGeometry, IGeometryBuilder, GeometryDescriptor} from "../index.ts";
4
4
 
5
5
  /**
6
6
  * The GeometryBuilder class provides methods for creating various types of geometries, such as quads, with specified parameters like scale and winding order.
@@ -55,4 +55,16 @@ export class GeometryBuilder implements IGeometryBuilder {
55
55
 
56
56
  return geometry;
57
57
  }
58
- }
58
+
59
+ /** @inheritdoc */
60
+ public create(descriptor: GeometryDescriptor): IGeometry {
61
+ const vertexCount = descriptor.positions.length / 3;
62
+ return new BaseGeometry(
63
+ [...descriptor.positions],
64
+ descriptor.indices ? [...descriptor.indices] : undefined,
65
+ descriptor.normals ? [...descriptor.normals] : new Array(vertexCount * 3).fill(0),
66
+ descriptor.textureCoords ? [...descriptor.textureCoords] : new Array(vertexCount * 2).fill(0),
67
+ descriptor.colors ? [...descriptor.colors] : new Array(vertexCount * 4).fill(1),
68
+ );
69
+ }
70
+ }
@@ -1,6 +1,28 @@
1
1
  import type { IGeometry } from "./IGeometry.ts";
2
2
  import {vec2} from "gl-matrix";
3
3
 
4
+ /**
5
+ * The geometry descriptor.
6
+ * @public
7
+ */
8
+ export interface GeometryDescriptor {
9
+
10
+ /** Positions, 3 per vertex. */
11
+ readonly positions: number[];
12
+
13
+ /** Triangle indices, 3 per triangle. Optional for non-indexed geometry. */
14
+ readonly indices?: number[];
15
+
16
+ /** Normals, 3 per vertex. */
17
+ readonly normals?: number[];
18
+
19
+ /** Texture coordinates, 2 per vertex. */
20
+ readonly textureCoords?: number[];
21
+
22
+ /** RGBA colours, 4 per vertex. */
23
+ readonly colors?: number[];
24
+ }
25
+
4
26
  /**
5
27
  * The geometry builder.
6
28
  */
@@ -13,5 +35,13 @@ export interface IGeometryBuilder {
13
35
  * @returns The geometry.
14
36
  */
15
37
  quadGeometry(scale?: vec2, counterClockwise?: boolean): IGeometry;
16
-
38
+
39
+ /**
40
+ * Creates geometry from a plain descriptor.
41
+ * Attributes a material's geometry format needs but the descriptor lacks are filled with defaults:
42
+ * white colours, zero texture coordinates and zero normals.
43
+ * @param descriptor - The geometry descriptor. Its arrays are copied.
44
+ * @returns The geometry.
45
+ */
46
+ create(descriptor: GeometryDescriptor): IGeometry;
17
47
  }
@@ -1,4 +1,5 @@
1
1
  export * from "./IGeometryBuilder.ts";
2
2
  export * from "./IGeometry.ts";
3
3
  export * from "./VertexFormat.ts";
4
- export * from "./GeometryFormat.ts";
4
+ export * from "./GeometryFormat.ts";
5
+ export * from "./BaseGeometry.ts";
@@ -63,6 +63,8 @@ export class InputManager implements IInputManager {
63
63
  private readonly _touchCapabilities: TouchPanelCapabilities;
64
64
  private readonly _contacts: TouchContact[];
65
65
  private _touchListening = false;
66
+ /** Aborting it removes every canvas listener added in initialize(). */
67
+ private _listeners = new AbortController();
66
68
  /** Set in update, consumed in afterUpdate. Ageing before a publish would hide the press. */
67
69
  private _touchPublished = false;
68
70
 
@@ -120,6 +122,13 @@ export class InputManager implements IInputManager {
120
122
  return this._touchCapabilities;
121
123
  }
122
124
 
125
+ /** Removes the canvas listeners. Called from `Framework.dispose()`. */
126
+ public dispose(): void {
127
+ this._listeners.abort();
128
+ this._listeners = new AbortController();
129
+ this._touchListening = false;
130
+ }
131
+
123
132
  /** @inheritDoc */
124
133
  public initialize(): void {
125
134
 
@@ -133,20 +142,20 @@ export class InputManager implements IInputManager {
133
142
  canvas.addEventListener("mousemove", (e: MouseEvent) => {
134
143
  this._mousePosition[0] = e.clientX;
135
144
  this._mousePosition[1] = e.clientY;
136
- });
145
+ }, {signal: this._listeners.signal});
137
146
 
138
147
  canvas.addEventListener("mousedown", (e: MouseEvent) => {
139
148
  const idx = e.button;
140
149
  const btn = this._mouseButtonMap[idx] ?? MouseButton.NONE;
141
150
  this._mouseButtonDown[btn] = true;
142
- })
151
+ }, {signal: this._listeners.signal})
143
152
 
144
153
  canvas.addEventListener("mouseup", (e: MouseEvent) => {
145
154
  const idx = e.button;
146
155
  const btn = this._mouseButtonMap[idx] ?? MouseButton.NONE;
147
156
  this._mouseButtonDown[btn] = false;
148
157
  this._mouseButtonReleased[btn] = true;
149
- });
158
+ }, {signal: this._listeners.signal});
150
159
 
151
160
  canvas.addEventListener("wheel", (e: WheelEvent) => {
152
161
 
@@ -167,7 +176,7 @@ export class InputManager implements IInputManager {
167
176
  vec2.set(this._scrollWheelPosition, x, y);
168
177
 
169
178
  e.preventDefault();
170
- })
179
+ }, {signal: this._listeners.signal})
171
180
  }
172
181
 
173
182
  private _handleTouchEvents(canvas: HTMLCanvasElement): void {
@@ -179,7 +188,7 @@ export class InputManager implements IInputManager {
179
188
  // Pan and pinch-zoom start on this canvas only. The rest of the page is left alone.
180
189
  canvas.style.touchAction = "none";
181
190
 
182
- const options = InputManager._touchListenerOptions;
191
+ const options: AddEventListenerOptions = {...InputManager._touchListenerOptions, signal: this._listeners.signal};
183
192
  canvas.addEventListener("touchstart", this._onTouchStart, options);
184
193
  canvas.addEventListener("touchmove", this._onTouchMove, options);
185
194
  canvas.addEventListener("touchend", this._onTouchEnd, options);
@@ -0,0 +1,53 @@
1
+ import {Color} from "../data/Color.ts";
2
+ import {createLightId} from "./LightId.ts";
3
+ import type {Scene} from "../scene/Scene.ts";
4
+
5
+ /** The descriptor for an ambient light. All fields are optional. */
6
+ export interface AmbientLightDescriptor {
7
+ /** The unique id. Assigned automatically when omitted. */
8
+ id?: number;
9
+
10
+ /** The optional name for a light. */
11
+ name?: string;
12
+
13
+ /** The light colour. Alpha is ignored. Defaults to black. */
14
+ color?: Color;
15
+
16
+ /** Multiplies the colour. Defaults to 1. */
17
+ intensity?: number;
18
+ }
19
+
20
+ /**
21
+ * The ambient light. Plain data: it has no GPU resources.
22
+ * Put it into a {@link LightsBuffer} to use it in shaders.
23
+ * @public
24
+ */
25
+ export class AmbientLight {
26
+
27
+ /**
28
+ * The constructor.
29
+ * @param descriptor The optional descriptor. The colour is copied.
30
+ * @param scene The optional scene to register with.
31
+ */
32
+ public constructor(descriptor?: AmbientLightDescriptor, scene?: Scene) {
33
+
34
+ this.id = descriptor?.id ?? createLightId();
35
+ this.name = descriptor?.name;
36
+ this.color = descriptor?.color?.copy() ?? Color.black();
37
+ this.intensity = descriptor?.intensity ?? 1;
38
+
39
+ scene?.add(this);
40
+ }
41
+
42
+ /** The unique id of this light. */
43
+ public readonly id: number;
44
+
45
+ /** The optional name for a light. */
46
+ public name?: string;
47
+
48
+ /** The light color. Alpha is ignored. */
49
+ public color: Color;
50
+
51
+ /** Multiplies {@link color} when written to the lights buffer. */
52
+ public intensity: number;
53
+ }
@@ -0,0 +1,60 @@
1
+ import {vec3} from "gl-matrix";
2
+ import {Color} from "../data/Color.ts";
3
+ import {createLightId} from "./LightId.ts";
4
+ import type {Scene} from "../scene/Scene.ts";
5
+
6
+ /** The descriptor for a directional light. All fields are optional. */
7
+ export interface DirectionalLightDescriptor {
8
+ /** The unique id. Assigned automatically when omitted. */
9
+ id?: number;
10
+
11
+ /** The optional name for a light. */
12
+ name?: string;
13
+
14
+ /** The light colour. Alpha is ignored. Defaults to white. */
15
+ color?: Color;
16
+
17
+ /** Multiplies the colour. Defaults to 1. */
18
+ intensity?: number;
19
+
20
+ /** The direction in which the light travels. Defaults to straight down, (0, -1, 0). */
21
+ direction?: vec3;
22
+ }
23
+
24
+ /**
25
+ * The directional light. Plain data: it has no GPU resources.
26
+ * @public
27
+ */
28
+ export class DirectionalLight {
29
+
30
+ /**
31
+ * The constructor.
32
+ * @param descriptor The optional descriptor. Colour and direction are copied.
33
+ * @param scene The optional scene; the light adds itself via {@link Scene.add}.
34
+ * @throws Error when the scene has no free directional light slot left (the light is then not in the scene).
35
+ */
36
+ public constructor(descriptor?: DirectionalLightDescriptor, scene?: Scene) {
37
+ this.id = descriptor?.id ?? createLightId();
38
+ this.name = descriptor?.name;
39
+ this.color = descriptor?.color?.copy() ?? Color.white();
40
+ this.intensity = descriptor?.intensity ?? 1;
41
+ this.direction = descriptor?.direction ? vec3.clone(descriptor.direction) : vec3.fromValues(0, -1, 0);
42
+
43
+ scene?.add(this);
44
+ }
45
+
46
+ /** The unique id of this light. */
47
+ public readonly id: number;
48
+
49
+ /** The optional name for a light. */
50
+ public name?: string;
51
+
52
+ /** The light colour. Alpha is ignored. */
53
+ public color: Color;
54
+
55
+ /** Multiplies {@link color} when written to the lights buffer. */
56
+ public intensity: number;
57
+
58
+ /** The direction in which the light travels. */
59
+ public direction: vec3;
60
+ }