Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow asset to specify which ply elements to load #5810

Merged
merged 1 commit into from Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion extras/index.js
Expand Up @@ -5,7 +5,7 @@ export { UsdzExporter } from './exporters/usdz-exporter.js';
export { GltfExporter } from './exporters/gltf-exporter.js';

// splat
export { registerPlyParser } from './splat/ply-parser.js';
export { registerPlyParser, getDefaultPlyElements } from './splat/ply-parser.js';
export { Splat } from './splat/splat.js';
export { SplatData } from './splat/splat-data.js';
export { SplatInstance } from './splat/splat-instance.js';
20 changes: 11 additions & 9 deletions extras/splat/ply-parser.js
Expand Up @@ -3,13 +3,11 @@ import { SplatData } from './splat-data.js';
import { readPly } from './ply-reader.js';

// filter out element data we're not going to use
const elements = [
const defaultElements = [
'x', 'y', 'z',
'red', 'green', 'blue',
'opacity',
'f_dc_0', 'f_dc_1', 'f_dc_2',
'scale_0', 'scale_1', 'scale_2',
'rot_0', 'rot_1', 'rot_2', 'rot_3'
'f_dc_0', 'f_dc_1', 'f_dc_2', 'opacity',
'rot_0', 'rot_1', 'rot_2', 'rot_3',
'scale_0', 'scale_1', 'scale_2'
];

class PlyParser {
Expand All @@ -25,9 +23,9 @@ class PlyParser {
this.maxRetries = maxRetries;
}

async load(url, callback) {
async load(url, callback, asset) {
const response = await fetch(url.load);
readPly(response.body.getReader(), new Set(elements))
readPly(response.body.getReader(), new Set(asset.data.elements ?? defaultElements))
.then((response) => {
callback(null, new SplatContainerResource(this.device, new SplatData(response)));
})
Expand All @@ -46,4 +44,8 @@ const registerPlyParser = (app) => {
containerHandler.parsers.ply = new PlyParser(app.graphicsDevice, app.assets, app.loader.maxRetries);
};

export { registerPlyParser };
const getDefaultPlyElements = () => {
return defaultElements.slice();
};

export { registerPlyParser, getDefaultPlyElements };