forked from phenom/healer-man
34 lines
1013 B
TypeScript
34 lines
1013 B
TypeScript
import { Vector3, type Object3D } from "three";
|
|
|
|
const anchors = new Map<string, Object3D>();
|
|
|
|
export function registerCombatEffectAnchor(actorId: string, object: Object3D): () => void {
|
|
anchors.set(actorId, object);
|
|
return () => {
|
|
if (anchors.get(actorId) === object) anchors.delete(actorId);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Copies an actor's current rendered world position into an effect's parent
|
|
* space. This follows the scene object directly instead of a throttled combat
|
|
* or network snapshot while deliberately avoiding inherited actor rotation.
|
|
*/
|
|
export function updateCombatEffectAnchorPosition(
|
|
actorId: string | undefined,
|
|
effect: Object3D,
|
|
worldPosition: Vector3,
|
|
): boolean {
|
|
if (!actorId) return false;
|
|
const anchor = anchors.get(actorId);
|
|
if (!anchor) return false;
|
|
anchor.getWorldPosition(worldPosition);
|
|
effect.parent?.worldToLocal(worldPosition);
|
|
effect.position.copy(worldPosition);
|
|
return true;
|
|
}
|
|
|
|
export function clearCombatEffectAnchorRegistry(): void {
|
|
anchors.clear();
|
|
}
|