# triangles-mesh-random-pts

> generate random points and normals evenly distributed on a triangle mesh

Latest version **0.0.2** (published 2022-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install triangles-mesh-random-pts
pnpm add triangles-mesh-random-pts
yarn add triangles-mesh-random-pts
bun add triangles-mesh-random-pts
```

## 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.2 |
| Published | 2022-04-05 |
| First published | 2022-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | stonkpunk |
| Maintainers | stonkpunk |
| Keywords | triangles, mesh, 3d, hairs, hair, fur, surface, normals, random |

## Links

- npm: https://www.npmjs.com/package/triangles-mesh-random-pts
- Homepage: https://github.com/stonkpunk/my-npm-modules/tree/main/triangles-mesh-random-pts
- npm.io page: https://npm.io/package/triangles-mesh-random-pts

## Dependencies (6)

- [chance](https://npm.io/package/chance.md) ^1.1.8
- [normals](https://npm.io/package/normals.md) ^1.1.0
- [triangles-index](https://npm.io/package/triangles-index.md) 0.0.3
- [triangle-area-fast](https://npm.io/package/triangle-area-fast.md) 0.0.24
- [triangle-random-pts](https://npm.io/package/triangle-random-pts.md) 0.0.11
- [barycentric-coordinates](https://npm.io/package/barycentric-coordinates.md) 0.0.3

## Recent versions

- 0.0.2 (latest) — 2022-04-05
- 0.0.1 — 2022-03-10

## README

# triangles-mesh-random-pts

generate random points and normals evenly distributed on a triangle mesh.

you can use this tool to generate random points on a surface and/or to create "hairs" on a surface.

each result has format `{pt: [x,y,z], normal: [x,y,z], normalLine: [[x,y,z],[x,y,z]], triangleIndex: int}`

triangles are chosen randomly [weighted by area], then points are generated using `triangle-random-pts`

resulting normals are interpolated via vertex normals + barycentric coordinates.

## Installation

```sh
npm i triangles-mesh-random-pts
```

## Usage 

```javascript
var meshRndPts = require('triangles-mesh-random-pts');

//here we generate 5000 random points on the surface of the stanford bunny mesh
//each result has format {pt: [x,y,z], normal: [x,y,z], normalLine: [[x,y,z],[x,y,z]], triangleIndex: int}

var bunny = require("bunny");
var results = meshRndPts.randomPtsNormalsForMeshIndexed(bunny,5000);

//meshRndPts.randomPtsNormalsForMesh(tris, numberPts) is similar but takes a list of triangles and indexes them automatically
//where each triangle = [[x,y,z],[x,y,z],[x,y,z]]

//view the result with ascii-raytracer

var art = require('ascii-raytracer');
var config = {
    thickness:0.05, //line rendering thickness
    lines: results.map(r=>r.normalLine),
    lineColors: results.map(r=>[Math.random(),Math.random(),Math.random()]),
    resolution: 64,
    aspectRatio: 1.0,
    mouseControl:false,
    cameraPos: [-6.63,11.11,16.56],
    cameraRot: [1.93,-7.47]
}
art.runScene(config);
```

![500](https://i.imgur.com/AAwTEpn.png)

^500 random bunny hairs

![5000](https://i.imgur.com/lsGbafv.png)

^5,000 random bunny hairs

![50000](https://i.imgur.com/bOq0d2P.png)

^50,000 random bunny hairs


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

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