-
-
Save Rojoss/83f67295f3abbdca728247611703ec9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class CurveMesh extends Mesh { | |
constructor(curve: Curve, texture: PIXI.Texture) { | |
super(texture, new Float32Array(0), new Float32Array(0), new Uint16Array(0)); | |
this.curve = curve; | |
} | |
public updateTransform(): void { | |
this.vertices = new Float32Array(this._vertices); | |
this.uvs = new Float32Array(this._uvs); | |
this.indices = new Uint16Array(this._indices); | |
// this.dirty++; | |
// this.indexDirty++; | |
} | |
public addPoint(): void { | |
const i = this._vertices.length; | |
const pos = this.curve.getPosition(); | |
// Get the left and right points based on the position, direction and radius of the line. | |
const points = this.calculateVertices(pos, this.curve.radius.getValue(), this.curve.getAngle()); | |
this._vertices.push(points[1].x, points[1].y, points[0].x, points[0].y); | |
const u = 0; // TODO: Calculate UV offset based on curve length and texture scale | |
this._uvs.push(u, 0, u, 1); | |
// tslint:disable-next-line:no-magic-numbers | |
if (this._vertices.length < 8) { /* 8 = 4 vertices = 2 points */ | |
return; | |
} | |
// Create 2 triangles... (tried many different ways) | |
this._indices.push(i-2, i, i+1); | |
this._indices.push(i-2, i+1, i-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment