Skip to content

Commit cd5b3e1

Browse files
authored
Merge pull request #691 from pmndrs/dev
Version 6.37.0
2 parents 54b36e8 + 809695f commit cd5b3e1

File tree

12 files changed

+1458
-815
lines changed

12 files changed

+1458
-815
lines changed

manual/assets/js/src/demos/ascii.js

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import {
2+
CubeTextureLoader,
3+
FogExp2,
4+
LoadingManager,
5+
PerspectiveCamera,
6+
Scene,
7+
SRGBColorSpace,
8+
WebGLRenderer
9+
} from "three";
10+
11+
import {
12+
ASCIIEffect,
13+
ASCIITexture,
14+
BlendFunction,
15+
EffectComposer,
16+
EffectPass,
17+
RenderPass
18+
} from "postprocessing";
19+
20+
import { Pane } from "tweakpane";
21+
import { SpatialControls } from "spatial-controls";
22+
import { calculateVerticalFoV, FPSMeter } from "../utils";
23+
import * as Domain from "../objects/Domain";
24+
25+
function load() {
26+
27+
const assets = new Map();
28+
const loadingManager = new LoadingManager();
29+
const cubeTextureLoader = new CubeTextureLoader(loadingManager);
30+
31+
const path = document.baseURI + "img/textures/skies/sunset/";
32+
const format = ".png";
33+
const urls = [
34+
path + "px" + format, path + "nx" + format,
35+
path + "py" + format, path + "ny" + format,
36+
path + "pz" + format, path + "nz" + format
37+
];
38+
39+
return new Promise((resolve, reject) => {
40+
41+
loadingManager.onLoad = () => resolve(assets);
42+
loadingManager.onError = (url) => reject(new Error(`Failed to load ${url}`));
43+
44+
cubeTextureLoader.load(urls, (t) => {
45+
46+
t.colorSpace = SRGBColorSpace;
47+
assets.set("sky", t);
48+
49+
});
50+
51+
});
52+
53+
}
54+
55+
window.addEventListener("load", () => load().then((assets) => {
56+
57+
// Renderer
58+
59+
const renderer = new WebGLRenderer({
60+
powerPreference: "high-performance",
61+
antialias: false,
62+
stencil: false,
63+
depth: false
64+
});
65+
66+
renderer.debug.checkShaderErrors = (window.location.hostname === "localhost");
67+
const container = document.querySelector(".viewport");
68+
container.prepend(renderer.domElement);
69+
70+
// Camera & Controls
71+
72+
const camera = new PerspectiveCamera();
73+
const controls = new SpatialControls(camera.position, camera.quaternion, renderer.domElement);
74+
const settings = controls.settings;
75+
settings.rotation.sensitivity = 2.2;
76+
settings.rotation.damping = 0.05;
77+
settings.translation.damping = 0.1;
78+
controls.position.set(0, 10, 1);
79+
controls.lookAt(0, 10, -1);
80+
81+
// Scene, Lights, Objects
82+
83+
const scene = new Scene();
84+
scene.fog = new FogExp2(0x373134, 0.06);
85+
scene.background = assets.get("sky");
86+
scene.add(Domain.createLights());
87+
scene.add(Domain.createEnvironment(scene.background));
88+
scene.add(Domain.createActors(scene.background));
89+
90+
// Post Processing
91+
92+
const composer = new EffectComposer(renderer, {
93+
multisampling: Math.min(4, renderer.capabilities.maxSamples)
94+
});
95+
96+
const effect = new ASCIIEffect({
97+
asciiTexture: new ASCIITexture({
98+
characters: " .:,'-^=*+?!|0#X%WM@",
99+
font: "Arial",
100+
fontSize: 54,
101+
size: 1024,
102+
maxCharsPerRow: 16
103+
}),
104+
cellSize: 12,
105+
inverted: false
106+
});
107+
108+
composer.addPass(new RenderPass(scene, camera));
109+
composer.addPass(new EffectPass(camera, effect));
110+
111+
// Settings
112+
113+
const params = { useSceneColor: true };
114+
115+
const fpsMeter = new FPSMeter();
116+
const pane = new Pane({ container: container.querySelector(".tp") });
117+
pane.addBinding(fpsMeter, "fps", { readonly: true, label: "FPS" });
118+
119+
const folder = pane.addFolder({ title: "Settings" });
120+
folder.addBinding(effect, "inverted");
121+
folder.addBinding(effect, "cellSize", { min: 2, max: 24, step: 2 });
122+
folder.addBinding(effect, "color", { color: { type: "float" } });
123+
folder.addBinding(params, "useSceneColor").on("change",
124+
(e) => void (effect.color = e.value ? null : effect.color.getHex()));
125+
126+
folder.addBinding(effect.blendMode.opacity, "value", { label: "opacity", min: 0, max: 1, step: 0.01 });
127+
folder.addBinding(effect.blendMode, "blendFunction", { options: BlendFunction });
128+
129+
// Resize Handler
130+
131+
function onResize() {
132+
133+
const width = container.clientWidth, height = container.clientHeight;
134+
camera.aspect = width / height;
135+
camera.fov = calculateVerticalFoV(90, Math.max(camera.aspect, 16 / 9));
136+
camera.updateProjectionMatrix();
137+
composer.setSize(width, height);
138+
139+
}
140+
141+
window.addEventListener("resize", onResize);
142+
onResize();
143+
144+
// Render Loop
145+
146+
requestAnimationFrame(function render(timestamp) {
147+
148+
fpsMeter.update(timestamp);
149+
controls.update(timestamp);
150+
composer.render();
151+
requestAnimationFrame(render);
152+
153+
});
154+
155+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
layout: single
3+
collection: sections
4+
title: ASCII
5+
draft: false
6+
menu:
7+
demos:
8+
parent: special-effects
9+
weight: 9
10+
script: ascii
11+
---
12+
13+
# ASCII
14+
15+
### External Resources

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postprocessing",
3-
"version": "6.36.7",
3+
"version": "6.37.0",
44
"description": "A post processing library for three.js.",
55
"homepage": "https://github.com/pmndrs/postprocessing",
66
"license": "Zlib",
@@ -58,6 +58,7 @@
5858
"pnpm": {
5959
"onlyBuiltDependencies": [
6060
"@parcel/watcher",
61+
"core-js",
6162
"esbuild",
6263
"hugo-bin"
6364
]
@@ -88,7 +89,7 @@
8889
"watch:js": "node esbuild -w"
8990
},
9091
"peerDependencies": {
91-
"three": ">= 0.157.0 < 0.174.0"
92+
"three": ">= 0.157.0 < 0.175.0"
9293
},
9394
"devDependencies": {
9495
"@tweakpane/core": "2.x.x",
@@ -101,7 +102,7 @@
101102
"cssnano": "7.x.x",
102103
"dat.gui": "0.x.x",
103104
"del-cli": "6.x.x",
104-
"esbuild": "0.24.x",
105+
"esbuild": "0.25.x",
105106
"esbuild-plugin-glsl": "1.x.x",
106107
"esdoc": "1.x.x",
107108
"esdoc-importpath-plugin": "1.x.x",

0 commit comments

Comments
 (0)