Needle Engine

Changes between version 3.6.1-beta and 3.6.2-beta
Files changed (9) hide show
  1. src/engine-components/export/usdz/extensions/behavior/AudioExtension.ts +2 -0
  2. src/engine/debug/debug_overlay.ts +6 -1
  3. src/engine/debug/debug.ts +2 -2
  4. src/engine/engine_addressables.ts +12 -0
  5. src/engine/engine_assetdatabase.ts +8 -1
  6. src/engine/engine_license.ts +25 -2
  7. src/needle-engine.ts +0 -3
  8. src/engine-components/NestedGltf.ts +11 -2
  9. src/engine-components/export/usdz/ThreeUSDZExporter.ts +3 -2
src/engine-components/export/usdz/extensions/behavior/AudioExtension.ts CHANGED
@@ -17,6 +17,8 @@
17
17
  const audioSources = GameObject.getComponents(object, AudioSource);
18
18
  if (audioSources.length) {
19
19
  for (const audioSource of audioSources) {
20
+
21
+ if (!audioSource.clip) continue;
20
22
 
21
23
  // do nothing if this audio source is not set to play on awake -
22
24
  // should be controlled via PlayAudioOnClick instead then.
src/engine/debug/debug_overlay.ts CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
  const debug = getParam("debugdebug");
8
- const hide = getParam("noerrors");
8
+ let hide = getParam("noerrors");
9
9
 
10
10
  const arContainerClassName = "ar";
11
11
  const globalErrorContainerKey = "needle_engine_global_error_container";
@@ -21,6 +21,11 @@
21
21
  return errorCount;
22
22
  }
23
23
 
24
+ /** Set false to prevent overlay messages from being shown */
25
+ export function setAllowOverlayMessages(allow: boolean) {
26
+ hide = !allow;
27
+ }
28
+
24
29
  export function makeErrorsVisibleForDevelopment() {
25
30
  if (hide) return;
26
31
  const isLocal = isLocalNetwork();
src/engine/debug/debug.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { addLog, LogType } from "./debug_overlay";
1
+ import { addLog, LogType, setAllowOverlayMessages } from "./debug_overlay";
2
2
  import { showDebugConsole } from "./debug_console";
3
3
  import { isLocalNetwork } from "../engine_networking_utils";
4
4
 
5
5
  export { showDebugConsole }
6
- export { LogType };
6
+ export { LogType, setAllowOverlayMessages };
7
7
 
8
8
  /** Displays a debug message on screen for a certain amount of time */
9
9
  export function showBalloonMessage(text: string, logType: LogType = LogType.Log) {
src/engine/engine_addressables.ts CHANGED
@@ -59,6 +59,8 @@
59
59
 
60
60
  export type ProgressCallback = (asset: AssetReference, prog: ProgressEvent) => void;
61
61
 
62
+ const $assetReference = Symbol("assetReference");
63
+
62
64
  export class AssetReference {
63
65
 
64
66
  static getOrCreate(sourceId: SourceIdentifier, url: string, context: Context): AssetReference {
@@ -191,6 +193,16 @@
191
193
  this._glbRoot = this.tryGetActualGameObjectRoot(res);
192
194
  this._loading = undefined;
193
195
  if (res) {
196
+
197
+ // Make sure the loaded roots all have a reference to this AssetReference
198
+ // that was originally loading it.
199
+ // We need this when the loaded asset is being disposed
200
+ // TODO: we have to prevent disposing resources that are still in use
201
+ res[$assetReference] = this;
202
+ if (this._glbRoot)
203
+ this._glbRoot[$assetReference] = this;
204
+ if (this.asset) this.asset[$assetReference] = this;
205
+
194
206
  // we need to handle the pre_setup callsbacks before instantiating
195
207
  // because that is where deserialization happens
196
208
  processNewScripts(context);
src/engine/engine_assetdatabase.ts CHANGED
@@ -40,9 +40,14 @@
40
40
  export function setDisposable(obj: object | null | undefined, disposable: boolean) {
41
41
  if (!obj) return;
42
42
  obj[$disposable] = disposable;
43
- if(debug) console.warn("Set disposable", disposable, obj);
43
+ if (debug) console.warn("Set disposable", disposable, obj);
44
44
  }
45
45
 
46
+ const $disposed = Symbol("disposed");
47
+ export function isDisposed(obj: object) {
48
+ return obj[$disposed] === true;
49
+ }
50
+
46
51
  /** Recursive disposes all referenced resources by this object. Does not traverse children */
47
52
  export function disposeObjectResources(obj: object | null | undefined) {
48
53
  if (!obj) return;
@@ -51,6 +56,8 @@
51
56
  return;
52
57
  }
53
58
 
59
+ obj[$disposed] = true;
60
+
54
61
  if (obj instanceof Scene) {
55
62
  disposeObjectResources(obj.environment);
56
63
  disposeObjectResources(obj.background);
src/engine/engine_license.ts CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  // This is modified by a bundler (e.g. vite)
9
9
  // Do not edit manually
10
- const NEEDLE_ENGINE_LICENSE_TYPE: string = "basic";
10
+ let NEEDLE_ENGINE_LICENSE_TYPE: string = "basic";
11
11
  if (debug) console.log("License Type: " + NEEDLE_ENGINE_LICENSE_TYPE)
12
12
 
13
13
  export function hasProLicense() {
@@ -36,6 +36,27 @@
36
36
  showLicenseInfo(evt.context);
37
37
  });
38
38
 
39
+ let licenseCheckPromise: Promise<void>;
40
+ async function checkLicense() {
41
+ if (NEEDLE_ENGINE_LICENSE_TYPE === "basic") {
42
+ try {
43
+ const licenseUrl = "https://engine.needle.tools/licensing/check";
44
+ const res = await fetch(licenseUrl);
45
+ if (debug) {
46
+ const text = await res.text();
47
+ console.log("\"" + text + "\"\n", res);
48
+ }
49
+ if (res.status === 200) {
50
+ NEEDLE_ENGINE_LICENSE_TYPE = "pro";
51
+ }
52
+ }
53
+ catch (err) {
54
+ if (debug) console.error("License check failed", err);
55
+ }
56
+ }
57
+ }
58
+ licenseCheckPromise = checkLicense();
59
+
39
60
  async function showLicenseInfo(ctx: IContext) {
40
61
  try {
41
62
  if (hasCommercialLicense() !== true) return onNonCommercialVersionDetected(ctx);
@@ -52,7 +73,9 @@
52
73
  const licenseDuration = 5000;
53
74
  const licenseDelay = 200;
54
75
 
55
- function onNonCommercialVersionDetected(ctx: IContext) {
76
+ async function onNonCommercialVersionDetected(ctx: IContext) {
77
+ await licenseCheckPromise;
78
+ if (hasCommercialLicense()) return;
56
79
  logNonCommercialUse();
57
80
  ctx.domElement.addEventListener("ready", () => {
58
81
  setTimeout(()=>{
src/needle-engine.ts CHANGED
@@ -47,6 +47,3 @@
47
47
  }
48
48
  else console.warn("Threejs is already imported");
49
49
 
50
-
51
-
52
- import "./engine/engine_license";
src/engine-components/NestedGltf.ts CHANGED
@@ -34,7 +34,7 @@
34
34
  opts.parent = parent;
35
35
  this.gameObject.updateMatrix();
36
36
  const matrix = this.gameObject.matrix;
37
- if (debug) console.log("Load nested:", this.filePath?.uri ?? this.filePath, this.gameObject.position)
37
+ if (debug) console.log("Load nested:", this.filePath?.uri ?? this.filePath, this.gameObject.position);
38
38
  const res = await this.filePath?.instantiate?.call(this.filePath, opts);
39
39
  if (res) {
40
40
  res.matrixAutoUpdate = false;
@@ -44,11 +44,20 @@
44
44
  res.layers.disableAll();
45
45
  res.layers.set(this.layer);
46
46
  }
47
- this.destroy();
48
47
  if (debug) console.log("Nested loading done:", this.filePath?.uri ?? this.filePath, res);
49
48
  }
50
49
  }
51
50
 
51
+ onDestroy(): void {
52
+ // When the NestedGLTF gets destroyed we assume the loaded glTF is also destroyed
53
+ // meaning the resources, textures etc are disposed
54
+ // When this NestedGLTF would now be loaded again the AssetReference would still be in the loaded state
55
+ // so it would instantiate without textures etc...
56
+ // Perhaps we want to add a dispose callback or event method too?
57
+ // Somehow we have to clean the AssetReference state
58
+ this.filePath?.unload();
59
+ }
60
+
52
61
  hash(str: string): number {
53
62
  let hash = 0;
54
63
  for (let i = 0; i < str.length; i++) {
src/engine-components/export/usdz/ThreeUSDZExporter.ts CHANGED
@@ -477,7 +477,7 @@
477
477
 
478
478
  if ( canvas ) {
479
479
 
480
- const blob = await new Promise( resolve => canvas.toBlob( resolve, isRGBA ? 'image/png' : 'image/jpeg', 1 ) ) as any;
480
+ const blob = await new Promise( resolve => canvas.toBlob( resolve, isRGBA ? 'image/png' : 'image/jpeg', 0.95 ) ) as any;
481
481
  files[ `textures/Texture_${id}.${isRGBA ? 'png' : 'jpg'}` ] = new Uint8Array( await blob.arrayBuffer() );
482
482
 
483
483
  } else {
@@ -788,7 +788,8 @@
788
788
 
789
789
  if ( isImageBitmap( image ) ) {
790
790
 
791
- const scale = 1024 / Math.max( image.width, image.height );
791
+ // max. canvas size on Safari is still 4096x4096
792
+ const scale = 4096 / Math.max( image.width, image.height );
792
793
 
793
794
  const canvas = document.createElement( 'canvas' );
794
795
  canvas.width = image.width * Math.min( 1, scale );