Hey, I used chatgpt to write some code to see if it could make the model load in when the image is detected
`import { Behaviour, GameObject, AssetReference } from "@needle-tools/engine";
class DetecttoLoad extends Behaviour {
private onImageTrackingUpdate = (event: any) => {
const trackedImages = event.detail;
for (const trackedImage of trackedImages) {
// Check if the tracked image corresponds to the model you want to load
if (this.shouldLoadModel(trackedImage)) {
this.loadModel(trackedImage);
}
}
};
private shouldLoadModel(trackedImage: any): boolean {
// Replace this with your own criteria for deciding when to load the model
return trackedImage.model && trackedImage.model.object !== null;
}
private loadModel(trackedImage: any) {
// Use the trackedImage data to decide which model to load
const modelReference = trackedImage.model.object;
// Check if the model is not already loaded
if (!modelReference.isLoaded) {
modelReference.loadAssetAsync().then((asset: GameObject | null) => {
if (asset) {
// Add the model to the scene or manipulate it as needed
this.context.scene.add(asset);
// Apply the tracked image's position and rotation to the model
trackedImage.applyToObject(asset);
}
});
}
}
onEnable(): void {
// Register the event listener for image tracking updates
this.addEventListener("image-tracking", this.onImageTrackingUpdate);
}
onDisable(): void {
// Unregister the event listener when the component is disabled
this.removeEventListener("image-tracking", this.onImageTrackingUpdate);
}
}
export default DetecttoLoad;`