Prompt specification
Build or customize the Three.js 3D scene "Marked Wheel and Contact Point" 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: Marked Wheel and Contact Point
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/marked-wheel-and-contact-point-x3637
Scene Description Prompt:
Model a wheel with a visible radius and rim marker on a flat track. Show the contact point and distinguish translation from rotation geometrically. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (marked-wheel-and-contact-point-x3637):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Rolling Wheel — Translation and Rotation</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: #172033;
background: #eaf0f6;
}
#app,
#app canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
}
.panel {
position: absolute;
z-index: 10;
padding: 16px 18px;
border: 1px solid rgba(91, 108, 130, 0.25);
border-radius: 12px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 10px 30px rgba(31, 49, 76, 0.12);
backdrop-filter: blur(12px);
}
#legend {
top: 18px;
left: 18px;
width: 285px;
}
#legend h1 {
margin: 0 0 5px;
font-size: 18px;
letter-spacing: -0.02em;
}
#legend p {
margin: 0 0 13px;
color: #5b6678;
font-size: 12px;
line-height: 1.45;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 8px 0;
font-size: 12px;
}
.swatch {
width: 25px;
height: 4px;
flex: 0 0 auto;
border-radius: 4px;
}
.swatch.radius {
background: #7c3aed;
}
.swatch.rotation {
background: #f59e0b;
}
.swatch.translation {
background: #0891b2;
}
.swatch.contact {
width: 10px;
height: 10px;
margin: 0 7px;
border-radius: 50%;
background: #eab308;
box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.18);
}
.formula {
margin-top: 13px;
padding: 9px 10px;
border-radius: 8px;
background: #eef2f7;
color: #475569;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
text-align: center;
}
#controls {
right: 18px;
top: 18px;
display: flex;
gap: 8px;
}
button {
padding: 8px 12px;
border: 1px solid #cbd5e1;
border-radius: 8px;
color: #243047;
background: rgba(255, 255, 255, 0.94);
font: inherit;
font-size: 12px;
font-weight: 650;
cursor: pointer;
}
button:hover {
border-color: #94a3b8;
background: #f8fafc;
}
#hint {
position: absolute;
z-index: 10;
right: 18px;
bottom: 16px;
padding: 8px 11px;
border-radius: 8px;
color: #64748b;
background: rgba(255, 255, 255, 0.78);
font-size: 11px;
pointer-events: none;
}
.label {
position: absolute;
z-index: 5;
padding: 5px 8px;
border: 1px solid currentColor;
border-radius: 6px;
background: rgba(255, 255, 255, 0.91);
box-shadow: 0 3px 12px rgba(30, 41, 59, 0.12);
font-size: 11px;
font-weight: 700;
line-height: 1;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
}
#radiusLabel {
color: #6d28d9;
}
#markerLabel {
color: #be185d;
}
#rotationLabel {
color: #b45309;
}
#translationLabel {
color: #0e7490;
}
#contactLabel {
color: #a16207;
}
#axleLabel {
color: #475569;
}
@media (max-width: 700px) {
#legend {
width: 230px;
padding: 12px;
}
#legend p,
.formula {
display: none;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<section id="legend" class="panel">
<h1>Rolling Wheel</h1>
<p>
The wheel is rigid. Its axle translates along the track while the
rim rotates about the axle.
</p>
<div class="legend-row">
<span class="swatch radius"></span>
<span>Wheel radius, fixed to the wheel</span>
</div>
<div class="legend-row">
<span class="swatch rotation"></span>
<span>Rotation about the axle</span>
</div>
<div class="legend-row">
<span class="swatch translation"></span>
<span>Translation of the axle</span>
</div>
<div class="legend-row">
<span class="swatch contact"></span>
<span>Instantaneous contact point</span>
</div>
<div class="formula">
No slip: θ = −x / R · R = 1.15 m
</div>
</section>
<div id="controls" class="panel">
<button id="pauseButton" type="button">Pause</button>
<button id="resetButton" type="button">Reset motion</button>
</div>
<div id="hint">Drag to orbit · Scroll to zoom</div>
<div id="radiusLabel" class="label">Radius R = 1.15 m</div>
<div id="markerLabel" class="label">Rim marker</div>
<div id="rotationLabel" class="label">Rotation</div>
<div id="translationLabel" class="label">Translation of axle</div>
<div id="contactLabel" class="label">Contact point</div>
<div id="axleLabel" class="label">Axle center</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeaf0f6);
scene.fog = new THREE.Fog(0xeaf0f6, 13, 30);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
app.appendChild(renderer.domElement);
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xffffff, 0x66758b, 2.1));
const sun = new THREE.DirectionalLight(0xffffff, 3.0);
sun.position.set(4.5, 8, 5.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0005;
scene.add(sun);
// ---------------------------------------------------------------------
// Flat track
// ---------------------------------------------------------------------
const trackMaterial = new THREE.MeshStandardMaterial({
color: 0xb9c5d1,
roughness: 0.96,
metalness: 0.0,
flatShading: true
});
const track = new THREE.Mesh(
new THREE.BoxGeometry(20, 0.18, 6),
trackMaterial
);
track.position.y = -0.09;
track.receiveShadow = true;
scene.add(track);
const trackEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(track.geometry),
new THREE.LineBasicMaterial({
color: 0x8795a8,
transparent: true,
opacity: 0.7
})
);
trackEdges.position.copy(track.position);
scene.add(trackEdges);
// Subtle grid drawn directly on the track.
const gridVertices = [];
for (let x = -9; x <= 9; x += 1) {
gridVertices.push(x, 0.006, -2.8, x, 0.006, 2.8);
}
for (let z = -2.5; z <= 2.5; z += 1) {
gridVertices.push(-9, 0.006, z, 9, 0.006, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
scene.add(
new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x9aa8b9,
transparent: true,
opacity: 0.42
})
)
);
// ---------------------------------------------------------------------
// Low-poly wheel
// ---------------------------------------------------------------------
const R = 1.15;
const TIRE_TUBE = 0.13;
const wheel = new THREE.Group();
wheel.position.set(0, R, 0);
scene.add(wheel);
const tireMaterial = new THREE.MeshStandardMaterial({
color: 0x202a38,
roughness: 0.83,
metalness: 0.04,
flatShading: true
});
const tire = new THREE.Mesh(
new THREE.TorusGeometry(R - TIRE_TUBE, TIRE_TUBE, 6, 20),
tireMaterial
);
tire.castShadow = true;
tire.receiveShadow = true;
wheel.add(tire);
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0xb7c2cf,
roughness: 0.43,
metalness: 0.58,
flatShading: true
});
const rim = new THREE.Mesh(
new THREE.TorusGeometry(R * 0.68, 0.045, 5, 16),
rimMaterial
);
rim.position.z = 0.16;
rim.castShadow = true;
wheel.add(rim);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.23, 0.56, 10),
rimMaterial
);
hub.rotation.x = Math.PI / 2;
hub.castShadow = true;
wheel.add(hub);
const axle = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 1.05, 8),
new THREE.MeshStandardMaterial({
color: 0x526173,
roughness: 0.4,
metalness: 0.7,
flatShading: true
})
);
axle.rotation.x = Math.PI / 2;
axle.castShadow = true;
wheel.add(axle);
const spokeMaterial = new THREE.MeshStandardMaterial({
color: 0xd3dbe4,
roughness: 0.48,
metalness: 0.42,
flatShading: true
});
const spokeLength = R * 0.66;
const spokeOffset = R * 0.34;
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const spoke = new THREE.Mesh(
new THREE.BoxGeometry(spokeLength, 0.075, 0.085),
spokeMaterial
);
spoke.position.set(
Math.cos(angle) * spokeOffset,
Math.sin(angle) * spokeOffset,
0.17
);
spoke.rotation.z = angle;
spoke.castShadow = true;
wheel.add(spoke);
}
// Bright rim marker. It is attached to the rotating wheel.
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xec4899,
emissive: 0x5b0f31,
emissiveIntensity: 0.35,
roughness: 0.35,
flatShading: true
});
const rimMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 8, 6),
markerMaterial
);
rimMarker.position.set(R - 0.10, 0, 0.145);
rimMarker.castShadow = true;
wheel.add(rimMarker);
// A radius line from the axle to the actual outer radius.
// The line is in the wheel, so it rotates with the rim.
const radiusGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0.22),
new THREE.Vector3(R, 0, 0.22)
]);
const radiusLine = new THREE.Line(
radiusGeometry,
new THREE.LineBasicMaterial({ color: 0x7c3aed })
);
wheel.add(radiusLine);
// ---------------------------------------------------------------------
// Rotation indicator: a curved arrow around the moving axle
// ---------------------------------------------------------------------
const rotationGuide = new THREE.Group();
rotationGuide.position.y = R;
scene.add(rotationGuide);
const rotationRadius = R + 0.36;
const rotationPoints = [];
const startAngle = 2.45;
const endAngle = 0.45;
for (let i = 0; i <= 60; i++) {
const t = i / 60;
const angle = THREE.MathUtils.lerp(startAngle, endAngle, t);
rotationPoints.push(
new THREE.Vector3(
Math.cos(angle) * rotationRadius,
Math.sin(angle) * rotationRadius,
0.35
)
);
}
const rotationArc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(rotationPoints),
new THREE.LineBasicMaterial({ color: 0xf59e0b })
);
rotationGuide.add(rotationArc);
// ConeGeometry points along +Y. Rotate it so its tip follows the
// clockwise tangent of the arc.
const rotationHead = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.30, 8),
new THREE.MeshBasicMaterial({ color: 0xf59e0b })
);
const tangent = new THREE.Vector3(
Math.sin(endAngle),
-Math.cos(endAngle),
0
).normalize();
rotationHead.position.set(
Math.cos(endAngle) * rotationRadius,
Math.sin(endAngle) * rotationRadius,
0.35
);
rotationHead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
rotationGuide.add(rotationHead);
// ---------------------------------------------------------------------
// Translation indicator: a straight double-headed arrow on the track
// ---------------------------------------------------------------------
const translationGroup = new THREE.Group();
translationGroup.position.set(0, 0.09, 1.65);
scene.add(translationGroup);
const translationColor = 0x0891b2;
const translationMaterial = new THREE.MeshStandardMaterial({
color: translationColor,
emissive: 0x073b4c,
emissiveIntensity: 0.25,
roughness: 0.5,
flatShading: true
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 2.5, 8),
translationMaterial
);
shaft.rotation.z = Math.PI / 2;
translationGroup.add(shaft);
const rightHead = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.30, 8),
translationMaterial
);
rightHead.rotation.z = -Math.PI / 2;
rightHead.position.x = 1.40;
translationGroup.add(rightHead);
const leftHead = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.30, 8),
translationMaterial
);
leftHead.rotation.z = Math.PI / 2;
leftHead.position.x = -1.40;
translationGroup.add(leftHead);
// ---------------------------------------------------------------------
// Contact-point visualization
// ---------------------------------------------------------------------
const contactGeometry = new THREE.BufferGeometry();
contactGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, R, 0,
0, 0.015, 0
], 3)
);
const contactLine = new THREE.Line(
contactGeometry,
new THREE.LineDashedMaterial({
color: 0xeab308,
dashSize: 0.10,
gapSize: 0.075,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
contactLine.computeLineDistances();
contactLine.renderOrder = 20;
scene.add(contactLine);
const contactPoint = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 8, 6),
new THREE.MeshBasicMaterial({
color: 0xfacc15,
depthTest: false
})
);
contactPoint.position.y = 0.025;
contactPoint.renderOrder = 21;
scene.add(contactPoint);
const contactRing = new THREE.Mesh(
new THREE.RingGeometry(0.12, 0.18, 20),
new THREE.MeshBasicMaterial({
color: 0xfacc15,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.88,
depthTest: false
})
);
contactRing.rotation.x = -Math.PI / 2;
contactRing.position.y = 0.012;
contactRing.renderOrder = 19;
scene.add(contactRing);
const axleDot = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 8, 6),
new THREE.MeshBasicMaterial({ color: 0x334155 })
);
axleDot.position.z = 0.39;
wheel.add(axleDot);
// ---------------------------------------------------------------------
// Labels
// ---------------------------------------------------------------------
const labels = {
radius: document.querySelector("#radiusLabel"),
marker: document.querySelector("#markerLabel"),
rotation: document.querySelector("#rotationLabel"),
translation: document.querySelector("#translationLabel"),
contact: document.querySelector("#contactLabel"),
axle: document.querySelector("#axleLabel")
};
function placeLabel(element, worldPosition, offsetX = 0, offsetY = 0) {
const projected = worldPosition.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.transform =
`translate(-50%, -50%) translate(${offsetX}px, ${offsetY}px)`;
element.style.visibility =
projected.z > 1 || projected.z < -1 ? "hidden" : "visible";
}
// ---------------------------------------------------------------------
// Camera controls implemented directly without Three.js addons
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.0, 0);
let cameraRadius = 8.2;
let cameraTheta = 0.50;
let cameraPhi = 1.08;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + deltaY * 0.005,
0.25,
Math.PI * 0.86
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.006,
4.7,
16
);
},
{ passive: false }
);
updateCamera();
// ---------------------------------------------------------------------
// Motion controls and animation
// ---------------------------------------------------------------------
let paused = false;
let phase = -0.85;
const pauseButton = document.querySelector("#pauseButton");
const resetButton = document.querySelector("#resetButton");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
resetButton.addEventListener("click", () => {
phase = -0.85;
});
const clock = new THREE.Clock();
const wheelX = new THREE.Vector3();
const markerWorld = new THREE.Vector3();
const radiusWorld = new THREE.Vector3();
const contactWorld = new THREE.Vector3();
const axleWorld = new THREE.Vector3();
const rotationWorld = new THREE.Vector3();
const translationWorld = new THREE.Vector3(0, 0.18, 1.65);
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
phase += dt * 0.55;
}
// The axle translates back and forth. The wheel angle is tied to the
// axle position by the no-slip rolling condition theta = -x / R.
const x = 2.25 * Math.sin(phase);
wheel.position.x = x;
wheel.rotation.z = -x / R;
rotationGuide.position.x = x;
contactPoint.position.x = x;
contactRing.position.x = x;
const positions = contactLine.geometry.attributes.position;
positions.setXYZ(0, x, R, 0);
positions.setXYZ(1, x, 0.015, 0);
positions.needsUpdate = true;
contactLine.computeLineDistances();
// World positions for the HTML labels.
markerWorld.copy(rimMarker.position);
wheel.localToWorld(markerWorld);
radiusWorld.set(R * 0.55, 0, 0.25);
wheel.localToWorld(radiusWorld);
contactWorld.set(x, 0.03, 0);
axleWorld.set(x, R, 0.38);
rotationWorld.set(x, R + rotationRadius + 0.12, 0.35);
placeLabel(labels.radius, radiusWorld, 27, -22);
placeLabel(labels.marker, markerWorld, 33, -24);
placeLabel(labels.rotation, rotationWorld, 0, -3);
placeLabel(labels.translation, translationWorld, 0, -27);
placeLabel(labels.contact, contactWorld, 38, 22);
placeLabel(labels.axle, axleWorld, -42, -20);
renderer.render(scene, camera);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```