Needle Engine

Changes between version 3.7.6-beta and 3.7.7-beta
Files changed (5) hide show
  1. plugins/vite/vite-4.4-hack.js +25 -16
  2. src/engine-components/DragControls.ts +7 -8
  3. src/engine-components/utils/LookAt.ts +8 -1
  4. src/engine-components/ui/PointerEvents.ts +6 -0
  5. src/engine-components/Renderer.ts +8 -7
plugins/vite/vite-4.4-hack.js CHANGED
@@ -1,29 +1,38 @@
1
1
  import path from 'path';
2
- import { readFileSync, writeFileSync } from 'fs';
3
- import { exec, execSync } from 'child_process';
2
+ import { readFileSync, realpathSync, writeFileSync } from 'fs';
3
+ import { execSync } from 'child_process';
4
4
 
5
5
  /**
6
+ * Make sure we dont have vite 4.4.x installed when needle engine is used locally
6
7
  * @param {import('../types').userSettings} userSettings
7
8
  */
8
9
  export const vite_4_4_hack = (command, config, userSettings) => {
9
- if (userSettings.vite44Hack !== true) return;
10
+ // if (userSettings.vite44Hack !== true) return;
10
11
  return {
11
12
  name: "needle-vite-4.4-hack",
12
13
  async configureServer(server) {
14
+ // Check if this plugin should run
13
15
  const dir = process.cwd();
14
- const packageJsonPath = path.join(dir, "package.json");
15
- const currentPackageJson = readFileSync(packageJsonPath, "utf8");
16
- if (currentPackageJson.includes('"vite": "^4.3.4"')) {
17
- // see https://github.com/vitejs/vite/issues/13736
18
- console.log("Detected problematic vite version: Vite 4.4.x does currently have problems with typescript decorators. Switching to 4.3.9...")
19
- const newPackageJson = currentPackageJson.replace('"vite": "^4.3.4"', '"vite": "<= 4.3.9"');
20
- writeFileSync(packageJsonPath, newPackageJson, "utf8");
21
- // stop current server
22
- await server.close();
23
- // re-install with the limited package version
24
- execSync("npm install", { stdio: "inherit", cwd: dir });
25
- // start again
26
- execSync("npm start", { stdio: "inherit", cwd: dir });
16
+ const needleEngineDirectory = path.join(dir, "node_modules", "@needle-tools", "engine");
17
+ const resolveSymlink = realpathSync(needleEngineDirectory);
18
+ // this issue only arises when the engine is installed locally
19
+ const isSymlink = resolveSymlink !== needleEngineDirectory;
20
+
21
+ if (userSettings.vite44Hack === true || isSymlink) {
22
+ const packageJsonPath = path.join(dir, "package.json");
23
+ const currentPackageJson = readFileSync(packageJsonPath, "utf8");
24
+ if (currentPackageJson.includes('"vite": "^4.3.4"')) {
25
+ // see https://github.com/vitejs/vite/issues/13736
26
+ console.log("Detected problematic vite version: Vite 4.4.x does currently have problems with typescript decorators. Switching to 4.3.9...")
27
+ const newPackageJson = currentPackageJson.replace('"vite": "^4.3.4"', '"vite": "<= 4.3.9"');
28
+ writeFileSync(packageJsonPath, newPackageJson, "utf8");
29
+ // stop current server
30
+ await server.close();
31
+ // re-install with the limited package version
32
+ execSync("npm install", { stdio: "inherit", cwd: dir });
33
+ // start again
34
+ execSync("npm start", { stdio: "inherit", cwd: dir });
35
+ }
27
36
  }
28
37
  },
29
38
  }
src/engine-components/DragControls.ts CHANGED
@@ -108,8 +108,9 @@
108
108
  DragControls._active += 1;
109
109
  this._dragDelta.set(0, 0);
110
110
  this._didDrag = false;
111
- this._waitingForDragStart = args;
112
- args.StopPropagation();
111
+ // Clone to not modify the original event (and this event is used in the actual onDragStart method)
112
+ this._waitingForDragStart = args.clone();
113
+ args.stopPropagation();
113
114
  // disabling pointer controls here already, otherwise we get a few frames of movement event in orbit controls and this will rotate the camera sligthly AFTER drag controls dragging ends.
114
115
  if (this.orbit) this.orbit.enabled = false;
115
116
  }
@@ -117,11 +118,11 @@
117
118
  onPointerUp(args: PointerEventData) {
118
119
  this._waitingForDragStart = null;
119
120
  if (!this.allowEdit(this.gameObject)) return;
120
- if(DragControls._active > 0)
121
+ if (DragControls._active > 0)
121
122
  DragControls._active -= 1;
122
123
  if (WebXR.IsInWebXR) return;
123
124
  this.onDragEnd(args);
124
- args.StopPropagation();
125
+ args.stopPropagation();
125
126
  if (this.orbit) this.orbit.enabled = true;
126
127
  }
127
128
 
@@ -131,7 +132,6 @@
131
132
 
132
133
  // drag start only after having dragged for some pixels
133
134
  if (this._waitingForDragStart) {
134
-
135
135
  if (!this._didDrag) {
136
136
  // this is so we can e.g. process clicks without having a drag change the position
137
137
  // e.g. a click to rotate the object
@@ -142,7 +142,6 @@
142
142
  this._didDrag = true;
143
143
  else return;
144
144
  }
145
-
146
145
  const args = this._waitingForDragStart;
147
146
  this._waitingForDragStart = null;
148
147
  this.onDragStart(args);
@@ -247,7 +246,7 @@
247
246
  if (!this || !this._isDragging) return;
248
247
  this._isDragging = false;
249
248
  if (!this._dragHelper) return;
250
- for(const rb of this._draggingRigidbodies){
249
+ for (const rb of this._draggingRigidbodies) {
251
250
  rb.setVelocity(rb.smoothedVelocity);
252
251
  }
253
252
  this._draggingRigidbodies.length = 0;
@@ -336,7 +335,7 @@
336
335
  for (const rb of this._rbs) {
337
336
  rb.wakeUp();
338
337
  // if (!rb.smoothedVelocity) continue;
339
- rb.setVelocity(0,0,0);
338
+ rb.setVelocity(0, 0, 0);
340
339
  }
341
340
  }
342
341
 
src/engine-components/utils/LookAt.ts CHANGED
@@ -34,8 +34,15 @@
34
34
  if (this.keepUpDirection)
35
35
  lookTarget.y = lookFrom.y;
36
36
 
37
- if (this.copyTargetRotation)
37
+ if (this.copyTargetRotation) {
38
38
  setWorldQuaternion(this.gameObject, getWorldQuaternion(target));
39
+
40
+ // look at forward again so we don't get any roll
41
+ if (this.keepUpDirection) {
42
+ const forwardPoint = lookFrom.sub(this.forward);
43
+ this.gameObject.lookAt(forwardPoint);
44
+ }
45
+ }
39
46
  else
40
47
  this.gameObject.lookAt(lookTarget);
41
48
 
src/engine-components/ui/PointerEvents.ts CHANGED
@@ -48,6 +48,12 @@
48
48
  this.event = events;
49
49
  this.input = input;
50
50
  }
51
+
52
+ clone() {
53
+ const clone = new PointerEventData(this.input, this.event);
54
+ Object.assign(clone, this);
55
+ return clone;
56
+ }
51
57
  }
