Prompt specification
Build or customize the Three.js 3D scene "One Swatch Between Two Surrounds" 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: One Swatch Between Two Surrounds
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/one-swatch-between-two-surrounds-x3285
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing color appearance under different surrounds. Place identical central swatches inside two differently colored frames under matched lighting. State that material values are identical and keep geometry and exposure controlled. Stylized solid forms.
Working Three.js Starter (one-swatch-between-two-surrounds-x3285):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Same Swatch — Different Surround</title>
<style>
:root {
color-scheme: light;
--ink: #292a28;
--muted: #666862;
--paper: rgba(250, 249, 245, 0.88);
--line: rgba(41, 42, 40, 0.14);
--warm: #b86e58;
--cool: #4f7f9f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7e6e1;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.intro {
position: fixed;
z-index: 3;
top: 28px;
left: 30px;
width: min(540px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
margin: 0 0 10px;
color: #696b65;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 48px);
font-weight: 680;
letter-spacing: -0.045em;
line-height: 0.98;
}
h1 span {
color: #777a72;
font-weight: 470;
}
.intro p {
max-width: 510px;
margin: 14px 0 0;
color: #5e615a;
font-size: 14px;
line-height: 1.5;
}
.identity {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 15px;
padding: 8px 11px;
border: 1px solid rgba(41, 42, 40, 0.12);
border-radius: 999px;
background: rgba(250, 249, 245, 0.68);
color: #454842;
font-size: 11px;
font-weight: 720;
letter-spacing: 0.07em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.identity::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #738b68;
box-shadow: 0 0 0 3px rgba(115, 139, 104, 0.14);
content: "";
}
.scene-label {
position: fixed;
z-index: 2;
display: flex;
align-items: center;
gap: 9px;
min-width: 152px;
padding: 8px 11px;
border: 1px solid rgba(41, 42, 40, 0.12);
border-radius: 12px;
background: rgba(250, 249, 245, 0.84);
box-shadow: 0 8px 26px rgba(52, 50, 44, 0.08);
pointer-events: none;
transform: translate(-50%, -50%);
backdrop-filter: blur(10px);
}
.scene-label .dot {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow:
inset 0 0 0 1px rgba(0, 0, 0, 0.09),
0 0 0 3px rgba(255, 255, 255, 0.6);
}
.scene-label.warm .dot {
background: var(--warm);
}
.scene-label.cool .dot {
background: var(--cool);
}
.scene-label strong {
display: block;
font-size: 11px;
font-weight: 760;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.scene-label code {
display: block;
margin-top: 2px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
}
.audit {
position: fixed;
z-index: 3;
right: 24px;
bottom: 24px;
width: 322px;
padding: 16px 17px 14px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 16px 50px rgba(50, 48, 42, 0.12);
backdrop-filter: blur(18px);
}
.audit-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.audit-heading h2 {
margin: 0;
font-size: 12px;
font-weight: 780;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.audit-heading span {
padding: 4px 7px;
border-radius: 999px;
background: rgba(115, 139, 104, 0.13);
color: #52674a;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.audit-grid {
display: grid;
grid-template-columns: 1fr auto;
gap: 7px 14px;
margin: 0;
font-size: 11px;
}
.audit-grid dt {
color: var(--muted);
}
.audit-grid dd {
margin: 0;
color: #343632;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-align: right;
}
.audit-note {
margin: 12px 0 0;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #62655e;
font-size: 10px;
line-height: 1.45;
}
.controls {
position: fixed;
z-index: 4;
bottom: 24px;
left: 30px;
display: flex;
align-items: center;
gap: 12px;
}
.hint {
color: #666961;
font-size: 11px;
}
#reset-view {
padding: 9px 12px;
border: 1px solid rgba(41, 42, 40, 0.14);
border-radius: 10px;
background: rgba(250, 249, 245, 0.82);
color: #41443e;
font-size: 11px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 6px 20px rgba(50, 48, 42, 0.07);
backdrop-filter: blur(10px);
}
#reset-view:hover {
background: #fbfaf6;
}
#reset-view:active {
transform: translateY(1px);
}
#reset-view:focus-visible {
outline: 2px solid #71866a;
outline-offset: 3px;
}
@media (max-width: 760px) {
.intro {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
.eyebrow {
margin-bottom: 7px;
font-size: 9px;
}
h1 {
font-size: 31px;
}
.intro p {
max-width: 360px;
margin-top: 9px;
font-size: 12px;
}
.identity {
margin-top: 10px;
padding: 6px 9px;
font-size: 9px;
}
.scene-label {
min-width: 132px;
padding: 6px 8px;
}
.scene-label strong {
font-size: 9px;
}
.audit {
right: 14px;
bottom: 62px;
width: min(310px, calc(100vw - 28px));
padding: 12px 13px;
}
.audit-note {
display: none;
}
.controls {
bottom: 16px;
left: 18px;
}
.hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<main id="app">
<div
id="stage"
role="img"
aria-label="Two identical gray-beige swatches, one inside a warm coral frame and one inside a cool blue frame, under matched neutral lighting."
></div>
<header class="intro">
<p class="eyebrow">Perceptual color / controlled comparison</p>
<h1>Same swatch.<br><span>Different surround.</span></h1>
<p>
The two center tiles share one material instance. Neutral lighting and
fixed exposure are matched; only the surrounding color changes.
</p>
<div class="identity">Material values are identical</div>
</header>
<div id="warm-label" class="scene-label warm" aria-hidden="true">
<span class="dot"></span>
<span>
<strong>Warm surround</strong>
<code>#B86E58</code>
</span>
</div>
<div id="cool-label" class="scene-label cool" aria-hidden="true">
<span class="dot"></span>
<span>
<strong>Cool surround</strong>
<code>#4F7F9F</code>
</span>
</div>
<section class="audit" aria-label="Material and rendering controls">
<div class="audit-heading">
<h2>Shared swatch material</h2>
<span>Identical</span>
</div>
<dl class="audit-grid">
<dt>Type</dt>
<dd>MeshStandardMaterial</dd>
<dt>Color / sRGB</dt>
<dd>#A8A18D</dd>
<dt>Roughness</dt>
<dd>0.58</dd>
<dt>Metalness</dt>
<dd>0.00</dd>
<dt>Geometry</dt>
<dd>Shared instance</dd>
<dt>Scale</dt>
<dd>1.00 / 1.00</dd>
<dt>Light color</dt>
<dd>#FFFFFF</dd>
<dt>Local lights</dt>
<dd>Matched pair</dd>
<dt>Exposure</dt>
<dd>ACES / 1.00</dd>
</dl>
<p class="audit-note">
The apparent shift is a contextual color effect, not a change in the
swatch’s material values. Geometry, lighting, camera scale, and
exposure remain controlled.
</p>
</section>
<div class="controls">
<span class="hint">Drag to orbit · wheel to zoom · double-click to reset</span>
<button id="reset-view" type="button">Reset view</button>
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const warmLabel = document.querySelector("#warm-label");
const coolLabel = document.querySelector("#cool-label");
const resetButton = document.querySelector("#reset-view");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.0;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D color comparison. Drag to orbit, use the wheel to zoom, or press the reset button."
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#E7E6E1");
// Orthographic projection keeps both swatches at exactly the same scale.
const camera = new THREE.OrthographicCamera(-4, 4, 2.3, -2.3, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.48, 0);
const defaultView = {
yaw: 0,
pitch: 0.025,
zoom: 1
};
const currentView = { ...defaultView };
const desiredView = { ...defaultView };
function roundedRectShape(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;
}
function roundedRectHole(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const path = new THREE.Path();
// Clockwise winding makes this a valid hole in the outer shape.
path.moveTo(x + radius, y);
path.quadraticCurveTo(x, y, x, y + radius);
path.lineTo(x, y + height - radius);
path.quadraticCurveTo(x, y + height, x + radius, y + height);
path.lineTo(x + width - radius, y + height);
path.quadraticCurveTo(
x + width,
y + height,
x + width,
y + height - radius
);
path.lineTo(x + width, y + radius);
path.quadraticCurveTo(x + width, y, x + width - radius, y);
path.lineTo(x + radius, y);
return path;
}
function roundedPrism(width, height, radius, depth, bevel = 0.025) {
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, height, radius),
{
depth,
steps: 1,
curveSegments: 18,
bevelEnabled: true,
bevelSegments: 4,
bevelSize: bevel,
bevelThickness: bevel
}
);
geometry.center();
geometry.computeVertexNormals();
return geometry;
}
// Identical frame geometry is shared by both surrounds.
const frameShape = roundedRectShape(2.38, 2.64, 0.22);
frameShape.holes.push(roundedRectHole(1.62, 1.86, 0.14));
const frameGeometry = new THREE.ExtrudeGeometry(frameShape, {
depth: 0.34,
steps: 1,
curveSegments: 24,
bevelEnabled: true,
bevelSegments: 5,
bevelSize: 0.045,
bevelThickness: 0.045
});
frameGeometry.center();
frameGeometry.computeVertexNormals();
const fieldGeometry = roundedPrism(1.60, 1.84, 0.13, 0.18, 0.025);
const swatchGeometry = roundedPrism(0.88, 0.88, 0.12, 0.18, 0.035);
const baseGeometry = roundedPrism(2.62, 0.62, 0.16, 0.16, 0.025);
baseGeometry.rotateX(-Math.PI / 2);
baseGeometry.computeVertexNormals();
// The same material object is assigned to both center swatches.
const swatchMaterial = new THREE.MeshStandardMaterial({
color: "#A8A18D",
roughness: 0.58,
metalness: 0.0
});
swatchMaterial.name = "SharedSwatchMaterial";
const warmMaterial = new THREE.MeshStandardMaterial({
color: "#B86E58",
roughness: 0.58,
metalness: 0.0
});
const coolMaterial = new THREE.MeshStandardMaterial({
color: "#4F7F9F",
roughness: 0.58,
metalness: 0.0
});
const baseMaterial = new THREE.MeshStandardMaterial({
color: "#BDBBB3",
roughness: 0.78,
metalness: 0.0
});
const floorMaterial = new THREE.MeshStandardMaterial({
color: "#D6D5CF",
roughness: 0.92,
metalness: 0.0
});
const floor = new THREE.Mesh(new THREE.PlaneGeometry(30, 30), floorMaterial);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
function addEnclosure(x, surroundMaterial, name) {
const group = new THREE.Group();
group.name = name;
group.position.x = x;
const base = new THREE.Mesh(baseGeometry, baseMaterial);
base.position.set(0, 0.08, -0.03);
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const field = new THREE.Mesh(fieldGeometry, surroundMaterial);
field.position.set(0, 1.5, -0.065);
field.castShadow = true;
field.receiveShadow = true;
group.add(field);
const frame = new THREE.Mesh(frameGeometry, surroundMaterial);
frame.position.set(0, 1.5, 0);
frame.castShadow = true;
frame.receiveShadow = true;
group.add(frame);
const swatch = new THREE.Mesh(swatchGeometry, swatchMaterial);
swatch.position.set(0, 1.5, 0.33);
swatch.castShadow = true;
swatch.receiveShadow = true;
group.add(swatch);
// Each enclosure receives an identical neutral-white local light.
const localLight = new THREE.PointLight(
0xffffff,
7.0,
4.5,
2.0
);
localLight.position.set(0, 2.78, 2.15);
group.add(localLight);
scene.add(group);
return { group, swatch };
}
const warm = addEnclosure(-1.45, warmMaterial, "WarmSurround");
const cool = addEnclosure(1.45, coolMaterial, "CoolSurround");
console.assert(
warm.swatch.material === cool.swatch.material,
"Both swatches must use the identical material instance."
);
console.assert(
warm.swatch.geometry === cool.swatch.geometry,
"Both swatches must use the identical geometry instance."
);
// Neutral, matched scene lighting.
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x707070, 1.15);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xffffff, 2.2);
key.position.set(0, 5.5, 6);
key.target.position.set(0, 1.2, 0);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -5;
key.shadow.camera.right = 5;
key.shadow.camera.top = 5;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 15;
key.shadow.bias = -0.00035;
key.shadow.normalBias = 0.025;
scene.add(key, key.target);
const fill = new THREE.DirectionalLight(0xffffff, 0.65);
fill.position.set(0, 2.5, -4);
fill.target.position.set(0, 1.4, 0);
scene.add(fill, fill.target);
const labelAnchors = {
warm: new THREE.Vector3(-1.45, 3.03, 0.1),
cool: new THREE.Vector3(1.45, 3.03, 0.1)
};
function updateProjection() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve a minimum horizontal field so both comparisons remain visible.
const minimumWorldWidth = 6.7;
const viewHeight = Math.max(4.55, minimumWorldWidth / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
function updateCamera() {
const radius = 10;
const cosPitch = Math.cos(currentView.pitch);
camera.position.set(
cameraTarget.x + radius * Math.sin(currentView.yaw) * cosPitch,
cameraTarget.y + radius * Math.sin(currentView.pitch),
cameraTarget.z + radius * Math.cos(currentView.yaw) * cosPitch
);
camera.lookAt(cameraTarget);
camera.zoom = currentView.zoom;
camera.updateProjectionMatrix();
}
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function resetView() {
desiredView.yaw = defaultView.yaw;
desiredView.pitch = defaultView.pitch;
desiredView.zoom = defaultView.zoom;
}
// Custom pointer controls: limited orbit and zoom, with no external addon.
let dragging = false;
let pointerId = null;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(pointerId);
renderer.domElement.focus({ preventScroll: true });
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredView.yaw = THREE.MathUtils.clamp(
desiredView.yaw - dx * 0.004,
-0.28,
0.28
);
desiredView.pitch = THREE.MathUtils.clamp(
desiredView.pitch + dy * 0.0025,
-0.12,
0.18
);
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
if (renderer.domElement.hasPointerCapture(pointerId)) {
renderer.domElement.releasePointerCapture(pointerId);
}
pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredView.zoom = THREE.MathUtils.clamp(
desiredView.zoom * Math.exp(-event.deltaY * 0.001),
0.82,
1.35
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
resetButton.addEventListener("click", resetView);
renderer.domElement.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
desiredView.yaw = THREE.MathUtils.clamp(
desiredView.yaw + 0.025,
-0.28,
0.28
);
} else if (event.key === "ArrowRight") {
desiredView.yaw = THREE.MathUtils.clamp(
desiredView.yaw - 0.025,
-0.28,
0.28
);
} else if (event.key === "+" || event.key === "=") {
desiredView.zoom = Math.min(1.35, desiredView.zoom + 0.05);
} else if (event.key === "-") {
desiredView.zoom = Math.max(0.82, desiredView.zoom - 0.05);
} else if (event.key === "Home") {
resetView();
}
});
window.addEventListener("resize", updateProjection);
updateProjection();
renderer.setAnimationLoop(() => {
const damping = 0.14;
currentView.yaw +=
(desiredView.yaw - currentView.yaw) * damping;
currentView.pitch +=
(desiredView.pitch - currentView.pitch) * damping;
currentView.zoom +=
(desiredView.zoom - currentView.zoom) * damping;
updateCamera();
renderer.render(scene, camera);
positionLabel(warmLabel, labelAnchors.warm);
positionLabel(coolLabel, labelAnchors.cool);
});
</script>
</body>
</html>
```