@@ -7,11 +7,8 @@ console.log("Deepar version: " + deepar.version);
7
7
// Top-level await is not supported.
8
8
// So we wrap the whole code in an async function that is called immediatly.
9
9
( async function ( ) {
10
- // Resize the canvas according to screen size and pixel ratio.
11
- const canvas = document . getElementById ( "deepar-canvas" ) ;
12
- const dpr = window . devicePixelRatio || 1 ;
13
- canvas . width = Math . floor ( window . innerWidth * dpr ) ;
14
- canvas . height = Math . floor ( window . innerHeight * dpr ) ;
10
+ // Get the element you want to place DeepAR into. DeepAR will inherit its width and height from this and fill it.
11
+ const previewElement = document . getElementById ( "ar-screen" ) ;
15
12
16
13
// trigger loading progress bar animation
17
14
const loadingProgressBar = document . getElementById ( "loading-progress-bar" ) ;
@@ -43,12 +40,17 @@ console.log("Deepar version: " + deepar.version);
43
40
try {
44
41
deepAR = await deepar . initialize ( {
45
42
licenseKey : "your_license_key_goes_here" ,
46
- canvas ,
43
+ previewElement ,
47
44
effect : effectList [ 0 ] ,
48
45
// Removing the rootPath option will make DeepAR load the resources from the JSdelivr CDN,
49
46
// which is fine for development but is not recommended for production since it's not optimized for performance and can be unstable.
50
47
// More info here: https://docs.deepar.ai/deepar-sdk/deep-ar-sdk-for-web/download-optimizations#custom-deployment-of-deepar-web-resources
51
48
rootPath : "./deepar-resources" ,
49
+ additionalOptions : {
50
+ cameraConfig : {
51
+ // facingMode: 'environment' // uncomment this line to use the rear camera
52
+ } ,
53
+ } ,
52
54
} ) ;
53
55
} catch ( error ) {
54
56
console . error ( error ) ;
@@ -57,15 +59,6 @@ console.log("Deepar version: " + deepar.version);
57
59
return ;
58
60
}
59
61
60
- var resizeCanvas = function ( ) {
61
- const canvas = document . getElementById ( "deepar-canvas" ) ;
62
- const dpr = window . devicePixelRatio || 1 ;
63
- canvas . width = Math . floor ( window . innerWidth * dpr ) ;
64
- canvas . height = Math . floor ( window . innerHeight * dpr ) ;
65
- } ;
66
-
67
- window . addEventListener ( "resize" , resizeCanvas ) ;
68
-
69
62
// Hide the loading screen.
70
63
document . getElementById ( "loading-screen" ) . style . display = "none" ;
71
64
document . getElementById ( "ar-screen" ) . style . display = "block" ;
0 commit comments