Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
JavaScript Module
  • Loading branch information
lanceschi committed Jan 13, 2022
2 parents e612368 + d2eec12 commit d0f907f
Show file tree
Hide file tree
Showing 10 changed files with 408 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2018,
"ecmaVersion": 2021,
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v2.0.0] - 2022-01-13

### Added

- Added NPM packages:
- `cross-blob` `3.0.0`

### Changed

- Changed the library to a JavaScript Module
- Node engine version is now set to `>=12.0.0`
- Updated wrapped `PLYLoader` library to the latest: `0.136.0`
- Partial test rewrote
- README.md edits
- NPM package upgrades:
- three ^0.125.0 → ^0.136.0

## [v1.2.2] - 2022-01-13

### Changed
Expand Down
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,41 @@
# Three.js PLY file format loader to use with Node.js

## Description
Node.js wrapper for [three.js][THREEJS-github-link] PLYLoader (currently three.js v0.125.0).
Node.js wrapper for [three.js][THREEJS-github-link] PLYLoader (currently three.js v0.136.0).

Original PLYLoader source code can be found [here][PLYLoader-source-link].

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][javascript-module-url]. The recommended use with CommonJS files is through [dynamic imports][dynamic-import-url].

## Usage

```javascript
const fs = require("fs");
const { join } = require("path");
const THREE = require("three");

// Require object constructor
const PLYLoader = require("threejs-ply-loader")(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();
// 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);
// 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);
// Convert node file Buffer to ArrayBuffer
const fileArrayBuffer = plyLoader.bufferToArrayBuffer(fileBuffer);

// Parse 3D model into THREE geometry
const geometry = plyLoader.parse(fileArrayBuffer);
// Parse 3D model into THREE geometry
const geometry = plyLoader.parse(fileArrayBuffer);
})();
```


Expand Down Expand Up @@ -59,6 +66,6 @@ npm test
Developed with Node v16.13.2

[THREEJS-github-link]: https://github.com/mrdoob/three.js
[PLYLoader-source-link]: https://github.com/mrdoob/three.js/blob/r115/examples/js/loaders/PLYLoader.js


[PLYLoader-source-link]: https://github.com/mrdoob/three.js/blob/r136/examples/js/loaders/PLYLoader.js
[javascript-module-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
[dynamic-import-url]: https://v8.dev/features/dynamic-import#dynamic
6 changes: 4 additions & 2 deletions examples/ply-model-to-png.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const THREE = require('three');
const { SoftwareRenderer } = require('three-software-renderer');
const { PNG } = require('pngjs');
const fs = require('fs');
const PLYLoader = require('../src')(THREE);
const { join } = require('path');

(() => {
(async () => {
const { PLYLoaderFactory } = await import('../src/index.mjs');
const PLYLoader = PLYLoaderFactory(THREE);

try {
// Scene and perspective camera setup
const width = 1024;
Expand Down
142 changes: 108 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d0f907f

Please sign in to comment.