Script TS TypeScript Free

Examle in TypeScript

Examle in TypeScript picture
Author
bitbybit
Created
Mar 19, 2021, 10:05:46 AM
Last edit
Dec 5, 2023, 6:00:36 PM

Edit scriptPreview

Project

Parametric lamp hood model

This example demonstrates how parametric 3D model can be produced by using NURBS framework and CAD features of BitByBit platform. Parametric lamp model can also be saved to STL format and 3D printed.

View full project
const Inputs = Bit.Inputs;

let start = async () => {

    const isocurveSegments = 70;
    const isocurveSubdivisions = 41;
    const verticalIsocurveRadius = 0.1;
    const downloadStl = false;

    const profiles = [
        bitbybit.verb.curve.ellipse.createEllipse({
            center: [0, 0, 0],
            xAxis: [2, -0.5, 2],
            yAxis: [0, -0.5, 2],
        }),
        bitbybit.verb.curve.ellipse.createEllipse({
            center: [0, 3, 0],
            xAxis: [2, 0, 0],
            yAxis: [0, 0, 4],
        }),
        bitbybit.verb.curve.ellipse.createEllipse({
            center: [0, 6, 0],
            xAxis: [4, 0, 0],
            yAxis: [0, 0, 2],
        }),
        bitbybit.verb.curve.ellipse.createEllipse({
            center: [0, 12, 0],
            xAxis: [1, 0, 0],
            yAxis: [0, 0, 2],
        }),
        bitbybit.verb.curve.ellipse.createEllipse({
            center: [0, 16, 0],
            xAxis: [2, 0.5, 0],
            yAxis: [0, 0.5, 2],
        }),
    ];

    const surface = bitbybit.verb.surface.createSurfaceByLoftingCurves({
        curves: profiles,
        degreeV: 3,
    });

    const allIsocurves = bitbybit.verb.surface.isocurvesSubdivision({
        surface,
        isocurveSegments,
        includeFirst: true,
        includeLast: true,
        useV: false,
    });

    const hullSolids = await Promise.all(allIsocurves.map(async (curve) => {
        const centers = bitbybit.verb.curve.divideByEqualArcLengthToPoints({
            curve,
            subdivision: isocurveSubdivisions,
        });
        const spheres = await bitbybit.jscad.shapes.spheresOnCenterPoints({
            centers,
            radius: verticalIsocurveRadius,
            segments: 4,
        });
        return bitbybit.jscad.hulls.hullChain({
            meshes: spheres,
        });
    }));

    const drawSolidsInput = new Inputs.Draw.DrawBasicGeometryOptions();
    drawSolidsInput.colours = '#ffffff';
    await bitbybit.draw.drawAnyAsync({ entity: hullSolids, options: drawSolidsInput });

    if (downloadStl) {
        await bitbybit.jscad.downloadSolidsSTL({
            meshes: hullSolids,
            fileName: 'bitbybit-model',
        });
    }
}

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.