npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@web-3d/three

v1.0.0

Published

web3d 系列工具库的 Three.js 引擎适配层

Readme

@web-3d/three

@web-3d/three 是 web3d 纯数据与计算库的 Three.js 适配层,负责把通用几何和图模型转换为 BufferGeometry、Mesh 与可编辑场景对象。

功能

  • 把 GeometryData、带状几何和管道几何转换为 Three.js BufferGeometry。
  • 原位更新 attribute 和 index,支持按需计算包围盒与包围球。
  • 使用 BandPlugin、PipePlugin 渲染 @web-3d/graph 中的边和节点。
  • 处理二度转角、多分支条带填充和空间管道节点。
  • 使用 createThreeGraphEditor 组合图模型、Three.js 视图和交互编辑器。
  • 通过 Signal 依赖跟踪增量重建受影响的几何体。

安装

pnpm add @web-3d/three @web-3d/geometry @web-3d/graph @web-3d/inter-draw @three3d/inter-draw three

three 是 peer dependency,应由应用统一提供。

模块

| 入口 | 职责 | | --- | --- | | @web-3d/three/geometry | 几何数据到 BufferGeometry 的转换与更新 | | @web-3d/three/renderer | 图的带状、管道渲染插件 | | @web-3d/three/graph-editor | Three.js 图编辑器集成 |

本包只负责 Three.js 对象与生命周期。曲线、扫掠和节点拼接算法保留在 @web-3d/tools、@web-3d/geometry;图拓扑和变更事件保留在 @web-3d/graph。

条带图渲染插件

使用 BandPlugin 可以把 @web-3d/graph 中的每条边渲染为 Three.js 条带。插件会先生成全部边,再统一处理节点:二度节点使用独立转角连接两条边,三个及以上分支可以使用直边中心填充、三顶点直接汇聚或相切圆弧填充。节点位置或边曲线变化后,相关结果会在同一轮重建。

import { GraphRenderer } from '@web-3d/graph';
import { BandPlugin, PipePlugin } from '@web-3d/three';

const renderer = new GraphRenderer(graph, { scene });
const bandPlugin = new BandPlugin();
renderer.install(bandPlugin, {
  section: {
    leftRadius: 0.5,
    rightRadius: 1,
  },
  uv: { u: 'normalized', v: 'normalized' },
  node: {
    mode: 'fill',
    round: { radius: 2, divisions: 12 },
    corner: { type: 'round', size: 1, divisions: 8 },
  },
  // 边和节点也可以从各自的数据中提供局部配置。
  getEdgeOptions: (edge) => edge.data.band,
  getNodeOptions: (node) => node.data.band,
});

BandPlugin 和 PipePlugin 都是对象式插件,需要先创建实例。它们公开边与节点参数解析、材质解析、统一重建及重建完成后的扩展点;道路等业务插件可以继承对应类,只重写所需方法。一个实例同一时间只能安装到一个宿主,卸载后可以再次安装;需要同时渲染多套结果时创建多个实例。

条带节点的 mode 支持:

  • fill:多分支节点生成独立中心填充体,是默认方式;
  • direct:三顶点多分支条带直接汇聚;双顶点多分支会忽略该选择并继续填充;
  • round:双顶点或三顶点多分支使用与相邻边界相切的圆弧,生成圆滑中心填充体;
  • none:保留各边未经节点连接的端部。

除 mode: 'none' 外,二度节点始终进入独立的转角流程,不会调用多分支拼接算法。corner.type 支持 bevel、chamfer、round、hermite 和 none,分别表示斜接、平直倒角、圆角、Hermite 转角和不处理转角;非斜接转角会生成独立连接体。corner.size 控制二度转角尺寸,corner.divisions 控制圆角与 Hermite 转角的细分数。多分支圆滑式单独使用 round.radius 和 round.divisions,不与二度节点的 corner 参数混用。

