Skip to content

Conversation

@slimbuck
Copy link
Member

@slimbuck slimbuck commented Sep 23, 2025

This PR adds support for generating gaussians via an external script.

The script must have .mjs extension and export a class called Generator with the following structure:

class Generator {
    // number of gaussians to generate
    count: number;
    // names of the columns to generate
    columnNames: string[];
    // callback function to get the data for row 'index'
    getRow: (index: number, row: any) => void;
};

Parameters are passed to the generator from the command line using:

--params name=value,name=value

The (name,value) pairs are passed to a static create function on Generator which is responsible for constructing the instance.

This is an example grid generator script gen-grid.mjs:

class Generator {
    constructor(width, height, scale) {
        const ls = Math.log(scale);

        this.count = width * height;

        this.columnNames = [
            'x', 'y', 'z',
            'scale_0', 'scale_1', 'scale_2',
            'f_dc_0', 'f_dc_1', 'f_dc_2', 'opacity',
            'rot_0', 'rot_1', 'rot_2', 'rot_3'
        ];

        const SH_C0 = 0.28209479177387814;
        const invSigmoid = (opacity) => (opacity <= 0) ? -20 : (opacity >= 1) ? 20 : -Math.log(1 / opacity - 1);

        this.getRow = (index, row) =>{
            row.x = (index % width) * scale;
            row.y = 0;
            row.z = Math.floor(index / width) * scale;

            // e^x
            row.scale_0 = ls;
            row.scale_1 = ls;
            row.scale_2 = ls;

            row.f_dc_0 = (1 - 0.5) / SH_C0;
            row.f_dc_1 = (1 - 0.5) / SH_C0;
            row.f_dc_2 = (1 - 0.5) / SH_C0;
            row.opacity = invSigmoid(1.0);
            
            row.rot_0 = 0;
            row.rot_1 = 0;
            row.rot_2 = 0;
            row.rot_3 = 1;
        };
    }

    static create(params) {
        const w = parseInt(params.find(p => p.name === 'width')?.value ?? '1000', 10);
        const h = parseInt(params.find(p => p.name === 'height')?.value ?? '1000', 10);
        const s = parseFloat(params.find(p => p.name === 'scale')?.value ?? '1.0');

        console.log(`Generating grid ${w} x ${h} x ${s}`);

        return new Generator(w, h, s);
    }
};

export { Generator };

Which can be invoked as follows:

splat-transform gen-grid.mjs --params width=100,height=100,scale=0.1 scenes/grid.ply

@slimbuck slimbuck requested review from a team and Copilot September 23, 2025 10:04
@slimbuck slimbuck self-assigned this Sep 23, 2025
@slimbuck slimbuck added the enhancement New feature or request label Sep 23, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for generating Gaussian splat data using external MJS scripts, allowing dynamic data generation through custom generator classes. The implementation introduces a new file reader for .mjs files that can execute JavaScript modules to generate splat data programmatically.

  • Added MJS file reading capability with parameter passing support
  • Extended command-line argument parsing to handle script parameters via --param flags
  • Integrated the new MJS reader into the main file processing pipeline

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/readers/read-mjs.ts Implements the MJS file reader that loads generator scripts and produces splat data
src/process.ts Adds Param type and handles param actions in the processing pipeline
src/index.ts Integrates MJS reading, adds parameter parsing, and updates the main file reading logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@willeastcott
Copy link
Contributor

Why not check in a generators folder with an example or two?

@willeastcott
Copy link
Contributor

Also, please update the README.

@slimbuck slimbuck merged commit 4316f91 into playcanvas:main Sep 23, 2025
2 checks passed
@slimbuck slimbuck deleted the mjs-dev branch September 23, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants