Script: 3D Text Cutout TypeScript

3D Text Cutout TypeScript picture
Type
Typescript logo indicatortypescript
Author
matas
Date Created
Sep 18, 2023, 4:26:55 PM
Last Edit Date
Feb 27, 2024, 3:59:56 PM

Project Information

Example script on how to use boolean difference opertaion on 3D text to cut it out from a solid shape.

View Full Project

Script Code



const start = async () => {

    const options = new Bit.Advanced.Text3D.Text3DDto();
    options.text = "Hello World!";
    options.fontType = Bit.Advanced.Text3D.fontsEnum.Silkscreen;
    options.direction = [0, 1, 0];
    options.origin = [6, -1.5, 0.5];
    options.height = 3;
    options.originAlignment = Bit.Advanced.Text3D.recAlignmentEnum.rightTop;
    const text = await bitbybit.advanced.text3d.create(options);

    const box = await bitbybit.occt.shapes.solid.createBox({
        width: 20,
        height: 1,
        length: 5,
        center: [0, 0, 0],
    });

    const boxFilleted = await bitbybit.occt.fillets.filletEdges({
        shape: box,
        radius: 0.2,
    });

    const cutout = await bitbybit.occt.booleans.difference({
        shape: boxFilleted,
        shapes: [text.compound],
        keepEdges: false
    });

    const drawOptions = new Bit.Inputs.Draw.DrawOcctShapeOptions();
    drawOptions.faceColour = "#0000ff";

    bitbybit.draw.drawAnyAsync({
        entity: cutout,
        options: drawOptions
    });

}

start();