Prompt specification
Build or customize the Three.js 3D scene "Oil and water layered vessel" 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: Oil and water layered vessel
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/oil-and-water-layered-vessel-x0109
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts separate oil and water layers. Model a clear small vessel with two distinct liquid layers and a nearby spoon; a side cutaway reveals the interface without making the layers transparent enough to disappear. Stylized solid forms.
Working Three.js Starter (oil-and-water-layered-vessel-x0109):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Oil & Water — Cutaway Vessel</title>
<style>
:root {
--ink: #283438;
--muted: #69777a;
--paper: rgba(250, 247, 240, 0.88);
--line: rgba(40, 52, 56, 0.13);
--water: #24b7ca;
--oil: #f0a129;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee8dd;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: clamp(20px, 4vw, 46px);
left: clamp(20px, 4vw, 54px);
max-width: 390px;
}
.eyebrow {
margin: 0 0 9px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(34px, 5vw, 66px);
font-weight: 560;
letter-spacing: -0.055em;
line-height: 0.96;
}
.subtitle {
max-width: 330px;
margin: 17px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.legend {
position: absolute;
top: clamp(20px, 4vw, 42px);
right: clamp(20px, 4vw, 44px);
width: 174px;
padding: 17px 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(63, 51, 39, 0.08);
backdrop-filter: blur(12px);
}
.legend-title {
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 9px;
font-size: 13px;
font-weight: 650;
}
.swatch {
width: 15px;
height: 15px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.water {
background: var(--water);
}
.swatch.oil {
background: var(--oil);
}
.legend-note {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.controls {
position: absolute;
left: clamp(20px, 4vw, 54px);
bottom: clamp(20px, 4vw, 40px);
display: flex;
align-items: center;
gap: 12px;
color: var(--muted);
font-size: 12px;
}
.controls::before {
content: "";
width: 26px;
height: 1px;
background: var(--muted);
opacity: 0.55;
}
button {
pointer-events: auto;
margin-left: 4px;
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.96);
}
button:focus-visible {
outline: 2px solid rgba(36, 183, 202, 0.65);
outline-offset: 3px;
}
@media (max-width: 650px) {
.title-card {
max-width: 250px;
}
.subtitle {
display: none;
}
.legend {
top: auto;
right: 16px;
bottom: 18px;
width: 154px;
}
.controls {
left: 18px;
bottom: 22px;
max-width: 150px;
line-height: 1.4;
}
.controls::before {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive 3D cutaway vessel containing oil and water"></main>
<div class="hud">
<header class="title-card">
<p class="eyebrow">Two-liquid study</p>
<h1>Oil &<br />Water</h1>
<p class="subtitle">
A stylized cutaway vessel showing two distinct, immiscible layers
with a nearby solid-form spoon.
</p>
</header>
<aside class="legend" aria-label="Liquid color legend">
<div class="legend-title">Liquid layers</div>
<div class="legend-row">
<span class="swatch water"></span>
<span>Water</span>
</div>
<div class="legend-row">
<span class="swatch oil"></span>
<span>Oil</span>
</div>
<div class="legend-note">
Opaque bodies preserve the interface and readable cut faces.
</div>
</aside>
<div class="controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
</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 container = document.querySelector("#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;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee8dd);
scene.fog = new THREE.Fog(0xeee8dd, 9, 17);
const camera = new THREE.PerspectiveCamera(
37,
window.innerWidth / window.innerHeight,
0.1,
100
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xffffff, 0xb9aa91, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.3);
keyLight.position.set(-3.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 16;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9ecff, 1.45);
fillLight.position.set(5, 3.5, -4);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffd99d, 1.0);
rimLight.position.set(-4, 3, -3);
scene.add(rimLight);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xeee8dd,
roughness: 0.94,
metalness: 0
});
const coasterMaterial = new THREE.MeshStandardMaterial({
color: 0xd8cdbb,
roughness: 0.82,
metalness: 0
});
const coasterRingMaterial = new THREE.MeshStandardMaterial({
color: 0xb7aa95,
roughness: 0.75,
metalness: 0
});
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xdffbff,
roughness: 0.08,
metalness: 0,
transparent: true,
opacity: 0.23,
clearcoat: 1,
clearcoatRoughness: 0.06,
side: THREE.DoubleSide,
depthWrite: false
});
const glassEdgeMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.68,
depthWrite: false
});
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x24b7ca,
roughness: 0.24,
metalness: 0,
clearcoat: 0.65,
clearcoatRoughness: 0.18
});
const oilMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf0a129,
roughness: 0.29,
metalness: 0,
clearcoat: 0.72,
clearcoatRoughness: 0.2
});
const oilTopMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf7b542,
roughness: 0.22,
metalness: 0,
clearcoat: 0.8,
clearcoatRoughness: 0.14
});
const interfaceMaterial = new THREE.MeshStandardMaterial({
color: 0xbf7419,
roughness: 0.5,
metalness: 0
});
const spoonMaterial = new THREE.MeshStandardMaterial({
color: 0xb9c6c9,
roughness: 0.27,
metalness: 0.68
});
// ------------------------------------------------------------
// Geometry helpers
//
// The cutaway is a wedge removed from the front of the vessel.
// Both the glass and the liquid volumes use the same wedge, so
// their vertical radial faces are exposed as solid sections.
// ------------------------------------------------------------
const cutCenter = 0.45;
const cutHalfWidth = 0.68;
const sectorStart = cutCenter + cutHalfWidth;
const sectorEnd = sectorStart + (Math.PI * 2 - cutHalfWidth * 2);
function topDownPoint(theta, radius) {
// This mapping becomes world X/Z after rotateX(-PI / 2).
return new THREE.Vector2(
Math.sin(theta) * radius,
-Math.cos(theta) * radius
);
}
function makeSolidSectorShape(radius, start, end, steps = 150) {
const shape = new THREE.Shape();
shape.moveTo(0, 0);
for (let i = 0; i <= steps; i++) {
const theta = THREE.MathUtils.lerp(start, end, i / steps);
const point = topDownPoint(theta, radius);
shape.lineTo(point.x, point.y);
}
shape.closePath();
return shape;
}
function makeAnnularSectorShape(
outerRadius,
innerRadius,
start,
end,
steps = 150
) {
const shape = new THREE.Shape();
for (let i = 0; i <= steps; i++) {
const theta = THREE.MathUtils.lerp(start, end, i / steps);
const point = topDownPoint(theta, outerRadius);
if (i === 0) shape.moveTo(point.x, point.y);
else shape.lineTo(point.x, point.y);
}
for (let i = steps; i >= 0; i--) {
const theta = THREE.MathUtils.lerp(start, end, i / steps);
const point = topDownPoint(theta, innerRadius);
shape.lineTo(point.x, point.y);
}
shape.closePath();
return shape;
}
function createExtrudedMesh(shape, height, bottomY, material) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: height,
steps: 1,
bevelEnabled: false
});
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = bottomY;
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
class HorizontalArcCurve extends THREE.Curve {
constructor(radius, y, start, end) {
super();
this.radius = radius;
this.y = y;
this.start = start;
this.end = end;
}
getPoint(t, target = new THREE.Vector3()) {
const theta = THREE.MathUtils.lerp(this.start, this.end, t);
return target.set(
Math.sin(theta) * this.radius,
this.y,
Math.cos(theta) * this.radius
);
}
}
function createArcTube(radius, y, start, end, tubeRadius, material) {
const curve = new HorizontalArcCurve(radius, y, start, end);
const geometry = new THREE.TubeGeometry(
curve,
160,
tubeRadius,
7,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
return mesh;
}
// ------------------------------------------------------------
// Ground and coaster
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.012;
ground.receiveShadow = true;
scene.add(ground);
const coaster = new THREE.Mesh(
new THREE.CylinderGeometry(1.47, 1.5, 0.1, 96),
coasterMaterial
);
coaster.position.set(-0.52, 0.05, 0);
coaster.castShadow = true;
coaster.receiveShadow = true;
scene.add(coaster);
const coasterRing = new THREE.Mesh(
new THREE.TorusGeometry(1.28, 0.009, 8, 96),
coasterRingMaterial
);
coasterRing.rotation.x = Math.PI / 2;
coasterRing.position.set(-0.52, 0.103, 0);
scene.add(coasterRing);
// ------------------------------------------------------------
// Cutaway vessel
// ------------------------------------------------------------
const vessel = new THREE.Group();
vessel.position.x = -0.52;
scene.add(vessel);
const glassBottom = new THREE.Mesh(
new THREE.CylinderGeometry(1.19, 1.19, 0.08, 96),
glassMaterial
);
glassBottom.position.y = 0.15;
glassBottom.renderOrder = 4;
vessel.add(glassBottom);
const shellBottom = 0.19;
const shellHeight = 1.72;
const shellTop = shellBottom + shellHeight;
const shellShape = makeAnnularSectorShape(
1.19,
1.12,
sectorStart,
sectorEnd
);
const glassShell = createExtrudedMesh(
shellShape,
shellHeight,
shellBottom,
glassMaterial
);
glassShell.renderOrder = 4;
vessel.add(glassShell);
// Rounded upper lips on the inner and outer glass edges.
vessel.add(
createArcTube(
1.19,
shellTop,
sectorStart,
sectorEnd,
0.018,
glassEdgeMaterial
)
);
vessel.add(
createArcTube(
1.12,
shellTop,
sectorStart,
sectorEnd,
0.014,
glassEdgeMaterial
)
);
// Bright vertical edges define the cutaway opening.
for (const theta of [sectorStart, sectorEnd]) {
const edge = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.012, shellHeight, 8),
glassEdgeMaterial
);
edge.position.set(
Math.sin(theta) * 1.155,
shellBottom + shellHeight / 2,
Math.cos(theta) * 1.155
);
edge.renderOrder = 5;
vessel.add(edge);
}
// ------------------------------------------------------------
// Two solid liquid volumes
// ------------------------------------------------------------
const liquidRadius = 1.105;
const waterBottom = 0.20;
const waterTop = 0.92;
const interfaceTop = 0.945;
const oilTop = 1.69;
const waterShape = makeSolidSectorShape(
liquidRadius,
sectorStart,
sectorEnd
);
const water = createExtrudedMesh(
waterShape,
waterTop - waterBottom,
waterBottom,
waterMaterial
);
vessel.add(water);
// A narrow amber band makes the interface legible in the cut face.
const interfaceBand = createExtrudedMesh(
waterShape,
interfaceTop - waterTop,
waterTop,
interfaceMaterial
);
vessel.add(interfaceBand);
const oil = createExtrudedMesh(
waterShape,
oilTop - interfaceTop,
interfaceTop,
oilMaterial
);
vessel.add(oil);
// Slightly brighter top layer and meniscus highlight.
const oilSurface = createExtrudedMesh(
waterShape,
0.016,
oilTop,
oilTopMaterial
);
vessel.add(oilSurface);
vessel.add(
createArcTube(
liquidRadius,
oilTop + 0.017,
sectorStart,
sectorEnd,
0.012,
oilTopMaterial
)
);
// ------------------------------------------------------------
// Nearby spoon
// ------------------------------------------------------------
const spoon = new THREE.Group();
spoon.position.set(1.65, -0.035, 0.62);
spoon.rotation.set(0, -0.52, -0.025);
scene.add(spoon);
// Concave, solid-looking bowl made from a closed lathe profile.
const bowlProfile = [
new THREE.Vector2(0.018, -0.035),
new THREE.Vector2(0.24, -0.035),
new THREE.Vector2(0.38, -0.018),
new THREE.Vector2(0.46, 0.025),
new THREE.Vector2(0.47, 0.075),
new THREE.Vector2(0.43, 0.09),
new THREE.Vector2(0.39, 0.045),
new THREE.Vector2(0.25, 0.012),
new THREE.Vector2(0.018, 0.005)
];
const bowl = new THREE.Mesh(
new THREE.LatheGeometry(bowlProfile, 64),
spoonMaterial
);
bowl.position.y = 0.1;
bowl.castShadow = true;
bowl.receiveShadow = true;
spoon.add(bowl);
const bowlCenterCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.055, 16),
spoonMaterial
);
bowlCenterCap.position.y = 0.087;
bowlCenterCap.castShadow = true;
spoon.add(bowlCenterCap);
const handleShape = new THREE.Shape();
handleShape.moveTo(0.35, -0.105);
handleShape.lineTo(1.23, -0.076);
handleShape.quadraticCurveTo(1.47, -0.072, 1.53, 0);
handleShape.quadraticCurveTo(1.47, 0.072, 1.23, 0.076);
handleShape.lineTo(0.35, 0.105);
handleShape.closePath();
const handleGeometry = new THREE.ExtrudeGeometry(handleShape, {
depth: 0.06,
bevelEnabled: true,
bevelThickness: 0.014,
bevelSize: 0.016,
bevelSegments: 3,
curveSegments: 28
});
handleGeometry.rotateX(-Math.PI / 2);
const handle = new THREE.Mesh(handleGeometry, spoonMaterial);
handle.position.y = 0.073;
handle.castShadow = true;
handle.receiveShadow = true;
spoon.add(handle);
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom and reset
// ------------------------------------------------------------
class CameraRig {
constructor(cameraObject, domElement, target) {
this.camera = cameraObject;
this.dom = domElement;
this.target = target.clone();
this.initialTheta = 0.52;
this.initialPhi = 1.12;
this.initialRadius = 6.7;
this.theta = this.initialTheta;
this.phi = this.initialPhi;
this.radius = this.initialRadius;
this.desiredTheta = this.theta;
this.desiredPhi = this.phi;
this.desiredRadius = this.radius;
this.dragging = false;
this.pointerX = 0;
this.pointerY = 0;
this.bindEvents();
this.update(1);
}
bindEvents() {
this.dom.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
this.dragging = true;
this.pointerX = event.clientX;
this.pointerY = event.clientY;
this.dom.setPointerCapture(event.pointerId);
this.dom.classList.add("dragging");
});
this.dom.addEventListener("pointermove", (event) => {
if (!this.dragging) return;
const dx = event.clientX - this.pointerX;
const dy = event.clientY - this.pointerY;
this.pointerX = event.clientX;
this.pointerY = event.clientY;
this.desiredTheta -= dx * 0.006;
this.desiredPhi = THREE.MathUtils.clamp(
this.desiredPhi - dy * 0.005,
0.43,
1.46
);
});
const endDrag = (event) => {
this.dragging = false;
this.dom.classList.remove("dragging");
if (this.dom.hasPointerCapture(event.pointerId)) {
this.dom.releasePointerCapture(event.pointerId);
}
};
this.dom.addEventListener("pointerup", endDrag);
this.dom.addEventListener("pointercancel", endDrag);
this.dom.addEventListener(
"wheel",
(event) => {
event.preventDefault();
this.desiredRadius = THREE.MathUtils.clamp(
this.desiredRadius * Math.exp(event.deltaY * 0.001),
4.8,
10
);
},
{ passive: false }
);
this.dom.addEventListener("dblclick", () => this.reset());
}
reset() {
this.desiredTheta = this.initialTheta;
this.desiredPhi = this.initialPhi;
this.desiredRadius = this.initialRadius;
}
update(deltaTime) {
const smoothing = 1 - Math.exp(-12 * deltaTime);
this.theta = THREE.MathUtils.lerp(
this.theta,
this.desiredTheta,
smoothing
);
this.phi = THREE.MathUtils.lerp(
this.phi,
this.desiredPhi,
smoothing
);
this.radius = THREE.MathUtils.lerp(
this.radius,
this.desiredRadius,
smoothing
);
const horizontal = this.radius * Math.sin(this.phi);
this.camera.position.set(
this.target.x + horizontal * Math.sin(this.theta),
this.target.y + this.radius * Math.cos(this.phi),
this.target.z + horizontal * Math.cos(this.theta)
);
this.camera.lookAt(this.target);
}
}
const rig = new CameraRig(
camera,
renderer.domElement,
new THREE.Vector3(0.2, 0.82, 0.05)
);
document.querySelector("#reset").addEventListener("click", () => {
rig.reset();
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const deltaTime = Math.min(clock.getDelta(), 0.05);
rig.update(deltaTime);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```