<!--
Auto-generated by: https://github.com/threlte/threlte/tree/main/packages/gltf
Command: npx @threlte/gltf@2.0.1 nature_edit/Bush_Snow_1.gltf --types -s -T --root nature_edit/
-->

<script lang="ts">
	import type * as THREE from 'three';
	import { Group } from 'three';
	import { T, type Props, type Events, type Slots, forwardEventHandlers } from '@threlte/core';
	import { useGltf } from '@threlte/extras';

	type $$Props = Props<THREE.Group> & {
		color?: THREE.Color | string | number;
		berriesColor?: THREE.Color | string | number;
		snowColor?: THREE.Color | string | number;
		variant?: 1 | 2;
		berries?: boolean;
		snow?: boolean;
	};
	type $$Events = Events<THREE.Group>;
	type $$Slots = Slots<THREE.Group> & { fallback: {}; error: { error: any } };

	export const ref = new Group();

	export let color: THREE.Color | string | number | undefined = undefined;

	export let berriesColor: THREE.Color | string | number | undefined = undefined;
	export let snowColor: THREE.Color | string | number | undefined = undefined;

	export let variant: 1 | 2 = 1;

	export let berries: boolean = false;
	export let snow: boolean = false;

	type GLTFResult = {
		nodes: {
			Bush_1: THREE.Mesh;
			Bush_2: THREE.Mesh;
		};
		materials: {
			Bush: THREE.MeshStandardMaterial;
			Snow: THREE.MeshStandardMaterial;
			Berries: THREE.MeshStandardMaterial;
		};
	};

	const gltf = useGltf<GLTFResult>(`nature/Bush_${(snow ? 'Snow_' : 'Berries_') + variant}.glb`, {
		useDraco: true
	});

	const component = forwardEventHandlers();
</script>

<T is={ref} dispose={false} {...$$restProps} bind:this={$component}>
	{#await gltf}
		<slot name="fallback" />
	{:then gltf}
		<T.Group rotation={[-Math.PI / 2, 0, 0]} scale={100}>
			<T.Mesh
				castShadow
				receiveShadow
				geometry={gltf.nodes.Bush_1.geometry}
				material={gltf.materials.Bush.clone()}
				material.metalness={0}
				material.roughness={1}
				material.color={color}
			/>
			{#if snow}
				<T.Mesh
					castShadow
					receiveShadow
					geometry={gltf.nodes.Bush_2.geometry}
					material={gltf.materials.Snow.clone()}
					material.color={snowColor}
				/>
			{:else if berries}
				<T.Mesh
					castShadow
					receiveShadow
					geometry={gltf.nodes.Bush_2.geometry}
					material={gltf.materials.Berries.clone()}
					material.metalness={0}
					material.roughness={1}
					material.color={berriesColor}
				/>
			{/if}
		</T.Group>
	{:catch error}
		<slot name="error" {error} />
	{/await}

	<slot {ref} />
</T>