52
58
 
53
59
  export interface IPointerDownHandler {
src/engine-components/Renderer.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  import { NEEDLE_progressive } from "../engine/extensions/NEEDLE_progressive";
11
11
  import { NEED_UPDATE_INSTANCE_KEY } from "../engine/engine_instancing";
12
12
  import { IRenderer, ISharedMaterials } from "../engine/engine_types";
13
- import { debug, ReflectionProbe } from "./ReflectionProbe";
13
+ import { ReflectionProbe } from "./ReflectionProbe";
14
14
  import { setCustomVisibility } from "../engine/js-extensions/Layers";
15
15
  import { isLocalNetwork } from "../engine/engine_networking_utils";
16
16
  import { showBalloonWarning } from "../engine/debug/debug";
@@ -184,7 +184,7 @@
184
184
  this.changed = true;
185
185
  }
186
186
 
187
- private getMaterial(index: number) : Material | null {
187
+ private getMaterial(index: number): Material | null {
188
188
  index = this.resolveIndex(index);
189
189
  if (index < 0) return null;
190
190
  const obj = this._targets;
@@ -347,7 +347,7 @@
347
347
  if (debugRenderer) console.log("Renderer ", this.name, this);
348
348
  this.clearInstancingState();
349
349
 
350
- if (this.probeAnchor && debug) this.probeAnchor.add(new AxesHelper(.2));
350
+ if (this.probeAnchor && debugRenderer) this.probeAnchor.add(new AxesHelper(.2));
351
351
 
352
352
  this._reflectionProbe = null;
353
353
 
@@ -364,11 +364,12 @@
364
364
  for (let i = 0; i < this.gameObject.children.length; i++) {
365
365
  const ch = this.gameObject.children[i];
366
366
  // ignore nested groups or objects that have their own renderer (aka their own render order settings)
367
- if (ch.type !== "Mesh" || GameObject.getComponent(ch, Renderer)) continue;
367
+ if (!this.isMeshOrSkinnedMesh(ch) || GameObject.getComponent(ch, Renderer)) continue;
368
368
  if (this.renderOrder.length <= index) {
369
369
  console.error("Incorrect element count", this);
370
370
  break;
371
371
  }
372
+ // if(debugRenderer) console.log("Setting render order", ch, this.renderOrder[index])
372
373
  ch.renderOrder = this.renderOrder[index];
373
374
  index += 1;
374
375
  }
@@ -449,7 +450,7 @@
449
450
  }
450
451
  }
451
452
  else {
452
- if (debug) console.warn("Lightmap not found", this.sourceId, this.lightmapIndex);
453
+ if (debugRenderer) console.warn("Lightmap not found", this.sourceId, this.lightmapIndex);
453
454
  }
454
455
  }
455
456
 
@@ -562,7 +563,7 @@
562
563
  else {
563
564
  this.applySettings(this.gameObject);
564
565
  }
565
-
566
+
566
567
  if (this.sharedMaterials.changed) {
567
568
  this.sharedMaterials.changed = false;
568
569
  this.applyLightmapping();
@@ -605,7 +606,7 @@
605
606
  }
606
607
  }
607
608
 
608
-
609
+
609
610
  if (this.reflectionProbeUsage !== ReflectionProbeUsage.Off && this._reflectionProbe) {
610
611
  this._reflectionProbe.onSet(this);
611
612
  }