Prompt specification
Build or customize the Three.js 3D scene "Grain pile and angle marker" 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: Grain pile and angle marker
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/grain-pile-and-angle-marker-x1389
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a static granular pile and its slope. Build a small pile of distinct rounded particles on a tray with an illustrated slope angle; label the static arrangement a geometric model rather than measured material behavior. Low-poly.
Working Three.js Starter (grain-pile-and-angle-marker-x1389):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Static Granular Pile — Geometric Model</title>
<style>
:root {
--ink: #20373b;
--muted: #657679;
--accent: #cf714a;
--paper: rgba(249, 247, 241, 0.88);
--line: rgba(32, 55, 59, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eae7df;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
top: 28px;
left: 28px;
width: min(350px, calc(100vw - 56px));
padding: 20px 22px 19px;
pointer-events: none;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 4px;
box-shadow: 0 12px 40px rgba(42, 58, 56, 0.09);
backdrop-filter: blur(12px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
content: "";
box-shadow: 0 0 0 4px rgba(207, 113, 74, 0.13);
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 37px);
font-weight: 760;
line-height: 0.98;
letter-spacing: -0.045em;
}
h1 span {
color: var(--accent);
font-weight: 620;
}
.description {
margin: 15px 0 0;
color: var(--muted);
font-size: 12.5px;
line-height: 1.55;
}
.notice {
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
line-height: 1.48;
}
.notice strong {
color: var(--ink);
font-weight: 760;
}
.legend {
position: fixed;
top: 30px;
right: 30px;
display: grid;
gap: 10px;
padding: 13px 15px;
pointer-events: none;
background: rgba(249, 247, 241, 0.74);
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
}
.legend-line {
width: 24px;
height: 2px;
background: var(--accent);
}
.legend-box {
width: 17px;
height: 12px;
border: 1px solid rgba(32, 55, 59, 0.42);
background:
linear-gradient(135deg, transparent 46%, rgba(32, 55, 59, 0.42) 47% 53%, transparent 54%);
}
.controls {
position: fixed;
right: 30px;
bottom: 24px;
pointer-events: none;
color: rgba(32, 55, 59, 0.62);
font-size: 10px;
font-weight: 720;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.hud {
top: 14px;
left: 14px;
width: min(320px, calc(100vw - 28px));
padding: 16px 17px;
}
.description {
display: none;
}
.notice {
margin-top: 11px;
}
.legend {
display: none;
}
.controls {
right: 15px;
bottom: 15px;
}
}
</style>
</head>
<body>
<main
id="scene"
role="img"
aria-label="A low-poly static granular pile arranged on a tray, with an illustrative 34 degree surface angle annotation."
></main>
<section class="hud" aria-label="Scene information">
<div class="eyebrow">Granular arrangement / 01</div>
<h1>
Static pile<br />
<span>geometric model</span>
</h1>
<p class="description">
A fixed arrangement of individually colored, faceted particles on a
shallow tray. No dynamics, settling, or material calibration are implied.
</p>
<div class="notice">
<strong>Illustrative only.</strong>
The marked angle is a diagrammatic surface guide—not measured material
behavior.
</div>
</section>
<aside class="legend" aria-hidden="true">
<div class="legend-item">
<span class="legend-line"></span>
Illustrated surface guide
</div>
<div class="legend-item">
<span class="legend-box"></span>
Fixed low-poly particles
</div>
</aside>
<div class="controls">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";
const sceneRoot = document.getElementById("scene");
// ------------------------------------------------------------
// Renderer and camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional geometric model of a static granular pile."
);
renderer.domElement.tabIndex = 0;
sceneRoot.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeae7df);
scene.fog = new THREE.Fog(0xeae7df, 17, 34);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.15, 0);
let desiredAzimuth = 0.64;
let desiredPolar = 1.02;
let currentAzimuth = desiredAzimuth;
let currentPolar = desiredPolar;
function fittedDistance() {
const verticalHalfAngle = THREE.MathUtils.degToRad(camera.fov * 0.5);
const aspect = window.innerWidth / window.innerHeight;
return Math.max(13.5, 11.4 / (2 * verticalHalfAngle * aspect));
}
let desiredRadius = fittedDistance();
let currentRadius = desiredRadius;
function updateCamera() {
const horizontalRadius =
currentRadius * Math.sin(currentPolar);
camera.position.set(
cameraTarget.x +
horizontalRadius * Math.sin(currentAzimuth),
cameraTarget.y +
currentRadius * Math.cos(currentPolar),
cameraTarget.z +
horizontalRadius * Math.cos(currentAzimuth)
);
camera.lookAt(cameraTarget);
}
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff8e8,
0x667b7b,
2.1
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d2, 3.25);
keyLight.position.set(-5.5, 10.5, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.0003;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9e3e6, 1.15);
fillLight.position.set(7, 5, -7);
scene.add(fillLight);
// ------------------------------------------------------------
// Ground, tray, feet, and corner details
// ------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xdedbd2,
roughness: 1,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI * 0.5;
ground.position.y = -0.17;
ground.receiveShadow = true;
scene.add(ground);
const trayBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x315c63,
roughness: 0.72,
metalness: 0.06
});
const trayInsetMaterial = new THREE.MeshStandardMaterial({
color: 0xb8a27b,
roughness: 0.9,
metalness: 0
});
const trayEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x254a50,
roughness: 0.67,
metalness: 0.08
});
const footMaterial = new THREE.MeshStandardMaterial({
color: 0x203a3f,
roughness: 0.8,
metalness: 0.05
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xc99a52,
roughness: 0.62,
metalness: 0.16
});
function addBox(width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
addBox(10.4, 0.32, 5.8, trayBaseMaterial, 0, 0.12, 0);
addBox(9.98, 0.09, 5.22, trayInsetMaterial, 0, 0.315, 0);
addBox(0.22, 0.38, 5.8, trayEdgeMaterial, -5.09, 0.4, 0);
addBox(0.22, 0.38, 5.8, trayEdgeMaterial, 5.09, 0.4, 0);
addBox(10.4, 0.38, 0.22, trayEdgeMaterial, 0, 0.4, -2.79);
addBox(10.4, 0.38, 0.22, trayEdgeMaterial, 0, 0.4, 2.79);
const footPositions = [
[-4.3, -2.15],
[4.3, -2.15],
[-4.3, 2.15],
[4.3, 2.15]
];
for (const [x, z] of footPositions) {
addBox(0.76, 0.18, 0.76, footMaterial, x, -0.075, z);
}
const cornerPositions = [
[-4.98, -2.69],
[4.98, -2.69],
[-4.98, 2.69],
[4.98, 2.69]
];
for (const [x, z] of cornerPositions) {
addBox(0.34, 0.13, 0.34, brassMaterial, x, 0.625, z);
}
// ------------------------------------------------------------
// Deterministic particle arrangement
// ------------------------------------------------------------
function mulberry32(seed) {
return function random() {
let value = seed += 0x6D2B79F5;
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(82417);
const palette = [
0xd56d55,
0xdda04b,
0xe3c46b,
0x69958f,
0x7a72a4,
0xc58a68,
0xb95154,
0xa5b09a,
0xd79872,
0x4f7d86
];
const pileCenterX = -0.85;
const particleFloor = 0.36;
const layerDefinitions = [
[12, 5],
[11, 5],
[10, 4],
[9, 4],
[8, 4],
[7, 3],
[6, 3],
[5, 3],
[4, 2],
[3, 2],
[2, 2],
[1, 1]
];
const particleTransforms = [];
const particleColors = [];
for (let layer = 0; layer < layerDefinitions.length; layer++) {
const [countX, countZ] = layerDefinitions[layer];
const layerOffset = layer % 2 === 0 ? -0.1 : 0.1;
for (let iz = 0; iz < countZ; iz++) {
for (let ix = 0; ix < countX; ix++) {
const radius = 0.285 + random() * 0.05;
const scaleX = radius * (0.95 + random() * 0.1);
const scaleY = radius * (0.72 + random() * 0.08);
const scaleZ = radius * (0.95 + random() * 0.1);
const x =
pileCenterX +
(ix - (countX - 1) * 0.5) * 0.68 +
layerOffset +
(random() - 0.5) * 0.055;
const z =
(iz - (countZ - 1) * 0.5) * 0.68 +
(layer % 2 === 0 ? 0.08 : -0.08) +
(random() - 0.5) * 0.055;
const y =
particleFloor +
0.255 +
layer * 0.235 +
(random() - 0.5) * 0.025;
const rotation = new THREE.Euler(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
const quaternion = new THREE.Quaternion().setFromEuler(rotation);
const matrix = new THREE.Matrix4().compose(
new THREE.Vector3(x, y, z),
quaternion,
new THREE.Vector3(scaleX, scaleY, scaleZ)
);
particleTransforms.push(matrix);
const baseColor = new THREE.Color(
palette[Math.floor(random() * palette.length)]
);
baseColor.multiplyScalar(0.9 + random() * 0.18);
particleColors.push(baseColor);
}
}
}
const particleGeometry = new THREE.IcosahedronGeometry(1, 1);
const particleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.83,
metalness: 0,
flatShading: true
});
const particles = new THREE.InstancedMesh(
particleGeometry,
particleMaterial,
particleTransforms.length
);
particles.castShadow = true;
particles.receiveShadow = true;
particles.instanceMatrix.setUsage(THREE.StaticDrawUsage);
for (let i = 0; i < particleTransforms.length; i++) {
particles.setMatrixAt(i, particleTransforms[i]);
particles.setColorAt(i, particleColors[i]);
}
particles.instanceMatrix.needsUpdate = true;
particles.instanceColor.needsUpdate = true;
scene.add(particles);
// A subtle wire overlay emphasizes the low-poly construction.
const wireMaterial = new THREE.MeshBasicMaterial({
color: 0x253c3f,
wireframe: true,
transparent: true,
opacity: 0.045,
depthWrite: false
});
const particleWireframe = new THREE.InstancedMesh(
particleGeometry,
wireMaterial,
particleTransforms.length
);
for (let i = 0; i < particleTransforms.length; i++) {
particleWireframe.setMatrixAt(i, particleTransforms[i]);
}
particleWireframe.instanceMatrix.needsUpdate = true;
particleWireframe.renderOrder = 1;
scene.add(particleWireframe);
// ------------------------------------------------------------
// Illustrated slope-angle construction
// ------------------------------------------------------------
const angleOrigin = new THREE.Vector3(2.45, 0.39, 2.38);
const angleDegrees = 34;
const angleRadians = THREE.MathUtils.degToRad(angleDegrees);
const surfaceLength = 2.35;
const horizontalLength = 2.65;
const surfaceEnd = angleOrigin.clone().add(
new THREE.Vector3(
-Math.cos(angleRadians) * surfaceLength,
Math.sin(angleRadians) * surfaceLength,
0
)
);
const horizontalEnd = angleOrigin.clone().add(
new THREE.Vector3(-horizontalLength, 0, 0)
);
const projectionEnd = new THREE.Vector3(
surfaceEnd.x,
angleOrigin.y,
surfaceEnd.z
);
function addLine(points, material) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, material);
if (material.isLineDashedMaterial) {
line.computeLineDistances();
}
scene.add(line);
return line;
}
const horizontalMaterial = new THREE.LineDashedMaterial({
color: 0x53696b,
dashSize: 0.12,
gapSize: 0.075,
transparent: true,
opacity: 0.76
});
const surfaceMaterial = new THREE.LineDashedMaterial({
color: 0xcf714a,
dashSize: 0.14,
gapSize: 0.065,
transparent: true,
opacity: 0.95
});
const projectionMaterial = new THREE.LineDashedMaterial({
color: 0x889392,
dashSize: 0.07,
gapSize: 0.065,
transparent: true,
opacity: 0.58
});
const arcMaterial = new THREE.LineBasicMaterial({
color: 0xcf714a,
transparent: true,
opacity: 0.95
});
addLine(
[angleOrigin.clone(), horizontalEnd.clone()],
horizontalMaterial
);
addLine(
[angleOrigin.clone(), surfaceEnd.clone()],
surfaceMaterial
);
addLine(
[surfaceEnd.clone(), projectionEnd.clone()],
projectionMaterial
);
const arcPoints = [];
const arcRadius = 0.62;
for (let i = 0; i <= 48; i++) {
const t = angleRadians * (i / 48);
arcPoints.push(
new THREE.Vector3(
angleOrigin.x - Math.cos(t) * arcRadius,
angleOrigin.y + Math.sin(t) * arcRadius,
angleOrigin.z + 0.006
)
);
}
addLine(arcPoints, arcMaterial);
const triangleGeometry = new THREE.BufferGeometry();
triangleGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
angleOrigin.x, angleOrigin.y, angleOrigin.z - 0.006,
horizontalEnd.x, horizontalEnd.y, horizontalEnd.z - 0.006,
surfaceEnd.x, surfaceEnd.y, surfaceEnd.z - 0.006
],
3
)
);
triangleGeometry.setIndex([0, 1, 2]);
const triangle = new THREE.Mesh(
triangleGeometry,
new THREE.MeshBasicMaterial({
color: 0xcf714a,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.075,
depthWrite: false
})
);
scene.add(triangle);
const originMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 8, 6),
new THREE.MeshBasicMaterial({ color: 0xcf714a })
);
originMarker.position.copy(angleOrigin);
scene.add(originMarker);
const endMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.035, 8, 6),
new THREE.MeshBasicMaterial({ color: 0xcf714a })
);
endMarker.position.copy(surfaceEnd);
scene.add(endMarker);
// ------------------------------------------------------------
// Canvas-based in-scene label
// ------------------------------------------------------------
function createAngleLabel() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 180;
const context = canvas.getContext("2d");
const x = 8;
const y = 8;
const width = 496;
const height = 164;
const radius = 22;
context.clearRect(0, 0, canvas.width, canvas.height);
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
context.fillStyle = "rgba(249, 247, 241, 0.94)";
context.fill();
context.strokeStyle = "rgba(207, 113, 74, 0.55)";
context.lineWidth = 4;
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#20373b";
context.font = "700 66px ui-sans-serif, system-ui, sans-serif";
context.fillText("θ 34°", 256, 72);
context.fillStyle = "#cf714a";
context.font = "700 22px ui-sans-serif, system-ui, sans-serif";
context.fillText("ILLUSTRATIVE", 256, 127);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(1.15, 1.3, 2.43);
sprite.scale.set(1.55, 0.55, 1);
sprite.renderOrder = 20;
scene.add(sprite);
}
createAngleLabel();
// ------------------------------------------------------------
// Direct camera controls: no external controls module
// ------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let activePointerId = null;
const canvas = renderer.domElement;
function clampRadius(value) {
const fit = fittedDistance();
return THREE.MathUtils.clamp(value, fit * 0.72, fit * 1.65);
}
function resetView() {
desiredAzimuth = 0.64;
desiredPolar = 1.02;
desiredRadius = fittedDistance();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.pointerType === "mouse") return;
dragging = true;
activePointerId = event.pointerId;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredAzimuth -= deltaX * 0.006;
desiredPolar = THREE.MathUtils.clamp(
desiredPolar + deltaY * 0.005,
0.38,
1.38
);
});
function stopDragging(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = clampRadius(
desiredRadius + event.deltaY * 0.008
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetView();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
desiredRadius = clampRadius(desiredRadius);
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
function animate() {
const damping = 0.09;
currentAzimuth +=
(desiredAzimuth - currentAzimuth) * damping;
currentPolar +=
(desiredPolar - currentPolar) * damping;
currentRadius +=
(desiredRadius - currentRadius) * damping;
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
animate();
</script>
</body>
</html>
```