Prompt specification
Build or customize the Three.js 3D scene "Crack-tip concentration analogy display" 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: Crack-tip concentration analogy display
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/crack-tip-concentration-analogy-display-x1950
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing glass and ceramic microstructures. Place smooth and notched brittle-block models with illustrative stress contours; label the contours qualitative and show why geometry can influence fracture initiation. A 3D cutaway view.
Working Three.js Starter (crack-tip-concentration-analogy-display-x1950):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Brittle Fracture: Geometry, Stress and Microstructure</title>
<style>
:root {
color-scheme: dark;
--bg: #07111e;
--panel: rgba(10, 22, 37, 0.82);
--panel-border: rgba(176, 216, 238, 0.16);
--text: #e9f4fb;
--muted: #93aabd;
--cyan: #63d9ed;
--green: #8ae3b8;
--yellow: #ffd166;
--orange: #ff9654;
--red: #ff5364;
--glass: #83d8ef;
--ceramic: #d7c7ad;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 42% 35%, rgba(28, 73, 100, 0.32), transparent 42%),
radial-gradient(circle at 80% 80%, rgba(106, 67, 37, 0.15), transparent 38%),
var(--bg);
color: var(--text);
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;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(3, 8, 15, 0.25), transparent 22%),
radial-gradient(circle at center, transparent 48%, rgba(2, 7, 13, 0.56) 100%);
z-index: 2;
}
.header {
position: fixed;
z-index: 5;
top: 25px;
left: 28px;
width: min(620px, calc(100vw - 390px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 10px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
max-width: 650px;
margin: 0;
font-size: clamp(28px, 3.5vw, 54px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
}
.subtitle {
max-width: 570px;
margin: 15px 0 0;
color: #a9bdcc;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 6;
top: 24px;
right: 24px;
width: 326px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 20px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 22px 70px rgba(0, 0, 0, 0.32),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px) saturate(1.15);
scrollbar-width: thin;
scrollbar-color: rgba(121, 188, 218, 0.3) transparent;
}
.panel h2 {
margin: 0 0 10px;
font-size: 17px;
letter-spacing: -0.02em;
}
.panel p {
margin: 0;
color: var(--muted);
font-size: 12.5px;
line-height: 1.55;
}
.section {
margin-top: 18px;
padding-top: 17px;
border-top: 1px solid rgba(177, 214, 232, 0.11);
}
.section-title {
margin-bottom: 11px !important;
color: #cfe0eb !important;
font-size: 10px !important;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-gradient {
height: 9px;
overflow: hidden;
border-radius: 20px;
background: linear-gradient(
90deg,
var(--cyan),
var(--green),
var(--yellow),
var(--orange),
var(--red)
);
box-shadow: 0 0 18px rgba(255, 120, 90, 0.16);
}
.legend-row {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #adc2d0;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.qualifier {
margin-top: 8px !important;
color: #738b9c !important;
font-size: 10.5px !important;
font-style: italic;
}
.comparison {
display: grid;
gap: 10px;
}
.comparison-item {
display: grid;
grid-template-columns: 28px 1fr;
gap: 10px;
align-items: start;
}
.comparison-icon {
display: grid;
place-items: center;
width: 28px;
height: 28px;
border: 1px solid rgba(125, 217, 237, 0.2);
border-radius: 9px;
color: var(--cyan);
background: rgba(99, 217, 237, 0.07);
font-size: 14px;
font-weight: 800;
}
.comparison-item strong {
display: block;
margin-bottom: 3px;
color: #e3edf4;
font-size: 12px;
}
.comparison-item span {
color: var(--muted);
font-size: 11.5px;
line-height: 1.45;
}
.material-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 10px;
}
.swatch {
width: 34px;
height: 34px;
flex: 0 0 auto;
border-radius: 9px;
border: 1px solid rgba(255, 255, 255, 0.13);
}
.swatch.glass {
background:
radial-gradient(circle at 28% 30%, rgba(255,255,255,.9) 0 2px, transparent 3px),
radial-gradient(circle at 70% 64%, rgba(255,255,255,.55) 0 1px, transparent 2px),
linear-gradient(135deg, rgba(122,225,245,.7), rgba(53,130,168,.2));
}
.swatch.ceramic {
background:
radial-gradient(circle at 25% 30%, #7c674e 0 1px, transparent 2px),
radial-gradient(circle at 70% 65%, #9c896e 0 1px, transparent 2px),
#d7c7ad;
background-size: 9px 9px, 13px 13px, auto;
}
.material-row strong {
display: block;
margin-bottom: 2px;
font-size: 12px;
}
.material-row span {
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.note {
padding: 11px 12px;
border: 1px solid rgba(255, 209, 102, 0.14);
border-radius: 11px;
background: rgba(255, 209, 102, 0.045);
color: #b9c8d2 !important;
font-size: 10.5px !important;
}
.controls {
position: fixed;
z-index: 7;
left: 27px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 8px;
align-items: center;
padding: 9px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: rgba(8, 19, 32, 0.78);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(14px);
}
.control {
position: relative;
display: flex;
align-items: center;
gap: 7px;
padding: 8px 10px;
border-radius: 9px;
color: #b9cbd7;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
user-select: none;
font-size: 11px;
font-weight: 650;
white-space: nowrap;
}
.control:hover {
background: rgba(255, 255, 255, 0.07);
}
.control input {
width: 13px;
height: 13px;
margin: 0;
accent-color: var(--cyan);
}
button.control {
border: 0;
font: inherit;
}
.help {
position: fixed;
z-index: 5;
right: 28px;
bottom: 25px;
color: rgba(173, 198, 214, 0.65);
pointer-events: none;
font-size: 10.5px;
letter-spacing: 0.02em;
}
.label-layer {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.model-label,
.callout {
position: absolute;
visibility: hidden;
white-space: nowrap;
}
.model-label {
padding: 7px 10px;
border: 1px solid rgba(168, 219, 237, 0.2);
border-radius: 8px;
color: #e7f3fa;
background: rgba(6, 18, 30, 0.78);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(8px);
transform: translate(-50%, -125%);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.model-label.glass {
border-color: rgba(99, 217, 237, 0.33);
}
.model-label.ceramic {
border-color: rgba(215, 199, 173, 0.34);
}
.callout {
display: flex;
align-items: center;
gap: 8px;
color: #dbe8f0;
transform: translate(8px, -50%);
font-size: 10.5px;
font-weight: 650;
text-shadow: 0 2px 8px #000;
}
.callout::before {
content: "";
width: 7px;
height: 7px;
flex: 0 0 auto;
border: 2px solid #ffcb67;
border-radius: 50%;
background: #ff725b;
box-shadow: 0 0 12px rgba(255, 101, 83, 0.72);
}
@media (max-width: 900px) {
.header {
top: 17px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
max-width: 500px;
font-size: clamp(26px, 6vw, 42px);
}
.subtitle {
max-width: 500px;
font-size: 12px;
}
.panel {
top: auto;
right: 12px;
bottom: 76px;
width: min(340px, calc(100vw - 24px));
max-height: 34vh;
padding: 15px;
}
.panel h2 {
font-size: 15px;
}
.controls {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
.help {
display: none;
}
}
@media (max-width: 560px) {
.subtitle {
display: none;
}
.panel {
max-height: 29vh;
}
.control {
padding: 7px 8px;
font-size: 10px;
}
.model-label {
font-size: 8.5px;
}
.callout {
font-size: 9px;
}
}
</style>
</head>
<body>
<div class="vignette"></div>
<header class="header">
<div class="eyebrow">Brittle materials / fracture initiation</div>
<h1>Geometry decides where weakness becomes a crack.</h1>
<p class="subtitle">
Four cutaway specimens compare glass and ceramic blocks with smooth and
notched edges. The colored fields are qualitative illustrations of local
stress concentration—not finite-element results.
</p>
</header>
<aside class="panel">
<h2>How to read the scene</h2>
<p>
Outward arrows indicate tensile loading. A sharp notch focuses the local
field; a nominally smooth edge instead relies on microscopic flaws,
pores, or surface damage.
</p>
<div class="section">
<p class="section-title">Qualitative stress concentration</p>
<div class="legend-gradient"></div>
<div class="legend-row">
<span>Low</span>
<span>Medium</span>
<span>High</span>
</div>
<p class="qualifier">
Relative concentration only; colors and contour spacing are illustrative.
</p>
</div>
<div class="section comparison">
<p class="section-title">Geometry changes initiation</p>
<div class="comparison-item">
<div class="comparison-icon">S</div>
<div>
<strong>Smooth edge</strong>
<span>
Stress is distributed more broadly. Initiation occurs at the most
vulnerable microscopic defect or surface flaw.
</span>
</div>
</div>
<div class="comparison-item">
<div class="comparison-icon">N</div>
<div>
<strong>Notched edge</strong>
<span>
The notch radius creates a local stress concentration. A crack can
nucleate at the notch tip even when the global load is moderate.
</span>
</div>
</div>
</div>
<div class="section">
<p class="section-title">Material microstructure</p>
<div class="material-row">
<div class="swatch glass"></div>
<div>
<strong>Glass</strong>
<span>Mostly continuous amorphous phase, with rare bubbles and surface flaws.</span>
</div>
</div>
<div class="material-row">
<div class="swatch ceramic"></div>
<div>
<strong>Ceramic</strong>
<span>Polycrystalline grains, pores, grain boundaries and microcracks.</span>
</div>
</div>
</div>
<div class="section">
<p class="note">
Presentation cutaway: the upper-right section is removed to expose the
specimen interior. It is not the mechanical notch. The deliberately
notched specimens also have a V-notch in the left, loaded edge.
</p>
</div>
</aside>
<div class="label-layer" id="labels"></div>
<div class="controls" aria-label="Scene controls">
<label class="control">
<input id="stressToggle" type="checkbox" checked>
Stress contours
</label>
<label class="control">
<input id="crackToggle" type="checkbox" checked>
Crack paths
</label>
<label class="control">
<input id="microToggle" type="checkbox" checked>
Microstructure
</label>
<label class="control">
<input id="orbitToggle" type="checkbox" checked>
Auto orbit
</label>
<button class="control" id="resetView" type="button">Reset view</button>
</div>
<div class="help">Drag to orbit · Scroll to zoom · R 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 and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x07111e, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111e, 0.021);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight(0xc9ecff, 0x172033, 2.3);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.8);
keyLight.position.set(-5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x49d7ff, 18, 18, 2);
cyanLight.position.set(-7, 3, 4);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xffa45d, 13, 15, 2);
warmLight.position.set(7, 2, 2);
scene.add(warmLight);
const rimLight = new THREE.DirectionalLight(0x84b9ff, 1.6);
rimLight.position.set(4, 5, -8);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Ground and layout
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.ShadowMaterial({
color: 0x000000,
opacity: 0.34
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.13;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(50, 50, 0x27475b, 0x172c3d);
grid.position.y = -1.115;
grid.material.transparent = true;
grid.material.opacity = 0.36;
scene.add(grid);
const W = 3.0;
const H = 2.1;
const D = 2.15;
const CUT_X = 0.65;
const CUT_Y = 0.20;
const NOTCH_DEPTH = 0.42;
const NOTCH_HALF = 0.14;
const layout = [
{
material: "glass",
shape: "smooth",
notched: false,
position: new THREE.Vector3(-3.0, 0, -1.8)
},
{
material: "glass",
shape: "notched",
notched: true,
position: new THREE.Vector3(2.65, 0, -1.8)
},
{
material: "ceramic",
shape: "smooth",
notched: false,
position: new THREE.Vector3(-3.0, 0, 2.35)
},
{
material: "ceramic",
shape: "notched",
notched: true,
position: new THREE.Vector3(2.65, 0, 2.35)
}
];
const stressGroups = [];
const crackGroups = [];
const microGroups = [];
const animatedMarkers = [];
const labels = [];
// -------------------------------------------------------------------------
// Deterministic procedural textures
// -------------------------------------------------------------------------
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ t >>> 15, t | 1);
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
function makeCeramicTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const image = ctx.createImageData(256, 256);
const rand = mulberry32(8117);
for (let i = 0; i < image.data.length; i += 4) {
const n = (rand() - 0.5) * 25;
image.data[i] = 211 + n;
image.data[i + 1] = 202 + n;
image.data[i + 2] = 181 + n;
image.data[i + 3] = 255;
}
ctx.putImageData(image, 0, 0);
for (let i = 0; i < 520; i++) {
const x = rand() * 256;
const y = rand() * 256;
const r = 0.3 + rand() * 1.8;
const dark = rand() > 0.5;
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI * 2);
ctx.fillStyle = dark
? `rgba(91,72,51,${0.08 + rand() * 0.16})`
: `rgba(255,250,232,${0.08 + rand() * 0.18})`;
ctx.fill();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2.4, 2.0);
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeDiscTexture(color, ring = false) {
const canvas = document.createElement("canvas");
canvas.width = 64;
canvas.height = 64;
const ctx = canvas.getContext("2d");
const c = 32;
const gradient = ctx.createRadialGradient(
c - 5, c - 6, 1,
c, c, 29
);
if (ring) {
gradient.addColorStop(0, "rgba(230,251,255,0.1)");
gradient.addColorStop(0.60, "rgba(180,238,250,0.03)");
gradient.addColorStop(0.78, color);
gradient.addColorStop(0.92, "rgba(230,251,255,0.5)");
gradient.addColorStop(1, "rgba(230,251,255,0)");
} else {
gradient.addColorStop(0, color);
gradient.addColorStop(0.58, color);
gradient.addColorStop(1, "rgba(0,0,0,0)");
}
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 64, 64);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const ceramicTexture = makeCeramicTexture();
const bubbleTexture = makeDiscTexture(
"rgba(181,239,251,0.72)",
true
);
const grainTexture = makeDiscTexture(
"rgba(75,57,38,0.70)"
);
const poreTexture = makeDiscTexture(
"rgba(35,28,23,0.82)"
);
const markerTexture = makeDiscTexture(
"rgba(255,83,79,0.95)"
);
// -------------------------------------------------------------------------
// Geometry and materials
// -------------------------------------------------------------------------
function makeBlockShape(notched) {
const shape = new THREE.Shape();
const left = -W / 2;
const bottom = -H / 2;
const top = H / 2;
const right = W / 2;
shape.moveTo(left, bottom);
if (notched) {
shape.lineTo(left, -NOTCH_HALF);
shape.lineTo(left + NOTCH_DEPTH, 0);
shape.lineTo(left, NOTCH_HALF);
shape.lineTo(left, top);
} else {
shape.lineTo(left, top);
}
// Upper-right presentation cutaway.
shape.lineTo(CUT_X, top);
shape.lineTo(CUT_X, CUT_Y);
shape.lineTo(right, CUT_Y);
shape.lineTo(right, bottom);
shape.closePath();
return shape;
}
function makeBlockGeometry(notched) {
const geometry = new THREE.ExtrudeGeometry(
makeBlockShape(notched),
{
depth: D,
steps: 1,
bevelEnabled: true,
bevelThickness: 0.025,
bevelSize: 0.025,
bevelOffset: 0,
bevelSegments: 2,
curveSegments: 1
}
);
geometry.translate(0, 0, -D / 2);
geometry.computeVertexNormals();
return geometry;
}
const glassFaceMaterial = new THREE.MeshPhysicalMaterial({
color: 0x8bd9ea,
roughness: 0.10,
metalness: 0,
transmission: 0.72,
transparent: true,
opacity: 0.82,
ior: 1.52,
thickness: 1.15,
attenuationColor: new THREE.Color(0x4eb5d0),
attenuationDistance: 3.2,
clearcoat: 0.75,
clearcoatRoughness: 0.14,
side: THREE.DoubleSide,
depthWrite: false
});
const glassSideMaterial = new THREE.MeshPhysicalMaterial({
color: 0x6fc9df,
roughness: 0.16,
metalness: 0,
transmission: 0.42,
transparent: true,
opacity: 0.78,
ior: 1.52,
thickness: 0.7,
side: THREE.DoubleSide,
depthWrite: false
});
const ceramicFaceMaterial = new THREE.MeshStandardMaterial({
color: 0xd7c7ad,
map: ceramicTexture,
roughness: 0.78,
metalness: 0.03,
bumpMap: ceramicTexture,
bumpScale: 0.018
});
const ceramicSideMaterial = new THREE.MeshStandardMaterial({
color: 0xe2d3b8,
map: ceramicTexture,
roughness: 0.69,
metalness: 0.02,
bumpMap: ceramicTexture,
bumpScale: 0.012
});
function isMaterialAt(x, y, notched) {
if (x < -W / 2 || x > W / 2 || y < -H / 2 || y > H / 2) {
return false;
}
// Presentation cutaway.
if (x > CUT_X && y > CUT_Y) {
return false;
}
// Mechanical notch void.
if (notched) {
const n = (x + W / 2) / NOTCH_DEPTH;
if (
n >= 0 && n <= 1 &&
Math.abs(y) < NOTCH_HALF * (1 - n)
) {
return false;
}
}
return true;
}
function makePlate() {
const plate = new THREE.Mesh(
new THREE.BoxGeometry(3.55, 0.07, 2.72),
new THREE.MeshStandardMaterial({
color: 0x102334,
roughness: 0.72,
metalness: 0.18,
transparent: true,
opacity: 0.86
})
);
plate.position.y = -1.085;
plate.receiveShadow = true;
return plate;
}
// -------------------------------------------------------------------------
// Qualitative stress field shader
// -------------------------------------------------------------------------
const stressVertexShader = `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const stressFragmentShader = `
precision highp float;
varying vec2 vUv;
uniform float uNotched;
uniform float uStrength;
void main() {
vec2 p = vec2(
(vUv.x - 0.5) * 3.0,
(vUv.y - 0.5) * 2.1
);
// Match the presentation cutaway.
if (p.x > 0.65 && p.y > 0.20) {
discard;
}
// Match the V-notch void.
if (uNotched > 0.5) {
float n = (p.x + 1.5) / 0.42;
if (
n >= 0.0 && n <= 1.0 &&
abs(p.y) < 0.14 * (1.0 - n)
) {
discard;
}
}
vec2 source = (uNotched > 0.5)
? vec2(-1.08, 0.0)
: vec2(-1.49, 0.0);
float distanceToSource = length(
(p - source) * vec2(1.0, 1.10)
);
float concentration = exp(
-distanceToSource * (uNotched > 0.5 ? 2.8 : 2.45)
);
concentration *= (uNotched > 0.5) ? 1.25 : 0.96;
concentration = clamp(concentration, 0.0, 1.0);
float phase =
(1.0 - concentration) * 5.6 +
p.y * 0.10 +
p.x * 0.035;
float bandDistance = abs(fract(phase) - 0.5);
float contour = 1.0 - smoothstep(0.035, 0.115, bandDistance);
vec3 lowColor = vec3(0.20, 0.83, 0.94);
vec3 midColor = vec3(1.00, 0.78, 0.23);
vec3 highColor = vec3(1.00, 0.18, 0.20);
vec3 color = mix(
lowColor,
midColor,
smoothstep(0.10, 0.64, concentration)
);
color = mix(
color,
highColor,
smoothstep(0.67, 1.0, concentration)
);
float alpha =
(0.022 + concentration * 0.16) *
(0.30 + contour * 0.70) *
uStrength;
gl_FragColor = vec4(color, alpha);
}
`;
function makeStressMaterial(notched, strength) {
return new THREE.ShaderMaterial({
uniforms: {
uNotched: { value: notched ? 1 : 0 },
uStrength: { value: strength }
},
vertexShader: stressVertexShader,
fragmentShader: stressFragmentShader,
transparent: true,
depthWrite: false,
depthTest: false,
blending: THREE.AdditiveBlending,
side: THREE.DoubleSide,
toneMapped: false
});
}
// -------------------------------------------------------------------------
// Marching-squares style contour lines on the front section
// -------------------------------------------------------------------------
const contourColors = [
0x58d6e6,
0x78e0b5,
0xffd166,
0xff8b4c,
0xff5364
];
function stressValue(x, y, notched) {
const sourceX = notched ? -1.08 : -1.49;
const d = Math.hypot(x - sourceX, y * 1.10);
if (notched) {
return Math.min(1, 1.25 * Math.exp(-d * 2.8));
}
return Math.exp(-d * 2.55);
}
function buildContourSegments(level, notched) {
const positions = [];
const nx = 64;
const ny = 46;
const xMin = -W / 2;
const xMax = W / 2;
const yMin = -H / 2;
const yMax = H / 2;
function crossing(a, b) {
const denominator = b.v - a.v;
if (Math.abs(denominator) < 1e-9) {
return null;
}
const t = (level - a.v) / denominator;
return {
x: a.x + (b.x - a.x) * t,
y: a.y + (b.y - a.y) * t
};
}
for (let ix = 0; ix < nx; ix++) {
for (let iy = 0; iy < ny; iy++) {
const x0 = xMin + (xMax - xMin) * ix / nx;
const x1 = xMin + (xMax - xMin) * (ix + 1) / nx;
const y0 = yMin + (yMax - yMin) * iy / ny;
const y1 = yMin + (yMax - yMin) * (iy + 1) / ny;
const p0 = { x: x0, y: y0, v: stressValue(x0, y0, notched) };
const p1 = { x: x1, y: y0, v: stressValue(x1, y0, notched) };
const p2 = { x: x1, y: y1, v: stressValue(x1, y1, notched) };
const p3 = { x: x0, y: y1, v: stressValue(x0, y1, notched) };
const edges = [
[p0, p1],
[p1, p2],
[p2, p3],
[p3, p0]
];
const hits = [];
for (const [a, b] of edges) {
if ((a.v < level && b.v >= level) ||
(b.v < level && a.v >= level)) {
const hit = crossing(a, b);
if (hit) hits.push(hit);
}
}
const pairs = [];
if (hits.length === 2) {
pairs.push([hits[0], hits[1]]);
} else if (hits.length === 4) {
pairs.push([hits[0], hits[1]]);
pairs.push([hits[2], hits[3]]);
}
for (const [a, b] of pairs) {
const midX = (a.x + b.x) * 0.5;
const midY = (a.y + b.y) * 0.5;
if (!isMaterialAt(midX, midY, notched)) {
continue;
}
positions.push(
a.x, a.y, D / 2 + 0.035,
b.x, b.y, D / 2 + 0.035
);
}
}
}
return positions;
}
function addContourLines(group, notched) {
const levels = [0.16, 0.30, 0.46, 0.62, 0.78];
levels.forEach((level, index) => {
const positions = buildContourSegments(level, notched);
if (!positions.length) return;
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const material = new THREE.LineBasicMaterial({
color: contourColors[index],
transparent: true,
opacity: 0.82,
depthWrite: false,
depthTest: true,
toneMapped: false
});
const lines = new THREE.LineSegments(geometry, material);
lines.renderOrder = 7;
group.add(lines);
});
}
// -------------------------------------------------------------------------
// Procedural microstructures
// -------------------------------------------------------------------------
function addGlassMicrostructure(group, seed) {
const rand = mulberry32(seed);
const micro = new THREE.Group();
for (let i = 0; i < 29; i++) {
let x, y, z;
let attempts = 0;
do {
x = -1.28 + rand() * 2.55;
y = -0.84 + rand() * 1.65;
z = -0.82 + rand() * 1.64;
attempts++;
} while (!isMaterialAt(x, y, false) && attempts < 30);
const bubble = new THREE.Sprite(
new THREE.SpriteMaterial({
map: bubbleTexture,
transparent: true,
opacity: 0.28 + rand() * 0.32,
depthWrite: false,
depthTest: true,
toneMapped: false
})
);
const size = 0.07 + rand() * 0.13;
bubble.scale.set(size, size, size);
bubble.position.set(x, y, z);
bubble.renderOrder = 1;
micro.add(bubble);
}
// Sparse flow-like streaks suggest a continuous amorphous phase.
for (let i = 0; i < 4; i++) {
const points = [];
for (let j = 0; j < 7; j++) {
points.push(
new THREE.Vector3(
-1.2 + j * 0.36 + (rand() - 0.5) * 0.13,
-0.58 + i * 0.36 + (rand() - 0.5) * 0.13,
-0.55 + rand() * 1.1
)
);
}
const curve = new THREE.CatmullRomCurve3(points);
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(55)
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0xa6e9f5,
transparent: true,
opacity: 0.16,
depthWrite: false
})
);
line.renderOrder = 1;
micro.add(line);
}
group.add(micro);
microGroups.push(micro);
}
function addCeramicMicrostructure(group, notched, seed) {
const rand = mulberry32(seed);
const micro = new THREE.Group();
const grainPositions = [];
for (let i = 0; i < 185; i++) {
let x, y;
let attempts = 0;
do {
x = -1.43 + rand() * 2.83;
y = -0.97 + rand() * 1.92;
attempts++;
} while (!isMaterialAt(x, y, notched) && attempts < 30);
grainPositions.push(x, y, D / 2 + 0.021);
}
const grainGeometry = new THREE.BufferGeometry();
grainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(grainPositions, 3)
);
const grains = new THREE.Points(
grainGeometry,
new THREE.PointsMaterial({
color: 0x6d583f,
map: grainTexture,
size: 0.052,
sizeAttenuation: true,
transparent: true,
opacity: 0.72,
alphaTest: 0.04,
depthWrite: false
})
);
grains.renderOrder = 6;
micro.add(grains);
// Dark pores on the exposed section.
for (let i = 0; i < 18; i++) {
let x, y;
let attempts = 0;
do {
x = -1.32 + rand() * 2.58;
y = -0.88 + rand() * 1.72;
attempts++;
} while (!isMaterialAt(x, y, notched) && attempts < 30);
const pore = new THREE.Sprite(
new THREE.SpriteMaterial({
map: poreTexture,
transparent: true,
opacity: 0.70,
depthWrite: false,
toneMapped: false
})
);
const size = 0.045 + rand() * 0.07;
pore.scale.set(size, size, size);
pore.position.set(x, y, D / 2 + 0.034);
pore.renderOrder = 7;
micro.add(pore);
}
// Short grain-boundary-like microcracks.
for (let i = 0; i < 10; i++) {
let x, y;
let attempts = 0;
do {
x = -1.2 + rand() * 2.1;
y = -0.82 + rand() * 1.56;
attempts++;
} while (!isMaterialAt(x, y, notched) && attempts < 30);
const length = 0.08 + rand() * 0.17;
const angle = (rand() - 0.5) * 1.6;
const dx = Math.cos(angle) * length;
const dy = Math.sin(angle) * length;
const points = [
new THREE.Vector3(x, y, D / 2 + 0.042),
new THREE.Vector3(
x + dx * 0.48 + (rand() - 0.5) * 0.025,
y + dy * 0.48,
D / 2 + 0.042
),
new THREE.Vector3(
x + dx,
y + dy,
D / 2 + 0.042
)
];
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0x594738,
transparent: true,
opacity: 0.62,
depthWrite: false
})
);
line.renderOrder = 7;
micro.add(line);
}
// A smooth edge still contains microscopic flaws.
if (!notched) {
const flaw = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-1.485, 0.02, D / 2 + 0.046),
new THREE.Vector3(-1.435, 0.055, D / 2 + 0.046),
new THREE.Vector3(-1.40, 0.025, D / 2 + 0.046)
]),
new THREE.LineBasicMaterial({
color: 0x6e3a33,
transparent: true,
opacity: 0.95
})
);
flaw.renderOrder = 8;
micro.add(flaw);
}
group.add(micro);
microGroups.push(micro);
}
// -------------------------------------------------------------------------
// Illustrative crack paths and initiation markers
// -------------------------------------------------------------------------
function addCrackPath(group, notched) {
const crack = new THREE.Group();
const startX = notched ? -1.075 : -1.475;
const z = D / 2 + 0.065;
const points = [
new THREE.Vector3(startX, 0.0, z),
new THREE.Vector3(startX + 0.18, 0.055, z + 0.006),
new THREE.Vector3(startX + 0.34, -0.075, z + 0.012),
new THREE.Vector3(startX + 0.52, 0.105, z + 0.018),
new THREE.Vector3(startX + 0.72, -0.025, z + 0.024),
new THREE.Vector3(startX + 0.92, 0.06, z + 0.03)
];
const curve = new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.15);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 70, 0.013, 6, false),
new THREE.MeshStandardMaterial({
color: 0x5a151c,
roughness: 0.4,
metalness: 0.05,
emissive: 0x5d1016,
emissiveIntensity: 0.35
})
);
tube.castShadow = true;
tube.renderOrder = 9;
crack.add(tube);
const marker = new THREE.Sprite(
new THREE.SpriteMaterial({
map: markerTexture,
transparent: true,
opacity: 0.95,
depthWrite: false,
depthTest: false,
toneMapped: false
})
);
marker.position.copy(points[0]);
marker.scale.set(0.19, 0.19, 0.19);
marker.renderOrder = 10;
crack.add(marker);
animatedMarkers.push(marker);
group.add(crack);
crackGroups.push(crack);
}
// -------------------------------------------------------------------------
// Labels
// -------------------------------------------------------------------------
const labelLayer = document.getElementById("labels");
function addLabel(text, className, group, localPosition) {
const element = document.createElement("div");
element.className = className;
element.textContent = text;
labelLayer.appendChild(element);
labels.push({
element,
group,
localPosition: localPosition.clone()
});
}
// -------------------------------------------------------------------------
// Build all four specimens
// -------------------------------------------------------------------------
function addTensionArrows(group) {
const arrowColor = 0xb9d5e4;
const leftArrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(-1.66, -0.58, 0.31),
0.56,
arrowColor,
0.15,
0.095
);
const rightArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(1.66, -0.58, 0.31),
0.56,
arrowColor,
0.15,
0.095
);
for (const arrow of [leftArrow, rightArrow]) {
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.75;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.9;
group.add(arrow);
}
}
layout.forEach((config, index) => {
const group = new THREE.Group();
group.position.copy(config.position);
scene.add(group);
group.add(makePlate());
const geometry = makeBlockGeometry(config.notched);
const isGlass = config.material === "glass";
const block = new THREE.Mesh(
geometry,
isGlass
? [glassFaceMaterial, glassSideMaterial]
: [ceramicFaceMaterial, ceramicSideMaterial]
);
block.castShadow = true;
block.receiveShadow = true;
block.renderOrder = isGlass ? 3 : 1;
group.add(block);
const edgeMaterial = new THREE.LineBasicMaterial({
color: isGlass ? 0xa7efff : 0xffedc9,
transparent: true,
opacity: isGlass ? 0.48 : 0.42,
depthWrite: false,
toneMapped: false
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 28),
edgeMaterial
);
edges.renderOrder = 5;
group.add(edges);
const stress = new THREE.Group();
if (isGlass) {
// Transparent slices suggest a field extending through the volume.
[-0.68, -0.08, 0.52].forEach((z, sliceIndex) => {
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(W, H),
makeStressMaterial(config.notched, 0.72 - sliceIndex * 0.12)
);
plane.position.z = z;
plane.renderOrder = 4;
stress.add(plane);
});
}
const frontField = new THREE.Mesh(
new THREE.PlaneGeometry(W, H),
makeStressMaterial(config.notched, isGlass ? 0.78 : 1.0)
);
frontField.position.z = D / 2 + 0.018;
frontField.renderOrder = 8;
stress.add(frontField);
addContourLines(stress, config.notched);
group.add(stress);
stressGroups.push(stress);
if (isGlass) {
addGlassMicrostructure(group, 2200 + index * 71);
} else {
addCeramicMicrostructure(group, config.notched, 4400 + index * 91);
}
addCrackPath(group, config.notched);
addTensionArrows(group);
const materialName = config.material === "glass" ? "Glass" : "Ceramic";
const shapeName = config.notched ? "Notched" : "Smooth";
addLabel(
`${materialName} / ${shapeName}`,
`model-label ${config.material}`,
group,
new THREE.Vector3(0, 1.47, 0)
);
addLabel(
config.notched
? "notch-tip concentration"
: "surface-flaw sensitivity",
"callout",
group,
new THREE.Vector3(
config.notched ? -1.08 : -1.48,
0.44,
D / 2 + 0.13
)
);
});
// -------------------------------------------------------------------------
// Simple camera controls implemented directly, without addons
// -------------------------------------------------------------------------
class SimpleOrbit {
constructor() {
this.target = new THREE.Vector3(-1.0, 0.0, 0.35);
this.desiredTarget = this.target.clone();
this.radius = 16.6;
this.theta = 0.56;
this.phi = 1.10;
this.desiredRadius = this.radius;
this.desiredTheta = this.theta;
this.desiredPhi = this.phi;
this.dragging = false;
this.pointerX = 0;
this.pointerY = 0;
this.autoRotate = true;
this.lastAutoAngle = 0;
this.onPointerDown = this.onPointerDown.bind(this);
this.onPointerMove = this.onPointerMove.bind(this);
this.onPointerUp = this.onPointerUp.bind(this);
this.onWheel = this.onWheel.bind(this);
this.onContextMenu = (event) => event.preventDefault();
renderer.domElement.addEventListener(
"pointerdown",
this.onPointerDown
);
window.addEventListener("pointermove", this.onPointerMove);
window.addEventListener("pointerup", this.onPointerUp);
renderer.domElement.addEventListener("wheel", this.onWheel, {
passive: false
});
renderer.domElement.addEventListener(
"contextmenu",
this.onContextMenu
);
}
onPointerDown(event) {
this.dragging = true;
this.pointerX = event.clientX;
this.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
}
onPointerMove(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.38,
1.43
);
}
onPointerUp(event) {
this.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = "grab";
}
onWheel(event) {
event.preventDefault();
this.desiredRadius = THREE.MathUtils.clamp(
this.desiredRadius * Math.exp(event.deltaY * 0.001),
10.5,
25
);
}
reset() {
this.desiredTarget.set(-1.0, 0, 0.35);
this.desiredRadius = 16.6;
this.desiredTheta = 0.56;
this.desiredPhi = 1.10;
}
update(dt) {
if (this.autoRotate && !this.dragging) {
this.desiredTheta += dt * 0.075;
}
const smoothing = 1 - Math.exp(-dt * 8.0);
this.theta += (this.desiredTheta - this.theta) * smoothing;
this.phi += (this.desiredPhi - this.phi) * smoothing;
this.radius += (this.desiredRadius - this.radius) * smoothing;
this.target.lerp(this.desiredTarget, smoothing);
const sinPhi = Math.sin(this.phi);
camera.position.set(
this.target.x + this.radius * sinPhi * Math.sin(this.theta),
this.target.y + this.radius * Math.cos(this.phi),
this.target.z + this.radius * sinPhi * Math.cos(this.theta)
);
camera.lookAt(this.target);
}
}
const controls = new SimpleOrbit();
renderer.domElement.style.cursor = "grab";
// -------------------------------------------------------------------------
// UI controls
// -------------------------------------------------------------------------
const stressToggle = document.getElementById("stressToggle");
const crackToggle = document.getElementById("crackToggle");
const microToggle = document.getElementById("microToggle");
const orbitToggle = document.getElementById("orbitToggle");
const resetView = document.getElementById("resetView");
stressToggle.addEventListener("change", () => {
stressGroups.forEach(group => group.visible = stressToggle.checked);
});
crackToggle.addEventListener("change", () => {
crackGroups.forEach(group => group.visible = crackToggle.checked);
});
microToggle.addEventListener("change", () => {
microGroups.forEach(group => group.visible = microToggle.checked);
});
orbitToggle.addEventListener("change", () => {
controls.autoRotate = orbitToggle.checked;
});
resetView.addEventListener("click", () => controls.reset());
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
controls.reset();
}
if (event.key.toLowerCase() === "s") {
stressToggle.checked = !stressToggle.checked;
stressToggle.dispatchEvent(new Event("change"));
}
if (event.key.toLowerCase() === "c") {
crackToggle.checked = !crackToggle.checked;
crackToggle.dispatchEvent(new Event("change"));
}
});
// -------------------------------------------------------------------------
// Resize and projected HTML labels
// -------------------------------------------------------------------------
let mobileLayout = window.innerWidth < 900;
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
const nowMobile = width < 900;
if (nowMobile !== mobileLayout) {
mobileLayout = nowMobile;
if (nowMobile) {
controls.desiredTarget.set(0, 0.75, 0.35);
controls.desiredRadius = 18.5;
} else {
controls.desiredTarget.set(-1.0, 0, 0.35);
controls.desiredRadius = 16.6;
}
}
}
window.addEventListener("resize", resize);
resize();
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.localPosition);
label.group.localToWorld(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.style.visibility = visible ? "visible" : "hidden";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
controls.update(dt);
animatedMarkers.forEach((marker, index) => {
const pulse = 1 + Math.sin(elapsed * 3.3 + index * 1.7) * 0.13;
marker.scale.set(0.19 * pulse, 0.19 * pulse, 0.19 * pulse);
marker.material.opacity = 0.78 + Math.sin(elapsed * 3.3 + index) * 0.16;
});
scene.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```