Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dmnsgn/vector-field
A data structure and lookup for 3D vector fields (flow fields).
https://github.com/dmnsgn/vector-field
3d flow flow-field lookup noise perlin vector-field vectors
Last synced: about 2 months ago
JSON representation
A data structure and lookup for 3D vector fields (flow fields).
- Host: GitHub
- URL: https://github.com/dmnsgn/vector-field
- Owner: dmnsgn
- License: mit
- Created: 2020-01-14T18:03:35.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-07T14:27:13.000Z (7 months ago)
- Last Synced: 2024-12-13T06:50:13.593Z (2 months ago)
- Topics: 3d, flow, flow-field, lookup, noise, perlin, vector-field, vectors
- Language: JavaScript
- Homepage: https://dmnsgn.github.io/vector-field/
- Size: 11.2 MB
- Stars: 40
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# vector-field
[![npm version](https://img.shields.io/npm/v/vector-field)](https://www.npmjs.com/package/vector-field)
[![stability-stable](https://img.shields.io/badge/stability-stable-green.svg)](https://www.npmjs.com/package/vector-field)
[![npm minzipped size](https://img.shields.io/bundlephobia/minzip/vector-field)](https://bundlephobia.com/package/vector-field)
[![dependencies](https://img.shields.io/librariesio/release/npm/vector-field)](https://github.com/dmnsgn/vector-field/blob/main/package.json)
[![types](https://img.shields.io/npm/types/vector-field)](https://github.com/microsoft/TypeScript)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-fa6673.svg)](https://conventionalcommits.org)
[![styled with prettier](https://img.shields.io/badge/styled_with-Prettier-f8bc45.svg?logo=prettier)](https://github.com/prettier/prettier)
[![linted with eslint](https://img.shields.io/badge/linted_with-ES_Lint-4B32C3.svg?logo=eslint)](https://github.com/eslint/eslint)
[![license](https://img.shields.io/github/license/dmnsgn/vector-field)](https://github.com/dmnsgn/vector-field/blob/main/LICENSE.md)A data structure and lookup for 3D vector fields (flow fields).
[![paypal](https://img.shields.io/badge/donate-paypal-informational?logo=paypal)](https://paypal.me/dmnsgn)
[![coinbase](https://img.shields.io/badge/donate-coinbase-informational?logo=coinbase)](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3)
[![twitter](https://img.shields.io/twitter/follow/dmnsgn?style=social)](https://twitter.com/dmnsgn)![](https://raw.githubusercontent.com/dmnsgn/vector-field/main/screenshot.gif)
See the [example](https://dmnsgn.github.io/vector-field/) and its [source](index.html).
## Installation
```bash
npm install vector-field
```## Usage
```js
import VectorField from "vector-field";let time = 0;
const directionFn = ([x, y, z]) => {
const n = myNoise4D(x, y, z, time);
const theta = n;
const phi = n;return [
Math.sin(theta) * Math.cos(phi),
Math.sin(theta) * Math.sin(phi),
Math.cos(theta),
];
};
const vectorField = new VectorField(directionFn, [12, 6, 6], 1);const frame = () => {
time += 0.001;
vectorField.update();
requestAnimationFrame(frame);
};requestAnimationFrame(() => {
frame();
});
```## API
## Classes
- VectorField
-
A data structure and lookup for 3D vector fields (flow fields).
## Typedefs
-
vec3 :Array.<number>
-
VectorFieldCell :object
-
VectorFieldDirectionFn :function
-
The custom function to compute the cell direction (often a noise function)
## VectorField
A data structure and lookup for 3D vector fields (flow fields).
**Kind**: global class
**Properties**
| Name | Type |
| ----------- | -------------------------------------------------------------- |
| directionFn | [VectorFieldDirectionFn
](#VectorFieldDirectionFn) |
| steps | [vec3
](#vec3) |
| bounds | [vec3
](#vec3) |
| halfBounds | [vec3
](#vec3) |
| field | [Array.<VectorFieldCell>
](#VectorFieldCell) |
- [VectorField](#VectorField)
- [new VectorField(directionFn, [steps], [bounds])](#new_VectorField_new)
- [.update()](#VectorField+update)
- [.lookup(cell)](#VectorField+lookup) ⇒ [VectorFieldCell
](#VectorFieldCell) \| undefined
### new VectorField(directionFn, [steps], [bounds])
Creates an instance of VectorField.
| Param | Type | Default | Description |
| ----------- | -------------------------------------------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| directionFn | [VectorFieldDirectionFn
](#VectorFieldDirectionFn) | | The custom function to compute the cell direction (often a noise function) |
| [steps] | number
\| [vec3
](#vec3) | 10
| The number of steps on each dimension (all positive integer). Use integer for identical dimensions. |
| [bounds] | number
\| [vec3
](#vec3) | 1
| The size of a containing box for the field. Is divided into steps for each dimension (all positive). Use integer for identical dimensions. |
### vectorField.update()
Create/update the field according to the provided noise function.
**Kind**: instance method of [VectorField
](#VectorField)
### vectorField.lookup(cell) ⇒ [VectorFieldCell
](#VectorFieldCell) \| undefined
Find a `VectorFieldCell` at specified position. Useful to compute a particle's velocity for instance.
**Kind**: instance method of [VectorField
](#VectorField)
| Param | Type | Description |
| ----- | -------------------------- | ------------ |
| cell | [vec3
](#vec3) | [cx, cy, cz] |
## vec3 : Array.<number>
## VectorFieldCell : object
**Kind**: global typedef
**Properties**
| Name | Type |
| --------- | -------------------------- |
| position | [vec3
](#vec3) |
| direction | [vec3
](#vec3) |
## VectorFieldDirectionFn : function
The custom function to compute the cell direction (often a noise function)
**Kind**: global typedef
| Param | Type |
| ------------ | -------------------------- |
| position | [vec3
](#vec3) |
| stepPosition | [vec3
](#vec3) |
## License
MIT. See [license file](https://github.com/dmnsgn/vector-field/blob/main/LICENSE.md).