Prompt specification
Build or customize the Three.js 3D scene "Scarf wrapping sequence" 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: Scarf wrapping sequence
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/scarf-wrapping-sequence-x0614
Scene Description Prompt:
Wrap a low-poly scarf around a stand and through its loop while preserving over-under crossings. Create standalone HTML using Three.js from cdnjs.
Working Three.js Starter (scarf-wrapping-sequence-x0614):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Woven Through — Low-Poly Scarf Study</title>
<style>
:root {
--ink: #392820;
--muted: rgba(57, 40, 32, 0.62);
--paper: rgba(250, 246, 238, 0.78);
--line: rgba(57, 40, 32, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e0d3;
color: var(--ink);
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;
outline: none;
}
.title {
position: fixed;
top: clamp(22px, 4vw, 52px);
left: clamp(22px, 4vw, 58px);
z-index: 3;
pointer-events: none;
max-width: 330px;
}
.eyebrow {
margin-bottom: 9px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
color: var(--muted);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 6vw, 72px);
font-weight: 400;
line-height: 0.91;
letter-spacing: -0.045em;
}
.subtitle {
margin: 16px 0 0;
max-width: 245px;
font-size: 12px;
line-height: 1.55;
color: var(--muted);
}
.controls {
position: fixed;
right: clamp(18px, 3vw, 42px);
bottom: clamp(18px, 3vw, 34px);
z-index: 4;
display: flex;
align-items: center;
gap: 10px;
padding: 8px 9px 8px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(66, 42, 28, 0.09);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
font-size: 11px;
color: var(--muted);
user-select: none;
}
button {
border: 0;
border-radius: 999px;
padding: 8px 12px;
background: var(--ink);
color: #fffaf2;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
background: #65483b;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #e9e0d3;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.24em;
text-transform: uppercase;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 620px) {
.title {
max-width: 230px;
}
.subtitle {
display: none;
}
.controls {
left: 18px;
right: auto;
}
}
</style>
</head>
<body>
<div class="title">
<div class="eyebrow">Object study · 01</div>
<h1>Woven<br />Through</h1>
<p class="subtitle">
A faceted scarf wraps the timber stand, enters the brass loop, and returns
across itself with deliberate over-and-under crossings.
</p>
</div>
<div class="controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset</button>
</div>
<div id="loading">Preparing the weave</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e0d3);
scene.fog = new THREE.Fog(0xe9e0d3, 9, 19);
const camera = new THREE.PerspectiveCamera(
36,
innerWidth / innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.body.prepend(renderer.domElement);
// ------------------------------------------------------------
// Lighting and stage
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff4df, 0x705448, 2.15));
const key = new THREE.DirectionalLight(0xffead0, 4.2);
key.position.set(4.5, 7, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -5;
key.shadow.camera.right = 5;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -2;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 16;
key.shadow.bias = -0.00025;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0x9ab8d8, 1.35);
fill.position.set(-4, 3.5, 2);
scene.add(fill);
const rim = new THREE.PointLight(0xffb56b, 14, 10, 2);
rim.position.set(-2.8, 4.7, -2.5);
scene.add(rim);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xd8ccbb,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.012;
ground.receiveShadow = true;
scene.add(ground);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x4b3027,
roughness: 0.78,
metalness: 0,
flatShading: true
});
const darkWoodMaterial = new THREE.MeshStandardMaterial({
color: 0x2f201c,
roughness: 0.72,
metalness: 0,
flatShading: true
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xb58943,
roughness: 0.34,
metalness: 0.78,
flatShading: true
});
const creamMaterial = new THREE.MeshStandardMaterial({
color: 0xe8c99a,
roughness: 0.9,
metalness: 0,
flatShading: true
});
// ------------------------------------------------------------
// Faceted timber stand
// ------------------------------------------------------------
const stand = new THREE.Group();
scene.add(stand);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.52, 0.58, 0.16, 10),
darkWoodMaterial
);
base.position.y = 0.08;
base.castShadow = true;
base.receiveShadow = true;
stand.add(base);
const footRing = new THREE.Mesh(
new THREE.CylinderGeometry(0.3, 0.33, 0.065, 12),
brassMaterial
);
footRing.position.y = 0.185;
footRing.castShadow = true;
stand.add(footRing);
const column = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.23, 2.02, 10, 1),
woodMaterial
);
column.position.y = 1.22;
column.castShadow = true;
column.receiveShadow = true;
stand.add(column);
const lowerCollar = new THREE.Mesh(
new THREE.CylinderGeometry(0.235, 0.25, 0.13, 10),
brassMaterial
);
lowerCollar.position.y = 0.49;
lowerCollar.castShadow = true;
stand.add(lowerCollar);
const upperCollar = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.14, 10),
brassMaterial
);
upperCollar.position.y = 2.13;
upperCollar.castShadow = true;
stand.add(upperCollar);
const mount = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17, 1),
brassMaterial
);
mount.position.set(0, 2.01, 0);
mount.scale.set(1, 0.8, 1);
mount.castShadow = true;
stand.add(mount);
// Custom low-poly elliptical brass loop, lying in the XY plane.
function createEllipticalLoop(rx, ry, tubeRadius, centerY) {
const ringSegments = 36;
const tubeSegments = 6;
const positions = [];
const indices = [];
for (let i = 0; i <= ringSegments; i++) {
const a = (i / ringSegments) * Math.PI * 2;
const cx = rx * Math.cos(a);
const cy = centerY + ry * Math.sin(a);
// Radial vector perpendicular to the ellipse tangent.
const radial = new THREE.Vector3(
ry * Math.cos(a),
rx * Math.sin(a),
0
).normalize();
for (let j = 0; j <= tubeSegments; j++) {
const b = (j / tubeSegments) * Math.PI * 2;
const p = new THREE.Vector3(cx, cy, 0)
.addScaledVector(radial, Math.cos(b) * tubeRadius)
.addScaledVector(new THREE.Vector3(0, 0, 1), Math.sin(b) * tubeRadius);
positions.push(p.x, p.y, p.z);
}
}
const stride = tubeSegments + 1;
for (let i = 0; i < ringSegments; i++) {
for (let j = 0; j < tubeSegments; j++) {
const a = i * stride + j;
const b = a + stride;
const c = b + 1;
const d = a + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const loop = new THREE.Mesh(
createEllipticalLoop(0.5, 0.7, 0.047, 2.62),
brassMaterial
);
loop.castShadow = true;
loop.receiveShadow = true;
stand.add(loop);
// ------------------------------------------------------------
// Scarf centerline
//
// The route is authored as cubic Bézier sections. Depth and height
// changes at the three self-crossings keep the weave legible:
// 1. Return from the back passes over the ascending tail.
// 2. The descending diagonal passes in front of the rise.
// 3. The lower sweep passes in front of the first diagonal.
// ------------------------------------------------------------
const bezierSections = [
{
steps: 18,
p0: [-1.22, 0.20, 0.92],
p1: [-1.24, 0.28, 0.92],
p2: [-0.92, 1.15, 0.68],
p3: [-0.68, 1.48, 0.56]
},
{
steps: 15,
p0: [-0.68, 1.48, 0.56],
p1: [-0.52, 1.66, 0.60],
p2: [-0.26, 1.82, 0.68],
p3: [0.00, 1.86, 0.68]
},
{
steps: 15,
p0: [0.00, 1.86, 0.68],
p1: [0.30, 1.90, 0.62],
p2: [0.56, 1.88, 0.24],
p3: [0.53, 1.84, -0.22]
},
{
steps: 16,
p0: [0.53, 1.84, -0.22],
p1: [0.49, 1.90, -0.52],
p2: [0.08, 1.98, -0.60],
p3: [-0.43, 1.95, -0.42]
},
{
steps: 16,
p0: [-0.43, 1.95, -0.42],
p1: [-0.63, 1.93, -0.20],
p2: [-0.72, 1.84, 0.34],
p3: [-0.64, 1.84, 0.63]
},
{
steps: 18,
p0: [-0.64, 1.84, 0.63],
p1: [-0.60, 2.06, 0.58],
p2: [-0.42, 2.31, 0.40],
p3: [-0.22, 2.50, 0.18]
},
{
steps: 15,
p0: [-0.22, 2.50, 0.18],
p1: [-0.10, 2.60, 0.03],
p2: [0.08, 2.70, -0.15],
p3: [0.25, 2.68, -0.28]
},
{
steps: 13,
p0: [0.25, 2.68, -0.28],
p1: [0.38, 2.67, -0.18],
p2: [0.38, 2.60, 0.05],
p3: [0.24, 2.55, 0.27]
},
{
steps: 18,
p0: [0.24, 2.55, 0.27],
p1: [0.03, 2.38, 0.55],
p2: [-0.32, 2.13, 0.72],
p3: [-0.62, 2.02, 0.73]
},
{
steps: 13,
p0: [-0.62, 2.02, 0.73],
p1: [-0.78, 1.89, 0.80],
p2: [-0.77, 1.72, 0.88],
p3: [-0.62, 1.65, 0.93]
},
{
steps: 18,
p0: [-0.62, 1.65, 0.93],
p1: [-0.34, 1.53, 1.00],
p2: [0.32, 1.52, 1.02],
p3: [0.68, 1.66, 0.89]
},
{
steps: 18,
p0: [0.68, 1.66, 0.89],
p1: [0.90, 1.30, 0.91],
p2: [1.08, 0.23, 1.08],
p3: [1.22, 0.20, 1.12]
}
];
function cubicBezier(section, t) {
const p0 = new THREE.Vector3(...section.p0);
const p1 = new THREE.Vector3(...section.p1);
const p2 = new THREE.Vector3(...section.p2);
const p3 = new THREE.Vector3(...section.p3);
const u = 1 - t;
return new THREE.Vector3()
.addScaledVector(p0, u * u * u)
.addScaledVector(p1, 3 * u * u * t)
.addScaledVector(p2, 3 * u * t * t)
.addScaledVector(p3, t * t * t);
}
const path = [];
for (const section of bezierSections) {
for (let i = 0; i < section.steps; i++) {
path.push(cubicBezier(section, i / section.steps));
}
}
path.push(cubicBezier(bezierSections[bezierSections.length - 1], 1));
// Arc length and parallel-transport frames.
const cumulativeLength = [0];
for (let i = 1; i < path.length; i++) {
cumulativeLength.push(
cumulativeLength[i - 1] + path[i].distanceTo(path[i - 1])
);
}
const tangents = [];
const normals = [];
const sides = [];
for (let i = 0; i < path.length; i++) {
const previous = path[Math.max(0, i - 1)];
const next = path[Math.min(path.length - 1, i + 1)];
const tangent = new THREE.Vector3().subVectors(next, previous).normalize();
tangents.push(tangent);
let normal;
if (i === 0) {
const reference = Math.abs(tangent.z) > 0.9
? new THREE.Vector3(0, 1, 0)
: new THREE.Vector3(0, 0, 1);
normal = reference
.clone()
.addScaledVector(tangent, -reference.dot(tangent))
.normalize();
} else {
const rotation = new THREE.Quaternion().setFromUnitVectors(
tangents[i - 1],
tangent
);
normal = normals[i - 1].clone().applyQuaternion(rotation);
normal.addScaledVector(tangent, -normal.dot(tangent)).normalize();
// A restrained twist keeps the broad facets readable.
const ds = cumulativeLength[i] - cumulativeLength[i - 1];
const twist = 0.22 * Math.cos(cumulativeLength[i] * 0.7) * ds * 0.7;
normal.applyAxisAngle(tangent, twist);
normal.addScaledVector(tangent, -normal.dot(tangent)).normalize();
}
const side = new THREE.Vector3()
.crossVectors(normal, tangent)
.normalize();
if (side.lengthSq() < 0.001) {
side.crossVectors(new THREE.Vector3(0, 1, 0), tangent).normalize();
}
normals.push(normal);
sides.push(side);
}
// ------------------------------------------------------------
// Low-poly ribbon geometry
// ------------------------------------------------------------
const widthOffsets = [-1, -0.52, 0, 0.52, 1];
const ridgeOffsets = [0.008, 0.019, 0.025, 0.019, 0.008];
const halfWidth = 0.17;
const crossSections = path.map((point, i) => {
const section = [];
for (let j = 0; j < widthOffsets.length; j++) {
const p = point.clone()
.addScaledVector(sides[i], widthOffsets[j] * halfWidth)
.addScaledVector(normals[i], ridgeOffsets[j]);
section.push(p);
}
return section;
});
const baseColor = new THREE.Color(0xc9573f);
const creamColor = new THREE.Color(0xf0d5aa);
const darkColor = new THREE.Color(0x8f3e34);
function scarfColor(distance) {
const phase = distance % 1.45;
if (phase < 0.12) return creamColor.clone();
if (phase < 0.19) return darkColor.clone();
return baseColor.clone();
}
const positions = [];
const colors = [];
for (let i = 0; i < crossSections.length - 1; i++) {
const distance = (cumulativeLength[i] + cumulativeLength[i + 1]) * 0.5;
for (let j = 0; j < widthOffsets.length - 1; j++) {
const a = crossSections[i][j];
const b = crossSections[i][j + 1];
const c = crossSections[i + 1][j + 1];
const d = crossSections[i + 1][j];
const triangleColor = scarfColor(distance);
// Contrasting woven border.
if (j === 0 || j === widthOffsets.length - 2) {
triangleColor.lerp(creamColor, 0.24);
}
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
d.x, d.y, d.z,
b.x, b.y, b.z,
c.x, c.y, c.z,
d.x, d.y, d.z
);
for (let k = 0; k < 6; k++) {
colors.push(
triangleColor.r,
triangleColor.g,
triangleColor.b
);
}
}
}
const ribbonGeometry = new THREE.BufferGeometry();
ribbonGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
ribbonGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
ribbonGeometry.computeVertexNormals();
const scarfMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.86,
metalness: 0,
side: THREE.DoubleSide,
flatShading: true
});
const scarf = new THREE.Mesh(ribbonGeometry, scarfMaterial);
scarf.castShadow = true;
scarf.receiveShadow = true;
scene.add(scarf);
// ------------------------------------------------------------
// Fringe at both ends
// ------------------------------------------------------------
function createFringe(endpoint, outward, side) {
const group = new THREE.Group();
for (let i = -3; i <= 3; i++) {
const offset = i * 0.045;
const length = 0.145 + (i % 2 === 0 ? 0.018 : 0);
const start = endpoint.clone()
.addScaledVector(side, offset)
.addScaledVector(outward, 0.015);
const end = start.clone()
.addScaledVector(outward, length)
.add(new THREE.Vector3(0, -0.006, 0));
const direction = end.clone().sub(start);
const geometry = new THREE.CylinderGeometry(
0.006,
0.011,
direction.length(),
4
);
const strand = new THREE.Mesh(geometry, creamMaterial);
strand.position.copy(start).add(end).multiplyScalar(0.5);
strand.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
strand.castShadow = true;
group.add(strand);
}
return group;
}
const startFringe = createFringe(
path[0],
tangents[0].clone().negate(),
sides[0]
);
const endFringe = createFringe(
path[path.length - 1],
tangents[tangents.length - 1].clone(),
sides[sides.length - 1]
);
scene.add(startFringe, endFringe);
// ------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel/pinch to zoom.
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 1.58, 0);
const initialView = {
yaw: 0.62,
pitch: 1.22,
radius: 6.55
};
let yaw = initialView.yaw;
let pitch = initialView.pitch;
let radius = initialView.radius;
let dragging = false;
let previousX = 0;
let previousY = 0;
let lastInteraction = performance.now();
function updateCamera() {
const horizontal = Math.sin(pitch) * radius;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.cos(pitch) * radius,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
lastInteraction = performance.now();
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch - dy * 0.005, 0.58, 1.48);
lastInteraction = performance.now();
});
function endDrag(event) {
dragging = false;
lastInteraction = performance.now();
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius + event.deltaY * 0.0045,
4.3,
9.2
);
lastInteraction = performance.now();
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
yaw = initialView.yaw;
pitch = initialView.pitch;
radius = initialView.radius;
lastInteraction = performance.now();
});
renderer.domElement.addEventListener("dblclick", () => {
yaw = initialView.yaw;
pitch = initialView.pitch;
radius = initialView.radius;
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
if (!dragging && !reducedMotion && now - lastInteraction > 3500) {
yaw += dt * 0.035;
}
updateCamera();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
}
}
updateCamera();
animate();
</script>
</body>
</html>
```