chorama 0.0.0

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 (256) hide show
  1. package/.configs/tsconfig.lib.json +43 -0
  2. package/.configs/tsconfig.website.json +34 -0
  3. package/.github/workflows/static.yml +88 -0
  4. package/.vscode/launch.json +29 -0
  5. package/.vscode/tasks.json +19 -0
  6. package/README.md +127 -0
  7. package/assets/images/disappointed.jpg +0 -0
  8. package/assets/images/skybox/grimmnight_back.png +0 -0
  9. package/assets/images/skybox/grimmnight_bottom.png +0 -0
  10. package/assets/images/skybox/grimmnight_front.png +0 -0
  11. package/assets/images/skybox/grimmnight_left.png +0 -0
  12. package/assets/images/skybox/grimmnight_right.png +0 -0
  13. package/assets/images/skybox/grimmnight_top.png +0 -0
  14. package/assets/images/skybox/miramar_back.png +0 -0
  15. package/assets/images/skybox/miramar_bottom.png +0 -0
  16. package/assets/images/skybox/miramar_front.png +0 -0
  17. package/assets/images/skybox/miramar_left.png +0 -0
  18. package/assets/images/skybox/miramar_right.png +0 -0
  19. package/assets/images/skybox/miramar_top.png +0 -0
  20. package/assets/images/uv.jpg +0 -0
  21. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_BaseColor.png +0 -0
  22. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_Normal.png +0 -0
  23. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_OcclusionRoughMetal.png +0 -0
  24. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_BaseColor.png +0 -0
  25. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_Normal.png +0 -0
  26. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_OcclusionRoughMetal.png +0 -0
  27. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_BaseColor.png +0 -0
  28. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_Normal.png +0 -0
  29. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png +0 -0
  30. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_BaseColor.png +0 -0
  31. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_Normal.png +0 -0
  32. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_OcclusionRoughMetal.png +0 -0
  33. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_BaseColor.png +0 -0
  34. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_Normal.png +0 -0
  35. package/assets/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_OcclusionRoughMetal.png +0 -0
  36. package/assets/models/gltf/flight_helmet/index.bin +0 -0
  37. package/assets/models/gltf/flight_helmet/index.gltf +705 -0
  38. package/assets/models/gltf/object.gltf +23 -0
  39. package/assets/models/gltf/pirate_girl/index.bin +0 -0
  40. package/assets/models/gltf/pirate_girl/index.gltf +2082 -0
  41. package/assets/models/obj/pirate_girl/pirate_girl.obj +18459 -0
  42. package/assets/models/obj/pirate_girl/pirate_girl.png +0 -0
  43. package/astro.config.mjs +45 -0
  44. package/content/guide/api-map.md +89 -0
  45. package/content/guide/camera-and-controls.md +98 -0
  46. package/content/guide/first-scene.md +176 -0
  47. package/content/guide/index.md +72 -0
  48. package/content/guide/installation.md +179 -0
  49. package/content/guide/materials-and-lighting.md +138 -0
  50. package/content/guide/plugins-and-render-pipeline.md +124 -0
  51. package/content/guide/render-targets-and-views.md +147 -0
  52. package/content/guide/scene-graph-and-transforms.md +113 -0
  53. package/content/guide/textures-and-assets.md +120 -0
  54. package/content/guide/troubleshooting.md +49 -0
  55. package/env.d.ts +19 -0
  56. package/examples/addons/rendergraph_gui.js +580 -0
  57. package/examples/camera/orthographic.js +120 -0
  58. package/examples/camera/perspective.js +138 -0
  59. package/examples/lights/directional.js +397 -0
  60. package/examples/lights/multiple_spot_lights.js +304 -0
  61. package/examples/lights/point.js +337 -0
  62. package/examples/lights/spot.js +366 -0
  63. package/examples/loader/gltf_material.js +111 -0
  64. package/examples/loader/gltfloader.js +78 -0
  65. package/examples/loader/objloader.js +95 -0
  66. package/examples/material/cullface.js +111 -0
  67. package/examples/material/materials.js +126 -0
  68. package/examples/material/standard/basic.js +164 -0
  69. package/examples/mesh/circle.js +117 -0
  70. package/examples/mesh/cuboid.js +151 -0
  71. package/examples/mesh/cylinder.js +139 -0
  72. package/examples/mesh/geometries.js +108 -0
  73. package/examples/mesh/meshTopology.js +103 -0
  74. package/examples/mesh/plane.js +117 -0
  75. package/examples/mesh/skinning.js +136 -0
  76. package/examples/mesh/uvsphere.js +113 -0
  77. package/examples/other/rotatingCube.js +93 -0
  78. package/examples/other/rotatingSphere.js +96 -0
  79. package/examples/rendertarget/basic_canvas.js +130 -0
  80. package/examples/rendertarget/depth_texture.js +130 -0
  81. package/examples/rendertarget/image_target.js +140 -0
  82. package/examples/rendertarget/multiple_views.js +158 -0
  83. package/examples/rendertarget/render_masks.js +173 -0
  84. package/examples/rendertarget/split_screen.js +123 -0
  85. package/examples/rendertarget/split_view.js +137 -0
  86. package/examples/skybox/skybox.js +111 -0
  87. package/examples/texture/arrays.js +156 -0
  88. package/examples/texture/textureWrap.js +118 -0
  89. package/examples/transform/propagation.js +92 -0
  90. package/package.json +55 -0
  91. package/rollup.config.js +66 -0
  92. package/scripts/stage-chorama.mjs +29 -0
  93. package/src/caches/cache.js +420 -0
  94. package/src/caches/index.js +2 -0
  95. package/src/caches/uniformbuffers.js +104 -0
  96. package/src/cameracontrols/index.js +258 -0
  97. package/src/constants/index.js +3 -0
  98. package/src/constants/mesh.js +197 -0
  99. package/src/constants/others.js +218 -0
  100. package/src/constants/texture.js +183 -0
  101. package/src/core/constants.js +14 -0
  102. package/src/core/extensions.js +42 -0
  103. package/src/core/index.js +7 -0
  104. package/src/core/layouts/index.js +4 -0
  105. package/src/core/layouts/meshvertex.js +60 -0
  106. package/src/core/layouts/uniform.js +21 -0
  107. package/src/core/layouts/uniformbuffer.js +15 -0
  108. package/src/core/layouts/vertexbuffer.js +43 -0
  109. package/src/core/limits.js +247 -0
  110. package/src/core/resources/blendparams.js +89 -0
  111. package/src/core/resources/framebuffer.js +127 -0
  112. package/src/core/resources/gpubuffer.js +32 -0
  113. package/src/core/resources/gpumesh.js +43 -0
  114. package/src/core/resources/gputexture.js +73 -0
  115. package/src/core/resources/index.js +5 -0
  116. package/src/core/shader.js +62 -0
  117. package/src/core/webgl/bindgroup.js +89 -0
  118. package/src/core/webgl/descriptors.js +104 -0
  119. package/src/core/webgl/index.js +5 -0
  120. package/src/core/webgl/renderpassencoder.js +96 -0
  121. package/src/core/webgl/renderpipeline.js +54 -0
  122. package/src/core/webgl/utils.js +371 -0
  123. package/src/core/webgl/webglrenderdevice.js +235 -0
  124. package/src/function.js +358 -0
  125. package/src/index.js +15 -0
  126. package/src/loader/gltf.js +2172 -0
  127. package/src/loader/index.js +3 -0
  128. package/src/loader/loader.js +174 -0
  129. package/src/loader/obj.js +188 -0
  130. package/src/loader/texture.js +85 -0
  131. package/src/loader/utils.js +16 -0
  132. package/src/material/basic.js +75 -0
  133. package/src/material/depth.js +73 -0
  134. package/src/material/index.js +8 -0
  135. package/src/material/lambert.js +73 -0
  136. package/src/material/material.js +106 -0
  137. package/src/material/normal.js +30 -0
  138. package/src/material/phong.js +86 -0
  139. package/src/material/raw.js +52 -0
  140. package/src/material/standard.js +221 -0
  141. package/src/math/index.js +3 -0
  142. package/src/math/transform.js +38 -0
  143. package/src/mesh/attribute/attribute.js +79 -0
  144. package/src/mesh/attribute/index.js +1 -0
  145. package/src/mesh/attributedata/index.js +1 -0
  146. package/src/mesh/attributedata/separate.js +180 -0
  147. package/src/mesh/builders/base.js +41 -0
  148. package/src/mesh/builders/circle.js +63 -0
  149. package/src/mesh/builders/cuboid.js +135 -0
  150. package/src/mesh/builders/cylinder.js +131 -0
  151. package/src/mesh/builders/index.js +7 -0
  152. package/src/mesh/builders/plane.js +73 -0
  153. package/src/mesh/builders/utils.js +20 -0
  154. package/src/mesh/builders/uvsphere.js +80 -0
  155. package/src/mesh/builders/wireframe.js +62 -0
  156. package/src/mesh/index.js +4 -0
  157. package/src/mesh/mesh.js +149 -0
  158. package/src/objects/bone.js +17 -0
  159. package/src/objects/camera/camera.js +56 -0
  160. package/src/objects/camera/index.js +2 -0
  161. package/src/objects/camera/projection.js +203 -0
  162. package/src/objects/debug/index.js +1 -0
  163. package/src/objects/debug/skeleton.js +28 -0
  164. package/src/objects/index.js +7 -0
  165. package/src/objects/light/ambient.js +20 -0
  166. package/src/objects/light/directional.js +29 -0
  167. package/src/objects/light/index.js +5 -0
  168. package/src/objects/light/point.js +32 -0
  169. package/src/objects/light/shadow/index.js +1 -0
  170. package/src/objects/light/shadow/shadow.js +67 -0
  171. package/src/objects/light/spot.js +56 -0
  172. package/src/objects/mesh.js +141 -0
  173. package/src/objects/object3d.js +167 -0
  174. package/src/objects/skybox.js +38 -0
  175. package/src/plugins/camera/camera.js +19 -0
  176. package/src/plugins/camera/index.js +2 -0
  177. package/src/plugins/camera/nodes/cameraview.js +46 -0
  178. package/src/plugins/camera/nodes/index.js +2 -0
  179. package/src/plugins/camera/nodes/opaquepass.js +79 -0
  180. package/src/plugins/index.js +6 -0
  181. package/src/plugins/light/index.js +2 -0
  182. package/src/plugins/light/light.js +23 -0
  183. package/src/plugins/light/nodes/index.js +1 -0
  184. package/src/plugins/light/nodes/light.js +127 -0
  185. package/src/plugins/meshmaterial/index.js +3 -0
  186. package/src/plugins/meshmaterial/meshmaterial.js +381 -0
  187. package/src/plugins/meshmaterial/nodes/index.js +1 -0
  188. package/src/plugins/meshmaterial/nodes/meshmaterial.js +50 -0
  189. package/src/plugins/meshmaterial/resources/index.js +1 -0
  190. package/src/plugins/meshmaterial/resources/meshmaterialpipelines.js +50 -0
  191. package/src/plugins/shadow/index.js +3 -0
  192. package/src/plugins/shadow/nodes/index.js +3 -0
  193. package/src/plugins/shadow/nodes/shadow.js +272 -0
  194. package/src/plugins/shadow/nodes/shadowOccluder.js +112 -0
  195. package/src/plugins/shadow/nodes/shadowOpaquePass.js +73 -0
  196. package/src/plugins/shadow/resources/ShadowMap.js +99 -0
  197. package/src/plugins/shadow/resources/index.js +2 -0
  198. package/src/plugins/shadow/resources/shadowpipelines.js +25 -0
  199. package/src/plugins/shadow/shadow.js +31 -0
  200. package/src/plugins/skeletonhelper/index.js +1 -0
  201. package/src/plugins/skeletonhelper/skeletonhelper.js +160 -0
  202. package/src/plugins/skybox/index.js +3 -0
  203. package/src/plugins/skybox/nodes/index.js +1 -0
  204. package/src/plugins/skybox/nodes/skybox.js +143 -0
  205. package/src/plugins/skybox/resources/index.js +2 -0
  206. package/src/plugins/skybox/resources/skyboxmesh.js +14 -0
  207. package/src/plugins/skybox/resources/skyboxpipeline.js +6 -0
  208. package/src/plugins/skybox/skybox.js +137 -0
  209. package/src/renderer/core/index.js +179 -0
  210. package/src/renderer/graph/index.js +3 -0
  211. package/src/renderer/graph/nodes.js +34 -0
  212. package/src/renderer/graph/rendergraph.js +182 -0
  213. package/src/renderer/index.js +5 -0
  214. package/src/renderer/plugin.js +36 -0
  215. package/src/renderer/renderer.js +179 -0
  216. package/src/renderer/views.js +28 -0
  217. package/src/rendertarget/canvastarget.js +30 -0
  218. package/src/rendertarget/image.js +132 -0
  219. package/src/rendertarget/index.js +3 -0
  220. package/src/rendertarget/rendertarget.js +89 -0
  221. package/src/shader/basicFragment.glsl +30 -0
  222. package/src/shader/basicVertex.glsl +87 -0
  223. package/src/shader/common/color.glsl +7 -0
  224. package/src/shader/common/common.glsl +25 -0
  225. package/src/shader/common/index.js +4 -0
  226. package/src/shader/common/light.glsl +437 -0
  227. package/src/shader/common/math.glsl +12 -0
  228. package/src/shader/debug/index.js +2 -0
  229. package/src/shader/debug/skeletonFragment.glsl +8 -0
  230. package/src/shader/debug/skeletonVertex.glsl +27 -0
  231. package/src/shader/depthFragment.glsl +37 -0
  232. package/src/shader/index.js +11 -0
  233. package/src/shader/lambertFragment.glsl +126 -0
  234. package/src/shader/normalFragment.glsl +25 -0
  235. package/src/shader/phongFragment.glsl +140 -0
  236. package/src/shader/skyboxFragment.glsl +16 -0
  237. package/src/shader/skyboxVertex.glsl +20 -0
  238. package/src/shader/standardFragment.glsl +274 -0
  239. package/src/texture/index.js +2 -0
  240. package/src/texture/sampler.js +111 -0
  241. package/src/texture/texture.js +234 -0
  242. package/src/utils/index.js +115 -0
  243. package/tsconfig.json +11 -0
  244. package/website/config/index.ts +1 -0
  245. package/website/config/navigation.ts +53 -0
  246. package/website/content.config.ts +92 -0
  247. package/website/layouts/DocLayout.astro +501 -0
  248. package/website/layouts/Example.astro +91 -0
  249. package/website/pages/examples/[...slug].astro +77 -0
  250. package/website/pages/examples/index.astro +98 -0
  251. package/website/pages/examples/samples/[...slug].astro +17 -0
  252. package/website/pages/guide/[slug].astro +30 -0
  253. package/website/pages/guide/index.astro +21 -0
  254. package/website/pages/index.astro +9 -0
  255. package/website/plugins/remark-link-base.js +23 -0
  256. package/website/utils/url.ts +30 -0
