Hi there, I am trying to work on a project based on multiple VPS locations. We are wanting to have a target real world object image pop up on the screen as a starting point in the storytelling journey which guides the user to what needs to be scanned. I want the image to disappear when that particular VPS mesh/location is found and reappear it when the mesh is lost.
I have the images as a overlay group and using the following script on individual VPS location to trigger the enabling an disabling of these images.
import * as ecs from ‘/ecs’
ecs.registerComponent({name: ‘EnableOnVPSLocation’,schema: {locationName: ecs.string, // Name of the VPS location (from Geospatial Browser)targetEntity: ecs.eid // Entity to enable/disable},
add: (world, component) => {const {eid, schema} = component
const enableTarget = () => {
if (typeof schema.targetEntity === 'number') {
ecs.Disabled.remove(world, schema.targetEntity)
console.log(`[EnableOnVPSLocation] Enabled target entity ${schema.targetEntity}`)
}
}
const disableTarget = () => {
if (typeof schema.targetEntity === 'number') {
ecs.Disabled.set(world, schema.targetEntity, {})
console.log(`[EnableOnVPSLocation] Disabled target entity ${schema.targetEntity}`)
}
}
world.events.addListener(world.events.globalId, 'reality.locationfound', (e: any) => {
const {name, position, rotation} = e.data
if (name === schema.locationName) {
// Show and update position/rotation of this component's entity
ecs.Hidden.remove(world, eid)
ecs.Position.set(world, eid, position)
ecs.Quaternion.set(world, eid, rotation)
// Enable the target entity
enableTarget()
}
})
world.events.addListener(world.events.globalId, 'reality.locationlost', (e: any) => {
const {name} = e.data
if (name === schema.locationName) {
// Hide this component's entity
ecs.Hidden.set(world, eid, {})
// Disable the target entity
disableTarget()
}
})
can you please explain if this approach is right or is there a easier way to achieve this?
I have also tried another approach using MESH NAME as variable and not have the script attached to the vps itself. That did not work either. What am I doing wrong here?