Mike0021's picture
Publish Phase A cleared procedural Three.js 3D scenes dataset (26 rows with validated GLBs, renders, code, and scrubbed traces)
59c7fd7 verified
Raw History Blame Contribute Delete
10.3 kB
import * as THREE from 'three';
/* ---------- tiny deterministic RNG ---------- */
function rng(seed) {
let a = seed >>> 0;
return function () {
a |= 0; a = (a + 0x6D2B79F5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function cv(size = 512) {
const c = document.createElement('canvas');
c.width = c.height = size;
return c;
}
function tex(canvas, srgb = true, repeat = [1, 1], aniso = 8) {
const t = new THREE.CanvasTexture(canvas);
t.wrapS = t.wrapT = THREE.RepeatWrapping;
t.repeat.set(repeat[0], repeat[1]);
t.anisotropy = aniso;
if (srgb) t.colorSpace = THREE.SRGBColorSpace;
return t;
}
function rgba(hex, a) {
const c = new THREE.Color(hex);
return `rgba(${Math.round(c.r * 255)},${Math.round(c.g * 255)},${Math.round(c.b * 255)},${a})`;
}
/* ---------- wood ---------- */
export function makeWood({
base = '#8a5a32', dark = '#4a2b15', light = '#c19460',
seed = 3, size = 512, repeat = [1, 1], knots = 5, grainFreq = 0.012,
} = {}) {
const rand = rng(seed);
const alb = cv(size), bmp = cv(size), rgh = cv(size);
const a = alb.getContext('2d'), b = bmp.getContext('2d'), r = rgh.getContext('2d');
a.fillStyle = base; a.fillRect(0, 0, size, size);
b.fillStyle = '#7f7f7f'; b.fillRect(0, 0, size, size);
r.fillStyle = '#a8a8a8'; r.fillRect(0, 0, size, size);
// wide tonal planks / colour variation
for (let i = 0; i < 16; i++) {
const y = rand() * size, h = 20 + rand() * 90;
const g = a.createLinearGradient(0, y, 0, y + h);
const col = rand() > 0.5 ? light : dark;
g.addColorStop(0, rgba(col, 0));
g.addColorStop(0.5, rgba(col, 0.05 + rand() * 0.09));
g.addColorStop(1, rgba(col, 0));
a.fillStyle = g; a.fillRect(0, y, size, h);
}
// long grain strokes
const strokes = Math.round(size * 1.15);
for (let i = 0; i < strokes; i++) {
const y = rand() * size;
const amp = 1 + rand() * 8;
const freq = grainFreq * (0.5 + rand() * 1.5);
const phase = rand() * Math.PI * 2;
const drift = (rand() - 0.5) * 0.02;
const col = rand() > 0.42 ? dark : light;
const alpha = 0.025 + rand() * 0.11;
const w = 0.4 + rand() * 1.7;
a.beginPath(); b.beginPath();
for (let x = 0; x <= size; x += 8) {
const yy = y + Math.sin(x * freq + phase) * amp + x * drift;
if (x === 0) { a.moveTo(x, yy); b.moveTo(x, yy); }
else { a.lineTo(x, yy); b.lineTo(x, yy); }
}
a.strokeStyle = rgba(col, alpha); a.lineWidth = w; a.stroke();
const gv = Math.round(105 + rand() * 60);
b.strokeStyle = `rgba(${gv},${gv},${gv},${0.25 + rand() * 0.3})`;
b.lineWidth = w; b.stroke();
// roughness variation
r.beginPath();
for (let x = 0; x <= size; x += 16) {
const yy = y + Math.sin(x * freq + phase) * amp + x * drift;
if (x === 0) r.moveTo(x, yy); else r.lineTo(x, yy);
}
const rv = Math.round(150 + rand() * 70);
r.strokeStyle = `rgba(${rv},${rv},${rv},0.18)`; r.lineWidth = w * 2; r.stroke();
}
// knots
for (let k = 0; k < knots; k++) {
const kx = rand() * size, ky = rand() * size;
const kr = 8 + rand() * 30;
for (let ring = 0; ring < 8; ring++) {
const rr = kr * (1 - ring / 10);
a.beginPath();
a.ellipse(kx + ring * 1.5, ky, rr, rr * (0.3 + rand() * 0.15), 0.1, 0, Math.PI * 2);
a.strokeStyle = rgba(dark, 0.12 + ring * 0.03);
a.lineWidth = 1.1 + rand() * 2.2;
a.stroke();
b.beginPath();
b.ellipse(kx + ring * 1.5, ky, rr, rr * (0.3 + rand() * 0.15), 0.1, 0, Math.PI * 2);
b.strokeStyle = `rgba(70,70,70,${0.2 + ring * 0.03})`; b.lineWidth = 1.5; b.stroke();
}
a.beginPath(); a.ellipse(kx, ky, kr * 0.28, kr * 0.22, 0.1, 0, Math.PI * 2);
a.fillStyle = rgba(dark, 0.4); a.fill();
}
// fine pores / speckle
for (let i = 0; i < size * 2; i++) {
const x = rand() * size, y = rand() * size;
a.fillStyle = rgba(rand() > 0.5 ? dark : light, 0.03 + rand() * 0.08);
a.fillRect(x, y, 1 + rand() * 5, 0.6 + rand() * 1.2);
}
// subtle weathering patches
for (let i = 0; i < 12; i++) {
const x = rand() * size, y = rand() * size, rad = 30 + rand() * 110;
const g = a.createRadialGradient(x, y, 0, x, y, rad);
g.addColorStop(0, 'rgba(40,32,24,0.10)');
g.addColorStop(1, 'rgba(40,32,24,0)');
a.fillStyle = g; a.fillRect(x - rad, y - rad, rad * 2, rad * 2);
}
return {
map: tex(alb, true, repeat),
bumpMap: tex(bmp, false, repeat),
roughnessMap: tex(rgh, false, repeat),
};
}
/* ---------- metal ---------- */
export function makeMetal({
base = '#9aa0a4', seed = 7, size = 256, repeat = [1, 1], brushed = true,
} = {}) {
const rand = rng(seed);
const alb = cv(size), bmp = cv(size), rgh = cv(size);
const a = alb.getContext('2d'), b = bmp.getContext('2d'), r = rgh.getContext('2d');
a.fillStyle = base; a.fillRect(0, 0, size, size);
b.fillStyle = '#808080'; b.fillRect(0, 0, size, size);
r.fillStyle = '#707070'; r.fillRect(0, 0, size, size);
for (let i = 0; i < size * 4; i++) {
const x = rand() * size, y = rand() * size;
const v = Math.round(60 + rand() * 170);
a.fillStyle = `rgba(${v},${v},${v},${0.05 + rand() * 0.12})`;
if (brushed) a.fillRect(x, y, 6 + rand() * 40, 0.7);
else a.fillRect(x, y, 1 + rand() * 2, 1 + rand() * 2);
b.fillStyle = `rgba(${v},${v},${v},0.15)`;
b.fillRect(x, y, brushed ? 10 + rand() * 40 : 1.5, brushed ? 0.8 : 1.5);
}
// patina blotches
for (let i = 0; i < 24; i++) {
const x = rand() * size, y = rand() * size, rad = 4 + rand() * 25;
const g = a.createRadialGradient(x, y, 0, x, y, rad);
g.addColorStop(0, `rgba(70,60,48,${0.04 + rand() * 0.12})`);
g.addColorStop(1, 'rgba(70,60,48,0)');
a.fillStyle = g; a.fillRect(x - rad, y - rad, rad * 2, rad * 2);
}
return {
map: tex(alb, true, repeat),
bumpMap: tex(bmp, false, repeat),
roughnessMap: tex(rgh, false, repeat),
};
}
/* ---------- concrete / stone floor ---------- */
export function makeConcrete({ seed = 11, size = 512, repeat = [1, 1] } = {}) {
const rand = rng(seed);
const alb = cv(size), bmp = cv(size), rgh = cv(size);
const a = alb.getContext('2d'), b = bmp.getContext('2d'), r = rgh.getContext('2d');
a.fillStyle = '#77726a'; a.fillRect(0, 0, size, size);
b.fillStyle = '#808080'; b.fillRect(0, 0, size, size);
r.fillStyle = '#bdbdbd'; r.fillRect(0, 0, size, size);
for (let i = 0; i < 1500; i++) {
const x = rand() * size, y = rand() * size, rad = 1 + rand() * 18;
const v = rand();
const col = v > 0.5 ? '30,28,24' : '212,205,190';
const g = a.createRadialGradient(x, y, 0, x, y, rad);
g.addColorStop(0, `rgba(${col},${0.03 + rand() * 0.14})`);
g.addColorStop(1, `rgba(${col},0)`);
a.fillStyle = g; a.fillRect(x - rad, y - rad, rad * 2, rad * 2);
const gv = Math.round(90 + rand() * 90);
b.fillStyle = `rgba(${gv},${gv},${gv},0.12)`;
b.fillRect(x, y, rad * 0.6, rad * 0.6);
}
for (let i = 0; i < 1300; i++) {
const x = rand() * size, y = rand() * size;
a.fillStyle = `rgba(${rand() > 0.5 ? '20,18,16' : '230,225,210'},${0.05 + rand() * 0.12})`;
a.fillRect(x, y, 1 + rand() * 2, 1 + rand() * 2);
}
// cracks
for (let c = 0; c < 5; c++) {
let x = rand() * size, y = rand() * size;
a.beginPath(); a.moveTo(x, y); b.beginPath(); b.moveTo(x, y);
for (let s = 0; s < 26; s++) {
x += (rand() - 0.5) * 34; y += (rand() - 0.5) * 34;
a.lineTo(x, y); b.lineTo(x, y);
}
a.strokeStyle = 'rgba(28,25,22,0.35)'; a.lineWidth = 1 + rand() * 1.2; a.stroke();
b.strokeStyle = 'rgba(40,40,40,0.5)'; b.lineWidth = 2; b.stroke();
}
return {
map: tex(alb, true, repeat),
bumpMap: tex(bmp, false, repeat),
roughnessMap: tex(rgh, false, repeat),
};
}
/* ---------- rough sawn end grain ---------- */
export function makeEndGrain({ base = '#9a6b3d', seed = 21, size = 512 } = {}) {
const rand = rng(seed);
const alb = cv(size), bmp = cv(size);
const a = alb.getContext('2d'), b = bmp.getContext('2d');
a.fillStyle = base; a.fillRect(0, 0, size, size);
b.fillStyle = '#7a7a7a'; b.fillRect(0, 0, size, size);
for (let i = 0; i < 700; i++) {
const x = rand() * size, y = rand() * size;
const rr = 2 + rand() * 22;
a.beginPath(); a.ellipse(x, y, rr, rr * (0.4 + rand() * 0.6), rand() * 3, 0, Math.PI * 2);
a.strokeStyle = rgba('#4d3017', 0.05 + rand() * 0.15);
a.lineWidth = 0.7 + rand() * 1.6; a.stroke();
b.beginPath(); b.ellipse(x, y, rr, rr * 0.6, 0, 0, Math.PI * 2);
b.strokeStyle = 'rgba(90,90,90,0.2)'; b.lineWidth = 1.2; b.stroke();
}
return { map: tex(alb), bumpMap: tex(bmp, false) };
}
/* ---------- window sky gradient ---------- */
export function makeWindowGlow() {
const size = 512;
const c = cv(size); const g = c.getContext('2d');
const grad = g.createLinearGradient(0, 0, 0, size);
grad.addColorStop(0, '#cfe3ef');
grad.addColorStop(0.45, '#f4e8c9');
grad.addColorStop(0.72, '#f8d79c');
grad.addColorStop(1, '#d8a86a');
g.fillStyle = grad; g.fillRect(0, 0, size, size);
// soft distant trees / haze
const r = rng(4);
for (let i = 0; i < 18; i++) {
const x = r() * size, y = size * (0.55 + r() * 0.2), rad = 40 + r() * 110;
const gg = g.createRadialGradient(x, y, 0, x, y, rad);
gg.addColorStop(0, `rgba(95,96,62,${0.06 + r() * 0.1})`);
gg.addColorStop(1, 'rgba(95,96,62,0)');
g.fillStyle = gg; g.fillRect(x - rad, y - rad, rad * 2, rad * 2);
}
return tex(c, true, [1, 1]);
}
/* ---------- cloth / canvas ---------- */
export function makeCanvasCloth({ base = '#c8b58f', seed = 33, size = 256, repeat = [1, 1] } = {}) {
const rand = rng(seed);
const c = cv(size); const g = c.getContext('2d');
g.fillStyle = base; g.fillRect(0, 0, size, size);
for (let y = 0; y < size; y += 2) {
g.fillStyle = `rgba(${rand() > 0.5 ? '255,250,235' : '70,55,35'},${0.04 + rand() * 0.05})`;
g.fillRect(0, y, size, 1);
}
for (let x = 0; x < size; x += 2) {
g.fillStyle = `rgba(${rand() > 0.5 ? '255,250,235' : '60,48,30'},${0.03 + rand() * 0.05})`;
g.fillRect(x, 0, 1, size);
}
return { map: tex(c, true, repeat) };
}