@@ -0,0 +1,111 @@
1
+ import { TextureFilter, TextureWrap } from '../constants/index.js'
2
+ import { CompareFunction } from '../core/index.js'
3
+ export class Sampler {
4
+ /**
5
+ * @type {TextureFilter}
6
+ */
7
+
8
+ magnificationFilter
9
+ /**
10
+ * @type {TextureFilter}
11
+ */
12
+ minificationFilter
13
+ /**
14
+ * @type {TextureFilter | undefined}
15
+ */
16
+ mipmapFilter
17
+
18
+ /**
19
+ * @type {TextureWrap}
20
+ */
21
+ wrapS
22
+ /**
23
+ * @type {TextureWrap}
24
+ */
25
+ wrapT
26
+ /**
27
+ * @type {TextureWrap}
28
+ */
29
+ wrapR
30
+ /**
31
+ * @type {number}
32
+ */
33
+ anisotropy
34
+ /**
35
+ * @type {SamplerLODSettings}
36
+ */
37
+ lod
38
+ /**
39
+ * @type {CompareFunction | undefined}
40
+ */
41
+ compare
42
+ /**
43
+ * @param {SamplerSettings} settings
44
+ */
45
+ constructor({
46
+ magnificationFilter = Sampler.defaultSettings.magnificationFilter,
47
+ minificationFilter = Sampler.defaultSettings.minificationFilter,
48
+ mipmapFilter = Sampler.defaultSettings.mipmapFilter,
49
+ wrapS = Sampler.defaultSettings.wrapS,
50
+ wrapT = Sampler.defaultSettings.wrapT,
51
+ wrapR = Sampler.defaultSettings.wrapR,
52
+ lod = Sampler.defaultSettings.lod,
53
+ anisotropy = Sampler.defaultSettings.anisotropy,
54
+ compare = Sampler.defaultSettings.compare
55
+ } = Sampler.defaultSettings) {
56
+ this.minificationFilter = minificationFilter
57
+ this.magnificationFilter = magnificationFilter
58
+ this.mipmapFilter = mipmapFilter
59
+ this.wrapS = wrapS
60
+ this.wrapT = wrapT
61
+ this.wrapR = wrapR
62
+ this.anisotropy = anisotropy
63
+ this.lod = lod
64
+ this.compare = compare
65
+ }
66
+
67
+ static default(){
68
+ return new Sampler()
69
+ }
70
+
71
+ /**
72
+ * @readonly
73
+ * @type {Readonly<
74
+ * Required<Omit<SamplerSettings,'compare' | 'mipmapFilter'>>
75
+ * > & {
76
+ * compare: CompareFunction | undefined;
77
+ * mipmapFilter: TextureFilter | undefined;
78
+ * }
79
+ * }
80
+ */
81
+ static defaultSettings = {
82
+ magnificationFilter: TextureFilter.Linear,
83
+ minificationFilter: TextureFilter.Linear,
84
+ mipmapFilter: undefined,
85
+ wrapS: TextureWrap.Clamp,
86
+ wrapT: TextureWrap.Clamp,
87
+ wrapR: TextureWrap.Clamp,
88
+ lod: { min: 0, max: 12 },
89
+ anisotropy: 1,
90
+ compare: undefined
91
+ }
92
+ }
93
+
94
+ /**
95
+ * @typedef SamplerSettings
96
+ * @property {TextureFilter} [minificationFilter]
97
+ * @property {TextureFilter} [magnificationFilter]
98
+ * @property {TextureFilter} [mipmapFilter]
99
+ * @property {TextureWrap} [wrapS]
100
+ * @property {TextureWrap} [wrapT]
101
+ * @property {TextureWrap} [wrapR]
102
+ * @property {SamplerLODSettings} [lod]
103
+ * @property {number} [anisotropy]
104
+ * @property {CompareFunction} [compare]
105
+ */
106
+
107
+ /**
108
+ * @typedef SamplerLODSettings
109
+ * @property {number} max
110
+ * @property {number} min
111
+ */
@@ -0,0 +1,234 @@
1
+ import { TextureFormat, TextureType } from "../constants/index.js"
2
+
3
+ export class Texture {
4
+
5
+ /**
6
+ * Tracks if the texture has changed since last checked.
7
+ * @type {boolean}
8
+ */
9
+ #changed = false
10
+
11
+ /**
12
+ * The raw pixel data for the texture.
13
+ * @type {ArrayBuffer | undefined}
14
+ */
15
+ #data
16
+
17
+ /**
18
+ * The width of the texture in pixels.
19
+ * @type {number}
20
+ */
21
+ #width
22
+
23
+ /**
24
+ * The height of the texture in pixels.
25
+ * @type {number}
26
+ */
27
+ #height
28
+
29
+ /**
30
+ * The depth of the texture, used for 3D textures or texture arrays.
31
+ * @type {number}
32
+ */
33
+ #depth
34
+
35
+ /**
36
+ * The texture format of this texture.
37
+ * @type {TextureFormat}
38
+ */
39
+ #format
40
+
41
+ /**
42
+ * Whether mipmaps should be automatically generated for this texture.
43
+ * @type {boolean}
44
+ */
45
+ #generateMipmaps
46
+
47
+ /**
48
+ * Whether the texture should be flipped vertically on upload.
49
+ * @type {boolean}
50
+ */
51
+ #flipY
52
+
53
+ /**
54
+ * The type of texture (e.g., Texture2D, TextureCube, etc.).
55
+ * @type {TextureType}
56
+ */
57
+ #type
58
+
59
+ /**
60
+ * @param {TextureSettings & { data?: ArrayBuffer, type: TextureType }} settings
61
+ */
62
+ constructor({
63
+ data,
64
+ type,
65
+ format = Texture.defaultSettings.format,
66
+ generateMipmaps = Texture.defaultSettings.generateMipmaps,
67
+ flipY = Texture.defaultSettings.flipY,
68
+ width = Texture.defaultSettings.width,
69
+ height = Texture.defaultSettings.height,
70
+ depth = Texture.defaultSettings.depth,
71
+ }) {
72
+ this.#data = data
73
+ this.#type = type
74
+ this.#width = width
75
+ this.#height = height
76
+ this.#depth = depth
77
+ this.#flipY = flipY
78
+ this.#format = format
79
+ this.#generateMipmaps = generateMipmaps
80
+ }
81
+
82
+ /**
83
+ * @package
84
+ * @returns {boolean}
85
+ * This is an internal property, do not use!
86
+ */
87
+ get changed() {
88
+ const previous = this.#changed
89
+ this.#changed = false
90
+ return previous
91
+ }
92
+
93
+ /** @type {ArrayBuffer | undefined} */
94
+ get data() { return this.#data }
95
+ set data(value) {
96
+ this.#data = value
97
+ this.#changed = true
98
+ }
99
+
100
+ /** @type {number} */
101
+ get width() { return this.#width }
102
+ set width(value) {
103
+ this.#width = value
104
+ this.#changed = true
105
+ }
106
+
107
+ /** @type {number} */
108
+ get height() { return this.#height }
109
+ set height(value) {
110
+ this.#height = value
111
+ this.#changed = true
112
+ }
113
+
114
+ /** @type {number} */
115
+ get depth() { return this.#depth }
116
+ set depth(value) {
117
+ this.#depth = value
118
+ this.#changed = true
119
+ }
120
+
121
+ /** @type {TextureFormat} */
122
+ get format() { return this.#format }
123
+ set format(value) {
124
+ this.#format = value
125
+ this.#changed = true
126
+ }
127
+
128
+ /** @type {boolean} */
129
+ get generateMipmaps() { return this.#generateMipmaps }
130
+ set generateMipmaps(value) {
131
+ this.#generateMipmaps = value
132
+ this.#changed = true
133
+ }
134
+
135
+ /** @type {boolean} */
136
+ get flipY() { return this.#flipY }
137
+ set flipY(value) {
138
+ this.#flipY = value
139
+ this.#changed = true
140
+ }
141
+
142
+ /** @type {TextureType} */
143
+ get type() { return this.#type }
144
+ set type(value) {
145
+ this.#type = value
146
+ this.#changed = true
147
+ }
148
+
149
+ /**
150
+ * Applies a new set of texture settings.
151
+ * @param {TextureSettings} settings
152
+ */
153
+ apply({
154
+ format = Texture.defaultSettings.format,
155
+ generateMipmaps = Texture.defaultSettings.generateMipmaps,
156
+ flipY = Texture.defaultSettings.flipY,
157
+ width = Texture.defaultSettings.width,
158
+ height = Texture.defaultSettings.height,
159
+ depth = Texture.defaultSettings.depth,
160
+ }) {
161
+ this.width = width
162
+ this.height = height
163
+ this.depth = depth
164
+ this.flipY = flipY
165
+ this.format = format
166
+ this.generateMipmaps = generateMipmaps
167
+ }
168
+
169
+ /**
170
+ * Copies the values from another texture into this one.
171
+ * @param {this} other
172
+ * @returns {this}
173
+ */
174
+ copy(other) {
175
+ this.data = other.data ? other.data.slice() : undefined
176
+ this.format = other.format
177
+ this.width = other.width
178
+ this.height = other.height
179
+ this.depth = other.depth
180
+ this.type = other.type
181
+ this.flipY = other.flipY
182
+ this.generateMipmaps = other.generateMipmaps
183
+ return this
184
+ }
185
+
186
+ /**
187
+ * Creates a new texture that is a copy of this one.
188
+ * @returns {this}
189
+ */
190
+ clone() {
191
+ return new /** @type {new (...args:any[]) => this} */(this.constructor)({}).copy(this)
192
+ }
193
+
194
+ /**
195
+ * Creates a default 1×1 white texture.
196
+ * @returns {Texture}
197
+ */
198
+ static default() {
199
+ const width = 1
200
+ const height = 1
201
+ const pixel = new Uint8Array([255, 255, 255, 255])
202
+ const texture = new Texture({
203
+ width,
204
+ height,
205
+ data: pixel.buffer,
206
+ type: TextureType.Texture2D,
207
+ })
208
+ return texture
209
+ }
210
+
211
+ /**
212
+ * Default texture settings.
213
+ * @readonly
214
+ * @type {Readonly<Required<TextureSettings>>}
215
+ */
216
+ static defaultSettings = {
217
+ format: TextureFormat.RGBA8Unorm,
218
+ generateMipmaps: false,
219
+ flipY: false,
220
+ width: 0,
221
+ height: 0,
222
+ depth: 1,
223
+ }
224
+ }
225
+
226
+ /**
227
+ * @typedef TextureSettings
228
+ * @property {boolean} [generateMipmaps=true]
229
+ * @property {TextureFormat} [format]
230
+ * @property {boolean} [flipY]
231
+ * @property {number} [width]
232
+ * @property {number} [height]
233
+ * @property {number} [depth]
234
+ */
@@ -0,0 +1,115 @@
1
+ import { Vector2 } from "../math/index.js"
2
+
3
+ export class ViewRectangle {
4
+ offset = new Vector2()
5
+ size = new Vector2(1, 1)
6
+
7
+ /**
8
+ * @param {ViewRectangle} other
9
+ */
10
+ copy(other) {
11
+ this.offset.copy(other.offset)
12
+ this.size.copy(other.size)
13
+ }
14
+
15
+ clone() {
16
+ return new ViewRectangle().copy(this)
17
+ }
18
+ }
19
+
20
+ export class Range {
21
+ start
22
+ end
23
+ constructor(start = 0, end = 1) {
24
+ this.start = start
25
+ this.end = end
26
+ }
27
+
28
+ /**
29
+ * @param {Range} other
30
+ */
31
+ copy(other) {
32
+ this.start = other.start
33
+ this.end = other.end
34
+ }
35
+
36
+ clone() {
37
+ return new Range().copy(this)
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Throws an error if the supplied test is null or undefined.
43
+ *
44
+ * @template T
45
+ * @param {T} test
46
+ * @param {string} message
47
+ * @returns {asserts test is NonNullable<T>}
48
+ */
49
+ export function assert(test, message) {
50
+ if (test === undefined || test === null) throw message
51
+ }
52
+
53
+ /**
54
+ * @template T
55
+ * @template {string} U
56
+ * @typedef {T & {__brand: U;}} Brand
57
+ */
58
+
59
+ /**
60
+ * @param {ArrayBufferLike} source
61
+ * @param {ArrayBufferLike} destination
62
+ * @param {number | undefined} offset
63
+ * @param {number | undefined} length
64
+ */
65
+ export function copyBuffer(source, destination, offset, length) {
66
+ const sourceView = new Uint8Array(source)
67
+ const destView = new Uint8Array(destination, offset, length)
68
+ destView.set(sourceView)
69
+ }
70
+
71
+ export class AbstractClassError {
72
+ static Unconstructable = "The class `{0}` is not constructible.Extend the class."
73
+ static MethodUnimplemented = "The method `{0}.{1}()` is not implemented. Override the method without using `super.{1}()`."
74
+ static MethodUncallable = "The method `{0}.{1}()` is not callable.`{0}` is an abstract class."
75
+ }
76
+
77
+ /**
78
+ * @param {string} string
79
+ * @param {string[]} args
80
+ */
81
+ export function formatString(string, ...args) {
82
+ return string.replace(/{(\d+)}/g, function (match, number) {
83
+ const index = parseInt(number)
84
+ if (typeof index == 'number') {
85
+ return args[index] || match
86
+ }
87
+
88
+ return match
89
+ })
90
+ }
91
+
92
+ /**
93
+ * @param {object} item
94
+ * @param {object} baseConstructor
95
+ * @param {string} methodName
96
+ * @returns {never}
97
+ */
98
+ export function abstractMethod(item, baseConstructor, methodName) {
99
+ if (item.constructor === baseConstructor) {
100
+ throw formatString(AbstractClassError.MethodUncallable, item.constructor.name, methodName)
101
+ }
102
+ throw formatString(AbstractClassError.MethodUnimplemented, item.constructor.name, methodName)
103
+ }
104
+
105
+ /**
106
+ *
107
+ * @param {object} item
108
+ * @param {object} baseConstructor
109
+ * @returns {never | void}
110
+ */
111
+ export function abstractClass(item, baseConstructor) {
112
+ if(item.constructor === baseConstructor){
113
+ throw formatString(AbstractClassError.Unconstructable, item.constructor.name)
114
+ }
115
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ {
5
+ "path": "./.configs/tsconfig.lib.json"
6
+ },
7
+ {
8
+ "path": "./.configs/tsconfig.website.json"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1 @@
1
+ export * from './navigation'
@@ -0,0 +1,53 @@
1
+ import { withBase } from "../utils/url";
2
+
3
+ export interface NavTab {
4
+ label: string;
5
+ href?: string;
6
+ children?: NavTab[];
7
+ }
8
+
9
+ const tabs: NavTab[] = [
10
+ {
11
+ label: "Introduction",
12
+ href: "#chorama",
13
+ children: [
14
+ { label: "Top", href: "#chorama" },
15
+ { label: "Features", href: "#features" },
16
+ { label: "Who This Is For", href: "#who-this-is-for" },
17
+ { label: "Getting Started", href: "#getting-started" },
18
+ { label: "Core Usage Flow", href: "#core-usage-flow" }
19
+ ]
20
+ },
21
+ {
22
+ label: "Guide",
23
+ href: "/guide",
24
+ children: [
25
+ { label: "Overview", href: "/guide" },
26
+ { label: "Installation", href: "/guide/installation" },
27
+ { label: "First Scene", href: "/guide/first-scene" },
28
+ { label: "Camera and Controls", href: "/guide/camera-and-controls" },
29
+ { label: "Materials and Lighting", href: "/guide/materials-and-lighting" },
30
+ { label: "Textures and Assets", href: "/guide/textures-and-assets" },
31
+ { label: "Render Targets and Views", href: "/guide/render-targets-and-views" },
32
+ { label: "Scene Graph and Transforms", href: "/guide/scene-graph-and-transforms" },
33
+ { label: "Plugins and Render Pipeline", href: "/guide/plugins-and-render-pipeline" },
34
+ { label: "API Map", href: "/guide/api-map" },
35
+ { label: "Troubleshooting", href: "/guide/troubleshooting" }
36
+ ]
37
+ },
38
+ {
39
+ label: "Examples",
40
+ href: "/examples",
41
+ children: [{ label: "Overview", href: "/examples" }]
42
+ }
43
+ ];
44
+
45
+ function mapTabLinks(tab: NavTab): NavTab {
46
+ return {
47
+ ...tab,
48
+ href: tab.href ? withBase(tab.href) : undefined,
49
+ children: tab.children?.map(mapTabLinks),
50
+ };
51
+ }
52
+
53
+ export const sidebarTabs: NavTab[] = tabs.map(mapTabLinks);
@@ -0,0 +1,92 @@
1
+ import { defineCollection, z } from "astro:content";
2
+ import { glob } from "astro/loaders";
3
+ import { readdir, readFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+
6
+ const examplesRoot = path.resolve("./examples");
7
+
8
+ interface ExampleEntry {
9
+ id: string;
10
+ title: string;
11
+ description: string;
12
+ category: string;
13
+ filePath: string;
14
+ source: string;
15
+ }
16
+
17
+ function toTitle(value: string): string {
18
+ return value
19
+ .replace(/[_-]+/g, " ")
20
+ .replace(/\b\w/g, (match) => match.toUpperCase());
21
+ }
22
+
23
+ async function collectExampleFiles(dir: string, root: string): Promise<string[]> {
24
+ const dirEntries = await readdir(dir, { withFileTypes: true });
25
+ const files: string[] = [];
26
+
27
+ for (const dirEntry of dirEntries) {
28
+ const fullPath = path.join(dir, dirEntry.name);
29
+ const relativePath = path.relative(root, fullPath).split(path.sep).join("/");
30
+
31
+ if (dirEntry.isDirectory()) {
32
+ if (relativePath === "addons" || relativePath.startsWith("addons/")) {
33
+ continue;
34
+ }
35
+ files.push(...(await collectExampleFiles(fullPath, root)));
36
+ continue;
37
+ }
38
+
39
+ if (dirEntry.isFile() && dirEntry.name.endsWith(".js")) {
40
+ files.push(path.relative(root, fullPath));
41
+ }
42
+ }
43
+
44
+ return files;
45
+ }
46
+
47
+ const examples = defineCollection({
48
+ loader: async (): Promise<ExampleEntry[]> => {
49
+ const relativePaths = await collectExampleFiles(examplesRoot, examplesRoot);
50
+
51
+ return Promise.all(
52
+ relativePaths.map(async (relativePath) => {
53
+ const normalizedPath = relativePath.split(path.sep).join("/");
54
+ const id = normalizedPath.replace(/\.js$/, "");
55
+ const segments = id.split("/");
56
+ const category = segments[0] || "uncategorized";
57
+ const fileName = segments.at(-1) || "example";
58
+
59
+ return {
60
+ id,
61
+ title: toTitle(fileName),
62
+ description: `${toTitle(category)} example`,
63
+ category,
64
+ filePath: `/examples/${normalizedPath}`,
65
+ source: await readFile(path.join(examplesRoot, relativePath), "utf-8")
66
+ };
67
+ })
68
+ );
69
+ },
70
+ schema: z.object({
71
+ title: z.string(),
72
+ description: z.string(),
73
+ category: z.string(),
74
+ filePath: z.string(),
75
+ source: z.string()
76
+ })
77
+ });
78
+
79
+ const guide = defineCollection({
80
+ loader: glob({
81
+ pattern: "**/*.md",
82
+ base: "./content/guide"
83
+ }),
84
+ schema: z.object({
85
+ title: z.string()
86
+ })
87
+ });
88
+
89
+ export const collections = {
90
+ examples,
91
+ guide
92
+ };