@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
@@ -28,7 +28,7 @@ export class PlayerSync extends Behaviour {
28
28
  }
29
29
 
30
30
  private async onUserJoined(_model) {
31
- const instance = await this.asset?.instantiateSynced({parent:this.gameObject}, true);
31
+ const instance = await this.asset?.instantiateSynced({ parent: this.gameObject }, true);
32
32
  if (instance) {
33
33
  let pl = GameObject.getComponent(instance as Object3D, PlayerState);
34
34
  if (pl) {
@@ -60,6 +60,17 @@ export class PlayerSync extends Behaviour {
60
60
  }
61
61
  }
62
62
 
63
+ export enum PlayerStateEvent {
64
+ OwnerChanged = "ownerChanged",
65
+ }
66
+
67
+ export declare interface PlayerStateOwnerChangedArgs {
68
+ playerState: PlayerState;
69
+ oldValue: string;
70
+ newValue: string;
71
+ }
72
+
73
+ export declare type PlayerStateEventCallback = (args: CustomEvent<PlayerStateOwnerChangedArgs>) => void;
63
74
 
64
75
  export class PlayerState extends Behaviour {
65
76
 
@@ -78,24 +89,70 @@ export class PlayerState extends Behaviour {
78
89
  //** use to check if a component or gameobject is part of a instance owned by the local player */
79
90
  static isLocalPlayer(obj: THREE.Object3D | Component): boolean {
80
91
  if (obj instanceof Object3D) {
81
- return GameObject.getComponentInParent(obj, PlayerState)?.isLocalPlayer ?? false;
92
+ const state = GameObject.getComponentInParent(obj, PlayerState);
93
+ return state?.isLocalPlayer ?? false;
82
94
  }
83
95
  else if (obj instanceof Component) {
84
- return GameObject.getComponentInParent(obj.gameObject, PlayerState)?.isLocalPlayer ?? false;
96
+ const state = GameObject.getComponentInParent(obj.gameObject, PlayerState);
97
+ return state?.isLocalPlayer ?? false;
85
98
  }
86
99
  return false;
87
100
  }
88
101
 
89
- @syncField()
90
- @serializable()
102
+ // static Callback
103
+ private static _callbacks: { [key: string]: PlayerStateEventCallback[] } = {};
104
+ /**
105
+ * Add a callback for a PlayerStateEvent
106
+ */
107
+ static addEventListener(event: PlayerStateEvent, cb: PlayerStateEventCallback) {
108
+ if (!this._callbacks[event]) this._callbacks[event] = [];
109
+ this._callbacks[event].push(cb);
110
+ return cb;
111
+ }
112
+ static removeEventListener(event: PlayerStateEvent, cb: PlayerStateEventCallback) {
113
+ if (!this._callbacks[event]) return;
114
+ const index = this._callbacks[event].indexOf(cb);
115
+ if (index >= 0) this._callbacks[event].splice(index, 1);
116
+ }
117
+ private static dispatchEvent(event: PlayerStateEvent, args: CustomEvent<PlayerStateOwnerChangedArgs>) {
118
+ if (!this._callbacks[event]) return;
119
+ for (const cb of this._callbacks[event]) {
120
+ cb(args);
121
+ }
122
+ }
123
+
124
+ @syncField("onOwnerChange")
91
125
  owner?: string;
92
126
 
93
127
  get isLocalPlayer(): boolean {
94
128
  return this.owner === this.context.connection.connectionId;
95
129
  }
96
130
 
131
+ private onOwnerChange(newOwner: string, oldOwner: string) {
132
+ // Remove from local owner array if it was local before
133
+ const index = PlayerState._local.indexOf(this);
134
+ if (index >= 0) PlayerState._local.splice(index, 1);
135
+
136
+ // Args to use for dispatching events
137
+ const detail: PlayerStateOwnerChangedArgs = {
138
+ playerState: this,
139
+ oldValue: oldOwner,
140
+ newValue: newOwner
141
+ }
142
+
143
+ if (this.owner === this.context.connection.connectionId) {
144
+ PlayerState._local.push(this);
145
+ // console.warn(this.gameObject.guid, this.guid, this.owner, this.isLocalPlayer, PlayerState.isLocalPlayer(this));
146
+ const evt = new CustomEvent("local-owner-changed", { detail: detail });
147
+ this.dispatchEvent(evt);
148
+ PlayerState.dispatchEvent(PlayerStateEvent.OwnerChanged, evt);
149
+ }
150
+ const evt = new CustomEvent("owner-changed", { detail: detail });
151
+ this.dispatchEvent(evt);
152
+ PlayerState.dispatchEvent(PlayerStateEvent.OwnerChanged, evt);
153
+ }
154
+
97
155
  awake(): void {
98
- if (this.isLocalPlayer) PlayerState.local.push(this);
99
156
  PlayerState.all.push(this);
100
157
 
101
158
  this.context.connection.beginListen(RoomEvents.UserLeftRoom, (model: { userId: string }) => {
@@ -109,12 +166,16 @@ export class PlayerState extends Behaviour {
109
166
  }
110
167
 
111
168
  start() {
112
- if (!this.owner || !this.context.connection.userIsInRoom(this.owner)) {
169
+ // If a player is spawned but not in the room anymore we want to destroy it
170
+ // this might happen in a case where all users get disconnected at once and the server
171
+ // still has the syncInstantiate messages that are sent to all clients
172
+ if (this.owner && !this.context.connection.userIsInRoom(this.owner)) {
113
173
  this.doDestroy();
114
174
  return;
115
175
  }
116
176
  }
117
177
 
178
+ /** this tells the server that this client has been destroyed and the networking message for the instantiate will be removed */
118
179
  doDestroy() {
119
180
  syncDestroy(this.gameObject, this.context.connection);
120
181
  }
@@ -1,13 +1,15 @@
1
1
  class ARButton {
2
2
 
3
- static createButton( renderer, sessionInit = {} ) {
3
+ static createButton( renderer, options = {} ) {
4
4
 
5
5
  const button = document.createElement( 'button' );
6
6
  let ARButtonControlsDomOverlay = false;
7
7
 
8
- function showStartAR( /*device*/ ) {
8
+ function showStartAR( /*device*/ ) {
9
+
10
+ options.optionalFeatures = options.optionalFeatures || [];
9
11
 
10
- if ( sessionInit.domOverlay === undefined) {
12
+ if ( options.domOverlay === undefined) {
11
13
 
12
14
  var overlay = document.createElement( 'div' );
13
15
  overlay.style.display = 'none';
@@ -32,25 +34,12 @@ class ARButton {
32
34
  path.setAttribute( 'stroke-width', 2 );
33
35
  svg.appendChild( path );
34
36
 
35
- if ( sessionInit.optionalFeatures === undefined ) {
36
-
37
- sessionInit.optionalFeatures = [];
38
-
39
- }
40
-
41
- sessionInit.optionalFeatures.push( 'dom-overlay' );
42
- sessionInit.domOverlay = { root: overlay };
37
+ options.optionalFeatures.push( 'dom-overlay' );
38
+ options.domOverlay = { root: overlay };
43
39
  ARButtonControlsDomOverlay = true;
44
40
 
45
41
  }
46
42
 
47
- if ( sessionInit.optionalFeatures === undefined ) sessionInit.optionalFeatures = [];
48
-
49
- // added for Hololens support
50
- sessionInit.optionalFeatures.push( 'local-floor' );
51
- sessionInit.optionalFeatures.push( 'hand-tracking' );
52
- sessionInit.optionalFeatures.push( 'layers' );
53
-
54
43
  //
55
44
 
56
45
  let currentSession = null;
@@ -62,8 +51,8 @@ class ARButton {
62
51
  // HTMLElements that are inside the Canvas element are not visible in the DOM Overlay.
63
52
  const isWebXRViewer = /WebXRViewer\//i.test( navigator.userAgent );
64
53
  if (isWebXRViewer) {
65
- if(sessionInit.domOverlay?.root) {
66
- const overlayElement = sessionInit.domOverlay.root;
54
+ if(options.domOverlay?.root) {
55
+ const overlayElement = options.domOverlay.root;
67
56
  originalDomOverlayParent = overlayElement.parentElement;
68
57
  if (originalDomOverlayParent) {
69
58
  console.log("Reparent DOM Overlay to body", overlayElement, overlayElement.style.display);
@@ -89,7 +78,7 @@ class ARButton {
89
78
  button.textContent = 'STOP AR';
90
79
 
91
80
  if (ARButtonControlsDomOverlay)
92
- sessionInit.domOverlay.root.style.display = '';
81
+ options.domOverlay.root.style.display = '';
93
82
 
94
83
  currentSession = session;
95
84
 
@@ -103,10 +92,10 @@ class ARButton {
103
92
 
104
93
  // if we reparented the DOM overlay, we're reverting it here
105
94
  if (originalDomOverlayParent)
106
- originalDomOverlayParent.appendChild(sessionInit.domOverlay.root);
95
+ originalDomOverlayParent.appendChild(options.domOverlay.root);
107
96
 
108
97
  if (ARButtonControlsDomOverlay)
109
- sessionInit.domOverlay.root.style.display = 'none';
98
+ options.domOverlay.root.style.display = 'none';
110
99
 
111
100
  currentSession = null;
112
101
 
@@ -138,7 +127,7 @@ class ARButton {
138
127
 
139
128
  if ( currentSession === null ) {
140
129
 
141
- navigator.xr.requestSession( 'immersive-ar', sessionInit ).then( onSessionStarted );
130
+ navigator.xr.requestSession( 'immersive-ar', options ).then( onSessionStarted );
142
131
 
143
132
  } else {
144
133
 
@@ -2,12 +2,6 @@ class VRButton {
2
2
 
3
3
  static createButton( renderer, options ) {
4
4
 
5
- if ( options ) {
6
-
7
- console.error( 'THREE.VRButton: The "options" parameter has been removed. Please set the reference space type via renderer.xr.setReferenceSpaceType() instead.' );
8
-
9
- }
10
-
11
5
  const button = document.createElement( 'button' );
12
6
 
13
7
  function showEnterVR( /*device*/ ) {
@@ -70,7 +64,7 @@ class VRButton {
70
64
  // ('local' is always available for immersive sessions and doesn't need to
71
65
  // be requested separately.)
72
66
 
73
- const sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor', 'hand-tracking', 'high-fixed-foveation-level', 'layers' ] };
67
+ const sessionInit = { optionalFeatures: options.optionalFeatures };
74
68
  navigator.xr.requestSession( 'immersive-vr', sessionInit ).then( onSessionStarted );
75
69
 
76
70
  } else {
@@ -1,34 +0,0 @@
1
- import { Behaviour } from "./Component";
2
- import { Context } from "../engine/engine_setup";
3
- export declare enum TonemappingMode {
4
- None = 0,
5
- Neutral = 1,
6
- ACES = 2
7
- }
8
- export declare class VolumeParameter {
9
- overrideState: boolean;
10
- value: number;
11
- }
12
- export declare class VolumeComponent {
13
- active: boolean;
14
- parameters?: VolumeParameter[];
15
- }
16
- export declare class ToneMapping extends VolumeComponent {
17
- mode?: VolumeParameter;
18
- get isToneMapping(): boolean;
19
- }
20
- export declare class ColorAdjustments extends VolumeComponent {
21
- postExposure?: VolumeParameter;
22
- }
23
- export declare class VolumeProfile {
24
- components?: VolumeComponent[];
25
- apply(context: Context): void;
26
- unapply(context: Context): void;
27
- private onUpdate;
28
- }
29
- export declare class Volume extends Behaviour {
30
- sharedProfile?: VolumeProfile;
31
- awake(): void;
32
- onEnable(): void;
33
- onDisable(): void;
34
- }
@@ -1,140 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { Behaviour } from "./Component";
8
- import { LinearToneMapping, ACESFilmicToneMapping, ReinhardToneMapping } from "three";
9
- import { serializable } from "../engine/engine_serialization_decorator";
10
- import { getParam } from "../engine/engine_utils";
11
- const debug = getParam("debugvolume");
12
- export var TonemappingMode;
13
- (function (TonemappingMode) {
14
- TonemappingMode[TonemappingMode["None"] = 0] = "None";
15
- TonemappingMode[TonemappingMode["Neutral"] = 1] = "Neutral";
16
- TonemappingMode[TonemappingMode["ACES"] = 2] = "ACES";
17
- })(TonemappingMode || (TonemappingMode = {}));
18
- export class VolumeParameter {
19
- overrideState = false;
20
- value = 0;
21
- }
22
- export class VolumeComponent {
23
- active = false;
24
- parameters;
25
- }
26
- export class ToneMapping extends VolumeComponent {
27
- mode;
28
- get isToneMapping() { return true; }
29
- }
30
- export class ColorAdjustments extends VolumeComponent {
31
- postExposure;
32
- }
33
- // resolve the types:
34
- function resolveComponentType(data) {
35
- if ("mode" in data)
36
- return ToneMapping;
37
- if ("postExposure" in data)
38
- return ColorAdjustments;
39
- return VolumeComponent;
40
- }
41
- const volumeKey = Symbol("volumeprofile");
42
- export class VolumeProfile {
43
- components;
44
- apply(context) {
45
- this.onUpdate(context, false);
46
- }
47
- unapply(context) {
48
- this.onUpdate(context, true);
49
- }
50
- onUpdate(context, remove) {
51
- if (!this.components)
52
- return;
53
- const renderer = context.renderer;
54
- const currentProfile = renderer[volumeKey];
55
- const isActive = currentProfile !== undefined;
56
- if (remove) {
57
- // can not remove volume profile that is not active
58
- if (!isActive)
59
- return;
60
- }
61
- else {
62
- renderer[volumeKey] = this;
63
- }
64
- for (const component of this.components) {
65
- if (component instanceof ToneMapping) {
66
- const tonemapping = component;
67
- if (!component.active || remove) {
68
- context.renderer.toneMapping = LinearToneMapping;
69
- continue;
70
- }
71
- if (debug)
72
- console.log("VOLUME:", TonemappingMode[tonemapping.mode?.value ?? 0]);
73
- const mode = tonemapping.mode;
74
- const value = mode?.overrideState ? mode?.value : 0;
75
- switch (value ?? 0) {
76
- case TonemappingMode.None:
77
- context.renderer.toneMapping = LinearToneMapping;
78
- break;
79
- case TonemappingMode.Neutral:
80
- context.renderer.toneMapping = ReinhardToneMapping;
81
- break;
82
- case TonemappingMode.ACES:
83
- context.renderer.toneMapping = ACESFilmicToneMapping;
84
- break;
85
- }
86
- }
87
- else if (component instanceof ColorAdjustments) {
88
- if (!component.active)
89
- continue;
90
- const colorAdjustments = component;
91
- // unity range goes from -15..15
92
- // three.js range goes from 0..inf
93
- if (debug)
94
- console.log(colorAdjustments.postExposure);
95
- let exposure = 1;
96
- // convert to linear
97
- if (colorAdjustments.postExposure)
98
- exposure = Math.pow(2, colorAdjustments.postExposure.value);
99
- // ACES applies a factor of roughly 1.666 ( /= .6 )
100
- if (context.renderer.toneMapping === ACESFilmicToneMapping) {
101
- // exposure /= Math.PI / 2;
102
- }
103
- const useExposure = colorAdjustments.postExposure?.overrideState && !remove;
104
- context.renderer.toneMappingExposure = useExposure ? exposure : 1;
105
- if (!context.renderer.toneMapping)
106
- context.renderer.toneMapping = LinearToneMapping;
107
- }
108
- }
109
- }
110
- }
111
- __decorate([
112
- serializable([d => resolveComponentType(d), VolumeComponent])
113
- ], VolumeProfile.prototype, "components", void 0);
114
- export class Volume extends Behaviour {
115
- sharedProfile;
116
- awake() {
117
- if (debug) {
118
- console.log(this);
119
- console.log("Press P to toggle post processing");
120
- window.addEventListener("keydown", (e) => {
121
- if (e.key === "p") {
122
- console.log("Toggle volume: " + this.name, !this.enabled);
123
- this.enabled = !this.enabled;
124
- }
125
- });
126
- }
127
- }
128
- onEnable() {
129
- if (debug)
130
- console.log("APPLY VOLUME", this);
131
- this.sharedProfile?.apply(this.context);
132
- }
133
- onDisable() {
134
- this.sharedProfile?.unapply(this.context);
135
- }
136
- }
137
- __decorate([
138
- serializable(VolumeProfile)
139
- ], Volume.prototype, "sharedProfile", void 0);
140
- //# sourceMappingURL=Volume.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Volume.js","sourceRoot":"","sources":["../../../src/engine-components/Volume.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAiB,iBAAiB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACrG,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC;AA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C1D,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;iBAChC;YACL,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IAED,QAAQ;QACJ,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;QAC5C,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,SAAS;QACL,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACJ;AAvBG;IADC,YAAY,CAAC,aAAa,CAAC;6CACE"}
@@ -1,141 +0,0 @@
1
- import { Behaviour } from "./Component";
2
- import { NoToneMapping, LinearToneMapping, ACESFilmicToneMapping, ReinhardToneMapping } from "three";
3
- import { serializable } from "../engine/engine_serialization_decorator";
4
- import { Context } from "../engine/engine_setup";
5
- import { getParam } from "../engine/engine_utils";
6
-
7
- const debug = getParam("debugvolume");
8
-
9
- export enum TonemappingMode {
10
- None = 0,
11
- Neutral = 1, // Neutral tonemapper
12
- ACES = 2, // ACES Filmic reference tonemapper (custom approximation)
13
- }
14
-
15
- export class VolumeParameter {
16
- overrideState: boolean = false;
17
- value: number = 0;
18
- }
19
-
20
- export class VolumeComponent {
21
- active: boolean = false;
22
- parameters?: VolumeParameter[];
23
- }
24
-
25
- export class ToneMapping extends VolumeComponent {
26
- mode?: VolumeParameter;
27
- get isToneMapping() { return true; }
28
- }
29
-
30
- export class ColorAdjustments extends VolumeComponent {
31
- postExposure?: VolumeParameter;
32
- }
33
-
34
- // resolve the types:
35
- function resolveComponentType(data) {
36
- if ("mode" in data) return ToneMapping;
37
- if ("postExposure" in data) return ColorAdjustments;
38
- return VolumeComponent;
39
- }
40
-
41
- const volumeKey = Symbol("volumeprofile");
42
-
43
- export class VolumeProfile {
44
- @serializable([d => resolveComponentType(d), VolumeComponent])
45
- components?: VolumeComponent[];
46
-
47
- apply(context: Context) {
48
- this.onUpdate(context, false);
49
- }
50
-
51
- unapply(context: Context) {
52
- this.onUpdate(context, true);
53
- }
54
-
55
- private onUpdate(context: Context, remove: boolean) {
56
- if (!this.components) return;
57
- const renderer = context.renderer;
58
- const currentProfile = renderer[volumeKey];
59
- const isActive = currentProfile !== undefined;
60
- if (remove) {
61
- // can not remove volume profile that is not active
62
- if (!isActive) return;
63
- }
64
- else {
65
- renderer[volumeKey] = this;
66
- }
67
- for (const component of this.components) {
68
-
69
- if (component instanceof ToneMapping) {
70
- const tonemapping = component as ToneMapping;
71
- if (!component.active || remove) {
72
- context.renderer.toneMapping = LinearToneMapping;
73
- continue;
74
- }
75
- if (debug) console.log("VOLUME:", TonemappingMode[tonemapping.mode?.value ?? 0]);
76
- const mode = tonemapping.mode;
77
- const value = mode?.overrideState ? mode?.value : 0;
78
- switch (value ?? 0) {
79
- case TonemappingMode.None:
80
- context.renderer.toneMapping = LinearToneMapping;
81
- break;
82
- case TonemappingMode.Neutral:
83
- context.renderer.toneMapping = ReinhardToneMapping;
84
- break;
85
- case TonemappingMode.ACES:
86
- context.renderer.toneMapping = ACESFilmicToneMapping;
87
- break;
88
- }
89
- }
90
- else if (component instanceof ColorAdjustments) {
91
- if (!component.active) continue;
92
- const colorAdjustments = component as ColorAdjustments;
93
- // unity range goes from -15..15
94
- // three.js range goes from 0..inf
95
- if (debug)
96
- console.log(colorAdjustments.postExposure);
97
- let exposure = 1;
98
- // convert to linear
99
- if (colorAdjustments.postExposure)
100
- exposure = Math.pow(2, colorAdjustments.postExposure.value);
101
- // ACES applies a factor of roughly 1.666 ( /= .6 )
102
- if (context.renderer.toneMapping === ACESFilmicToneMapping) {
103
- // exposure /= Math.PI / 2;
104
- }
105
- const useExposure = colorAdjustments.postExposure?.overrideState && !remove;
106
- context.renderer.toneMappingExposure = useExposure ? exposure : 1;
107
- if (!context.renderer.toneMapping)
108
- context.renderer.toneMapping = LinearToneMapping;
109
- }
110
- }
111
- }
112
- }
113
-
114
-
115
- export class Volume extends Behaviour {
116
-
117
- @serializable(VolumeProfile)
118
- sharedProfile?: VolumeProfile;
119
-
120
- awake() {
121
- if (debug) {
122
- console.log(this);
123
- console.log("Press P to toggle post processing");
124
- window.addEventListener("keydown", (e) => {
125
- if (e.key === "p") {
126
- console.log("Toggle volume: " + this.name, !this.enabled);
127
- this.enabled = !this.enabled;
128
- }
129
- });
130
- }
131
- }
132
-
133
- onEnable() {
134
- if (debug) console.log("APPLY VOLUME", this)
135
- this.sharedProfile?.apply(this.context);
136
- }
137
-
138
- onDisable() {
139
- this.sharedProfile?.unapply(this.context);
140
- }
141
- }