节点几何算法由 web3d-geometry 的 joinBandNodeInPlace、joinPipeNodeInPlace 和 trimSweepGeometry 统一完成。本包中的图插件只收集节点相邻端、传入配置、汇总一条边两端的裁切请求,并负责把返回的几何数据转换为 Three.js 对象;圆角路径、边界截面、空间排序和多分支裁切均不在渲染层实现。条带的填充式与圆滑式多分支节点会把拼接端面落实到路径内部的截面环,裁掉节点侧的原条带后再渲染独立填充体,二者不会共面覆盖。

多分支节点的 miterLimit 控制尖角切线投影相对于相邻条带最大半宽的限制倍数,必须不小于 1,默认值为 4。任一侧投影超限时,两侧边界点会分别沿自己的切线截断,并在两个截断点之间生成平直填充,避免近共线方向产生过长尖角或在节点上留下固定断面。trimRings 只限制直接式斜切传播的截面环数,不参与斜接限制判定;填充式和圆滑式会按实际拼接边界裁掉已经跨过的截面环。direct 模式只在退化扇区生成附加填充体。

节点选项中的 connectorUV 可以单独指定二度转角连接体的 UV,未设置时跟随边条带。节点和边使用不同纹理材质时,通常应为连接体设置 { u: 'normalized', v: 'normalized' }。

PipePlugin 使用相同的数据驱动结构。它不会生成管道中心填充体,只负责用节点裁切面处理转角和分支端部:

const pipePlugin = new PipePlugin();
renderer.install(pipePlugin, {
  section: { radius: 0.4, shape: circleShape(16) },
  node: {
    mode: 'spatial',
    corner: { type: 'round', size: 1, divisions: 8 },
  },
  getEdgeOptions: (edge) => edge.data.pipe,
  getNodeOptions: (node) => node.data.pipe,
});

管道二度节点使用与条带相同的转角选项。三个及以上分支默认使用 spatial,适合任意三维分布;共面多分支可选 ring,不需要任何节点处理时使用 none 或让 getNodeOptions 返回 false。

配置回调在响应式重建任务中执行;如果 data 中保存的是 alien-signals 信号并在回调里读取,信号变化会直接触发几何体重建。

运行 pnpm demo:graph-plugins 可以在同一份可编辑图上独立开关管道和条带插件;运行 pnpm demo:band-road 可以绘制、编辑双向道路及其曲线控制点,左右半带分别表示一个行车方向;运行 pnpm demo:band-graph 或 pnpm demo:pipe-graph 可以打开通用交互图示例,在 GUI 中切换节点转角类型并调整尺寸、细分数和 Hermite 张力。

运行 pnpm demo:test 可以启动完整的图渲染人工验收页面;运行 pnpm demo:test:build 会生成可直接交付测试人员的单文件 HTML。

图编辑器坐标解析

createThreeGraphEditor 可以直接接收有序的 pointResolvers。固定高度平面不需要创建透明 Three.js Mesh:

import { createThreeGraphEditor, PlanePointResolver } from '@web-3d/three';

const integration = createThreeGraphEditor({
  element: renderer.domElement,
  camera,
  scene,
  graph,
  pointResolvers: [
    new PlanePointResolver({
      normal: [0, 1, 0],
      point: [0, 8, 0],
    }),
  ],
});

不传 pointResolvers 时仍默认使用 RayPickAdapter 的实际拾取结果,并由 pickedObjects 指定参与求交的对象。需要降级时,可以把 AdapterPointResolver 放在固定平面解析器之前;数组中首个成功的解析结果生效。

开发

pnpm test
pnpm typecheck
pnpm build
pnpm demo:graph-plugins
pnpm demo:band-road
pnpm demo:test
pnpm demo:test:build
pnpm apidoc

几何与节点拼接修改应同时验证条带、管道和道路示例;图编辑器修改应验证拾取、拖动、固定平面坐标解析以及资源销毁。

作者:郭斌勇 · 微信:keyanzhe · 邮箱:[email protected]