Prompt specification
Build or customize the Three.js 3D scene "Eyebrow Mouth and Eye Shape Controls" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Eyebrow Mouth and Eye Shape Controls
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/eyebrow-mouth-and-eye-shape-controls-x3717
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts adjustable facial components. Model an original stylized face with independently adjustable brows, eyelids, and mouth curves. Describe visible configurations without assigning diagnostic or personality meanings to them. Low-poly.
Working Three.js Starter (eyebrow-mouth-and-eye-shape-controls-x3717):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Low-Poly Face Components</title>
<style>
:root {
color-scheme: dark;
--bg: #101722;
--panel: rgba(18, 27, 39, 0.9);
--panel-border: rgba(184, 216, 224, 0.16);
--text: #edf4f2;
--muted: #9aadb5;
--accent: #ef9a75;
--accent-2: #69b8b5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.brand {
position: fixed;
top: 26px;
left: 28px;
z-index: 2;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent-2);
font-size: 0.68rem;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.35rem, 2.6vw, 2.2rem);
font-weight: 560;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 360px;
margin: 8px 0 0;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 3;
top: 24px;
right: 24px;
width: 330px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 8px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(16px);
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 11px 12px;
}
.panel-title {
font-size: 0.75rem;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.reset {
border: 1px solid rgba(239, 154, 117, 0.35);
border-radius: 999px;
padding: 7px 10px;
background: rgba(239, 154, 117, 0.08);
color: #ffc4a6;
font: inherit;
font-size: 0.7rem;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
.reset:hover {
background: rgba(239, 154, 117, 0.17);
}
.reset:active {
transform: scale(0.97);
}
details {
margin: 5px 0;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
summary {
padding: 11px 12px;
color: #dbe7e6;
font-size: 0.76rem;
font-weight: 680;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
user-select: none;
}
.control {
display: grid;
grid-template-columns: 1fr 54px;
gap: 5px 10px;
align-items: center;
padding: 8px 12px 11px;
}
.control label {
color: #becacc;
font-size: 0.76rem;
}
.control output {
color: var(--accent);
font-size: 0.72rem;
font-variant-numeric: tabular-nums;
text-align: right;
}
.control input {
grid-column: 1 / -1;
width: 100%;
height: 4px;
margin: 5px 0 2px;
appearance: none;
border-radius: 999px;
background: #344451;
accent-color: var(--accent);
cursor: pointer;
}
.control input::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 2px solid #16202b;
border-radius: 50%;
background: #f2ad89;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.control input::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #16202b;
border-radius: 50%;
background: #f2ad89;
}
.readout {
position: fixed;
z-index: 2;
left: 28px;
bottom: 28px;
width: min(460px, calc(100vw - 56px));
padding: 14px 16px;
border-left: 2px solid var(--accent);
background: rgba(13, 21, 31, 0.78);
backdrop-filter: blur(12px);
pointer-events: none;
}
.readout h2 {
margin: 0 0 7px;
color: #f6b18f;
font-size: 0.68rem;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.readout p {
margin: 0;
color: #c8d5d7;
font-size: 0.76rem;
line-height: 1.6;
}
.camera-hint {
position: fixed;
z-index: 2;
right: 28px;
bottom: 26px;
color: rgba(216, 230, 231, 0.58);
font-size: 0.68rem;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 18px;
left: 18px;
}
.subtitle {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 43vh;
border-radius: 15px;
}
.readout {
top: 82px;
bottom: auto;
left: 18px;
width: calc(100vw - 36px);
padding: 10px 12px;
}
.readout p {
display: -webkit-box;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly face scene"></canvas>
<header class="brand">
<p class="eyebrow">Low-poly geometry study</p>
<h1>Face Components</h1>
<p class="subtitle">
Adjust the brows, eyelids, and mouth independently. All descriptions refer
only to the visible geometry.
</p>
</header>
<aside class="panel" aria-label="Face component controls">
<div class="panel-head">
<span class="panel-title">Components</span>
<button class="reset" id="reset" type="button">Reset parts</button>
</div>
<div id="controls"></div>
</aside>
<section class="readout" aria-live="polite">
<h2>Visible configuration</h2>
<p id="description"></p>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const controlsRoot = document.getElementById("controls");
const descriptionElement = document.getElementById("description");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101722);
scene.fog = new THREE.Fog(0x101722, 8, 18);
const camera = new THREE.PerspectiveCamera(
32,
window.innerWidth / window.innerHeight,
0.1,
40
);
let cameraYaw = 0;
let cameraPitch = 0.025;
let cameraDistance = 5.35;
let targetYaw = cameraYaw;
let targetPitch = cameraPitch;
let targetDistance = cameraDistance;
let cameraTargetY = window.innerWidth < 760 ? -0.34 : -0.12;
function updateCamera() {
const target = new THREE.Vector3(0, cameraTargetY, 0);
const horizontal = cameraDistance * Math.cos(cameraPitch);
camera.position.set(
target.x + horizontal * Math.sin(cameraYaw),
target.y + cameraDistance * Math.sin(cameraPitch),
target.z + horizontal * Math.cos(cameraYaw)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xb8d8ed, 0x442938, 1.85);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffe3c7, 3.4);
key.position.set(3.8, 5.2, 5.6);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -4;
key.shadow.camera.right = 4;
key.shadow.camera.top = 4;
key.shadow.camera.bottom = -4;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 15;
key.shadow.bias = -0.0004;
scene.add(key);
const fill = new THREE.DirectionalLight(0x80bfd0, 1.25);
fill.position.set(-4, 1.5, 3);
scene.add(fill);
const rim = new THREE.PointLight(0xef8b72, 16, 10, 2);
rim.position.set(-2.8, 1.8, -2.8);
scene.add(rim);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x151e2a,
roughness: 0.92,
metalness: 0.02
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(24, 24),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.16;
ground.receiveShadow = true;
scene.add(ground);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(1.72, 1.9, 0.13, 32),
new THREE.MeshStandardMaterial({
color: 0x20303a,
roughness: 0.8,
metalness: 0.08
})
);
platform.position.y = -2.17;
platform.receiveShadow = true;
scene.add(platform);
function pseudoRandom(value) {
const x = Math.sin(value * 12.9898 + 78.233) * 43758.5453;
return x - Math.floor(x);
}
function makeHeadGeometry() {
const rings = [
{ y: -1.18, rx: 0.34, rz: 0.30 },
{ y: -0.88, rx: 0.68, rz: 0.58 },
{ y: -0.42, rx: 0.96, rz: 0.78 },
{ y: 0.08, rx: 1.03, rz: 0.84 },
{ y: 0.52, rx: 0.93, rz: 0.79 },
{ y: 0.90, rx: 0.67, rz: 0.64 },
{ y: 1.18, rx: 0.30, rz: 0.36 }
];
const segments = 14;
const positions = [];
const colors = [];
let triangleIndex = 0;
const ringPoints = rings.map((ring, ringIndex) => {
const points = [];
for (let j = 0; j < segments; j++) {
const offset = ringIndex % 2 === 0 ? 0 : Math.PI / segments * 0.42;
const angle = j / segments * Math.PI * 2 + offset;
points.push(
new THREE.Vector3(
Math.sin(angle) * ring.rx,
ring.y,
Math.cos(angle) * ring.rz
)
);
}
return points;
});
function addTriangle(a, b, c) {
const random = pseudoRandom(triangleIndex++);
const color = new THREE.Color().setHSL(
0.058 + random * 0.012,
0.48,
0.615 + random * 0.075
);
for (const point of [a, b, c]) {
positions.push(point.x, point.y, point.z);
colors.push(color.r, color.g, color.b);
}
}
for (let r = 0; r < ringPoints.length - 1; r++) {
const lower = ringPoints[r];
const upper = ringPoints[r + 1];
for (let j = 0; j < segments; j++) {
const next = (j + 1) % segments;
addTriangle(lower[j], lower[next], upper[j]);
addTriangle(lower[next], upper[next], upper[j]);
}
}
const top = new THREE.Vector3(0, 1.27, 0);
const bottom = new THREE.Vector3(0, -1.23, 0);
const topRing = ringPoints[ringPoints.length - 1];
const bottomRing = ringPoints[0];
for (let j = 0; j < segments; j++) {
const next = (j + 1) % segments;
addTriangle(top, topRing[j], topRing[next]);
addTriangle(bottom, bottomRing[next], bottomRing[j]);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
return geometry;
}
const head = new THREE.Mesh(
makeHeadGeometry(),
new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.83,
metalness: 0,
flatShading: true
})
);
head.castShadow = true;
head.receiveShadow = true;
scene.add(head);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.44, 0.72, 8),
new THREE.MeshStandardMaterial({
color: 0xd68d6c,
roughness: 0.86,
flatShading: true
})
);
neck.position.y = -1.43;
neck.castShadow = true;
scene.add(neck);
const shoulders = new THREE.Mesh(
new THREE.CylinderGeometry(1.03, 1.38, 0.5, 8),
new THREE.MeshStandardMaterial({
color: 0x355d62,
roughness: 0.74,
metalness: 0.06,
flatShading: true
})
);
shoulders.position.set(0, -1.86, -0.03);
shoulders.scale.z = 0.56;
shoulders.rotation.y = Math.PI / 8;
shoulders.castShadow = true;
shoulders.receiveShadow = true;
scene.add(shoulders);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.39, 0.065, 5, 10),
new THREE.MeshStandardMaterial({
color: 0x73aaa6,
roughness: 0.58,
metalness: 0.12,
flatShading: true
})
);
collar.rotation.x = Math.PI / 2;
collar.position.set(0, -1.66, 0.02);
collar.castShadow = true;
scene.add(collar);
const earMaterial = new THREE.MeshStandardMaterial({
color: 0xd68d6c,
roughness: 0.88,
flatShading: true
});
for (const side of [-1, 1]) {
const ear = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.19),
earMaterial
);
ear.position.set(side * 1.015, -0.06, -0.02);
ear.scale.set(0.72, 1.18, 0.58);
ear.castShadow = true;
scene.add(ear);
}
function makeNose() {
const top = new THREE.Vector3(0, 0.23, 0.87);
const tip = new THREE.Vector3(0, -0.16, 1.035);
const left = new THREE.Vector3(-0.15, -0.235, 0.855);
const right = new THREE.Vector3(0.15, -0.235, 0.855);
const bottom = new THREE.Vector3(0, -0.285, 0.94);
const triangles = [
[top, left, tip],
[top, tip, right],
[tip, left, bottom],
[tip, bottom, right],
[left, right, bottom]
];
const positions = [];
const colors = [];
triangles.forEach((triangle, index) => {
const color = new THREE.Color().setHSL(
0.06,
0.46,
0.63 + index * 0.018
);
for (const point of triangle) {
positions.push(point.x, point.y, point.z);
colors.push(color.r, color.g, color.b);
}
});
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
return geometry;
}
const nose = new THREE.Mesh(
makeNose(),
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.78,
flatShading: true
})
);
nose.castShadow = true;
scene.add(nose);
const nostrilMaterial = new THREE.MeshBasicMaterial({
color: 0x693d3b
});
for (const side of [-1, 1]) {
const nostril = new THREE.Mesh(
new THREE.CircleGeometry(0.031, 6),
nostrilMaterial
);
nostril.position.set(side * 0.075, -0.238, 0.947);
nostril.scale.set(1.35, 0.55, 1);
nostril.rotation.z = side * 0.18;
scene.add(nostril);
}
function polygonGeometry(points) {
const shape = new THREE.Shape();
shape.moveTo(points[0][0], points[0][1]);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i][0], points[i][1]);
}
shape.closePath();
return new THREE.ShapeGeometry(shape);
}
function almondPoints(scaleX = 1, scaleY = 1) {
return [
[-0.28 * scaleX, 0],
[-0.19 * scaleX, 0.105 * scaleY],
[0, 0.135 * scaleY],
[0.19 * scaleX, 0.10 * scaleY],
[0.28 * scaleX, 0],
[0.18 * scaleX, -0.09 * scaleY],
[0, -0.115 * scaleY],
[-0.18 * scaleX, -0.095 * scaleY]
];
}
function replaceGeometry(mesh, geometry) {
const oldGeometry = mesh.geometry;
mesh.geometry = geometry;
if (oldGeometry) {
oldGeometry.dispose();
}
}
function ribbonGeometry(points, width) {
const positions = [];
const indices = [];
const count = points.length;
for (let i = 0; i < count; i++) {
const previous = points[Math.max(0, i - 1)];
const next = points[Math.min(count - 1, i + 1)];
const point = points[i];
const dx = next.x - previous.x;
const dy = next.y - previous.y;
const length = Math.hypot(dx, dy) || 1;
const nx = -dy / length;
const ny = dx / length;
const z = point.z ?? 0;
positions.push(
point.x + nx * width * 0.5,
point.y + ny * width * 0.5,
z,
point.x - nx * width * 0.5,
point.y - ny * width * 0.5,
z
);
if (i < count - 1) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const eyeSocketMaterial = new THREE.MeshStandardMaterial({
color: 0x8d5148,
roughness: 0.9,
side: THREE.DoubleSide
});
const eyeWhiteMaterial = new THREE.MeshStandardMaterial({
color: 0xf2eee4,
roughness: 0.6,
side: THREE.DoubleSide
});
const irisMaterial = new THREE.MeshStandardMaterial({
color: 0x3b7475,
roughness: 0.48,
flatShading: true,
side: THREE.DoubleSide
});
const pupilMaterial = new THREE.MeshBasicMaterial({
color: 0x10151a
});
const lidMaterial = new THREE.MeshStandardMaterial({
color: 0xe1a078,
roughness: 0.86,
side: THREE.DoubleSide
});
const lashMaterial = new THREE.MeshBasicMaterial({
color: 0x33282a,
side: THREE.DoubleSide
});
function createEye(side) {
const group = new THREE.Group();
group.position.set(side * 0.395, 0.13, 0.845);
group.rotation.y = side * 0.13;
scene.add(group);
const socket = new THREE.Mesh(
polygonGeometry(almondPoints(1.12, 1.17)),
eyeSocketMaterial
);
group.add(socket);
const white = new THREE.Mesh(
polygonGeometry(almondPoints()),
eyeWhiteMaterial
);
white.position.z = 0.012;
group.add(white);
const iris = new THREE.Mesh(
new THREE.CircleGeometry(0.079, 12),
irisMaterial
);
iris.position.set(0, 0.002, 0.021);
group.add(iris);
const pupil = new THREE.Mesh(
new THREE.CircleGeometry(0.034, 10),
pupilMaterial
);
pupil.position.set(0, 0.002, 0.026);
group.add(pupil);
const highlight = new THREE.Mesh(
new THREE.CircleGeometry(0.015, 8),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
highlight.position.set(-0.025, 0.033, 0.031);
group.add(highlight);
const upperLid = new THREE.Mesh(new THREE.BufferGeometry(), lidMaterial);
upperLid.position.z = 0.035;
group.add(upperLid);
const lowerLid = new THREE.Mesh(new THREE.BufferGeometry(), lidMaterial);
lowerLid.position.z = 0.035;
group.add(lowerLid);
const upperLash = new THREE.Mesh(
ribbonGeometry(
almondPoints().slice(0, 5).map(([x, y]) => ({ x, y })),
0.015
),
lashMaterial
);
upperLash.position.z = 0.042;
group.add(upperLash);
const lowerLash = new THREE.Mesh(
ribbonGeometry(
almondPoints().slice(4).map(([x, y]) => ({ x, y })),
0.009
),
lashMaterial
);
lowerLash.position.z = 0.042;
group.add(lowerLash);
return {
group,
upperLid,
lowerLid,
upperLash,
lowerLash
};
}
const leftEye = createEye(-1);
const rightEye = createEye(1);
const upperBoundary = [
[-0.28, 0],
[-0.19, 0.105],
[0, 0.135],
[0.19, 0.10],
[0.28, 0]
];
const lowerBoundary = [
[-0.28, 0],
[-0.18, -0.095],
[0, -0.115],
[0.18, -0.09],
[0.28, 0]
];
function updateEye(eye, upperDrop, lowerRise) {
const upperEdge = upperBoundary.map((point, index) => ({
x: point[0],
y: THREE.MathUtils.lerp(
point[1],
lowerBoundary[index][1],
upperDrop
)
}));
const lowerEdge = lowerBoundary.map((point, index) => ({
x: point[0],
y: THREE.MathUtils.lerp(
point[1],
upperBoundary[index][1],
lowerRise
)
}));
const upperPolygon = [
...upperBoundary,
...upperEdge.slice().reverse()
];
const lowerPolygon = [
...lowerBoundary,
...lowerEdge.slice().reverse()
];
replaceGeometry(
eye.upperLid,
polygonGeometry(upperPolygon)
);
replaceGeometry(
eye.lowerLid,
polygonGeometry(lowerPolygon)
);
eye.upperLid.visible = upperDrop > 0.001;
eye.lowerLid.visible = lowerRise > 0.001;
replaceGeometry(
eye.upperLash,
ribbonGeometry(upperEdge, 0.015)
);
replaceGeometry(
eye.lowerLash,
ribbonGeometry(lowerEdge, 0.009)
);
}
const browMaterial = new THREE.MeshStandardMaterial({
color: 0x3b2b2c,
roughness: 0.86,
flatShading: true
});
function createBrow(centerX) {
const group = new THREE.Group();
group.position.set(centerX, 0.37, 0.82);
scene.add(group);
const points = [
[-0.235, -0.012, -0.075],
[-0.105, 0.035, 0.002],
[0.065, 0.042, 0.005],
[0.235, -0.015, -0.077]
].map(([x, y, z]) => new THREE.Vector3(x, y, z));
const curve = new THREE.CatmullRomCurve3(points);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 8, 0.033, 4, false),
browMaterial
);
mesh.castShadow = true;
group.add(mesh);
return group;
}
const leftBrow = createBrow(-0.405);
const rightBrow = createBrow(0.405);
const mouthLip = new THREE.Mesh(
new THREE.BufferGeometry(),
new THREE.MeshStandardMaterial({
color: 0xb54e5d,
roughness: 0.58,
side: THREE.DoubleSide,
flatShading: true
})
);
mouthLip.castShadow = true;
scene.add(mouthLip);
const mouthSeam = new THREE.Mesh(
new THREE.BufferGeometry(),
new THREE.MeshBasicMaterial({
color: 0x5c2937,
side: THREE.DoubleSide
})
);
scene.add(mouthSeam);
function mouthCenterline() {
const halfWidth = 0.36 * state.mouthWidth;
const leftY = -0.535 + state.mouthLeftCorner;
const rightY = -0.535 + state.mouthRightCorner;
const averageY = (leftY + rightY) * 0.5;
const controlY = averageY + state.mouthArc * 2;
const points = [];
for (let i = 0; i <= 10; i++) {
const t = i / 10;
const oneMinusT = 1 - t;
const x =
oneMinusT * oneMinusT * -halfWidth +
2 * oneMinusT * t * 0 +
t * t * halfWidth;
const y =
oneMinusT * oneMinusT * leftY +
2 * oneMinusT * t * controlY +
t * t * rightY;
const z = 0.782 + 0.035 * (1 - Math.pow(x / 0.6, 2));
points.push(new THREE.Vector3(x, y, z));
}
return points;
}
function mouthLipGeometry(centerline, halfThickness) {
const positions = [];
const indices = [];
const count = centerline.length;
for (let i = 0; i < count; i++) {
const previous = centerline[Math.max(0, i - 1)];
const next = centerline[Math.min(count - 1, i + 1)];
const point = centerline[i];
const dx = next.x - previous.x;
const dy = next.y - previous.y;
const length = Math.hypot(dx, dy) || 1;
const nx = -dy / length;
const ny = dx / length;
positions.push(
point.x + nx * halfThickness,
point.y + ny * halfThickness,
point.z,
point.x - nx * halfThickness,
point.y - ny * halfThickness,
point.z
);
if (i < count - 1) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function updateMouth() {
const centerline = mouthCenterline();
replaceGeometry(
mouthLip,
mouthLipGeometry(centerline, 0.043)
);
replaceGeometry(
mouthSeam,
ribbonGeometry(
centerline.map(point => ({
x: point.x,
y: point.y,
z: point.z + 0.008
})),
0.009
)
);
}
const controlGroups = [
{
title: "Brows",
items: [
{
key: "browLeftHeight",
label: "Left brow height",
min: -0.18,
max: 0.18,
step: 0.005,
value: 0.02,
format: "units"
},
{
key: "browRightHeight",
label: "Right brow height",
min: -0.18,
max: 0.18,
step: 0.005,
value: 0.02,
format: "units"
},
{
key: "browLeftAngle",
label: "Left brow angle",
min: -30,
max: 30,
step: 1,
value: 0,
format: "angle"
},
{
key: "browRightAngle",
label: "Right brow angle",
min: -30,
max: 30,
step: 1,
value: 0,
format: "angle"
}
]
},
{
title: "Eyelids",
items: [
{
key: "leftUpperDrop",
label: "Left upper lid drop",
min: 0,
max: 1,
step: 0.01,
value: 0.12,
format: "percent"
},
{
key: "rightUpperDrop",
label: "Right upper lid drop",
min: 0,
max: 1,
step: 0.01,
value: 0.12,
format: "percent"
},
{
key: "leftLowerRise",
label: "Left lower lid rise",
min: 0,
max: 1,
step: 0.01,
value: 0,
format: "percent"
},
{
key: "rightLowerRise",
label: "Right lower lid rise",
min: 0,
max: 1,
step: 0.01,
value: 0,
format: "percent"
}
]
},
{
title: "Mouth",
items: [
{
key: "mouthWidth",
label: "Mouth width",
min: 0.7,
max: 1.3,
step: 0.01,
value: 1,
format: "percentBase"
},
{
key: "mouthArc",
label: "Center arc",
min: -0.18,
max: 0.18,
step: 0.005,
value: 0.025,
format: "units"
},
{
key: "mouthLeftCorner",
label: "Left corner height",
min: -0.14,
max: 0.14,
step: 0.005,
value: 0,
format: "units"
},
{
key: "mouthRightCorner",
label: "Right corner height",
min: -0.14,
max: 0.14,
step: 0.005,
value: 0,
format: "units"
}
]
}
];
const state = {};
const defaults = {};
const inputElements = {};
const outputElements = {};
function formatValue(item, value) {
switch (item.format) {
case "angle":
return `${Math.round(value)}°`;
case "percent":
return `${Math.round(value * 100)}%`;
case "percentBase":
return `${Math.round(value * 100)}%`;
default:
return `${value > 0 ? "+" : ""}${value.toFixed(3)}`;
}
}
for (const group of controlGroups) {
const details = document.createElement("details");
details.open = true;
const summary = document.createElement("summary");
summary.textContent = group.title;
details.appendChild(summary);
for (const item of group.items) {
state[item.key] = item.value;
defaults[item.key] = item.value;
const row = document.createElement("div");
row.className = "control";
const label = document.createElement("label");
label.textContent = item.label;
label.htmlFor = item.key;
const output = document.createElement("output");
output.textContent = formatValue(item, item.value);
const input = document.createElement("input");
input.id = item.key;
input.type = "range";
input.min = item.min;
input.max = item.max;
input.step = item.step;
input.value = item.value;
input.setAttribute("aria-label", item.label);
input.addEventListener("input", () => {
state[item.key] = Number(input.value);
output.textContent = formatValue(item, state[item.key]);
applyFace();
updateDescription();
});
row.append(label, output, input);
details.appendChild(row);
inputElements[item.key] = input;
outputElements[item.key] = { element: output, item };
}
controlsRoot.appendChild(details);
}
function signedAmount(value) {
return Math.abs(value).toFixed(3);
}
function describeHeight(value, baseline = "baseline") {
if (Math.abs(value) < 0.005) {
return `at the ${baseline}`;
}
return `${signedAmount(value)} units ${value > 0 ? "above" : "below"} the ${baseline}`;
}
function describeAngle(value) {
const magnitude = Math.abs(value);
if (magnitude < 1) {
return "level";
}
const direction = value > 0 ? "counterclockwise" : "clockwise";
const intensity = magnitude < 10 ? "slightly " : "";
return `${intensity}${direction}`;
}
function updateDescription() {
const leftBrowText =
`left is ${describeHeight(state.browLeftHeight)} and ` +
`${describeAngle(state.browLeftAngle)}`;
const rightBrowText =
`right is ${describeHeight(state.browRightHeight)} and ` +
`${describeAngle(state.browRightAngle)}`;
const arcDirection = state.mouthArc >= 0 ? "upward" : "downward";
const arcText =
Math.abs(state.mouthArc) < 0.005
? "the center follows a straight chord"
: `the center arcs ${signedAmount(state.mouthArc)} units ${arcDirection}`;
descriptionElement.textContent =
`Brows: ${leftBrowText}; ${rightBrowText}. ` +
`Eyelids: the left upper lid is lowered ${Math.round(state.leftUpperDrop * 100)}% ` +
`and its lower lid is raised ${Math.round(state.leftLowerRise * 100)}%; ` +
`the right upper lid is lowered ${Math.round(state.rightUpperDrop * 100)}% ` +
`and its lower lid is raised ${Math.round(state.rightLowerRise * 100)}%. ` +
`Mouth: width is ${Math.round(state.mouthWidth * 100)}% of the base, ` +
`${arcText}, the left corner is ${describeHeight(state.mouthLeftCorner, "corner baseline")}, ` +
`and the right corner is ${describeHeight(state.mouthRightCorner, "corner baseline")}.`;
}
function applyFace() {
leftBrow.position.y = 0.37 + state.browLeftHeight;
rightBrow.position.y = 0.37 + state.browRightHeight;
leftBrow.rotation.z = THREE.MathUtils.degToRad(state.browLeftAngle);
rightBrow.rotation.z = THREE.MathUtils.degToRad(state.browRightAngle);
updateEye(leftEye, state.leftUpperDrop, state.leftLowerRise);
updateEye(rightEye, state.rightUpperDrop, state.rightLowerRise);
updateMouth();
}
document.getElementById("reset").addEventListener("click", () => {
for (const key of Object.keys(defaults)) {
state[key] = defaults[key];
inputElements[key].value = defaults[key];
outputElements[key].element.textContent = formatValue(
outputElements[key].item,
defaults[key]
);
}
applyFace();
updateDescription();
});
applyFace();
updateDescription();
// Custom orbit and zoom controls, implemented without Three.js addons.
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - lastX;
const deltaY = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
targetYaw -= deltaX * 0.006;
targetPitch = THREE.MathUtils.clamp(
targetPitch + deltaY * 0.005,
-0.65,
0.72
);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
targetDistance = THREE.MathUtils.clamp(
targetDistance + event.deltaY * 0.0035,
3.4,
7.5
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
targetYaw = 0;
targetPitch = 0.025;
targetDistance = 5.35;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
cameraTargetY = width < 760 ? -0.34 : -0.12;
}
window.addEventListener("resize", resize);
function animate() {
requestAnimationFrame(animate);
cameraYaw += (targetYaw - cameraYaw) * 0.12;
cameraPitch += (targetPitch - cameraPitch) * 0.12;
cameraDistance += (targetDistance - cameraDistance) * 0.12;
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```