lythreeframe 1.0.0
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/lythreeFrame/exporter.ts +36 -0
- package/lythreeFrame/src/AssetManagement/AssetDefines.ts +8 -0
- package/lythreeFrame/src/AssetManagement/AssetManager.ts +286 -0
- package/lythreeFrame/src/AssetManagement/AssetPointer/AssetPointer.ts +41 -0
- package/lythreeFrame/src/AssetManagement/Task/Task.ts +24 -0
- package/lythreeFrame/src/Container/SmartPointer.ts +54 -0
- package/lythreeFrame/src/Defines.ts +11 -0
- package/lythreeFrame/src/Delegate.ts +37 -0
- package/lythreeFrame/src/Factory/CameraFactory.ts +81 -0
- package/lythreeFrame/src/Factory/RendererFactory.ts +7 -0
- package/lythreeFrame/src/Frame/Controller.ts +261 -0
- package/lythreeFrame/src/Frame/Viewport.ts +516 -0
- package/lythreeFrame/src/Frame/World.ts +59 -0
- package/lythreeFrame/src/Frame.ts +511 -0
- package/lythreeFrame/src/Geometry/PlaneGeometry.ts +53 -0
- package/lythreeFrame/src/Geometry/TriangleGeometry.ts +50 -0
- package/lythreeFrame/src/Library/ContainerLibrary.ts +21 -0
- package/lythreeFrame/src/Library/MaterialLibrary.ts +288 -0
- package/lythreeFrame/src/Library/Math.ts +154 -0
- package/lythreeFrame/src/Library/ResourceLibrary.ts +21 -0
- package/lythreeFrame/src/Object/Actor.ts +571 -0
- package/lythreeFrame/src/Object/Actors/Camera/CameraActor.ts +11 -0
- package/lythreeFrame/src/Object/Actors/Light/DirectionalLightActor.ts +18 -0
- package/lythreeFrame/src/Object/Actors/Shape/BoxActor.ts +20 -0
- package/lythreeFrame/src/Object/Actors/Shape/CurveActor.ts +11 -0
- package/lythreeFrame/src/Object/Actors/Shape/PlaneActor.ts +27 -0
- package/lythreeFrame/src/Object/Actors/Shape/TubeActor.ts +37 -0
- package/lythreeFrame/src/Object/BaseObject.ts +45 -0
- package/lythreeFrame/src/Object/Components/2D/2DComponent.ts +64 -0
- package/lythreeFrame/src/Object/Components/Camera/CameraComponent.ts +113 -0
- package/lythreeFrame/src/Object/Components/Component.ts +67 -0
- package/lythreeFrame/src/Object/Components/Light/DirectionalLight/DirectionalLightComponent.ts +78 -0
- package/lythreeFrame/src/Object/Components/Light/LightComponent.ts +54 -0
- package/lythreeFrame/src/Object/Components/Mesh/InstanceMesh/InstanceMeshComponent.ts +39 -0
- package/lythreeFrame/src/Object/Components/Mesh/InstanceMesh/MultiInstanceMeshComponent.ts +115 -0
- package/lythreeFrame/src/Object/Components/Mesh/Line/CurveComponent.ts +221 -0
- package/lythreeFrame/src/Object/Components/Mesh/MeshComponent.ts +162 -0
- package/lythreeFrame/src/Object/Components/Mesh/Shape/BoxComponent.ts +17 -0
- package/lythreeFrame/src/Object/Components/Mesh/Shape/PlaneComponent.ts +10 -0
- package/lythreeFrame/src/Object/Components/Mesh/Shape/SphereComponent.ts +10 -0
- package/lythreeFrame/src/Object/Components/Mesh/Sprite/SpriteComponent.ts +32 -0
- package/lythreeFrame/src/Object/Components/SceneComponent.ts +809 -0
- package/lythreeFrame/src/Object/Controller/Controller.ts +764 -0
- package/lythreeFrame/src/Object/Pawn/CameraStatus.ts +262 -0
- package/lythreeFrame/src/Object/Pawn/FirstPerson.ts +230 -0
- package/lythreeFrame/src/Object/Pawn/Oribital.ts +276 -0
- package/lythreeFrame/src/Object/Pawn/PawnBase.ts +189 -0
- package/lythreeFrame/src/Object/Pawn/TopView.ts +205 -0
- package/lythreeFrame/src/Object/Pawn/TransformControl.ts +215 -0
- package/lythreeFrame/src/Object/Pawn/staticCamera.ts +80 -0
- package/lythreeFrame/src/Object/PawnV2/FirstPerson.ts +12 -0
- package/lythreeFrame/src/Object/PawnV2/Oribital.ts +45 -0
- package/lythreeFrame/src/Object/PawnV2/Pawn.ts +50 -0
- package/lythreeFrame/src/Object/PawnV2/TransformControl.ts +201 -0
- package/lythreeFrame/src/PostProcess/Param/Bloom.ts +12 -0
- package/lythreeFrame/src/PostProcess/Param/DOF.ts +14 -0
- package/lythreeFrame/src/PostProcess/Param/Denoise.ts +14 -0
- package/lythreeFrame/src/PostProcess/Param/GTAO.ts +21 -0
- package/lythreeFrame/src/PostProcess/Param/LensFlare.ts +11 -0
- package/lythreeFrame/src/PostProcess/Param/MotionBlur.ts +8 -0
- package/lythreeFrame/src/PostProcess/Param/Outline.ts +20 -0
- package/lythreeFrame/src/PostProcess/Param/SSR.ts +11 -0
- package/lythreeFrame/src/PostProcess/Param/ToneMapping.ts +31 -0
- package/lythreeFrame/src/PostProcess/PostProcessParam.ts +26 -0
- package/lythreeFrame/src/PostProcess/WebGPUPostProcessFactory.ts +217 -0
- package/lythreeFrame/src/Shader/Postprocess/ColorShader.ts +49 -0
- package/lythreeFrame/src/ThreeJsApp.ts +124 -0
- package/package.json +21 -0
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
|
|
2
|
+
// import {LYRaycaster} from '../Raycast/Raycaster';
|
|
3
|
+
// import {PerspectiveCamera, Quaternion, Vector2, Camera, Object3D, Vector3, Mesh} from "three";
|
|
4
|
+
// import {LYOrbital} from "../Pawn/Oribital";
|
|
5
|
+
// import {ITransforming, LYTransformControl} from "../Pawn/TransformControl";
|
|
6
|
+
// import {LYDelegate} from "../../Delegate";
|
|
7
|
+
// import {LYThreeWorld} from "../../Frame";
|
|
8
|
+
|
|
9
|
+
// import {SceneComponent} from "../Components/SceneComponent.ts";
|
|
10
|
+
// import {PawnBase} from "../Pawn/PawnBase.ts";
|
|
11
|
+
|
|
12
|
+
// const maxClickTime = 0.15; // The time between left mouse button down and left mouse button up if greater than this, will not trigger click event.
|
|
13
|
+
|
|
14
|
+
// // forever tick
|
|
15
|
+
// export class LYController
|
|
16
|
+
// {
|
|
17
|
+
// protected hoverable: SceneComponent[] = []
|
|
18
|
+
// protected clickable: SceneComponent[] = []
|
|
19
|
+
// protected blockingMesh: Mesh[] = []
|
|
20
|
+
// protected world:LYThreeWorld
|
|
21
|
+
// protected pawn: PawnBase | null = null
|
|
22
|
+
// protected cameraStat
|
|
23
|
+
// protected camera: Camera | null
|
|
24
|
+
// protected transformControl
|
|
25
|
+
// protected onClickNullEvent: Function[] = []
|
|
26
|
+
// protected bLeftMouseButtonDown: boolean = false
|
|
27
|
+
// protected leftMouseButtonDownTime: number = 0
|
|
28
|
+
|
|
29
|
+
// protected onMouseUpDelegate: LYDelegate = new LYDelegate();
|
|
30
|
+
// protected onMouseMoveDelegate: LYDelegate = new LYDelegate();
|
|
31
|
+
// protected onMouseEnterDelegate: LYDelegate = new LYDelegate();
|
|
32
|
+
// protected onMouseLeaveDelegate: LYDelegate = new LYDelegate();
|
|
33
|
+
|
|
34
|
+
// protected resizeObserver
|
|
35
|
+
// protected onPointerUpFunc: Function
|
|
36
|
+
// protected onPointerDownFunc: Function
|
|
37
|
+
// protected onPointerMoveFunc: Function
|
|
38
|
+
// protected onPointerEnterFunc: Function
|
|
39
|
+
// protected onPointerLeaveFunc: Function
|
|
40
|
+
|
|
41
|
+
// protected pointer: Vector2;
|
|
42
|
+
// private hoveringComp: SceneComponent[] = [];
|
|
43
|
+
|
|
44
|
+
// private ray = null;
|
|
45
|
+
// public bLockCameraRotationByMouseMove: boolean = false;
|
|
46
|
+
// public bCameraRotationLockedAlready: boolean = true;
|
|
47
|
+
// private startPointerDownPos: Vector2;
|
|
48
|
+
|
|
49
|
+
// protected onCameraMoveEvents: Function[] = []
|
|
50
|
+
// private onCameraMove: Function
|
|
51
|
+
// private onCameraChangedDelegate: LYDelegate = new LYDelegate()
|
|
52
|
+
|
|
53
|
+
// get hoverDepth(): number
|
|
54
|
+
// {
|
|
55
|
+
// return this._hoverDepth;
|
|
56
|
+
// }
|
|
57
|
+
|
|
58
|
+
// set hoverDepth(value: number)
|
|
59
|
+
// {
|
|
60
|
+
// this._hoverDepth = Math.floor(value);
|
|
61
|
+
// }
|
|
62
|
+
|
|
63
|
+
// private _hoverDepth: number = 1;
|
|
64
|
+
|
|
65
|
+
// constructor(world: LYThreeWorld)
|
|
66
|
+
// {
|
|
67
|
+
|
|
68
|
+
// this.world = world
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
// this.transformControl = null;
|
|
72
|
+
|
|
73
|
+
// this.pointer = new Vector2();
|
|
74
|
+
|
|
75
|
+
// this.ray = null
|
|
76
|
+
// this.hoverable = [];
|
|
77
|
+
// this.clickable = []
|
|
78
|
+
|
|
79
|
+
// this.cameraStat = null;
|
|
80
|
+
|
|
81
|
+
// this.IsTickable = true;
|
|
82
|
+
|
|
83
|
+
// this.leftMouseButtonDownTime = 0;
|
|
84
|
+
// this.bLeftMouseButtonDown = false;
|
|
85
|
+
|
|
86
|
+
// this.onPointerMoveFunc = () =>
|
|
87
|
+
// {
|
|
88
|
+
// this.onPointerMove(event)
|
|
89
|
+
// };
|
|
90
|
+
// this.onPointerDownFunc = () =>
|
|
91
|
+
// {
|
|
92
|
+
// this.onPointerDown(event)
|
|
93
|
+
// };
|
|
94
|
+
// this.onPointerUpFunc = () =>
|
|
95
|
+
// {
|
|
96
|
+
// this.onPointerUp(event)
|
|
97
|
+
// };
|
|
98
|
+
// this.onPointerEnterFunc = () =>
|
|
99
|
+
// {
|
|
100
|
+
// this.onMouseEnterCanvas()
|
|
101
|
+
// };
|
|
102
|
+
// this.onPointerLeaveFunc = () =>
|
|
103
|
+
// {
|
|
104
|
+
// this.onMouseLeaveCanvas()
|
|
105
|
+
// };
|
|
106
|
+
// this.onCameraMove = () =>
|
|
107
|
+
// {
|
|
108
|
+
// this.onCameraMoveEvents.forEach((elem) =>
|
|
109
|
+
// {
|
|
110
|
+
// elem()
|
|
111
|
+
// })
|
|
112
|
+
// }
|
|
113
|
+
// this.switchPawnMode(new LYOrbital(this.world))
|
|
114
|
+
|
|
115
|
+
// }
|
|
116
|
+
|
|
117
|
+
// init()
|
|
118
|
+
// {
|
|
119
|
+
// // if (!this.camera)
|
|
120
|
+
// // {
|
|
121
|
+
// // let ele = this.world.Element;
|
|
122
|
+
// // this.switchCamera(new PerspectiveCamera(90, ele.clientWidth / ele.clientHeight, 0.5, 7000))
|
|
123
|
+
// // }
|
|
124
|
+
// // if (!this.pawn)
|
|
125
|
+
// // {
|
|
126
|
+
// // this.pawn = new LYOrbital(this.world, this.Camera);
|
|
127
|
+
// // this.pawn.possess(this.onCameraMove);
|
|
128
|
+
// // }
|
|
129
|
+
|
|
130
|
+
// this.resizeObserver = new ResizeObserver((entries) =>
|
|
131
|
+
// {
|
|
132
|
+
// for (let entry of entries)
|
|
133
|
+
// {
|
|
134
|
+
// if (entry.contentBoxSize)
|
|
135
|
+
// {
|
|
136
|
+
// this.onWindowResize()
|
|
137
|
+
// }
|
|
138
|
+
// }
|
|
139
|
+
// });
|
|
140
|
+
// this.resizeObserver.observe(this.world.OuterElement);
|
|
141
|
+
|
|
142
|
+
// this.onMouseEnterCanvas()
|
|
143
|
+
// let ele = this.world.Element
|
|
144
|
+
// ele.addEventListener('mouseenter', this.onPointerEnterFunc);
|
|
145
|
+
// ele.addEventListener("mouseleave", this.onPointerLeaveFunc);
|
|
146
|
+
// }
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
// addCameraMoveEvent(newFunc: Function)
|
|
150
|
+
// {
|
|
151
|
+
// this.onCameraMoveEvents.push(newFunc)
|
|
152
|
+
// }
|
|
153
|
+
|
|
154
|
+
// removeCameraMoveEvent(target: Function)
|
|
155
|
+
// {
|
|
156
|
+
// let index = this.onCameraMoveEvents.indexOf(target)
|
|
157
|
+
// if (index >= 0)
|
|
158
|
+
// {
|
|
159
|
+
// this.onCameraMoveEvents.splice(index, 1)
|
|
160
|
+
// }
|
|
161
|
+
// }
|
|
162
|
+
|
|
163
|
+
// get OnMouseUp()
|
|
164
|
+
// {
|
|
165
|
+
// return this.onMouseUpDelegate
|
|
166
|
+
// }
|
|
167
|
+
|
|
168
|
+
// get OnMouseMove()
|
|
169
|
+
// {
|
|
170
|
+
// return this.onMouseMoveDelegate
|
|
171
|
+
// }
|
|
172
|
+
|
|
173
|
+
// get onMouseEnter()
|
|
174
|
+
// {
|
|
175
|
+
// return this.onMouseEnterDelegate
|
|
176
|
+
// }
|
|
177
|
+
|
|
178
|
+
// get onMouseLeave()
|
|
179
|
+
// {
|
|
180
|
+
// return this.onMouseLeaveDelegate
|
|
181
|
+
// }
|
|
182
|
+
|
|
183
|
+
// // forever tick
|
|
184
|
+
// set IsTickable(bCanTick)
|
|
185
|
+
// {
|
|
186
|
+
// super.IsTickable = true;
|
|
187
|
+
// }
|
|
188
|
+
|
|
189
|
+
// // tick function, not supposed to be called
|
|
190
|
+
// tick(deltaTime:number)
|
|
191
|
+
// {
|
|
192
|
+
|
|
193
|
+
// if (this.pawn)
|
|
194
|
+
// {
|
|
195
|
+
// this.pawn.tick(deltaTime)
|
|
196
|
+
// }
|
|
197
|
+
// if (this.transformControl)
|
|
198
|
+
// {
|
|
199
|
+
// this.transformControl.tick(deltaTime)
|
|
200
|
+
|
|
201
|
+
// }
|
|
202
|
+
// if (this.bLeftMouseButtonDown)
|
|
203
|
+
// {
|
|
204
|
+
// this.leftMouseButtonDownTime += deltaTime
|
|
205
|
+
// }
|
|
206
|
+
// }
|
|
207
|
+
|
|
208
|
+
// // current camera
|
|
209
|
+
// get Camera(): Camera | null
|
|
210
|
+
// {
|
|
211
|
+
// return this.pawn?.Camera || null;
|
|
212
|
+
// }
|
|
213
|
+
|
|
214
|
+
// get onCameraChanged(): LYDelegate
|
|
215
|
+
// {
|
|
216
|
+
// return this.onCameraChangedDelegate
|
|
217
|
+
// }
|
|
218
|
+
|
|
219
|
+
// // control method
|
|
220
|
+
// get PawnMode()
|
|
221
|
+
// {
|
|
222
|
+
// return this.pawn
|
|
223
|
+
// }
|
|
224
|
+
|
|
225
|
+
// switchPawnMode(newPawn: PawnBase)
|
|
226
|
+
// {
|
|
227
|
+
// let oldPawn = this.pawn
|
|
228
|
+
|
|
229
|
+
// this.pawn = newPawn
|
|
230
|
+
// if (oldPawn)
|
|
231
|
+
// {
|
|
232
|
+
// oldPawn.unpossess();
|
|
233
|
+
// oldPawn.destroy();
|
|
234
|
+
// }
|
|
235
|
+
// this.pawn.addOnChangeEvent(this.onCameraMove)
|
|
236
|
+
// this.pawn.possess();
|
|
237
|
+
// this.onCameraChanged.broadcast()
|
|
238
|
+
|
|
239
|
+
// this.world.markRenderStateDirty();
|
|
240
|
+
// }
|
|
241
|
+
|
|
242
|
+
// // transform position
|
|
243
|
+
// setPosition(param1, param2 = undefined, param3 = undefined)
|
|
244
|
+
// {
|
|
245
|
+
// if (this.pawn)
|
|
246
|
+
// {
|
|
247
|
+
// this.pawn.setPosition(param1, param2, param3)
|
|
248
|
+
// this.world.markRenderStateDirty();
|
|
249
|
+
// }
|
|
250
|
+
// }
|
|
251
|
+
|
|
252
|
+
// // transform quaternion
|
|
253
|
+
// setQuaternion(newQuat)
|
|
254
|
+
// {
|
|
255
|
+
// if (this.pawn)
|
|
256
|
+
// {
|
|
257
|
+
// this.pawn.setQuaternion(newQuat)
|
|
258
|
+
// this.world.markRenderStateDirty();
|
|
259
|
+
// }
|
|
260
|
+
// }
|
|
261
|
+
|
|
262
|
+
// // transform euler
|
|
263
|
+
// setRotation(newEuler)
|
|
264
|
+
// {
|
|
265
|
+
// if (this.pawn)
|
|
266
|
+
// {
|
|
267
|
+
// this.pawn.setQuaternion(new Quaternion().setFromEuler(newEuler))
|
|
268
|
+
// this.world.markRenderStateDirty();
|
|
269
|
+
// }
|
|
270
|
+
// }
|
|
271
|
+
|
|
272
|
+
// // focus
|
|
273
|
+
// focusTo(targetPos, targetQuat, distance, time, onGoing: Function | null = null, onFinished: Function | null = null)
|
|
274
|
+
// {
|
|
275
|
+
// this.pawn.focusTo(targetPos, targetQuat, distance, time, onGoing, onFinished)
|
|
276
|
+
// }
|
|
277
|
+
|
|
278
|
+
// movePawnTo(targetPos: Vector3)
|
|
279
|
+
// {
|
|
280
|
+
|
|
281
|
+
// }
|
|
282
|
+
|
|
283
|
+
// enableTransformControl(primaryTarget: ITransforming, multiTargets: ITransforming[], onUpdate: Function | null = null, onDragging: Function | null)
|
|
284
|
+
// {
|
|
285
|
+
// if (this.transformControl)
|
|
286
|
+
// {
|
|
287
|
+
// this.disableTransformControl()
|
|
288
|
+
// }
|
|
289
|
+
// this.transformControl = new LYTransformControl(this.world, this.Camera)
|
|
290
|
+
// this.transformControl.possess()
|
|
291
|
+
// this.transformControl.setSpace("local")
|
|
292
|
+
// this.transformControl.setTarget(primaryTarget, multiTargets, onUpdate, onDragging)
|
|
293
|
+
// this.transformControl.setAxis(primaryTarget.getAllowedTransformType().translate)
|
|
294
|
+
// this.world?.markRenderStateDirty()
|
|
295
|
+
// }
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
// disableTransformControl()
|
|
300
|
+
// {
|
|
301
|
+
// if (this.transformControl)
|
|
302
|
+
// {
|
|
303
|
+
// this.transformControl.destroy();
|
|
304
|
+
// }
|
|
305
|
+
// this.transformControl = null
|
|
306
|
+
// this.world?.markRenderStateDirty()
|
|
307
|
+
// }
|
|
308
|
+
|
|
309
|
+
// getTransformToolMode(): "translate" | "rotate" | "scale"
|
|
310
|
+
// {
|
|
311
|
+
// return this.transformControl.getMode()
|
|
312
|
+
// }
|
|
313
|
+
|
|
314
|
+
// setTransformToolMode(mode: "translate" | "rotate" | "scale"): void
|
|
315
|
+
// {
|
|
316
|
+
// this.transformControl.setMode(mode)
|
|
317
|
+
// }
|
|
318
|
+
|
|
319
|
+
// setTransformToolAxis(axis: "X" | "Y" | "Z" | "E" | "XY" | "YZ" | "XZ" | "XYZ" | "XYZE" | null): void
|
|
320
|
+
// {
|
|
321
|
+
// this.transformControl.setAxis(axis)
|
|
322
|
+
// }
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
// onWindowResize()
|
|
326
|
+
// {
|
|
327
|
+
// let ele = this.world.OuterElement;
|
|
328
|
+
// if (!ele)
|
|
329
|
+
// {
|
|
330
|
+
// return
|
|
331
|
+
// }
|
|
332
|
+
// this.Camera.aspect = ele.clientWidth / ele.clientHeight;
|
|
333
|
+
// this.Camera.updateProjectionMatrix();
|
|
334
|
+
// this.world.renderer.setSize(ele.clientWidth, ele.clientHeight);
|
|
335
|
+
// this.world.labelRenderer.setSize(ele.clientWidth, ele.clientHeight);
|
|
336
|
+
// if (this.world.Composer)
|
|
337
|
+
// {
|
|
338
|
+
// this.world.Composer.setSize(ele.clientWidth, ele.clientHeight)
|
|
339
|
+
// }
|
|
340
|
+
// this.world.markRenderStateDirty();
|
|
341
|
+
// }
|
|
342
|
+
|
|
343
|
+
// onPointerMove(event)
|
|
344
|
+
// {
|
|
345
|
+
// let ele = this.world.OuterElement;
|
|
346
|
+
// const canvasRect = this.world.Element.getBoundingClientRect();
|
|
347
|
+
// const offsetX = canvasRect.left;
|
|
348
|
+
// const offsetY = canvasRect.top;
|
|
349
|
+
|
|
350
|
+
// const pointer = new Vector2(((event.clientX - offsetX) / ele.clientWidth) * 2 - 1, 1 - ((event.clientY - offsetY) / ele.clientHeight) * 2)
|
|
351
|
+
|
|
352
|
+
// if (event.buttons !== 0)
|
|
353
|
+
// {
|
|
354
|
+
// this.pawn.stopFocusing()
|
|
355
|
+
// if (this.bLockCameraRotationByMouseMove && (!this.bCameraRotationLockedAlready))
|
|
356
|
+
// {
|
|
357
|
+
// const deltaX = Math.abs(pointer.x - this.startPointerDownPos.x)
|
|
358
|
+
// const deltaY = Math.abs(pointer.y - this.startPointerDownPos.y)
|
|
359
|
+
// if (Math.min(deltaY, deltaX) > 0.002)
|
|
360
|
+
// {
|
|
361
|
+
// this.bCameraRotationLockedAlready = true
|
|
362
|
+
// this.PawnMode.startLockCameraRotation(deltaX > deltaY ? new Vector2(1, 0) : new Vector2(0, 1))
|
|
363
|
+
// }
|
|
364
|
+
// }
|
|
365
|
+
// return
|
|
366
|
+
// }
|
|
367
|
+
// this.pointer = pointer
|
|
368
|
+
|
|
369
|
+
// let hover = this.getHitResultUnderCursor(this.hoverable, this._hoverDepth)
|
|
370
|
+
// let newHoverComp = []
|
|
371
|
+
// hover.forEach((elem) =>
|
|
372
|
+
// {
|
|
373
|
+
// if (elem.hitComp)
|
|
374
|
+
// {
|
|
375
|
+
// newHoverComp.push(elem.hitComp)
|
|
376
|
+
// }
|
|
377
|
+
// })
|
|
378
|
+
|
|
379
|
+
// this.hoveringComp.forEach((elem) =>
|
|
380
|
+
// {
|
|
381
|
+
// if (newHoverComp.indexOf(elem) < 0)
|
|
382
|
+
// {
|
|
383
|
+
// elem.onHorveringEnd();
|
|
384
|
+
// }
|
|
385
|
+
// })
|
|
386
|
+
|
|
387
|
+
// newHoverComp.forEach((elem) =>
|
|
388
|
+
// {
|
|
389
|
+
// if (this.hoveringComp.indexOf(elem) < 0)
|
|
390
|
+
// {
|
|
391
|
+
// elem.onHorveringBegin();
|
|
392
|
+
// }
|
|
393
|
+
// })
|
|
394
|
+
|
|
395
|
+
// this.hoveringComp = newHoverComp
|
|
396
|
+
|
|
397
|
+
// this.OnMouseMove.broadcast(event)
|
|
398
|
+
// }
|
|
399
|
+
|
|
400
|
+
// onPointerDown(event)
|
|
401
|
+
// {
|
|
402
|
+
// // left mouse button
|
|
403
|
+
// if (event.button === 0)
|
|
404
|
+
// {
|
|
405
|
+
// this.bLeftMouseButtonDown = true;
|
|
406
|
+
// if (this.bLockCameraRotationByMouseMove)
|
|
407
|
+
// {
|
|
408
|
+
// let ele = this.world.OuterElement;
|
|
409
|
+
// const canvasRect = this.world.Element.getBoundingClientRect();
|
|
410
|
+
// const offsetX = canvasRect.left;
|
|
411
|
+
// const offsetY = canvasRect.top;
|
|
412
|
+
// this.pointer.x = ((event.clientX - offsetX) / ele.clientWidth) * 2 - 1;
|
|
413
|
+
// this.pointer.y = 1 - ((event.clientY - offsetY) / ele.clientHeight) * 2;
|
|
414
|
+
// this.startPointerDownPos = this.pointer.clone()
|
|
415
|
+
// this.bCameraRotationLockedAlready = false
|
|
416
|
+
// }
|
|
417
|
+
// }
|
|
418
|
+
// }
|
|
419
|
+
|
|
420
|
+
// onPointerUp(event)
|
|
421
|
+
// {
|
|
422
|
+
// if (event.button === 0)
|
|
423
|
+
// {
|
|
424
|
+
// this.bLeftMouseButtonDown = false;
|
|
425
|
+
// if (this.leftMouseButtonDownTime < maxClickTime)
|
|
426
|
+
// {
|
|
427
|
+
// this.onClick(event)
|
|
428
|
+
// }
|
|
429
|
+
|
|
430
|
+
// this.leftMouseButtonDownTime = 0;
|
|
431
|
+
|
|
432
|
+
// this.PawnMode.stopLockCameraRotation()
|
|
433
|
+
|
|
434
|
+
// this.bCameraRotationLockedAlready = true
|
|
435
|
+
// }
|
|
436
|
+
// this.OnMouseUp.broadcast(event)
|
|
437
|
+
// }
|
|
438
|
+
|
|
439
|
+
// onMouseEnterCanvas()
|
|
440
|
+
// {
|
|
441
|
+
// let ele = this.world.Element
|
|
442
|
+
// ele.addEventListener('pointermove', this.onPointerMoveFunc);
|
|
443
|
+
// ele.addEventListener("pointerup", this.onPointerUpFunc);
|
|
444
|
+
// ele.addEventListener("pointerdown", this.onPointerDownFunc);
|
|
445
|
+
// this.onMouseEnterDelegate.broadcast()
|
|
446
|
+
// }
|
|
447
|
+
|
|
448
|
+
// onMouseLeaveCanvas()
|
|
449
|
+
// {
|
|
450
|
+
// let ele = this.world.Element
|
|
451
|
+
// ele.removeEventListener('pointermove', this.onPointerMoveFunc);
|
|
452
|
+
// ele.removeEventListener("pointerup", this.onPointerUpFunc);
|
|
453
|
+
// ele.removeEventListener("pointerdown", this.onPointerDownFunc);
|
|
454
|
+
// this.onMouseLeaveDelegate.broadcast()
|
|
455
|
+
|
|
456
|
+
// }
|
|
457
|
+
|
|
458
|
+
// projectWorldPositionToScreen(pos: Vector3)
|
|
459
|
+
// {
|
|
460
|
+
// let temp = new Vector3().copy(pos)
|
|
461
|
+
// temp.project(this.Camera)
|
|
462
|
+
// let ele = this.world.Element
|
|
463
|
+
// const width = ele.clientWidth;
|
|
464
|
+
// const height = ele.clientHeight;
|
|
465
|
+
|
|
466
|
+
// const screenX = (temp.x + 1) / 2 * width;
|
|
467
|
+
// const screenY = (1 - temp.y) / 2 * height;
|
|
468
|
+
// return new Vector2(screenX, screenY)
|
|
469
|
+
// }
|
|
470
|
+
|
|
471
|
+
// // excute when click nothing
|
|
472
|
+
// addClickNullEvent(func)
|
|
473
|
+
// {
|
|
474
|
+
// if (!func)
|
|
475
|
+
// {
|
|
476
|
+
// return
|
|
477
|
+
// }
|
|
478
|
+
// this.onClickNullEvent.push(func)
|
|
479
|
+
// }
|
|
480
|
+
|
|
481
|
+
// removeClickNullEvent(func)
|
|
482
|
+
// {
|
|
483
|
+
// let index = this.onClickNullEvent.indexOf(func)
|
|
484
|
+
// if (index >= 0)
|
|
485
|
+
// {
|
|
486
|
+
// this.onClickNullEvent.splice(index, 1)
|
|
487
|
+
// }
|
|
488
|
+
// }
|
|
489
|
+
|
|
490
|
+
// onClick(event)
|
|
491
|
+
// {
|
|
492
|
+
// let ele = this.world.Element;
|
|
493
|
+
|
|
494
|
+
// let bound = ele.getBoundingClientRect();
|
|
495
|
+
// this.pointer.x = ((event.clientX - bound.left) / ele.offsetWidth) * 2 - 1;// 标准设备横坐标
|
|
496
|
+
// this.pointer.y = -((event.clientY - bound.top) / ele.offsetHeight) * 2 + 1;// 标准设备纵坐标
|
|
497
|
+
|
|
498
|
+
// if (this.clickable.length > 0)
|
|
499
|
+
// {
|
|
500
|
+
// let res = this.getHitResultUnderCursor(this.clickable)
|
|
501
|
+
|
|
502
|
+
// if (res.length === 0)
|
|
503
|
+
// {
|
|
504
|
+
// this.onClickNullEvent.forEach((elem) =>
|
|
505
|
+
// {
|
|
506
|
+
// elem()
|
|
507
|
+
// })
|
|
508
|
+
// return
|
|
509
|
+
// }
|
|
510
|
+
// let hitComp = res[0].hitComp
|
|
511
|
+
// let hitInfo = res[0].hitInfo
|
|
512
|
+
|
|
513
|
+
// if (hitComp)
|
|
514
|
+
// {
|
|
515
|
+
// hitComp.onClicked();
|
|
516
|
+
// }
|
|
517
|
+
// else
|
|
518
|
+
// {
|
|
519
|
+
// this.onClickNullEvent.forEach((elem) =>
|
|
520
|
+
// {
|
|
521
|
+
// elem()
|
|
522
|
+
// })
|
|
523
|
+
// }
|
|
524
|
+
// }
|
|
525
|
+
// else
|
|
526
|
+
// {
|
|
527
|
+
// this.onClickNullEvent.forEach((elem) =>
|
|
528
|
+
// {
|
|
529
|
+
// elem()
|
|
530
|
+
// })
|
|
531
|
+
// }
|
|
532
|
+
// }
|
|
533
|
+
|
|
534
|
+
// addBlockable(object: Mesh)
|
|
535
|
+
// {
|
|
536
|
+
// let index = this.blockingMesh.indexOf(object)
|
|
537
|
+
// if (index >= 0)
|
|
538
|
+
// {
|
|
539
|
+
// return
|
|
540
|
+
// }
|
|
541
|
+
// this.blockingMesh.push(object)
|
|
542
|
+
// }
|
|
543
|
+
|
|
544
|
+
// removeBlockable(object: Mesh)
|
|
545
|
+
// {
|
|
546
|
+
// let index = this.blockingMesh.indexOf(object)
|
|
547
|
+
// if (index >= 0)
|
|
548
|
+
// {
|
|
549
|
+
// this.blockingMesh.splice(index, 1)
|
|
550
|
+
// }
|
|
551
|
+
// }
|
|
552
|
+
|
|
553
|
+
// // line trace
|
|
554
|
+
// registAsHoverable(LYObject: SceneComponent)
|
|
555
|
+
// {
|
|
556
|
+
// let index = this.hoverable.indexOf(LYObject)
|
|
557
|
+
// if (index >= 0)
|
|
558
|
+
// {
|
|
559
|
+
// return
|
|
560
|
+
// }
|
|
561
|
+
|
|
562
|
+
// this.hoverable.push(LYObject)
|
|
563
|
+
// }
|
|
564
|
+
|
|
565
|
+
// unregistAsHoverable(LYObject: SceneComponent)
|
|
566
|
+
// {
|
|
567
|
+
// let index = this.hoverable.indexOf(LYObject)
|
|
568
|
+
// if (index >= 0)
|
|
569
|
+
// {
|
|
570
|
+
// this.hoverable.splice(index, 1)
|
|
571
|
+
// }
|
|
572
|
+
// }
|
|
573
|
+
|
|
574
|
+
// registAsClickable(LYObject: SceneComponent)
|
|
575
|
+
// {
|
|
576
|
+
// if (!LYObject)
|
|
577
|
+
// {
|
|
578
|
+
// console.error("Controller::registAsClickable : clickable is null", LYObject)
|
|
579
|
+
// return
|
|
580
|
+
// }
|
|
581
|
+
|
|
582
|
+
// let index = this.clickable.indexOf(LYObject)
|
|
583
|
+
// if (index >= 0)
|
|
584
|
+
// {
|
|
585
|
+
// return
|
|
586
|
+
// }
|
|
587
|
+
// this.clickable.push(LYObject)
|
|
588
|
+
// }
|
|
589
|
+
|
|
590
|
+
// unregistAsClickable(LYObject: SceneComponent)
|
|
591
|
+
// {
|
|
592
|
+
// let index = this.clickable.indexOf(LYObject)
|
|
593
|
+
// if (index >= 0)
|
|
594
|
+
// {
|
|
595
|
+
// this.clickable.splice(index, 1)
|
|
596
|
+
// }
|
|
597
|
+
// }
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
// public getHitResultUnderCursor(objects: SceneComponent[] = [], depth: number = 1)
|
|
601
|
+
// {
|
|
602
|
+
// if (!this.ray)
|
|
603
|
+
// {
|
|
604
|
+
// this.ray = new LYRaycaster(this.world)
|
|
605
|
+
// }
|
|
606
|
+
// if (!this.Camera)
|
|
607
|
+
// {
|
|
608
|
+
// return []
|
|
609
|
+
// }
|
|
610
|
+
// this.ray.setFromCamera(this.pointer, this.Camera)
|
|
611
|
+
// let retVal = [];
|
|
612
|
+
// let realHit = new Set()
|
|
613
|
+
|
|
614
|
+
// if(objects.length === 0)
|
|
615
|
+
// {
|
|
616
|
+
// let arr = new Set(this.clickable.concat(this.hoverable))
|
|
617
|
+
// arr.forEach((elem)=>{
|
|
618
|
+
// realHit.add(elem.threeObject)
|
|
619
|
+
// })
|
|
620
|
+
// }
|
|
621
|
+
// else
|
|
622
|
+
// {
|
|
623
|
+
// objects.forEach((obj) =>
|
|
624
|
+
// {
|
|
625
|
+
// realHit.add(obj.threeObject)
|
|
626
|
+
// })
|
|
627
|
+
// }
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
// this.blockingMesh.forEach((obj) =>
|
|
631
|
+
// {
|
|
632
|
+
// realHit.add(obj)
|
|
633
|
+
// })
|
|
634
|
+
// let traced = this.ray.intersectObjects(Array.from(realHit), false)
|
|
635
|
+
// if (traced.length === 0)
|
|
636
|
+
// {
|
|
637
|
+
// return retVal
|
|
638
|
+
// }
|
|
639
|
+
|
|
640
|
+
// for (let i = 0; (i < traced.length) && (i < depth); ++i)
|
|
641
|
+
// {
|
|
642
|
+
// let myObj = traced[i].object.userData["LYObject"]
|
|
643
|
+
// if (this.blockingMesh.indexOf(traced[i].object) >= 0)
|
|
644
|
+
// {
|
|
645
|
+
// return retVal
|
|
646
|
+
// }
|
|
647
|
+
// if (myObj instanceof SceneComponent)
|
|
648
|
+
// {
|
|
649
|
+
// retVal.push({
|
|
650
|
+
// hitComp: myObj,
|
|
651
|
+
// hitInfo: traced[i]
|
|
652
|
+
// })
|
|
653
|
+
// }
|
|
654
|
+
// }
|
|
655
|
+
// return retVal
|
|
656
|
+
// }
|
|
657
|
+
|
|
658
|
+
// public getHitOnScreentPosition(clientX: number, clientY: number, traceObjects: Object3D[])
|
|
659
|
+
// {
|
|
660
|
+
// if (!this.ray)
|
|
661
|
+
// {
|
|
662
|
+
// this.ray = new LYRaycaster(this.world)
|
|
663
|
+
// }
|
|
664
|
+
// let ele = this.world.OuterElement;
|
|
665
|
+
// const canvasRect = this.world.Element.getBoundingClientRect();
|
|
666
|
+
// const offsetX = canvasRect.left;
|
|
667
|
+
// const offsetY = canvasRect.top;
|
|
668
|
+
// const pointer = new Vector2(((clientX - offsetX) / ele.clientWidth) * 2 - 1, 1 - ((clientY - offsetY) / ele.clientHeight) * 2)
|
|
669
|
+
// this.ray.setFromCamera(pointer, this.Camera)
|
|
670
|
+
// let traced = this.ray.intersectObjects(traceObjects, true)
|
|
671
|
+
// return traced
|
|
672
|
+
// }
|
|
673
|
+
|
|
674
|
+
// getTracedResultFromObjects(clientX: number, clientY: number, objects: Object3D[] = this.world?.scene?.children)
|
|
675
|
+
// {
|
|
676
|
+
// if (!this.ray)
|
|
677
|
+
// {
|
|
678
|
+
// this.ray = new LYRaycaster(this.world)
|
|
679
|
+
// }
|
|
680
|
+
// let ele = this.world.OuterElement;
|
|
681
|
+
// const canvasRect = this.world.Element.getBoundingClientRect();
|
|
682
|
+
// const offsetX = canvasRect.left;
|
|
683
|
+
// const offsetY = canvasRect.top;
|
|
684
|
+
// const pointer = new Vector2(((clientX - offsetX) / ele.clientWidth) * 2 - 1, 1 - ((clientY - offsetY) / ele.clientHeight) * 2)
|
|
685
|
+
// this.ray.setFromCamera(pointer, this.Camera)
|
|
686
|
+
// let traced = this.ray.intersectObjects(objects, true)
|
|
687
|
+
// return traced
|
|
688
|
+
// }
|
|
689
|
+
|
|
690
|
+
// lineTrace(origin: Vector3, direction: Vector3, ignoreObjects: Object3D[] | null = null)
|
|
691
|
+
// {
|
|
692
|
+
// if (!this.ray)
|
|
693
|
+
// {
|
|
694
|
+
// this.ray = new LYRaycaster(this.world)
|
|
695
|
+
// }
|
|
696
|
+
|
|
697
|
+
// this.ray.setOriginAndDirection(origin, direction)
|
|
698
|
+
|
|
699
|
+
// let traced = this.ray.intersectObjects(this.world.scene?.children, true)
|
|
700
|
+
// for (let i = 0; i < traced.length; ++i)
|
|
701
|
+
// {
|
|
702
|
+
// if (!ignoreObjects || ignoreObjects.length === 0)
|
|
703
|
+
// {
|
|
704
|
+
// return traced[i]
|
|
705
|
+
// }
|
|
706
|
+
// if (ignoreObjects.indexOf(traced[i].object) < 0)
|
|
707
|
+
// {
|
|
708
|
+
// return traced[i]
|
|
709
|
+
// }
|
|
710
|
+
// }
|
|
711
|
+
// return null
|
|
712
|
+
// }
|
|
713
|
+
|
|
714
|
+
// setViewOffset(offsetX: number, offsetY: number)
|
|
715
|
+
// {
|
|
716
|
+
// let ele = this.world.OuterElement;
|
|
717
|
+
// let w = ele.clientWidth
|
|
718
|
+
// let h = ele.clientHeight
|
|
719
|
+
// if (this.Camera instanceof PerspectiveCamera)
|
|
720
|
+
// {
|
|
721
|
+
// this.Camera.setViewOffset(w, h, w * offsetX, h * offsetY, w, h)
|
|
722
|
+
// }
|
|
723
|
+
// }
|
|
724
|
+
|
|
725
|
+
// setViewOffsetX(offsetX: number)
|
|
726
|
+
// {
|
|
727
|
+
// let ele = this.world.OuterElement;
|
|
728
|
+
// let w = ele.clientWidth
|
|
729
|
+
// let h = ele.clientHeight
|
|
730
|
+
// if (this.Camera instanceof PerspectiveCamera)
|
|
731
|
+
// {
|
|
732
|
+
// this.Camera.setViewOffset(w, h, w * offsetX, 0, w, h)
|
|
733
|
+
// }
|
|
734
|
+
// }
|
|
735
|
+
|
|
736
|
+
// destroy(): void
|
|
737
|
+
// {
|
|
738
|
+
// if (this.pawn)
|
|
739
|
+
// {
|
|
740
|
+
// this.pawn.unpossess();
|
|
741
|
+
// this.pawn.destroy();
|
|
742
|
+
// this.pawn = null;
|
|
743
|
+
// }
|
|
744
|
+
// this.resizeObserver.disconnect();
|
|
745
|
+
// let ele = this.world.Element
|
|
746
|
+
// ele.removeEventListener('mouseenter', this.onPointerEnterFunc);
|
|
747
|
+
// ele.removeEventListener("mouseleave", this.onPointerLeaveFunc);
|
|
748
|
+
|
|
749
|
+
// this.onMouseLeaveCanvas()
|
|
750
|
+
|
|
751
|
+
// this.hoverable = [];
|
|
752
|
+
// this.clickable = [];
|
|
753
|
+
// this.blockingMesh = []
|
|
754
|
+
// this.cameraStat = null;
|
|
755
|
+
// this.camera = null;
|
|
756
|
+
// this.transformControl = null;
|
|
757
|
+
// this.onClickNullEvent = [];
|
|
758
|
+
|
|
759
|
+
// this.onMouseEnterDelegate.clear()
|
|
760
|
+
// this.onMouseLeaveDelegate.clear()
|
|
761
|
+
// this.onMouseMoveDelegate.clear()
|
|
762
|
+
// this.onCameraChanged.clear()
|
|
763
|
+
// }
|
|
764
|
+
// }
|