Script: Split Shape Example In TypeScript

Split Shape Example In TypeScript picture
Type
Typescript logo indicatortypescript
Date Created
Feb 6, 2025, 11:29:15 AM
Last Edit Date
Feb 6, 2025, 11:40:09 AM

Project Information

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

Script Code

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 & Pricing

Choose Your Plan

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

B2B

ENTERPRISE

Custom pricing

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

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