Drawing Dynamic Text - Code Contribution

22 августа 2018 14:10
I have implemented the following function textPoints(string, scale)
which borrows from OpenJSCAD module text the function
vector_text(0, 0, string); // get line segments [ [ [x1,y1], [x2,y2] ...], [ ]... ]

The output is passed to draw_line as following
m_geom.draw_line(empty, new Float32Array(engine3d.textPoints('Blend4Web Rules', 0.05)), true);

Below is my code without the JSCAD code that is open source.
    textPoints: function (string, scale) {
        const points = [];

        const processPair = function (p0, p1) {
            points.push(p0[0] * scale);// x0
            points.push(p0[1] * scale);// y0
            points.push(0);            // z0
            points.push(p1[0] * scale);// x1
            points.push(p1[1] * scale);// y1
            points.push(0);            // z1
            //
            points.push(p0[0] * scale);// x2
            points.push(p0[1] * scale);// y2
            points.push(0);            // z2
            points.push(p1[0] * scale);// x3
            points.push(p1[1] * scale);// y3
            points.push(0);            // z3
        }

        // get line segments [ [ [x1,y1], [x2,y2] ...], [ ]... ]
        const stringLines = JSCAD.text.vector_text(0, 0, string);

        for (let i = 0, lena = stringLines.length; i < lena; i++) {
            const letterPoints = stringLines[i];
            for (let j = 0, lenb = letterPoints.length - 1; j < lenb; j++) {
                processPair(letterPoints[j], letterPoints[j + 1]);
            }
        }
        return points;
    }

This how it looks
 
Пожалуйста, зарегистрируйтесь или войдите под своей учетной записью , чтобы оставлять сообщения.