@needle-tools/engine 4.16.1 → 4.16.3

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 (100) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/components.needle.json +1 -1
  3. package/dist/{needle-engine.bundle-CKIxz09L.js → needle-engine.bundle-BE9apg0j.js} +5358 -5343
  4. package/dist/{needle-engine.bundle-DSHShuiJ.umd.cjs → needle-engine.bundle-CYtylxkF.umd.cjs} +131 -131
  5. package/dist/{needle-engine.bundle-C3aSGlMn.min.js → needle-engine.bundle-eJXdUwvK.min.js} +132 -132
  6. package/dist/needle-engine.d.ts +31 -9
  7. package/dist/needle-engine.js +2 -2
  8. package/dist/needle-engine.min.js +1 -1
  9. package/dist/needle-engine.umd.cjs +1 -1
  10. package/lib/engine-components/EventType.d.ts +1 -13
  11. package/lib/engine-components/EventType.js +13 -12
  12. package/lib/engine-components/EventType.js.map +1 -1
  13. package/lib/engine-components/ReflectionProbe.d.ts +31 -8
  14. package/lib/engine-components/ReflectionProbe.js +57 -15
  15. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  16. package/lib/engine-components/VideoPlayer.d.ts +1 -1
  17. package/lib/engine-components/VideoPlayer.js +1 -1
  18. package/lib/engine-components/VideoPlayer.js.map +1 -1
  19. package/package.json +15 -6
  20. package/plugins/next/next.d.ts +8 -0
  21. package/plugins/next/next.js +7 -6
  22. package/plugins/types/userconfig.d.ts +4 -6
  23. package/plugins/vite/ai.d.ts +17 -0
  24. package/plugins/vite/ai.js +2 -2
  25. package/plugins/vite/alias.d.ts +8 -0
  26. package/plugins/vite/alias.js +5 -2
  27. package/plugins/vite/asap.d.ts +7 -0
  28. package/plugins/vite/asap.js +3 -3
  29. package/plugins/vite/build-pipeline.d.ts +15 -0
  30. package/plugins/vite/build-pipeline.js +5 -6
  31. package/plugins/vite/build.d.ts +7 -0
  32. package/plugins/vite/build.js +5 -2
  33. package/plugins/vite/buildinfo.d.ts +7 -0
  34. package/plugins/vite/buildinfo.js +4 -2
  35. package/plugins/vite/config.d.ts +13 -0
  36. package/plugins/vite/config.js +1 -1
  37. package/plugins/vite/copyfiles.d.ts +7 -0
  38. package/plugins/vite/copyfiles.js +4 -2
  39. package/plugins/vite/custom-element-data.d.ts +25 -0
  40. package/plugins/vite/custom-element-data.js +2 -1
  41. package/plugins/vite/defines.d.ts +10 -0
  42. package/plugins/vite/defines.js +4 -3
  43. package/plugins/vite/dependencies.d.ts +21 -0
  44. package/plugins/vite/dependencies.js +3 -1
  45. package/plugins/vite/dependency-watcher.d.ts +11 -0
  46. package/plugins/vite/dependency-watcher.js +2 -1
  47. package/plugins/vite/drop-client.d.ts +1 -0
  48. package/plugins/vite/drop.d.ts +7 -0
  49. package/plugins/vite/drop.js +4 -4
  50. package/plugins/vite/editor-connection.d.ts +8 -0
  51. package/plugins/vite/editor-connection.js +6 -2
  52. package/plugins/vite/facebook-instant-games.d.ts +7 -0
  53. package/plugins/vite/facebook-instant-games.js +4 -2
  54. package/plugins/vite/gzip.d.ts +6 -0
  55. package/plugins/vite/gzip.js +5 -0
  56. package/plugins/vite/imports-logger.d.ts +13 -0
  57. package/plugins/vite/imports-logger.js +2 -1
  58. package/plugins/vite/index.d.ts +54 -0
  59. package/plugins/vite/index.js +16 -15
  60. package/plugins/vite/license.d.ts +7 -0
  61. package/plugins/vite/license.js +6 -6
  62. package/plugins/vite/local-files-analysis.d.ts +95 -0
  63. package/plugins/vite/local-files-analysis.js +2 -1
  64. package/plugins/vite/local-files-core.d.ts +51 -0
  65. package/plugins/vite/local-files-core.js +2 -2
  66. package/plugins/vite/local-files-internals.d.ts +3 -0
  67. package/plugins/vite/local-files-utils.d.ts +77 -0
  68. package/plugins/vite/local-files.d.ts +2 -0
  69. package/plugins/vite/logger.d.ts +8 -0
  70. package/plugins/vite/logger.js +1 -1
  71. package/plugins/vite/logging.d.ts +31 -0
  72. package/plugins/vite/meta.d.ts +7 -0
  73. package/plugins/vite/meta.js +4 -3
  74. package/plugins/vite/needle-app.d.ts +7 -0
  75. package/plugins/vite/needle-app.js +1 -1
  76. package/plugins/vite/npm.d.ts +4 -0
  77. package/plugins/vite/npm.js +1 -1
  78. package/plugins/vite/peer.d.ts +7 -0
  79. package/plugins/vite/peer.js +3 -1
  80. package/plugins/vite/poster-client.d.ts +1 -0
  81. package/plugins/vite/poster.d.ts +8 -0
  82. package/plugins/vite/poster.js +5 -2
  83. package/plugins/vite/pwa.d.ts +7 -0
  84. package/plugins/vite/pwa.js +4 -4
  85. package/plugins/vite/reload-client.d.ts +1 -0
  86. package/plugins/vite/reload.d.ts +7 -0
  87. package/plugins/vite/reload.js +7 -6
  88. package/plugins/vite/server.d.ts +7 -0
  89. package/plugins/vite/server.js +5 -5
  90. package/plugins/vite/transform-codegen.d.ts +8 -0
  91. package/plugins/vite/transform-codegen.js +6 -4
  92. package/plugins/vite/transform.d.ts +5 -0
  93. package/plugins/vite/transform.js +1 -1
  94. package/plugins/vite/vite-4.4-hack.d.ts +8 -0
  95. package/plugins/vite/vite-4.4-hack.js +1 -1
  96. package/src/engine-components/EventType.ts +13 -12
  97. package/src/engine-components/ReflectionProbe.ts +65 -20
  98. package/src/engine-components/VideoPlayer.ts +1 -1
  99. package/plugins/types/next.d.ts +0 -3
  100. package/plugins/types/vite.d.ts +0 -14
