npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ankhzet/goo

v0.0.2

Published

Elegoo .goo file format reader/writer

Downloads

126

Readme

@ankhzet/goo

Elegoo .goo file format reader/writer

Reading from .goo files

const filePath = path.resolve('./test.goo');
const binaryReader = new BinaryReader(await fs.open(filePath));
const gooReader = new GooReader(binaryReader);

const goo = await gooReader.read();

console.log(goo); // { header: { ... }, layers: [...] }

for (const { dimensions, input } of goo.header.previews) {
    // save preview image into file
    await saveImage({
        input,
        dimensions: dimensions,
        pathname: path.resolve(`./preview-${dimensions.x}x${dimensions.y}.png`),
    });
}

for (const [index, { slice }] of read.layers.entries()) {
    // save slice image into file
    await saveImage({
        input: slice,
        dimensions: goo.header.printer.resolution,
        pathname: path.resolve(`./layer-${index}.png`),
    });
}

Writing to .goo files

const outPath = path.resolve('<path>/test.goo');
const previewPath = path.resolve('<path>/preview.png');
const slicePath = path.resolve('<path>/preview.png');

const binaryWriter = new BinaryWriter(1024 * 1024);
const gooWriter = new GooWriter(binaryWriter);
const previews = [116, 290].map((size): GooPreview => ({
    dimensions: { x: size, y: size },
    input: previewPath,
}));
const layerHeight = 0.05;
const layers: GooLayer[] = [<GooLayer>{
    slice: slicePath,
    definition: {
        pause: {
            mode: 0,
            z: 100,
        },
        z: layerHeight * 0 + layerHeight,
        exposure: 5,
        offTime: 0.1,
        times: {
            before: {
                lift: 0,
            },
            after: {
                lift: 0,
                retract: 0,
            },
        },
        motions: {
            lift: {
                first: {
                    distance: 5.0,
                    speed: 65.0,
                },
                second: {
                    distance: 0,
                    speed: 0,
                },
            },
            retract: {
                first: {
                    distance: 5.0,
                    speed: 150.0,
                },
                second: {
                    distance: 0,
                    speed: 0,
                },
            },
        },
        pwm: 255,
    },
    transform: {
        invert: false,
        translate: {
            x: 0,
            y: 0,
        },
        scale: 1.0,
        rotate: {
            angle: 0,
            origin: { x: 0, y: 0 },
        },
    },
}];
const goo = {
    header: {
        date: new Date(),
        printer: PRINTER_MARS_4_ULTRA_9K,
        layers: layers.length,
        previews,

        layerConfig: {
            bottomLayers: 1,
            transitionLayers: 1,
            thickness: 0.05,
            bottomExposure: 10,
            commonExposure: 10,
            exposureDelay: true,
            turnOffTime: 0.1,
            advance: false,
            timings: {
                bottom: {
                    before: {
                        lift: 0,
                    },
                    after: {
                        lift: 0,
                        retract: 0,
                    },
                },
                common: {
                    before: {
                        lift: 0,
                    },
                    after: {
                        lift: 0,
                        retract: 0,
                    },
                },
            },
            motions: {
                first: {
                    lift: {
                        bottom: {
                            distance: 5.0,
                            speed: 65.0,
                        },
                        common: {
                            distance: 5.0,
                            speed: 65.0,
                        },
                    },
                    retract: {
                        bottom: {
                            distance: 5.0,
                            speed: 150.0,
                        },
                        common: {
                            distance: 5.0,
                            speed: 150.0,
                        },
                    },
                },
                second: {
                    lift: {
                        common: {
                            distance: 0,
                            speed: 0,
                        },
                        bottom: {
                            distance: 0,
                            speed: 0,
                        },
                    },
                    retract: {
                        common: {
                            distance: 0,
                            speed: 0,
                        },
                        bottom: {
                            distance: 0,
                            speed: 0,
                        },
                    },
                },
            },
            pwm: {
                bottom: 255,
                common: 255,
            },
        },
        summary: {
            price: 9.99,
            currency: 'USD',
            time: layers.reduce((acc, layer) => acc + layerTime(layer), 0),
            volume: 100.0,
            weight: 100.0,
        },
    },
    layers,
};

await fs.rm(outPath, { force: true }); // remove old file
const out = await fs.open(outPath, 'w+');

try {
    await gooWriter.write(goo, (buffer) => out.write(buffer));
} finally {
    await out.close();
}

