Skip to content

Commit 92dc519

Browse files
authored
Merge pull request #654 from pmndrs/dev
Version 6.36.1
2 parents a475fa5 + 304a140 commit 92dc519

File tree

10 files changed

+1175
-1100
lines changed

10 files changed

+1175
-1100
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postprocessing",
3-
"version": "6.36.0",
3+
"version": "6.36.1",
44
"description": "A post processing library for three.js.",
55
"homepage": "https://github.com/pmndrs/postprocessing",
66
"license": "Zlib",
@@ -85,7 +85,7 @@
8585
"watch:js": "node esbuild -w"
8686
},
8787
"peerDependencies": {
88-
"three": ">= 0.157.0 < 0.168.0"
88+
"three": ">= 0.157.0 < 0.169.0"
8989
},
9090
"devDependencies": {
9191
"@tweakpane/core": "2.x.x",
@@ -111,7 +111,7 @@
111111
"npm-run-all": "4.x.x",
112112
"postcss": "8.x.x",
113113
"postcss-cli": "11.x.x",
114-
"postcss-preset-env": "9.x.x",
114+
"postcss-preset-env": "10.x.x",
115115
"sass": "1.x.x",
116116
"spatial-controls": "6.x.x",
117117
"stylelint": "16.x.x",

pnpm-lock.yaml

Lines changed: 1064 additions & 1035 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/EffectComposer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Timer } from "./Timer.js";
1414
import { ClearMaskPass } from "../passes/ClearMaskPass.js";
1515
import { CopyPass } from "../passes/CopyPass.js";
1616
import { MaskPass } from "../passes/MaskPass.js";
17+
import { Pass } from "../passes/Pass.js";
1718

1819
/**
1920
* The EffectComposer may be used in place of a normal WebGLRenderer.
@@ -714,6 +715,8 @@ export class EffectComposer {
714715
this.copyPass.dispose();
715716
this.timer.dispose();
716717

718+
Pass.fullscreenGeometry.dispose();
719+
717720
}
718721

719722
}

src/core/Selection.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { IdManager } from "../utils/IdManager.js";
2+
3+
const idManager = /* @__PURE__ */ new IdManager(2);
4+
15
/**
26
* An object selection.
37
*
@@ -10,29 +14,35 @@ export class Selection extends Set {
1014
* Constructs a new selection.
1115
*
1216
* @param {Iterable<Object3D>} [iterable] - A collection of objects that should be added to this selection.
13-
* @param {Number} [layer=10] - A dedicated render layer for selected objects.
17+
* @param {Number} [layer] - A dedicated render layer for selected objects. Range is `[2, 31]`. Starts at 2 if omitted.
1418
*/
1519

