# trilinear-distortion

> distort 3d meshes / points within a bounding box by warping the corners of the box

Latest version **0.0.11** (published 2022-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install trilinear-distortion
pnpm add trilinear-distortion
yarn add trilinear-distortion
bun add trilinear-distortion
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2022-09-25 |
| First published | 2022-09-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | stonkpunk |
| Maintainers | stonkpunk |
| Keywords | trilinear, distort, warp, space, lut |

## Links

- npm: https://www.npmjs.com/package/trilinear-distortion
- Homepage: https://github.com/stonkpunk/my-npm-modules/tree/main/trilinear-distortion
- npm.io page: https://npm.io/package/trilinear-distortion

## Recent versions

- 0.0.11 (latest) — 2022-09-25
- 0.0.1 — 2022-09-25

## README

# trilinear-distortion

distort 3d meshes / points within a bounding box by warping the corners of the box

also useful for shifting color spaces / LUTs

## Installation

```sh
npm i trilinear-distortion
```

## Usage 

```javascript
var bunny = require('bunny'); //bunny mesh {cells, positions}
var tmv = require('triangles-mesh-viewer-sdl-regl'); //triangle mesh viewer
var meshViewer = tmv.meshViewer.modelViewer(bunny); //load bunny into viewer

var distort = require('trilinear-distortion');

//create distortion object from corners of mesh bounding box
var distortionObj = distort.distortionObjFromMesh(bunny);

//add extra triangles to mesh to make bounding box visible
distort.addBoundingBoxLinesToMesh(bunny);

//distortionObj has format:
// {
//     p000: [x,y,z], //lower xyz corner
//     p001: [x,y,z],
//     p010: [x,y,z],
//     p011: [x,y,z],
//     p100: [x,y,z],
//     p101: [x,y,z],
//     p110: [x,y,z],
//     p111: [x,y,z], //upper xyz corner
// }

//randomly jitter the corners of the distortion object
setInterval(function(){
    //distortionObj = distort.jitterDistortionObjectCopy(distortionObjOrig, 0.50); //jitter a copy instead of modifying orig
    distortionObj = distort.jitterDistortionObjectInPlace(distortionObj, 0.50); //randomly jitter corners
    var newModel = distort.distortedMeshCopy(bunny, distortionObj);
    meshViewer.updateModel(newModel); //update the model in the mesh viewer
},100);

//all functions:
//distortionObjUnit() ==> distortionObj at corners of unit cube [[0,0,0],[1,1,1]]
//distortionObjFromAABB(boundingBox=[[x,y,z],[x,y,z]]) ==> distortionObj
//distortionObjFromMesh(bunny)
//distortPtTrilinear(pt, aabbStarting, distortionObj)
//distortPtsTrilinear(pts, aabbStarting, distortionObj)
//meshBoundingBox(bunny = {cells,positions}) ==> [[x,y,z],[x,y,z]] = [minCorner,maxCorner] //aka aabb
//boundingBoxOfPts(pts = [[x,y,z] ... ])
//addBoundingBoxLinesToMesh(bunny)
//jitterDistortionObjectInPlace(distortionObj, amt)
//jitterDistortionObjectCopy(distortionObj, amt)
//distortMeshInPlace(bunny, distortionObj)
//distortedMeshCopy(bunny, distortionObj)
```

![bunny1](https://i.imgur.com/JwDW9Dy.png)

![bunny2](https://i.imgur.com/guZmTdk.png)

## See Also

- [triangles-mesh-viewer-sdl-regl](https://www.npmjs.com/package/triangles-mesh-viewer-sdl-regl)



[![stonks](https://i.imgur.com/UpDxbfe.png)](https://www.npmjs.com/~stonkpunk)

---
_Source: https://npm.io/package/trilinear-distortion · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