Printer definitions

const PRINTER_MARS_4_ULTRA_9K: PrinterDefinition = {
    name: 'ELEGOO Mars 4 Ultra 9K',
    type: 'MSLA',
    resolution: { x: 8520, y: 4320 },
    platform: { x: 153.36, y: 77.76, z: 165 },
    mirror: { x: true, y: false },
    resinProfile: 'PCB', // unused
    grayscale: true,
    antialiasing: 4,
    blur: 2,
    gray: 5,
};

Filling Goo structure

When constructing Goo instance, image fields can be either paths to the file (all formats supported by sharp library out of the box should be supported), or actual image color channels data:

type ImageChannels = 1|2|3|4;
type ImageDescriptor = string | {
    buffer: Buffer;
    channels: ImageChannels;
};

Previews:

// this would be used for preview
const previewPath = path.resolve('<path>/preview.png');

// 116 and 290 are hardcoded in the `.goo` specification
const previews = [116, 290].map((size) => ({
    dimensions: { x: size, y: size },
    input: previewPath,
}));

Layers:

// images of slices themselves
const slicePaths = [
    path.resolve('<path>/layer-0.png'),
    path.resolve('<path>/layer-1.png'),
    path.resolve('<path>/layer-2.png'),
    ...
];
// depends on printer, resin, timings etc.
const layerHeight = 0.05;

// all settings in this example are tuned for a one-layer `.goo` file, used to burn PCB pattern on the photoresist
const layers = slicePaths.map((slice, index) => ({
    // slice image path
    slice,

    // all fields have documentation, with value types specified (seconds, pixels, mm etc.)
    definition: {
        pause: {
            mode: 0,
            z: 100,
        },
        z: layerHeight * index + layerHeight,
        exposure: 5,
        offTime: 0.1,
        times: {
            before: {
                lift: 0,
            },
            after: {
                lift: 0,
                retract: 0,
            },
        },
        motions: {
            lift: {
                first: {
                    distance: 5.0,
                    speed: 65.0,
                },
                second: {
                    distance: 0,
                    speed: 0,
                },
            },
            retract: {
                first: {
                    distance: 5.0,
                    speed: 150.0,
                },
                second: {
                    distance: 0,
                    speed: 0,
                },
            },
        },
        pwm: 255,
    },
    transform: {
        invert: false,
        translate: {
            x: 0,
            y: 0,
        },
        scale: 1.0,
        rotate: {
            angle: 0,
            origin: { x: 0, y: 0 },
        },
    },
}));

Goo:

const goo = {
    header: {
        date: new Date(),
        printer: PRINTER_MARS_4_ULTRA_9K,
        layers: layers.length,
        previews,

        layerConfig: {
            bottomLayers: 1,
            transitionLayers: 1,
            thickness: layerHeight,
            bottomExposure: 10,
            commonExposure: 10,
            exposureDelay: true,
            turnOffTime: 0.1,
            advance: false,
            timings: {
                bottom: {
                    before: {
                        lift: 0,
                    },
                    after: {
                        lift: 0,
                        retract: 0,
                    },
                },
                common: {
                    before: {
                        lift: 0,
                    },
                    after: {
                        lift: 0,
                        retract: 0,
                    },
                },
            },
            motions: {
                first: {
                    lift: {
                        bottom: {
                            distance: 5.0,
                            speed: 65.0,
                        },
                        common: {
                            distance: 5.0,
                            speed: 65.0,
                        },
                    },
                    retract: {
                        bottom: {
                            distance: 5.0,
                            speed: 150.0,
                        },
                        common: {
                            distance: 5.0,
                            speed: 150.0,
                        },
                    },
                },
                second: {
                    lift: {
                        common: {
                            distance: 0,
                            speed: 0,
                        },
                        bottom: {
                            distance: 0,
                            speed: 0,
                        },
                    },
                    retract: {
                        common: {
                            distance: 0,
                            speed: 0,
                        },
                        bottom: {
                            distance: 0,
                            speed: 0,
                        },
                    },
                },
            },
            pwm: {
                bottom: 255,
                common: 255,
            },
        },
        summary: {
            price: 9.99,
            currency: 'USD',
            time: layers.reduce((acc, layer) => acc + layerTime(layer), 0),
            volume: 100.0,
            weight: 100.0,
        },
    },
    layers,
};