@needle-tools/engine 3.5.5-alpha → 3.5.6-alpha

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/needle-engine.js +4435 -4429
  3. package/dist/needle-engine.light.js +82299 -0
  4. package/dist/needle-engine.light.min.js +5055 -0
  5. package/dist/needle-engine.light.umd.cjs +5055 -0
  6. package/dist/needle-engine.min.js +290 -290
  7. package/dist/needle-engine.umd.cjs +281 -281
  8. package/lib/engine/engine_components.d.ts +2 -2
  9. package/lib/engine/engine_components.js +7 -2
  10. package/lib/engine/engine_components.js.map +1 -1
  11. package/lib/engine-components/Component.d.ts +3 -0
  12. package/lib/engine-components/Component.js.map +1 -1
  13. package/lib/engine-components/export/usdz/USDZExporter.js +0 -1
  14. package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
  15. package/lib/engine-components/js-extensions/Object3D.js +4 -1
  16. package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
  17. package/lib/engine-components/ui/Button.js +10 -0
  18. package/lib/engine-components/ui/Button.js.map +1 -1
  19. package/lib/engine-components/ui/Canvas.js +2 -1
  20. package/lib/engine-components/ui/Canvas.js.map +1 -1
  21. package/lib/engine-components/ui/CanvasGroup.js +1 -3
  22. package/lib/engine-components/ui/CanvasGroup.js.map +1 -1
  23. package/lib/engine-components/ui/Graphic.d.ts +2 -0
  24. package/lib/engine-components/ui/Graphic.js +16 -5
  25. package/lib/engine-components/ui/Graphic.js.map +1 -1
  26. package/lib/engine-components/ui/Interfaces.d.ts +4 -1
  27. package/lib/engine-components/ui/Interfaces.js.map +1 -1
  28. package/lib/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +3 -2
  30. package/plugins/vite/defines.js +8 -2
  31. package/src/engine/engine_components.ts +7 -2
  32. package/src/engine-components/Component.ts +3 -1
  33. package/src/engine-components/ParticleSystemModules.ts +1483 -1483
  34. package/src/engine-components/export/usdz/USDZExporter.ts +0 -1
  35. package/src/engine-components/js-extensions/Object3D.ts +5 -1
  36. package/src/engine-components/ui/Button.ts +5 -0
  37. package/src/engine-components/ui/Canvas.ts +2 -1
  38. package/src/engine-components/ui/CanvasGroup.ts +2 -4
  39. package/src/engine-components/ui/Graphic.ts +24 -15
  40. package/src/engine-components/ui/Interfaces.ts +5 -1