@@ -1,17 +1,21 @@
1
- import { CubeTexture, EquirectangularReflectionMapping, LinearSRGBColorSpace, Material, Object3D, Texture, Vector3 } from "three";
1
+ import { Box3, Color, CubeTexture, EquirectangularReflectionMapping, LinearSRGBColorSpace, LineSegments, Material, Object3D, Quaternion, Texture, Vector3 } from "three";
2
2
 
3
+ import { CreateWireCube } from "../engine/engine_gizmos.js";
3
4
  import { MaterialPropertyBlock } from "../engine/engine_materialpropertyblock.js";
4
5
  import { loadPMREM } from "../engine/engine_pmrem.js";
5
6
  import { serializable } from "../engine/engine_serialization.js";
6
7
  import { Context } from "../engine/engine_setup.js";
8
+ import { getBoundingBox, getWorldPosition } from "../engine/engine_three_utils.js";
7
9
  import { getParam, resolveUrl } from "../engine/engine_utils.js";
8
- import { BoxHelperComponent } from "./BoxHelperComponent.js";
9
10
  import { Behaviour } from "./Component.js";
10
11
  import { EventList } from "./EventList.js";
11
12
 
12
13
  export const debug = getParam("debugreflectionprobe");
13
14
  const disable = getParam("noreflectionprobe");
14
15
 
16
+ let box: Box3 | null = null;
17
+ const _identityRotation = new Quaternion();
18
+
15
19
  const $reflectionProbeKey = Symbol("reflectionProbeKey");
16
20
  /**
17
21
  * The [ReflectionProbe](https://engine.needle.tools/docs/api/ReflectionProbe) provides environment reflection data to materials within its defined area.
@@ -40,10 +44,11 @@ const $reflectionProbeKey = Symbol("reflectionProbeKey");
40
44
  export class ReflectionProbe extends Behaviour {
41
45
 
42
46
  private static _probes: Map<Context, ReflectionProbe[]> = new Map();
43
-
44
-
47
+ private static testBox: Box3 = new Box3();
48
+
45
49
  /**
46
- * Checks if the given material is currently using a reflection probe. This is determined by checking for an override on the material's "envMap" property, which is set by the Renderer component when applying a reflection probe.
50
+ * Checks if the given material is currently using a reflection probe.
51
+ * This is determined by checking for an override on the material's "envMap" property, which is set by the Renderer component when applying a reflection probe.
47
52
  */
