Script TS TypeScript Free

Split Shape Example In TypeScript

Split Shape Example In TypeScript picture
Author
bitbybit
Created
Feb 6, 2025, 10:29:15 AM
Last edit
Feb 6, 2025, 10:40:09 AM

Edit scriptPreview

Project

Split shape with shapes

New OCCT feature implemented that allows to split shape with multiple shapes in destructive and non-destructive modes via BOPAlgo_Builder functionality

View full project
const bending = 5;

const dirLightOpt = new Bit.Inputs.BabylonScene.DirectionalLightDto();
dirLightOpt.intensity = 3;
dirLightOpt.shadowGeneratorMapSize = 3000;
bitbybit.babylon.scene.drawDirectionalLight(dirLightOpt);

const start = async () => {
    const line1 = await bitbybit.occt.shapes.wire.createLineWire({
        start: [5, bending, -5],
        end: [-5, -bending, -5]
    });
    const line2 = await bitbybit.occt.shapes.wire.createLineWire({
        start: [5, -bending, 5],
        end: [-5, bending, 5]
    });

    const loft = await bitbybit.occt.operations.loft({
        shapes: [line1, line2],
        makeSolid: false,
    });

    const span = bitbybit.vector.span({
        min: -2,
        max: 2,
        step: 0.3,
    });

    const vectors = span.map(y => [0, y, 0] as Bit.Inputs.Base.Vector3);

    const translationPromises = vectors.map(v => bitbybit.occt.transforms.translate({ shape: loft, translation: v }));
    const translatedShapes = await Promise.all(translationPromises);

    const sphere = await bitbybit.occt.shapes.solid.createSphere({
        radius: 3,
        center: [0, 0, 0],
    });

    const splitShapes = await bitbybit.occt.operations.splitShapeWithShapes({
        shape: sphere,
        shapes: translatedShapes,
        nonDestructive: false,
        localFuzzyTolerance: 1e-4
    });

    const removedSplitShapes = bitbybit.lists.removeItemsAtIndexes({
        list: splitShapes,
        indexes: [0, 3, 4, 7, 8, 11, 12],
    });

    const compoundSplitShapes = await bitbybit.occt.shapes.compound.makeCompound({
        shapes: removedSplitShapes
    });

    const drawOpt = new Bit.Inputs.Draw.DrawOcctShapeOptions();
    drawOpt.faceColour = "#7300ff";
    drawOpt.precision = 0.001;
    bitbybit.draw.drawAnyAsync({
        entity: compoundSplitShapes,
        options: drawOpt
    });
}

start();

Plans and pricing

Choose your plan

Editor plans for 3D development, API keys for server-side CAD algorithms

EnterpriseB2BCustompricing

Custom software development, dedicated servers and CAD automation at scale.

Learn moreContact us

CAD automation and software
  • Custom software development
  • Cloud CAD automation pipelines
  • 3D configurators (STEP & GLTF)
  • Batch export jobs
  • Custom algorithms & deployment
Infrastructure and support
  • Custom compute allocation
  • Dedicated / VPS server tenants
  • Long-running computation jobs
  • Custom upload limits & overage
  • SLA & premium support

All prices exclude applicable taxesView all plan details

Contact

Talk to us

Tell us what you are building or what is blocking you, through whichever channel suits you.