Skip to content

Commit 208ff23

Browse files
committed
Hotfix for updateVisualSettings
1 parent e6675db commit 208ff23

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

examples/jsm/effects/AsciiEffect.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class AsciiEffect {
2929
let iFontWeight = options[ 'fontWeight' ] || 400;
3030
let fCharScale = options[ 'charScale' ] || 1.0;
3131

32+
// Font size and line height calculations - declared here so updateVisualSettings can modify them
33+
let baseFontSize = 2 / fResolution;
34+
let strFontSize = ( baseFontSize * fCharScale ) + 'px';
35+
let fLineHeight = ( 2 / fResolution );
36+
3237
// Cache for letter spacing calculation optimization
3338
// Only recalculates when font-related parameters change
3439
let cachedLetterSpacing = null;
@@ -126,6 +131,7 @@ class AsciiEffect {
126131
fResolution = newSettings.resolution;
127132
renderer.setPixelRatio( fResolution );
128133
needsResolutionUpdate = true;
134+
needsFontRecalculation = true; // Resolution affects font size calculations
129135

130136
}
131137

@@ -151,16 +157,22 @@ class AsciiEffect {
151157

152158
}
153159

154-
if ( needsResolutionUpdate ) {
160+
// Recalculate font-dependent variables when needed
161+
if ( needsFontRecalculation ) {
155162

156-
initAsciiSize();
163+
// Recalculate font size and line height based on new parameters
164+
baseFontSize = 2 / fResolution;
165+
strFontSize = ( baseFontSize * fCharScale ) + 'px';
166+
fLineHeight = ( 2 / fResolution );
167+
168+
// Force recalculation of letter spacing since font parameters changed
169+
cachedLetterSpacing = null;
157170

158171
}
159172

160-
// Force recalculation of letter spacing since font parameters changed
161-
if ( needsFontRecalculation ) {
173+
if ( needsResolutionUpdate || needsFontRecalculation ) {
162174

163-
cachedLetterSpacing = null;
175+
initAsciiSize();
164176

165177
}
166178

@@ -268,12 +280,6 @@ class AsciiEffect {
268280

269281
}
270282

271-
// Apply character scaling to font size (fully dynamic calculation)
272-
const baseFontSize = 2 / fResolution;
273-
const strFontSize = ( baseFontSize * fCharScale ) + 'px';
274-
275-
const fLineHeight = ( 2 / fResolution );
276-
277283
// Calculate letter spacing for monospace fonts, so that each character fits in a perfect square
278284
function calculateLetterSpacing( fontFamily, fontSize, fontWeight, lineHeight ) {
279285

0 commit comments

Comments
 (0)