-
Notifications
You must be signed in to change notification settings - Fork 25
Support viewer html output #29
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9199ff4
adds support for viewer app generation from ply
praveenpenumaka 0ee7c99
Adds playcanvas npm module as dep.
praveenpenumaka 2dcaad2
adds supersplat-viewer dependency
praveenpenumaka d1670de
updated documentation
praveenpenumaka 8348e12
corrects minor documentation issues
praveenpenumaka 963b1a6
Update README.md
praveenpenumaka 82f99f1
Update README.md
praveenpenumaka 4a64207
Update src/index.ts
praveenpenumaka 100ed7a
Rename flags and make them global
slimbuck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { open, unlink, FileHandle } from 'node:fs/promises'; | ||
| import os from 'node:os'; | ||
|
|
||
| import { html, css, js } from '@playcanvas/supersplat-viewer'; | ||
| import { Vec3 } from 'playcanvas'; | ||
|
|
||
| import { writeCompressedPly } from './write-compressed-ply'; | ||
| import { PlyData } from '../readers/read-ply'; | ||
|
|
||
|
|
||
| const writeHtmlApp = async (fileHandle: FileHandle, plyData: PlyData, camera: Vec3, target: Vec3) => { | ||
| const pad = (text: string, spaces: number) => { | ||
| const whitespace = ' '.repeat(spaces); | ||
| return text.split('\n').map(line => whitespace + line).join('\n'); | ||
| }; | ||
| const encodeBase64 = (bytes: Uint8Array) => { | ||
| let binary = ''; | ||
| const len = bytes.byteLength; | ||
| for (let i = 0; i < len; i++) { | ||
| binary += String.fromCharCode(bytes[i]); | ||
| } | ||
| return Buffer.from(binary, 'binary').toString('base64'); | ||
| }; | ||
|
|
||
| const experienceSettings = { | ||
| camera: { | ||
| fov: 50, | ||
| position: [camera.x, camera.y, camera.z], | ||
| target: [target.x, target.y, target.z], | ||
| startAnim: 'none', | ||
| animTrack: undefined as unknown as string | undefined | ||
| }, | ||
| background: { | ||
| color: [0.4, 0.4, 0.4] | ||
| }, | ||
| animTracks: [] as unknown[] | ||
| }; | ||
|
|
||
| const tempPlyPath = `${os.tmpdir()}/temp.ply`; | ||
| const tempPly = await open(tempPlyPath, 'w+'); | ||
| await writeCompressedPly(tempPly, plyData.elements[0].dataTable); | ||
| const openPly = await open(tempPlyPath, 'r'); | ||
| const compressedPly = encodeBase64(await openPly.readFile()); | ||
| await openPly.close(); | ||
| await unlink(tempPlyPath); | ||
|
|
||
| const style = '<link rel="stylesheet" href="./index.css">'; | ||
| const script = '<script type="module" src="./index.js"></script>'; | ||
| const settings = 'settings: fetch(settingsUrl).then(response => response.json())'; | ||
| const content = 'fetch(contentUrl)'; | ||
|
|
||
| const generatedHtml = html | ||
| .replace(style, `<style>\n${pad(css, 12)}\n </style>`) | ||
| .replace(script, `<script type="module">\n${pad(js, 12)}\n </script>`) | ||
| .replace(settings, `settings: ${JSON.stringify(experienceSettings)}`) | ||
| .replace(content, `fetch("data:application/ply;base64,${compressedPly}")`); | ||
slimbuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| await fileHandle.write(new TextEncoder().encode(generatedHtml)); | ||
|
|
||
slimbuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| export { writeHtmlApp }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.