Skip to main content

Usage

NPM

Browser

import * as PCL from 'pcl.js';async function main() {  // Initialization  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();

Node.js

const PCL = require('pcl.js');async function main() {  // Initialization  await PCL.init();  // ...}main();

CDN

<script>async function main() {  // Initialization, PCL is a global object.  await PCL.init();  // ...}main();</script>
TIP

It is recommended to use CDN to load pcl-core.wasm

jsdelivr: https://cdn.jsdelivr.net/npm/pcl.js/dist/pcl-core.wasm
unpkg: https://unpkg.com/pcl.js/dist/pcl-core.wasm

Basic Usage Example

Filtering a PointCloud using a PassThrough filter.
See: https://pcl.readthedocs.io/projects/tutorials/en/master/passthrough.html#passthrough

TypeScript
import * as PCL from 'pcl.js';async function main() {  await PCL.init({    url: 'https://cdn.jsdelivr.net/npm/pcl.js/dist/pcl-core.wasm',  });  // Get PCD file  const data = await fetch('https://cdn.jsdelivr.net/gh/luoxuhai/pcl.js@master/data/rops_tutorial/points.pcd').then(res => res.arrayBuffer());  // Load PCD file data, return point cloud object  const cloud = PCL.loadPCDData<PCL.PointXYZ>('data, PCL.PointXYZ);  // Filtering a PointCloud using a PassThrough filter  // See: https://pcl.readthedocs.io/projects/tutorials/en/master/passthrough.html#passthrough  const pass = new PCL.PassThrough<PCL.PointXYZ>(PCL.PointXYZ);  pass.setInputCloud(cloud);  pass.setFilterFieldName('z');  pass.setFilterLimits(0.0, 1.0);  const cloudFiltered = pass.filter();  // Save filtered point cloud objects as PCD files, the content is ArrayBuffer  const cloudFilteredData = PCL.savePCDDataASCII(cloudFiltered);}main();