@adatechnology/game-fluids-three

中文文档
0.4.12发布于 2026/11/06MITTypeScriptES Module构建来源已验证近 30 天下载 4886

three.js renderer for @adatechnology/game-fluids: liquid surfaces inside containers, streams with a drop at the tip, puddles that grow from a flow front, wet surfaces that reflect and dry from the edge.

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. API
  4. Running film
  5. Português

@adatechnology/game-fluids-three

three.js renderer for @adatechnology/game-fluids. It only reads the simulation state, so it draws exactly what the deterministic world says (a LAN client with the same state draws the same liquids). three is a peer dependency used for types only: you pass your own THREE instance at runtime.

What it draws:

  • Liquid in containers: inside every bound object, the container's inner shape clipped by the world-space liquid surface, so the top is always on the surface plane whatever the tilt (upright, lying down, upside down). One material per liquid (colour, opacity, roughness from gloss). Steam puffs rise from a hot surface.
  • Streams: a thread along the ballistic path (tube updated in place) that narrows as it accelerates, with a drop that grows at the leading tip and a trailing drop when it ends; thin streams are a sequence of falling drops.
  • Stains: a smooth fan from the 16 flow-front radii (never a perfect disc), lying on the surface plane a hair above it (polygonOffset, oriented by the stain's normal), tinted by the liquid with a soft rim, plus an inner glossy fan at wetRadius that reflects the environment and recedes while it dries. A dried mark is a faint matte patch.
  • Splashes: pooled round droplets (THREE.Points with a small ShaderMaterial, the round sprite is drawn in the fragment shader, no textures).

Lit with the standard material, no transmission, a handful of draw calls, fixed budgets per quality.

Install

pnpm add @adatechnology/game-fluids-three @adatechnology/game-fluids three

Browser without a bundler (the global is GameFluidsThree; it bundles the few game-fluids helpers it calls, you still load GameFluids to create the world):

<script src="https://unpkg.com/three/build/three.min.js"></script>
<script src="https://unpkg.com/@adatechnology/game-fluids/dist/index.global.js"></script>
<script src="https://unpkg.com/@adatechnology/game-fluids-three/dist/index.global.js"></script>
<script>
  const fluids = GameFluids.createFluids({ seed: 1 })
  const view = GameFluidsThree.createFluidRenderer(THREE, { scene, fluids })
</script>

Usage

import * as THREE from 'three'
import { createFluids } from '@adatechnology/game-fluids'
import { createFluidRenderer } from '@adatechnology/game-fluids-three'

const fluids = createFluids({ seed: 7 })
fluids.addSurface({ id: 'floor', point: [0, 0, 0], normal: [0, 1, 0], halfSize: [10, 10], porosity: 0.05 })
fluids.addContainer(
  { capacity: 0.25, liquid: 'coffee', liters: 0.25, temperature: 90, shape: { kind: 'cylinder', radius: 0.04, height: 0.1 }, opening: 0.04 },
  { id: 'cup' },
)

const view = createFluidRenderer(THREE, { scene, fluids, quality: 'medium', envMap })
view.bindContainer('cup', cupObject, { innerOffset: [0, 0.005, 0] }) // inner bottom centre in the object's space

// every frame
const p = cupObject.localToWorld(new THREE.Vector3(0, 0.005, 0)) // world position of the inner bottom centre
fluids.setTransform('cup', [p.x, p.y, p.z], [q.x, q.y, q.z, q.w])
fluids.update(dt)
view.update(dt)

innerOffset is the offset, in the bound object's space, of the origin of the container shape (the inner bottom centre). The transform given to fluids.setTransform must be that point's world position and the object's world rotation. Objects are assumed to have uniform scale.

Destroying a container's object (for example from @adatechnology/game-destruction): call view.unbindContainer(id) and fluids.removeContainer(id); the stains already on the floor stay and dry on their own.

API

createFluidRenderer(THREE, options) returns a FluidRenderer.

Option
sceneWhere the effects are added (one fluid_renderer group)
fluidsThe FluidWorld to draw
quality'low', 'medium' (default) or 'high': sets the mesh resolution and the budgets below
envMapEnvironment map the wet surfaces reflect (otherwise scene.environment if the host set one)
pointScalePixel scale of the point sprites, about half the canvas height (default 600)
Method
bindContainer(containerId, object3D, { innerOffset? })Draw the liquid of a world container inside the object
unbindContainer(containerId)Remove that liquid
update(dt)Advance the visuals; call it after fluids.update(dt)
clear()Remove stains, streams and particles (bindings stay)
dispose()Remove everything from the scene and free geometries and materials
stats(){ quality, containers, streams, stains, particles, triangles, budget }

Budgets: stains 24 / 48 / 96, streams 12 / 24 / 48 and particles 96 / 256 / 512 for low / medium / high. When the world has more stains than the budget, the newest are drawn.

Types exported: FluidRenderer, FluidRendererOptions, FluidRendererStats, BindOptions, FluidQuality, ThreeLib. smoothOutline(front, subdiv) is exported too (the periodic Catmull-Rom used for the stain rim).

Running film

createFilmManager(THREE, options) draws the film of @adatechnology/game-fluids (blood, old blood, bile, motor oil, fuel running down a wall or a floor) over the host's surfaces. The shader is the Fluid Standard's (thickness to colour, normals from the gradient, gloss, bile bubbles, oil and fuel iridescence, cracks where it dried thick); it is drawn transparent, so the host's own surface shows where nothing is wet. The film stays near the player: at most 6 grids of 2 x 2 m (160 x 160 cells), only within 30 m, simulated inside a millisecond budget and uploaded by the dirty rectangle (gpu: pass the WebGLRenderer so copyTextureToTexture can be used). A grid that is out of range, still for 20 s or squeezed out by a newer one is baked into the stain decals of the fluid world (fluids.splash with the film's colours) and freed.

