How to use the @pixi/utils.earcut function in @pixi/utils

To help you get started, we’ve selected a few @pixi/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pixijs / pixi.js / packages / graphics / src / utils / buildPoly.js View on Github external
if (points.length >= 6)
        {
            const holeArray = [];
            // Process holes..

            for (let i = 0; i < holes.length; i++)
            {
                const hole = holes[i];

                holeArray.push(points.length / 2);
                points = points.concat(hole.points);
            }

            // sort color
            const triangles = earcut(points, holeArray, 2);

            if (!triangles)
            {
                return;
            }

            const vertPos = verts.length / 2;

            for (let i = 0; i < triangles.length; i += 3)
            {
                indices.push(triangles[i] + vertPos);
                indices.push(triangles[i + 1] + vertPos);
                indices.push(triangles[i + 2] + vertPos);
            }

            for (let i = 0; i < points.length; i++)
github pixijs / pixi.js / packages / graphics / src / utils / buildRoundedRectangle.js View on Github external
triangulate(graphicsData, graphicsGeometry)
    {
        const points = graphicsData.points;

        const verts = graphicsGeometry.points;
        const indices = graphicsGeometry.indices;

        const vecPos = verts.length / 2;

        const triangles = earcut(points, null, 2);

        for (let i = 0, j = triangles.length; i < j; i += 3)
        {
            indices.push(triangles[i] + vecPos);
            //     indices.push(triangles[i] + vecPos);
            indices.push(triangles[i + 1] + vecPos);
            //   indices.push(triangles[i + 2] + vecPos);
            indices.push(triangles[i + 2] + vecPos);
        }

        for (let i = 0, j = points.length; i < j; i++)
        {
            verts.push(points[i], points[++i]);
        }
    },
};
github pixijs / pixi.js / packages / graphics / src / utils / buildPoly.js View on Github external
}

        // get first and last point.. figure out the middle!
        const verts = webGLData.points;
        const indices = webGLData.indices;

        const length = points.length / 2;

        // sort color
        const color = hex2rgb(graphicsData.fillColor);
        const alpha = graphicsData.fillAlpha;
        const r = color[0] * alpha;
        const g = color[1] * alpha;
        const b = color[2] * alpha;

        const triangles = earcut(points, holeArray, 2);

        if (!triangles)
        {
            return;
        }

        const vertPos = verts.length / 6;

        for (let i = 0; i < triangles.length; i += 3)
        {
            indices.push(triangles[i] + vertPos);
            indices.push(triangles[i] + vertPos);
            indices.push(triangles[i + 1] + vertPos);
            indices.push(triangles[i + 2] + vertPos);
            indices.push(triangles[i + 2] + vertPos);
        }
github pixijs / pixi.js / packages / graphics / src / utils / buildRoundedRectangle.js View on Github external
if (graphicsData.fill)
    {
        const color = hex2rgb(graphicsData.fillColor);
        const alpha = graphicsData.fillAlpha;

        const r = color[0] * alpha;
        const g = color[1] * alpha;
        const b = color[2] * alpha;

        const verts = webGLData.points;
        const indices = webGLData.indices;

        const vecPos = verts.length / 6;

        const triangles = earcut(recPoints, null, 2);

        for (let i = 0, j = triangles.length; i < j; i += 3)
        {
            indices.push(triangles[i] + vecPos);
            indices.push(triangles[i] + vecPos);
            indices.push(triangles[i + 1] + vecPos);
            indices.push(triangles[i + 2] + vecPos);
            indices.push(triangles[i + 2] + vecPos);
        }

        for (let i = 0, j = recPoints.length; i < j; i++)
        {
            verts.push(recPoints[i], recPoints[++i], r, g, b, alpha);
        }
    }