Needle Engine

Changes between version 3.10.0-beta.2 and 3.10.1-beta
Files changed (5) hide show
  1. src/engine-components/DragControls.ts +2 -0
  2. src/engine/engine_element_loading.ts +31 -13
  3. src/engine/engine_input.ts +1 -1
  4. src/engine/engine_license.ts +12 -5
  5. src/engine-components/SpatialTrigger.ts +3 -3
src/engine-components/DragControls.ts CHANGED
@@ -65,6 +65,8 @@
65
65
  this._dragDelta = new Vector2();
66
66
  }
67
67
 
68
+
69
+ // TODO: Update DragEventListener code
68
70
  addDragEventListener(type: DragEvents, cb: (ctrls: DragControls, args: SelectArgs) => void | Function) {
69
71
  switch (type) {
70
72
  case DragEvents.SelectStart:
src/engine/engine_element_loading.ts CHANGED
@@ -3,10 +3,11 @@
3
3
  import { LoadingProgressArgs } from "./engine_setup";
4
4
  import { getParam } from "./engine_utils";
5
5
  import { logoSVG } from "./assets"
6
- import { hasCommercialLicense, hasProLicense } from "./engine_license";
6
+ import { hasCommercialLicense, hasProLicense, runtimeLicenseCheckPromise } from "./engine_license";
7
7
 
8
8
  const debug = getParam("debugloading");
9
9
  const debugRendering = getParam("debugloadingrendering");
10
+ const debugLicense = getParam("debuglicense");
10
11
 
11
12
  declare type LoadingStyleOption = "dark" | "light";
12
13
 
@@ -16,10 +17,10 @@
16
17
  }
17
18
 
18
19
  export interface ILoadingViewHandler {
19
- onLoadingBegin(message?: string);
20
+ onLoadingBegin(message?: string)
20
21
  onLoadingUpdate(progress: LoadingProgressArgs | number, message?: string);
21
22
  onLoadingFinished(message?: string);
22
- setMessage(string:string);
23
+ setMessage(string: string);
23
24
  }
24
25
 
25
26
  let currentFileProgress = 0;
@@ -73,7 +74,7 @@
73
74
  this._loadingElementOptions = opts;
74
75
  }
75
76
 
76
- onLoadingBegin(message?: string) {
77
+ async onLoadingBegin(message?: string) {
77
78
  const _element = this._element.shadowRoot || this._element;
78
79
  if (debug) console.warn("Begin Loading")
79
80
  if (!this._loadingElement) {
@@ -172,7 +173,7 @@
172
173
  this._loadingTextContainer.textContent = percent;
173
174
  }
174
175
 
175
- private createLoadingElement(existing?: HTMLElement): HTMLElement {
176
+ private createLoadingElement(existing?: HTMLElement) {
176
177
  if (debug && !existing) console.log("Creating loading element");
177
178
  this._loadingElement = existing || document.createElement("div");
178
179
 
@@ -249,7 +250,7 @@
249
250
  logo.src = customLogo;
250
251
  }
251
252
  }
252
- this._loadingElement.appendChild(logo);
253
+ this._loadingElement.appendChild(logo);
253
254
  this._loadingElement.appendChild(loadingBarContainer);
254
255
 
255
256
 
@@ -301,14 +302,31 @@
301
302
  }
302
303
  }
303
304
 
304
- if (!hasCommercialLicense()) {
305
- const nonCommercialContainer = document.createElement("div");
306
- nonCommercialContainer.style.paddingTop = ".6em";
307
- nonCommercialContainer.style.fontSize = ".8em";
308
- nonCommercialContainer.innerText = "NON COMMERCIAL";
309
- this._loadingElement.appendChild(nonCommercialContainer);
310
- }
305
+ this.handleRuntimeLicense(this._loadingElement);
311
306
 
312
307
  return this._loadingElement;
313
308
  }
309
+
310
+ private async handleRuntimeLicense(loadingElement: HTMLElement) {
311
+ // First check if we have a commercial license
312
+ let commercialLicense = hasCommercialLicense();
313
+ // if it's the case then we don't need to perform a runtime check
314
+ if (commercialLicense) return;
315
+
316
+ // Use the runtime license check
317
+ if (runtimeLicenseCheckPromise) {
318
+ if (debugLicense) console.log("Waiting for runtime license check");
319
+ await runtimeLicenseCheckPromise;
320
+ commercialLicense = hasCommercialLicense();
321
+ }
322
+ if (commercialLicense) return;
323
+
324
+ // If we don't have a commercial license, then we need to display our message
325
+ if (debugLicense) console.log("Loading UI has commercial license?", commercialLicense);
326
+ const nonCommercialContainer = document.createElement("div");
327
+ nonCommercialContainer.style.paddingTop = ".6em";
328
+ nonCommercialContainer.style.fontSize = ".8em";
329
+ nonCommercialContainer.innerText = "NON COMMERCIAL";
330
+ loadingElement.appendChild(nonCommercialContainer);
331
+ }
314
332
  }
