Skip to content

Commit

Permalink
Merge pull request #654 from pmndrs/dev
Browse files Browse the repository at this point in the history
Version 6.36.1
  • Loading branch information
vanruesc authored Sep 2, 2024
2 parents a475fa5 + 304a140 commit 92dc519
Show file tree
Hide file tree
Showing 10 changed files with 1,175 additions and 1,100 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postprocessing",
"version": "6.36.0",
"version": "6.36.1",
"description": "A post processing library for three.js.",
"homepage": "https://github.com/pmndrs/postprocessing",
"license": "Zlib",
Expand Down Expand Up @@ -85,7 +85,7 @@
"watch:js": "node esbuild -w"
},
"peerDependencies": {
"three": ">= 0.157.0 < 0.168.0"
"three": ">= 0.157.0 < 0.169.0"
},
"devDependencies": {
"@tweakpane/core": "2.x.x",
Expand All @@ -111,7 +111,7 @@
"npm-run-all": "4.x.x",
"postcss": "8.x.x",
"postcss-cli": "11.x.x",
"postcss-preset-env": "9.x.x",
"postcss-preset-env": "10.x.x",
"sass": "1.x.x",
"spatial-controls": "6.x.x",
"stylelint": "16.x.x",
Expand Down
2,099 changes: 1,064 additions & 1,035 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/core/EffectComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Timer } from "./Timer.js";
import { ClearMaskPass } from "../passes/ClearMaskPass.js";
import { CopyPass } from "../passes/CopyPass.js";
import { MaskPass } from "../passes/MaskPass.js";
import { Pass } from "../passes/Pass.js";

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

Pass.fullscreenGeometry.dispose();

}

}
36 changes: 23 additions & 13 deletions src/core/Selection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { IdManager } from "../utils/IdManager.js";

const idManager = /* @__PURE__ */ new IdManager(2);

/**
* An object selection.
*
Expand All @@ -10,29 +14,35 @@ export class Selection extends Set {
* Constructs a new selection.
*
* @param {Iterable<Object3D>} [iterable] - A collection of objects that should be added to this selection.
* @param {Number} [layer=10] - A dedicated render layer for selected objects.
* @param {Number} [layer] - A dedicated render layer for selected objects. Range is `[2, 31]`. Starts at 2 if omitted.
*/

