-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
documentation/.vuepress/public/code-samples/component-filereference.ts
This file contains 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,20 @@ | ||
import { Behaviour, FileReference, ImageReference, serializable } from "@needle-tools/engine"; | ||
|
||
export class FileReferenceExample extends Behaviour { | ||
|
||
// A FileReference can be used to load and assign arbitrary data in the editor. You can use it to load images, audio, text files... FileReference types will not be saved inside as part of the GLB (the GLB will only contain a relative URL to the file) | ||
@serializable(FileReference) | ||
myFile?: FileReference; | ||
// Tip: if you want to export and load an image (that is not part of your GLB) if you intent to add it to your HTML content for example you can use the ImageReference type instead of FileReference. It will be loaded as an image and you can use it as a source for an <img> tag. | ||
|
||
async start() { | ||
console.log("This is my file: ", this.myFile); | ||
// load the file | ||
const data = await this.myFile?.loadRaw(); | ||
if (!data) { | ||
console.error("Failed loading my file..."); | ||
return; | ||
} | ||
console.log("Loaded my file. These are the bytes:", await data.arrayBuffer()); | ||
} | ||
} |
This file contains 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