-
Notifications
You must be signed in to change notification settings - Fork 0
/
getOrAddNameplateContainer.ts
44 lines (42 loc) · 1.19 KB
/
getOrAddNameplateContainer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as THREE from "three";
import { getOrAddObject } from "./getOrAddObject";
import {
NameplatePositionHeightOptions,
nameplatePositionHeight,
} from "./namePlatePositionHeight";
export type GetOrAddNameplateContainerOptions = {
/** re-adjust position even when the nameplate container exists */
adjustPosition?: boolean;
};
/**
* get the nameplate container object if it exists, otherwise add it
*
* @param parent parent object
* @param avatarObject avatar object for position detection
* @param options options
* @returns
*/
export function getOrAddNameplateContainer(
parent: THREE.Object3D,
avatarObject: THREE.Object3D | undefined,
options?: GetOrAddNameplateContainerOptions & NameplatePositionHeightOptions,
) {
return getOrAddObject(
parent,
"nameplateContainer",
() => new THREE.Object3D(),
{
afterCreate: (container) => {
container.position.y = nameplatePositionHeight(avatarObject, options);
},
afterExists: options?.adjustPosition
? (container) => {
container.position.y = nameplatePositionHeight(
avatarObject,
options,
);
}
: undefined,
},
);
}