constructor(iterable, layer = 10) {
constructor(iterable, layer = idManager.getNextId()) {

super();

/**
* Controls whether objects that are added to this selection should be removed from all other layers.
*/

this.exclusive = false;

/**
* The current render layer for selected objects.
*
* @type {Number}
* @private
*/

this.l = layer;
this._layer = layer;

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

this.exclusive = false;
console.warn("Layer out of range, resetting to 2");
idManager.reset(2);
this._layer = idManager.getNextId();

}

if(iterable !== undefined) {

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

get layer() {

return this.l;
return this._layer;

}

set layer(value) {

const currentLayer = this.l;
const currentLayer = this._layer;

for(const object of this) {

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

}

this.l = value;
this._layer = value;

}

/**
* Returns the current render layer for selected objects.
*
* The default layer is 10. If this collides with your own custom layers, please change it before rendering!
* The default layer is 2. If this collides with your own custom layers, please change it before rendering!
*
* @deprecated Use layer instead.
* @return {Number} The layer.
Expand Down
7 changes: 1 addition & 6 deletions src/effects/LUT3DEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,7 @@ export class LUT3DEffect extends Effect {

}

// TODO Added for compatibility with r138. Remove later.
if(lut.source === undefined) {

lut.needsUpdate = true;

}
lut.needsUpdate = true;

}

Expand Down
3 changes: 0 additions & 3 deletions src/effects/OutlineEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,10 @@ export class OutlineEffect extends Effect {
/**
* A selection of objects that will be outlined.
*
* The default layer of this selection is 10.
*
* @type {Selection}
*/

this.selection = new Selection();
this.selection.layer = 10;

/**
* The pulse speed. Set to 0 to disable.
Expand Down
3 changes: 0 additions & 3 deletions src/effects/SelectiveBloomEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,11 @@ export class SelectiveBloomEffect extends BloomEffect {
/**
* A selection of objects.
*
* The default layer of this selection is 11.
*
* @type {Selection}
* @readonly
*/

this.selection = new Selection();
this.selection.layer = 11;

/**
* Backing data for {@link inverted}.
Expand Down
67 changes: 30 additions & 37 deletions src/passes/Pass.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,16 @@ import {
WebGLRenderTarget
} from "three";

const dummyCamera = /* @__PURE__ */ new Camera();
let geometry = null;

/**
* Returns a shared fullscreen triangle.
*
* The screen size is 2x2 units (NDC). A triangle needs to be 4x4 units to fill the screen.
*
* @private
* @return {BufferGeometry} The fullscreen geometry.
*/

function getFullscreenTriangle() {

if(geometry === null) {

const vertices = new Float32Array([-1, -1, 0, 3, -1, 0, -1, 3, 0]);
const uvs = new Float32Array([0, 0, 2, 0, 0, 2]);
geometry = new BufferGeometry();

// Added for backward compatibility (setAttribute was added in three r110).
if(geometry.setAttribute !== undefined) {

geometry.setAttribute("position", new BufferAttribute(vertices, 3));
geometry.setAttribute("uv", new BufferAttribute(uvs, 2));

} else {

geometry.addAttribute("position", new BufferAttribute(vertices, 3));
geometry.addAttribute("uv", new BufferAttribute(uvs, 2));

}

}
const fullscreenGeometry = /* @__PURE__ */ (() => {

const vertices = new Float32Array([-1, -1, 0, 3, -1, 0, -1, 3, 0]);
const uvs = new Float32Array([0, 0, 2, 0, 0, 2]);
const geometry = new BufferGeometry();
geometry.setAttribute("position", new BufferAttribute(vertices, 3));
geometry.setAttribute("uv", new BufferAttribute(uvs, 2));
return geometry;

}
})();

/**
* An abstract pass.
Expand All @@ -62,6 +34,21 @@ function getFullscreenTriangle() {

export class Pass {

/**
* A shared fullscreen triangle.
*
* The screen size is 2x2 units (NDC). A triangle needs to be 4x4 units to fill the screen.
* @see https://michaldrobot.com/2014/04/01/gcn-execution-patterns-in-full-screen-passes/
* @type {BufferGeometry}
* @internal
*/

static get fullscreenGeometry() {

return fullscreenGeometry;

}

/**
* Constructs a new pass.
*
Expand All @@ -70,7 +57,7 @@ export class Pass {
* @param {Camera} [camera] - A camera. Fullscreen effect passes don't require a camera.
*/

constructor(name = "Pass", scene = new Scene(), camera = dummyCamera) {
constructor(name = "Pass", scene = new Scene(), camera = new Camera()) {

/**
* The name of this pass.
Expand Down Expand Up @@ -268,7 +255,7 @@ export class Pass {

} else {

screen = new Mesh(getFullscreenTriangle(), value);
screen = new Mesh(Pass.fullscreenGeometry, value);
screen.frustumCulled = false;

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

}

if(this.fullscreenMaterial !== null) {

this.fullscreenMaterial.dispose();

}

}

}
49 changes: 49 additions & 0 deletions src/utils/IdManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* An ID manager.
*/

export class IdManager {

/**
* Constructs a new ID manager.
*
* @param initialId - The first ID.
*/

constructor(initialId = 0) {

/**
* The next ID.
*/

this.nextId = initialId;

}

/**
* Returns the next unique ID.
*
* @return The ID.
*/

getNextId() {

return this.nextId++;

}

/**
* Resets the ID counter.
*
* @param initialId - The first ID.
* @return This manager.
*/

reset(initialId = 0) {

this.nextId = initialId;
return this;

}

}
2 changes: 2 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from "./orthographicDepthToViewZ.js";
export * from "./viewZToOrthographicDepth.js";

export * from "./IdManager.js";

0 comments on commit 92dc519

Please sign in to comment.