import { defineConfig } from 'vite';
import wasm from 'vite-plugin-wasm';
export default defineConfig({
plugins: [wasm()],
});import { interpolate_wasm } from 'heatmap-points-wasm';
const inputPoints = [
{ x: 0, y: 0, z: 0, value: 1 },
{ x: 1, y: 1, z: 1, value: 2 },
{ x: 2, y: 2, z: 2, value: 3 },
];
const interpolatedPoints = interpolate_wasm(
JSON.stringify(inputPoints), // 输入点云数据的 JSON 字符串
10, // grid size
);
console.log(JSON.parse(interpolatedPoints)); // 输出插值后的点云数据heatmap-points-wasm/
├── src/
│ ├── lib.rs # WASM 库入口和导出函数
│ ├── main.rs # Rust 可执行文件入口
│ └── interpolation.rs # 核心插值算法实现
├── Cargo.toml # Rust 项目配置
└── README.md # 项目文档
# 安装 Rust 参考官网 https://www.rust-lang.org/tools/install
# 添加 WASM 编译目标
rustup target add wasm32-unknown-unknown
# 安装 wasm-bindgen CLI 工具
cargo install wasm-bindgen-cli# 运行 main.rs
cargo run main这将:
- 执行三维插值计算
- 输出插值结果统计信息
- 生成
interpolated_point_cloud.json文件
# 打npm包
wasm-pack build
# 发布
cd pkg
npm publish --access public --registry https://registry.npmjs.org打包之后,进入 app 目录
cd app
npm install
npm run dev即可以在浏览器中查看效果