import * as THREE from 'three'; import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'; export class Flower { static collection = []; constructor() { this.position = new THREE.Vector3(); this.rotation = new THREE.Vector3(); this.model = null; this.nectarRemaining = 100; } static loadModel() { return new Promise((resolve, reject) => { var gltfloader = new GLTFLoader(); return gltfloader.load( './flowers/scene.gltf', function (gltf) { resolve(gltf); }, function (xhr) { }, function (error) { reject(error); } ); }); } async load(model) { this.model = model.scene.clone() ?? await Flower.loadModel().scene; this.init(); } init() { this.model.scale.set(0.5, 0.5, 0.5); this.model.traverse(function (node) { if (node.isMesh) { node.castShadow = true; node.receiveShadow = true; } }); this.position.z = 100; } addToScene(scene) { scene.add(this.model); } update(delta, timer) { this.model.position.set(this.position.x, this.position.y, this.position.z); this.model.rotation.set(this.rotation.x, this.rotation.y, this.rotation.z); } visitFromBee(bee) { bee.carryingHoney += 10; this.nectarRemaining -= 10; bee.setTarget(bee.homeHive.entranceWaypoint); } }