@vvfx/sdk 0.2.8 → 0.2.9
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/config.js +231 -0
- package/dist/exporter/config.js +18 -0
- package/dist/exporter/const.js +71 -0
- package/dist/exporter/export-media.js +878 -0
- package/dist/exporter/exporter.js +121 -0
- package/dist/exporter/index.js +1 -0
- package/dist/exporter/types.js +1 -0
- package/dist/exporter/utils.js +190 -0
- package/dist/exporter/wav-audio.js +50 -0
- package/dist/gesture-handler/gizmo/adsorption-gizmo.js +227 -0
- package/dist/gesture-handler/gizmo/control-gizmo.js +149 -0
- package/dist/gesture-handler/gizmo/gizmo.js +17 -0
- package/dist/gesture-handler/gizmo/icon-gizmo.js +189 -0
- package/dist/gesture-handler/gizmo/index.js +6 -0
- package/dist/gesture-handler/gizmo/item-create-gizmo.js +256 -0
- package/dist/gesture-handler/gizmo/loading-gizmo.js +320 -0
- package/dist/gesture-handler/gizmo/mask-gizmo.js +648 -0
- package/dist/gesture-handler/gizmo/picture-cut-gizmo.js +550 -0
- package/dist/gesture-handler/gizmo/picture-expand-gizmo.js +491 -0
- package/dist/gesture-handler/gizmo/preference-gizmo.js +148 -0
- package/dist/gesture-handler/gizmo/selector-gizmo.d.ts +1 -1
- package/dist/gesture-handler/gizmo/selector-gizmo.js +468 -0
- package/dist/gesture-handler/gizmo/sprite-text-edit-gizmo.js +247 -0
- package/dist/gesture-handler/gizmo/text-gizmo.js +1033 -0
- package/dist/gesture-handler/gizmo/transform-gizmo.js +1199 -0
- package/dist/gesture-handler/gizmo/type.js +18 -0
- package/dist/gesture-handler/index.js +3 -0
- package/dist/gesture-handler/src/gesture-handler.js +770 -0
- package/dist/gesture-handler/src/icons.js +24 -0
- package/dist/gesture-handler/utils.js +40 -0
- package/dist/html-overlay/anchor-navigation-runtime.js +27 -0
- package/dist/html-overlay/auto-height-runtime.js +132 -0
- package/dist/html-overlay/document-runtime.js +71 -0
- package/dist/html-overlay/document-transform.js +96 -0
- package/dist/html-overlay/dom-order.js +8 -0
- package/dist/html-overlay/host-message-runtime.js +24 -0
- package/dist/html-overlay/html-capture-runtime.js +282 -0
- package/dist/html-overlay/html-viewport-style.js +10 -0
- package/dist/html-overlay/index.js +1 -0
- package/dist/html-overlay/manager.js +1663 -0
- package/dist/html-overlay/mime-utils.js +21 -0
- package/dist/html-overlay/overlay-transform.js +57 -0
- package/dist/html-overlay/path-utils.js +35 -0
- package/dist/html-overlay/shell-runtime.js +12 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -75311
- package/dist/index.mjs +75311 -0
- package/dist/{index.js.map → index.mjs.map} +1 -1
- package/dist/layer-order.js +8 -0
- package/dist/math/box2.js +396 -0
- package/dist/math/circle.js +131 -0
- package/dist/math/euler.js +35 -0
- package/dist/math/index.js +13 -0
- package/dist/math/line2.js +153 -0
- package/dist/math/line3.js +36 -0
- package/dist/math/matrix4.js +207 -0
- package/dist/math/plane.js +52 -0
- package/dist/math/quaternion.js +3 -0
- package/dist/math/ray-caster.js +25 -0
- package/dist/math/ray.js +47 -0
- package/dist/math/type.js +1 -0
- package/dist/math/utils.js +77 -0
- package/dist/math/vector2.js +70 -0
- package/dist/math/vector3.js +60 -0
- package/dist/screen-shot/index.js +1 -0
- package/dist/screen-shot/screen-shot.js +113 -0
- package/dist/sdk-item/base-item.js +160 -0
- package/dist/sdk-item/card-item.js +131 -0
- package/dist/sdk-item/effects-item.js +144 -0
- package/dist/sdk-item/frame-item.js +217 -0
- package/dist/sdk-item/generator-item.js +188 -0
- package/dist/sdk-item/group-item.js +116 -0
- package/dist/sdk-item/index.js +39 -0
- package/dist/sdk-item/sprite-item.js +147 -0
- package/dist/sdk-item/text-item.js +223 -0
- package/dist/sdk-item/types.d.ts +1 -1
- package/dist/sdk-item/types.js +15 -0
- package/dist/sdk-item/video-item.js +174 -0
- package/dist/sdk.js +1903 -0
- package/dist/service/UndoRedo.js +79 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +2 -0
- package/dist/shared/player.d.ts +1 -1
- package/dist/shared/player.js +9 -0
- package/dist/shared/spec.d.ts +1 -0
- package/dist/shared/spec.js +1 -0
- package/dist/size-adapte/index.js +1 -0
- package/dist/size-adapte/size-adapt.js +395 -0
- package/dist/types.d.ts +5 -1
- package/dist/types.js +17 -0
- package/dist/utils/background-manager.js +189 -0
- package/dist/utils/common-utils.js +183 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/interaction-utils.js +205 -0
- package/dist/utils/json-data-utils.js +1529 -0
- package/dist/utils/layout-utils.js +1217 -0
- package/dist/utils/page-data-utils.js +5397 -0
- package/dist/utils/player-data-utils.js +48 -0
- package/dist/utils/types.js +8 -0
- package/dist/wireframe/common/box.js +18 -0
- package/dist/wireframe/common/dashed-line.js +21 -0
- package/dist/wireframe/common/line.js +17 -0
- package/dist/wireframe/common/pixi-ext.js +1 -0
- package/dist/wireframe/common/pixi.js +31 -0
- package/dist/wireframe/index.js +4 -0
- package/package.json +10 -3
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { Graphics } from '@pixi/graphics';
|
|
2
|
+
import '../../wireframe/common/pixi-ext';
|
|
3
|
+
import { SDK } from '../../sdk';
|
|
4
|
+
import { Box2 } from '../../math/box2';
|
|
5
|
+
import { spec, SpriteComponent, TextComponent, VideoComponent, RichTextComponent } from '../../shared';
|
|
6
|
+
import { Gizmo } from './gizmo';
|
|
7
|
+
import { Ray, Vector2 } from '../../math';
|
|
8
|
+
import { arrAdd } from '../../utils/common-utils';
|
|
9
|
+
import { isCardItem, isEffectsItem, isFrameItem, SDKItemType } from '../../sdk-item';
|
|
10
|
+
/**
|
|
11
|
+
* @description 画板元素左上角点击交互区域尺寸
|
|
12
|
+
*/
|
|
13
|
+
const FRAME_INTERACTION_WIDTH = 40;
|
|
14
|
+
const FRAME_INTERACTION_HEIGHT = 20;
|
|
15
|
+
export class SelectorGizmo extends Gizmo {
|
|
16
|
+
/**
|
|
17
|
+
* @description 点选绘制结果
|
|
18
|
+
*/
|
|
19
|
+
result = {
|
|
20
|
+
type: 'null',
|
|
21
|
+
box: new Box2(),
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* @description 选中元素ID
|
|
25
|
+
*/
|
|
26
|
+
selectedItemIds = [];
|
|
27
|
+
/**
|
|
28
|
+
* @description 可选择子元素父节点序号
|
|
29
|
+
*/
|
|
30
|
+
activeParentIds = [];
|
|
31
|
+
/**
|
|
32
|
+
* @description 框选鼠标起始点
|
|
33
|
+
*/
|
|
34
|
+
cursorPoint = new Vector2();
|
|
35
|
+
/**
|
|
36
|
+
* @description 交互起始点
|
|
37
|
+
*/
|
|
38
|
+
startPoint = new Vector2();
|
|
39
|
+
/**
|
|
40
|
+
* @description 预处理鼠标位置
|
|
41
|
+
*/
|
|
42
|
+
firstClickPoint = new Vector2();
|
|
43
|
+
/**
|
|
44
|
+
* @description 选择器图形
|
|
45
|
+
*/
|
|
46
|
+
graphics = new Graphics();
|
|
47
|
+
pageDataUtils;
|
|
48
|
+
clearResult = false;
|
|
49
|
+
type = 'selector';
|
|
50
|
+
get interactive() {
|
|
51
|
+
return SDK.config.gestureHandlerConfig.selectorGizmoEnabled;
|
|
52
|
+
}
|
|
53
|
+
set interactive(bool) {
|
|
54
|
+
SDK.config.gestureHandlerConfig.selectorGizmoEnabled = true;
|
|
55
|
+
}
|
|
56
|
+
constructor(utils) {
|
|
57
|
+
super();
|
|
58
|
+
this.pageDataUtils = utils;
|
|
59
|
+
}
|
|
60
|
+
actionKey() { }
|
|
61
|
+
endActionKey() { }
|
|
62
|
+
/**
|
|
63
|
+
* 获取选择器交互绘制结果
|
|
64
|
+
* @returns 点选交互信息
|
|
65
|
+
*/
|
|
66
|
+
getRenderObjects() {
|
|
67
|
+
if (!this.interactive) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
if (!this.clearResult) {
|
|
71
|
+
this.refreshResults();
|
|
72
|
+
return [this.graphics];
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.result = {
|
|
76
|
+
type: 'null',
|
|
77
|
+
box: new Box2()
|
|
78
|
+
};
|
|
79
|
+
this.clearResult = false;
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 取消预备状态
|
|
85
|
+
*/
|
|
86
|
+
cancelPreparation() {
|
|
87
|
+
this.result.type = 'null';
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 准备行动事件 - 预选
|
|
91
|
+
* @param event 鼠标事件
|
|
92
|
+
*/
|
|
93
|
+
preparationAction(event, targetType) {
|
|
94
|
+
this.result.box = new Box2();
|
|
95
|
+
if (!this.interactive) {
|
|
96
|
+
console.warn('Selector gizmo is not opened, use #SDK.setSelectorConfig() open this feature.');
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
// 获取鼠标位置
|
|
100
|
+
// 根据鼠标位置进行射线碰撞
|
|
101
|
+
const mousePoint = new Vector2(event.offsetX, event.offsetY);
|
|
102
|
+
const originSelectedItemIDs = this.hitTest(mousePoint);
|
|
103
|
+
this.selectedItemIds = this.filterSelectedItems(originSelectedItemIDs);
|
|
104
|
+
const id = this.selectedItemIds[0] ?? '';
|
|
105
|
+
this.resetActiveParentIds(id);
|
|
106
|
+
const allSelected = [...this.pageDataUtils.getPageData().activeData.selectedItems, ...this.pageDataUtils.getPageData().activeData.selectedItems.flatMap(id => this.pageDataUtils.getChildrenIds(id))];
|
|
107
|
+
const hasPreSelectedId = this.pageDataUtils.getPageData()?.activeData.preSelectedItem;
|
|
108
|
+
if ((id.length && (targetType && !allSelected.includes(id))) || !targetType) {
|
|
109
|
+
// 根据碰撞结果获取预选结果
|
|
110
|
+
// 当预选结果存在且未被选中时,添加辅助绘制结果 && 当不是直接触发预选时,筛选掉子元素
|
|
111
|
+
if (id.length
|
|
112
|
+
&& !this.pageDataUtils.isItemSelected(id)
|
|
113
|
+
&& !allSelected.includes(id)) {
|
|
114
|
+
this.pageDataUtils.addPreSelectedItem(id);
|
|
115
|
+
if (id !== hasPreSelectedId) {
|
|
116
|
+
this.pageDataUtils.playVideoItem(id);
|
|
117
|
+
this.pageDataUtils.playEffectsItem(id);
|
|
118
|
+
this.pageDataUtils.pauseVideoItem(hasPreSelectedId);
|
|
119
|
+
this.pageDataUtils.pauseEffectsItem(hasPreSelectedId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.pageDataUtils.pauseVideoItem(hasPreSelectedId);
|
|
124
|
+
this.pageDataUtils.pauseEffectsItem(hasPreSelectedId);
|
|
125
|
+
this.pageDataUtils.clearPreSelectedItem();
|
|
126
|
+
}
|
|
127
|
+
return this.type;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this.pageDataUtils.pauseVideoItem(hasPreSelectedId);
|
|
131
|
+
this.pageDataUtils.pauseEffectsItem(hasPreSelectedId);
|
|
132
|
+
this.pageDataUtils.clearPreSelectedItem();
|
|
133
|
+
return targetType;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 行动前置事件
|
|
138
|
+
* - 二维模式 设置框选起始状态 || 选中元素
|
|
139
|
+
* - 三维模式 设置交互起始态 || 选中元素
|
|
140
|
+
* @description 当未处于预选态时,表明触发框选交互,设置起始点;当处于预选态时,表明触发 transformGizmo.
|
|
141
|
+
* @param event 鼠标事件
|
|
142
|
+
*/
|
|
143
|
+
preAction(event, isDoubleClick = false, firstClickPoint) {
|
|
144
|
+
if (!this.interactive) {
|
|
145
|
+
console.warn('Selector gizmo is not opened, use #SDK.setSelectorConfig() open this feature.');
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
const hasPreSelectedId = this.pageDataUtils.getPageData()?.activeData.preSelectedItem;
|
|
149
|
+
this.pageDataUtils.pauseVideoItem(hasPreSelectedId);
|
|
150
|
+
this.pageDataUtils.pauseEffectsItem(hasPreSelectedId);
|
|
151
|
+
this.pageDataUtils.clearPreSelectedItem();
|
|
152
|
+
// 根据左右键来区分点选交互逻辑
|
|
153
|
+
switch (event.button) {
|
|
154
|
+
// 左键前置事件
|
|
155
|
+
case 0: {
|
|
156
|
+
// 未触发多选逻辑时,清空原有选中元素,添加当前选中元素
|
|
157
|
+
const currentMousePoint = new Vector2(event.offsetX, event.offsetY);
|
|
158
|
+
firstClickPoint ??= this.firstClickPoint;
|
|
159
|
+
if (isDoubleClick && currentMousePoint.distanceTo(firstClickPoint) < 4) {
|
|
160
|
+
const mousePosition = new Vector2(event.offsetX, event.offsetY);
|
|
161
|
+
const originSelectedItemIDs = this.hitTest(mousePosition);
|
|
162
|
+
this.selectedItemIds = this.filterSelectedItems(originSelectedItemIDs);
|
|
163
|
+
}
|
|
164
|
+
if (!isDoubleClick) {
|
|
165
|
+
this.firstClickPoint.set(event.offsetX, event.offsetY);
|
|
166
|
+
}
|
|
167
|
+
if (!event.shiftKey) {
|
|
168
|
+
this.pageDataUtils.clearSelectedItems(this.selectedItemIds.length === 0);
|
|
169
|
+
}
|
|
170
|
+
else if (isDoubleClick) {
|
|
171
|
+
// 清除选中元素父级的选中态
|
|
172
|
+
const selected = this.selectedItemIds[0];
|
|
173
|
+
if (selected) {
|
|
174
|
+
const viewItem = this.pageDataUtils.getSDKItem(selected);
|
|
175
|
+
if (viewItem?.parentId) {
|
|
176
|
+
this.pageDataUtils.removeSelectedItems([viewItem.parentId]);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// 框选逻辑
|
|
181
|
+
if (this.selectedItemIds.length === 0) {
|
|
182
|
+
this.startPoint = new Vector2(event.clientX, event.clientY);
|
|
183
|
+
this.cursorPoint = new Vector2(event.offsetX, event.offsetY);
|
|
184
|
+
this.activeParentIds = [];
|
|
185
|
+
this.active = true;
|
|
186
|
+
return this.type;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
const selectedIds = this.addSelectedItem(this.selectedItemIds[0]);
|
|
190
|
+
if (selectedIds?.length === 1 && this.pageDataUtils.getSDKItem(selectedIds[0])?.type === SDKItemType.TEXT) {
|
|
191
|
+
return 'text';
|
|
192
|
+
}
|
|
193
|
+
return 'transform';
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// 右键前置事件
|
|
197
|
+
case 2: {
|
|
198
|
+
// 仅当存在预选中元素时刷新选中元素,否则不刷新
|
|
199
|
+
const allSelected = [...this.pageDataUtils.getPageData().activeData.selectedItems, ...this.pageDataUtils.getPageData().activeData.selectedItems.flatMap(id => this.pageDataUtils.getChildrenIds(id))];
|
|
200
|
+
if (this.selectedItemIds.length && !allSelected.includes(this.selectedItemIds[0])) {
|
|
201
|
+
if (!event.shiftKey) {
|
|
202
|
+
this.pageDataUtils.clearSelectedItems();
|
|
203
|
+
}
|
|
204
|
+
this.pageDataUtils.addSelectedItems([this.selectedItemIds[0]]);
|
|
205
|
+
this.clearResult = true;
|
|
206
|
+
}
|
|
207
|
+
// 存储变更前的值
|
|
208
|
+
this.pageDataUtils.saveUndoRedoOldData();
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
// 其它按键
|
|
212
|
+
default: {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 行动事件 - 框选[仅支持2D框选]
|
|
219
|
+
* @param event 鼠标事件
|
|
220
|
+
*/
|
|
221
|
+
action(event) {
|
|
222
|
+
const endPoint = new Vector2().addVectors(this.cursorPoint, new Vector2().subtractVectors(new Vector2(event.clientX, event.clientY), this.startPoint));
|
|
223
|
+
const size = new Vector2().subtractVectors(this.cursorPoint, endPoint);
|
|
224
|
+
const center = new Vector2().addVectors(this.cursorPoint, endPoint).multiply(0.5);
|
|
225
|
+
size.x = Math.abs(size.x);
|
|
226
|
+
size.y = Math.abs(size.y);
|
|
227
|
+
const box = new Box2().setFromCenterAndSize(center, size);
|
|
228
|
+
this.result.type = 'region';
|
|
229
|
+
this.result.box = box;
|
|
230
|
+
this.pageDataUtils.clearSelectedItems();
|
|
231
|
+
const items = this.pageDataUtils.getPageData().items?.filter(item => this.pageDataUtils.getItemEditEnable(item.id));
|
|
232
|
+
const toAddItems = [];
|
|
233
|
+
// 进行框选判断时,跳过locked或不可见状态元素
|
|
234
|
+
if (size.length() > 0) {
|
|
235
|
+
items?.forEach(item => {
|
|
236
|
+
if (box.intersectsBox(this.pageDataUtils.getViewBoxById(item.id), false)) {
|
|
237
|
+
toAddItems.push(item.id);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
const resultSelectedIds = this.filterSelectedItems(toAddItems);
|
|
242
|
+
this.pageDataUtils.addSelectedItems(resultSelectedIds);
|
|
243
|
+
}
|
|
244
|
+
endAction() {
|
|
245
|
+
this.active = false;
|
|
246
|
+
this.result.type = 'null';
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
addSelectedItem(id) {
|
|
250
|
+
this.pageDataUtils.addSelectedItems([id]);
|
|
251
|
+
const selectedIds = this.pageDataUtils.getPageData()?.activeData?.selectedItems;
|
|
252
|
+
this.addActiveParentIds(selectedIds);
|
|
253
|
+
this.clearResult = true;
|
|
254
|
+
// 存储变更前的值
|
|
255
|
+
this.pageDataUtils.saveUndoRedoOldData();
|
|
256
|
+
return selectedIds;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* 交互中断事件 - 清空交互状态, 重新进行交互Gizmo选中
|
|
260
|
+
* @returns undefined
|
|
261
|
+
*/
|
|
262
|
+
interruption() {
|
|
263
|
+
this.active = false;
|
|
264
|
+
this.result.type = 'null';
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* 射线碰撞结果
|
|
269
|
+
* @param point 屏幕点坐标
|
|
270
|
+
* @param cameraState 相机状态
|
|
271
|
+
* @param isLeftDown 是否为左键
|
|
272
|
+
* @returns 射线碰撞结果
|
|
273
|
+
*/
|
|
274
|
+
hitTest(point) {
|
|
275
|
+
const playerComposition = this.pageDataUtils.getCurrentComposition();
|
|
276
|
+
if (!playerComposition?.items) {
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
const { x, y } = this.pageDataUtils.getViewportByViewPoint(point);
|
|
280
|
+
const result = {
|
|
281
|
+
ray: new Ray(),
|
|
282
|
+
regions: [],
|
|
283
|
+
};
|
|
284
|
+
try {
|
|
285
|
+
result.regions = playerComposition.hitTest(x, y, true);
|
|
286
|
+
result.ray = playerComposition.getHitTestRay(x, y);
|
|
287
|
+
}
|
|
288
|
+
catch (e) {
|
|
289
|
+
console.warn(e);
|
|
290
|
+
}
|
|
291
|
+
this.refreshResultRegions(result);
|
|
292
|
+
const selectedIds = this.reorderHitTestResult(result, playerComposition).filter(id => id !== 'extra-camera' && this.pageDataUtils.getItemEditEnable(id));
|
|
293
|
+
// 新增画板元素强制选中规则
|
|
294
|
+
const resultSelectedIds = this.preSelectedFrameOutBound(point, selectedIds);
|
|
295
|
+
return resultSelectedIds;
|
|
296
|
+
}
|
|
297
|
+
refreshResultRegions(hitTestResult) {
|
|
298
|
+
const effectsItems = this.pageDataUtils.getPageData()?.items.filter(item => isEffectsItem(item));
|
|
299
|
+
const effectsItemMap = new Map();
|
|
300
|
+
effectsItems?.forEach(item => {
|
|
301
|
+
item.property.children?.forEach(id => {
|
|
302
|
+
effectsItemMap.set(id, item.id);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
hitTestResult.regions.forEach(region => {
|
|
306
|
+
region.id = effectsItemMap.get(region.id) ?? region.id;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
reorderHitTestResult(hitTestResult, playerComposition) {
|
|
310
|
+
if (hitTestResult.regions.length === 0 || !playerComposition) {
|
|
311
|
+
return [];
|
|
312
|
+
}
|
|
313
|
+
// 碰撞射线
|
|
314
|
+
const { ray } = hitTestResult;
|
|
315
|
+
// player碰撞元素顺序与编辑器列表相反,所以需要做一个顺序取反
|
|
316
|
+
const regions = hitTestResult.regions.reverse();
|
|
317
|
+
const results = [];
|
|
318
|
+
regions.forEach(region => {
|
|
319
|
+
let item;
|
|
320
|
+
const dfsItem = (items, id) => {
|
|
321
|
+
for (const i of items) {
|
|
322
|
+
if (i.getInstanceId() === id) {
|
|
323
|
+
item = i;
|
|
324
|
+
}
|
|
325
|
+
if (item) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
dfsItem(i.children, id);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
dfsItem(playerComposition.items, region.id);
|
|
332
|
+
if (item === undefined) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const targetItemId = item.getInstanceId();
|
|
336
|
+
const distance = ray.origin.clone().distance(region.position.clone());
|
|
337
|
+
// 是否需要深度判断[当元素开启深度遮挡以及为mesh元素时]
|
|
338
|
+
const isNeedDepthTest = item.type === spec.ItemType.mesh
|
|
339
|
+
|| item.getComponent(SpriteComponent)?.renderer?.occlusion
|
|
340
|
+
|| item.getComponent(TextComponent)?.renderer?.occlusion
|
|
341
|
+
|| item.getComponent(VideoComponent)?.renderer?.occlusion
|
|
342
|
+
|| item.getComponent(RichTextComponent)?.renderer?.occlusion;
|
|
343
|
+
// 当需要进行深度检测并且结果长度大于0时,进行判断
|
|
344
|
+
if (isNeedDepthTest && results.length > 0) {
|
|
345
|
+
// 添加状态 - 当添加状态为true时才会继续进行判断
|
|
346
|
+
let tryAdd = true;
|
|
347
|
+
results.forEach((result, i) => {
|
|
348
|
+
if (!tryAdd) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
// 如果当前distance小于或者等于结果distance时,表示当前结果会被优先选择,测试将当前值插入该位置,并且关闭添加状态,不继续进行判断
|
|
352
|
+
if (distance <= result[1]) {
|
|
353
|
+
results.splice(i, 0, [targetItemId, distance]);
|
|
354
|
+
tryAdd = false;
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
// 如果当前distance大于所有结果distance时,直接将当前值加入结果
|
|
358
|
+
if (i === results.length - 1) {
|
|
359
|
+
results.push([targetItemId, distance]);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
// 当不需要进行深度检测或结果长度等于0时,直接将当前值加入结果
|
|
365
|
+
results.push([targetItemId, distance]);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
// 返回元素顺序
|
|
369
|
+
return results.map(result => {
|
|
370
|
+
return result[0];
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
filterSelectedItems(selectedIds) {
|
|
374
|
+
const resultSelectedIds = [];
|
|
375
|
+
const getFinalSelectedId = (id) => {
|
|
376
|
+
const sdkItem = this.pageDataUtils.getSDKItem(id);
|
|
377
|
+
if (!sdkItem.parentId || this.pageDataUtils.getSDKItem(sdkItem.parentId)?.type === SDKItemType.FRAME || this.activeParentIds.includes(sdkItem.parentId)) {
|
|
378
|
+
return sdkItem.id;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
return getFinalSelectedId(sdkItem.parentId);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
const loadingItems = this.pageDataUtils.getPageData()?.activeData.loadingItems ?? [];
|
|
385
|
+
selectedIds.forEach(id => {
|
|
386
|
+
const finalSelectedId = getFinalSelectedId(id);
|
|
387
|
+
if (!loadingItems.includes(finalSelectedId)) {
|
|
388
|
+
arrAdd(resultSelectedIds, finalSelectedId);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
return resultSelectedIds;
|
|
392
|
+
}
|
|
393
|
+
addActiveParentIds(selectedIds) {
|
|
394
|
+
this.activeParentIds = [];
|
|
395
|
+
selectedIds?.forEach(id => {
|
|
396
|
+
const sdkItem = this.pageDataUtils.getSDKItem(id);
|
|
397
|
+
if (!sdkItem) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const addAllLayerParent = (id) => {
|
|
401
|
+
this.activeParentIds.push(id);
|
|
402
|
+
const sdkItem = this.pageDataUtils.getSDKItem(id);
|
|
403
|
+
if (sdkItem.parentId) {
|
|
404
|
+
addAllLayerParent(sdkItem.parentId);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
addAllLayerParent(id);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
resetActiveParentIds(id) {
|
|
411
|
+
const viewItem = this.pageDataUtils.getSDKItem(id);
|
|
412
|
+
if (!viewItem) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
this.activeParentIds = this.activeParentIds.filter(id => id === viewItem.parentId);
|
|
416
|
+
}
|
|
417
|
+
refreshResults() {
|
|
418
|
+
const { box } = this.result;
|
|
419
|
+
this.graphics.clear();
|
|
420
|
+
const preSelectedItem = this.pageDataUtils.getPreSelectedItem();
|
|
421
|
+
const preSelectedItemBox = this.pageDataUtils.getViewBoxById(preSelectedItem?.id ?? '');
|
|
422
|
+
const { regionBoxColor, regionBoxAlpha, preSelectedWidth, preSelectedColor, regionWireframeWidth, regionWireframeColor, regionWireframeAlpha, } = SDK.config.gestureHandlerConfig.selectorGizmoConfig;
|
|
423
|
+
if (!preSelectedItemBox?.isEmpty() && !isCardItem(preSelectedItem)) {
|
|
424
|
+
this.graphics.lineStyle(preSelectedWidth, preSelectedColor);
|
|
425
|
+
this.graphics.drawBox(preSelectedItemBox);
|
|
426
|
+
}
|
|
427
|
+
if (!box.isEmpty()) {
|
|
428
|
+
switch (this.result.type) {
|
|
429
|
+
case 'region': {
|
|
430
|
+
this.graphics.lineStyle(regionWireframeWidth, regionWireframeColor, regionWireframeAlpha);
|
|
431
|
+
this.graphics.drawBox(box);
|
|
432
|
+
this.graphics.beginFill(regionBoxColor, regionBoxAlpha);
|
|
433
|
+
this.graphics.fillBox(box);
|
|
434
|
+
this.graphics.endFill();
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* 画板元素点击区域优先处理
|
|
442
|
+
* 当点击画板左上角 40x20 区域时,强制优先选中画板
|
|
443
|
+
* @param mouse 鼠标位置
|
|
444
|
+
* @param currentSelectedIds 当前选中的元素ID列表
|
|
445
|
+
* @returns 处理后的选中ID列表
|
|
446
|
+
*/
|
|
447
|
+
preSelectedFrameOutBound(mouse, currentSelectedIds) {
|
|
448
|
+
const frameBoxInfoes = this.pageDataUtils.getPageData()?.items.filter(item => isFrameItem(item)).map(item => {
|
|
449
|
+
return { id: item.id, box: this.pageDataUtils.getViewBoxById(item.id) };
|
|
450
|
+
});
|
|
451
|
+
if (!frameBoxInfoes?.length) {
|
|
452
|
+
return currentSelectedIds;
|
|
453
|
+
}
|
|
454
|
+
let hasSelectedFrame = false;
|
|
455
|
+
frameBoxInfoes.forEach(frameBoxInfo => {
|
|
456
|
+
if (hasSelectedFrame) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const { min } = frameBoxInfo.box;
|
|
460
|
+
const interactionBox = new Box2().setFromVec2Array([min.clone(), min.clone().add(new Vector2(FRAME_INTERACTION_WIDTH, -FRAME_INTERACTION_HEIGHT))]);
|
|
461
|
+
if (interactionBox.containsPoint(mouse)) {
|
|
462
|
+
hasSelectedFrame = true;
|
|
463
|
+
currentSelectedIds.splice(0, 0, frameBoxInfo.id);
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
return currentSelectedIds;
|
|
467
|
+
}
|
|
468
|
+
}
|