-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- feat: added constants for package type
- docs: added docs for Package class
- Loading branch information
Showing
7 changed files
with
145 additions
and
23 deletions.
There are no files selected for viewing
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
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
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,108 @@ | ||
## Package | ||
|
||
**new Package(config)** | ||
|
||
Accepts the following configuration: | ||
|
||
```js | ||
new Package({ | ||
arType: 'pattern', // see exported AR_* constants | ||
assetType: '3d', // see exported ASSET_* constants | ||
assetFile: yourAssetFile, // read details after this code block | ||
assetName: 'model.gltf', // the AR asset filename, including the file extension | ||
assetParam: { | ||
isValid: true, // whether the scale/size parameters are correct or not (if you don't know what this is, set to true) | ||
scale: 1.0, // scale of the asset | ||
size: { // sizes of the asset, unused | ||
width: 1.0, | ||
height: 1.0, | ||
depth: 1.0 | ||
}, | ||
latitude: 12.345678, // required for location based AR | ||
longitude: 12.345678 // required for location based AR | ||
}, | ||
markerPatt: '...', // the content of the generated .patt file, as a string (required for pattern/location based AR) | ||
matrixType: '...', // see exported MATRIX_* constants (required for barcode based AR) | ||
markerValue: 7, // barcode value (required for barcode based AR) | ||
}); | ||
``` | ||
|
||
The `assetFile` parameter must be: | ||
- a base64 encoded string (use `FileReader.readAsDataURL()` and strip the initial `data:*/*;base64,` string) for 3d/image assets | ||
- a `Blob` for audio/video assets when using Zip provider | ||
- an `ArrayBuffer` for audio/video when using GitHub provider | ||
|
||
**serve(config)** | ||
|
||
Deploys the package, based on the chosen provider. Accepts the following configuration: | ||
|
||
```js | ||
package.serve({ | ||
packageType: 'zip', // see exported PACKAGE_* constants | ||
config: {...} // see either serveFiles() documentation for your chosen provider | ||
}); | ||
``` | ||
|
||
### Example | ||
|
||
```js | ||
const { | ||
AR_PATTERN, | ||
ASSET_3D, | ||
PACKAGE_GITHUB, | ||
PACKAGE_ZIP, | ||
MarkerModule | ||
} = ARjsStudioBackend; | ||
|
||
// helper function -- promisify file reading | ||
const reader = new FileReader(); | ||
const waitRead = () => { | ||
return new Promise(resolve => { | ||
reader.addEventListener('load', () => { | ||
resolve(reader.result); | ||
}); | ||
}) | ||
}; | ||
|
||
// read marker image | ||
const markerFile = document.querySelector('#marker-image').files[0]; | ||
reader.readAsDataURL(markerFile); | ||
const originalMarker = await waitRead(); | ||
|
||
// generate .patt file | ||
const textPatt = await MarkerModule.getMarkerPattern(originalMarker); | ||
|
||
// read asset file | ||
const assetFile = document.querySelector('#asset-file-selector').files[0]; | ||
reader.readAsDataURL(assetFile); | ||
const base64Asset = await waitRead(); | ||
|
||
// create the package | ||
const package = new Package({ | ||
arType: AR_PATTERN, | ||
assetType: ASSET_3D, | ||
assetFile: base64Asset, | ||
assetName: file.name, | ||
assetParam: { | ||
isValid: true, | ||
scale: 1.0 | ||
}, | ||
markerPatt: textPatt | ||
}); | ||
|
||
// deploy to github... | ||
const pagesURL = await package.serve({ | ||
packageType: PACKAGE_GITHUB, | ||
token: 'user github token', | ||
repo: 'arjs-awesome-repo-84265' | ||
}); | ||
console.log(`navigate to ${pagesURL} to see your project`); | ||
|
||
// ...or generate a zip file (or both!) | ||
const zipFile = await package.serve({ | ||
packageType: PACKAGE_ZIP, | ||
compress: 9 | ||
}); | ||
// trigger download | ||
window.location = `data:application/zip;base64,${zipFile}`; | ||
``` |
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
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
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
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