All Projects → donmccurdy → mikktspace-wasm

donmccurdy / mikktspace-wasm

Licence: MIT license
MikkTSpace vertex tangent calculation for JavaScript/TypeScript/Node.js, using Web Assembly.

Programming Languages

javascript
184084 projects - #8 most used programming language
rust
11053 projects

Projects that are alternatives of or similar to mikktspace-wasm

envelope ex
Utilities for calculating and comparing envelopes from geometries
Stars: ✭ 15 (-21.05%)
Mutual labels:  geometry
PointProjector
A simple Cinema 4D plugin that non-destructively projects the points of a spline or polygon object on geometry.
Stars: ✭ 20 (+5.26%)
Mutual labels:  geometry
EsriRESTScraper
A Python class that scrapes ESRI Rest Endpoints and exports data to a geodatabase
Stars: ✭ 43 (+126.32%)
Mutual labels:  geometry
vexed-generation
Polymorphic helper functions & geometry ops for Houdini VEX / OpenCL
Stars: ✭ 32 (+68.42%)
Mutual labels:  geometry
geos-cli
A native geometry command line library using libgeos.
Stars: ✭ 20 (+5.26%)
Mutual labels:  geometry
vec
Vector graphics software to generate HPGL output to drive a plotter
Stars: ✭ 19 (+0%)
Mutual labels:  geometry
osm-static-maps
Openstreetmap static maps is a nodejs lib, CLI and server open source inspired on google static map service
Stars: ✭ 130 (+584.21%)
Mutual labels:  geometry
dmc
Dual Marching Cubes Implementation in C++
Stars: ✭ 45 (+136.84%)
Mutual labels:  geometry
GIBBON
The Geometry and Image-Based Bioengineering add-On for MATLAB
Stars: ✭ 132 (+594.74%)
Mutual labels:  geometry
batyr
Microservice for on-demand synchronization of geographical vector datasources to a PostgreSQL/PostGIS database. The service provides an HTTP API for easy integration into other applications.
Stars: ✭ 25 (+31.58%)
Mutual labels:  geometry
elm-geometry-svg
Render 2D elm-geometry types as SVG
Stars: ✭ 40 (+110.53%)
Mutual labels:  geometry
DynamicalBilliards.jl
An easy-to-use, modular, extendable and absurdly fast Julia package for dynamical billiards in two dimensions.
Stars: ✭ 97 (+410.53%)
Mutual labels:  geometry
Mathematics for Machine Learning
Learn mathematics behind machine learning and explore different mathematics in machine learning.
Stars: ✭ 28 (+47.37%)
Mutual labels:  geometry
geok
Kotlin geometry library
Stars: ✭ 29 (+52.63%)
Mutual labels:  geometry
martinez-src
Mirrored implementations of polygon clipping/CSG/operations algorithm, in C (original, by Martínez et al) and ActionScript3 (port, by Mahir Iqbal)
Stars: ✭ 34 (+78.95%)
Mutual labels:  geometry
tyssue
An epithelium simulation library
Stars: ✭ 50 (+163.16%)
Mutual labels:  geometry
topo
A Geometry library for Elixir that calculates spatial relationships between two geometries
Stars: ✭ 125 (+557.89%)
Mutual labels:  geometry
vg
Vector-geometry toolbelt for 3D points and vectors
Stars: ✭ 106 (+457.89%)
Mutual labels:  geometry
variational-surface-cutting
Codebase for "Variational Surface Cutting" by Sharp & Crane, SIGGRAPH 2018
Stars: ✭ 64 (+236.84%)
Mutual labels:  geometry
classy blocks
Python classes for easier creation of OpenFOAM's blockMesh dictionaries.
Stars: ✭ 53 (+178.95%)
Mutual labels:  geometry

mikktspace-wasm

Latest NPM release Build Status

MikkTSpace vertex tangent calculation, in Web Assembly.

A common misunderstanding about tangent space normal maps is that this representation is somehow asset independent. However, normals sampled/captured from a high resolution surface and then transformed into tangent space is more like an encoding. Thus to reverse the original captured field of normals the transformation used to decode would have to be the exact inverse of that which was used to encode.

— Morten S. Mikkelsen

When normal maps render incorrectly, with distortion or unexpectedly inverted insets and extrusions, this misconception may be the cause. Most normal map bakers use the MikkTSpace standard to generate vertex tangents while creating a normal map, and the technique is recommended by the glTF 2.0 specification. Engines reconstructing the tangent space at runtime often use other methods — e.g. derivatives in the pixel shader — for efficiency, when original tangents are not provided. This works well for most assets, but may not work as well for others.

If you have an...

  • Asset that needs to render predictably in many engines
  • Asset Pipeline that needs to produce assets with predictable normal map behavior
  • Engine that needs to support arbitrary assets perfectly (and can afford the per-vertex pre-processing)

...then MikkTSpace vertex tangents may resolve or prevent rendering issues with normal maps.

correct incorrect
correct rendering incorrect rendering

Figure: Flight Helmet glTF 2.0 sample, shown with correct (left) and incorrect (right) vertex tangents.

Other considerations

The MikkTSpace algorithm requires unindexed (unwelded) triangles as input. It is safe to create an index (welding vertices whose tangents and other attributes are identical) after generating tangents, but you cannot reuse prior indices after generating tangents. This additional cost is, perhaps, why some realtime engines choose to generate tangents with cheaper alternative algorithms, when pre-computed tangents are not provided with the asset.

When generating vertex tangents for glTF 2.0 assets, you will want to flip the sign of the tangents (tangent.w *= -1) before storing them in the glTF file. While MikkTSpace does not document a particular UV convention that I could find, this appears to be a necessary conversion to the texture coordinate convention used in glTF.

Quickstart

Installation:

npm install --save mikktspace

The mikktspace package includes two entrypoints. For modern projects, the default entrypoint uses ES Modules:

import { generateTangents } from 'mikktspace';

const tangents = generateTangents(positions, normals, uvs); // → Float32Array

Node.js does not yet support ES Modules with WebAssembly particularly well (as of Node.js v14), so the mikktspace package also provides a CommonJS entrypoint. The CommonJS entrypoint works only in Node.js.

const { generateTangents } = require('mikktspace');

const tangents = generateTangents(positions, normals, uvs); // → Float32Array

API

generateTangents

Generates vertex tangents for the given position/normal/texcoord attributes. Triangles of the input geometry must be unindexed/unwelded.

Parameters

Returns

Float32Array

Contributing

  1. Install Rust and wasm-pack
  2. Install local dependencies: yarn install
  3. Build: yarn dist
  4. Test: yarn test

Credits

This WebAssembly library is made possible by the gltf-rs/mikktspace project, and by the MikkTSpace standard created by Morten S. Mikkelsen.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].