forked from Orillusion/orillusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutlineManager.ts
71 lines (61 loc) · 2.17 KB
/
OutlineManager.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { MeshRenderer } from "../components/renderer/MeshRenderer";
import { Object3D } from "../core/entities/Object3D";
import { Color } from "../math/Color";
import { outlinePostData } from "./OutlinePostData";
/**
* manager of outline effect
* @group IO
*/
export class OutlinePostManager {
private _tempIndexArray: number[] = [];
/**
* config outline manager.
* Specify specific 3D objects to use the specified color for display outline
* @param objectList A set of 3D objects
* @param color Specified color for outline
*/
public setOutline(objectList: Object3D[], color?: Color) {
this.setOutlineList([objectList], color ? [color] : null);
}
/**
* config outline manager.
* The first set of objects uses the first color to display outline, and so on
* @param groupList A group of 3D objects set
* @param colorList Specified color list for outline
*/
public setOutlineList(groupList: Object3D[][], colorList?: Color[]) {
groupList ||= [];
let defaultColor = outlinePostData.defaultColor;
let maxGroup = outlinePostData.SlotCount;
for (let i = 0; i < maxGroup; i++) {
this._tempIndexArray.length = 0;
let group = groupList[i];
let color = (colorList ? colorList[i] : null) || defaultColor;
if (group) {
for (const item of group) {
this.getEntityIdList(item, this._tempIndexArray);
}
}
outlinePostData.fillDataAt(i, this._tempIndexArray, color);
}
}
/**
* clear outline effect
*/
public clearOutline(): this {
outlinePostData.clear();
return this;
}
private _rendererList: MeshRenderer[] = [];
private getEntityIdList(item: Object3D, target: number[]): void {
this._rendererList.length = 0;
let renderers = item.getComponents(MeshRenderer, this._rendererList);
for (const render of renderers) {
target.push(render.object3D.transform._worldMatrix.index);
}
}
}
/**
* @internal
*/
export let outlinePostManager: OutlinePostManager = new OutlinePostManager();