Skip to content

Commit

Permalink
0.6.0 update
Browse files Browse the repository at this point in the history
Rename files and functions for consistency, upate README
  • Loading branch information
oculus42 committed Mar 14, 2018
1 parent 11b3911 commit b1b9f84
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 23 deletions.
82 changes: 63 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,98 @@
# osPoly - openscad-poly-tools
A library to manipulate OpenSCAD Polyhedrons

[![npm](https://img.shields.io/npm/v/openscad-poly-tools.svg)](https://www.npmjs.com/package/openscad-poly-tools)

This library is still in development (pre 1.0.0) and may change *significantly* between minor versions.
Once it reaches 1.0.0 all breaking changes will use a major revision number.

## Motivation
After importing an STL into OpenSCAD with [http://jsfiddle.net/Riham/yzvGD/](http://jsfiddle.net/Riham/yzvGD/) I realized there was a significant duplication of points.

### JSFiddle Update
I also [forked the JSFiddle](http://jsfiddle.net/_sir/yzvGD/595/) with a version that prevents the extra vertices.
I also [forked the original JSFiddle](http://jsfiddle.net/_sir/yzvGD/595/) with a version that eliminates the extra vertices.
The changes in the JSFiddle are not related to the `.simplify()` command created below, but import functionality is planned.


## Features
## Functions

### osPoly.simplify({points, faces});
### Simplify Functions

#### reportDuplicatePercentage(model)
Give the percentage of duplicates in the array of points. No changes are made.

```javascript
osPoly.simplify({
points: myPolyPoints,
faces: myPolyFaces
});
osPoly.reportDuplicatePercentage(myModel);
```

#### simplify(model)
Eliminate duplicate points in the model's `points` array and re-map the indices in the `faces` to match.

```javascript
osPoly.simplify(myModel);
```

Removes duplicate points in the `points` array and remaps the indexes in `faces`.
### Translate Functions

### osPoly.translate(points, offset);
### centerOnAxis(model, axis)
Move the center (average of the highest and lowest points) of a model to the origin of the specified axis.

```javascript
osPoly.translate(myPoints, { x: 5, y: 0, z: -1});
osPoly.centerOnAxis(myModel, 'x')
```

Recenter the object
#### moveToOrigin(model, axis, [moveTop])
Move the lowest or highest point on an axis to the origin.

`axisIndex` matches the index of the `[x, y, z]` coordinates (i.e. `0`, `1`, `2`).
`moveTop` is a Boolean that indicates whether the smallest (`false`) or largest (`true`) value will move to origin.
```javascript
osPoly.moveToOrigin(myModel, 'z')
```

#### translate(model, vector)
Shift the model along one or more axes.

### osPoly.moveToAxis(points, axisIndex, moveTop);
```javascript
osPoly.translate(myModel, { x: 10, y: -2, z: 0.25 });
```

### Edit


#### filterForMatch(model, predicate)
Get only the faces of the model which have points matching the predicate.

**NOTE:** This is not the same as a Boolean operation in OpenSCAD. Any faces that have points eliminated by the predicate will be removed, not modified.

```javascript
osPoly.filterForMatch(myModel, (point) => point.x > 0);
```

#### removeDeadPoints(model)
Eliminate any dead points and correct the indices of the faces to match.

```javascript
osPoly.moveToAxis(myPoints, 1);
osPoly.removeDeadPoints(myModel);
```

Intended to *drop* an object to the origin of an axis.
## Notes

As of 0.6.0, all exposed functions take a model, which is an object with arrays of points and faces.

```javascript
myModel = {
points: [...],
faces: [...],
};
```

`axisIndex` matches the index of the `[x, y, z]` coordinates (i.e. `0`, `1`, `2`).
`moveTop` is a Boolean that indicates whether the smallest (`false`) or largest (`true`) value will move to origin.
Where an axis is specified, the library should accept the string `'x'`, `'y'`, or `'z'`; or their
index `0`, `1`, or `2`, respectively.


## Goals
* ~~Perform simple, brute-force point de-duplication on polyhedrons.~~
* ~~Move objects~~
* ~~Cut parts of an object~~
* ~~Provide a consistent interface for all functions~~
* Incorporate the importer from https://www.thingiverse.com/thing:62666
* Provide a consistent interface for all functions
* Identify faces sharing points in the same plane and merge them
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { filterForMatch, removeDeadPoints } from './src/piece.mjs';
import { filterForMatch, removeDeadPoints } from './src/edit.mjs';
import { reportDuplicatePercentage, simplify } from './src/simplify.mjs';
import { centerOnAxis, moveToAxis, translate } from './src/translate.mjs';
import { centerOnAxis, moveToOrigin, translate } from './src/translate.mjs';

export default {
centerOnAxis,
filterForMatch,
moveToAxis,
moveToOrigin,
removeDeadPoints,
reportDuplicatePercentage,
simplify,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openscad-poly-tools",
"version": "0.5.0",
"version": "0.6.0",
"description": "OpenSCAD Polyhedron Tools",
"main": "index.js",
"scripts": {
Expand Down
File renamed without changes.

0 comments on commit b1b9f84

Please sign in to comment.