MapAnchor
Needle Engine component that positions a GameObject at a map-local coordinate after localization
Last updated
Was this helpful?
Needle Engine component that positions a GameObject at a map-local coordinate after localization
import { MapAnchor } from '@multisetai/vps/needle';A Needle Engine Behaviour that applies VPS localization to a GameObject. After a successful localization, it transforms the object to the correct world position using the map-to-world matrix. MapAnchor is detected and wired automatically by MultisetVPS at startup.
offset
THREE.Vector3
(0, 0, 0)
Position offset from the map origin in metres
matchOrientation
boolean
true
Align the object's rotation to the map orientation
rotationOffset
THREE.Euler
(0°, 0°, 0°)
Additional rotation applied after matchOrientation. Only takes effect when matchOrientation is true.
hideUntilLocalized
boolean
true
Keep the object invisible until the first successful localization and re-hide it when the session ends
isRightHanded
boolean
false
Set true if entering Three.js (right-handed) coordinates. Leave false for Unity (left-handed) coordinates — MapAnchor converts automatically.
Needle Engine uses Three.js coordinates (right-handed, Y-up). Unity uses a left-handed coordinate system. MapAnchor converts automatically when isRightHanded is false:
The X component of offset is negated
The Y and Z components of rotationOffset are negated
Set isRightHanded: true only if you are entering coordinates from a Three.js source (such as a previous localization result).
When hideUntilLocalized is true, the entire GameObject is hidden until the first localization. Because Needle Engine skips start() on invisible GameObjects, any sibling component that must run before localization should be placed on a separate always-visible GameObject.
connectAdapter(adapter: NeedleAdapter)
Wire this anchor to an adapter. Called automatically by MultisetVPS for scene-placed anchors. Safe to call multiple times.
applyLocalization(result: ILocalizeAndMapDetails, worldFromMap: THREE.Matrix4)
Apply a localization result directly. Useful for testing or replaying a saved result.
awake()
Sets visible = false if hideUntilLocalized is true
onDestroy()
Removes all registered listeners to prevent memory leaks
When a MapAnchor is instantiated at runtime (after MultisetVPS.start() has already run), call registerAnchor on the adapter to wire it up:
Last updated
Was this helpful?
Was this helpful?
import { instantiate } from '@needle-tools/engine';
import { MapAnchor } from '@multisetai/vps/needle';
const instance = instantiate(myPrefab);
const anchor = instance.getComponent(MapAnchor);
if (anchor && vps.adapter) {
vps.adapter.registerAnchor(anchor);
// If a localization already happened, the anchor is positioned immediately
}
