Skip to content

Commit cb2385e

Browse files
authored
Update engine (#340)
1 parent 5f8c0a5 commit cb2385e

File tree

5 files changed

+21
-29
lines changed

5 files changed

+21
-29
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"eslint": "^9.29.0",
4343
"eslint-import-resolver-typescript": "^4.4.3",
4444
"globals": "^16.2.0",
45-
"playcanvas": "^2.10.6",
45+
"playcanvas": "^2.11.0",
4646
"qrious": "^4.0.2",
4747
"react": "^18.3.1",
4848
"react-dom": "^18.3.1",

rollup.config.mjs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ import { copyAndWatch } from './plugins/copy-and-watch.mjs';
1616

1717
// debug, profile, release
1818
const BUILD_TYPE = process.env.BUILD_TYPE || 'release';
19-
const ENGINE_DIR = process.env.ENGINE_PATH || 'node_modules/playcanvas';
20-
21-
const ENGINE_NAME = (BUILD_TYPE === 'debug') ? 'playcanvas.dbg/src/index.js' : 'playcanvas/src/index.js';
22-
const ENGINE_PATH = path.resolve(ENGINE_DIR, 'build', ENGINE_NAME);
23-
const PCUI_DIR = path.resolve(process.env.PCUI_PATH || 'node_modules/@playcanvas/pcui');
19+
const ENGINE_DIR = path.resolve(`node_modules/playcanvas/build/playcanvas${BUILD_TYPE === 'debug' ? '.dbg' : ''}/src/index.js`);
2420

2521
const BLUE_OUT = '\x1b[34m';
2622
const BOLD_OUT = '\x1b[1m';
@@ -31,7 +27,6 @@ const title = [
3127
'Building PlayCanvas Model Viewer',
3228
`type ${BOLD_OUT}${BUILD_TYPE}${REGULAR_OUT}`,
3329
`engine ${BOLD_OUT}${ENGINE_DIR}${REGULAR_OUT}`,
34-
`pcui ${BOLD_OUT}${PCUI_DIR}${REGULAR_OUT}`
3530
].map(l => `${BLUE_OUT}${l}`).join('\n');
3631
console.log(`${BLUE_OUT}${title}${RESET_OUT}\n`);
3732

@@ -74,20 +69,13 @@ export default {
7469
image({ dom: true }),
7570
alias({
7671
entries: {
77-
'playcanvas': ENGINE_PATH,
78-
'@playcanvas/pcui': PCUI_DIR
72+
'playcanvas': ENGINE_DIR
7973
}
8074
}),
8175
commonjs(),
8276
resolve(),
8377
typescript({
84-
compilerOptions: {
85-
baseUrl: '.',
86-
paths: {
87-
'playcanvas': [ENGINE_DIR],
88-
'@playcanvas/pcui': [PCUI_DIR]
89-
}
90-
}
78+
tsconfig: './tsconfig.json'
9179
}),
9280
json(),
9381
(BUILD_TYPE !== 'debug') && terser({

src/png-exporter.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ class PngExporter {
3636
return result;
3737
};
3838

39-
const main = async () => {
40-
const lodepng = await initLodepng();
39+
const main = () => {
40+
const init = initLodepng();
41+
42+
self.onmessage = async (message) => {
43+
const lodepng = await init;
4144

42-
self.onmessage = (message) => {
4345
const data = message.data;
4446

4547
// compress

src/viewer.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,6 @@ class Viewer {
275275
observer.set('camera.multisampleSupported', multisampleSupported);
276276
observer.set('camera.multisample', multisampleSupported && observer.get('camera.multisample'));
277277

278-
// create the exporter
279-
this.pngExporter = new PngExporter();
280-
281278
// create drop handler
282279
CreateDropHandler(document.getElementById('app'), (files: Array<File>, resetScene: boolean) => {
283280
this.loadFiles(files, resetScene);
@@ -1023,6 +1020,12 @@ class Viewer {
10231020

10241021
downloadPngScreenshot() {
10251022
const texture = this.camera.camera.renderTarget.colorBuffer;
1023+
1024+
// construct exporter on demand
1025+
if (!this.pngExporter) {
1026+
this.pngExporter = new PngExporter();
1027+
}
1028+
10261029
texture.read(0, 0, texture.width, texture.height).then((typedArray: Uint32Array) => {
10271030
this.pngExporter.export(
10281031
'model-viewer.png',
@@ -1156,8 +1159,7 @@ class Viewer {
11561159
buffer: {
11571160
processAsync: processBuffer.bind(this)
11581161
}
1159-
}
1160-
);
1162+
});
11611163
containerAsset.on('load', () => resolve(containerAsset));
11621164
containerAsset.on('error', (err: string) => reject(err));
11631165
this.app.assets.add(containerAsset);
@@ -1191,7 +1193,7 @@ class Viewer {
11911193

11921194
isGSplatFilename(filename: string) {
11931195
const parts = filename.split('?')[0].split('/').pop().split('.');
1194-
const result = parts.length > 0 && ['ply', 'json'].includes(parts.pop().toLowerCase());
1196+
const result = parts.length > 0 && ['ply', 'json', 'sog'].includes(parts.pop().toLowerCase());
11951197
return result;
11961198
}
11971199

0 commit comments

Comments
 (0)