Newfangled Package Modernizer

    threejs-ply-loader

    2.0.1 • Public • Published

    ci   npm publish   npm version   npm

    Three.js PLY file format loader to use with Node.js

    Description

    Node.js wrapper for three.js PLYLoader (currently three.js v0.136.0).

    Original PLYLoader source code can be found here.

    Beside some minor edits, I added an additional helper function for converting Node Buffer to ArrayBuffer (convenience-wise) and I put in place tests.

    This library was developed as a JavaScript Module. The recommended use with CommonJS files is through dynamic imports.

    Usage

    const fs = require("fs");
    const { join } = require("path");
    const THREE = require("three");
    
    (async () => {
      // Import PLYLoader Factory
      const { PLYLoaderFactory } = await import("threejs-ply-loader");
    
      // Initialize PLYLoader Class
      const PLYLoader = PLYLoaderFactory(THREE);
    
      // Instantiate PLYLoader object
      const plyLoader = new PLYLoader();
    
      // Read 3D Model as PLY file format
      const sourceFilepath = join(__dirname, "assets/cube.ply");
      const fileBuffer = fs.readFileSync(sourceFilepath);
    
      // Convert node file Buffer to ArrayBuffer
      const fileArrayBuffer = plyLoader.bufferToArrayBuffer(fileBuffer);
    
      // Parse 3D model into THREE geometry
      const geometry = plyLoader.parse(fileArrayBuffer);
    })();

    Example

    An example is present in the examples folder. It will load a PLY file model and output its rendering to a PNG file. It can be run from a shell:

    npm install
    npm run example:cube-to-png

    The output image is going to located in examples/temp/vertex-colored-cube.png

    Tests

    They can be run from a shell:

    npm install
    npm test

    Development notes

    Developed with Node v16.13.2

    Install

    npm i threejs-ply-loader

    DownloadsWeekly Downloads

    396

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    24.1 kB

    Total Files

    6

    Last publish

    Collaborators

    • lanceschi