48
53
  static isUsingReflectionProbe(material: Material) {
49
54
  return !!(material as any)[$reflectionProbeKey];
@@ -101,14 +106,17 @@ export class ReflectionProbe extends Behaviour {
101
106
  private _textureUrlInFlight?: string;
102
107
 
103
108
  /**
104
- * The cubemap or HDR texture used for reflections. Can be assigned directly or via a URL string. When assigning via URL, the texture will be loaded asynchronously and applied once ready.
109
+ * The cubemap or HDR texture used for reflections. Can be assigned directly or via a URL string.
110
+ * When assigning via URL, the texture will be loaded asynchronously and applied once ready.
111
+ * @param tex The texture or URL to assign to this reflection probe
112
+ * @default null
105
113
  */
106
114
  @serializable([Texture, String])
107
115
  set texture(tex: Texture | null) {
108
116
  if (this._texture === tex) return;
109
117
 
110
118
  if (typeof tex === "string") {
111
- if(debug) console.debug(`[ReflectionProbe] Loading reflection probe texture from URL: ${tex}`);
119
+ if (debug) console.debug(`[ReflectionProbe] Loading reflection probe texture from URL: ${tex}`);
112
120
  this._textureUrlInFlight = tex;
113
121
  const textureUrl = resolveUrl(this.sourceId, tex);
114
122
  loadPMREM(textureUrl, this.context.renderer).then(loaded => {
@@ -124,7 +132,7 @@ export class ReflectionProbe extends Behaviour {
124
132
  // During deserialization / loading of the GLB the deserializer sets an empty DataTexture
125
133
  // But if the texture is serialized as a string (via Blender Reflection Probes) then the async loading above
126
134
  // Will abort IF textureInFlight is reset (here). That's why we do NOT reset textureInFlight during initialization (when __didAwake is false). Only after awake, when we are sure that the async loading is done, we reset the in-flight URL to allow new assignments.
127
- if(this.__didAwake) this._textureUrlInFlight = undefined;
135
+ if (this.__didAwake) this._textureUrlInFlight = undefined;
128
136
 
129
137
  this._texture = tex;
130
138
 
@@ -144,30 +152,49 @@ export class ReflectionProbe extends Behaviour {
144
152
  return this._texture;
145
153
  }
146
154
 
155
+ /**
156
+ * The intensity of the reflection probe's influence.
157
+ * Higher values will make reflections brighter, while lower values will make them dimmer.
158
+ * The default value is 1, which means the reflections will be applied at their original brightness. Adjust this value to achieve the desired look for your scene.
159
+ * @default 1
160
+ */
147
161
  @serializable()
148
162
  intensity: number = 1;
149
163
 
150
164
  /**
151
- * Defines the center and size of the reflection probe's influence area.
165
+ * Defines the center of the reflection probe's influence area relative to the GameObject's position.
166
+ * The probe will affect objects within a box defined by this center and the `size` property.
167
+ * Note: The actual influence area is determined by both the `center` and `size` properties. The `center` defines the offset from the GameObject's position, while the `size` defines the dimensions of the box around that center. Objects within this box will be influenced by the reflection probe.
152
168
  */
153
169
  @serializable(Vector3)
154
- center?: Vector3;
170
+ center: Vector3 = new Vector3();
155
171
 
156
172
  /**
157
- * Defines the size of the reflection probe's influence area. Objects within this box will be affected by the probe's reflections.
173
+ * Defines the size of the reflection probe's influence area. Objects within this box will be affected by the probe's reflections.
174
+ * Note: The actual influence area is determined by both the `center` and `size` properties. The `center` defines the offset from the GameObject's position, while the `size` defines the dimensions of the box around that center. Objects within this box will be influenced by the reflection probe.
158
175
  */
159
176
  @serializable(Vector3)
160
- size?: Vector3;
177
+ size: Vector3 = new Vector3(1, 1, 1);
161
178
 
162
179
  /**
163
180
  * Workaround for lightmap. Compensates for the fact that lightmaps are pre-multiplied by intensity, while reflection probes are not. This means that if you use both lightmaps and reflection probes, you may need to adjust this value to get the correct balance between them. The default value of `Math.PI` is a good starting point for most cases, but you may need to tweak it based on your specific lighting setup and artistic needs.
164
181
  */
165
182
  __lightmapIntensityScale: boolean = true;
166
183
 
167
- private _boxHelper?: BoxHelperComponent;
168
184
 
169
185
  private isInBox(obj: Object3D) {
170
- return this._boxHelper?.isInBox(obj);
186
+
187
+ box ??= new Box3();
188
+ box!.setFromCenterAndSize(this.gameObject.worldPosition.add(this.center), this.gameObject.worldScale.multiply(this.size));
189
+
190
+ getBoundingBox([obj], undefined, undefined, ReflectionProbe.testBox);
191
+
192
+ if (ReflectionProbe.testBox.isEmpty()) {
193
+ return box.containsPoint(obj.worldPosition);
194
+ }
195
+ else {
196
+ return box?.intersectsBox(ReflectionProbe.testBox);
197
+ }
171
198
  }
172
199
 
173
200
  constructor() {
@@ -178,12 +205,15 @@ export class ReflectionProbe extends Behaviour {
178
205
  ReflectionProbe._probes.get(this.context)?.push(this);
179
206
  }
180
207
 
208
+ private _gizmo: LineSegments | null = null;
209
+ private _color: Color | null = null;
210
+
181
211
  /** @internal */
182
212
  awake() {
183
- this._boxHelper = this.gameObject.addComponent(BoxHelperComponent) as BoxHelperComponent;
184
- this._boxHelper.updateBox(true);
185
- if (debug)
186
- this._boxHelper.showHelper(0x555500, true);
213
+ if (debug) {
214
+ this._gizmo = CreateWireCube(0x555500);
215
+ this.gameObject.add(this._gizmo);
216
+ }
187
217
 
188
218
  if (this._texture) {
189
219
  this._texture.mapping = EquirectangularReflectionMapping;
@@ -192,6 +222,15 @@ export class ReflectionProbe extends Behaviour {
192
222
  }
193
223
  }
194
224
 
225
+ /** @internal */
226
+ update(): void {
227
+ if (this._gizmo) {
228
+ if (this.center) this._gizmo.position.copy(this.center);
229
+ if (this.size) this._gizmo.scale.copy(this.size);
230
+ this._gizmo.worldQuaternion = _identityRotation.identity();
231
+ }
232
+ }
233
+
195
234
  /** @internal */
196
235
  onEnable(): void {
197
236
  ReflectionProbe.onEnabled?.invoke(this);
@@ -221,7 +260,10 @@ export class ReflectionProbe extends Behaviour {
221
260
  }
222
261
 
223
262
  /**
224
- * Applies this reflection probe to the given object by setting material property overrides for "envMap", "envMapRotation", and "envMapIntensity". This is typically called by the Renderer component when determining which reflection probe to use for a given object.
263
+ * Applies this reflection probe to the given object by setting material property overrides for "envMap", "envMapRotation", and "envMapIntensity".
264
+ * This is typically called by the Renderer component when determining which reflection probe to use for a given object.
265
+ * @param object The object to apply the reflection probe to
266
+ * @see {@link unapply} for the corresponding method to remove the probe's influence from an object.
225
267
  */
226
268
  apply(object: Object3D) {
227
269
  if (disable) return;
@@ -240,7 +282,10 @@ export class ReflectionProbe extends Behaviour {
240
282
  }
241
283
 
242
284
  /**
243
- * Removes the reflection probe overrides from the given object. This is typically called by the Renderer component when an object is no longer influenced by this probe or when the probe is disabled.
285
+ * Removes the reflection probe overrides from the given object.
286
+ * This is typically called by the Renderer component when an object is no longer influenced by this probe or when the probe is disabled.
287
+ * @param object The object to remove the reflection probe overrides from
288
+ * @see {@link apply} for the corresponding method to apply the probe's influence to an object.
244
289
  */
245
290
  unapply(obj: Object3D) {
246
291
  const block = MaterialPropertyBlock.get(obj);
@@ -143,7 +143,7 @@ export class VideoPlayer extends Behaviour {
143
143
  private _url: string | null = null;
144
144
 
145
145
  @serializable()
146
- private renderMode?: VideoRenderMode;
146
+ private renderMode: VideoRenderMode = VideoRenderMode.MaterialOverride;
147
147
 
148
148
  @serializable()
149
149
  private targetMaterialProperty?: string;
@@ -1,3 +0,0 @@
1
- import { userSettings } from './userconfig.js';
2
-
3
- export declare function needleNext(nextConfig?: import('next').NextConfig, userSettings?: userSettings): Promise<import('next').NextConfig>;
@@ -1,14 +0,0 @@
1
- import { needleConfig, needleMeta } from "./needleConfig.d.ts";
2
- import { userSettings } from "./userconfig.d.ts";
3
-
4
- export declare function needlePlugins(command: import("vite").ConfigEnv["command"], meta?: needleMeta | null, userSettings?: userSettings): Promise<any>;
5
-
6
- /**
7
- * Loads the generated needle meta file
8
- */
9
- export declare function loadConfig(path: string | null = null): Promise<needleMeta | null>;
10
-
11
- /**
12
- * Returns true if the project is configured to use gzip compression
13
- */
14
- export declare function useGzip(config?: needleConfig): boolean;