const film = createFilmManager(THREE, { scene, camera, random: createFilmLcg(1), fluids, gpu: renderer })
film.launch({ fluid: 'blood', point: [0, 1.2, 0], velocity: [1, -1, 0], radius: 4 }) // a drop; the grid is made under it
film.drip({ fluid: 'fuel', point: [0, 0.9, 0], every: 0.5 })
const bridge = createFilmBridge({ fluids, manager: film, random })
// every frame: fluids.update(dt); bridge.update(dt); film.update(dt)
bridge.splat({ fluid: 'blood', point, direction, tint: { fresh: 0x8a0a0a, dry: 0x3a1c12 } }) // a wound, in the colours of an infection age
bridge.setWeather({ rain: 1 }) // the rain hook: drying stops, spread x1.5 (a no-op until game-weather drives it)

surfaceAt(point) gives the floor, the wall and the curb of a point (layoutFromSurfaces); without it the film lies on the ground. A leak of a liquid that has a film drips from the hole into it until the stream ends.

Português

Renderizador three.js do @adatechnology/game-fluids: o líquido dentro do recipiente (um volume cortado pelo plano da superfície, sempre horizontal no mundo), fios de líquido com gota na ponta, manchas que crescem a partir de uma frente de fluxo (nunca um disco perfeito), brilho de superfície molhada que reflete o cenário e seca da borda para dentro, vapor e gotas de respingo. Só lê o estado da simulação, então é igual em LAN.

const view = createFluidRenderer(THREE, { scene, fluids, quality: 'medium', envMap })
view.bindContainer('copo', objetoDoCopo, { innerOffset: [0, 0.005, 0] })
// a cada frame: fluids.setTransform(...); fluids.update(dt); view.update(dt)

版本与发布记录

@adatechnology/game-fluids-three 共发布 29 个版本,首次发布于 2026/10/23;过去 12 个月发布了 29 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.12latest2026/11/06今天
0.4.112026/11/041 天前
0.4.102026/11/041 天前
0.4.92026/11/042 天前
0.4.82026/11/042 天前
0.4.72026/11/032 天前

关于 @adatechnology/game-fluids-three 的常见问题

@adatechnology/game-fluids-three 是什么?

three.js renderer for @adatechnology/game-fluids: liquid surfaces inside containers, streams with a drop at the tip, puddles that grow from a flow front, wet surfaces that reflect and dry from the edge.

如何安装 @adatechnology/game-fluids-three?

在项目目录运行 npm install @adatechnology/game-fluids-three,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:three(^0.160.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adatechnology/game-fluids-three 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adatechnology/game-fluids-three 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adatechnology/game-fluids-three 可以商用吗?

@adatechnology/game-fluids-three 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adatechnology/game-fluids-three 的下载量有多少?

根据 npm 官方下载统计,@adatechnology/game-fluids-three 在 2026/10/05 – 2026/11/03 这 30 天内被下载 4,886 次,日均约 163 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adatechnology/game-fluids-three 还在维护吗?

最新版本 0.4.12 发布于 2026/11/06(今天);至今共发布 29 个版本,其中过去 12 个月发布了 29 个;首次发布于 2026/10/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。