Repository Public
1<!-- Démonstration 3D du kit 3 : surface mathématique z = f(x, y) en WebGL (Three.js), orbite de caméra par images clés, étiquette HTML par-dessus. -->2<div class="scene" data-bg="theme">3 <div class="sk-ui"><div class="sk-safe top left"><p class="sk-kicker" data-in="rise" data-at="0.2">Surface</p><h1 class="sk-title sm" data-in="rise" data-at="0.4">Descendre la <em>pente</em></h1></div></div>4</div>5<script>6SK.three(function (c) {7 var T = c.THREE, n = 70, f = function (x, y) { return 0.9 * Math.sin(x * 0.9) * Math.cos(y * 0.9) + 0.06 * (x * x + y * y); };8 var g = new T.PlaneGeometry(8, 8, n, n), pos = g.attributes.position, col = [], lo = new T.Color(c.color("var(--s)")), hi = new T.Color(c.color("var(--gold)"));9 for (var i = 0; i < pos.count; i++) { var z = f(pos.getX(i), pos.getY(i)); pos.setZ(i, z); var k = Math.min(1, Math.max(0, (z + 0.9) / 3)), cc = lo.clone().lerp(hi, k); col.push(cc.r, cc.g, cc.b); }10 g.setAttribute("color", new T.Float32BufferAttribute(col, 3)); g.computeVertexNormals();11 var mesh = new T.Mesh(g, new T.MeshStandardMaterial({ vertexColors: true, roughness: 0.55, metalness: 0.1, side: T.DoubleSide, flatShading: false }));12 var wire = new T.LineSegments(new T.WireframeGeometry(g), new T.LineBasicMaterial({ color: 0xffffff, transparent: true, opacity: 0.08 }));13 var grp = new T.Group(); grp.add(mesh, wire); grp.rotation.x = -Math.PI / 2; c.scene.add(grp); c.lights(1);14 var ball = new T.Mesh(new T.SphereGeometry(0.16, 32, 16), new T.MeshStandardMaterial({ color: c.color("var(--gold)"), emissive: c.color("var(--gold)"), emissiveIntensity: 0.6 })); grp.add(ball);15 var path = SKN && SKN.gradientDescent ? null : null, x = 3.1, y = 2.6, pts = [];16 for (var s = 0; s < 220; s++) { var h = 1e-3, gx = (f(x + h, y) - f(x - h, y)) / (2 * h), gy = (f(x, y + h) - f(x, y - h)) / (2 * h); pts.push([x, y, f(x, y)]); x -= 0.04 * gx; y -= 0.04 * gy; }17 c.onFrame(function (t) { var u = SK.E.inout(SK.clamp01((t - SK.T("@descente")) / 3.2)), i = Math.min(pts.length - 1, Math.floor(u * (pts.length - 1))), p = pts[i]; ball.position.set(p[0], p[1], p[2] + 0.16); mesh.scale.z = wire.scale.z = SK.E.out(SK.clamp01(t / 1.2)); });18 c.orbit({ target: [0, 0.3, 0], keys: [{ at: 0, yaw: -35, pitch: 28, dist: 15 }, { at: "@descente", yaw: 10, pitch: 34, dist: 12.5 }, { at: "end", yaw: 55, pitch: 24, dist: 11, ease: "glide" }] });19});20</script>21