KITASENJU DESIGN BLOG

memo, html, javascript, unity

webglからpngを毎フレームレンダリング

async tick(){
            this.renderer.render(this.scene, this.oCamera);

            if(Params.isRec) Params.download2();

            setTimeout(()=>{
                this.tick();
            },1000/60)
}
 public static dhandle:any;
    public static async donwloadInit(){
        Params.dhandle = await (window as any).showDirectoryPicker()
        Params.dhandle.requestPermission({ writable: true })    
        Params.download2();
    }

    public static async download2(){

        
        let dom = document.getElementById("webgl") as HTMLCanvasElement;
        await dom.toBlob(async (result)=>{

            //console.log(result);
            let filename = Params.filename;
            if(this.downloadIndex==0){
                filename = Params.filenameInfo;
            }
            let filename1 = filename+"_"+Params.zeroPadding(Params.downloadIndex,4)+".png";
            let fhandle = await Params.dhandle.getFileHandle(
                filename1, { create: true }
            );
            Params.downloadIndex++;

            const writable = await fhandle.createWritable();
            await writable.write(result);
            await writable.close();

        },"image/png");

    }

"FOOTER"