Prompt specification
Build or customize the Three.js 3D scene "Tube puncture localization model" 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: Tube puncture localization model
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tube-puncture-localization-model-x0241
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts bicycle inner-tube repair. Show a short inflated bicycle tube segment with a marked tiny opening and a translucent patch nearby; the patch must cover the opening with visible margin. Stylized solid forms.
Working Three.js Starter (tube-puncture-localization-model-x0241):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Inner Tube Repair</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #f2eee7;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
pointer-events: none;
color: #222b2d;
}
.eyebrow {
margin: 0 0 6px;
color: #b65331;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin: 9px 0 0;
color: #657073;
font-size: 13px;
}
.callout {
position: fixed;
z-index: 4;
pointer-events: none;
padding: 9px 12px 9px 10px;
border: 1px solid rgba(34, 43, 45, 0.14);
border-radius: 10px;
background: rgba(255, 253, 248, 0.92);
box-shadow: 0 8px 24px rgba(43, 47, 45, 0.09);
color: #293234;
font-size: 12px;
font-weight: 700;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
}
.callout span {
display: inline-grid;
width: 21px;
height: 21px;
margin-right: 7px;
place-items: center;
border-radius: 50%;
color: white;
font-size: 10px;
}
.callout.pinhole span {
background: #c65d37;
}
.callout.patch span {
background: #168e87;
}
.hint {
position: fixed;
right: 24px;
bottom: 22px;
z-index: 5;
pointer-events: none;
padding: 9px 12px;
border: 1px solid rgba(34, 43, 45, 0.12);
border-radius: 999px;
background: rgba(255, 253, 248, 0.78);
color: #697376;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
backdrop-filter: blur(8px);
}
@media (max-width: 700px) {
.title {
top: 18px;
left: 18px;
}
.subtitle {
display: none;
}
.callout {
padding: 7px 9px;
font-size: 10px;
}
.hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div class="title">
<p class="eyebrow">Workshop Study / 01</p>
<h1>Inner-tube repair</h1>
<p class="subtitle">A translucent patch aligned over a marked pinhole.</p>
</div>
<div id="pinholeLabel" class="callout pinhole">
<span>1</span>Marked pinhole
</div>
<div id="patchLabel" class="callout patch">
<span>2</span>Patch with clear margin
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D scene showing an inner-tube pinhole and a covering patch"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf2eee7);
scene.fog = new THREE.Fog(0xf2eee7, 9, 20);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
40
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff8ed, 0x6d7779, 2.1));
const keyLight = new THREE.DirectionalLight(0xfff3dc, 3.1);
keyLight.position.set(3.5, 6.5, 4.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xaed9df, 1.25);
fillLight.position.set(-4, 2.5, -3);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xffb277, 18, 9, 2);
rimLight.position.set(-2.5, 2.8, 3.2);
scene.add(rimLight);
// ------------------------------------------------------------
// Ground and stylized support blocks
// ------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe8e2d8,
roughness: 0.96,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0xc7b59c,
roughness: 0.82
});
for (const x of [-1.05, 1.05]) {
const support = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 0.17, 0.72),
supportMaterial
);
support.position.set(x, 0.085, 0);
support.castShadow = true;
support.receiveShadow = true;
scene.add(support);
}
// Soft graphic contact shadow.
const shadowMaterial = new THREE.MeshBasicMaterial({
color: 0x252b2b,
transparent: true,
opacity: 0.075,
depthWrite: false
});
const contactShadow = new THREE.Mesh(
new THREE.CircleGeometry(1, 64),
shadowMaterial
);
contactShadow.rotation.x = -Math.PI / 2;
contactShadow.scale.set(2.2, 0.62, 1);
contactShadow.position.set(0, 0.012, 0);
scene.add(contactShadow);
// ------------------------------------------------------------
// Short inflated inner-tube segment
// ------------------------------------------------------------
const tubeRadius = 0.56;
const tubeLength = 3.3;
const tubeY = 0.73;
const rubberMaterial = new THREE.MeshStandardMaterial({
color: 0x272d30,
roughness: 0.5,
metalness: 0.02
});
const innerRubberMaterial = new THREE.MeshStandardMaterial({
color: 0x101416,
roughness: 0.95,
side: THREE.BackSide
});
const tube = new THREE.Mesh(
new THREE.CylinderGeometry(
tubeRadius,
tubeRadius,
tubeLength,
64,
1,
true
),
rubberMaterial
);
tube.rotation.z = Math.PI / 2;
tube.position.y = tubeY;
tube.castShadow = true;
tube.receiveShadow = true;
scene.add(tube);
// Recessed dark interior makes the cut ends read as hollow.
const innerTube = new THREE.Mesh(
new THREE.CylinderGeometry(
0.395,
0.395,
tubeLength - 0.08,
64,
1,
true
),
innerRubberMaterial
);
innerTube.rotation.z = Math.PI / 2;
innerTube.position.y = tubeY;
innerTube.receiveShadow = true;
scene.add(innerTube);
// Rounded rubber rims around both open ends.
for (const x of [-tubeLength / 2, tubeLength / 2]) {
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.478, 0.082, 20, 64),
rubberMaterial
);
rim.rotation.y = Math.PI / 2;
rim.position.set(x, tubeY, 0);
rim.castShadow = true;
scene.add(rim);
}
// ------------------------------------------------------------
// Pinhole, marker ring, and surface-oriented patch
// ------------------------------------------------------------
// Surface point on the upper/front side of the tube.
const surfaceAngle = THREE.MathUtils.degToRad(55);
const surfaceNormal = new THREE.Vector3(
0,
Math.sin(surfaceAngle),
Math.cos(surfaceAngle)
);
const surfaceTangent = new THREE.Vector3(
0,
Math.cos(surfaceAngle),
-Math.sin(surfaceAngle)
);
const puncturePoint = new THREE.Vector3(
0.2,
tubeY + tubeRadius * surfaceNormal.y,
tubeRadius * surfaceNormal.z
);
// Local X follows the tube; local Y follows the curved surface.
const surfaceBasis = new THREE.Matrix4().makeBasis(
new THREE.Vector3(1, 0, 0),
surfaceTangent,
surfaceNormal
);
const surfaceQuaternion = new THREE.Quaternion().setFromRotationMatrix(
surfaceBasis
);
// The tiny dark opening.
const opening = new THREE.Mesh(
new THREE.CircleGeometry(0.048, 32),
new THREE.MeshBasicMaterial({ color: 0x090b0c })
);
opening.position.copy(puncturePoint).addScaledVector(surfaceNormal, 0.012);
opening.quaternion.copy(surfaceQuaternion);
scene.add(opening);
// Bright chalk-like marking around the pinhole.
const marker = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.013, 12, 48),
new THREE.MeshStandardMaterial({
color: 0xe16b3e,
roughness: 0.76,
emissive: 0x6b210d,
emissiveIntensity: 0.08
})
);
marker.position.copy(puncturePoint).addScaledVector(surfaceNormal, 0.018);
marker.quaternion.copy(surfaceQuaternion);
scene.add(marker);
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;
}
// Patch dimensions deliberately leave a generous visible border
// around the 0.105-unit marker ring.
const patchShape = roundedRectangleShape(1.02, 0.72, 0.2);
const patchGeometry = new THREE.ExtrudeGeometry(patchShape, {
depth: 0.035,
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: 0.014,
bevelThickness: 0.012,
curveSegments: 20
});
const patchMaterial = new THREE.MeshPhysicalMaterial({
color: 0x55c8bd,
roughness: 0.28,
metalness: 0,
transparent: true,
opacity: 0.58,
transmission: 0.18,
thickness: 0.055,
ior: 1.32,
side: THREE.DoubleSide,
depthWrite: false
});
const patchGroup = new THREE.Group();
// It floats only slightly above the tube, while remaining directly
// aligned over the opening.
patchGroup.position
.copy(puncturePoint)
.addScaledVector(surfaceNormal, 0.105);
patchGroup.quaternion.copy(surfaceQuaternion);
const patch = new THREE.Mesh(patchGeometry, patchMaterial);
patchGroup.add(patch);
// Crisp outline helps the translucent patch remain readable.
const patchOutlinePoints = patchShape
.getPoints(36)
.map((point) => new THREE.Vector3(point.x, point.y, 0.052));
const patchOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(patchOutlinePoints),
new THREE.LineBasicMaterial({
color: 0x147f79,
transparent: true,
opacity: 0.95
})
);
patchGroup.add(patchOutline);
// A subtle lighter center strip suggests the rubberized film.
const filmHighlight = new THREE.Mesh(
new THREE.PlaneGeometry(0.63, 0.13),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
filmHighlight.position.set(-0.06, 0.19, 0.055);
patchGroup.add(filmHighlight);
scene.add(patchGroup);
// ------------------------------------------------------------
// Small graphic leader lines for the labels
// ------------------------------------------------------------
function addLeader(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.7
});
const line = new THREE.Line(geometry, material);
scene.add(line);
return line;
}
const pinholeLabelAnchor = puncturePoint
.clone()
.addScaledVector(surfaceNormal, 0.34)
.add(new THREE.Vector3(-0.72, 0.18, 0.05));
const patchLabelAnchor = patchGroup.position
.clone()
.addScaledVector(surfaceNormal, 0.27)
.add(new THREE.Vector3(0.73, 0.19, 0.05));
addLeader(
[
puncturePoint.clone().addScaledVector(surfaceNormal, 0.08),
pinholeLabelAnchor
],
0xc65d37
);
addLeader(
[
patchGroup.position.clone().addScaledVector(surfaceNormal, 0.065),
patchLabelAnchor
],
0x168e87
);
// ------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel to zoom
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 0.87, 0);
const initialView = {
yaw: 0.57,
pitch: 0.31,
distance: 5.65
};
let yaw = initialView.yaw;
let pitch = initialView.pitch;
let distance = initialView.distance;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const horizontalDistance = Math.cos(pitch) * distance;
camera.position.set(
target.x + Math.sin(yaw) * horizontalDistance,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * horizontalDistance
);
camera.lookAt(target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
yaw -= deltaX * 0.006;
pitch += deltaY * 0.005;
pitch = THREE.MathUtils.clamp(pitch, -0.15, 1.15);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (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();
distance = THREE.MathUtils.clamp(
distance + event.deltaY * 0.004,
3.9,
9
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
yaw = initialView.yaw;
pitch = initialView.pitch;
distance = initialView.distance;
updateCamera();
});
updateCamera();
// ------------------------------------------------------------
// Project HTML annotations into screen space
// ------------------------------------------------------------
const pinholeLabel = document.getElementById("pinholeLabel");
const patchLabel = document.getElementById("patchLabel");
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
element.style.opacity = visible ? "1" : "0";
element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
renderer.setAnimationLoop(() => {
positionLabel(pinholeLabel, pinholeLabelAnchor);
positionLabel(patchLabel, patchLabelAnchor);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```