<!--
Auto-generated by: https://github.com/threlte/threlte/tree/main/packages/gltf
Command: npx @threlte/gltf@3.0.0 static/models/pottedPlant.glb -t -s
-->

<script lang="ts">
	import type * as THREE from 'three';

	import type { Snippet } from 'svelte';
	import { T, type Props } from '@threlte/core';
	import { useGltf } from '@threlte/extras';
	import { base } from '$app/paths';

	let {
		fallback,
		error,
		children,
		ref = $bindable(),
		colors,
		opacity,
		...props
	}: Props<THREE.Group> & {
		ref?: THREE.Group;
		children?: Snippet<[{ ref: THREE.Group }]>;
		fallback?: Snippet;
		error?: Snippet<[{ error: Error }]>;
		colors?: (number | string)[];
		opacity?: number;
	} = $props();

	type GLTFResult = {
		nodes: {
			Mesh_pottedPlant: THREE.Mesh;
			Mesh_pottedPlant_1: THREE.Mesh;
			plant: THREE.Mesh;
		};
		materials: {
			wood: THREE.MeshStandardMaterial;
			woodDark: THREE.MeshStandardMaterial;
			plant: THREE.MeshStandardMaterial;
		};
	};

	const gltf = useGltf<GLTFResult>(base + '/models/kenney-furniture-kit/pottedPlant.glb');
</script>

<T.Group bind:ref dispose={false} {...props}>
	{#await gltf}
		{@render fallback?.()}
	{:then gltf}
		<T.Group scale={2}>
			<T.Mesh
				castShadow
				receiveShadow
				geometry={gltf.nodes.Mesh_pottedPlant.geometry}
				material={gltf.materials.wood.clone()}
				material.color={colors?.[0] ?? gltf.materials.wood.color}
				material.opacity={opacity ?? gltf.materials.wood.opacity}
				material.transparent={opacity !== undefined}
			/>
			<T.Mesh
				castShadow
				receiveShadow
				geometry={gltf.nodes.Mesh_pottedPlant_1.geometry}
				material={gltf.materials.woodDark.clone()}
				material.color={colors?.[1] ?? gltf.materials.woodDark.color}
				material.opacity={opacity ?? gltf.materials.woodDark.opacity}
				material.transparent={opacity !== undefined}
			/>
			<T.Mesh
				castShadow
				receiveShadow
				geometry={gltf.nodes.plant.geometry}
				material={gltf.materials.plant.clone()}
				material.color={colors?.[2] ?? gltf.materials.plant.color}
				material.opacity={opacity ?? gltf.materials.plant.opacity}
				material.transparent={opacity !== undefined}
				position={[-0.05, 0.06, 0.06]}
				scale={0.5}
			/>
		</T.Group>
	{:catch err}
		{@render error?.({ error: err })}
	{/await}

	{@render children?.({ ref })}
</T.Group>
