diff options
Diffstat (limited to 'public/bluebey-studio/src/face.js')
| -rw-r--r-- | public/bluebey-studio/src/face.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/public/bluebey-studio/src/face.js b/public/bluebey-studio/src/face.js index e3063f2..f2440d3 100644 --- a/public/bluebey-studio/src/face.js +++ b/public/bluebey-studio/src/face.js @@ -1,6 +1,12 @@ import * as THREE from 'three'; import { drawEyes, drawMouth, drawHeadCoverWrap, canvasLayout } from './faceArt.js'; +// The hair plate's texture is drawn at this multiple of the plate's natural UV +// size. The hairline crosses the head over only a fraction of that height, so at +// 1x its edge comes out visibly jagged; doubling it (with the finer curve +// subdivision in `drawHeadCoverWrap`) keeps the edge smooth. +const HAIR_SCALE = 2; + /** * Owns the two procedural textures (eyes and mouth) and keeps them in sync with * the face parameters. @@ -48,7 +54,7 @@ export class Face { this.beardImages = {}; this.eyeCanvas = makeCanvas(this.eyeLayout); this.mouthCanvas = makeCanvas(this.mouthLayout); - this.hairCanvas = this.hairLayout ? makeCanvas(this.hairLayout) : null; + this.hairCanvas = this.hairLayout ? makeCanvas(this.hairLayout, HAIR_SCALE) : null; this.eyeCtx = this.eyeCanvas.getContext('2d'); this.mouthCtx = this.mouthCanvas.getContext('2d'); this.hairCtx = this.hairCanvas ? this.hairCanvas.getContext('2d') : null; @@ -264,10 +270,13 @@ export class Face { this.hairMesh.renderOrder = p.eyes.headMark?.overEyes === false ? 0 : 3; const layout = this.hairLayout; const ctx = this.hairCtx; - ctx.clearRect(0, 0, layout.width, layout.height); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.clearRect(0, 0, layout.width * HAIR_SCALE, layout.height * HAIR_SCALE); + ctx.scale(HAIR_SCALE, HAIR_SCALE); // `drawHeadCoverWrap` works in canvas coordinates (its x axis is the UV // angle already normalised), so it is not shifted by the window offset. drawHeadCoverWrap(ctx, p.eyes.headMark ?? {}, layout); + ctx.setTransform(1, 0, 0, 1, 0, 0); this.hairTexture.needsUpdate = true; } @@ -275,10 +284,10 @@ export class Face { } } -function makeCanvas({ width, height }) { +function makeCanvas({ width, height }, scale = 1) { const canvas = document.createElement('canvas'); - canvas.width = width; - canvas.height = height; + canvas.width = Math.round(width * scale); + canvas.height = Math.round(height * scale); return canvas; } |