16-
constructor(iterable, layer = 10) {
20+
constructor(iterable, layer = idManager.getNextId()) {
1721

1822
super();
1923

24+
/**
25+
* Controls whether objects that are added to this selection should be removed from all other layers.
26+
*/
27+
28+
this.exclusive = false;
29+
2030
/**
2131
* The current render layer for selected objects.
2232
*
2333
* @type {Number}
2434
* @private
2535
*/
2636

27-
this.l = layer;
37+
this._layer = layer;
2838

29-
/**
30-
* Controls whether objects that are added to this selection should be removed from all other layers.
31-
*
32-
* @type {Boolean}
33-
*/
39+
if(this._layer < 1 || this._layer > 31) {
3440

35-
this.exclusive = false;
41+
console.warn("Layer out of range, resetting to 2");
42+
idManager.reset(2);
43+
this._layer = idManager.getNextId();
44+
45+
}
3646

3747
if(iterable !== undefined) {
3848

@@ -50,13 +60,13 @@ export class Selection extends Set {
5060

5161
get layer() {
5262

53-
return this.l;
63+
return this._layer;
5464

5565
}
5666

5767
set layer(value) {
5868

59-
const currentLayer = this.l;
69+
const currentLayer = this._layer;
6070

6171
for(const object of this) {
6272

@@ -65,14 +75,14 @@ export class Selection extends Set {
6575

6676
}
6777

68-
this.l = value;
78+
this._layer = value;
6979

7080
}
7181

7282
/**
7383
* Returns the current render layer for selected objects.
7484
*
75-
* The default layer is 10. If this collides with your own custom layers, please change it before rendering!
85+
* The default layer is 2. If this collides with your own custom layers, please change it before rendering!
7686
*
7787
* @deprecated Use layer instead.
7888
* @return {Number} The layer.

src/effects/LUT3DEffect.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,7 @@ export class LUT3DEffect extends Effect {
251251

252252
}
253253

254-
// TODO Added for compatibility with r138. Remove later.
255-
if(lut.source === undefined) {
256-
257-
lut.needsUpdate = true;
258-
259-
}
254+
lut.needsUpdate = true;
260255

261256
}
262257

src/effects/OutlineEffect.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,10 @@ export class OutlineEffect extends Effect {
214214
/**
215215
* A selection of objects that will be outlined.
216216
*
217-
* The default layer of this selection is 10.
218-
*
219217
* @type {Selection}
220218
*/
221219

222220
this.selection = new Selection();
223-
this.selection.layer = 10;
224221

225222
/**
226223
* The pulse speed. Set to 0 to disable.

src/effects/SelectiveBloomEffect.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,11 @@ export class SelectiveBloomEffect extends BloomEffect {
9595
/**
9696
* A selection of objects.
9797
*
98-
* The default layer of this selection is 11.
99-
*
10098
* @type {Selection}
10199
* @readonly
102100
*/
103101

104102
this.selection = new Selection();
105-
this.selection.layer = 11;
106103

107104
/**
108105
* Backing data for {@link inverted}.

src/passes/Pass.js

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,16 @@ import {
1010
WebGLRenderTarget
1111
} from "three";
1212

13-
const dummyCamera = /* @__PURE__ */ new Camera();
14-
let geometry = null;
15-
16-
/**
17-
* Returns a shared fullscreen triangle.
18-
*
19-
* The screen size is 2x2 units (NDC). A triangle needs to be 4x4 units to fill the screen.
20-
*
21-
* @private
22-
* @return {BufferGeometry} The fullscreen geometry.
23-
*/
24-
25-
function getFullscreenTriangle() {
26-
27-
if(geometry === null) {
28-
29-
const vertices = new Float32Array([-1, -1, 0, 3, -1, 0, -1, 3, 0]);
30-
const uvs = new Float32Array([0, 0, 2, 0, 0, 2]);
31-
geometry = new BufferGeometry();
32-
33-
// Added for backward compatibility (setAttribute was added in three r110).
34-
if(geometry.setAttribute !== undefined) {
35-
36-
geometry.setAttribute("position", new BufferAttribute(vertices, 3));
37-
geometry.setAttribute("uv", new BufferAttribute(uvs, 2));
38-
39-
} else {
40-
41-
geometry.addAttribute("position", new BufferAttribute(vertices, 3));
42-
geometry.addAttribute("uv", new BufferAttribute(uvs, 2));
43-
44-
}
45-
46-
}
13+
const fullscreenGeometry = /* @__PURE__ */ (() => {
4714

15+
const vertices = new Float32Array([-1, -1, 0, 3, -1, 0, -1, 3, 0]);
16+
const uvs = new Float32Array([0, 0, 2, 0, 0, 2]);
17+
const geometry = new BufferGeometry();
18+
geometry.setAttribute("position", new BufferAttribute(vertices, 3));
19+
geometry.setAttribute("uv", new BufferAttribute(uvs, 2));
4820
return geometry;
4921

50-
}
22+
})();
5123

5224
/**
5325
* An abstract pass.
@@ -62,6 +34,21 @@ function getFullscreenTriangle() {
6234

6335
export class Pass {
6436

37+
/**
38+
* A shared fullscreen triangle.
39+
*
40+
* The screen size is 2x2 units (NDC). A triangle needs to be 4x4 units to fill the screen.
41+
* @see https://michaldrobot.com/2014/04/01/gcn-execution-patterns-in-full-screen-passes/
42+
* @type {BufferGeometry}
43+
* @internal
44+
*/
45+
46+
static get fullscreenGeometry() {
47+
48+
return fullscreenGeometry;
49+
50+
}
51+
6552
/**
6653
* Constructs a new pass.
6754
*
@@ -70,7 +57,7 @@ export class Pass {
7057
* @param {Camera} [camera] - A camera. Fullscreen effect passes don't require a camera.
7158
*/
7259

73-
constructor(name = "Pass", scene = new Scene(), camera = dummyCamera) {
60+
constructor(name = "Pass", scene = new Scene(), camera = new Camera()) {
7461

7562
/**
7663
* The name of this pass.
@@ -268,7 +255,7 @@ export class Pass {
268255

269256
} else {
270257

271-
screen = new Mesh(getFullscreenTriangle(), value);
258+
screen = new Mesh(Pass.fullscreenGeometry, value);
272259
screen.frustumCulled = false;
273260

274261
if(this.scene === null) {
@@ -406,6 +393,12 @@ export class Pass {
406393

407394
}
408395

396+
if(this.fullscreenMaterial !== null) {
397+
398+
this.fullscreenMaterial.dispose();
399+
400+
}
401+
409402
}
410403

411404
}

src/utils/IdManager.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* An ID manager.
3+
*/
4+
5+
export class IdManager {
6+
7+
/**
8+
* Constructs a new ID manager.
9+
*
10+
* @param initialId - The first ID.
11+
*/
12+
13+
constructor(initialId = 0) {
14+
15+
/**
16+
* The next ID.
17+
*/
18+
19+
this.nextId = initialId;
20+
21+
}
22+
23+
/**
24+
* Returns the next unique ID.
25+
*
26+
* @return The ID.
27+
*/
28+
29+
getNextId() {
30+
31+
return this.nextId++;
32+
33+
}
34+
35+
/**
36+
* Resets the ID counter.
37+
*
38+
* @param initialId - The first ID.
39+
* @return This manager.
40+
*/
41+
42+
reset(initialId = 0) {
43+
44+
this.nextId = initialId;
45+
return this;
46+
47+
}
48+
49+
}

src/utils/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export * from "./orthographicDepthToViewZ.js";
22
export * from "./viewZToOrthographicDepth.js";
3+
4+
export * from "./IdManager.js";

0 commit comments

Comments
 (0)