JSFiddle - React, Tailwind, and code Playground
by georgie
HTML
<script src="https://rawgit.com/r3mi/poly2tri.js/master/dist/poly2tri.js"></script>
<script src="https://rawgit.com/lodash/lodash/master/lodash.js"></script>
<script src="https://rawgit.com/GoodBoyDigital/pixi.js/master/bin/pixi.js"></script>
JavaScript
var verticesToContour = function(list){
var results = [];
for(var i = 0; i < list.length; i+=2){
results.push({x:list[i], y:list[i+1]})
}
return results;
}
var contourToVertices = function(list){
var results = [];
for(var i = 0; i < list.length; i++){
results.push(list[i].x, list[i].y)
}
return results;
}
var _renderCanvasDrawTriangle = function (context, vertices, uvs, index0, index1, index2)
{
var textureSource = this._texture.baseTexture.source;
var textureWidth = this._texture.baseTexture.width;
var textureHeight = this._texture.baseTexture.height;
var x0 = vertices[index0], x1 = vertices[index1], x2 = vertices[index2];
var y0 = vertices[index0 + 1], y1 = vertices[index1 + 1], y2 = vertices[index2 + 1];
var u0 = uvs[index0] * textureWidth, u1 = uvs[index1] * textureWidth, u2 = uvs[index2] * textureWidth;
var v0 = uvs[index0 + 1] * textureHeight, v1 = uvs[index1 + 1] * textureHeight, v2 = uvs[index2 + 1] * textureHeight;
this.canvasPadding = 1;
if (this.canvasPadding > 0)
{
var paddingX = this.canvasPadding / this.worldTransform.a;
var paddingY = this.canvasPadding / this.worldTransform.d;
var centerX = (x0 + x1 + x2) / 3;
var centerY = (y0 + y1 + y2) / 3;
var normX = x0 - centerX;
var normY = y0 - centerY;
var dist = Math.sqrt(normX * normX + normY * normY);
x0 = centerX + (normX / dist) * (dist + paddingX);
y0 = centerY + (normY / dist) * (dist + paddingY);
//
normX = x1 - centerX;
normY = y1 - centerY;
dist = Math.sqrt(normX * normX + normY * normY);
x1 = centerX + (normX / dist) * (dist + paddingX);
y1 = centerY + (normY / dist) * (dist + paddingY);
normX = x2 - centerX;
normY = y2 -...