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,366 @@
1
+ import {
2
+ MeshMaterial3D,
3
+ WebGLRenderer,
4
+ TextureLoader,
5
+ PerspectiveProjection,
6
+ Camera,
7
+ WebGLRenderDevice,
8
+ PlaneMeshBuilder,
9
+ OrbitCameraControls,
10
+ MeshMaterialPlugin,
11
+ LightPlugin,
12
+ AmbientLight,
13
+ TextureType,
14
+ SkyBox,
15
+ UVSphereMeshBuilder,
16
+ LambertMaterial,
17
+ BasicMaterial,
18
+ Color,
19
+ PhongMaterial,
20
+ StandardMaterial,
21
+ SpotLight,
22
+ Vector3,
23
+ CuboidMeshBuilder,
24
+ Affine3,
25
+ CanvasTarget,
26
+ SkyboxPlugin,
27
+ ShadowPlugin,
28
+ PCFShadowFilter,
29
+ PCSSShadowFilter,
30
+ SpotLightShadow,
31
+ CameraPlugin
32
+ } from "chorama"
33
+ import { GUI } from "dat.gui"
34
+ import { addRenderGraphGuiAddon } from "@examples/rendergraph_gui"
35
+
36
+ const canvas = document.createElement('canvas')
37
+ const renderTarget = new CanvasTarget(canvas)
38
+ const renderDevice = new WebGLRenderDevice(canvas,{
39
+ depth:true
40
+ })
41
+ const renderer = new WebGLRenderer({
42
+ plugins: [
43
+ new CameraPlugin(),
44
+ new ShadowPlugin(),
45
+ new LightPlugin(),
46
+ new SkyboxPlugin(),
47
+ new MeshMaterialPlugin(),
48
+ ]
49
+ })
50
+
51
+ // loaders
52
+ const textureLoader = new TextureLoader()
53
+
54
+ // assets
55
+ const environmentTexture = textureLoader.load({
56
+ paths: [
57
+ "/images/skybox/miramar_right.png",
58
+ "/images/skybox/miramar_left.png",
59
+ "/images/skybox/miramar_top.png",
60
+ "/images/skybox/miramar_bottom.png",
61
+ "/images/skybox/miramar_back.png",
62
+ "/images/skybox/miramar_front.png",
63
+ ],
64
+ type: TextureType.TextureCubeMap,
65
+ })
66
+ const texture = textureLoader.load({
67
+ paths: ["/images/uv.jpg"],
68
+ })
69
+ /**@type {[LambertMaterial, PhongMaterial, StandardMaterial]} */
70
+ const materials = [
71
+ new LambertMaterial({
72
+ mainTexture: texture
73
+ }),
74
+ new PhongMaterial({
75
+ mainTexture: texture
76
+ }),
77
+ new StandardMaterial({
78
+ mainTexture: texture,
79
+ roughness: 0.4,
80
+ metallic: 0
81
+ })
82
+ ]
83
+ const meshBuilder = new PlaneMeshBuilder()
84
+ const lightMeshBuilder = new CuboidMeshBuilder()
85
+ lightMeshBuilder.height = 0.01
86
+ lightMeshBuilder.width = 0.01
87
+ lightMeshBuilder.depth = 0.5
88
+ meshBuilder.width = 10
89
+ meshBuilder.height = 10
90
+
91
+ // objects
92
+ const camera = new Camera(renderTarget)
93
+ const cameraControls = new OrbitCameraControls(camera, canvas)
94
+
95
+ const ambientLight = new AmbientLight()
96
+
97
+ const shadow = new SpotLightShadow()
98
+ const shadowFilterSettings = {
99
+ mode: 'None',
100
+ get radius() {
101
+ return (shadow.filterMode instanceof PCFShadowFilter || shadow.filterMode instanceof PCSSShadowFilter)
102
+ ? shadow.filterMode.radius
103
+ : 1
104
+ },
105
+ set radius(value) {
106
+ if (shadow.filterMode instanceof PCFShadowFilter || shadow.filterMode instanceof PCSSShadowFilter) {
107
+ shadow.filterMode.radius = value
108
+ }
109
+ },
110
+ get searchRadius() {
111
+ return shadow.filterMode instanceof PCSSShadowFilter ? shadow.filterMode.searchRadius : 2
112
+ },
113
+ set searchRadius(value) {
114
+ if (shadow.filterMode instanceof PCSSShadowFilter) {
115
+ shadow.filterMode.searchRadius = value
116
+ }
117
+ },
118
+ get penumbra() {
119
+ return shadow.filterMode instanceof PCSSShadowFilter ? shadow.filterMode.penumbra : 1
120
+ },
121
+ set penumbra(value) {
122
+ if (shadow.filterMode instanceof PCSSShadowFilter) {
123
+ shadow.filterMode.penumbra = value
124
+ }
125
+ }
126
+ }
127
+ const light = new SpotLight()
128
+ const skyBox = new SkyBox({
129
+ day: environmentTexture
130
+ })
131
+ const ground = new MeshMaterial3D(meshBuilder.build(), materials[0])
132
+ const objects = createObjects()
133
+ const lightHelper = new MeshMaterial3D(lightMeshBuilder.build(), new BasicMaterial({
134
+ color: new Color(1, 0, 0)
135
+ }))
136
+
137
+ ambientLight.intensity = 0.15
138
+ skyBox.transform.orientation.rotateY(Math.PI)
139
+ light.intensity = 1
140
+ light.add(lightHelper)
141
+ light.transform.position.y = 1
142
+ light.range = 10
143
+ light.shadow = shadow
144
+ shadow.filterMode = undefined
145
+ ground.transform.orientation.rotateX(-Math.PI / 2)
146
+
147
+ //set up the camera
148
+ cameraControls.distance = 2
149
+ if (camera.projection instanceof PerspectiveProjection) {
150
+ camera.projection.fov = Math.PI / 180 * 75
151
+ camera.projection.aspect = innerWidth / innerHeight
152
+ }
153
+
154
+ document.body.append(canvas)
155
+ addEventListener("resize", updateView)
156
+ updateView()
157
+ requestAnimationFrame(update)
158
+
159
+ function createObjects() {
160
+ const results = []
161
+ const meshBuilder2 = new UVSphereMeshBuilder()
162
+ meshBuilder2.radius = 0.25
163
+ const sphereMesh = meshBuilder2.build()
164
+
165
+ for (let x = -5; x < 5; x++) {
166
+ for (let y = -5; y < 5; y++) {
167
+ const object = new MeshMaterial3D(sphereMesh, materials[0])
168
+
169
+ object.transform.position.x = x
170
+ object.transform.position.y = 0.5
171
+ object.transform.position.z = y
172
+ results.push(object)
173
+ }
174
+ }
175
+
176
+ return results
177
+ }
178
+
179
+ function update() {
180
+ cameraControls.update()
181
+ renderer.render([ground, ...objects, light, ambientLight, skyBox, camera], renderDevice)
182
+ requestAnimationFrame(update)
183
+ }
184
+
185
+ function updateView() {
186
+ canvas.style.width = innerWidth + "px"
187
+ canvas.style.height = innerHeight + "px"
188
+ canvas.width = innerWidth * devicePixelRatio
189
+ canvas.height = innerHeight * devicePixelRatio
190
+
191
+ if (camera.projection instanceof PerspectiveProjection) {
192
+ camera.projection.aspect = innerWidth / innerHeight
193
+ }
194
+ }
195
+
196
+ // gui controls
197
+ const options = [
198
+ 'LAMBERT',
199
+ 'PHONG',
200
+ 'STANDARD'
201
+ ]
202
+ const settings = {
203
+ position: new Vector3(),
204
+ color: {
205
+ r: 0,
206
+ g: 0,
207
+ b: 0
208
+ },
209
+ material: options[0],
210
+ shadow: true
211
+ }
212
+ const controls = new GUI()
213
+ const lightFolder = controls.addFolder("Light")
214
+ const shadowFolder = controls.addFolder("Shadow")
215
+ /**
216
+ * @type {import("dat.gui").GUIController<object>}
217
+ */
218
+ let shadowRadiusControl
219
+ /** @type {import("dat.gui").GUIController<object>} */
220
+ let shadowSearchRadiusControl
221
+ /** @type {import("dat.gui").GUIController<object>} */
222
+ let shadowPenumbraControl
223
+ lightFolder
224
+ .add(light.transform.position, 'x', -10, 10)
225
+ .name("Translate X")
226
+ lightFolder
227
+ .add(light.transform.position, 'y', 0, 2)
228
+ .name("Translate Y")
229
+ lightFolder
230
+ .add(light.transform.position, 'z', -10, 10)
231
+ .name("Translate Z")
232
+ lightFolder
233
+ .add(settings.position, 'x', -1, 1)
234
+ .name("Direction X")
235
+ .onChange(setOrientation)
236
+ lightFolder
237
+ .add(settings.position, 'y', -1, 1)
238
+ .name("Direction Y")
239
+ .onChange(setOrientation)
240
+ lightFolder
241
+ .add(settings.position, 'z', -1, 1)
242
+ .name("Direction Z")
243
+ .onChange(setOrientation)
244
+ lightFolder
245
+ .add(light, 'intensity', 0, 100)
246
+ .name("Intensity")
247
+ lightFolder
248
+ .add(light, 'innerAngle', 0, Math.PI / 2)
249
+ .name("Inner Angle")
250
+ lightFolder
251
+ .add(light, 'outerAngle', 0, Math.PI / 2)
252
+ .name("Outer Angle")
253
+ lightFolder
254
+ .add(light, 'range', 0, 10)
255
+ .name("Range")
256
+ lightFolder
257
+ .add(light, 'decay', 0, 100)
258
+ .name("Distance Decay")
259
+ lightFolder
260
+ .add(settings, 'material', options)
261
+ .name("Material")
262
+ .onChange(changeMaterial)
263
+ lightFolder
264
+ .addColor(settings, 'color')
265
+ .name('Color')
266
+ .onChange((value) => {
267
+ light.color.set(
268
+ value.r / 255,
269
+ value.g / 255,
270
+ value.b / 255
271
+ )
272
+ })
273
+ shadowFolder
274
+ .add(settings, 'shadow')
275
+ .name("Enable Shadow")
276
+ .onChange(toggleShadows)
277
+ shadowFolder
278
+ .add(shadow, 'near', 0.1, 1)
279
+ .name('Near')
280
+ shadowFolder
281
+ .add(shadow, 'bias', 0, 0.01)
282
+ .name('Bias')
283
+ shadowFolder
284
+ .add(shadow, 'normalBias', 0, 0.005)
285
+ .name('Normal Bias')
286
+ shadowFolder
287
+ .add(shadowFilterSettings, 'mode', ['None', 'PCF', 'PCSS'])
288
+ .name('Shadow Filter')
289
+ .onChange(updateShadowFilterMode)
290
+ shadowRadiusControl = shadowFolder
291
+ .add(shadowFilterSettings, 'radius', 0, 4, 0.1)
292
+ .name('PCF Radius')
293
+ shadowSearchRadiusControl = shadowFolder
294
+ .add(shadowFilterSettings, 'searchRadius', 0, 8, 0.1)
295
+ .name('PCSS Search Radius')
296
+ shadowPenumbraControl = shadowFolder
297
+ .add(shadowFilterSettings, 'penumbra', 0, 6, 0.1)
298
+ .name('PCSS Penumbra')
299
+ updateShadowFilterControls()
300
+ lightFolder.open()
301
+ shadowFolder.open()
302
+ /**
303
+ * @param {string} value
304
+ */
305
+ function changeMaterial(value) {
306
+ switch (value) {
307
+ case options[0]:
308
+ objects.forEach((o) => o.material = materials[0])
309
+ ground.material = materials[0]
310
+ break;
311
+ case options[1]:
312
+ objects.forEach((o) => o.material = materials[1])
313
+ ground.material = materials[1]
314
+ break;
315
+ case options[2]:
316
+ objects.forEach((o) => o.material = materials[2])
317
+ ground.material = materials[2]
318
+ break;
319
+ default:
320
+ break;
321
+ }
322
+ }
323
+
324
+ function setOrientation() {
325
+ const transform = Affine3.lookAt(settings.position.normalize(), Vector3.Zero, Vector3.Y)
326
+ const [_, orientation] = transform.decompose()
327
+ light.transform.orientation.copy(orientation)
328
+ }
329
+
330
+ /**
331
+ * @param {boolean} value
332
+ */
333
+ function toggleShadows(value) {
334
+ if (value) {
335
+ light.shadow = shadow
336
+ } else {
337
+ light.shadow = undefined
338
+ }
339
+ }
340
+
341
+ function updateShadowFilterControls() {
342
+ const isPCF = shadow.filterMode instanceof PCFShadowFilter
343
+ const isPCSS = shadow.filterMode instanceof PCSSShadowFilter
344
+ shadowRadiusControl.domElement.style.display = (isPCF || isPCSS) ? '' : 'none'
345
+ shadowSearchRadiusControl.domElement.style.display = isPCSS ? '' : 'none'
346
+ shadowPenumbraControl.domElement.style.display = isPCSS ? '' : 'none'
347
+ }
348
+
349
+ /**
350
+ * @param {string} value
351
+ */
352
+ function updateShadowFilterMode(value) {
353
+ if (value === 'PCF') {
354
+ shadow.filterMode = new PCFShadowFilter()
355
+ } else if (value === 'PCSS') {
356
+ shadow.filterMode = new PCSSShadowFilter()
357
+ } else {
358
+ shadow.filterMode = undefined
359
+ }
360
+ updateShadowFilterControls()
361
+ }
362
+
363
+ addRenderGraphGuiAddon({
364
+ gui: controls,
365
+ renderer
366
+ })
@@ -0,0 +1,111 @@
1
+ import Stats from "stats.js";
2
+ import {
3
+ WebGLRenderer,
4
+ PerspectiveProjection,
5
+ GLTFLoader,
6
+ Camera,
7
+ WebGLRenderDevice,
8
+ MeshMaterialPlugin,
9
+ OrbitCameraControls,
10
+ TextureType,
11
+ SkyBox,
12
+ TextureLoader,
13
+ DirectionalLight,
14
+ LightPlugin,
15
+ AmbientLight,
16
+ CanvasTarget,
17
+ SkyboxPlugin,
18
+ CameraPlugin
19
+ } from 'chorama';
20
+
21
+ // performance monitor
22
+ const stats = new Stats()
23
+ stats.showPanel(1)
24
+ document.body.append(stats.dom)
25
+ stats.dom.removeAttribute('style')
26
+ stats.dom.classList.add('performance-monitor')
27
+
28
+ const canvas = document.createElement('canvas')
29
+ const renderTarget = new CanvasTarget(canvas)
30
+ const renderDevice = new WebGLRenderDevice(canvas,{
31
+ depth:true
32
+ })
33
+ const renderer = new WebGLRenderer({
34
+ plugins: [
35
+ new CameraPlugin(),
36
+ new LightPlugin(),
37
+ new SkyboxPlugin(),
38
+ new MeshMaterialPlugin(),
39
+ ]
40
+ })
41
+
42
+ // lighting
43
+ const ambientLight = new AmbientLight()
44
+ const directionalLight = new DirectionalLight()
45
+
46
+ directionalLight.transform.orientation
47
+ .rotateX(-Math.PI / 4)
48
+ .rotateZ(-Math.PI / 4)
49
+ directionalLight.intensity = 30
50
+ ambientLight.intensity = 0.15
51
+
52
+ // camera and camera controls
53
+ const camera = new Camera(renderTarget)
54
+ const cameraControls = new OrbitCameraControls(camera, canvas)
55
+ document.body.append(canvas)
56
+ updateView()
57
+
58
+ const textureLoader = new TextureLoader()
59
+ const gltfLoader = new GLTFLoader()
60
+
61
+ const day = textureLoader.load({
62
+ paths: [
63
+ "/images/skybox/miramar_right.png",
64
+ "/images/skybox/miramar_left.png",
65
+ "/images/skybox/miramar_top.png",
66
+ "/images/skybox/miramar_bottom.png",
67
+ "/images/skybox/miramar_back.png",
68
+ "/images/skybox/miramar_front.png",
69
+ ],
70
+ type: TextureType.TextureCubeMap,
71
+ })
72
+ const skyBox = new SkyBox({
73
+ day
74
+ })
75
+ skyBox.transform.orientation.rotateY(Math.PI)
76
+
77
+ // The gltf model
78
+ const model = gltfLoader.load({
79
+ paths: ["/models/gltf/flight_helmet/index.gltf"]
80
+ })
81
+
82
+ cameraControls.distance = 0.8
83
+ cameraControls.offset.y = 0.5
84
+ if (camera.projection instanceof PerspectiveProjection) {
85
+ camera.projection.fov = Math.PI / 180 * 75
86
+ camera.projection.aspect = innerWidth / innerHeight
87
+ }
88
+
89
+ document.body.append(canvas)
90
+ updateView()
91
+ addEventListener("resize", updateView)
92
+ requestAnimationFrame(update)
93
+
94
+ function update() {
95
+ stats.begin()
96
+ renderer.render([model, skyBox, ambientLight, directionalLight, camera], renderDevice)
97
+ cameraControls.update()
98
+ stats.end()
99
+ requestAnimationFrame(update)
100
+ }
101
+
102
+ function updateView() {
103
+ canvas.style.width = innerWidth + "px"
104
+ canvas.style.height = innerHeight + "px"
105
+ canvas.width = innerWidth * devicePixelRatio
106
+ canvas.height = innerHeight * devicePixelRatio
107
+
108
+ if (camera.projection instanceof PerspectiveProjection) {
109
+ camera.projection.aspect = innerWidth / innerHeight
110
+ }
111
+ }
@@ -0,0 +1,78 @@
1
+ import Stats from "stats.js";
2
+ import {
3
+ WebGLRenderer,
4
+ PerspectiveProjection,
5
+ GLTFLoader,
6
+ Camera,
7
+ Quaternion,
8
+ WebGLRenderDevice,
9
+ MeshMaterialPlugin,
10
+ AmbientLight,
11
+ LightPlugin,
12
+ CanvasTarget,
13
+ CameraPlugin
14
+ } from 'chorama';
15
+
16
+ // performance monitor
17
+ const stats = new Stats()
18
+ stats.showPanel(1)
19
+ document.body.append(stats.dom)
20
+ stats.dom.removeAttribute('style')
21
+ stats.dom.classList.add('performance-monitor')
22
+
23
+ const canvas = document.createElement('canvas')
24
+ const renderTarget = new CanvasTarget(canvas)
25
+ const renderDevice = new WebGLRenderDevice(canvas,{
26
+ depth:true
27
+ })
28
+ const renderer = new WebGLRenderer({
29
+ plugins:[
30
+ new CameraPlugin(),
31
+ new LightPlugin(),
32
+ new MeshMaterialPlugin(),
33
+ ]
34
+ })
35
+ const camera = new Camera(renderTarget)
36
+
37
+ // lights
38
+ const ambientLight = new AmbientLight()
39
+ document.body.append(canvas)
40
+ updateView()
41
+
42
+ const loader = new GLTFLoader()
43
+ const model = loader.load({
44
+ paths: ["/models/gltf/pirate_girl/index.gltf"]
45
+ })
46
+
47
+ camera.transform.position.z = 2
48
+ camera.transform.position.y = 2
49
+ if (camera.projection instanceof PerspectiveProjection) {
50
+ camera.projection.fov = Math.PI / 180 * 120
51
+ camera.projection.aspect = innerWidth / innerHeight
52
+ }
53
+
54
+ const rotation = Quaternion.fromEuler(0, Math.PI / 1000, 0)
55
+
56
+ document.body.append(canvas)
57
+ updateView()
58
+ addEventListener("resize", updateView)
59
+ requestAnimationFrame(update)
60
+
61
+ function update() {
62
+ stats.begin()
63
+ model.transform.orientation.multiply(rotation)
64
+ renderer.render([model, ambientLight, camera], renderDevice)
65
+ stats.end()
66
+ requestAnimationFrame(update)
67
+ }
68
+
69
+ function updateView() {
70
+ canvas.style.width = innerWidth + "px"
71
+ canvas.style.height = innerHeight + "px"
72
+ canvas.width = innerWidth * devicePixelRatio
73
+ canvas.height = innerHeight * devicePixelRatio
74
+
75
+ if (camera.projection instanceof PerspectiveProjection) {
76
+ camera.projection.aspect = innerWidth / innerHeight
77
+ }
78
+ }
@@ -0,0 +1,95 @@
1
+ import Stats from "stats.js";
2
+ import {
3
+ OBJLoader,
4
+ BasicMaterial,
5
+ WebGLRenderer,
6
+ TextureLoader,
7
+ PerspectiveProjection,
8
+ Camera,
9
+ Quaternion,
10
+ MeshMaterial3D,
11
+ LambertMaterial,
12
+ PhongMaterial,
13
+ WebGLRenderDevice,
14
+ MeshMaterialPlugin,
15
+ CanvasTarget,
16
+ CameraPlugin
17
+ } from 'chorama';
18
+
19
+ // performance monitor
20
+ const stats = new Stats()
21
+ stats.showPanel(1)
22
+ document.body.append(stats.dom)
23
+ stats.dom.removeAttribute('style')
24
+ stats.dom.classList.add('performance-monitor')
25
+
26
+ const canvas = document.createElement('canvas')
27
+ const renderTarget = new CanvasTarget(canvas)
28
+ const renderDevice = new WebGLRenderDevice(canvas,{
29
+ depth:true
30
+ })
31
+ const renderer = new WebGLRenderer({
32
+ plugins:[
33
+ new CameraPlugin(),
34
+ new MeshMaterialPlugin(),
35
+ ]
36
+ })
37
+ const camera = new Camera(renderTarget)
38
+ const textureLoader = new TextureLoader()
39
+ const loader = new OBJLoader()
40
+ const texture = textureLoader.load({
41
+ paths: ["/models/obj/pirate_girl/pirate_girl.png"],
42
+ textureSettings:{
43
+ flipY:true
44
+ }
45
+ })
46
+ const model = loader.load({
47
+ paths: ["/models/obj/pirate_girl/pirate_girl.obj"],
48
+ postprocessor:(asset)=>{
49
+ asset.traverseDFS((object)=>{
50
+ if (object instanceof MeshMaterial3D) {
51
+ if(
52
+ object.material instanceof BasicMaterial ||
53
+ object.material instanceof LambertMaterial ||
54
+ object.material instanceof PhongMaterial
55
+ ){
56
+ object.material.mainTexture = texture
57
+ }
58
+ }
59
+ return true
60
+ })
61
+ }
62
+ })
63
+ camera.transform.position.z = 2
64
+ camera.transform.position.y = 2
65
+ if (camera.projection instanceof PerspectiveProjection) {
66
+ camera.projection.fov = Math.PI / 180 * 120
67
+ camera.projection.aspect = innerWidth / innerHeight
68
+ }
69
+
70
+ const rotation = Quaternion.fromEuler(0, Math.PI / 1000, 0)
71
+
72
+ document.body.append(canvas)
73
+ updateView()
74
+ addEventListener("resize", updateView)
75
+ requestAnimationFrame(update)
76
+
77
+ function update() {
78
+ stats.begin()
79
+ model.transform.orientation.multiply(rotation)
80
+ renderer.render([model, camera], renderDevice)
81
+ stats.end()
82
+
83
+ requestAnimationFrame(update)
84
+ }
85
+
86
+ function updateView() {
87
+ canvas.style.width = innerWidth + "px"
88
+ canvas.style.height = innerHeight + "px"
89
+ canvas.width = innerWidth * devicePixelRatio
90
+ canvas.height = innerHeight * devicePixelRatio
91
+
92
+ if (camera.projection instanceof PerspectiveProjection) {
93
+ camera.projection.aspect = innerWidth / innerHeight
94
+ }
95
+ }