@needle-tools/engine 2.55.2-pre → 2.56.0-pre

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/engine",
3
- "version": "2.55.2-pre",
3
+ "version": "2.56.0-pre",
4
4
  "description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development, and can be deployed anywhere. It is flexible, extensible, and collaboration and XR come naturally.",
5
5
  "main": "dist/needle-engine.js",
6
6
  "module": "src/needle-engine.ts",
@@ -14,9 +14,9 @@ import { GLTF } from "three/examples/jsm/loaders/GLTFLoader";
14
14
 
15
15
  export enum DropListenerEvents {
16
16
  ObjectAdded = "object-added",
17
+ FileDropped = "file-dropped",
17
18
  }
18
19
 
19
-
20
20
  export class DropListener extends Behaviour {
21
21
 
22
22
  @serializable()
@@ -47,6 +47,17 @@ export class DropListener extends Behaviour {
47
47
  evt.preventDefault();
48
48
  }
49
49
 
50
+ async addFiles(fileList: Array<File>) {
51
+ for (const file of fileList) {
52
+ if (!file) continue;
53
+ console.log("Register file " + file.name + " to", this.filesBackendUrl, file);
54
+ const res = await files.addFile(file, this.context, this.filesBackendUrl);
55
+ this.dispatchEvent(new CustomEvent(DropListenerEvents.FileDropped, { detail: file }));
56
+ if (res)
57
+ this.addObject(undefined, res);
58
+ }
59
+ }
60
+
50
61
  private async onDrop(evt: DragEvent) {
51
62
  console.log(evt);
52
63
  if (!evt.dataTransfer) return;
@@ -61,6 +72,7 @@ export class DropListener extends Behaviour {
61
72
  if (!file) continue;
62
73
  console.log("Register file " + file.name + " to", this.filesBackendUrl, file);
63
74
  const res = await files.addFile(file, this.context, this.filesBackendUrl);
75
+ this.dispatchEvent(new CustomEvent(DropListenerEvents.FileDropped, { detail: file }));
64
76
  if (res)
65
77
  this.addObject(evt, res);
66
78
  }
@@ -82,17 +94,20 @@ export class DropListener extends Behaviour {
82
94
  }
83
95
  }
84
96
 
85
- private async addObject(evt: DragEvent, gltf: GLTF) {
97
+ private async addObject(evt: DragEvent | undefined, gltf: GLTF) {
86
98
  console.log("Dropped", gltf);
87
- const opts = new RaycastOptions();
88
- opts.setMask(0xffffff);
89
- opts.screenPointFromOffset(evt.offsetX, evt.offsetY);
90
- const rc = this.context.physics.raycast(opts);
99
+
91
100
  const obj = gltf.scene;
92
- if (rc && rc.length > 0) {
93
- for (const hit of rc) {
94
- obj.position.copy(hit.point);
95
- break;
101
+ if (evt !== undefined) {
102
+ const opts = new RaycastOptions();
103
+ opts.setMask(0xffffff);
104
+ opts.screenPointFromOffset(evt.offsetX, evt.offsetY);
105
+ const rc = this.context.physics.raycast(opts);
106
+ if (rc && rc.length > 0) {
107
+ for (const hit of rc) {
108
+ obj.position.copy(hit.point);
109
+ break;
110
+ }
96
111
  }
97
112
  }
98
113
  this.gameObject.add(obj);
@@ -300,7 +300,7 @@ export class Light extends Behaviour implements ILight {
300
300
  break;
301
301
  }
302
302
  }
303
- else if(!this.light) {
303
+ else if (!this.light) {
304
304
  switch (this.type) {
305
305
  case LightType.Directional:
306
306
  // console.log(this);
@@ -347,7 +347,7 @@ export class Light extends Behaviour implements ILight {
347
347
  if (this.light) {
348
348
  if (this._intensity >= 0)
349
349
  this.light.intensity = this._intensity;
350
- else
350
+ else
351
351
  this._intensity = this.light.intensity;
352
352
 
353
353
  if (this.shadows !== LightShadows.None) {
@@ -371,15 +371,8 @@ export class Light extends Behaviour implements ILight {
371
371
  if (debug)
372
372
  console.log("Override shadow bias?", this._overrideShadowBiasSettings, this.shadowBias, this.shadowNormalBias);
373
373
 
374
- // shadow bias settings
375
- if (this._overrideShadowBiasSettings === true) {
376
- this.light.shadow.bias = this.shadowBias;
377
- this.light.shadow.normalBias = this.shadowNormalBias;
378
- }
379
- else {
380
- this.light.shadow.bias = this.shadowBias * 0.00001;
381
- this.light.shadow.normalBias = this.shadowNormalBias * .0001;
382
- }
374
+ this.light.shadow.bias = this.shadowBias;
375
+ this.light.shadow.normalBias = this.shadowNormalBias;
383
376
 
384
377
  this.updateShadowSoftHard();
385
378
 
@@ -13,7 +13,16 @@ class Sprite {
13
13
  export class Image extends MaskableGraphic {
14
14
 
15
15
  @serializable(Sprite)
16
- sprite?: Sprite;
16
+ get sprite(): Sprite | undefined {
17
+ return this._sprite;
18
+ }
19
+ set sprite(sprite: Sprite | undefined) {
20
+ if (this._sprite === sprite) return;
21
+ this._sprite = sprite;
22
+ this.onAfterCreated();
23
+ }
24
+
25
+ private _sprite?: Sprite;
17
26
 
18
27
  private isBuiltinSprite() {
19
28
  switch (this.sprite?.texture?.name) {
@@ -24,7 +33,7 @@ export class Image extends MaskableGraphic {
24
33
  }
25
34
  // this is a hack/workaround for production builds where the name of the sprite is missing
26
35
  // need to remove this!!!!
27
- if(this.sprite?.texture?.image?.width === 32 && this.sprite?.texture?.image?.height === 32)
36
+ if (this.sprite?.texture?.image?.width === 32 && this.sprite?.texture?.image?.height === 32)
28
37
  return true;
29
38
  return false;
30
39
  }
@@ -39,6 +48,7 @@ export class Image extends MaskableGraphic {
39
48
  }
40
49
 
41
50
  protected onAfterCreated(): void {
51
+ if(!this.__didAwake) return;
42
52
  super.onAfterCreated();
43
53
  if (this.isBuiltinSprite()) return;
44
54
  this.setTexture(this.sprite?.texture);
@@ -47,9 +57,19 @@ export class Image extends MaskableGraphic {
47
57
 
48
58
  export class RawImage extends MaskableGraphic {
49
59
  @serializable(Texture)
50
- mainTexture?: Texture;
60
+ get mainTexture(): Texture | undefined {
61
+ return this._mainTexture;
62
+ }
63
+ set mainTexture(texture: Texture | undefined) {
64
+ if (this._mainTexture === texture) return;
65
+ this._mainTexture = texture;
66
+ this.onAfterCreated();
67
+ }
68
+
69
+ private _mainTexture?: Texture;
51
70
 
52
71
  protected onAfterCreated(): void {
72
+ if(!this.__didAwake) return;
53
73
  super.onAfterCreated();
54
74
  // console.log(this);
55
75
  // if (this.mainTexture) {