Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/asset-loader.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { getInputFormat, ReadFileSystem } from '@playcanvas/splat-transform';
import { AppBase, Asset, GSplatResource, Vec3 } from 'playcanvas';
import { ReadFileSystem } from '@playcanvas/splat-transform';
import { AppBase, Asset, GSplatResource } from 'playcanvas';

import { Events } from './events';
import { loadGSplatData, validateGSplatData } from './io';
import { Splat } from './splat';

const getOrientation = (filename: string) => {
switch (getInputFormat(filename)) {
case 'spz':
return new Vec3(0, 0, 0);
case 'lcc':
return new Vec3(90, 0, 180);
default:
return new Vec3(0, 0, 180);
}
};

// handles loading gsplat assets using splat-transform
class AssetLoader {
app: AppBase;
Expand All @@ -33,14 +22,14 @@ class AssetLoader {

try {
// Skip reordering for animation frames (speed) or when explicitly requested (already ordered)
const gsplatData = await loadGSplatData(filename, fileSystem, skipReorder || animationFrame);
const { gsplatData, transform } = await loadGSplatData(filename, fileSystem, skipReorder || animationFrame);
validateGSplatData(gsplatData);

const asset = new Asset(filename, 'gsplat', { url: `local-asset-${Date.now()}`, filename });
this.app.assets.add(asset);
asset.resource = new GSplatResource(this.app.graphicsDevice, gsplatData);

return new Splat(asset, getOrientation(filename));
return new Splat(asset, transform.rotation);
Comment thread
slimbuck marked this conversation as resolved.
} finally {
if (!animationFrame) {
this.events.fire('stopSpinner');
Expand Down
12 changes: 9 additions & 3 deletions src/io/read/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import {
DataTable,
Options,
ReadFileSystem,
Transform,
ZipReadFileSystem
} from '@playcanvas/splat-transform';
import { GSplatData } from 'playcanvas';

type LoadResult = {
gsplatData: GSplatData;
transform: Transform;
};

/**
* Default options for readFile.
*/
Expand Down Expand Up @@ -79,7 +85,7 @@ const dataTableToGSplatData = (dataTable: DataTable): GSplatData => {
* @param fileSystem - The file system to read from
* @param skipReorder - Skip morton reordering (for files already in morton order or animation playback)
*/
const loadGSplatData = async (filename: string, fileSystem: ReadFileSystem, skipReorder?: boolean): Promise<GSplatData> => {
const loadGSplatData = async (filename: string, fileSystem: ReadFileSystem, skipReorder?: boolean): Promise<LoadResult> => {
const inputFormat = getInputFormat(filename);
const lowerFilename = filename.toLowerCase();

Expand All @@ -95,7 +101,7 @@ const loadGSplatData = async (filename: string, fileSystem: ReadFileSystem, skip
params: [],
fileSystem: zipFs
});
return dataTableToGSplatData(tables[0]);
return { gsplatData: dataTableToGSplatData(tables[0]), transform: tables[0].transform };
} finally {
zipFs.close();
}
Expand Down Expand Up @@ -127,7 +133,7 @@ const loadGSplatData = async (filename: string, fileSystem: ReadFileSystem, skip

// Convert to GSplatData (use first table, as most formats return single table)
// LCC may return multiple tables for different LOD levels - we use the first (highest detail)
return dataTableToGSplatData(tables[0]);
return { gsplatData: dataTableToGSplatData(tables[0]), transform: tables[0].transform };
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/splat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Splat extends Element {

rebuildMaterial: (bands: number) => void;

constructor(asset: Asset, orientation: Vec3) {
constructor(asset: Asset, rotation: Quat) {
super(ElementType.splat);

const splatResource = asset.resource as GSplatResource;
Expand All @@ -86,7 +86,7 @@ class Splat extends Element {
this.numSplats = splatData.numSplats;

this.entity = new Entity('splatEntitiy');
this.entity.setEulerAngles(orientation);
this.entity.setLocalRotation(rotation);
this.entity.addComponent('gsplat', { asset });

const instance = this.entity.gsplat.instance;
Expand Down