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
6.86 kB
import * as THREE from 'three';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import { makeParquet, makeSkyTexture, makeDustTexture, rng } from './textures.js';
function radialShadowTexture() {
const c = document.createElement('canvas');
c.width = c.height = 512;
const ctx = c.getContext('2d');
const g = ctx.createRadialGradient(256, 256, 0, 256, 256, 256);
g.addColorStop(0, 'rgba(0,0,0,0.55)');
g.addColorStop(0.45, 'rgba(0,0,0,0.28)');
g.addColorStop(1, 'rgba(0,0,0,0)');
ctx.fillStyle = g;
ctx.fillRect(0, 0, 512, 512);
const t = new THREE.CanvasTexture(c);
t.colorSpace = THREE.SRGBColorSpace;
return t;
}
export function buildEnvironment(scene, renderer, camera) {
const parquet = makeParquet({ seed: 77 });
for (const t of [parquet.map, parquet.bumpMap, parquet.roughnessMap]) t.repeat.set(10, 10);
parquet.map.anisotropy = parquet.bumpMap.anisotropy = 16;
const floorMat = new THREE.MeshPhysicalMaterial({
map: parquet.map,
bumpMap: parquet.bumpMap,
bumpScale: 0.012,
roughnessMap: parquet.roughnessMap,
roughness: 0.62,
metalness: 0.0,
clearcoat: 0.16,
clearcoatRoughness: 0.6,
envMapIntensity: 0.35,
});
const floor = new THREE.Mesh(new THREE.PlaneGeometry(44, 44, 1, 1), floorMat);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
// soft contact shading beneath the group (pure lighting trick, not geometry)
const contact = new THREE.Mesh(
new THREE.PlaneGeometry(2.9, 2.4),
new THREE.MeshBasicMaterial({
map: radialShadowTexture(), transparent: true, opacity: 0.42,
depthWrite: false, blending: THREE.NormalBlending,
}),
);
contact.rotation.x = -Math.PI / 2;
contact.position.set(0.2, 0.004, 0.03);
contact.renderOrder = 1;
scene.add(contact);
const blobTex = radialShadowTexture();
const blobMat = new THREE.MeshBasicMaterial({ map: blobTex, transparent: true, opacity: 0.5, depthWrite: false });
for (const [x, z, sx, sz] of [[-0.74, 0.10, 0.95, 0.95], [0.30, 0.60, 0.95, 0.80], [1.26, -0.50, 0.78, 0.60]]) {
const blob = new THREE.Mesh(new THREE.PlaneGeometry(1, 1), blobMat);
blob.rotation.x = -Math.PI / 2;
blob.position.set(x, 0.006, z);
blob.scale.set(sx, sz, 1);
blob.renderOrder = 2;
scene.add(blob);
}
// sky dome
const dome = new THREE.Mesh(
new THREE.SphereGeometry(55, 56, 36),
new THREE.MeshBasicMaterial({ map: makeSkyTexture(), side: THREE.BackSide, fog: false, depthWrite: false }),
);
scene.add(dome);
scene.fog = new THREE.FogExp2(0x20140d, 0.05);
// ---- lighting rig ----
const hemi = new THREE.HemisphereLight(0x9c7b52, 0x170e08, 0.40);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffe0b5, 2.9);
key.position.set(3.1, 4.9, 2.6);
key.target.position.set(-0.1, 0.8, 0);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -3.4;
key.shadow.camera.right = 3.4;
key.shadow.camera.top = 3.6;
key.shadow.camera.bottom = -2.4;
key.shadow.camera.near = 0.6;
key.shadow.camera.far = 13;
key.shadow.bias = -0.00035;
key.shadow.normalBias = 0.022;
key.shadow.radius = 3.5;
scene.add(key);
scene.add(key.target);
const fill = new THREE.DirectionalLight(0x88b0dc, 0.9);
fill.position.set(-4.2, 2.4, 2.2);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffb26c, 1.7);
rim.position.set(-0.8, 3.0, -4.2);
scene.add(rim);
const windowPool = new THREE.SpotLight(0xffc987, 13, 9, 0.6, 0.8, 1.4);
windowPool.position.set(2.4, 3.6, 1.8);
windowPool.target.position.set(-0.2, 0.2, 0);
scene.add(windowPool);
scene.add(windowPool.target);
// ---- environment reflections ----
const pmrem = new THREE.PMREMGenerator(renderer);
const envRT = pmrem.fromScene(new RoomEnvironment(), 0.04);
scene.environment = envRT.texture;
scene.environmentIntensity = 0.42;
// ---- distant lit windows for atmosphere (well clear of orbit cameras) ----
const windowTex = (() => {
const c = document.createElement('canvas'); c.width = 512; c.height = 1024;
const ctx = c.getContext('2d');
const g = ctx.createLinearGradient(0, 0, 0, 1024);
g.addColorStop(0, 'rgba(255,196,120,0.55)');
g.addColorStop(0.45, 'rgba(255,205,140,0.85)');
g.addColorStop(0.8, 'rgba(255,220,165,0.65)');
g.addColorStop(1, 'rgba(255,190,120,0.25)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.moveTo(40, 1024); ctx.lineTo(40, 360);
ctx.arc(256, 360, 216, Math.PI, 0);
ctx.lineTo(472, 1024); ctx.closePath(); ctx.fill();
ctx.globalCompositeOperation = 'destination-out';
for (let y = 220; y < 1024; y += 150) { ctx.fillRect(48, y, 416, 12); }
ctx.fillRect(248, 140, 14, 884);
ctx.globalCompositeOperation = 'source-over';
ctx.strokeStyle = 'rgba(20,12,6,0.9)'; ctx.lineWidth = 22;
ctx.beginPath(); ctx.moveTo(40, 1024); ctx.lineTo(40, 360);
ctx.arc(256, 360, 216, Math.PI, 0); ctx.lineTo(472, 1024); ctx.stroke();
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace;
return t;
})();
const winMat = new THREE.MeshBasicMaterial({ map: windowTex, transparent: true, opacity: 0.5, depthWrite: false, fog: false, color: 0xdfe8f2 });
for (const [x, y, z, ry, sc] of [[-8.5, 3.3, -14, 0.34, 0.86], [6.4, 2.8, -13.5, -0.28, 0.72]]) {
const win = new THREE.Mesh(new THREE.PlaneGeometry(4.4, 8.8), winMat);
win.position.set(x, y, z); win.rotation.y = ry; win.scale.setScalar(sc);
scene.add(win);
}
// ---- floating dust ----
const r = rng(5);
const COUNT = 260;
const pos = new Float32Array(COUNT * 3);
const seeds = new Float32Array(COUNT);
for (let i = 0; i < COUNT; i++) {
const a = r() * Math.PI * 2;
const rad = Math.sqrt(r()) * 2.6;
pos[i * 3] = Math.cos(a) * rad + 0.15;
pos[i * 3 + 1] = 0.15 + r() * 2.6;
pos[i * 3 + 2] = Math.sin(a) * rad * 0.85;
seeds[i] = r() * 100;
}
const dustGeo = new THREE.BufferGeometry();
dustGeo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
const dust = new THREE.Points(dustGeo, new THREE.PointsMaterial({
map: makeDustTexture(), size: 0.021, transparent: true, opacity: 0.42,
depthWrite: false, blending: THREE.AdditiveBlending, sizeAttenuation: true,
color: 0xffd9a8,
}));
dust.frustumCulled = false;
scene.add(dust);
return {
floor, dust, key,
update(t) {
const p = dustGeo.attributes.position;
for (let i = 0; i < COUNT; i++) {
const s = seeds[i];
p.array[i * 3] += Math.sin(t * 0.21 + s) * 0.00055;
p.array[i * 3 + 1] += 0.00045 + Math.sin(t * 0.13 + s * 2.1) * 0.00035;
if (p.array[i * 3 + 1] > 2.9) p.array[i * 3 + 1] = 0.1;
}
p.needsUpdate = true;
dust.rotation.y = Math.sin(t * 0.03) * 0.02;
},
};
}