@needle-tools/engine 2.67.0-pre → 2.67.2-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.
@@ -16,18 +16,31 @@ export class PostProcessingHandler {
16
16
  private _lastVolumeComponents?: PostProcessingEffect[];
17
17
  private _effects: Array<Effect | Pass> = [];
18
18
 
19
+ get isActive() {
20
+ return this._isActive;
21
+ }
22
+
23
+ private _isActive: boolean = false;
24
+ private readonly context: Context;
19
25
 
20
- apply(context: Context, components: PostProcessingEffect[]) {
21
- this.onApply(context, components);
26
+ constructor(context: Context) {
27
+ this.context = context;
22
28
  }
23
29
 
24
- unapply(context: Context) {
30
+ apply(components: PostProcessingEffect[]) {
31
+ this._isActive = true;
32
+ this.onApply(this.context, components);
33
+ }
34
+
35
+ unapply() {
36
+ this._isActive = false;
25
37
  if (this._lastVolumeComponents) {
26
38
  for (const component of this._lastVolumeComponents) {
27
39
  component.unapply();
28
40
  }
29
41
  this._lastVolumeComponents.length = 0;
30
42
  }
43
+ const context = this.context;
31
44
  const active = context[activeKey] as PostProcessingHandler | null;
32
45
  if (active === this) {
33
46
  delete context[activeKey];
@@ -36,8 +49,8 @@ export class PostProcessingHandler {
36
49
  context.composer = null;
37
50
  }
38
51
 
39
- dispose(context: Context) {
40
- this.unapply(context);
52
+ dispose() {
53
+ this.unapply();
41
54
 
42
55
  for (const effect of this._effects) {
43
56
  effect.dispose();
@@ -71,7 +84,7 @@ export class PostProcessingHandler {
71
84
  }
72
85
  // apply or collect effects
73
86
  const res = component.apply();
74
- if (res === undefined || res === null) continue;
87
+ if (!res) continue;
75
88
  if (Array.isArray(res)) {
76
89
  this._effects.push(...res);
77
90
  }
@@ -116,7 +129,7 @@ export class PostProcessingHandler {
116
129
  prev.dispose();
117
130
  composer.removeAllPasses();
118
131
  composer.addPass(new RenderPass(context.scene, cam));
119
-
132
+
120
133
 
121
134
  if (debug)
122
135
  console.log("Set effects or passes", camera, effectsOrPasses, composer);
@@ -8,7 +8,6 @@ import { PostProcessingEffect } from "./PostProcessingEffect";
8
8
  import { VolumeParameter } from "./VolumeParameter";
9
9
  import { getEditorModificationCache } from "../../engine/engine_editor-sync";
10
10
  import { isDevEnvironment } from "../../engine/debug";
11
- // import { CustomPostProcessingEffect } from "./CustomPostProcessingEffect";
12
11
 
13
12
  const debug = getParam("debugpost");
14
13
 
@@ -17,7 +16,7 @@ export class Volume extends Behaviour implements IEditorModificationReceiver {
17
16
  @serializeable(VolumeProfile)
18
17
  sharedProfile?: VolumeProfile;
19
18
 
20
- private _postprocessing: PostProcessingHandler = new PostProcessingHandler();
19
+ private _postprocessing?: PostProcessingHandler;
21
20
  private _effects: PostProcessingEffect[] = [];
22
21
 
23
22
  awake() {
@@ -36,22 +35,17 @@ export class Volume extends Behaviour implements IEditorModificationReceiver {
36
35
  }
37
36
  }
38
37
 
39
- start() {
40
- this.apply();
41
- this.tryApplyCache();
42
- }
43
-
44
- onEnable() {
45
- // We need to wait for the camera to be ready
46
- if (this.__internalDidAwakeAndStart)
47
- this.apply();
48
- }
49
-
50
38
  onDisable() {
51
- this._postprocessing?.unapply(this.context);
39
+ this._postprocessing?.unapply();
52
40
  }
53
41
 
54
42
  onBeforeRender(): void {
43
+ // Wait for the first frame to be rendered before creating because then we know we have a camera (issue 135)
44
+ if (this.context.mainCamera) {
45
+ if (!this._postprocessing || !this._postprocessing.isActive)
46
+ this.apply();
47
+ }
48
+
55
49
  if (!this.context.isInXR && this.context.composer && this.context.mainCamera) {
56
50
  this.context.composer.setRenderer(this.context.renderer);
57
51
  this.context.composer.setMainScene(this.context.scene);
@@ -60,14 +54,14 @@ export class Volume extends Behaviour implements IEditorModificationReceiver {
60
54
  }
61
55
 
62
56
  onDestroy(): void {
63
- this._postprocessing?.dispose(this.context);
57
+ this._postprocessing?.dispose();
64
58
  }
65
59
 
66
60
  private _lastApplyTime?: number;
67
61
  private _rapidApplyCount = 0;
68
62
 
69
63
  private apply() {
70
- if (debug) console.log("Apply PostProcessing", this);
64
+ if (debug) console.log("Apply PostProcessing", this, this.context.mainCamera?.name);
71
65
 
72
66
  if (isDevEnvironment()) {
73
67
  if (this._lastApplyTime !== undefined && Date.now() - this._lastApplyTime < 100) {
@@ -95,13 +89,16 @@ export class Volume extends Behaviour implements IEditorModificationReceiver {
95
89
  if (comp.active) this._effects.push(comp);
96
90
  }
97
91
  }
92
+
98
93
  if (this._effects.length > 0) {
99
- this._postprocessing.apply(this.context, this._effects);
94
+ if (!this._postprocessing)
95
+ this._postprocessing = new PostProcessingHandler(this.context);
96
+ this._postprocessing.apply(this._effects);
100
97
  }
101
98
  }
102
99
 
103
100
  private unapply() {
104
- this._postprocessing.unapply(this.context);
101
+ this._postprocessing?.unapply();
105
102
  }
106
103
 
107
104
 
@@ -127,13 +127,18 @@ export class RectTransform extends BaseUIComponent {
127
127
  if (this.pivot && this.sizeDelta) {
128
128
  let tx = (this.pivot.x * 2 - 1);
129
129
  let ty = (this.pivot.y * 2 - 1);
130
- // tx -= this.m_AnchoredPosition.x * .05;
131
- ty -= this.anchoredPosition.y * .05;
132
- const offx = this.sizeDelta.x * tx;
133
- const offy = this.sizeDelta.y * ty;
130
+ tx -= this.anchoredPosition.x;// * .05;
131
+ ty -= this.anchoredPosition.y;// * .05;
132
+ const offx = tx;
133
+ const offy = ty;
134
134
  // console.log(this.name, this.pivot, tx, ty, "offset", offx, offy);
135
- pos.x -= offx * .5;
136
- pos.y -= offy * .5;
135
+ pos.x -= offx;
136
+ pos.y -= offy;
137
+
138
+ // TODO update size from anchoring, width, height, sizeDelta
139
+ if (this.shadowComponent)
140
+ // console.log(this.shadowComponent)
141
+ this.set({ width: this.sizeDelta.x, height: this.sizeDelta.y });
137
142
  }
138
143
  }
139
144