Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 44 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { ProcessAction, processDataTable } from './process';
import { isCompressedPly, decompressPly } from './readers/decompress-ply';
import { readKsplat } from './readers/read-ksplat';
import { readMjs, Param } from './readers/read-mjs';
import { readPly } from './readers/read-ply';
import { readSplat } from './readers/read-splat';
import { readSpz } from './readers/read-spz';
Expand All @@ -29,35 +30,40 @@
cameraTarget: Vec3
};

const readFile = async (filename: string) => {
console.log(`reading '${filename}'...`);
const inputFile = await open(filename, 'r');

const readFile = async (filename: string, params: Param[]) => {
const lowerFilename = filename.toLowerCase();
let fileData;

if (lowerFilename.endsWith('.ksplat')) {
fileData = await readKsplat(inputFile);
} else if (lowerFilename.endsWith('.splat')) {
fileData = await readSplat(inputFile);
} else if (lowerFilename.endsWith('.ply')) {
const ply = await readPly(inputFile);
if (isCompressedPly(ply)) {
fileData = {
comments: ply.comments,
elements: [{ name: 'vertex', dataTable: decompressPly(ply) }]
};
console.log(`reading '${filename}'...`);

if (lowerFilename.endsWith('.mjs')) {
fileData = await readMjs(filename, params);
} else {
const inputFile = await open(filename, 'r');

if (lowerFilename.endsWith('.ksplat')) {
fileData = await readKsplat(inputFile);
} else if (lowerFilename.endsWith('.splat')) {
fileData = await readSplat(inputFile);
} else if (lowerFilename.endsWith('.ply')) {
const ply = await readPly(inputFile);
if (isCompressedPly(ply)) {
fileData = {
comments: ply.comments,
elements: [{ name: 'vertex', dataTable: decompressPly(ply) }]
};
} else {
fileData = ply;
}
} else if (lowerFilename.endsWith('.spz')) {
fileData = await readSpz(inputFile);
} else {
fileData = ply;
await inputFile.close();
throw new Error(`Unsupported input file type: ${filename}`);
}
} else if (lowerFilename.endsWith('.spz')) {
fileData = await readSpz(inputFile);
} else {

await inputFile.close();
throw new Error(`Unsupported input file type: ${filename}`);
}

await inputFile.close();
return fileData;
};

Expand Down Expand Up @@ -229,7 +235,8 @@
scale: { type: 'string', short: 's', multiple: true },
filterNaN: { type: 'boolean', short: 'n', multiple: true },
filterByValue: { type: 'string', short: 'c', multiple: true },
filterBands: { type: 'string', short: 'b', multiple: true }
filterBands: { type: 'string', short: 'b', multiple: true },
param: { type: 'string', short: 'P', multiple: true }
}
});

Expand Down Expand Up @@ -338,6 +345,15 @@

break;
}
case 'param': {
const parts = t.value.split('=').map((p: string) => p.trim());
current.processActions.push({
kind: 'param',
name: parts[0],
value: parts[1] ?? ''
});
break;
}
}
}
}
Expand Down Expand Up @@ -417,7 +433,11 @@
try {
// read, filter, process input files
const inputFiles = (await Promise.all(inputArgs.map(async (inputArg) => {
const file = await readFile(resolve(inputArg.filename));
// extract params
const params = inputArg.processActions.filter(a => a.kind === 'param').map((p) => { return { name: p.name, value: p.value }; });

Check failure on line 437 in src/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block

Check failure on line 437 in src/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Statement inside of curly braces should be on next line

// read input
const file = await readFile(resolve(inputArg.filename), params);

// filter out non-gs data
if (file.elements.length !== 1 || file.elements[0].name !== 'vertex') {
Expand Down
12 changes: 11 additions & 1 deletion src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ type FilterBands = {
value: 0 | 1 | 2 | 3;
};

type ProcessAction = Translate | Rotate | Scale | FilterNaN | FilterByValue | FilterBands;
type Param = {
kind: 'param';
name: string;
value: string;
};

type ProcessAction = Translate | Rotate | Scale | FilterNaN | FilterByValue | FilterBands | Param;

const shNames = new Array(45).fill('').map((_, i) => `f_rest_${i}`);

Expand Down Expand Up @@ -128,6 +134,10 @@ const processDataTable = (dataTable: DataTable, processActions: ProcessAction[])
}
break;
}
case 'param': {
// skip params
break;
}
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/readers/read-mjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Column, DataTable } from '../data-table';

type SplatData = {
comments: string[];
elements: {
name: string,
dataTable: DataTable
}[];
};

type Param = {
name: string;
value: string;
};

type Generator = {
constructor(params: Param[]): void;

Check failure on line 17 in src/readers/read-mjs.ts

View workflow job for this annotation

GitHub Actions / Lint

Interfaces cannot be constructed, only classes
count: number;
columnNames: string[];
getRow: (index: number, row: any) => void;
};

const readMjs = async (filename: string, params: Param[]): Promise<SplatData> => {
const module = await import(filename);
if (!module) {
throw new Error(`Failed to load module: ${filename}`);
}

const generator = await (module.Generator?.create(params) as Generator);

if (!generator) {
throw new Error(`Failed to create Generator instance: ${filename}`);
}

const columns: Column[] = generator.columnNames.map((name: string) => {
return new Column(name, new Float32Array(generator.count));
});

const row: any = {};
for (let i = 0; i < generator.count; ++i) {
generator.getRow(i, row);
columns.forEach((c) => {
c.data[i] = row[c.name];
});
}

return {
comments: [],
elements: [{
name: 'vertex',
dataTable: new DataTable(columns)
}]
};
};

export { Param, readMjs };
Loading