@needle-tools/engine 2.66.1-pre → 2.67.0-pre

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 (230) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/needle-engine.js +34306 -26230
  3. package/dist/needle-engine.umd.cjs +743 -298
  4. package/lib/engine/api.d.ts +4 -0
  5. package/lib/engine/api.js +10 -0
  6. package/lib/engine/api.js.map +1 -1
  7. package/lib/engine/codegen/register_types.js +23 -7
  8. package/lib/engine/codegen/register_types.js.map +1 -1
  9. package/lib/engine/debug/debug_overlay.js +7 -1
  10. package/lib/engine/debug/debug_overlay.js.map +1 -1
  11. package/lib/engine/engine_addressables.js +2 -2
  12. package/lib/engine/engine_addressables.js.map +1 -1
  13. package/lib/engine/engine_assetdatabase.d.ts +17 -51
  14. package/lib/engine/engine_assetdatabase.js +252 -126
  15. package/lib/engine/engine_assetdatabase.js.map +1 -1
  16. package/lib/engine/engine_components.js +13 -1
  17. package/lib/engine/engine_components.js.map +1 -1
  18. package/lib/engine/engine_components_internal.d.ts +8 -0
  19. package/lib/engine/engine_components_internal.js +29 -0
  20. package/lib/engine/engine_components_internal.js.map +1 -0
  21. package/lib/engine/engine_constants.d.ts +1 -0
  22. package/lib/engine/engine_constants.js +1 -0
  23. package/lib/engine/engine_constants.js.map +1 -1
  24. package/lib/engine/engine_context_registry.d.ts +2 -0
  25. package/lib/engine/engine_context_registry.js +6 -0
  26. package/lib/engine/engine_context_registry.js.map +1 -1
  27. package/lib/engine/engine_editor-sync.d.ts +9 -0
  28. package/lib/engine/engine_editor-sync.js +8 -0
  29. package/lib/engine/engine_editor-sync.js.map +1 -0
  30. package/lib/engine/engine_element_loading.js +1 -1
  31. package/lib/engine/engine_element_loading.js.map +1 -1
  32. package/lib/engine/engine_gameobject.js +15 -20
  33. package/lib/engine/engine_gameobject.js.map +1 -1
  34. package/lib/engine/engine_gltf_builtin_components.d.ts +2 -3
  35. package/lib/engine/engine_gltf_builtin_components.js +23 -6
  36. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  37. package/lib/engine/engine_networking_auto.d.ts +1 -0
  38. package/lib/engine/engine_networking_auto.js +42 -9
  39. package/lib/engine/engine_networking_auto.js.map +1 -1
  40. package/lib/engine/engine_patcher.d.ts +8 -0
  41. package/lib/engine/engine_patcher.js +98 -0
  42. package/lib/engine/engine_patcher.js.map +1 -0
  43. package/lib/engine/engine_physics.d.ts +5 -1
  44. package/lib/engine/engine_physics.js +11 -1
  45. package/lib/engine/engine_physics.js.map +1 -1
  46. package/lib/engine/engine_scenetools.js +0 -1
  47. package/lib/engine/engine_scenetools.js.map +1 -1
  48. package/lib/engine/engine_serialization_core.js +4 -0
  49. package/lib/engine/engine_serialization_core.js.map +1 -1
  50. package/lib/engine/engine_setup.d.ts +1 -1
  51. package/lib/engine/engine_setup.js +9 -5
  52. package/lib/engine/engine_setup.js.map +1 -1
  53. package/lib/engine/engine_texture.d.ts +6 -1
  54. package/lib/engine/engine_texture.js +39 -1
  55. package/lib/engine/engine_texture.js.map +1 -1
  56. package/lib/engine/engine_types.d.ts +4 -0
  57. package/lib/engine/engine_types.js.map +1 -1
  58. package/lib/engine/engine_utils.js +3 -2
  59. package/lib/engine/engine_utils.js.map +1 -1
  60. package/lib/engine/extensions/NEEDLE_progressive.d.ts +0 -1
  61. package/lib/engine/extensions/NEEDLE_progressive.js +24 -26
  62. package/lib/engine/extensions/NEEDLE_progressive.js.map +1 -1
  63. package/lib/engine/extensions/extensions.d.ts +4 -1
  64. package/lib/engine/extensions/extensions.js +16 -0
  65. package/lib/engine/extensions/extensions.js.map +1 -1
  66. package/lib/engine/extensions/usage_tracker.d.ts +12 -0
  67. package/lib/engine/extensions/usage_tracker.js +59 -0
  68. package/lib/engine/extensions/usage_tracker.js.map +1 -0
  69. package/lib/engine-components/AnimatorController.js +4 -0
  70. package/lib/engine-components/AnimatorController.js.map +1 -1
  71. package/lib/engine-components/AudioSource.js +2 -1
  72. package/lib/engine-components/AudioSource.js.map +1 -1
  73. package/lib/engine-components/Camera.d.ts +6 -0
  74. package/lib/engine-components/Camera.js +70 -31
  75. package/lib/engine-components/Camera.js.map +1 -1
  76. package/lib/engine-components/Component.d.ts +52 -0
  77. package/lib/engine-components/Component.js +55 -14
  78. package/lib/engine-components/Component.js.map +1 -1
  79. package/lib/engine-components/Networking.js +19 -0
  80. package/lib/engine-components/Networking.js.map +1 -1
  81. package/lib/engine-components/OrbitControls.d.ts +2 -0
  82. package/lib/engine-components/OrbitControls.js +9 -0
  83. package/lib/engine-components/OrbitControls.js.map +1 -1
  84. package/lib/engine-components/ParticleSystem.js +11 -1
  85. package/lib/engine-components/ParticleSystem.js.map +1 -1
  86. package/lib/engine-components/ReflectionProbe.js +18 -6
  87. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  88. package/lib/engine-components/Renderer.d.ts +1 -1
  89. package/lib/engine-components/Renderer.js +24 -6
  90. package/lib/engine-components/Renderer.js.map +1 -1
  91. package/lib/engine-components/Skybox.js +2 -0
  92. package/lib/engine-components/Skybox.js.map +1 -1
  93. package/lib/engine-components/SmoothFollow.js +1 -2
  94. package/lib/engine-components/SmoothFollow.js.map +1 -1
  95. package/lib/engine-components/WebARCameraBackground.d.ts +19 -0
  96. package/lib/engine-components/WebARCameraBackground.js +185 -0
  97. package/lib/engine-components/WebARCameraBackground.js.map +1 -0
  98. package/lib/engine-components/WebXR.d.ts +4 -0
  99. package/lib/engine-components/WebXR.js +11 -8
  100. package/lib/engine-components/WebXR.js.map +1 -1
  101. package/lib/engine-components/WebXRAvatar.js +1 -0
  102. package/lib/engine-components/WebXRAvatar.js.map +1 -1
  103. package/lib/engine-components/codegen/components.d.ts +14 -6
  104. package/lib/engine-components/codegen/components.js +14 -6
  105. package/lib/engine-components/codegen/components.js.map +1 -1
  106. package/lib/engine-components/js-extensions/Object3D.js +4 -1
  107. package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
  108. package/lib/engine-components/postprocessing/Effects/Antialiasing.d.ts +13 -0
  109. package/lib/engine-components/postprocessing/Effects/Antialiasing.js +46 -0
  110. package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -0
  111. package/lib/engine-components/postprocessing/Effects/Bloom.d.ts +12 -0
  112. package/lib/engine-components/postprocessing/Effects/Bloom.js +76 -0
  113. package/lib/engine-components/postprocessing/Effects/Bloom.js.map +1 -0
  114. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.d.ts +8 -0
  115. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js +39 -0
  116. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -0
  117. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +12 -0
  118. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +96 -0
  119. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -0
  120. package/lib/engine-components/postprocessing/Effects/DepthOfField.d.ts +21 -0
  121. package/lib/engine-components/postprocessing/Effects/DepthOfField.js +87 -0
  122. package/lib/engine-components/postprocessing/Effects/DepthOfField.js.map +1 -0
  123. package/lib/engine-components/postprocessing/Effects/Pixelation.d.ts +7 -0
  124. package/lib/engine-components/postprocessing/Effects/Pixelation.js +30 -0
  125. package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -0
  126. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.d.ts +11 -0
  127. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js +70 -0
  128. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js.map +1 -0
  129. package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +16 -0
  130. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +52 -0
  131. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -0
  132. package/lib/engine-components/postprocessing/Effects/Vignette.d.ts +11 -0
  133. package/lib/engine-components/postprocessing/Effects/Vignette.js +57 -0
  134. package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -0
  135. package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +29 -0
  136. package/lib/engine-components/postprocessing/PostProcessingEffect.js +89 -0
  137. package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -0
  138. package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +13 -0
  139. package/lib/engine-components/postprocessing/PostProcessingHandler.js +119 -0
  140. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -0
  141. package/lib/engine-components/postprocessing/Volume.d.ts +23 -0
  142. package/lib/engine-components/postprocessing/Volume.js +176 -0
  143. package/lib/engine-components/postprocessing/Volume.js.map +1 -0
  144. package/lib/engine-components/postprocessing/VolumeParameter.d.ts +21 -0
  145. package/lib/engine-components/postprocessing/VolumeParameter.js +75 -0
  146. package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -0
  147. package/lib/engine-components/postprocessing/VolumeProfile.d.ts +7 -0
  148. package/lib/engine-components/postprocessing/VolumeProfile.js +42 -0
  149. package/lib/engine-components/postprocessing/VolumeProfile.js.map +1 -0
  150. package/lib/engine-components/timeline/TimelineTracks.js +14 -15
  151. package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
  152. package/lib/engine-components/ui/Text.js +28 -170
  153. package/lib/engine-components/ui/Text.js.map +1 -1
  154. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +18 -0
  155. package/lib/engine-components-experimental/networking/PlayerSync.js +61 -7
  156. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  157. package/lib/include/three/ARButton.d.ts +1 -1
  158. package/lib/include/three/ARButton.js +11 -19
  159. package/lib/include/three/ARButton.js.map +1 -1
  160. package/lib/include/three/VRButton.js +1 -4
  161. package/lib/include/three/VRButton.js.map +1 -1
  162. package/package.json +3 -2
  163. package/plugins/vite/drop-client.js +77 -0
  164. package/plugins/vite/drop.js +81 -0
  165. package/plugins/vite/editor-connection.js +121 -0
  166. package/plugins/vite/index.js +9 -4
  167. package/src/engine/api.ts +30 -1
  168. package/src/engine/codegen/register_types.js +25 -9
  169. package/src/engine/debug/debug_overlay.ts +7 -1
  170. package/src/engine/engine_addressables.ts +2 -2
  171. package/src/engine/engine_assetdatabase.ts +291 -184
  172. package/src/engine/engine_components.ts +20 -1
  173. package/src/engine/engine_components_internal.ts +30 -0
  174. package/src/engine/engine_constants.ts +4 -1
  175. package/src/engine/engine_context_registry.ts +7 -0
  176. package/src/engine/engine_editor-sync.ts +21 -0
  177. package/src/engine/engine_element_loading.ts +1 -1
  178. package/src/engine/engine_gameobject.ts +16 -21
  179. package/src/engine/engine_gltf_builtin_components.ts +30 -15
  180. package/src/engine/engine_networking_auto.ts +48 -11
  181. package/src/engine/engine_patcher.ts +113 -0
  182. package/src/engine/engine_physics.ts +15 -2
  183. package/src/engine/engine_scenetools.ts +0 -1
  184. package/src/engine/engine_serialization_core.ts +6 -0
  185. package/src/engine/engine_setup.ts +11 -5
  186. package/src/engine/engine_texture.ts +54 -5
  187. package/src/engine/engine_types.ts +6 -1
  188. package/src/engine/engine_utils.ts +6 -5
  189. package/src/engine/extensions/NEEDLE_progressive.ts +32 -32
  190. package/src/engine/extensions/extensions.ts +22 -1
  191. package/src/engine/extensions/usage_tracker.ts +91 -0
  192. package/src/engine-components/AnimatorController.ts +2 -0
  193. package/src/engine-components/AudioSource.ts +1 -1
  194. package/src/engine-components/Camera.ts +77 -37
  195. package/src/engine-components/Component.ts +74 -30
  196. package/src/engine-components/Networking.ts +9 -1
  197. package/src/engine-components/OrbitControls.ts +11 -2
  198. package/src/engine-components/ParticleSystem.ts +9 -1
  199. package/src/engine-components/ReflectionProbe.ts +17 -7
  200. package/src/engine-components/Renderer.ts +22 -5
  201. package/src/engine-components/Skybox.ts +2 -0
  202. package/src/engine-components/SmoothFollow.ts +4 -4
  203. package/src/engine-components/WebARCameraBackground.ts +215 -0
  204. package/src/engine-components/WebXR.ts +12 -8
  205. package/src/engine-components/WebXRAvatar.ts +1 -0
  206. package/src/engine-components/codegen/components.ts +14 -6
  207. package/src/engine-components/js-extensions/Object3D.ts +6 -1
  208. package/src/engine-components/postprocessing/Effects/Antialiasing.ts +52 -0
  209. package/src/engine-components/postprocessing/Effects/Bloom.ts +75 -0
  210. package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +36 -0
  211. package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +114 -0
  212. package/src/engine-components/postprocessing/Effects/DepthOfField.ts +90 -0
  213. package/src/engine-components/postprocessing/Effects/Pixelation.ts +28 -0
  214. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +71 -0
  215. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +55 -0
  216. package/src/engine-components/postprocessing/Effects/Vignette.ts +55 -0
  217. package/src/engine-components/postprocessing/PostProcessingEffect.ts +112 -0
  218. package/src/engine-components/postprocessing/PostProcessingHandler.ts +148 -0
  219. package/src/engine-components/postprocessing/Volume.ts +194 -0
  220. package/src/engine-components/postprocessing/VolumeParameter.ts +85 -0
  221. package/src/engine-components/postprocessing/VolumeProfile.ts +40 -0
  222. package/src/engine-components/timeline/TimelineTracks.ts +16 -17
  223. package/src/engine-components/ui/Text.ts +37 -174
  224. package/src/engine-components-experimental/networking/PlayerSync.ts +68 -7
  225. package/src/include/three/ARButton.js +13 -24
  226. package/src/include/three/VRButton.js +1 -7
  227. package/lib/engine-components/Volume.d.ts +0 -34
  228. package/lib/engine-components/Volume.js +0 -140
  229. package/lib/engine-components/Volume.js.map +0 -1
  230. package/src/engine-components/Volume.ts +0 -141
@@ -0,0 +1,215 @@
1
+ import { Behaviour } from "./Component";
2
+ import { serializable } from "../engine/engine_serialization_decorator";
3
+ import { RGBAColor } from "../engine-components/js-extensions/RGBAColor"
4
+ import { WebXR } from "../engine-components/WebXR";
5
+ import {
6
+ Camera as ThreeCamera,
7
+ Scene,
8
+ Texture,
9
+ Mesh, MeshBasicMaterial,
10
+ UniformsUtils,
11
+ PlaneGeometry,
12
+ ShaderLib,
13
+ ShaderMaterial,
14
+ DoubleSide
15
+ } from "three";
16
+
17
+ export class WebARCameraBackground extends Behaviour {
18
+
19
+ awake(): void {
20
+ WebXR.OptionalFeatures_AR.push('camera-access');
21
+ }
22
+
23
+ @serializable()
24
+ public backgroundTint: RGBAColor = new RGBAColor(1,1,1,1);
25
+
26
+ public get background() {
27
+ return this.backgroundPlane;
28
+ }
29
+
30
+ private _preRender;
31
+
32
+ onEnable(): void {
33
+ this._preRender = this.preRender.bind(this);
34
+ this.context.pre_render_callbacks.push(this._preRender);
35
+
36
+ if (this.backgroundPlane) {
37
+ this.gameObject.add(this.backgroundPlane);
38
+ this.backgroundPlane.visible = false;
39
+ }
40
+ }
41
+
42
+ onDisable(): void {
43
+ this.context.pre_render_callbacks = this.context.pre_render_callbacks.filter(cb => cb !== this._preRender);
44
+
45
+ if (this.backgroundPlane)
46
+ this.gameObject.remove(this.backgroundPlane);
47
+ }
48
+
49
+ private backgroundPlane?: Mesh;
50
+ private threeTexture?: Texture;
51
+ private forceTextureInitialization = function() {
52
+ const material = new MeshBasicMaterial();
53
+ const geometry = new PlaneGeometry();
54
+ const scene = new Scene();
55
+ scene.add(new Mesh(geometry, material));
56
+ const camera = new ThreeCamera();
57
+
58
+ return function forceTextureInitialization(renderer, texture) {
59
+ material.map = texture;
60
+ renderer.render(scene, camera);
61
+ };
62
+ }();
63
+
64
+ // TODO should only attach on session start, and detach on session end
65
+ private preRender() {
66
+ if (!this || !this.gameObject) return;
67
+
68
+ const xr = this.context.renderer.xr;
69
+ const frame = xr.getFrame();
70
+
71
+ if (frame) {
72
+
73
+ // We're generating a new texture here, and force three to initialize it
74
+ // from https://stackoverflow.com/a/55084367 to inject a custom texture into three.js
75
+ if (!this.threeTexture && this.context.renderer) {
76
+ this.threeTexture = new Texture();
77
+ // this.threeTexture.encoding = LinearEncoding;
78
+ this.forceTextureInitialization(this.context.renderer, this.threeTexture);
79
+ }
80
+
81
+ // simple mesh and fullscreen shader to display the camera texture
82
+ // from three: WebGLBackground
83
+ if (this.backgroundPlane === undefined) {
84
+ this.backgroundPlane = makeFullscreenPlane(this.backgroundTint);
85
+ this.gameObject.add(this.backgroundPlane);
86
+ }
87
+
88
+ // WebXR Raw Camera Access -
89
+ // we composite the camera texture into the scene background by rendering it first.
90
+ this.updateFromFrame(frame);
91
+ }
92
+
93
+ /*
94
+ if (this.planeMesh) {
95
+ this.planeMesh.visible = frame != null;
96
+ }
97
+ */
98
+ }
99
+
100
+ onBeforeRender(frame: XRFrame | null) {
101
+ this.updateFromFrame(frame);
102
+ }
103
+
104
+ updateFromFrame(frame: XRFrame | null) {
105
+ if (!frame) return;
106
+
107
+ // https://chromium.googlesource.com/chromium/src/+/7c5ac3c0f95b97cf12be95a5c1c0a8ff163246d8/third_party/webxr_test_pages/webxr-samples/proposals/camera-access-barebones.html
108
+ const pose = frame.getViewerPose(this.context.renderer.xr.getReferenceSpace()!);
109
+ if (pose) {
110
+ for( const view of pose.views) {
111
+ // @ts-ignore
112
+ if ('camera' in view && view.camera) {
113
+ const xrManager = this.context.renderer.xr;
114
+ let binding = xrManager.getBinding();
115
+ // not sure how / why this can be null, but we can recreate it here
116
+ if (!binding) binding = new XRWebGLBinding( frame.session, this.context.renderer.getContext() );
117
+
118
+ if (binding) {
119
+ let glImage: WebGLTexture | null = null;
120
+ if ('getCameraImage' in binding) {
121
+ // @ts-ignore
122
+ glImage = binding.getCameraImage(view.camera);
123
+
124
+ // discussion on exactly this:
125
+ // https://discourse.threejs.org/t/using-a-webgltexture-as-texture-for-three-js/46245/8
126
+ // HACK from https://stackoverflow.com/a/55084367 to inject a custom texture into three.js
127
+ const texProps = this.context.renderer.properties.get(this.threeTexture);
128
+ texProps.__webglTexture = glImage;
129
+
130
+ if (this.backgroundPlane) {
131
+ //@ts-ignore
132
+ this.backgroundPlane.setTexture(this.threeTexture);
133
+ this.backgroundPlane.visible = true;
134
+ }
135
+ }
136
+ }
137
+ else {
138
+ // console.error(view.camera, xrManager)
139
+ }
140
+ }
141
+ else {
142
+ // console.error("NO CAMERA IN VIEW")
143
+ }
144
+ }
145
+ }
146
+ else {
147
+ // console.error(this.context.renderer.xr.getReferenceSpace(), frame);
148
+ }
149
+ }
150
+ }
151
+ // TODO tint could be an uniform
152
+ let backgroundFragment: string = /* glsl */`
153
+ uniform sampler2D t2D;
154
+
155
+ varying vec2 vUv;
156
+
157
+ void main() {
158
+
159
+ vec4 texColor = texture2D( t2D, vUv );
160
+ texColor.w = 1.0;
161
+
162
+ // inline sRGB decode
163
+ texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
164
+
165
+ gl_FragColor = texColor * <backgroundTint>;
166
+
167
+ #include <tonemapping_fragment>
168
+ #include <encodings_fragment>
169
+
170
+ }
171
+ `;
172
+
173
+ // not sure where we want to move this and in which form is best (extends Object3D?)
174
+ export function makeFullscreenPlane(tint: RGBAColor ) {
175
+ const replacementTint = "vec4(" + tint.r.toFixed(3) + "," + tint.g.toFixed(3) + "," + tint.b.toFixed(3) + "," + tint.a.toFixed(3) + ")";
176
+ console.log(replacementTint);
177
+ const planeMesh = new Mesh(
178
+ new PlaneGeometry(2, 2),
179
+ // @ts-ignore
180
+ new ShaderMaterial({
181
+ name: 'BackgroundMaterial',
182
+ uniforms: UniformsUtils.clone( ShaderLib.background.uniforms ),
183
+ vertexShader: ShaderLib.background.vertexShader,
184
+ fragmentShader: backgroundFragment.replace("<backgroundTint>", replacementTint), // ShaderLib.background.fragmentShader,
185
+ side: DoubleSide,
186
+ depthTest: false,
187
+ depthWrite: false,
188
+ fog: false
189
+ })
190
+ );
191
+
192
+ planeMesh.geometry.deleteAttribute( 'normal' );
193
+
194
+ // add "map" material property so the renderer can evaluate it like for built-in materials
195
+ Object.defineProperty( planeMesh.material, 'map', {
196
+ get: function () {
197
+ return this.threeTexture;
198
+ }
199
+ } );
200
+
201
+ // Option 1: add the planeMesh to our scene for rendering.
202
+ // This is useful for applying custom shader effects on the background (instead of using the system composite)
203
+ planeMesh.renderOrder = -10000; // render first
204
+ planeMesh.layers.disableAll();
205
+ planeMesh.layers.enable(2); // ignore raycasts
206
+ planeMesh.frustumCulled = false;
207
+
208
+ // should be a class, for now lets just define a method for the weird way the texture needs to be set
209
+ // @ts-ignore
210
+ planeMesh.setTexture = function(texture) {
211
+ planeMesh.material.uniforms.t2D.value = texture;
212
+ }
213
+
214
+ return planeMesh;
215
+ }
@@ -78,6 +78,11 @@ export class WebXR extends Behaviour {
78
78
  public static get IsARSupported(): boolean { return arSupported; }
79
79
  public static get IsVRSupported(): boolean { return vrSupported; }
80
80
 
81
+ private static _optionalFeatures_VR: string[] = ['local-floor', 'bounded-floor', 'hand-tracking', 'high-fixed-foveation-level', 'layers'];
82
+ private static _optionalFeatures_AR: string[] = ['plane-detection', 'anchors', 'local-floor', 'hand-tracking', 'layers'];
83
+ public static get OptionalFeatures_VR(): string[] { return this._optionalFeatures_VR; }
84
+ public static get OptionalFeatures_AR(): string[] { return this._optionalFeatures_AR; }
85
+
81
86
  public static addEventListener(type: string, listener: any): any {
82
87
  this.events.addEventListener(type, listener);
83
88
  return listener;
@@ -93,7 +98,8 @@ export class WebXR extends Behaviour {
93
98
  }
94
99
  else
95
100
  webXR.__internalAwake();
96
- const vrButton = VRButton.createButton(webXR.context.renderer);
101
+ const options = { optionalFeatures: WebXR.OptionalFeatures_VR };
102
+ const vrButton = VRButton.createButton(webXR.context.renderer, options);
97
103
  vrButton.classList.add('webxr-ar-button');
98
104
  vrButton.classList.add('webxr-button');
99
105
  this.resetButtonStyles(vrButton);
@@ -106,19 +112,17 @@ export class WebXR extends Behaviour {
106
112
  public static createARButton(webXR: WebXR, opts?: CreateButtonOptions): HTMLButtonElement | HTMLAnchorElement {
107
113
  webXR.__internalAwake();
108
114
  const domOverlayRoot = webXR.webAR?.getAROverlayContainer();
109
- const features: any = {};
115
+ const options: any = { optionalFeatures: [...this.OptionalFeatures_AR] };
110
116
  if (domOverlayRoot) {
111
- features.domOverlay = { root: domOverlayRoot };
112
- features.optionalFeatures = ['hit-test', 'dom-overlay'];
117
+ options.domOverlay = { root: domOverlayRoot };
118
+ options.optionalFeatures.push('dom-overlay')
119
+ options.optionalFeatures.push('hit-test');
113
120
  }
114
121
  else {
115
122
  console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");
116
123
  }
117
- features.optionalFeatures.push('plane-detection');
118
- // features.optionalFeatures.push('light-estimation');
119
- features.optionalFeatures.push('anchors');
120
124
 
121
- const arButton = ARButton.createButton(webXR.context.renderer, features);
125
+ const arButton = ARButton.createButton(webXR.context.renderer, options);
122
126
  arButton.classList.add('webxr-ar-button');
123
127
  arButton.classList.add('webxr-button');
124
128
  WebXR.resetButtonStyles(arButton);
@@ -331,6 +331,7 @@ export class WebXRAvatar {
331
331
  if (this.flags.length <= 0) {
332
332
  if (this.head) {
333
333
  const flag = GameObject.addNewComponent(this.head, XRFlag) as XRFlag;
334
+ // TODO: the defaults are wrong? should be Desktop | ThirdPerson ?
334
335
  flag.visibleIn = XRStateFlag.ThirdPerson | XRStateFlag.VR;
335
336
  this.flags.push(flag);
336
337
  if (debug)
@@ -7,6 +7,7 @@ export { AnimationExtension } from "../export/usdz/extensions/Animation";
7
7
  export { AnimationTrackHandler } from "../timeline/TimelineTracks";
8
8
  export { Animator } from "../Animator";
9
9
  export { AnimatorController } from "../AnimatorController";
10
+ export { Antialiasing } from "../postprocessing/Effects/Antialiasing";
10
11
  export { AttachedObject } from "../WebXRController";
11
12
  export { AudioListener } from "../AudioListener";
12
13
  export { AudioSource } from "../AudioSource";
@@ -23,6 +24,7 @@ export { AvatarModel } from "../AvatarLoader";
23
24
  export { AxesHelper } from "../AxesHelper";
24
25
  export { BaseUIComponent } from "../ui/BaseUIComponent";
25
26
  export { BasicIKConstraint } from "../BasicIKConstraint";
27
+ export { Bloom } from "../postprocessing/Effects/Bloom";
26
28
  export { BoxCollider } from "../Collider";
27
29
  export { BoxGizmo } from "../Gizmos";
28
30
  export { BoxHelperComponent } from "../BoxHelperComponent";
@@ -34,13 +36,15 @@ export { CanvasGroup } from "../ui/CanvasGroup";
34
36
  export { CapsuleCollider } from "../Collider";
35
37
  export { CharacterController } from "../CharacterController";
36
38
  export { CharacterControllerInput } from "../CharacterController";
39
+ export { ChromaticAberration } from "../postprocessing/Effects/ChromaticAberration";
37
40
  export { Collider } from "../Collider";
38
- export { ColorAdjustments } from "../Volume";
41
+ export { ColorAdjustments } from "../postprocessing/Effects/ColorAdjustments";
39
42
  export { ColorBySpeedModule } from "../ParticleSystemModules";
40
43
  export { ColorOverLifetimeModule } from "../ParticleSystemModules";
41
44
  export { ControlTrackHandler } from "../timeline/TimelineTracks";
42
45
  export { Deletable } from "../DeleteBox";
43
46
  export { DeleteBox } from "../DeleteBox";
47
+ export { DepthOfField } from "../postprocessing/Effects/DepthOfField";
44
48
  export { DeviceFlag } from "../DeviceFlag";
45
49
  export { DragControls } from "../DragControls";
46
50
  export { DropListener } from "../DropListener";
@@ -92,9 +96,11 @@ export { ParticleBurst } from "../ParticleSystemModules";
92
96
  export { ParticleSubEmitter } from "../ParticleSystemSubEmitter";
93
97
  export { ParticleSystem } from "../ParticleSystem";
94
98
  export { ParticleSystemRenderer } from "../ParticleSystem";
99
+ export { PixelationEffect } from "../postprocessing/Effects/Pixelation";
95
100
  export { PlayableDirector } from "../timeline/PlayableDirector";
96
101
  export { PlayerColor } from "../PlayerColor";
97
102
  export { PointerEventData } from "../ui/PointerEvents";
103
+ export { PostProcessingHandler } from "../postprocessing/PostProcessingHandler";
98
104
  export { RawImage } from "../ui/Image";
99
105
  export { Raycaster } from "../ui/Raycaster";
100
106
  export { Rect } from "../ui/RectTransform";
@@ -109,6 +115,7 @@ export { Rigidbody } from "../RigidBody";
109
115
  export { RotationBySpeedModule } from "../ParticleSystemModules";
110
116
  export { RotationOverLifetimeModule } from "../ParticleSystemModules";
111
117
  export { ScreenCapture } from "../ScreenCapture";
118
+ export { ScreenSpaceAmbientOcclusion } from "../postprocessing/Effects/ScreenspaceAmbientOcclusion";
112
119
  export { ShadowCatcher } from "../ShadowCatcher";
113
120
  export { ShapeModule } from "../ParticleSystemModules";
114
121
  export { SignalAsset } from "../timeline/SignalAsset";
@@ -137,7 +144,7 @@ export { TestRunner } from "../TestRunner";
137
144
  export { TestSimulateUserData } from "../TestRunner";
138
145
  export { Text } from "../ui/Text";
139
146
  export { TextureSheetAnimationModule } from "../ParticleSystemModules";
140
- export { ToneMapping } from "../Volume";
147
+ export { ToneMapping } from "../postprocessing/Effects/Tonemapping";
141
148
  export { TrailModule } from "../ParticleSystemModules";
142
149
  export { TransformData } from "../export/usdz/extensions/Animation";
143
150
  export { TransformGizmo } from "../TransformGizmo";
@@ -148,13 +155,14 @@ export { USDZExporter } from "../export/usdz/USDZExporter";
148
155
  export { VelocityOverLifetimeModule } from "../ParticleSystemModules";
149
156
  export { VerticalLayoutGroup } from "../ui/Layout";
150
157
  export { VideoPlayer } from "../VideoPlayer";
158
+ export { Vignette } from "../postprocessing/Effects/Vignette";
151
159
  export { Voip } from "../Voip";
152
- export { Volume } from "../Volume";
153
- export { VolumeComponent } from "../Volume";
154
- export { VolumeParameter } from "../Volume";
155
- export { VolumeProfile } from "../Volume";
160
+ export { Volume } from "../postprocessing/Volume";
161
+ export { VolumeParameter } from "../postprocessing/VolumeParameter";
162
+ export { VolumeProfile } from "../postprocessing/VolumeProfile";
156
163
  export { VRUserState } from "../WebXRSync";
157
164
  export { WebAR } from "../WebXR";
165
+ export { WebARCameraBackground } from "../WebARCameraBackground";
158
166
  export { WebARSessionRoot } from "../WebARSessionRoot";
159
167
  export { WebXR } from "../WebXR";
160
168
  export { WebXRAvatar } from "../WebXRAvatar";
@@ -3,7 +3,7 @@ import { Object3D } from "three";
3
3
  import { Constructor, ConstructorConcrete, IComponent } from "../../engine/engine_types"
4
4
  import { IComponent as Component } from "../../engine/engine_types";
5
5
  import { addNewComponent, getComponent, getComponentInChildren, getComponentInParent, getComponents, getComponentsInChildren, getComponentsInParent, getOrAddComponent, removeComponent } from "../../engine/engine_components";
6
- import { isActiveSelf, setActive } from "../../engine/engine_gameobject";
6
+ import { isActiveSelf, setActive, destroy } from "../../engine/engine_gameobject";
7
7
 
8
8
  // used to decorate cloned object3D objects with the same added components defined above
9
9
  export function apply(object: Object3D) {
@@ -20,6 +20,10 @@ Object3D.prototype["setActive"] = function (active: boolean) {
20
20
  this.visible = active;
21
21
  }
22
22
 
23
+ Object3D.prototype["destroy"] = function () {
24
+ destroy(this);
25
+ }
26
+
23
27
  Object3D.prototype["addNewComponent"] = function <T extends Component>(type: ConstructorConcrete<T>) {
24
28
  return addNewComponent(this, new type());
25
29
  }
@@ -78,5 +82,6 @@ if (!Object.getOwnPropertyDescriptor(Object3D.prototype, "transform")) {
78
82
 
79
83
 
80
84
 
85
+
81
86
  // do this after adding the component extensions
82
87
  registerPrototypeExtensions(Object3D);
@@ -0,0 +1,52 @@
1
+ import { EdgeDetectionMode, SMAAEffect, SMAAPreset } from "postprocessing";
2
+ import { serializable } from "../../../engine/engine_serialization";
3
+ import { EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect";
4
+ import { VolumeParameter } from "../VolumeParameter";
5
+ import { registerCustomEffectType } from "../VolumeProfile";
6
+
7
+
8
+
9
+ export enum QualityLevel {
10
+ LOW = 0,
11
+ MEDIUM = 1,
12
+ HIGH = 2,
13
+ ULTRA = 3
14
+ }
15
+
16
+
17
+ export class Antialiasing extends PostProcessingEffect {
18
+ get typeName(): string {
19
+ return "Antialiasing";
20
+ }
21
+
22
+ // @serializable(VolumeParameter)
23
+ // edgeDetectionThreshold!: VolumeParameter;
24
+
25
+ @serializable(VolumeParameter)
26
+ preset!: VolumeParameter;
27
+
28
+
29
+ onCreateEffect(): EffectProviderResult {
30
+ const effect = new SMAAEffect({
31
+ preset: SMAAPreset.HIGH,
32
+ edgeDetectionMode: EdgeDetectionMode.DEPTH
33
+ });
34
+
35
+ this.preset.onValueChanged = (newValue) => {
36
+ effect.applyPreset(newValue);
37
+ };
38
+
39
+ // effect.edgeDetectionMaterial.edgeDetectionThreshold = .01;
40
+
41
+ // this.edgeDetectionThreshold.onValueChanged = (newValue) => {
42
+ // console.log(newValue);
43
+ // effect.edgeDetectionMaterial.edgeDetectionThreshold = newValue;
44
+ // }
45
+
46
+ return effect;
47
+ }
48
+
49
+
50
+ }
51
+
52
+ registerCustomEffectType("Antialiasing", Antialiasing)
@@ -0,0 +1,75 @@
1
+ import { BloomEffect, SelectiveBloomEffect } from "postprocessing";
2
+ import { serializable } from "../../../engine/engine_serialization";
3
+ import { PostProcessingEffect } from "../PostProcessingEffect";
4
+ import { VolumeParameter } from "../VolumeParameter";
5
+ import { registerCustomEffectType } from "../VolumeProfile";
6
+
7
+ export class Bloom extends PostProcessingEffect {
8
+
9
+ get typeName() {
10
+ return "Bloom";
11
+ }
12
+
13
+ @serializable(VolumeParameter)
14
+ threshold!: VolumeParameter;
15
+ @serializable(VolumeParameter)
16
+ intensity!: VolumeParameter;
17
+ @serializable(VolumeParameter)
18
+ scatter!: VolumeParameter;
19
+
20
+ selectiveBloom = true;
21
+
22
+ init() {
23
+ this.threshold.defaultValue = 1;
24
+ this.intensity.defaultValue = 0;
25
+ this.scatter.defaultValue = .2;
26
+
27
+ if (this.selectiveBloom) {
28
+ this.threshold.valueProcessor = (v: number) => v * .5;// / (Math.PI * 2);
29
+ this.intensity.valueProcessor = (v: number) => v * Math.PI * 2;
30
+ this.scatter.valueProcessor = (v: number) => .2 + Math.pow((1 - v), 2);
31
+ }
32
+ else {
33
+ this.threshold.valueProcessor = (v: number) => v / (Math.PI * 2);
34
+ this.intensity.valueProcessor = (v: number) => v;// * 2.2;
35
+ this.scatter.valueProcessor = (v: number) => (1 - v);
36
+ }
37
+ }
38
+
39
+ onCreateEffect() {
40
+ let bloom: BloomEffect;
41
+ if (this.selectiveBloom) {
42
+ // https://github.com/pmndrs/postprocessing/blob/64d2829f014cfec97a46bf3c109f3abc55af0715/demo/src/demos/BloomDemo.js#L265
43
+ const selectiveBloom = bloom = new SelectiveBloomEffect(this.context.scene, this.context.mainCamera!, {
44
+ luminanceThreshold: this.threshold.value,
45
+ luminanceSmoothing: this.scatter.value,
46
+ intensity: this.intensity.value,
47
+ mipmapBlur: false,
48
+ });
49
+ selectiveBloom.inverted = true;
50
+ }
51
+ else {
52
+ bloom = new BloomEffect();
53
+ }
54
+
55
+
56
+ const blur = bloom["mipmapBlurPass"];
57
+ if (typeof blur === "object") {
58
+ blur.radius = this.scatter.value;
59
+ }
60
+
61
+ this.intensity.onValueChanged = newValue => {
62
+ bloom!.intensity = newValue;
63
+ };
64
+ this.threshold.onValueChanged = newValue => {
65
+ bloom!.luminanceMaterial.threshold = newValue;
66
+ };
67
+ this.scatter.onValueChanged = newValue => {
68
+ bloom!.luminanceMaterial.smoothing = newValue;
69
+ };
70
+
71
+ return bloom;
72
+ }
73
+
74
+ }
75
+ registerCustomEffectType("Bloom", Bloom);
@@ -0,0 +1,36 @@
1
+ import { ChromaticAberrationEffect } from "postprocessing";
2
+ import { Vector2 } from "three";
3
+ import { serializable } from "../../../engine/engine_serialization";
4
+ import { EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect";
5
+ import { VolumeParameter } from "../VolumeParameter";
6
+ import { registerCustomEffectType, VolumeProfile } from "../VolumeProfile";
7
+
8
+ export class ChromaticAberration extends PostProcessingEffect {
9
+
10
+ get typeName() {
11
+ return "ChromaticAberration";
12
+ }
13
+
14
+ @serializable(VolumeParameter)
15
+ intensity!: VolumeParameter;
16
+
17
+ init() {
18
+ this.intensity.defaultValue = 0;
19
+ }
20
+
21
+ onCreateEffect(): EffectProviderResult {
22
+ const chromatic = new ChromaticAberrationEffect();
23
+ chromatic.offset = new Vector2(0, 0)
24
+ chromatic.radialModulation = true;
25
+ chromatic.modulationOffset = .15;
26
+ this.intensity.valueProcessor = v => v * .02;
27
+ this.intensity.onValueChanged = v => {
28
+ chromatic.offset.x = -v;
29
+ chromatic.offset.y = v;
30
+ }
31
+ return chromatic;
32
+ }
33
+
34
+ };
35
+
36
+ registerCustomEffectType("ChromaticAberration", ChromaticAberration);
@@ -0,0 +1,114 @@
1
+ import { BrightnessContrastEffect, HueSaturationEffect } from "postprocessing";
2
+ import { serializable } from "../../../engine/engine_serialization";
3
+ import { EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect";
4
+ import { VolumeParameter } from "../VolumeParameter";
5
+ import { registerCustomEffectType } from "../VolumeProfile";
6
+ import { NoToneMapping } from "three";
7
+
8
+
9
+ export class ColorAdjustments extends PostProcessingEffect {
10
+
11
+ get typeName() {
12
+ return "ColorAdjustments";
13
+ }
14
+
15
+ @serializable(VolumeParameter)
16
+ postExposure!: VolumeParameter;
17
+
18
+ @serializable(VolumeParameter)
19
+ contrast!: VolumeParameter;
20
+
21
+ @serializable(VolumeParameter)
22
+ hueShift!: VolumeParameter;
23
+
24
+ @serializable(VolumeParameter)
25
+ saturation!: VolumeParameter;
26
+
27
+ init() {
28
+ this.postExposure!.valueProcessor = v => {
29
+ // when using tone mapping, the exposure will just be set to the renderer
30
+ if (this.context.renderer.toneMapping !== NoToneMapping && v > 0) {
31
+ return Math.pow(2, v);
32
+ }
33
+ // Custom effects need modification
34
+ else {
35
+ return v / (2 * Math.PI);
36
+ }
37
+ }
38
+ this.postExposure.defaultValue = 0;
39
+
40
+ this.contrast.valueProcessor = (v: number) => {
41
+ let divisor = 100;
42
+ if (v > 0) divisor *= Math.PI * 2;
43
+ const val = v / divisor;
44
+ return val;
45
+ };
46
+ this.contrast.defaultValue = 0;
47
+
48
+ this.hueShift.valueProcessor = (v: number) => Math.PI * v / 180;
49
+ this.hueShift.defaultValue = 0;
50
+
51
+ this.saturation.valueProcessor = (v: number) => {
52
+ return (v / 180);
53
+ }
54
+ this.saturation.defaultValue = 0;
55
+ }
56
+
57
+ unapply() {
58
+ this.context.renderer.toneMappingExposure = 1;
59
+ }
60
+
61
+
62
+ onCreateEffect(): EffectProviderResult {
63
+
64
+ const brightnesscontrast = new BrightnessContrastEffect();
65
+ // TODO: darkening etc doesnt really work well in all cases right now
66
+ this.postExposure!.onValueChanged = v => {
67
+ // We can use the builtin exposure when tonemapping is set
68
+ if (this.context.renderer.toneMapping !== NoToneMapping) {
69
+ if (v === 0) {
70
+ this.context.renderer.toneMappingExposure = 1;
71
+ brightnesscontrast.brightness = 0;
72
+ }
73
+ else if (v > 0) {
74
+ this.context.renderer.toneMappingExposure = v;
75
+ brightnesscontrast.brightness = 0;
76
+ }
77
+ else {
78
+ this.context.renderer.toneMappingExposure = v;
79
+ brightnesscontrast.brightness = 0;
80
+ }
81
+ }
82
+ // Otherwise use the effect (they look sligthly different/behave different unfortunately)
83
+ else {
84
+ this.context.renderer.toneMappingExposure = 0;
85
+ brightnesscontrast.brightness = v;
86
+ }
87
+ }
88
+ this.contrast!.onValueChanged = v => brightnesscontrast.contrast = v;
89
+
90
+
91
+ const hueSaturationEffect = new HueSaturationEffect();
92
+ this.hueShift!.onValueChanged = v => hueSaturationEffect.hue = v;
93
+ this.saturation!.onValueChanged = v => hueSaturationEffect.saturation = v;
94
+
95
+ return [brightnesscontrast, hueSaturationEffect];
96
+ }
97
+
98
+ // apply() {
99
+ // this.postExposure!.onValueChanged = () => {
100
+ // this.setExposure();
101
+ // };
102
+
103
+ // // unity range goes from -15..15
104
+ // // three.js range goes from 0..inf
105
+ // if (this.postExposure?.overrideState) {
106
+ // this.setExposure();
107
+ // }
108
+ // }
109
+ // private setExposure() {
110
+ // const exposure = Math.pow(2, this.postExposure?.value ?? 0);
111
+ // this.context.renderer.toneMappingExposure = exposure;
112
+ // }
113
+ }
114
+ registerCustomEffectType("ColorAdjustments", ColorAdjustments);