-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename files and functions for consistency, upate README
- Loading branch information
Showing
4 changed files
with
67 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.