gulp-structify
Generates WebGL-compatible structs and struct buffers from a template file.
Install
npm install gulp-structify --save
Create a template file:
Suppose we want to create a Vec2 struct backed by a Float32Array. We start with a minimal template file called Vec2.template.ts:
import {Template} from "gulp-structify/template"; /** * A two-dimensional vector with (x,y) components. */class Vec2 extends Template<Float32Array> { /** * The X component of this Vec2. */ x: number; /** * The Y component of this Vec2. */ y: number;}Note: the template should not include a constructor or any static methods.
Add methods to the template
Now suppose we want to add a dot method to our Vec2 struct. We do this by adding the method to our template:
// ...class Vec2 extends Template<Float32Array> { // ... /** * Computes the dot product of this Vec2 with the other Vec2. */ dot(other: Vec2): number { return this.x * other.x + this.y * other.y; }} Note: gulp-structify automatically generates the following methods:
set(other: this)setScalar(k: number)add(other: this)subtract(other: this)mulScalar(k: number)divScalar(k: number)equals(other: this)equalsScalar(k: number)epsilonEquals(other: this, e: number)epsilonEqualsScalar(k: number, e: number)toString()
Create gulp task
var gulp = ;var rename = ;var structify = ; // Directory where template file is locatedvar directory = "./"; gulp;Run gulp task
gulp structify
Examples
| Template | Output | Usage |
|---|---|---|
| point.template.ts | point.ts | |
| vec2.template.ts | vec2.ts | |
| color.template.ts | color.ts |
