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 🙏

© 2025 – Pkg Stats / Ryan Hefner

b3dm

v0.1.1

Published

A TypeScript library for parsing and building B3DM (Batched 3D Model) files

Readme

b3dm

b3dm 是一个用于构建和解析 B3DM 格式文件的 TypeScript 库。B3DM 是 Cesium 3D Tiles 中的一种瓦片格式,用于存储带有批量表(Batch Table)和特征表(Feature Table)的 3D 模型数据。

功能特点

  • 构建 B3DM 文件:从 GLB 数据和元数据生成符合 B3DM 规范的二进制文件。
  • 解析 B3DM 文件:从 B3DM 文件中提取 GLB 数据、特征表和批量表。
  • 类型安全:基于 TypeScript 开发,提供完整的类型声明支持。
  • 轻量高效:专注于核心功能,易于集成到 3D 地理信息系统(GIS)项目中。

安装

通过 npm 安装:

npm install b3dm

使用示例

构建 B3DM 文件

import { buildB3dm } from 'b3dm';

// 输入 GLB 数据和元数据
const glbData = new Uint8Array([...]); // GLB 的二进制数据
const featureTableJSON = { BATCH_LENGTH: 10 };
const batchTableJSON = { name: 'Building A', height: 50 };

// 构建 B3DM 文件
const b3dmBuffer = buildB3dm({
  glbData,
  featureTableJSON,
  batchTableJSON,
});

// 将结果保存为文件
require('fs').writeFileSync('output.b3dm', Buffer.from(b3dmBuffer));

解析 B3DM 文件

import { parseB3dm } from 'b3dm';

// 读取 B3DM 文件
const b3dmData = require('fs').readFileSync('example.b3dm');
const parsedData = parseB3dm(b3dmData.buffer);

console.log('Header:', parsedData.header);
console.log('Feature Table JSON:', parsedData.featureTable.json);
console.log('Batch Table JSON:', parsedData.batchTable?.json);
console.log('GLB Data Length:', parsedData.glbData.byteLength);

API 文档

构建 B3DM 文件

buildB3dm(options: B3dmBuildOptions): ArrayBuffer

  • 参数
    • options: 构建选项
      • glbData: 输入的 GLB 二进制数据(Uint8Array)。
      • featureTableJSON: 特征表的 JSON 数据(可选,默认为空对象)。
      • featureTableBinary: 特征表的二进制数据(可选,默认为空数组)。
      • batchTableJSON: 批量表的 JSON 数据(可选,默认为空对象)。
      • batchTableBinary: 批量表的二进制数据(可选,默认为空数组)。
  • 返回值:生成的 B3DM 二进制数据(ArrayBuffer)。

解析 B3DM 文件

parseB3dm(arrayBuffer: ArrayBuffer): B3dmData

  • 参数
    • arrayBuffer: B3DM 文件的二进制数据(ArrayBuffer)。
  • 返回值:解析后的 B3DM 数据结构(B3dmData)。
    • header: 文件头信息(B3dmHeader)。
    • featureTable: 特征表,包含 JSON 和可选的二进制数据。
    • batchTable: 批量表(可选),包含 JSON 和可选的二进制数据。
    • glbData: 内嵌的 GLB 模型数据(Uint8Array)。

类型定义

以下是库中的主要接口定义:

/** B3DM 文件头结构 */
export interface B3dmHeader {
    magic: string;          // 固定为 "b3dm"
    version: number;        // 版本号(通常为 1)
    byteLength: number;     // 文件总长度
    featureTableJSONByteLength: number; // 特征表 JSON 长度
    featureTableBinaryByteLength: number; // 特征表二进制长度
    batchTableJSONByteLength: number; // 批量表 JSON 长度
    batchTableBinaryByteLength: number; // 批量表二进制长度
}

/** B3DM 完整数据结构 */
export interface B3dmData {
    header: B3dmHeader;
    featureTable: {
      json: Record<string, any>;
      binary?: Uint8Array;
    };
    batchTable?: {
      json: Record<string, any>;
      binary?: Uint8Array;
    };
    glbData: Uint8Array;    // 内嵌的 GLB 模型数据
}

/** 构建 B3DM 的选项 */
export interface B3dmBuildOptions {
    glbData: Uint8Array;    // 输入的 GLB 二进制数据
    featureTableJSON?: Record<string, any>; // 特征表 JSON
    featureTableBinary?: Uint8Array; // 特征表二进制
    batchTableJSON?: Record<string, any>; // 批量表 JSON
    batchTableBinary?: Uint8Array; // 批量表二进制
}

贡献指南

欢迎为 b3dm 提交问题或 Pull Request!以下是一些贡献建议:

  1. 报告问题:如果发现任何 Bug 或有改进建议,请在 GitHub Issues 中提交。
  2. 开发环境
    • 克隆仓库:git clone https://github.com/cesiumjs/b3dm.git
    • 安装依赖:npm install
    • 运行测试:npm test
  3. 代码风格:遵循 TypeScript 的最佳实践,确保代码格式化一致。
  4. 提交 PR:请在提交前运行 npm run build 确保代码能够正常构建。

许可证

b3dm 遵循 MIT License

希望这个库能帮助你更轻松地处理 B3DM 文件!如果有任何问题,欢迎随时联系我们。