webarkit / ARnft

A small javascript library for WebAR with NFT
GNU Lesser General Public License v3.0
219 stars 54 forks source link

Some new getters for the CameraViewRenderer class #218

Closed kalwalt closed 3 years ago

kalwalt commented 3 years ago

CameraViewRenderer new getters and functions

General infos

This PR add some more getters to the CameraViewRenderer class see #216 :

getVideo() to get the video HTML element getCanvasProcess() to get the canvas used in the process to transfer the video pixels to the WebWorker. getContextProcess() to get the context of the canvas :arrow_up: getFacing() to get the facing string (environment, user...) used for the video settings. Note that this can be retrieved only after initialization of the CameraViewRenderer instance.

and lastly prepareImage() to 'prepare' the canvas to fill with the video pixels.

Examples and tests

I will see if add some examples, but this getters will be only availables for the ARnft class. For now you can test inside the ARnft _initialize put this code just after this.cameraView = new CameraViewRenderer(document.getElementById("video") as HTMLVideoElement);:

let video = this.cameraView.getVideo();
let canvas = this.cameraView.getCanvasProcess();
let context = this.cameraView.getContexProcess();     
console.log(video);
console.log(canvas);
console.log(context);

and just after

 await this.cameraView.initialize(this.appData.videoSettings).catch((error: any) => {
            console.error(error);
            return Promise.reject(false);
        });

put this:

let facing = this.cameraView.getFacing();
console.log(facing);

you will see in the console:

ARnft.ts:167 <video id=​"video" autoplay muted playsinline>​</video>​
ARnft.ts:168 <canvas>​
ARnft.ts:169 CanvasRenderingContext2D {canvas: canvas, globalAlpha: 1, globalCompositeOperation: 'source-over', filter: 'none', imageSmoothingEnabled: true, …}
ARnft.ts:179 environment

Other

Minor fix for the arNFT_example.html https://github.com/webarkit/ARnft/pull/218/commits/702bbdfd7cbf7ee3020db12ec11bf5d886db0268 (root object3D) is not required anymore)

kalwalt commented 3 years ago

That getters can be used only if you import the CameraViewRenderer class, because we export only the ARnft class https://github.com/webarkit/ARnft/blob/ef9e182278da7a4d24460ba9222da531bea30e87/src/index.ts#L36-L40 it's not possible to test directly in vanilla js code. This will be useful for devloping other initialize functions as i started for example in the raw-initialize branch