|
8 | 8 | Directive,
|
9 | 9 | effect,
|
10 | 10 | ElementRef,
|
11 |
| - inject, |
12 |
| - Injector, |
13 | 11 | input,
|
14 | 12 | signal,
|
15 | 13 | TemplateRef,
|
@@ -50,7 +48,6 @@ export class ManagePortalScene {
|
50 | 48 | worldUnits = input.required<boolean>();
|
51 | 49 |
|
52 | 50 | constructor() {
|
53 |
| - const injector = inject(Injector); |
54 | 51 | const renderTextureStore = injectStore();
|
55 | 52 |
|
56 | 53 | const buffer1 = injectFBO();
|
@@ -100,59 +97,54 @@ export class ManagePortalScene {
|
100 | 97 | setEvents({ enabled: events });
|
101 | 98 | });
|
102 | 99 |
|
103 |
| - effect((onCleanup) => { |
104 |
| - const priority = this.priority(); |
105 |
| - |
106 |
| - // we start the before render in effect because we need the priority input to be resolved |
107 |
| - const sub = injectBeforeRender( |
108 |
| - ({ gl, camera }) => { |
109 |
| - const material = this.material(); |
110 |
| - |
111 |
| - const instanceState = getInstanceState(material); |
112 |
| - if (!instanceState) return; |
113 |
| - |
114 |
| - const parent = instanceState.parent(); |
115 |
| - if (!parent) return; |
116 |
| - |
117 |
| - const materialBlend = 'blend' in material && typeof material.blend === 'number' ? material.blend : 0; |
118 |
| - const [worldUnits, rootScene, scene, [quad, blend]] = [ |
119 |
| - this.worldUnits(), |
120 |
| - this.rootScene(), |
121 |
| - renderTextureStore.snapshot.scene, |
122 |
| - fullScreenQuad(), |
123 |
| - ]; |
124 |
| - // Move portal contents along with the parent if worldUnits is true |
125 |
| - if (!worldUnits) { |
126 |
| - // If the portal renders exclusively the original scene needs to be updated |
127 |
| - if (priority && materialBlend === 1) parent['updateWorldMatrix'](true, false); |
128 |
| - scene.matrixWorld.copy(parent['matrixWorld']); |
129 |
| - } else { |
130 |
| - scene.matrixWorld.identity(); |
| 100 | + injectBeforeRender( |
| 101 | + ({ gl, camera }) => { |
| 102 | + const material = this.material(); |
| 103 | + |
| 104 | + const instanceState = getInstanceState(material); |
| 105 | + if (!instanceState) return; |
| 106 | + |
| 107 | + const parent = instanceState.parent(); |
| 108 | + if (!parent) return; |
| 109 | + |
| 110 | + const priority = this.priority(); |
| 111 | + const materialBlend = 'blend' in material && typeof material.blend === 'number' ? material.blend : 0; |
| 112 | + const [worldUnits, rootScene, scene, [quad, blend]] = [ |
| 113 | + this.worldUnits(), |
| 114 | + this.rootScene(), |
| 115 | + renderTextureStore.snapshot.scene, |
| 116 | + fullScreenQuad(), |
| 117 | + ]; |
| 118 | + // Move portal contents along with the parent if worldUnits is true |
| 119 | + if (!worldUnits) { |
| 120 | + // If the portal renders exclusively the original scene needs to be updated |
| 121 | + if (priority && materialBlend === 1) parent['updateWorldMatrix'](true, false); |
| 122 | + scene.matrixWorld.copy(parent['matrixWorld']); |
| 123 | + } else { |
| 124 | + scene.matrixWorld.identity(); |
| 125 | + } |
| 126 | + |
| 127 | + // This bit is only necessary if the portal is blended, now it has a render-priority |
| 128 | + // and will take over the render loop |
| 129 | + if (priority) { |
| 130 | + if (materialBlend > 0 && materialBlend < 1) { |
| 131 | + // If blend is ongoing (> 0 and < 1) then we need to render both the root scene |
| 132 | + // and the portal scene, both will then be mixed in the quad from above |
| 133 | + blend.value = materialBlend; |
| 134 | + gl.setRenderTarget(buffer1()); |
| 135 | + gl.render(scene, camera); |
| 136 | + gl.setRenderTarget(buffer2()); |
| 137 | + gl.render(rootScene, camera); |
| 138 | + gl.setRenderTarget(null); |
| 139 | + quad.render(gl); |
| 140 | + } else if (materialBlend === 1) { |
| 141 | + // However if blend is 1 we only need to render the portal scene |
| 142 | + gl.render(scene, camera); |
131 | 143 | }
|
132 |
| - |
133 |
| - // This bit is only necessary if the portal is blended, now it has a render-priority |
134 |
| - // and will take over the render loop |
135 |
| - if (priority) { |
136 |
| - if (materialBlend > 0 && materialBlend < 1) { |
137 |
| - // If blend is ongoing (> 0 and < 1) then we need to render both the root scene |
138 |
| - // and the portal scene, both will then be mixed in the quad from above |
139 |
| - blend.value = materialBlend; |
140 |
| - gl.setRenderTarget(buffer1()); |
141 |
| - gl.render(scene, camera); |
142 |
| - gl.setRenderTarget(buffer2()); |
143 |
| - gl.render(rootScene, camera); |
144 |
| - gl.setRenderTarget(null); |
145 |
| - quad.render(gl); |
146 |
| - } else if (materialBlend === 1) { |
147 |
| - // However if blend is 1 we only need to render the portal scene |
148 |
| - gl.render(scene, camera); |
149 |
| - } |
150 |
| - } |
151 |
| - }, |
152 |
| - { injector, priority }, |
153 |
| - ); |
154 |
| - onCleanup(() => sub()); |
155 |
| - }); |
| 144 | + } |
| 145 | + }, |
| 146 | + { priority: this.priority }, |
| 147 | + ); |
156 | 148 | }
|
157 | 149 | }
|
158 | 150 |
|
|
0 commit comments