Metaballs
初出 1982 · Jim Blinn — Jim Blinn, "blobby" implicit surfaces (1982). · 年表 ↗
コミュニティ・通称 名称 — Blinn 自身の 1982 年の用語は「blobby model」。「メタボール」は同じ陰関数曲面技法に対する 後発のコミュニティ名で、人名エポニムではない。
ひとことで 陰関数の重ね合わせで滑らかな blob 状の形状を作る手法。多くは marching-squares で輪郭化される。
コード
上のデモの実際のスケッチ(サンドボックスで再現可能)。これで全部です。
metaballs/index.html
const SEED = Math.floor(Math.random()*1e9);
// Animated metaballs: sum of inverse-square fields from moving charges,
// thresholded into glowing blobs. Rendered at low res for speed.
const R = 200;
let balls = [];
function setup() {
randomSeed(SEED);
const s = Math.min(windowWidth, windowHeight);
pixelDensity(1);
const cnv = createCanvas(R, R);
cnv.elt.style.width = s + 'px';
cnv.elt.style.height = s + 'px';
cnv.elt.style.imageRendering = 'auto';
const n = 5 + Math.floor(random(4));
for (let i = 0; i < n; i++) {
balls.push({ x: random(R), y: random(R), vx: random(-1,1), vy: random(-1,1), r: random(18, 34) });
}
}
function draw() {
for (const b of balls) {
b.x += b.vx; b.y += b.vy;
if (b.x < 0 || b.x > R) b.vx *= -1;
if (b.y < 0 || b.y > R) b.vy *= -1;
}
loadPixels();
for (let y = 0; y < R; y++) {
for (let x = 0; x < R; x++) {
let sum = 0;
for (const b of balls) {
const dx = x - b.x, dy = y - b.y;
sum += (b.r * b.r) / (dx*dx + dy*dy + 1);
}
const idx = 4 * (y * R + x);
// colour ramp by field strength
const v = Math.min(1, sum);
let r, g, bl;
if (v < 1) { r = v*20; g = v*30; bl = v*60; }
else {
const t = Math.min(1, (sum - 1) * 0.5);
r = 40 + t*215; g = 60 + t*120; bl = 120 + t*100;
}
pixels[idx]=r; pixels[idx+1]=g; pixels[idx+2]=bl; pixels[idx+3]=255;
}
}
updatePixels();
}仕組み
各「ボール」に中心近傍で高く距離で減衰する関数(例 f(p)=r²/|p−中心|²、Blinn はガウシアン)を与え、(1) 各標本点で全ボールの寄与を 1 つのスカラー場に合算、(2) 閾値(等値)を選び合計がそれを超える点を「内側」とし、(3) その等値輪郭を抽出(2D は marching-squares、3D は marching-cubes)して融合した輪郭/曲面を得る。場が加算されるため近づく 2 球は膨らんで 1 つの滑らかな形に融合し、中心を動かすと融合がアニメートする。
パラメータ
ballCount: number — Number of charge points contributing to the scalar field.threshold: number — Iso-value at which the blended surface is drawn.falloff: number — How quickly each ball's influence decays with distance.
系譜
よく組み合わされるアルゴリズム
- Marching Squares / Contours · 1 作品
このアルゴリズムを使う作品 (1)
最終更新 2026-07-16