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

@pmx-three/core

v0.1.0

Published

Dependency-free TypeScript parser for PMX 2.x files

Readme

@pmx-three/core

无运行时依赖的 PMX 2.x 二进制解析器。

安装

npm install @pmx-three/core

基本用法

浏览器

import { parsePmx } from '@pmx-three/core';

const response = await fetch('/models/character.pmx');
if (!response.ok) throw new Error(`Request failed: ${response.status}`);

const pmx = parsePmx(await response.arrayBuffer());
console.log(pmx.metadata.name, pmx.vertices.length);

Node.js

Node.js 的 Buffer 可能只是底层 ArrayBuffer 的一个切片,传入前需保留正确的字节范围:

import { readFile } from 'node:fs/promises';
import { parsePmx } from '@pmx-three/core';

const bytes = await readFile('./character.pmx');
const buffer = bytes.buffer.slice(
  bytes.byteOffset,
  bytes.byteOffset + bytes.byteLength,
);
const pmx = parsePmx(buffer);

解析与校验

parsePmx 负责二进制格式解析:

import { parsePmx, PmxParseError } from '@pmx-three/core';

try {
  const model = parsePmx(buffer);
} catch (error) {
  if (error instanceof PmxParseError) {
    console.error(error.section); // 例如 "vertices"
    console.error(error.offset);  // 失败位置的字节偏移
  }
  throw error;
}

validatePmx 对已经解析的模型执行跨字段与索引引用检查:

import { parsePmx, validatePmx } from '@pmx-three/core';

const model = parsePmx(buffer);
const issues = validatePmx(model);
const errors = issues.filter((issue) => issue.severity === 'error');

for (const issue of issues) {
  console.warn(issue.code, issue.section, issue.itemIndex, issue.message);
}

也可以用 parsePmxWithDiagnostics(buffer) 一次获得 { model, issues }。二进制本身无法解析时,该函数仍会抛出 PmxParseErrorissues 只表示成功解析后的结构校验结果。

API

| 导出 | 说明 | | --- | --- | | parsePmx(buffer) | 将 PMX 2.0/2.1 二进制数据解析为 PmxModel | | parsePmxWithDiagnostics(buffer) | 解析模型并调用 validatePmx | | validatePmx(model) | 返回 PmxValidationIssue[],检查索引、材质覆盖范围与部分 PMX 版本约束 | | PmxParseError | 包含 sectionoffset 的解析异常 | | PmxBinaryReader | PMX 小端二进制读取器,供高级用法或扩展解析使用 | | PmxModel 及相关类型 | 完整的 TypeScript 数据结构定义 |

支持范围

  • PMX 2.0、2.1
  • UTF-16LE、UTF-8
  • BDEF1、BDEF2、BDEF4、SDEF、QDEF
  • group、vertex、bone、UV、material、flip、impulse morph
  • 刚体、关节,以及 PMX 2.1 软体数据

License

MIT