<!--
Auto-generated by: https://github.com/threlte/threlte/tree/main/packages/gltf
Command: npx @threlte/gltf@2.0.1 nature_edit/Cactus_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;
		flowerColor?: THREE.Color | string | number;
		variant?: 1 | 2 | 3 | 4 | 5;
		flower?: 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 flowerColor: THREE.Color | string | number | undefined = undefined;

	export let variant: 1 | 2 | 3 | 4 | 5 = 1;

	export let flower: boolean = false;

	type GLTFResult = {
		nodes: {
			Cactus_1: THREE.Mesh;
			Cactus_2: THREE.Mesh;
		};
		materials: {
			Cactus: THREE.MeshStandardMaterial;
			Flower: THREE.MeshStandardMaterial;
		};
	};

	const gltf = useGltf<GLTFResult>(`nature/Cactus_${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.Cactus_1.geometry}
				material={gltf.materials.Cactus.clone()}
				material.metalness={0}
				material.roughness={1}
				material.color={color}
			/>
			{#if flower}
				<T.Mesh
					castShadow
					receiveShadow
					geometry={gltf.nodes.Cactus_2.geometry}
					material={gltf.materials.Flower.clone()}
					material.metalness={0}
					material.roughness={1}
					material.color={flowerColor}
				/>
			{/if}
		</T.Group>
	{:catch error}
		<slot name="error" {error} />
	{/await}

	<slot {ref} />
</T>
