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,262 @@
|
|
|
1
|
+
// import {Euler, OrthographicCamera, PerspectiveCamera, Quaternion, Vector3} from "three";
|
|
2
|
+
// import {LYMath} from "../../Math/Math.ts";
|
|
3
|
+
|
|
4
|
+
// export class CameraStatus
|
|
5
|
+
// {
|
|
6
|
+
|
|
7
|
+
// get cameraQuaternion(): Quaternion
|
|
8
|
+
// {
|
|
9
|
+
// return this._cameraQuaternion;
|
|
10
|
+
// }
|
|
11
|
+
// get targetPosition(): Vector3
|
|
12
|
+
// {
|
|
13
|
+
// return this._targetPosition;
|
|
14
|
+
// }
|
|
15
|
+
// get cameraPosition(): Vector3
|
|
16
|
+
// {
|
|
17
|
+
// return this._cameraPosition;
|
|
18
|
+
// }
|
|
19
|
+
// private _cameraPosition:Vector3
|
|
20
|
+
// private _targetPosition:Vector3
|
|
21
|
+
// private _cameraQuaternion:Quaternion
|
|
22
|
+
|
|
23
|
+
// type:string = ""
|
|
24
|
+
// constructor(camera:PerspectiveCamera|OrthographicCamera, targetPosition:Vector3)
|
|
25
|
+
// {
|
|
26
|
+
// this._cameraPosition = new Vector3()
|
|
27
|
+
// this._cameraQuaternion = new Quaternion()
|
|
28
|
+
// this._targetPosition = new Vector3()
|
|
29
|
+
// this.update(camera,targetPosition)
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
// update(camera:PerspectiveCamera|OrthographicCamera, targetPosition:Vector3)
|
|
33
|
+
// {
|
|
34
|
+
// this.updateCameraPosition(camera.position)
|
|
35
|
+
// this.updateCameraQuaternion(camera.quaternion)
|
|
36
|
+
// this.updateTargetPosition(targetPosition)
|
|
37
|
+
|
|
38
|
+
// }
|
|
39
|
+
|
|
40
|
+
// updateCameraPosition(cameraPosition:Vector3)
|
|
41
|
+
// {
|
|
42
|
+
// this._cameraPosition.copy(cameraPosition)
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
// updateCameraQuaternion(cameraQuaternion:Quaternion)
|
|
46
|
+
// {
|
|
47
|
+
// this._cameraQuaternion.copy(cameraQuaternion)
|
|
48
|
+
// }
|
|
49
|
+
|
|
50
|
+
// updateTargetPosition(targetPosition:Vector3)
|
|
51
|
+
// {
|
|
52
|
+
// this._targetPosition.copy(targetPosition)
|
|
53
|
+
// }
|
|
54
|
+
|
|
55
|
+
// copy(other:CameraStatus)
|
|
56
|
+
// {
|
|
57
|
+
// this.updateCameraPosition(other.cameraPosition)
|
|
58
|
+
// this.updateCameraQuaternion(other.cameraQuaternion)
|
|
59
|
+
// this.updateTargetPosition(other.targetPosition)
|
|
60
|
+
// }
|
|
61
|
+
|
|
62
|
+
// toObject():object
|
|
63
|
+
// {
|
|
64
|
+
// let euler = new Euler().setFromQuaternion(this._cameraQuaternion)
|
|
65
|
+
|
|
66
|
+
// return {
|
|
67
|
+
// position: this._cameraPosition.toArray(),
|
|
68
|
+
// euler : LYMath.threeJsEulerAngleAsDegree(euler),
|
|
69
|
+
// type : this.type
|
|
70
|
+
// }
|
|
71
|
+
// }
|
|
72
|
+
|
|
73
|
+
// fromObject(object)
|
|
74
|
+
// {
|
|
75
|
+
// this.updateCameraPosition(new Vector3().fromArray(object.position))
|
|
76
|
+
// let euler = new Euler(LYMath.degreeToRadians(object.euler.x),LYMath.degreeToRadians(object.euler.y),LYMath.degreeToRadians(object.euler.z))
|
|
77
|
+
// this.updateCameraQuaternion(new Quaternion().setFromEuler(euler))
|
|
78
|
+
// }
|
|
79
|
+
// }
|
|
80
|
+
|
|
81
|
+
// export interface ICameraStatus
|
|
82
|
+
// {
|
|
83
|
+
// restore(status:CameraStatus):void
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
// export class PersepecticeCameraStatus extends CameraStatus
|
|
87
|
+
// {
|
|
88
|
+
// get fov(): number
|
|
89
|
+
// {
|
|
90
|
+
// return this._fov;
|
|
91
|
+
// }
|
|
92
|
+
// get far(): number
|
|
93
|
+
// {
|
|
94
|
+
// return this._far;
|
|
95
|
+
// }
|
|
96
|
+
// get near(): number
|
|
97
|
+
// {
|
|
98
|
+
// return this._near;
|
|
99
|
+
// }
|
|
100
|
+
|
|
101
|
+
// private _near: number = 1
|
|
102
|
+
// private _far: number = 1
|
|
103
|
+
// private _fov: number = 60
|
|
104
|
+
// constructor(camera:PerspectiveCamera, targetPosition:Vector3)
|
|
105
|
+
// {
|
|
106
|
+
// super(camera,targetPosition)
|
|
107
|
+
// this.type = "perspective"
|
|
108
|
+
// }
|
|
109
|
+
|
|
110
|
+
// update(camera:PerspectiveCamera, targetPosition:Vector3)
|
|
111
|
+
// {
|
|
112
|
+
// this.updateCameraPosition(camera.position)
|
|
113
|
+
// this.updateCameraQuaternion(camera.quaternion)
|
|
114
|
+
// this.updateTargetPosition(targetPosition)
|
|
115
|
+
|
|
116
|
+
// this.updateFar(camera.far)
|
|
117
|
+
// this.updateNear(camera.near)
|
|
118
|
+
// this.updateFOV(camera.fov)
|
|
119
|
+
// }
|
|
120
|
+
|
|
121
|
+
// updateNear(near:number)
|
|
122
|
+
// {
|
|
123
|
+
// this._near = near
|
|
124
|
+
// }
|
|
125
|
+
// updateFar(far:number)
|
|
126
|
+
// {
|
|
127
|
+
// this._far = far
|
|
128
|
+
// }
|
|
129
|
+
// updateFOV(fov:number)
|
|
130
|
+
// {
|
|
131
|
+
// this._fov = fov
|
|
132
|
+
// }
|
|
133
|
+
|
|
134
|
+
// copy(other:PersepecticeCameraStatus)
|
|
135
|
+
// {
|
|
136
|
+
// this.updateFOV(other.fov)
|
|
137
|
+
// this.updateNear(other.near)
|
|
138
|
+
// this.updateFar(other.far)
|
|
139
|
+
// super.copy(other)
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// toObject():object
|
|
143
|
+
// {
|
|
144
|
+
// let obj = super.toObject()
|
|
145
|
+
// obj.near = this._near
|
|
146
|
+
// obj.far = this._far
|
|
147
|
+
// obj.fov = this._fov
|
|
148
|
+
// return obj
|
|
149
|
+
// }
|
|
150
|
+
// fromObject(object)
|
|
151
|
+
// {
|
|
152
|
+
// super.fromObject(object)
|
|
153
|
+
// this.updateFOV(object.fov)
|
|
154
|
+
// this.updateNear(object.near)
|
|
155
|
+
// this.updateFar(object.far)
|
|
156
|
+
// }
|
|
157
|
+
// }
|
|
158
|
+
|
|
159
|
+
// export class OrthographicCameraStatus extends CameraStatus
|
|
160
|
+
// {
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
// constructor(camera:OrthographicCamera, targetPosition:Vector3)
|
|
164
|
+
// {
|
|
165
|
+
// super(camera,targetPosition)
|
|
166
|
+
// this.type = "orthographic"
|
|
167
|
+
|
|
168
|
+
// }
|
|
169
|
+
// get zoom(): number
|
|
170
|
+
// {
|
|
171
|
+
// return this._zoom;
|
|
172
|
+
// }
|
|
173
|
+
// private _zoom:number = 1
|
|
174
|
+
// update(camera:OrthographicCamera, targetPosition:Vector3)
|
|
175
|
+
// {
|
|
176
|
+
// this.updateCameraPosition(camera.position)
|
|
177
|
+
// this.updateCameraQuaternion(camera.quaternion)
|
|
178
|
+
// this.updateTargetPosition(targetPosition)
|
|
179
|
+
// this.updateCameraZoom(camera.zoom)
|
|
180
|
+
// this.updateCameraView(camera.left, camera.right, camera.top, camera.bottom)
|
|
181
|
+
// }
|
|
182
|
+
// updateCameraZoom(cameraZoom:number)
|
|
183
|
+
// {
|
|
184
|
+
// this._zoom = cameraZoom
|
|
185
|
+
// }
|
|
186
|
+
|
|
187
|
+
// get bottom(): number
|
|
188
|
+
// {
|
|
189
|
+
// return this._bottom;
|
|
190
|
+
// }
|
|
191
|
+
// get top(): number
|
|
192
|
+
// {
|
|
193
|
+
// return this._top;
|
|
194
|
+
// }
|
|
195
|
+
// get right(): number
|
|
196
|
+
// {
|
|
197
|
+
// return this._right;
|
|
198
|
+
// }
|
|
199
|
+
// get left(): number
|
|
200
|
+
// {
|
|
201
|
+
// return this._left;
|
|
202
|
+
// }
|
|
203
|
+
// private _left:number = -100
|
|
204
|
+
// private _right:number = -100
|
|
205
|
+
// private _top:number = -100
|
|
206
|
+
// private _bottom:number = -100
|
|
207
|
+
// updateCameraView(left:number, right:number, top:number, bottom:number)
|
|
208
|
+
// {
|
|
209
|
+
// this._left = left
|
|
210
|
+
// this._right = right
|
|
211
|
+
// this._top = top
|
|
212
|
+
// this._bottom = bottom
|
|
213
|
+
// }
|
|
214
|
+
// get far(): number
|
|
215
|
+
// {
|
|
216
|
+
// return this._far;
|
|
217
|
+
// }
|
|
218
|
+
// get near(): number
|
|
219
|
+
// {
|
|
220
|
+
// return this._near;
|
|
221
|
+
// }
|
|
222
|
+
|
|
223
|
+
// private _near: number = 1
|
|
224
|
+
// private _far: number = 1
|
|
225
|
+
// updateNear(near:number)
|
|
226
|
+
// {
|
|
227
|
+
// this._near = near
|
|
228
|
+
// }
|
|
229
|
+
// updateFar(far:number)
|
|
230
|
+
// {
|
|
231
|
+
// this._far = far
|
|
232
|
+
// }
|
|
233
|
+
|
|
234
|
+
// copy(other:OrthographicCameraStatus)
|
|
235
|
+
// {
|
|
236
|
+
// this.updateCameraView(other.left, other.right,other.top,other.bottom)
|
|
237
|
+
// this.updateNear(other.near)
|
|
238
|
+
// this.updateFar(other.far)
|
|
239
|
+
// super.copy(other)
|
|
240
|
+
// }
|
|
241
|
+
|
|
242
|
+
// toObject():object
|
|
243
|
+
// {
|
|
244
|
+
// let obj = super.toObject()
|
|
245
|
+
// obj.left = this.left
|
|
246
|
+
// obj.right = this.right
|
|
247
|
+
// obj.top = this.top
|
|
248
|
+
// obj.bottom = this.bottom
|
|
249
|
+
// obj.zoom = this.zoom
|
|
250
|
+
// obj.near = this.near
|
|
251
|
+
// obj.far = this.far
|
|
252
|
+
// return obj
|
|
253
|
+
// }
|
|
254
|
+
|
|
255
|
+
// fromObject(object)
|
|
256
|
+
// {
|
|
257
|
+
// super.fromObject(object)
|
|
258
|
+
// this.updateCameraView(object.left, object.right, object.top, object.bottom)
|
|
259
|
+
// this.updateNear(object.near)
|
|
260
|
+
// this.updateFar(object.far)
|
|
261
|
+
// }
|
|
262
|
+
// }
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import {PointerLockControls} from "three/examples/jsm/controls/PointerLockControls";
|
|
2
|
+
import {
|
|
3
|
+
CapsuleGeometry,
|
|
4
|
+
Euler,
|
|
5
|
+
MeshBasicMaterial,
|
|
6
|
+
Quaternion,
|
|
7
|
+
Vector3,
|
|
8
|
+
Camera,
|
|
9
|
+
Ray,
|
|
10
|
+
Plane, PerspectiveCamera
|
|
11
|
+
} from "three";
|
|
12
|
+
import {CameraStatus, PawnBase} from "./PawnBase";
|
|
13
|
+
|
|
14
|
+
export class LYFirstPerson extends PawnBase
|
|
15
|
+
{
|
|
16
|
+
protected speed: number = 10
|
|
17
|
+
protected cameraHeight: number = 1.5
|
|
18
|
+
|
|
19
|
+
protected mouseUpEvent
|
|
20
|
+
protected keyUpEvent
|
|
21
|
+
protected keyDownEvent
|
|
22
|
+
|
|
23
|
+
protected isForward: boolean = false;
|
|
24
|
+
protected isBackward: boolean = false;
|
|
25
|
+
protected isLeft: boolean = false;
|
|
26
|
+
protected isRight: boolean = false;
|
|
27
|
+
|
|
28
|
+
protected domElement
|
|
29
|
+
|
|
30
|
+
constructor(world)
|
|
31
|
+
{
|
|
32
|
+
let ele = world.Element;
|
|
33
|
+
let camera = new PerspectiveCamera(60, ele.clientWidth / ele.clientHeight, 0.1, 7000)
|
|
34
|
+
super(world,camera,new PointerLockControls(camera, world.renderer.domElement));
|
|
35
|
+
this.domElement = world.renderer.domElement
|
|
36
|
+
|
|
37
|
+
this.mouseUpEvent = () =>
|
|
38
|
+
{
|
|
39
|
+
this.Control.isLocked ? this.Control.unlock() : this.Control.lock()
|
|
40
|
+
}
|
|
41
|
+
this.keyDownEvent = (event) =>
|
|
42
|
+
{
|
|
43
|
+
this.onKeyDown(event)
|
|
44
|
+
}
|
|
45
|
+
this.keyUpEvent = (event) =>
|
|
46
|
+
{
|
|
47
|
+
this.onKeyUp(event)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
camera.position.y = Math.max(camera.position.y + this.cameraHeight, 5)
|
|
51
|
+
|
|
52
|
+
this.Camera.updateProjectionMatrix();
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const geometry = new CapsuleGeometry(0.3, 1.2, 4, 8);
|
|
56
|
+
const material = new MeshBasicMaterial({
|
|
57
|
+
color : 0x00ff00,
|
|
58
|
+
wireframe: true
|
|
59
|
+
});
|
|
60
|
+
this.cameraStatus.update(this.Camera.position, this.Camera.quaternion, 0)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected onKeyDown(event)
|
|
64
|
+
{
|
|
65
|
+
switch (event.code)
|
|
66
|
+
{
|
|
67
|
+
case 'ArrowUp':
|
|
68
|
+
case 'KeyW':
|
|
69
|
+
this.isForward = true;
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case 'ArrowLeft':
|
|
73
|
+
case 'KeyA':
|
|
74
|
+
this.isLeft = true;
|
|
75
|
+
break;
|
|
76
|
+
|
|
77
|
+
case 'ArrowDown':
|
|
78
|
+
case 'KeyS':
|
|
79
|
+
this.isBackward = true;
|
|
80
|
+
break;
|
|
81
|
+
|
|
82
|
+
case 'ArrowRight':
|
|
83
|
+
case 'KeyD':
|
|
84
|
+
this.isRight = true;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
protected onKeyUp(event)
|
|
90
|
+
{
|
|
91
|
+
switch (event.code)
|
|
92
|
+
{
|
|
93
|
+
|
|
94
|
+
case 'ArrowUp':
|
|
95
|
+
case 'KeyW':
|
|
96
|
+
this.isForward = false;
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
case 'ArrowLeft':
|
|
100
|
+
case 'KeyA':
|
|
101
|
+
this.isLeft = false;
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
case 'ArrowDown':
|
|
105
|
+
case 'KeyS':
|
|
106
|
+
this.isBackward = false;
|
|
107
|
+
break;
|
|
108
|
+
|
|
109
|
+
case 'ArrowRight':
|
|
110
|
+
case 'KeyD':
|
|
111
|
+
this.isRight = false;
|
|
112
|
+
break;
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
tick(deltaTime)
|
|
118
|
+
{
|
|
119
|
+
super.tick(deltaTime)
|
|
120
|
+
|
|
121
|
+
let movingDirection = new Vector3()
|
|
122
|
+
movingDirection.z = this.isForward ? this.isBackward ? 0 : -1 : this.isBackward ? 1 : 0;
|
|
123
|
+
movingDirection.x = this.isRight ? this.isLeft ? 0 : 1 : this.isLeft ? -1 : 0;
|
|
124
|
+
|
|
125
|
+
movingDirection.applyQuaternion(this.Camera.quaternion)
|
|
126
|
+
movingDirection.normalize()
|
|
127
|
+
movingDirection.y = 0
|
|
128
|
+
movingDirection.multiplyScalar(deltaTime * this.speed);
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
let finalY = this.Camera.position.y
|
|
132
|
+
if(this.World.Octree)
|
|
133
|
+
{
|
|
134
|
+
let ray = new Ray(this.Camera.position, movingDirection)
|
|
135
|
+
const result = this.World.Octree.rayIntersect(ray)
|
|
136
|
+
if (result && (result.distance < deltaTime * this.speed))
|
|
137
|
+
{
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
let rayDown = new Ray(this.Camera.position, new Vector3(0, -1, 0))
|
|
141
|
+
const resultDown = this.World.Octree.rayIntersect(rayDown)
|
|
142
|
+
|
|
143
|
+
if (resultDown)
|
|
144
|
+
{
|
|
145
|
+
finalY = resultDown.position.y + this.cameraHeight
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
this.Camera.position.set(
|
|
149
|
+
this.Camera.position.x + movingDirection.x,
|
|
150
|
+
finalY,
|
|
151
|
+
this.Camera.position.z + movingDirection.z
|
|
152
|
+
)
|
|
153
|
+
this.cameraStatus.update(this.Camera.position, this.Camera.quaternion, 0)
|
|
154
|
+
|
|
155
|
+
this.World.markRenderStateDirty();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
get Camera(): Camera
|
|
159
|
+
{
|
|
160
|
+
return this.Control.camera;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
setCamera(newCamera)
|
|
164
|
+
{
|
|
165
|
+
super.setCamera(newCamera)
|
|
166
|
+
this.Control.camera = newCamera
|
|
167
|
+
this.World.markRenderStateDirty();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
possess()
|
|
171
|
+
{
|
|
172
|
+
this.World.Controller.IsTickable = true
|
|
173
|
+
this.IsTickable = true;
|
|
174
|
+
this.domElement.addEventListener('mouseup', this.mouseUpEvent)
|
|
175
|
+
document.addEventListener('keydown', this.keyDownEvent)
|
|
176
|
+
document.addEventListener('keyup', this.keyUpEvent)
|
|
177
|
+
this.World.markRenderStateDirty();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
unpossess()
|
|
181
|
+
{
|
|
182
|
+
this.World.Controller.IsTickable = false
|
|
183
|
+
this.IsTickable = false
|
|
184
|
+
this.domElement.removeEventListener('mouseup', this.mouseUpEvent)
|
|
185
|
+
document.removeEventListener('keydown', this.keyDownEvent)
|
|
186
|
+
document.removeEventListener('keyup', this.keyUpEvent)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
focusTo(targetPos, targetQuat, distance, time = 0, onFinished = null)
|
|
190
|
+
{
|
|
191
|
+
console.log(targetPos)
|
|
192
|
+
this.Camera.position.set(targetPos.x, targetPos.y + this.cameraHeight, targetPos.z);
|
|
193
|
+
if (targetQuat instanceof Euler)
|
|
194
|
+
{
|
|
195
|
+
targetQuat = new Quaternion().setFromEuler(targetQuat)
|
|
196
|
+
}
|
|
197
|
+
let fV = new Vector3(0, 0, -1)
|
|
198
|
+
fV.applyQuaternion(targetQuat)
|
|
199
|
+
let lookingTarget = targetPos.clone()
|
|
200
|
+
lookingTarget.add(fV.multiplyScalar(100))
|
|
201
|
+
lookingTarget.y = targetPos.y + this.cameraHeight
|
|
202
|
+
this.Camera.lookAt(lookingTarget.x, targetPos.y + this.cameraHeight, lookingTarget.z)
|
|
203
|
+
|
|
204
|
+
this.cameraStatus.update(this.Camera.position, this.Camera.quaternion, lookingTarget)
|
|
205
|
+
|
|
206
|
+
if (onFinished)
|
|
207
|
+
{
|
|
208
|
+
onFinished();
|
|
209
|
+
}
|
|
210
|
+
this.World.markRenderStateDirty();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
restore(status: CameraStatus)
|
|
214
|
+
{
|
|
215
|
+
super.restore(status);
|
|
216
|
+
this.focusTo(status.targetPosition, status.cameraQuaternion, status.targetPosition.clone().sub(status.cameraPosition).length())
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
destroy()
|
|
220
|
+
{
|
|
221
|
+
if (this.Control)
|
|
222
|
+
{
|
|
223
|
+
this.domElement.removeEventListener('mouseup', this.mouseUpEvent)
|
|
224
|
+
document.removeEventListener('keydown', this.keyDownEvent)
|
|
225
|
+
document.removeEventListener('keyup', this.keyUpEvent)
|
|
226
|
+
this.Control.dispose();
|
|
227
|
+
}
|
|
228
|
+
super.destroy();
|
|
229
|
+
}
|
|
230
|
+
}
|