Needle Engine

Changes between version 4.4.2 and 4.4.3-beta
Files changed (6) hide show
  1. plugins/next/license.cjs +10 -4
  2. plugins/common/license.js +20 -10
  3. plugins/next/next.js +9 -1
  4. src/engine/engine_input.ts +47 -7
  5. src/engine/engine_license.ts +1 -1
  6. src/engine-components/SyncedTransform.ts +1 -1
plugins/next/license.cjs CHANGED
@@ -4,16 +4,22 @@
4
4
 
5
5
  module.exports = async function (source, _map) {
6
6
 
7
+ /** @ts-ignore */
8
+ const options = this.getOptions();
9
+
7
10
  /** @type {string | undefined} */
8
- let team = undefined;
11
+ let team = options.team;
9
12
 
10
- const meta = await getMeta();
11
- if (meta) {
12
- team = meta.license?.team;
13
+ if (!team) {
14
+ const meta = await getMeta();
15
+ if (meta) {
16
+ team = meta.license?.team;
17
+ }
13
18
  }
14
19
 
15
20
  // console.log("RESOLVE LICENSE...");
16
21
  return (await mod).replaceLicense(source, {
22
+ accessToken: options.accessToken,
17
23
  team: team,
18
24
  });
19
25
  };
plugins/common/license.js CHANGED
@@ -43,13 +43,14 @@
43
43
  export async function resolveLicense(args = null) {
44
44
  let accessToken = args?.accessToken;
45
45
 
46
- if (!accessToken && process.env.CI) {
46
+ // If a process.env.NEEDLE_CLOUD_TOKEN is set we want to use this (e.g. via nextjs)
47
+ if (!accessToken) {
47
48
  if (process.env.NEEDLE_CLOUD_TOKEN) {
48
- console.log("[needle-license] INFO: Using Needle Cloud access token from environment variable");
49
+ console.log("[needle-license] INFO: Using Needle Cloud access token from NEEDLE_CLOUD_TOKEN environment variable");
49
50
  accessToken = process.env.NEEDLE_CLOUD_TOKEN;
50
51
  }
51
- else {
52
- console.warn("[needle-license] WARN: Missing NEEDLE_CLOUD_TOKEN for CI environment run");
52
+ else if (process.env.CI) {
53
+ console.warn("[needle-license] WARN: Missing NEEDLE_CLOUD_TOKEN for CI environment");
53
54
  }
54
55
  }
55
56
 
@@ -92,8 +93,8 @@
92
93
  console.warn(message);
93
94
  return null;
94
95
  }
95
- else if (isStackblitz()) {
96
- console.error("[needle-license] License server is not available in Stackblitz. Please use an access token for authorization.");
96
+ else if (!canRunCLI(args)) {
97
+ console.error("[needle-license] License server CLI is not available. Please use an access token for authorization.");
97
98
  return null;
98
99
  }
99
100
 
@@ -237,8 +238,8 @@
237
238
  return null;
238
239
  }
239
240
  }
240
- else if (isStackblitz()) {
241
- console.error("[needle-license] License server is not available in Stackblitz. Please use an access token for authorization.");
241
+ else if (!canRunCLI(opts)) {
242
+ console.error("[needle-license] License server CLI is not available. Please use an access token for authorization.");
242
243
  return null;
243
244
  }
244
245
 
@@ -355,8 +356,17 @@
355
356
  }
356
357
 
357
358
 
358
- function isStackblitz() {
359
- return existsSync("/home/.stackblitz")
359
+ /**
360
+ * @param {DefaultOptions | undefined | null} opts
361
+ */
362
+ function canRunCLI(opts) {
363
+ // Note: the .stackblitz directory doesnt always exist it seems
364
+ if (existsSync("/home/.stackblitz")) {
365
+ if (opts?.loglevel === "verbose") console.log("[needle-license] INFO: Running in Stackblitz environment");
366
+ return false;
367
+ }
368
+ // Default to true:
369
+ return true;
360
370
  }
361
371
 
362
372
  /**
plugins/next/next.js CHANGED
@@ -89,10 +89,18 @@
89
89
 
90
90
  if (!config.module) config.module = {};
91
91
  if (!config.module.rules) config.module.rules = [];
92
+
93
+
92
94
  // add license plugin
95
+ const team_id = userSettings?.license?.team || undefined;
96
+
93
97
  config.module.rules.push({
94
98
  test: /engine_license\.(ts|js)$/,
95
- loader: resolve(__dirname, 'license.cjs')
99
+ loader: resolve(__dirname, `license.cjs`),
100
+ options: {
101
+ team: team_id,
102
+ accessToken: userSettings?.license?.accessToken,
103
+ }
96
104
  });
97
105
  // add mesh bvh worker transform
98
106
  config.module.rules.push({
src/engine/engine_input.ts CHANGED
@@ -671,15 +671,30 @@
671
671
  }
672
672
 
673
673
 
674
-
675
- getKeyDown(): string | null {
674
+ /** Get a key (if any) that was just pressed this frame (this is only true for the frame it was pressed down) */
675
+ getKeyDown(): string | null;
676
+ /** Get true or false if the given key was pressed this frame */
677
+ getKeyDown(key: KeyCode | ({} & string)): boolean;
678
+ getKeyDown(key?: KeyCode | ({} & string)): boolean | string | null {
679
+ // If a key is provided check if it was pressed this frame
680
+ if (key !== undefined) {
681
+ return this.isKeyDown(key);
682
+ }
683
+ // If no key was provided get the first key that was pressed this frame
676
684
  for (const key in this.keysPressed) {
677
685
  const k = this.keysPressed[key];
678
686
  if (k.startFrame === this.context.time.frameCount) return k.key;
679
687
  }
680
688
  return null;
681
689
  }
682
- getKeyPressed(): string | null {
690
+ /** Get a key (if any) that is currently being pressed (held down) */
691
+ getKeyPressed(): string | null;
692
+ /** Get true or false if the given key is pressed */
693
+ getKeyPressed(key: KeyCode | ({} & string)): boolean
694
+ getKeyPressed(key?: KeyCode | ({} & string)): boolean | string | null {
695
+ if (key !== undefined) {
696
+ return this.isKeyPressed(key);
697
+ }
683
698
  for (const key in this.keysPressed) {
684
699
  const k = this.keysPressed[key];
685
700
  if (k.pressed)
@@ -687,6 +702,25 @@
687
702
  }
688
703
  return null;
689
704
  }
705
+
706
+ /** Get a key (if any) that was released in this frame */
707
+ getKeyUp(): string | null;
708
+ /** Get true or false if the given key was released this frame */
709
+ getKeyUp(key: KeyCode | ({} & string)): boolean;
710
+ getKeyUp(key?: KeyCode | ({} & string)): boolean | string | null {
711
+
712
+ if (key !== undefined) {
713
+ return this.isKeyUp(key);
714
+ }
715
+ for (const key in this.keysPressed) {
716
+ const k = this.keysPressed[key];
717
+ if (k.pressed === false && k.frame === this.context.time.frameCount) return true;
718
+ return false;
719
+ }
720
+
721
+ return null;
722
+ }
723
+
690
724
  isKeyDown(keyCode: KeyCode | ({} & string)) {
691
725
  if (!this.context.application.isVisible || !this.context.application.hasFocus) return false;
692
726
  const codes = this.getCodeForCommonKeyName(keyCode);
@@ -694,7 +728,9 @@
694
728
  for (const code of codes) if (this.isKeyDown(code)) return true;
695
729
  return false;
696
730
  }
697
- return this.keysPressed[keyCode]?.startFrame === this.context.time.frameCount && this.keysPressed[keyCode].pressed;
731
+ const k = this.keysPressed[keyCode];
732
+ if (!k) return false;
733
+ return k.startFrame === this.context.time.frameCount && k.pressed;
698
734
  }
699
735
  isKeyUp(keyCode: KeyCode | ({} & string)) {
700
736
  if (!this.context.application.isVisible || !this.context.application.hasFocus) return false;
@@ -703,16 +739,20 @@
703
739
  for (const code of codes) if (this.isKeyUp(code)) return true;
704
740
  return false;
705
741
  }
706
- return this.keysPressed[keyCode]?.frame === this.context.time.frameCount && !this.keysPressed[keyCode].pressed;
742
+ const k = this.keysPressed[keyCode];
743
+ if (!k) return false;
744
+ return k.frame === this.context.time.frameCount && k.pressed === false;
707
745
  }
708
- isKeyPressed(keyCode: KeyCode | ({} & string)) {
746
+ isKeyPressed(keyCode: KeyCode | ({} & string)): boolean {
709
747
  if (!this.context.application.isVisible || !this.context.application.hasFocus) return false;
710
748
  const codes = this.getCodeForCommonKeyName(keyCode);
711
749
  if (codes !== null) {
712
750
  for (const code of codes) if (this.isKeyPressed(code)) return true;
713
751
  return false;
714
752
  }
715
- return this.keysPressed[keyCode]?.pressed;// && time.frameCount - this.keysPressed[keyCode].frame < 100;
753
+ const k = this.keysPressed[keyCode];
754
+ if (!k) return false;
755
+ return k.pressed || false;
716
756
  }
717
757
 
718
758
  // utility helper for mapping common names to actual codes; e.g. "Shift" -> "ShiftLeft" and "ShiftRight" or "a" -> "KeyA"
src/engine/engine_license.ts CHANGED
@@ -232,7 +232,7 @@
232
232
  padding-left: 30px;
233
233
  `;
234
234
  if (NEEDLE_ENGINE_LICENSE_TYPE === "edu") {
235
- console.log("%c " + "Supported by Needle for Education – https://needle.tools", style);
235
+ console.log("%c " + "This project is supported by Needle for Education – https://needle.tools", style);
236
236
  }
237
237
  else {
238
238
  // if the user has a basic license we already show the logo in the menu and log a license message
src/engine-components/SyncedTransform.ts CHANGED
@@ -321,7 +321,7 @@
321
321
 
322
322
  if (this._model && !this._model.hasOwnership && this._model.isOwned) {
323
323
  if (this._receivedDataBefore) {
324
- const t = this._receivedFastUpdate || this.fastMode ? .05 : .3;
324
+ const t = this._receivedFastUpdate || this.fastMode ? .5 : .3;
325
325
  let requireMarkDirty = false;
326
326
  if (this.interpolatePosition && this._targetPosition) {
327
327
  const pos = this.worldPosition;