bg2e-js 2.3.13 → 2.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bg2e-js.js +110 -101
- package/dist/bg2e-js.js.map +1 -1
- package/package.json +1 -1
- package/src/base/PolyList.ts +14 -1
- package/src/manipulation/SelectionHighlight.ts +0 -1
- package/src/manipulation/SelectionIdAssignVisitor.ts +10 -3
- package/src/manipulation/SelectionManager.ts +5 -1
- package/src/scene/Drawable.ts +4 -0
package/package.json
CHANGED
package/src/base/PolyList.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Vec from "../math/Vec";
|
|
|
2
2
|
import Mat4 from "../math/Mat4";
|
|
3
3
|
import Color from "./Color";
|
|
4
4
|
import Material from "./Material";
|
|
5
|
-
|
|
5
|
+
import Drawable from "../scene/Drawable";
|
|
6
6
|
|
|
7
7
|
export enum BufferType {
|
|
8
8
|
VERTEX = 1 << 0,
|
|
@@ -188,6 +188,8 @@ export default class PolyList {
|
|
|
188
188
|
private _selectable: boolean;
|
|
189
189
|
private _renderer?: any;
|
|
190
190
|
|
|
191
|
+
private _mainDrawable?: Drawable;
|
|
192
|
+
|
|
191
193
|
constructor() {
|
|
192
194
|
// The object will be rendered in the default layer for
|
|
193
195
|
// transparent or opaque objects
|
|
@@ -310,6 +312,17 @@ export default class PolyList {
|
|
|
310
312
|
this._selectable = s;
|
|
311
313
|
}
|
|
312
314
|
|
|
315
|
+
// The mainDrawable is a reference to the las Drawable object that contains this polyList. Note that
|
|
316
|
+
// in some circunstances a polyList can be shared by several Drawable objects, but the mainDrawable
|
|
317
|
+
// will be the last one that was assigned.
|
|
318
|
+
get mainDrawable(): Drawable | undefined {
|
|
319
|
+
return this._mainDrawable;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
set mainDrawable(d: Drawable | undefined) {
|
|
323
|
+
this._mainDrawable = d;
|
|
324
|
+
}
|
|
325
|
+
|
|
313
326
|
// The this._renderer variable is initialized by the polyListRenderer factory
|
|
314
327
|
get renderer(): any {
|
|
315
328
|
return this._renderer
|
|
@@ -91,7 +91,6 @@ export default class SelectionHighlight {
|
|
|
91
91
|
this._renderQueue?.draw(RenderLayer.SELECTION_DEFAULT);
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
// TODO: Draw target texture using a border detection shader
|
|
95
94
|
const shader = this._selectionDrawShader;
|
|
96
95
|
this._renderer.presentTexture(this._targetTexture, { clearBuffers: false, shader });
|
|
97
96
|
}
|
|
@@ -2,12 +2,19 @@ import NodeVisitor from "../scene/NodeVisitor";
|
|
|
2
2
|
import SelectionMode from "./SelectionMode";
|
|
3
3
|
import Color from "../base/Color";
|
|
4
4
|
import Node from "../scene/Node";
|
|
5
|
+
import PolyList from "../base/PolyList";
|
|
6
|
+
import Drawable from "../scene/Drawable";
|
|
5
7
|
|
|
6
8
|
const getColor = (comps: number[]) => "" + comps[0] + comps[1] + comps[2];
|
|
7
9
|
|
|
10
|
+
export type SelectionElement = {
|
|
11
|
+
polyList: PolyList;
|
|
12
|
+
drawable: Drawable;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
export default class SelectionAssignVisitor extends NodeVisitor {
|
|
9
16
|
protected _selectionMode: SelectionMode;
|
|
10
|
-
protected _elements: Record<string,
|
|
17
|
+
protected _elements: Record<string, SelectionElement>;
|
|
11
18
|
protected _r: number = 0;
|
|
12
19
|
protected _g: number = 0;
|
|
13
20
|
protected _b: number = 0;
|
|
@@ -56,7 +63,7 @@ export default class SelectionAssignVisitor extends NodeVisitor {
|
|
|
56
63
|
return new Color([components[0]/255, components[1]/255, components[2]/255, 1]);
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
findElement(pickedColor: Uint8Array | undefined | null) {
|
|
66
|
+
findElement(pickedColor: Uint8Array | undefined | null) : SelectionElement | null {
|
|
60
67
|
if (!pickedColor) {
|
|
61
68
|
return null;
|
|
62
69
|
}
|
|
@@ -66,7 +73,7 @@ export default class SelectionAssignVisitor extends NodeVisitor {
|
|
|
66
73
|
pickedColor[1],
|
|
67
74
|
pickedColor[2]
|
|
68
75
|
];
|
|
69
|
-
return this._elements[getColor(color)];
|
|
76
|
+
return this._elements[getColor(color)] || null;
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
visit(node: Node) {
|
|
@@ -159,8 +159,12 @@ export default class SelectionManager {
|
|
|
159
159
|
const pickedColor = this._selectionBuffer!.draw(this.sceneRoot, this.camera, evt.x * pixelRatio, evt.y * pixelRatio);
|
|
160
160
|
const item = this._selectionIdVisitor.findElement(pickedColor);
|
|
161
161
|
const isSelected = () => this._selection.find(s => {
|
|
162
|
-
return s.polyList === item.polyList && s.drawable === item.drawable
|
|
162
|
+
return item && s.polyList === item.polyList && s.drawable === item.drawable
|
|
163
163
|
});
|
|
164
|
+
if (item && this.selectionMode === SelectionMode.OBJECT) {
|
|
165
|
+
item.drawable.items.forEach(it => it.polyList.selected = true);
|
|
166
|
+
}
|
|
167
|
+
|
|
164
168
|
if (item && this._multiSelect && !isSelected()) {
|
|
165
169
|
this._selection.push(item);
|
|
166
170
|
this.triggerSelectionChanged();
|
package/src/scene/Drawable.ts
CHANGED
|
@@ -78,10 +78,14 @@ export default class Drawable extends Component {
|
|
|
78
78
|
throw new Error("Error adding polyList to drawable object: transform is not an instance of Mat4");
|
|
79
79
|
}
|
|
80
80
|
this._items.push({ polyList, material, transform });
|
|
81
|
+
polyList.mainDrawable = this;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
removePolyList(plist: PolyList): void {
|
|
84
85
|
this._items = this._items.filter(item => item.polyList != plist);
|
|
86
|
+
if (plist.mainDrawable === this) {
|
|
87
|
+
plist.mainDrawable = undefined;
|
|
88
|
+
}
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
destroy(): void {
|