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,276 @@
|
|
|
1
|
+
import {Euler, Quaternion, Vector3,Vector2, PerspectiveCamera} from "three";
|
|
2
|
+
import {gsap} from 'gsap';
|
|
3
|
+
|
|
4
|
+
import {CameraStatus, PawnBase} from "./PawnBase";
|
|
5
|
+
import {LYThreeWorld} from "../../Frame";
|
|
6
|
+
import {OrbitControls} from "three/examples/jsm/controls/OrbitControls";
|
|
7
|
+
import {PersepecticeCameraStatus} from "./CameraStatus.ts";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export class LYOrbital extends PawnBase
|
|
11
|
+
{
|
|
12
|
+
protected anim
|
|
13
|
+
private minAzimuthAngle: number;
|
|
14
|
+
private maxAzimuthAngle: number;
|
|
15
|
+
private minPolarAngle: number;
|
|
16
|
+
private maxPolarAngle: number;
|
|
17
|
+
override cameraStatus:PersepecticeCameraStatus
|
|
18
|
+
constructor(world: LYThreeWorld)
|
|
19
|
+
{
|
|
20
|
+
let ele = world.Element;
|
|
21
|
+
let camera = new PerspectiveCamera(60, ele.clientWidth / ele.clientHeight, 0.5, 7000)
|
|
22
|
+
super(world, camera, new OrbitControls(camera, world.renderer.domElement));
|
|
23
|
+
|
|
24
|
+
this.Camera.updateProjectionMatrix();
|
|
25
|
+
// this.enabled = false;
|
|
26
|
+
//this.Control.maxDistance = 300;
|
|
27
|
+
this.Control.maxPolarAngle = 0.49 * Math.PI;
|
|
28
|
+
this.minAzimuthAngle = this.Control.minAzimuthAngle
|
|
29
|
+
this.maxAzimuthAngle = this.Control.maxAzimuthAngle
|
|
30
|
+
this.minPolarAngle = this.Control.minPolarAngle
|
|
31
|
+
this.maxPolarAngle = this.Control.maxPolarAngle
|
|
32
|
+
this.IsTickable = true
|
|
33
|
+
|
|
34
|
+
this.cameraStatus = new PersepecticeCameraStatus(this.Camera, this.Camera.position)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
tick(deltaTime:number)
|
|
38
|
+
{
|
|
39
|
+
super.tick(deltaTime);
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set enabled(newEnable: boolean)
|
|
44
|
+
{
|
|
45
|
+
this.Control.panSpeed = newEnable ? 1 : 0;
|
|
46
|
+
this.Control.rotateSpeed = newEnable ? 1 : 0;
|
|
47
|
+
this.Control.zoomSpeed = newEnable ? 1 : 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
possess()
|
|
51
|
+
{
|
|
52
|
+
super.possess()
|
|
53
|
+
this.Control.addEventListener('change', this.changeEvent)
|
|
54
|
+
this.World.markRenderStateDirty();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
unpossess()
|
|
58
|
+
{
|
|
59
|
+
super.unpossess()
|
|
60
|
+
this.Control.removeEventListener("change", this.changeEvent)
|
|
61
|
+
this.onCameraMove = null
|
|
62
|
+
if (this.anim)
|
|
63
|
+
{
|
|
64
|
+
this.anim.kill();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get Camera()
|
|
69
|
+
{
|
|
70
|
+
return this.Control.object
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setCamera(newCamera)
|
|
74
|
+
{
|
|
75
|
+
super.setCamera(newCamera)
|
|
76
|
+
this.Control.object = newCamera
|
|
77
|
+
this.Control.update();
|
|
78
|
+
this.World.markRenderStateDirty();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
setPosition(param1, param2 = undefined, param3 = undefined)
|
|
82
|
+
{
|
|
83
|
+
super.setPosition(param1, param2, param3);
|
|
84
|
+
this.Control.update();
|
|
85
|
+
this.World.markRenderStateDirty();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
setQuaternion(newQuat)
|
|
89
|
+
{
|
|
90
|
+
super.setQuaternion(newQuat);
|
|
91
|
+
this.Control.update()
|
|
92
|
+
this.World.markRenderStateDirty();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// focusTo
|
|
96
|
+
// @targetPos Three.Vector3 : where your camera face to
|
|
97
|
+
// @targetQuat Three.Quaternion or Three.Euler : rotation of your camera
|
|
98
|
+
// @distance float : how far between targetPos and your camera's position
|
|
99
|
+
// @time float : how long will this process finish
|
|
100
|
+
focusTo(targetPos: Vector3, targetQuat: Quaternion | Euler, distance: number, time: number = 0, onGoing: Function | null = null, onFinished: Function | null = null)
|
|
101
|
+
{
|
|
102
|
+
let finalQuat = null
|
|
103
|
+
|
|
104
|
+
if (targetQuat instanceof Euler)
|
|
105
|
+
{
|
|
106
|
+
finalQuat = new Quaternion().setFromEuler(targetQuat)
|
|
107
|
+
}
|
|
108
|
+
else
|
|
109
|
+
{
|
|
110
|
+
finalQuat = targetQuat
|
|
111
|
+
}
|
|
112
|
+
if (!targetQuat)
|
|
113
|
+
{
|
|
114
|
+
finalQuat = this.Camera.quaternion
|
|
115
|
+
}
|
|
116
|
+
finalQuat.normalize()
|
|
117
|
+
let dir = new Vector3(0, 0, 1);
|
|
118
|
+
dir.applyQuaternion(finalQuat).multiplyScalar(-1);
|
|
119
|
+
dir.normalize()
|
|
120
|
+
// quat
|
|
121
|
+
let startQuat = this.Camera.quaternion.clone();
|
|
122
|
+
// position
|
|
123
|
+
let startPos = this.Camera.position.clone();
|
|
124
|
+
let endPos = new Vector3(targetPos.x + dir.x * distance * -1, targetPos.y + dir.y * distance * -1, targetPos.z + dir.z * distance * -1);
|
|
125
|
+
|
|
126
|
+
let posDir = new Vector3();
|
|
127
|
+
posDir.x = endPos.x - startPos.x;
|
|
128
|
+
posDir.y = endPos.y - startPos.y;
|
|
129
|
+
posDir.z = endPos.z - startPos.z;
|
|
130
|
+
let movingLength = posDir.length();
|
|
131
|
+
posDir.normalize();
|
|
132
|
+
|
|
133
|
+
// target
|
|
134
|
+
let startTarget = this.Control.target.clone()
|
|
135
|
+
let targetDir = new Vector3();
|
|
136
|
+
targetDir.x = targetPos.x - startTarget.x;
|
|
137
|
+
targetDir.y = targetPos.y - startTarget.y;
|
|
138
|
+
targetDir.z = targetPos.z - startTarget.z;
|
|
139
|
+
let targetDistance = targetDir.length();
|
|
140
|
+
targetDir.normalize();
|
|
141
|
+
|
|
142
|
+
this.cameraStatus.updateTargetPosition(targetPos)
|
|
143
|
+
|
|
144
|
+
// start animation
|
|
145
|
+
if (this.anim)
|
|
146
|
+
{
|
|
147
|
+
this.anim.kill();
|
|
148
|
+
}
|
|
149
|
+
if (movingLength + targetDistance < 0.1)
|
|
150
|
+
{
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
//this.enabled = false;
|
|
154
|
+
let obj = {alpha: 0}
|
|
155
|
+
let _this = this
|
|
156
|
+
this.anim = gsap.to(obj, {
|
|
157
|
+
duration : time,
|
|
158
|
+
alpha : 1,
|
|
159
|
+
onUpdate : () =>
|
|
160
|
+
{
|
|
161
|
+
let alpha = obj.alpha;
|
|
162
|
+
let camPos = new Vector3(startPos.x + posDir.x * alpha * movingLength, startPos.y + posDir.y * alpha * movingLength, startPos.z + posDir.z * alpha * movingLength)
|
|
163
|
+
let targetPos = new Vector3(startTarget.x + targetDir.x * alpha * targetDistance, startTarget.y + targetDir.y * alpha * targetDistance, startTarget.z + targetDir.z * alpha * targetDistance)
|
|
164
|
+
_this.Control.object.position.copy(camPos);
|
|
165
|
+
_this.Control.target.copy(targetPos);
|
|
166
|
+
|
|
167
|
+
_this.Control.update();
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
if (onGoing)
|
|
171
|
+
{
|
|
172
|
+
onGoing()
|
|
173
|
+
}
|
|
174
|
+
_this.World.markRenderStateDirty();
|
|
175
|
+
},
|
|
176
|
+
onComplete: function ()
|
|
177
|
+
{
|
|
178
|
+
//_this.enabled = true;
|
|
179
|
+
|
|
180
|
+
if (onFinished)
|
|
181
|
+
{
|
|
182
|
+
onFinished()
|
|
183
|
+
}
|
|
184
|
+
_this.World.markRenderStateDirty();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
stopFocusing()
|
|
190
|
+
{
|
|
191
|
+
if (this.anim)
|
|
192
|
+
{
|
|
193
|
+
this.anim.kill();
|
|
194
|
+
this.anim = null
|
|
195
|
+
}
|
|
196
|
+
//this.enabled = true
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
startLockCameraRotation(axis: Vector2)
|
|
200
|
+
{
|
|
201
|
+
this.minAzimuthAngle = this.Control.minAzimuthAngle
|
|
202
|
+
this.maxAzimuthAngle = this.Control.maxAzimuthAngle
|
|
203
|
+
this.minPolarAngle = this.Control.minPolarAngle
|
|
204
|
+
this.maxPolarAngle = this.Control.maxPolarAngle
|
|
205
|
+
|
|
206
|
+
if (axis.x === 1)
|
|
207
|
+
{
|
|
208
|
+
const curAngle = this.Control.getPolarAngle()
|
|
209
|
+
this.Control.minPolarAngle = curAngle
|
|
210
|
+
this.Control.maxPolarAngle = curAngle
|
|
211
|
+
}
|
|
212
|
+
else
|
|
213
|
+
{
|
|
214
|
+
const curAngle = this.Control.getAzimuthalAngle()
|
|
215
|
+
this.Control.minAzimuthAngle = curAngle
|
|
216
|
+
this.Control.maxAzimuthAngle = curAngle
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
stopLockCameraRotation()
|
|
221
|
+
{
|
|
222
|
+
this.Control.minAzimuthAngle = this.minAzimuthAngle
|
|
223
|
+
this.Control.maxAzimuthAngle = this.maxAzimuthAngle
|
|
224
|
+
this.Control.minPolarAngle = this.minPolarAngle
|
|
225
|
+
this.Control.maxPolarAngle = this.maxPolarAngle
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
zoomIn()
|
|
229
|
+
{
|
|
230
|
+
this.focusTo(this.cameraStatus.targetPosition, this.cameraStatus.cameraQuaternion, this.cameraStatus.targetPosition.clone().sub(this.cameraStatus.cameraPosition).length() * 0.9)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
zoomOut()
|
|
234
|
+
{
|
|
235
|
+
this.focusTo(this.cameraStatus.targetPosition, this.cameraStatus.cameraQuaternion, this.cameraStatus.targetPosition.clone().sub(this.cameraStatus.cameraPosition).length() * 1.1)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
restore(status: PersepecticeCameraStatus)
|
|
239
|
+
{
|
|
240
|
+
super.restore(status);
|
|
241
|
+
this.cameraStatus.copy(status)
|
|
242
|
+
|
|
243
|
+
this.focusTo(status.targetPosition, status.cameraQuaternion, status.targetPosition.clone().sub(status.cameraPosition).length())
|
|
244
|
+
this.Camera.near = status.near
|
|
245
|
+
this.Camera.far = status.far
|
|
246
|
+
this.Camera.fov = status.fov
|
|
247
|
+
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
protected onChangeEvent()
|
|
251
|
+
{
|
|
252
|
+
super.onChangeEvent();
|
|
253
|
+
|
|
254
|
+
this.World.markRenderStateDirty()
|
|
255
|
+
this.onChangeOnce = []
|
|
256
|
+
|
|
257
|
+
this.cameraStatus.update(this.Camera, this.Control.target)
|
|
258
|
+
let camPos = this.Control.object.position.clone()
|
|
259
|
+
let targetPos = this.Control.target.clone()
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
destroy()
|
|
263
|
+
{
|
|
264
|
+
if (this.anim)
|
|
265
|
+
{
|
|
266
|
+
this.anim.kill();
|
|
267
|
+
this.anim = null
|
|
268
|
+
}
|
|
269
|
+
if (this.Control)
|
|
270
|
+
{
|
|
271
|
+
this.Control.removeEventListener("change", this.changeEvent)
|
|
272
|
+
this.Control.dispose();
|
|
273
|
+
}
|
|
274
|
+
super.destroy();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {BaseObject} from "../BaseObject.js";
|
|
2
|
+
import {Quaternion, Vector3, Camera, Euler, Vector2} from "three";
|
|
3
|
+
import {LYThreeWorld} from "../../Frame";
|
|
4
|
+
import {ICameraStatus, CameraStatus} from "./CameraStatus";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// Base class for control method, should not be used directly
|
|
8
|
+
export class PawnBase extends BaseObject implements ICameraStatus
|
|
9
|
+
{
|
|
10
|
+
protected control
|
|
11
|
+
protected world: LYThreeWorld
|
|
12
|
+
protected camera: Camera
|
|
13
|
+
protected cameraStatus:CameraStatus
|
|
14
|
+
protected onCameraMove:Function|null = null
|
|
15
|
+
|
|
16
|
+
protected onChangeOnce:Function[] = []
|
|
17
|
+
protected onChange:Function[] = []
|
|
18
|
+
|
|
19
|
+
protected changeEvent:Function
|
|
20
|
+
|
|
21
|
+
constructor(world: LYThreeWorld, camera: Camera, control)
|
|
22
|
+
{
|
|
23
|
+
super();
|
|
24
|
+
this.control = control;
|
|
25
|
+
this.world = world
|
|
26
|
+
this.camera = camera
|
|
27
|
+
// this.cameraStatus = new CameraStatus(this.Camera.position, this.Camera.quaternion, this.Camera.position, 1)
|
|
28
|
+
|
|
29
|
+
this.onChange = []
|
|
30
|
+
this.onChangeOnce = []
|
|
31
|
+
this.changeEvent = ()=>{
|
|
32
|
+
this.onChangeEvent()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get CameraStatus():CameraStatus
|
|
37
|
+
{
|
|
38
|
+
return this.cameraStatus
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
tick(deltaTime)
|
|
42
|
+
{
|
|
43
|
+
super.tick(deltaTime)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
possess()
|
|
47
|
+
{
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
unpossess()
|
|
52
|
+
{
|
|
53
|
+
this.onChange = []
|
|
54
|
+
this.onChangeOnce = []
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
set enabled(newEnable:boolean)
|
|
58
|
+
{
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
startLockCameraRotation(axis: Vector2)
|
|
63
|
+
{
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
restore(status: CameraStatus) {}
|
|
67
|
+
|
|
68
|
+
stopLockCameraRotation()
|
|
69
|
+
{
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setPosition(param1, param2 = undefined, param3 = undefined)
|
|
74
|
+
{
|
|
75
|
+
if (param1 instanceof Vector3)
|
|
76
|
+
{
|
|
77
|
+
this.Camera.position.set(param1.x, param1.y, param1.z);
|
|
78
|
+
}
|
|
79
|
+
if (typeof (param1) === "number" && typeof (param2) === "number" && typeof (param3) === "number")
|
|
80
|
+
{
|
|
81
|
+
this.Camera.position.set(param1, param2, param3);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this.world)
|
|
85
|
+
{
|
|
86
|
+
this.world.markRenderStateDirty();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
setQuaternion(newQuat)
|
|
91
|
+
{
|
|
92
|
+
if (newQuat instanceof Quaternion)
|
|
93
|
+
{
|
|
94
|
+
this.Camera.rotation.setFromQuaternion(newQuat);
|
|
95
|
+
if (this.world)
|
|
96
|
+
{
|
|
97
|
+
this.world.markRenderStateDirty();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get Camera()
|
|
103
|
+
{
|
|
104
|
+
return this.camera
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setCamera(newCamera)
|
|
108
|
+
{
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get Control()
|
|
113
|
+
{
|
|
114
|
+
return this.control
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
get World()
|
|
118
|
+
{
|
|
119
|
+
return this.world;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
focusTo(targetPos: Vector3, targetQuat: Quaternion | Euler, distance: number, time: number, onGoing: Function | null = null, onFinished: Function | null = null)
|
|
123
|
+
{
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
moveTo(targetPos: Vector3)
|
|
128
|
+
{
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
stopFocusing()
|
|
133
|
+
{
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
destroy()
|
|
137
|
+
{
|
|
138
|
+
this.unpossess()
|
|
139
|
+
if (this.control)
|
|
140
|
+
{
|
|
141
|
+
this.control = null;
|
|
142
|
+
}
|
|
143
|
+
super.destroy();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
zoomIn()
|
|
147
|
+
{
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
zoomOut()
|
|
152
|
+
{
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected onChangeEvent()
|
|
157
|
+
{
|
|
158
|
+
for (let i = 0; i < this.onChange.length; ++i)
|
|
159
|
+
{
|
|
160
|
+
this.onChange[i]();
|
|
161
|
+
}
|
|
162
|
+
for (let i = 0; i < this.onChangeOnce.length; ++i)
|
|
163
|
+
{
|
|
164
|
+
this.onChangeOnce[i]();
|
|
165
|
+
}
|
|
166
|
+
this.onChangeOnce = []
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
addOnChangeEvent(event, bOnce = false)
|
|
170
|
+
{
|
|
171
|
+
if (bOnce)
|
|
172
|
+
{
|
|
173
|
+
this.onChangeOnce.push(event)
|
|
174
|
+
}
|
|
175
|
+
else
|
|
176
|
+
{
|
|
177
|
+
this.onChange.push(event)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
removeOnChangeEvent(event)
|
|
182
|
+
{
|
|
183
|
+
let index = this.onChange.indexOf(event)
|
|
184
|
+
if (index >= 0)
|
|
185
|
+
{
|
|
186
|
+
this.onChange.splice(index, 1);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {Euler, Quaternion, Vector3,OrthographicCamera} from "three";
|
|
2
|
+
|
|
3
|
+
import {PawnBase} from "./PawnBase";
|
|
4
|
+
import {LYThreeWorld} from "../../Frame";
|
|
5
|
+
import {OrbitControls} from "three/examples/jsm/controls/OrbitControls";
|
|
6
|
+
import {OrthographicCameraStatus} from "./CameraStatus.ts";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class LYTopView extends PawnBase
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
override camera :OrthographicCamera
|
|
13
|
+
override control:OrbitControls
|
|
14
|
+
override cameraStatus:OrthographicCameraStatus
|
|
15
|
+
override get Control(): any
|
|
16
|
+
{
|
|
17
|
+
return this.control;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor(world: LYThreeWorld)
|
|
21
|
+
{
|
|
22
|
+
let camera = new OrthographicCamera()
|
|
23
|
+
camera.near = 0.1
|
|
24
|
+
camera.far = 2000
|
|
25
|
+
|
|
26
|
+
let control = null
|
|
27
|
+
if(world.renderer && world.renderer.domElement)
|
|
28
|
+
{
|
|
29
|
+
control = new OrbitControls(camera, world.renderer.domElement)
|
|
30
|
+
control.enableRotate = false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
super(world, camera, control);
|
|
34
|
+
this.camera = camera
|
|
35
|
+
this.control = control
|
|
36
|
+
this.control.enableRotate = false
|
|
37
|
+
this.cameraStatus = new OrthographicCameraStatus(this.Camera, this.Camera.position.clone().add(new Vector3(0,-1000,0)))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
override get Camera(): OrthographicCamera
|
|
43
|
+
{
|
|
44
|
+
return this.camera
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
tick(deltaTime)
|
|
48
|
+
{
|
|
49
|
+
super.tick(deltaTime);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
possess()
|
|
54
|
+
{
|
|
55
|
+
|
|
56
|
+
this.Control.addEventListener('change', this.changeEvent)
|
|
57
|
+
this.World.markRenderStateDirty();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
unpossess()
|
|
61
|
+
{
|
|
62
|
+
this.onCameraMove = null
|
|
63
|
+
this.Control.removeEventListener("change", this.changeEvent)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
setCamera(newCamera)
|
|
68
|
+
{
|
|
69
|
+
super.setCamera(newCamera)
|
|
70
|
+
// this.Control.object = newCamera
|
|
71
|
+
// this.Control.update();
|
|
72
|
+
this.World.markRenderStateDirty();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
setPosition(param1, param2 = undefined, param3 = undefined)
|
|
76
|
+
{
|
|
77
|
+
// super.setPosition(param1, param2, param3);
|
|
78
|
+
// this.Control.update();
|
|
79
|
+
// this.World.markRenderStateDirty();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setQuaternion(newQuat)
|
|
83
|
+
{
|
|
84
|
+
// super.setQuaternion(newQuat);
|
|
85
|
+
// this.Control.update()
|
|
86
|
+
// this.World.markRenderStateDirty();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// focusTo
|
|
90
|
+
// @targetPos
|
|
91
|
+
focusTo(targetPos: Vector3, targetQuat: Quaternion | Euler, distance: number, time: number = 0, onGoing: Function | null = null, onFinished: Function | null = null)
|
|
92
|
+
{
|
|
93
|
+
// this.Camera.position.set(targetPos.x,targetPos.y + 1000, targetPos.z);
|
|
94
|
+
let quat1 = new Quaternion().setFromAxisAngle(new Vector3(1, 0, 0), Math.PI * 0.5).normalize();
|
|
95
|
+
|
|
96
|
+
this.Camera.quaternion.copy(quat1)
|
|
97
|
+
this.Control.object.position.set(targetPos.x, targetPos.y + distance, targetPos.z);
|
|
98
|
+
this.Control.target.copy(targetPos);
|
|
99
|
+
|
|
100
|
+
//1.计算透视相机到场景 scene 的深度距离 depth
|
|
101
|
+
let depth = distance;
|
|
102
|
+
let ele = this.world.OuterElement;
|
|
103
|
+
//2.得到透视相机的宽高比和垂直可视角度
|
|
104
|
+
let aspect = ele.clientWidth/ele.clientHeight;
|
|
105
|
+
let fov = 60;
|
|
106
|
+
let top_ortho = depth * Math.atan((Math.PI / 180) * (fov) / 2);
|
|
107
|
+
let right_ortho = top_ortho * aspect;
|
|
108
|
+
let bottom_ortho = -top_ortho;
|
|
109
|
+
let left_ortho = -right_ortho;
|
|
110
|
+
this.Camera.right = right_ortho
|
|
111
|
+
this.Camera.left = left_ortho
|
|
112
|
+
this.Camera.top = top_ortho
|
|
113
|
+
this.Camera.bottom = bottom_ortho
|
|
114
|
+
this.Camera.updateProjectionMatrix()
|
|
115
|
+
this.control.update()
|
|
116
|
+
if (onFinished)
|
|
117
|
+
{
|
|
118
|
+
onFinished();
|
|
119
|
+
}
|
|
120
|
+
this.World.markRenderStateDirty();
|
|
121
|
+
this.cameraStatus.updateTargetPosition(targetPos)
|
|
122
|
+
this.cameraStatus.updateCameraPosition(this.Camera.position)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
stopFocusing()
|
|
126
|
+
{
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
zoomIn()
|
|
131
|
+
{
|
|
132
|
+
this.Camera.zoom *= 1.1
|
|
133
|
+
this.cameraStatus.updateCameraZoom(this.Camera.zoom)
|
|
134
|
+
this.Camera.updateProjectionMatrix()
|
|
135
|
+
this.World.markRenderStateDirty();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
zoomOut()
|
|
139
|
+
{
|
|
140
|
+
this.Camera.zoom *= 0.9
|
|
141
|
+
this.cameraStatus.updateCameraZoom(this.Camera.zoom)
|
|
142
|
+
this.Camera.updateProjectionMatrix()
|
|
143
|
+
this.World.markRenderStateDirty();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
restore(status: OrthographicCameraStatus)
|
|
147
|
+
{
|
|
148
|
+
super.restore(status);
|
|
149
|
+
this.cameraStatus.copy(status)
|
|
150
|
+
|
|
151
|
+
this.Control.object.position.copy(status.cameraPosition.clone());
|
|
152
|
+
this.Control.target.copy(status.targetPosition);
|
|
153
|
+
|
|
154
|
+
let quat1 = new Quaternion().setFromAxisAngle(new Vector3(1, 0, 0), Math.PI * 0.5).normalize();
|
|
155
|
+
this.Camera.quaternion.copy(quat1)
|
|
156
|
+
|
|
157
|
+
//1.计算透视相机到场景 scene 的深度距离 depth
|
|
158
|
+
let depth = this.Camera.position.clone().sub(status.targetPosition).length();
|
|
159
|
+
let ele = this.world.OuterElement;
|
|
160
|
+
|
|
161
|
+
//2.得到透视相机的宽高比和垂直可视角度
|
|
162
|
+
let aspect = ele.clientWidth/ele.clientHeight;
|
|
163
|
+
let fov = 60;
|
|
164
|
+
|
|
165
|
+
//3.根据上述变量计算正交投影相机的视口矩形
|
|
166
|
+
let top_ortho = depth * Math.atan((Math.PI / 180) * (fov) / 2);
|
|
167
|
+
let right_ortho = top_ortho * aspect;
|
|
168
|
+
let bottom_ortho = -top_ortho;
|
|
169
|
+
let left_ortho = -right_ortho;
|
|
170
|
+
|
|
171
|
+
this.Camera.right = right_ortho
|
|
172
|
+
this.Camera.left = left_ortho
|
|
173
|
+
this.Camera.top = top_ortho
|
|
174
|
+
this.Camera.bottom = bottom_ortho
|
|
175
|
+
this.Camera.zoom = status.zoom
|
|
176
|
+
|
|
177
|
+
this.Camera.updateProjectionMatrix()
|
|
178
|
+
this.Control.update()
|
|
179
|
+
|
|
180
|
+
this.World.markRenderStateDirty();
|
|
181
|
+
|
|
182
|
+
this.cameraStatus.updateCameraZoom(this.Camera.zoom)
|
|
183
|
+
this.cameraStatus.updateTargetPosition(status.targetPosition)
|
|
184
|
+
this.cameraStatus.updateCameraPosition(this.Camera.position)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
destroy()
|
|
188
|
+
{
|
|
189
|
+
if (this.Control)
|
|
190
|
+
{
|
|
191
|
+
this.Control.dispose();
|
|
192
|
+
}
|
|
193
|
+
super.destroy();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
protected onChangeEvent()
|
|
197
|
+
{
|
|
198
|
+
super.onChangeEvent();
|
|
199
|
+
// this.cameraStatus.updateCameraQuaternion(this.Camera.quaternion)
|
|
200
|
+
this.cameraStatus.update(this.Camera, this.Camera.position.clone().add(new Vector3(0,-1000,0)))
|
|
201
|
+
this.World.markRenderStateDirty()
|
|
202
|
+
let camPos = this.Control.object.position.clone()
|
|
203
|
+
let targetPos = this.Control.target.clone()
|
|
204
|
+
}
|
|
205
|
+
}
|