@@ -66,7 +66,6 @@ export class USDZExporter extends Behaviour {
66
66
  private webARSessionRoot: WebARSessionRoot | undefined;
67
67
 
68
68
  start() {
69
- console.log(this.customUsdzFile);
70
69
  if (debug) {
71
70
  console.log(this);
72
71
  console.log("Debug USDZ, press 't' to export")
@@ -2,7 +2,7 @@ import { applyPrototypeExtensions, registerPrototypeExtensions } from "./Extensi
2
2
  import { Object3D } from "three";
3
3
  import { Constructor, ConstructorConcrete, IComponent } from "../../engine/engine_types"
4
4
  import { IComponent as Component } from "../../engine/engine_types";
5
- import { addNewComponent, getComponent, getComponentInChildren, getComponentInParent, getComponents, getComponentsInChildren, getComponentsInParent, getOrAddComponent, removeComponent } from "../../engine/engine_components";
5
+ import { moveComponentInstance, addNewComponent, getComponent, getComponentInChildren, getComponentInParent, getComponents, getComponentsInChildren, getComponentsInParent, getOrAddComponent, removeComponent } from "../../engine/engine_components";
6
6
  import { isActiveSelf, setActive, destroy } from "../../engine/engine_gameobject";
7
7
 
8
8
  // used to decorate cloned object3D objects with the same added components defined above
@@ -24,6 +24,10 @@ Object3D.prototype["destroy"] = function () {
24
24
  destroy(this);
25
25
  }
26
26
 
27
+ Object3D.prototype["addComponent"] = function <T extends IComponent>(instance: T) {
28
+ return moveComponentInstance(this, instance);
29
+ }
30
+
27
31
  Object3D.prototype["addNewComponent"] = function <T extends Component>(type: ConstructorConcrete<T>) {
28
32
  return addNewComponent(this, new type());
29
33
  }
@@ -68,6 +68,7 @@ export class Button extends Behaviour implements IPointerEventHandler {
68
68
  if (debug)
69
69
  console.log("Button Enter", this.animationTriggers?.highlightedTrigger, this.animator);
70
70
  this._isHovered = true;
71
+ if (!this.interactable) return;
71
72
  if (this.transition == Transition.Animation && this.animationTriggers && this.animator) {
72
73
  this.animator.setTrigger(this.animationTriggers.highlightedTrigger);
73
74
  }
@@ -81,6 +82,7 @@ export class Button extends Behaviour implements IPointerEventHandler {
81
82
  if (debug)
82
83
  console.log("Button Exit", this.animationTriggers?.highlightedTrigger, this.animator);
83
84
  this._isHovered = false;
85
+ if (!this.interactable) return;
84
86
  if (this.transition == Transition.Animation && this.animationTriggers && this.animator) {
85
87
  this.animator.setTrigger(this.animationTriggers.normalTrigger);
86
88
  }
@@ -93,6 +95,7 @@ export class Button extends Behaviour implements IPointerEventHandler {
93
95
  onPointerDown(_) {
94
96
  if (debug)
95
97
  console.log("Button Down", this.animationTriggers?.highlightedTrigger, this.animator);
98
+ if (!this.interactable) return;
96
99
  if (this.transition == Transition.Animation && this.animationTriggers && this.animator) {
97
100
  this.animator.setTrigger(this.animationTriggers.pressedTrigger);
98
101
  }
@@ -104,6 +107,7 @@ export class Button extends Behaviour implements IPointerEventHandler {
104
107
  onPointerUp(_) {
105
108
  if (debug)
106
109
  console.warn("Button Up", this.animationTriggers?.highlightedTrigger, this.animator, this._isHovered);
110
+ if (!this.interactable) return;
107
111
  if (this.transition == Transition.Animation && this.animationTriggers && this.animator) {
108
112
  this.animator.setTrigger(this._isHovered ? this.animationTriggers.highlightedTrigger : this.animationTriggers.normalTrigger);
109
113
  }
@@ -113,6 +117,7 @@ export class Button extends Behaviour implements IPointerEventHandler {
113
117
  }
114
118
 
115
119
  onPointerClick(_args: PointerEventData) {
120
+ if (!this.interactable) return;
116
121
  if (debug) {
117
122
  console.warn("Button Click", this.onClick);
118
123
  showBalloonMessage("CLICKED button " + this.name + " at " + this.context.time.frameCount);
@@ -293,7 +293,8 @@ export class Canvas extends UIRootComponent implements ICanvas {
293
293
  let camera = this.context.mainCameraComponent;
294
294
  let planeDistance: number = 10;
295
295
  if (camera && camera.nearClipPlane > 0 && camera.farClipPlane > 0) {
296
- planeDistance = Mathf.lerp(camera.nearClipPlane, camera.farClipPlane, .5);
296
+ // TODO: this is a hack/workaround for event system currently only passing events to the nearest object
297
+ planeDistance = Mathf.lerp(camera.nearClipPlane, camera.farClipPlane, .15);
297
298
  }
298
299
  if (this._renderMode === RenderMode.ScreenSpaceCamera) {
299
300
  if (this.worldCamera)
@@ -38,12 +38,10 @@ export class CanvasGroup extends Behaviour implements ICanvasGroup {
38
38
  this.applyChangesNow();
39
39
  }
40
40
 
41
- private _buffer : Graphic[] = [];
41
+ private _buffer: Graphic[] = [];
42
42
  private applyChangesNow() {
43
43
  for (const ch of GameObject.getComponentsInChildren(this.gameObject, Graphic, this._buffer)) {
44
- const col = ch.color;
45
- col.alpha = this._alpha;
46
- ch.color = col;
44
+ ch.setAlphaFactor(this._alpha);
47
45
  }
48
46
  }
49
47
  }
@@ -9,12 +9,12 @@ import { onChange, scheduleAction } from "./Utils"
9
9
  import { GameObject } from '../Component';
10
10
  import SimpleStateBehavior from "three-mesh-ui/examples/behaviors/states/SimpleStateBehavior"
11
11
  import { Outline } from './Outline';
12
- import { BehaviorExtension, UsdzBehaviour } from '../../engine-components/export/usdz/extensions/behavior/Behaviour';
13
- import { USDObject } from '../../engine-components/export/usdz/ThreeUSDZExporter';
14
12
 
15
- const _colorStateObject: { backgroundColor: Color, backgroundOpacity: number } = {
13
+ const _colorStateObject: { backgroundColor: Color, backgroundOpacity: number, borderColor: Color, borderOpacity: number } = {
16
14
  backgroundColor: new Color(1, 1, 1),
17
15
  backgroundOpacity: 1,
16
+ borderColor: new Color(1, 1, 1),
17
+ borderOpacity: 1,
18
18
  };
19
19
 
20
20
  export class Graphic extends BaseUIComponent implements IGraphic, IRectTransformChangedReceiver {
@@ -35,10 +35,20 @@ export class Graphic extends BaseUIComponent implements IGraphic, IRectTransform
35
35
  this._color.copy(col);
36
36
  }
37
37
 
38
+ private _alphaFactor: number = 1;
39
+ setAlphaFactor(factor: number) {
40
+ this._alphaFactor = factor;
41
+ this.onColorChanged();
42
+ }
43
+
38
44
  protected onColorChanged() {
39
- _colorStateObject.backgroundColor = this._color;
40
- _colorStateObject.backgroundOpacity = this._color.alpha;
41
- this.uiObject?.set(_colorStateObject);
45
+ if (this.uiObject) {
46
+ _colorStateObject.backgroundColor = this._color;
47
+ _colorStateObject.backgroundOpacity = this._color.alpha * this._alphaFactor;
48
+ this.applyEffects(_colorStateObject, this._alphaFactor);
49
+ this.uiObject.set(_colorStateObject);
50
+ this.markDirty();
51
+ }
42
52
  }
43
53
 
44
54
  // used via animations
@@ -52,10 +62,9 @@ export class Graphic extends BaseUIComponent implements IGraphic, IRectTransform
52
62
  protected uiObject: ThreeMeshUI.Block | null = null;
53
63
  private _color: RGBAColor = null!;
54
64
 
55
-
56
65
  private _rect: RectTransform | null = null;
57
66
 
58
- private _stateManager : SimpleStateBehavior | null = null;
67
+ private _stateManager: SimpleStateBehavior | null = null;
59
68
 
60
69
  protected get rectTransform(): RectTransform {
61
70
  if (!this._rect) {
@@ -65,7 +74,7 @@ export class Graphic extends BaseUIComponent implements IGraphic, IRectTransform
65
74
  }
66
75
 
67
76
  onParentRectTransformChanged() {
68
- this.uiObject?.set({ width: this.rectTransform.width, height:this.rectTransform.height })
77
+ this.uiObject?.set({ width: this.rectTransform.width, height: this.rectTransform.height })
69
78
  this.markDirty();
70
79
  }
71
80
 
@@ -73,7 +82,7 @@ export class Graphic extends BaseUIComponent implements IGraphic, IRectTransform
73
82
  super.__internalNewInstanceCreated();
74
83
  this._rect = null;
75
84
  this.uiObject = null;
76
- if(this._color) this._color = this._color.clone();
85
+ if (this._color) this._color = this._color.clone();
77
86
  }
78
87
 
79
88
  setState(state: string) {
@@ -93,7 +102,7 @@ export class Graphic extends BaseUIComponent implements IGraphic, IRectTransform
93
102
  // ie : (::firstChild::hover::disabled) where firstchild, hover and disabled are all on different channels
94
103
  // In order to keep needle Raycaster and EventSystem intact, I added in v7 a SimpleStateBehavior, which acts as previously
95
104
 
96
- if( !this._stateManager ) this._stateManager = new SimpleStateBehavior(this.uiObject);
105
+ if (!this._stateManager) this._stateManager = new SimpleStateBehavior(this.uiObject);
97
106
  //@ts-ignore
98
107
  this.uiObject.setupState(state.state, state.attributes);
99
108
  }
@@ -159,13 +168,13 @@ export class Graphic extends BaseUIComponent implements IGraphic, IRectTransform
159
168
  }
160
169
  protected onAfterCreated() { }
161
170
 
162
- private applyEffects(opts){
171
+ private applyEffects(opts, alpha: number = 1) {
163
172
  const outline = this.gameObject?.getComponent(Outline);
164
173
  if (outline) {
165
174
  if (outline.effectDistance) opts.borderWidth = Math.max(Math.abs(outline.effectDistance.x), Math.abs(outline.effectDistance.y));
166
175
  if (outline.effectColor) {
167
176
  opts.borderColor = outline.effectColor;
168
- opts.borderOpacity = outline.effectColor.alpha;
177
+ opts.borderOpacity = outline.effectColor.alpha * alpha;
169
178
  }
170
179
  }
171
180
  }
@@ -177,8 +186,8 @@ export class Graphic extends BaseUIComponent implements IGraphic, IRectTransform
177
186
  this.setOptions({ backgroundOpacity: 0 });
178
187
  if (tex) {
179
188
  // workaround for https://github.com/needle-tools/needle-engine-support/issues/109
180
- if(tex.encoding === sRGBEncoding) {
181
- if(Graphic.textureCache.has(tex)) {
189
+ if (tex.encoding === sRGBEncoding) {
190
+ if (Graphic.textureCache.has(tex)) {
182
191
  tex = Graphic.textureCache.get(tex)!;
183
192
  } else {
184
193
  const clone = tex.clone();
@@ -14,7 +14,11 @@ export interface ICanvasGroup {
14
14
  interactable: boolean;
15
15
  }
16
16
 
17
- export interface IGraphic extends IComponent {
17
+ export interface IHasImage {
18
+ setAlphaFactor(val: number);
19
+ }
20
+
21
+ export interface IGraphic extends IComponent, IHasImage {
18
22
  get isGraphic(): boolean;
19
23
  raycastTarget: boolean;
20
24
  }