跳到主要内容

使用

NPM

import * as PCL from 'pcl.js';async function main() {  // Initialization  const pcl = await PCL.init({    // Recommend, optional configuration, custom WebAssembly file link.    url: 'https://cdn.jsdelivr.net/npm/pcl.js/dist/pcl-core.wasm',    // You can also pass an ArrayBuffer of WebAssembly files.    // arrayBuffer: ArrayBuffer  });}main();

CDN

<script>async function main() {  // Initialization, PCL is a global object.  const pcl = await PCL.init();  // ...}main();</script>
提示

推荐使用CDN加载pcl-core.wasm

简单示例

使用 PassThrough 过滤器过滤点云。 参考: https://pcl.readthedocs.io/projects/tutorials/en/master/passthrough.html#passthrough

// TypeScriptimport * as PCL from 'pcl.js';async function main() {  const pcl = await PCL.init({    url: 'https://cdn.jsdelivr.net/npm/pcl.js/dist/pcl-core.wasm',  });  // 获取 PCD 文件  const data = await fetch('https://cdn.jsdelivr.net/gh/luoxuhai/pcl.js@master/data/rops_tutorial/points.pcd').then(res => res.arrayBuffer());  // 加载 PCD 数据,返回点云对象  const cloud = pcl.io.loadPCDData<PCL.PointXYZ>(data, PCL.PointXYZ);  // 使用 PassThrough 过滤器过滤点云  // 参考: https://pcl.readthedocs.io/projects/tutorials/en/master/passthrough.html#passthrough  const pass = new pcl.filters.PassThrough<PCL.PointXYZ>(PCL.PointXYZ);  pass.setInputCloud(cloud);  pass.setFilterFieldName('z');  pass.setFilterLimits(0.0, 1.0);  const cloudFiltered = pass.filter();  // 将过滤后的点云对象保存为 PCD 文件, 内容为 ArrayBuffer  const cloudFilteredData = pcl.io.savePCDDataASCII(cloudFiltered);}main();