Prompt specification
Build or customize the Three.js 3D scene "Paddle Plane and Approaching Ball" 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: Paddle Plane and Approaching Ball
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/paddle-plane-and-approaching-ball-x3629
Scene Description Prompt:
A stylized paddle and approaching ball with a marked contact plane. Highlight valid contact. Three.js from cdnjs, one HTML file.
Working Three.js Starter (paddle-plane-and-approaching-ball-x3629):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Paddle Contact Lab</title>
<style>
:root {
--cyan: #62e8ff;
--green: #73ffc2;
--amber: #ffbd66;
--red: #ff657a;
--ink: #06101d;
--muted: #8da5bb;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: #eaf8ff;
background:
radial-gradient(circle at 50% 36%, #10263c 0%, #07111f 43%, #030710 100%);
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: crosshair;
touch-action: none;
}
#scene::after {
content: "";
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
background:
linear-gradient(180deg, rgba(1, 5, 12, 0.34), transparent 25%),
radial-gradient(circle at center, transparent 52%, rgba(1, 4, 10, 0.54) 100%);
}
.ui {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.brand {
position: absolute;
top: 26px;
left: 30px;
max-width: 340px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 1px;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
text-transform: uppercase;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.04em;
}
.readout {
position: absolute;
top: 24px;
right: 24px;
width: min(330px, calc(100vw - 32px));
padding: 14px;
border: 1px solid rgba(98, 232, 255, 0.16);
border-radius: 16px;
background: rgba(4, 14, 26, 0.67);
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(14px);
}
.status {
display: flex;
align-items: center;
gap: 10px;
min-height: 42px;
padding: 0 12px;
border: 1px solid rgba(98, 232, 255, 0.18);
border-radius: 10px;
background: rgba(98, 232, 255, 0.055);
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
transition: 180ms ease;
}
.dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.status[data-state="valid"] {
color: var(--green);
border-color: rgba(115, 255, 194, 0.38);
background: rgba(115, 255, 194, 0.09);
}
.status[data-state="miss"] {
color: var(--red);
border-color: rgba(255, 101, 122, 0.38);
background: rgba(255, 101, 122, 0.09);
}
.status[data-state="inbound"] .dot {
animation: pulse 1.1s ease-in-out infinite;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 10px;
}
.metric {
min-width: 0;
padding: 11px 10px 10px;
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.metric span {
display: block;
margin-bottom: 5px;
color: #6f879c;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.metric strong {
display: block;
overflow: hidden;
color: #eaf8ff;
font-size: 16px;
font-variant-numeric: tabular-nums;
text-overflow: ellipsis;
white-space: nowrap;
}
#alignment.locked {
color: var(--green);
}
.readout-footer {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 11px;
}
.legend {
display: flex;
gap: 13px;
color: #7890a4;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
display: block;
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 8px rgba(98, 232, 255, 0.65);
}
.legend .valid i {
background: var(--green);
box-shadow: 0 0 8px rgba(115, 255, 194, 0.65);
}
#reset {
pointer-events: auto;
padding: 7px 10px;
border: 1px solid rgba(98, 232, 255, 0.2);
border-radius: 7px;
background: rgba(98, 232, 255, 0.06);
color: #b9d6e6;
font: inherit;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
transition: 160ms ease;
}
#reset:hover {
border-color: rgba(98, 232, 255, 0.55);
background: rgba(98, 232, 255, 0.13);
color: white;
}
.instructions {
position: absolute;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 13px;
width: max-content;
max-width: calc(100vw - 28px);
padding: 10px 14px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 999px;
background: rgba(3, 11, 21, 0.62);
color: #8299ac;
font-size: 10px;
letter-spacing: 0.055em;
backdrop-filter: blur(10px);
}
.instructions b {
color: #d9f5ff;
font-weight: 750;
}
.key {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 25px;
height: 22px;
margin: 0 2px;
padding: 0 6px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-bottom-color: rgba(255, 255, 255, 0.28);
border-radius: 5px;
background: rgba(255, 255, 255, 0.045);
color: #c9e9f5;
font-size: 9px;
font-weight: 800;
}
.separator {
width: 1px;
height: 13px;
background: rgba(255, 255, 255, 0.1);
}
@keyframes pulse {
0%, 100% {
opacity: 0.35;
transform: scale(0.78);
}
50% {
opacity: 1;
transform: scale(1.2);
}
}
@media (max-width: 700px) {
.brand {
top: 17px;
left: 17px;
}
h1 {
font-size: 22px;
}
.subtitle {
display: none;
}
.readout {
top: 76px;
right: 14px;
width: calc(100vw - 28px);
}
.instructions {
bottom: 14px;
gap: 8px;
padding: 9px 12px;
font-size: 9px;
}
.desktop-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header class="brand">
<div class="eyebrow">Kinetic study / 01</div>
<h1>Contact Lab</h1>
<p class="subtitle">Align the paddle with the incoming trajectory.</p>
</header>
<aside class="readout">
<div class="status" id="status" data-state="inbound">
<span class="dot"></span>
<span id="statusText">Ball inbound</span>
</div>
<div class="metrics">
<div class="metric">
<span>Valid hits</span>
<strong id="hits">00</strong>
</div>
<div class="metric">
<span>Missed</span>
<strong id="misses">00</strong>
</div>
<div class="metric">
<span>Alignment</span>
<strong id="alignment">LOCKED</strong>
</div>
</div>
<div class="readout-footer">
<div class="legend">
<span><i></i> Contact plane</span>
<span class="valid"><i></i> Valid zone</span>
</div>
<button id="reset" type="button">Restart</button>
</div>
</aside>
<div class="instructions">
<span><b>Move pointer</b> / <span class="key">A</span><span class="key">D</span> to steer</span>
<span class="separator desktop-hint"></span>
<span class="desktop-hint"><b>Right-drag</b> orbit · <b>Scroll</b> zoom</span>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x030710, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D paddle and approaching ball contact demonstration"
);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x050914, 15, 32);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
yaw: 0.34,
pitch: 0.3,
radius: 12.6,
target: new THREE.Vector3(0, 0.72, 0)
};
function updateCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.pitch,
cameraState.yaw
);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
}
updateCamera();
const COLORS = {
cyan: new THREE.Color(0x62e8ff),
green: new THREE.Color(0x73ffc2),
amber: new THREE.Color(0xffbd66),
red: new THREE.Color(0xff657a),
white: new THREE.Color(0xeafaff)
};
const CONTACT_Y = -0.63;
const PLANE_WIDTH = 7.8;
const PLANE_DEPTH = 3.5;
const PADDLE_WIDTH = 2.9;
const FOOTPRINT_WIDTH = 3.25;
const FOOTPRINT_DEPTH = 1.45;
const damp = (a, b, lambda, dt) =>
THREE.MathUtils.lerp(a, b, 1 - Math.exp(-lambda * dt));
// Lighting
scene.add(new THREE.HemisphereLight(0x9eeaff, 0x050713, 1.65));
const keyLight = new THREE.DirectionalLight(0xdaf7ff, 3.3);
keyLight.position.set(4.5, 9, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x38dfff, 28, 13, 2);
cyanLight.position.set(-4.5, 2.7, 4);
scene.add(cyanLight);
const greenLight = new THREE.PointLight(0x54ffba, 18, 10, 2);
greenLight.position.set(4, -0.2, 2.5);
scene.add(greenLight);
// Arena floor and grid
const floor = new THREE.Mesh(
new THREE.BoxGeometry(18, 0.12, 12),
new THREE.MeshStandardMaterial({
color: 0x071321,
roughness: 0.82,
metalness: 0.24
})
);
floor.position.y = -1.9;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(16, 24, 0x2abed6, 0x17455b);
grid.position.y = -1.825;
grid.material.transparent = true;
grid.material.opacity = 0.2;
grid.material.depthWrite = false;
scene.add(grid);
const railMaterial = new THREE.MeshBasicMaterial({
color: 0x1e738a,
transparent: true,
opacity: 0.7
});
for (const z of [-3.05, 3.05]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(9.7, 0.035, 0.035),
railMaterial
);
rail.position.set(0, -1.78, z);
scene.add(rail);
}
for (const x of [-4.85, 4.85]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.035, 6.1),
railMaterial
);
rail.position.set(x, -1.78, 0);
scene.add(rail);
}
// Subtle background particles
{
const count = 110;
const positions = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
positions[i * 3] = (Math.random() - 0.5) * 20;
positions[i * 3 + 1] = Math.random() * 10 - 1;
positions[i * 3 + 2] = (Math.random() - 0.5) * 13 - 1;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
const stars = new THREE.Points(
geometry,
new THREE.PointsMaterial({
color: 0x67cce4,
size: 0.025,
transparent: true,
opacity: 0.45,
depthWrite: false
})
);
scene.add(stars);
}
// Marked contact plane
const planeMaterial = new THREE.MeshBasicMaterial({
color: COLORS.cyan,
transparent: true,
opacity: 0.055,
side: THREE.DoubleSide,
depthWrite: false
});
const contactPlane = new THREE.Mesh(
new THREE.PlaneGeometry(PLANE_WIDTH, PLANE_DEPTH),
planeMaterial
);
contactPlane.rotation.x = -Math.PI / 2;
contactPlane.position.y = CONTACT_Y;
contactPlane.renderOrder = 1;
scene.add(contactPlane);
const planeBorderMaterial = new THREE.LineBasicMaterial({
color: COLORS.cyan,
transparent: true,
opacity: 0.78
});
const planeBorder = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(PLANE_WIDTH, 0.025, PLANE_DEPTH)
),
planeBorderMaterial
);
planeBorder.position.y = CONTACT_Y + 0.015;
scene.add(planeBorder);
{
const positions = [];
const divisionsX = 8;
const divisionsZ = 4;
for (let i = 0; i <= divisionsX; i++) {
const x = -PLANE_WIDTH / 2 + (PLANE_WIDTH * i) / divisionsX;
positions.push(x, 0, -PLANE_DEPTH / 2, x, 0, PLANE_DEPTH / 2);
}
for (let i = 0; i <= divisionsZ; i++) {
const z = -PLANE_DEPTH / 2 + (PLANE_DEPTH * i) / divisionsZ;
positions.push(-PLANE_WIDTH / 2, 0, z, PLANE_WIDTH / 2, 0, z);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const gridLines = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color: 0x42d7f2,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
gridLines.position.y = CONTACT_Y + 0.018;
scene.add(gridLines);
}
// Brighter corner brackets
{
const positions = [];
const arm = 0.45;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const x = sx * (PLANE_WIDTH / 2 - 0.15);
const z = sz * (PLANE_DEPTH / 2 - 0.15);
positions.push(x, 0, z, x - sx * arm, 0, z);
positions.push(x, 0, z, x, 0, z - sz * arm);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const brackets = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color: 0x8af2ff,
transparent: true,
opacity: 0.9
})
);
brackets.position.y = CONTACT_Y + 0.035;
scene.add(brackets);
}
// Paddle-shaped green footprint projected onto the contact plane
const footprintGroup = new THREE.Group();
footprintGroup.position.y = CONTACT_Y;
scene.add(footprintGroup);
const footprintMaterial = new THREE.MeshBasicMaterial({
color: COLORS.green,
transparent: true,
opacity: 0.1,
side: THREE.DoubleSide,
depthWrite: false
});
const footprint = new THREE.Mesh(
new THREE.PlaneGeometry(FOOTPRINT_WIDTH, FOOTPRINT_DEPTH),
footprintMaterial
);
footprint.rotation.x = -Math.PI / 2;
footprint.position.y = 0.025;
footprintGroup.add(footprint);
const footprintBorderMaterial = new THREE.LineBasicMaterial({
color: COLORS.green,
transparent: true,
opacity: 0.92
});
const footprintBorder = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(FOOTPRINT_WIDTH, 0.018, FOOTPRINT_DEPTH)
),
footprintBorderMaterial
);
footprintBorder.position.y = 0.032;
footprintGroup.add(footprintBorder);
// Landing reticle
const reticleGroup = new THREE.Group();
reticleGroup.position.y = CONTACT_Y + 0.045;
scene.add(reticleGroup);
const reticleMaterial = new THREE.MeshBasicMaterial({
color: COLORS.green,
transparent: true,
opacity: 0.95,
side: THREE.DoubleSide,
depthWrite: false
});
const reticle = new THREE.Mesh(
new THREE.RingGeometry(0.3, 0.365, 64),
reticleMaterial
);
reticle.rotation.x = -Math.PI / 2;
reticleGroup.add(reticle);
const crossGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.52, 0, 0),
new THREE.Vector3(-0.38, 0, 0),
new THREE.Vector3(0.38, 0, 0),
new THREE.Vector3(0.52, 0, 0),
new THREE.Vector3(0, 0, -0.52),
new THREE.Vector3(0, 0, -0.38),
new THREE.Vector3(0, 0, 0.38),
new THREE.Vector3(0, 0, 0.52)
]);
const reticleCross = new THREE.LineSegments(
crossGeometry,
new THREE.LineBasicMaterial({
color: COLORS.green,
transparent: true,
opacity: 0.85,
depthTest: false
})
);
reticleCross.renderOrder = 5;
reticleGroup.add(reticleCross);
// Vertical approach guide
const guideGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, CONTACT_Y, 0),
new THREE.Vector3(0, 5, 0)
]);
const guideMaterial = new THREE.LineDashedMaterial({
color: COLORS.green,
transparent: true,
opacity: 0.48,
dashSize: 0.16,
gapSize: 0.12,
depthTest: false
});
const guide = new THREE.Line(guideGeometry, guideMaterial);
guide.renderOrder = 4;
scene.add(guide);
// Rounded paddle geometry
function roundedRectangleShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
const paddleRoot = new THREE.Group();
paddleRoot.position.set(0, -1.15, 0);
scene.add(paddleRoot);
const paddlePivot = new THREE.Group();
paddleRoot.add(paddlePivot);
const paddleGeometry = new THREE.ExtrudeGeometry(
roundedRectangleShape(PADDLE_WIDTH, 0.28, 0.13),
{
depth: 1.15,
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: 0.045,
bevelThickness: 0.045,
curveSegments: 12
}
);
paddleGeometry.translate(0, 0, -0.575);
const paddleMaterial = new THREE.MeshPhysicalMaterial({
color: 0xcfe9f2,
roughness: 0.24,
metalness: 0.42,
clearcoat: 0.85,
clearcoatRoughness: 0.2
});
const paddleBody = new THREE.Mesh(paddleGeometry, paddleMaterial);
paddleBody.castShadow = true;
paddleBody.receiveShadow = true;
paddlePivot.add(paddleBody);
const paddleEdgeMaterial = new THREE.LineBasicMaterial({
color: COLORS.cyan,
transparent: true,
opacity: 0.95
});
const paddleEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(paddleGeometry, 25),
paddleEdgeMaterial
);
paddlePivot.add(paddleEdges);
const stripMaterial = new THREE.MeshStandardMaterial({
color: 0x123b43,
emissive: COLORS.green,
emissiveIntensity: 1.3,
roughness: 0.35,
metalness: 0.25
});
const paddleStrip = new THREE.Mesh(
new THREE.BoxGeometry(PADDLE_WIDTH - 0.25, 0.035, 0.82),
stripMaterial
);
paddleStrip.position.y = 0.165;
paddlePivot.add(paddleStrip);
for (const x of [-1.2, 1.2]) {
const light = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 12, 8),
new THREE.MeshBasicMaterial({ color: COLORS.green })
);
light.position.set(x, 0.19, 0.28);
paddlePivot.add(light);
}
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.16, 0.56, 18),
new THREE.MeshStandardMaterial({
color: 0x183344,
roughness: 0.38,
metalness: 0.65
})
);
stem.position.y = -0.43;
stem.castShadow = true;
paddleRoot.add(stem);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.52, 0.66, 0.09, 32),
new THREE.MeshStandardMaterial({
color: 0x0d2434,
roughness: 0.4,
metalness: 0.6
})
);
base.position.y = -0.7;
base.castShadow = true;
paddleRoot.add(base);
// Ball
const ballGroup = new THREE.Group();
scene.add(ballGroup);
const ball = new THREE.Mesh(
new THREE.SphereGeometry(0.38, 48, 32),
new THREE.MeshPhysicalMaterial({
color: 0xf2fdff,
emissive: 0x45cfea,
emissiveIntensity: 0.42,
roughness: 0.12,
metalness: 0.16,
clearcoat: 1,
clearcoatRoughness: 0.08
})
);
ball.castShadow = true;
ballGroup.add(ball);
const ballRing = new THREE.Mesh(
new THREE.TorusGeometry(0.49, 0.014, 10, 96),
new THREE.MeshBasicMaterial({
color: 0x79efff,
transparent: true,
opacity: 0.8
})
);
ballRing.rotation.set(0.75, 0.25, 0);
ballGroup.add(ballRing);
const ballWire = new THREE.Mesh(
new THREE.SphereGeometry(0.415, 16, 12),
new THREE.MeshBasicMaterial({
color: 0x79efff,
wireframe: true,
transparent: true,
opacity: 0.12
})
);
ballGroup.add(ballWire);
const ballLight = new THREE.PointLight(0x62e8ff, 18, 4.5, 2);
ballGroup.add(ballLight);
function createGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
64, 64, 0,
64, 64, 64
);
gradient.addColorStop(0, "rgba(190,250,255,0.95)");
gradient.addColorStop(0.18, "rgba(80,225,255,0.45)");
gradient.addColorStop(0.52, "rgba(50,180,255,0.12)");
gradient.addColorStop(1, "rgba(0,0,0,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 128, 128);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const ballGlow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: createGlowTexture(),
color: 0x6ae9ff,
transparent: true,
opacity: 0.72,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
ballGlow.scale.set(1.8, 1.8, 1);
ballGroup.add(ballGlow);
// Ball trail
const trailMeshes = [];
const trailHistory = [];
for (let i = 0; i < 14; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0x67eaff,
transparent: true,
opacity: 0.26 * (1 - i / 14),
depthWrite: false,
blending: THREE.AdditiveBlending
});
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(0.058 * (1 - i / 22), 8, 6),
material
);
scene.add(mesh);
trailMeshes.push(mesh);
}
// Expanding impact ring
const impactRing = new THREE.Mesh(
new THREE.RingGeometry(0.29, 0.36, 64),
new THREE.MeshBasicMaterial({
color: COLORS.green,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
impactRing.rotation.x = -Math.PI / 2;
impactRing.visible = false;
scene.add(impactRing);
// Contact burst particles
const particles = [];
const particleGeometry = new THREE.OctahedronGeometry(0.055, 0);
for (let i = 0; i < 24; i++) {
const mesh = new THREE.Mesh(
particleGeometry,
new THREE.MeshBasicMaterial({
color: COLORS.green,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
mesh.visible = false;
mesh.userData.velocity = new THREE.Vector3();
mesh.userData.life = 0;
scene.add(mesh);
particles.push(mesh);
}
// Scene label
function createLabel(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(4,15,27,0.78)";
context.strokeStyle = color;
context.lineWidth = 3;
context.beginPath();
context.roundRect(5, 5, 758, 150, 22);
context.fill();
context.stroke();
context.fillStyle = color;
context.font = "700 45px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.letterSpacing = "5px";
context.fillText(text, 384, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
})
);
sprite.scale.set(3.45, 0.72, 1);
sprite.renderOrder = 8;
return sprite;
}
const planeLabel = createLabel("CONTACT PLANE", "#73dcff");
planeLabel.position.set(0, CONTACT_Y + 0.14, -2.25);
scene.add(planeLabel);
// Simulation state
let mode = "approach";
let approachTime = 0;
let approachDuration = 2.65;
let startY = 5.2;
let targetBallX = 0;
let currentBallX = 0;
let bounceTime = 0;
let missTime = 0;
let hits = 0;
let misses = 0;
let feedbackStrength = 0;
let impactLife = 0;
const feedbackColor = COLORS.green.clone();
const basePlaneColor = COLORS.cyan.clone();
let paddleTargetX = 0;
let paddleVelocity = 0;
let keyLeft = false;
let keyRight = false;
const statusElement = document.getElementById("status");
const statusText = document.getElementById("statusText");
const hitsElement = document.getElementById("hits");
const missesElement = document.getElementById("misses");
const alignmentElement = document.getElementById("alignment");
const resetButton = document.getElementById("reset");
function nextBallTarget() {
const sign = Math.random() > 0.5 ? 1 : -1;
return sign * (1.3 + Math.random() * 1.2);
}
function beginApproach(initial = false) {
mode = "approach";
approachTime = 0;
startY = initial ? 5.2 : 4.75;
approachDuration = initial ? 2.65 : 1.8;
targetBallX = initial ? 0 : nextBallTarget();
if (initial) {
currentBallX = 0;
}
ballGroup.position.y = startY;
}
function restart() {
hits = 0;
misses = 0;
feedbackStrength = 0;
impactLife = 0;
impactRing.visible = false;
for (const particle of particles) {
particle.visible = false;
particle.userData.life = 0;
}
beginApproach(true);
}
function spawnBurst(color) {
for (const particle of particles) {
particle.visible = true;
particle.position.set(
ballGroup.position.x,
CONTACT_Y + 0.04,
ballGroup.position.z
);
particle.userData.velocity.set(
(Math.random() - 0.5) * 4.5,
0.6 + Math.random() * 2.8,
(Math.random() - 0.5) * 4.5
);
particle.userData.life = 0.55 + Math.random() * 0.45;
particle.material.color.copy(color);
particle.material.opacity = 1;
particle.scale.setScalar(1);
}
}
function resolveContact() {
const offset = Math.abs(
ballGroup.position.x - paddleRoot.position.x
);
const valid = offset <= PADDLE_WIDTH * 0.5 + 0.12;
ballGroup.position.y = CONTACT_Y;
if (valid) {
hits++;
mode = "bounce";
bounceTime = 0;
feedbackColor.copy(COLORS.green);
feedbackStrength = 1;
impactLife = 1;
impactRing.visible = true;
impactRing.position.set(
ballGroup.position.x,
CONTACT_Y + 0.075,
0
);
impactRing.scale.setScalar(1);
impactRing.material.color.copy(COLORS.green);
spawnBurst(COLORS.green);
} else {
misses++;
mode = "miss";
missTime = 0;
feedbackColor.copy(COLORS.red);
feedbackStrength = 1;
spawnBurst(COLORS.red);
}
}
function updateBall(dt) {
if (mode === "approach") {
approachTime += dt;
const t = Math.min(1, approachTime / approachDuration);
currentBallX = damp(currentBallX, targetBallX, 3.8, dt);
ballGroup.position.x = currentBallX;
ballGroup.position.y = THREE.MathUtils.lerp(
startY,
CONTACT_Y,
t * t
);
if (t >= 1) {
resolveContact();
}
} else if (mode === "bounce") {
bounceTime += dt;
const t = Math.min(1, bounceTime / 1.18);
currentBallX = damp(currentBallX, targetBallX, 3.3, dt);
ballGroup.position.x = currentBallX;
ballGroup.position.y =
CONTACT_Y + 4.0 * 4 * t * (1 - t);
if (t >= 1) {
beginApproach(false);
startY = ballGroup.position.y;
approachDuration = 1.45;
}
} else if (mode === "miss") {
missTime += dt;
ballGroup.position.y =
CONTACT_Y - 3.7 * missTime * missTime;
if (missTime > 0.55) {
beginApproach(false);
}
}
}
// Direct pointer and keyboard controls
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const paddlePlane = new THREE.Plane(
new THREE.Vector3(0, 1, 0),
1.15
);
const intersection = new THREE.Vector3();
let orbiting = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updatePaddleTarget(event) {
const bounds = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y =
-((event.clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(paddlePlane, intersection)) {
paddleTargetX = THREE.MathUtils.clamp(
intersection.x,
-4.15,
4.15
);
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button === 2) {
orbiting = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
} else {
updatePaddleTarget(event);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (orbiting) {
cameraState.yaw -=
(event.clientX - lastPointerX) * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch +
(event.clientY - lastPointerY) * 0.0045,
0.12,
0.72
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
} else {
updatePaddleTarget(event);
}
});
function endOrbit(event) {
orbiting = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endOrbit);
renderer.domElement.addEventListener("pointercancel", endOrbit);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
8.5,
17
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.code === "KeyA" || event.code === "ArrowLeft") {
keyLeft = true;
event.preventDefault();
}
if (event.code === "KeyD" || event.code === "ArrowRight") {
keyRight = true;
event.preventDefault();
}
if (event.code === "KeyR") {
restart();
}
});
window.addEventListener("keyup", (event) => {
if (event.code === "KeyA" || event.code === "ArrowLeft") {
keyLeft = false;
}
if (event.code === "KeyD" || event.code === "ArrowRight") {
keyRight = false;
}
});
resetButton.addEventListener("click", restart);
function updatePaddle(dt) {
const keyDirection = Number(keyRight) - Number(keyLeft);
paddleTargetX = THREE.MathUtils.clamp(
paddleTargetX + keyDirection * dt * 5.4,
-4.15,
4.15
);
const desiredVelocity =
(paddleTargetX - paddleRoot.position.x) * 12;
paddleVelocity = damp(
paddleVelocity,
desiredVelocity,
13,
dt
);
paddleRoot.position.x += paddleVelocity * dt;
paddlePivot.rotation.z = damp(
paddlePivot.rotation.z,
THREE.MathUtils.clamp(-paddleVelocity * 0.015, -0.18, 0.18),
10,
dt
);
footprintGroup.position.x = paddleRoot.position.x;
}
function updateParticles(dt) {
for (const particle of particles) {
if (particle.userData.life <= 0) {
continue;
}
particle.userData.life -= dt;
if (particle.userData.life <= 0) {
particle.visible = false;
continue;
}
particle.position.addScaledVector(
particle.userData.velocity,
dt
);
particle.userData.velocity.y -= 3.8 * dt;
particle.material.opacity = Math.min(
1,
particle.userData.life * 1.4
);
particle.scale.setScalar(
0.45 + particle.userData.life * 0.65
);
}
}
function updateVisuals(dt) {
const offset = Math.abs(
ballGroup.position.x - paddleRoot.position.x
);
const locked = offset <= PADDLE_WIDTH * 0.5 + 0.12;
const lockColor = locked ? COLORS.green : COLORS.amber;
feedbackStrength *= Math.exp(-dt * 4.2);
planeMaterial.color
.copy(basePlaneColor)
.lerp(feedbackColor, feedbackStrength * 0.9);
planeMaterial.opacity = 0.055 + feedbackStrength * 0.16;
planeBorderMaterial.color
.copy(basePlaneColor)
.lerp(feedbackColor, feedbackStrength);
footprintMaterial.color
.copy(lockColor)
.lerp(feedbackColor, feedbackStrength);
footprintMaterial.opacity = 0.085 + feedbackStrength * 0.17;
footprintBorderMaterial.color
.copy(lockColor)
.lerp(feedbackColor, feedbackStrength);
reticleMaterial.color
.copy(lockColor)
.lerp(feedbackColor, feedbackStrength);
reticleCross.material.color
.copy(lockColor)
.lerp(feedbackColor, feedbackStrength);
guideMaterial.color
.copy(lockColor)
.lerp(feedbackColor, feedbackStrength);
paddleEdgeMaterial.color
.copy(lockColor)
.lerp(feedbackColor, feedbackStrength);
stripMaterial.emissive.copy(lockColor);
stripMaterial.emissiveIntensity = locked ? 1.4 : 0.35;
reticleGroup.position.x = ballGroup.position.x;
reticleGroup.rotation.y += dt * 0.32;
const guidePositions = guideGeometry.attributes.position;
guidePositions.setXYZ(
0,
ballGroup.position.x,
CONTACT_Y + 0.045,
0
);
guidePositions.setXYZ(
1,
ballGroup.position.x,
ballGroup.position.y - 0.32,
0
);
guidePositions.needsUpdate = true;
guide.computeLineDistances();
if (impactLife > 0) {
impactLife = Math.max(0, impactLife - dt / 0.72);
impactRing.visible = true;
impactRing.scale.setScalar(1 + (1 - impactLife) * 4.8);
impactRing.material.opacity = impactLife * 0.85;
} else {
impactRing.visible = false;
}
// Trail history
trailHistory.unshift(ballGroup.position.clone());
if (trailHistory.length > trailMeshes.length) {
trailHistory.pop();
}
trailMeshes.forEach((mesh, index) => {
const historyPosition =
trailHistory[Math.min(index, trailHistory.length - 1)];
mesh.position.copy(historyPosition);
mesh.material.opacity = 0.24 * (1 - index / trailMeshes.length);
});
ballRing.rotation.z += dt * 1.4;
ballRing.rotation.y += dt * 0.75;
ballWire.rotation.y -= dt * 0.25;
ballGlow.material.opacity =
0.66 + Math.sin(performance.now() * 0.006) * 0.08;
// Interface
hitsElement.textContent = String(hits).padStart(2, "0");
missesElement.textContent = String(misses).padStart(2, "0");
alignmentElement.textContent = locked ? "LOCKED" : `${offset.toFixed(1)} m`;
alignmentElement.classList.toggle("locked", locked);
if (mode === "approach") {
statusElement.dataset.state = "inbound";
statusText.textContent = "Ball inbound";
} else if (mode === "bounce") {
statusElement.dataset.state = "valid";
statusText.textContent = "Valid contact";
} else {
statusElement.dataset.state = "miss";
statusText.textContent = "Contact missed";
}
}
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = camera.aspect < 0.78 ? 55 : 42;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", onResize);
onResize();
restart();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.04);
updatePaddle(dt);
updateBall(dt);
updateParticles(dt);
updateVisuals(dt);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```