src/engine/engine_input.ts CHANGED
@@ -532,7 +532,7 @@
532
532
  const diff = (upTime - evt.source.timeStamp);
533
533
  // on android touch up and mouse up have the exact same value
534
534
  // but on iOS they are not the same but a few milliseconds apart
535
- if (diff < 30) {
535
+ if (diff < 30 && diff > 0) {
536
536
  // we received an UP event for a touch, ignore this DOWN event
537
537
  if (debug) console.log("Ignoring mouse.down for touch.up");
538
538
  return;
src/engine/engine_license.ts CHANGED
@@ -38,26 +38,33 @@
38
38
  sendUsageMessageToAnalyticsBackend();
39
39
  });
40
40
 
41
- let licenseCheckPromise: Promise<void>;
41
+ export let runtimeLicenseCheckPromise: Promise<void>;
42
42
  async function checkLicense() {
43
+ // Only perform the runtime license check once
44
+ if (runtimeLicenseCheckPromise) return runtimeLicenseCheckPromise;
43
45
  if (NEEDLE_ENGINE_LICENSE_TYPE === "basic") {
44
46
  try {
45
47
  const licenseUrl = "https://engine.needle.tools/licensing/check";
46
48
  const res = await fetch(licenseUrl);
47
49
  if (debug) {
48
50
  const text = await res.text();
49
- console.log("\"" + text + "\"\n", res);
51
+ console.log("Response: \"" + text + "\"\n", res);
50
52
  }
51
53
  if (res.status === 200) {
54
+ if(debug) console.log("License check succeeded");
52
55
  NEEDLE_ENGINE_LICENSE_TYPE = "pro";
53
56
  }
57
+ else {
58
+ if (debug) console.log("License check failed with status " + res.status);
59
+ }
54
60
  }
55
61
  catch (err) {
56
62
  if (debug) console.error("License check failed", err);
57
63
  }
58
64
  }
65
+ else if (debug) console.log("Runtime license check is skipped because license is already applied as \"" + NEEDLE_ENGINE_LICENSE_TYPE + "\"");
59
66
  }
60
- licenseCheckPromise = checkLicense();
67
+ runtimeLicenseCheckPromise = checkLicense();
61
68
 
62
69
  async function showLicenseInfo(ctx: IContext) {
63
70
  try {
@@ -76,11 +83,11 @@
76
83
  const licenseDelay = 200;
77
84
 
78
85
  async function onNonCommercialVersionDetected(ctx: IContext) {
79
- await licenseCheckPromise;
86
+ await runtimeLicenseCheckPromise;
80
87
  if (hasCommercialLicense()) return;
81
88
  logNonCommercialUse();
82
89
  ctx.domElement.addEventListener("ready", () => {
83
- setTimeout(()=>{
90
+ setTimeout(() => {
84
91
  insertNonCommercialUseHint(ctx);
85
92
  }, 1000);
86
93
  });
src/engine-components/SpatialTrigger.ts CHANGED
@@ -63,17 +63,17 @@
63
63
  onEnterTrigger(trigger: SpatialTrigger): void {
64
64
  if(debug) console.log("ENTER TRIGGER", this.name, trigger.name, this, trigger);
65
65
  trigger.raiseOnEnterEvent(this);
66
- this.onEnter?.invoke();
66
+ this.onEnter?.invoke(this, trigger);
67
67
  }
68
68
  onExitTrigger(trigger: SpatialTrigger): void {
69
69
  if(debug) console.log("EXIT TRIGGER", this.name, trigger.name, this, trigger);
70
70
  trigger.raiseOnExitEvent(this);
71
- this.onExit?.invoke();
71
+ this.onExit?.invoke(this, trigger);
72
72
  }
73
73
 
74
74
  onStayTrigger(trigger: SpatialTrigger): void {
75
75
  trigger.raiseOnStayEvent(this);
76
- this.onStay?.invoke();
76
+ this.onStay?.invoke(this, trigger);
77
77
  }
78
78
  }