import * as THREE from 'three' ; import { VRM } from '../VRM' ; const _v2A = new THREE . Vector2 ( ) ; const _camera = new THREE . OrthographicCamera ( - 1 , 1 , - 1 , 1 , - 1 , 1 ) ; const _material = new THREE . MeshBasicMaterial ( { color : 0xffffff , side : THREE . DoubleSide } ) ; const _plane = new THREE . Mesh ( new THREE . PlaneBufferGeometry ( 2 , 2 ) , _material ) ; const _scene = new THREE . Scene ( ) ; _scene . add ( _plane ) ; /**
 * Extract a thumbnail image blob from a  VRM .
 * If the vrm does not have a thumbnail, it will throw an error.
 *  param renderer param vrm param size export function extractThumbnailBlob ( renderer , vrm , size = 512 ) { const texture = vrm . meta ?. texture ; if ( ! texture ) { throw new Error ( 'extractThumbnailBlob: This VRM does not have a thumbnail' ) ; } const canvas = renderer . getContext ( ) . canvas ; renderer . getSize ( _v2A ) ; const prevWidth = _v2A . x ; const prevHeight = _v2A . y ; renderer . setSize ( size , size , false ) ; _material . map = texture ; renderer . render ( _scene , _camera ) ; _material . map = null ; if ( canvas instanceof OffscreenCanvas ) { return canvas . convertToBlob ( ) . finally ( ( ) => { renderer . setSize ( prevWidth , prevHeight , false ) ; } ) ; } return new Promise ( ( resolve , reject ) => { canvas . toBlob ( ( blob ) => { renderer . setSize ( prevWidth , prevHeight , false ) ; if ( blob == null ) { reject ( 'extractThumbnailBlob: Failed to create a blob' ) ; } else { resolve ( blob ) ; } } ) ; } ) ; }