Prompt specification
Build or customize the Three.js 3D scene "Two Handles and a Shared Crate" 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: Two Handles and a Shared Crate
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-handles-and-a-shared-crate-x3217
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a long low-poly crate with two carrying handles. Build wooden panels, corner battens, and metal handle brackets with clear hand openings. Mark two support positions and the center of mass for a uniform load, with a thin vertical guide reaching the base. Keep the crate horizontal on a low stand. Its main purpose is to make balanced support placement readable from several viewpoints, without adding carriers or a full lifting simulation.
Working Three.js Starter (two-handles-and-a-shared-crate-x3217):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Balanced Crate Study</title>
<style>
:root {
color-scheme: light;
--ink: #183238;
--paper: rgba(248, 245, 236, 0.92);
--teal: #238f86;
--amber: #e98b3a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e2d6;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
#info {
position: fixed;
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 17px 18px 16px;
color: var(--ink);
background: var(--paper);
border: 1px solid rgba(24, 50, 56, 0.12);
border-radius: 16px;
box-shadow: 0 14px 40px rgba(34, 49, 48, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
user-select: none;
}
.eyebrow {
margin-bottom: 7px;
color: #668078;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0 0 7px;
font-size: 21px;
line-height: 1.15;
letter-spacing: -0.02em;
}
#info p {
margin: 0;
color: #4d6665;
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(24, 50, 56, 0.1);
font-size: 11px;
font-weight: 700;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}
.swatch.teal {
background: var(--teal);
}
.swatch.amber {
background: var(--amber);
}
#views {
position: fixed;
left: 50%;
bottom: 22px;
display: flex;
gap: 6px;
padding: 6px;
transform: translateX(-50%);
background: rgba(19, 42, 47, 0.9);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 13px;
box-shadow: 0 14px 38px rgba(24, 38, 38, 0.22);
backdrop-filter: blur(12px);
}
#views button {
min-width: 72px;
padding: 9px 12px;
border: 0;
border-radius: 9px;
color: #dce8e5;
background: transparent;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
cursor: pointer;
transition: color 150ms, background 150ms;
}
#views button:hover,
#views button:focus-visible {
color: white;
background: rgba(255, 255, 255, 0.1);
outline: none;
}
#views button.active {
color: #173338;
background: #f5f1e8;
}
#hint {
position: fixed;
right: 20px;
bottom: 24px;
padding: 8px 11px;
color: rgba(24, 50, 56, 0.72);
background: rgba(248, 245, 236, 0.68);
border-radius: 9px;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
pointer-events: none;
user-select: none;
}
@media (max-width: 680px) {
#info {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
#info p,
.legend {
display: none;
}
#views {
bottom: 12px;
}
#views button {
min-width: 58px;
padding: 9px 8px;
font-size: 10px;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<aside id="info">
<div class="eyebrow">Static balance / support study</div>
<h1>Long low-poly transport crate</h1>
<p>
Two symmetric support positions carry a uniform load. The marked center
of mass lies midway between them, with a guide dropping to the crate base.
</p>
<div class="legend">
<span><i class="swatch teal"></i>Support positions</span>
<span><i class="swatch amber"></i>Center of mass</span>
</div>
</aside>
<nav id="views" aria-label="Camera viewpoints">
<button data-view="overview" class="active">Overview</button>
<button data-view="front">Front</button>
<button data-view="end">End</button>
<button data-view="top">Top</button>
</nav>
<div id="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, scene, and camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e2d6);
scene.fog = new THREE.Fog(0xe8e2d6, 14, 29);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const orbitTarget = new THREE.Vector3(0, 1.5, 0);
let theta = 0.82;
let phi = 1.02;
let radius = 10.4;
let cameraTween = null;
const presets = {
overview: { theta: 0.82, phi: 1.02, radius: 10.4 },
front: { theta: 0.00, phi: 1.08, radius: 9.5 },
end: { theta: Math.PI / 2, phi: 1.03, radius: 8.8 },
top: { theta: 0.00, phi: 0.35, radius: 9.6 }
};
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
orbitTarget.x + radius * sinPhi * Math.sin(theta),
orbitTarget.y + radius * Math.cos(phi),
orbitTarget.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(orbitTarget);
}
function flyTo(preset) {
cameraTween = {
start: performance.now(),
duration: 720,
from: { theta, phi, radius },
to: { ...preset }
};
}
const viewButtons = [...document.querySelectorAll("#views button")];
viewButtons.forEach((button) => {
button.addEventListener("click", () => {
viewButtons.forEach((b) => b.classList.remove("active"));
button.classList.add("active");
flyTo(presets[button.dataset.view]);
});
});
// Direct orbit/zoom controls, implemented without addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTween = null;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
theta -= dx * 0.007;
phi = THREE.MathUtils.clamp(phi - dy * 0.006, 0.25, 1.43);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
6.1,
16
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
viewButtons.forEach((b) => b.classList.remove("active"));
viewButtons[0].classList.add("active");
flyTo(presets.overview);
});
// -------------------------------------------------------------------------
// Lighting and ground
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff5df,
0x58706f,
1.75
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d6, 3.15);
keyLight.position.set(5.5, 10, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb7d7db, 1.0);
fillLight.position.set(-6, 4, -5);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xdcd6c9,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const materials = {
wood: [
new THREE.MeshStandardMaterial({
color: 0xb7793e,
roughness: 0.86,
metalness: 0,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xc58b4d,
roughness: 0.88,
metalness: 0,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xa96b38,
roughness: 0.9,
metalness: 0,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xca9455,
roughness: 0.85,
metalness: 0,
flatShading: true
})
],
batten: new THREE.MeshStandardMaterial({
color: 0x704329,
roughness: 0.9,
metalness: 0,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x34464b,
roughness: 0.42,
metalness: 0.72,
flatShading: true
}),
metalEdge: new THREE.MeshStandardMaterial({
color: 0x718186,
roughness: 0.34,
metalness: 0.8,
flatShading: true
}),
stand: new THREE.MeshStandardMaterial({
color: 0x294047,
roughness: 0.54,
metalness: 0.6,
flatShading: true
}),
foot: new THREE.MeshStandardMaterial({
color: 0x17292e,
roughness: 0.68,
metalness: 0.48,
flatShading: true
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x111b1d,
roughness: 0.98,
metalness: 0
}),
teal: new THREE.MeshBasicMaterial({
color: 0x238f86,
transparent: true,
opacity: 0.9
}),
amber: new THREE.MeshBasicMaterial({
color: 0xe98b3a,
transparent: true,
opacity: 0.94,
depthTest: false,
depthWrite: false
}),
loadArrow: new THREE.MeshStandardMaterial({
color: 0x6f9691,
roughness: 0.72,
metalness: 0.08,
flatShading: true
})
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addRod(parent, start, end, radius, material, radialSegments = 8) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addNail(parent, position, axis = "z") {
const nail = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.027, 0.022, 8),
materials.metalEdge
);
nail.position.set(...position);
if (axis === "x") {
nail.rotation.z = Math.PI / 2;
} else if (axis === "y") {
nail.rotation.x = Math.PI / 2;
}
nail.castShadow = true;
parent.add(nail);
}
// -------------------------------------------------------------------------
// Low stand with two clearly marked support positions
// -------------------------------------------------------------------------
const stand = new THREE.Group();
scene.add(stand);
const supportX = [-1.55, 1.55];
// Tie beam makes the two supports read as one low, rigid stand.
addBox(
stand,
[3.85, 0.17, 0.28],
[0, 0.43, 0],
materials.stand
);
supportX.forEach((x, index) => {
// Broad foot.
addBox(
stand,
[0.93, 0.14, 2.55],
[x, 0.07, 0],
materials.foot
);
// Pedestal body.
addBox(
stand,
[0.50, 0.70, 2.15],
[x, 0.49, 0],
materials.stand
);
// Top bearing pad.
addBox(
stand,
[0.69, 0.12, 2.30],
[x, 0.90, 0],
materials.rubber
);
// Thin teal rim around the support position.
const floorRing = new THREE.Mesh(
new THREE.RingGeometry(0.43, 0.49, 36),
new THREE.MeshBasicMaterial({
color: 0x238f86,
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide,
depthWrite: false
})
);
floorRing.rotation.x = -Math.PI / 2;
floorRing.position.set(x, 0.018, 0);
stand.add(floorRing);
// Front-facing target identifies the exact support position.
const frontTarget = new THREE.Mesh(
new THREE.TorusGeometry(0.13, 0.025, 6, 24),
materials.teal
);
frontTarget.position.set(x, 0.54, 1.09);
stand.add(frontTarget);
addBox(
stand,
[0.018, 0.18, 0.018],
[x, 0.34, 1.095],
materials.teal,
false
);
addBox(
stand,
[0.14, 0.018, 0.018],
[x, 0.25, 1.095],
materials.teal,
false
);
});
// Dashed floor datum connects the two symmetric support positions.
const spanGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-1.55, 0.022, 1.78),
new THREE.Vector3(1.55, 0.022, 1.78)
]);
const spanLine = new THREE.Line(
spanGeometry,
new THREE.LineDashedMaterial({
color: 0x238f86,
transparent: true,
opacity: 0.42,
dashSize: 0.13,
gapSize: 0.10
})
);
spanLine.computeLineDistances();
scene.add(spanLine);
// -------------------------------------------------------------------------
// Wooden crate
// -------------------------------------------------------------------------
const crate = new THREE.Group();
scene.add(crate);
const length = 5.8;
const width = 2.2;
const bottomY = 0.98;
const topY = 2.52;
const sidePanelHeight = 1.29;
const sidePanelY = 1.745;
// Base boards.
const baseBoardCount = 5;
const baseGap = 0.025;
const baseBoardWidth = (width - baseGap * (baseBoardCount - 1)) / baseBoardCount;
for (let i = 0; i < baseBoardCount; i++) {
const z = -width / 2 + baseBoardWidth / 2 + i * (baseBoardWidth + baseGap);
addBox(
crate,
[length - 0.05, 0.14, baseBoardWidth],
[0, bottomY + 0.07, z],
materials.wood[(i + 1) % materials.wood.length]
);
}
// Long side panels, built from individual vertical wooden boards.
const sideBoardCount = 6;
const sideGap = 0.025;
const sideBoardWidth =
(length - sideGap * (sideBoardCount - 1)) / sideBoardCount;
[-1, 1].forEach((side) => {
for (let i = 0; i < sideBoardCount; i++) {
const x =
-length / 2 +
sideBoardWidth / 2 +
i * (sideBoardWidth + sideGap);
addBox(
crate,
[sideBoardWidth, sidePanelHeight, 0.13],
[x, sidePanelY, side * (width / 2 - 0.065)],
materials.wood[(i + (side > 0 ? 1 : 0)) % materials.wood.length]
);
}
});
// End panels.
const endBoardCount = 4;
const endGap = 0.024;
const endBoardWidth =
(width - endGap * (endBoardCount - 1)) / endBoardCount;
[-1, 1].forEach((side) => {
for (let i = 0; i < endBoardCount; i++) {
const z =
-width / 2 +
endBoardWidth / 2 +
i * (endBoardWidth + endGap);
addBox(
crate,
[0.14, sidePanelHeight, endBoardWidth],
[side * (length / 2 - 0.07), sidePanelY, z],
materials.wood[(i + (side > 0 ? 2 : 0)) % materials.wood.length]
);
}
});
// Top boards.
const topBoardCount = 5;
const topGap = 0.024;
const topBoardWidth =
(width - topGap * (topBoardCount - 1)) / topBoardCount;
for (let i = 0; i < topBoardCount; i++) {
const z =
-width / 2 +
topBoardWidth / 2 +
i * (topBoardWidth + topGap);
addBox(
crate,
[length - 0.08, 0.13, topBoardWidth],
[0, topY - 0.065, z],
materials.wood[(i + 2) % materials.wood.length]
);
}
// Four dark wooden corner battens.
[-1, 1].forEach((xSide) => {
[-1, 1].forEach((zSide) => {
addBox(
crate,
[0.22, 1.60, 0.22],
[
xSide * (length / 2 - 0.11),
1.75,
zSide * (width / 2 - 0.08)
],
materials.batten
);
});
});
// Top and lower perimeter rails.
[-1, 1].forEach((side) => {
addBox(
crate,
[length, 0.17, 0.16],
[0, topY - 0.035, side * (width / 2 - 0.08)],
materials.batten
);
addBox(
crate,
[length, 0.15, 0.15],
[0, bottomY + 0.065, side * (width / 2 - 0.08)],
materials.batten
);
});
[-1, 1].forEach((side) => {
addBox(
crate,
[0.16, 0.17, width],
[side * (length / 2 - 0.08), topY - 0.035, 0],
materials.batten
);
});
// Exposed nail heads on the corner battens.
[-1, 1].forEach((xSide) => {
[1.25, 1.72, 2.20].forEach((y) => {
addNail(
crate,
[xSide * (length / 2 - 0.11), y, width / 2 + 0.035],
"z"
);
addNail(
crate,
[xSide * (length / 2 - 0.11), y, -width / 2 - 0.035],
"z"
);
});
[1.25, 1.72, 2.20].forEach((y) => {
addNail(
crate,
[xSide * (length / 2 + 0.035), y, width / 2 - 0.08],
"x"
);
addNail(
crate,
[xSide * (length / 2 + 0.035), y, -width / 2 + 0.08],
"x"
);
});
});
// -------------------------------------------------------------------------
// Two carrying handles with metal brackets and open hand spaces
// -------------------------------------------------------------------------
function createHandle(centerX) {
const handle = new THREE.Group();
handle.position.x = centerX;
crate.add(handle);
const footOffset = 0.48;
const footY = topY + 0.20;
[-1, 1].forEach((side) => {
const x = side * footOffset;
// Flat metal mounting plate.
addBox(
handle,
[0.29, 0.09, 0.42],
[x, topY + 0.045, 0],
materials.metal
);
// Raised mounting bracket.
addBox(
handle,
[0.18, 0.18, 0.28],
[x, topY + 0.15, 0],
materials.metalEdge
);
// Four visible bolts per mounting plate.
[-0.075, 0.075].forEach((dx) => {
[-0.12, 0.12].forEach((z) => {
addBox(
handle,
[0.036, 0.025, 0.036],
[x + dx, topY + 0.105, z],
materials.metalEdge,
false
);
});
});
});
// Open polygonal arch; the space below the top bar remains unobstructed.
const path = [
[-footOffset, footY],
[-footOffset, 2.98],
[-0.38, 3.15],
[-0.24, 3.22],
[0.24, 3.22],
[0.38, 3.15],
[footOffset, 2.98],
[footOffset, footY]
];
for (let i = 0; i < path.length - 1; i++) {
addRod(
handle,
path[i],
path[i + 1],
0.064,
materials.metal,
8
);
}
}
createHandle(-1.55);
createHandle(1.55);
// -------------------------------------------------------------------------
// Uniform-load notation
// -------------------------------------------------------------------------
const loadGroup = new THREE.Group();
scene.add(loadGroup);
// A restrained row of downward symbols indicates distributed loading.
for (let i = 0; i < 7; i++) {
const x = -2.4 + i * 0.8;
addBox(
loadGroup,
[0.018, 0.24, 0.018],
[x, 2.91, -0.78],
materials.loadArrow,
false
);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.13, 3),
materials.loadArrow
);
arrowHead.position.set(x, 2.69, -0.78);
arrowHead.rotation.z = Math.PI;
loadGroup.add(arrowHead);
}
// -------------------------------------------------------------------------
// Center of mass and vertical guide to the crate base
// -------------------------------------------------------------------------
const centerOfMassY = (bottomY + topY) / 2;
const guide = new THREE.Mesh(
new THREE.CylinderGeometry(
0.012,
0.012,
centerOfMassY - bottomY,
6
),
materials.amber
);
guide.position.set(
0,
(centerOfMassY + bottomY) / 2,
0
);
guide.renderOrder = 20;
scene.add(guide);
// -------------------------------------------------------------------------
// Canvas-based labels and target markers
// -------------------------------------------------------------------------
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + width - r, y);
context.quadraticCurveTo(x + width, y, x + width, y + r);
context.lineTo(x + width, y + height - r);
context.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
context.lineTo(x + r, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
}
function createLabel(title, subtitle, accent, width = 2.05) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 180;
const context = labelCanvas.getContext("2d");
roundedRect(context, 5, 5, 630, 170, 24);
context.fillStyle = "rgba(17, 42, 47, 0.92)";
context.fill();
roundedRect(context, 5, 5, 12, 170, 6);
context.fillStyle = accent;
context.fill();
context.textAlign = "left";
context.textBaseline = "middle";
context.fillStyle = "#ffffff";
context.font = "800 35px system-ui, sans-serif";
context.fillText(title, 38, 66);
context.fillStyle = "rgba(226, 238, 235, 0.78)";
context.font = "600 23px system-ui, sans-serif";
context.fillText(subtitle, 39, 119);
const texture = new THREE.CanvasTexture(labelCanvas);
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.scale.set(width, width * 180 / 640, 1);
sprite.renderOrder = 30;
return sprite;
}
function createTarget(size, color = "#e98b3a") {
const targetCanvas = document.createElement("canvas");
targetCanvas.width = 256;
targetCanvas.height = 256;
const context = targetCanvas.getContext("2d");
context.clearRect(0, 0, 256, 256);
context.strokeStyle = color;
context.fillStyle = color;
context.lineWidth = 12;
context.lineCap = "round";
context.beginPath();
context.arc(128, 128, 75, 0, Math.PI * 2);
context.stroke();
context.beginPath();
context.moveTo(128, 28);
context.lineTo(128, 82);
context.moveTo(128, 174);
context.lineTo(128, 228);
context.moveTo(28, 128);
context.lineTo(82, 128);
context.moveTo(174, 128);
context.lineTo(228, 128);
context.stroke();
context.beginPath();
context.arc(128, 128, 13, 0, Math.PI * 2);
context.fill();
const texture = new THREE.CanvasTexture(targetCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(size, size, 1);
sprite.renderOrder = 25;
return sprite;
}
const comTarget = createTarget(0.36);
comTarget.position.set(0, centerOfMassY, 0);
scene.add(comTarget);
const baseTarget = createTarget(0.20);
baseTarget.position.set(0, bottomY, 0);
scene.add(baseTarget);
const supportLabelA = createLabel(
"SUPPORT A",
"SYMMETRIC POSITION",
"#38b8aa",
1.95
);
supportLabelA.position.set(-1.55, 0.42, 1.48);
scene.add(supportLabelA);
const supportLabelB = createLabel(
"SUPPORT B",
"SYMMETRIC POSITION",
"#38b8aa",
1.95
);
supportLabelB.position.set(1.55, 0.42, 1.48);
scene.add(supportLabelB);
const comLabel = createLabel(
"CENTER OF MASS",
"UNIFORM LOAD",
"#f1a05a",
1.92
);
comLabel.position.set(0, 2.06, 0);
scene.add(comLabel);
const loadLabel = createLabel(
"UNIFORM LOAD",
"DISTRIBUTED OVER THE CRATE",
"#8ab1aa",
2.62
);
loadLabel.position.set(0, 3.43, -0.78);
scene.add(loadLabel);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
function animate(now) {
if (cameraTween) {
const raw = Math.min(
1,
(now - cameraTween.start) / cameraTween.duration
);
const eased =
raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
theta = THREE.MathUtils.lerp(
cameraTween.from.theta,
cameraTween.to.theta,
eased
);
phi = THREE.MathUtils.lerp(
cameraTween.from.phi,
cameraTween.to.phi,
eased
);
radius = THREE.MathUtils.lerp(
cameraTween.from.radius,
cameraTween.to.radius,
eased
);
if (raw >= 1) {
cameraTween = null;
}
}
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```