import { Vector3 } from 'three/webgpu';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { withAssetLoader } from './LoadingManager.js';
/** Fit the COLLADA duck's closed surface to the simulation domain. */
export async function loadDuckVolume( container, height ) {
const gltf = await withAssetLoader( container, [ 'Duck model' ], manager => (
manager.load( 'Duck model', onProgress => new GLTFLoader().loadAsync( '/files/duck/Duck.glb', onProgress ) )
) );
const mesh = gltf.scene.getObjectByProperty( 'isMesh', true );
const geometry = mesh.geometry;
mesh.material.map?.image?.close?.();
mesh.material.map?.dispose();
mesh.material.dispose();
geometry.computeBoundingBox();
const bounds = geometry.boundingBox;
const center = bounds.getCenter( new Vector3() );
const scale = height / ( bounds.max.y - bounds.min.y );
geometry.translate( - center.x, - center.y, - center.z ).scale( scale, scale, scale );
return geometry;
}