Skip to content

Commit

Permalink
better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
yofreke committed Sep 21, 2016
1 parent 75e03cd commit 97bc5e6
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions js/deformers/three/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ export default class ThreeDeformer extends Deformer {
const texture = new Texture(srcElement);
texture.minFilter = LinearFilter;
const maskMaterial = this.maskMesh.material;
// maskMaterial.map = texture;
maskMaterial.map = texture;
// Un-set the defaults
// maskMaterial.wireframe = false;
// maskMaterial.color.set(0xffffff);
maskMaterial.wireframe = false;
maskMaterial.color.set(0xffffff);
return;
}

Expand All @@ -117,25 +117,32 @@ export default class ThreeDeformer extends Deformer {

const geom = this.maskMesh.geometry;
geom.faceVertexUvs = [[]];
const faceVertexUvs = geom.faceVertexUvs[0];
geom.faces = [];
geom.vertices = [];

for (let i = 0; i < this._maskTextureCoord.length; i += 6) {
const vertIndex = Math.floor(i / 6 * 3);
// Standin verts
geom.vertices[vertIndex] = new Vector3();
geom.vertices[vertIndex + 1] = new Vector3();
geom.vertices[vertIndex + 2] = new Vector3();
// Add a face
geom.faces.push(new Face3(
vertIndex,
vertIndex + 1,
vertIndex + 2
));
// Texture it
geom.faceVertexUvs[0].push([
faceVertexUvs.push([
new Vector2(this._maskTextureCoord[i], this._maskTextureCoord[i + 1]),
new Vector2(this._maskTextureCoord[i + 2], this._maskTextureCoord[i + 3]),
new Vector2(this._maskTextureCoord[i + 4], this._maskTextureCoord[i + 5])
]);

// geom.faceUvs[0].push(new Vector2(0, 1));
}

geom.uvsNeedUpdate = true;
geom.elementsNeedUpdate = true;
}

private updateMaskGeom (points: number[][]): void {
Expand All @@ -150,24 +157,21 @@ export default class ThreeDeformer extends Deformer {

for (let i = 0; i < maskVertices.length; i += 6) {
const vertIndex = Math.floor(i / 6 * 3);
geom.vertices[vertIndex] = new Vector3(
(maskVertices[i] * this.bgScaleX) + offsetX,
(bgH - (maskVertices[i + 1] * this.bgScaleY)) + offsetY,
0
);
geom.vertices[vertIndex + 1] = new Vector3(
(maskVertices[i + 2] * this.bgScaleX) + offsetX,
(bgH - (maskVertices[i + 3] * this.bgScaleY)) + offsetY,
0
);
geom.vertices[vertIndex + 2] = new Vector3(
(maskVertices[i + 4] * this.bgScaleX) + offsetX,
(bgH - (maskVertices[i + 5] * this.bgScaleY)) + offsetY,
0
);

const v1 = geom.vertices[vertIndex];
v1.x = (maskVertices[i] * this.bgScaleX) + offsetX;
v1.y = (bgH - (maskVertices[i + 1] * this.bgScaleY)) + offsetY;

const v2 = geom.vertices[vertIndex + 1];
v2.x = (maskVertices[i + 2] * this.bgScaleX) + offsetX;
v2.y = (bgH - (maskVertices[i + 3] * this.bgScaleY)) + offsetY;

const v3 = geom.vertices[vertIndex + 2];
v3.x = (maskVertices[i + 4] * this.bgScaleX) + offsetX;
v3.y = (bgH - (maskVertices[i + 5] * this.bgScaleY)) + offsetY;
}

geom.elementsNeedUpdate = true;
geom.verticesNeedUpdate = true;
}

public draw (points: number[][]): void {
Expand Down

0 comments on commit 97bc5e6

Please sign in to comment.