Add WebGL cloth and paper materials

This commit is contained in:
2026-06-06 08:03:45 +02:00
parent 13f8b60e20
commit 67c0c4e7e3
2 changed files with 300 additions and 33 deletions
+17 -6
View File
@@ -208,6 +208,7 @@ function createCoverAssemblyGeometry(pageWidth, depth, thickness, spineWidth, co
const uAt = (x) => (x - leftX) / (rightX - leftX || 1);
const vAt = (z) => (z + halfDepth) / depth;
const pointAt = (x, y, z) => ({ x, y, z, u: uAt(x), v: vAt(z) });
const coverProfileXs = section.map((point) => point.x);
const edgeProfile = Array.from({ length: edgeSteps + 1 }, (_, index) => {
const angle = Math.PI * 0.5 - (index / edgeSteps) * Math.PI;
return {
@@ -221,14 +222,24 @@ function createCoverAssemblyGeometry(pageWidth, depth, thickness, spineWidth, co
const cornerRadius = Math.max(0.0001, edgeRadius - inset);
const points = [];
const pushLinear = (fromX, fromZ, toX, toZ, steps) => {
for (let step = 0; step <= steps; step += 1) {
if (points.length && step === 0) continue;
const t = step / steps;
points.push({
x: THREE.MathUtils.lerp(fromX, toX, t),
z: THREE.MathUtils.lerp(fromZ, toZ, t)
const candidates = [];
for (let step = 0; step <= steps; step += 1) candidates.push(step / steps);
if (Math.abs(fromZ - toZ) < 0.000001) {
coverProfileXs.forEach((x) => {
const t = (x - fromX) / (toX - fromX || 1);
if (t > 0 && t < 1) candidates.push(t);
});
}
candidates
.sort((a, b) => a - b)
.forEach((t) => {
if (points.length && Math.abs(t) < 0.000001) return;
const x = THREE.MathUtils.lerp(fromX, toX, t);
const z = THREE.MathUtils.lerp(fromZ, toZ, t);
const previous = points[points.length - 1];
if (previous && Math.hypot(previous.x - x, previous.z - z) < 0.000001) return;
points.push({ x, z });
});
};
const pushCorner = (centerX, centerZ, fromAngle, toAngle) => {
for (let step = 1; step <= cornerSteps; step += 1) {