Talos docs

Instances

Since 0.7

The instances of an instancedMesh entity: what ctx.world.instances(entity) returns.

Plain text

Every instance has a stable id that hits and picks report too; every list is ascending by id.

Signature

export interface Instances {
  /** The instanced mesh's entity. */
  readonly entity: EntityHandle
  /** How many instances there are now. */
  readonly count: number
  /** Every instance id, ascending. */
  ids(): number[]
  /** The instance with this id, or null. */
  get(id: number): InstanceRecord | null
  /** Adds an instance (`position` required; no rotation and scale 1 by default); returns its new id, or null when the value is not a transform. */
  add(value: InstanceInput & { position: Vec3 }): number | null
  /** Changes the given fields of instance `id`; false when there is no such instance. */
  update(id: number, value: InstanceInput): boolean
  /** Removes instance `id`; false when there is none. Its id is never given again. */
  remove(id: number): boolean
  /**
   * Ids of the instances within `radius` of `center` (the mesh's frame), ascending. Inclusive: an instance
   * at exactly `radius` is in. Unlike `query({ near })` it compares squared distances (f32).
   */
  inSphere(center: Vec3, radius: number): number[]
}

Import: import type { Instances } from "@argus/api"

Members

MemberSignatureDescription
entityreadonly entity: EntityHandleThe instanced mesh's entity.
countreadonly count: numberHow many instances there are now.
idsids(): number[]Every instance id, ascending.
getget(id: number): InstanceRecord | nullThe instance with this id, or null.
addadd(value: InstanceInput & { position: Vec3 }): number | nullAdds an instance (position required; no rotation and scale 1 by default); returns its new id, or null when the value is not a transform.
updateupdate(id: number, value: InstanceInput): booleanChanges the given fields of instance id; false when there is no such instance.
removeremove(id: number): booleanRemoves instance id; false when there is none. Its id is never given again.
inSphereinSphere(center: Vec3, radius: number): number[]Ids of the instances within radius of center (the mesh's frame), ascending. Inclusive: an instance at exactly radius is in. Unlike query({ near }) it compares squared distances (f32).

Example

The tested fixture fixtures/app/agent.ts.

import type { Behavior } from "@argus/api"

// Sends a nav agent to `props.target` once, then reports arrival through ctx.state so the
// test can read it without polling the crowd directly.
export default {
  init(ctx) {
    ctx.state.arrived = false
    ctx.nav?.goTo(ctx.props.target as [number, number, number])
  },
  update(ctx) {
    if (ctx.nav?.arrived) ctx.state.arrived = true
  },
} satisfies Behavior