lythreeframe 1.0.1 → 1.0.5
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/LICENSE +8 -0
- package/README.md +3 -0
- package/dist/index.ts +80 -0
- package/package.json +18 -12
- package/rollup.config.js +31 -0
- package/src/draco/README.md +32 -0
- package/src/draco/draco_decoder.js +34 -0
- package/src/draco/draco_decoder.wasm +0 -0
- package/src/draco/draco_encoder.js +33 -0
- package/src/draco/draco_wasm_wrapper.js +117 -0
- package/src/draco/gltf/draco_decoder.js +33 -0
- package/src/draco/gltf/draco_decoder.wasm +0 -0
- package/src/draco/gltf/draco_encoder.js +33 -0
- package/src/draco/gltf/draco_wasm_wrapper.js +116 -0
- package/src/index.ts +44 -0
- package/{lythreeFrame/src → src/lythreeframe}/AssetManagement/AssetManager.ts +8 -6
- package/{lythreeFrame/src → src/lythreeframe}/AssetManagement/AssetPointer/AssetPointer.ts +1 -1
- package/{lythreeFrame/src → src/lythreeframe}/Frame/Controller.ts +7 -7
- package/{lythreeFrame/src → src/lythreeframe}/Frame/Viewport.ts +58 -58
- package/{lythreeFrame/src → src/lythreeframe}/Frame/World.ts +4 -4
- package/{lythreeFrame/src → src/lythreeframe}/Frame.ts +1 -1
- package/src/lythreeframe/Library/MaterialLibrary.ts +292 -0
- package/{lythreeFrame/src → src/lythreeframe}/Library/Math.ts +4 -4
- package/{lythreeFrame/src → src/lythreeframe}/Object/Actor.ts +2 -2
- package/{lythreeFrame/src → src/lythreeframe}/Object/Actors/Camera/CameraActor.ts +1 -1
- package/{lythreeFrame/src → src/lythreeframe}/Object/Actors/Light/DirectionalLightActor.ts +2 -2
- package/{lythreeFrame/src → src/lythreeframe}/Object/Actors/Shape/BoxActor.ts +2 -2
- package/{lythreeFrame/src → src/lythreeframe}/Object/Actors/Shape/PlaneActor.ts +2 -2
- package/src/lythreeframe/Object/Actors/Shape/TubeActor.ts +37 -0
- package/{lythreeFrame/src → src/lythreeframe}/Object/Components/2D/2DComponent.ts +1 -1
- package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Camera/CameraComponent.ts +1 -1
- package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Component.ts +1 -1
- package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Light/LightComponent.ts +1 -1
- package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Mesh/InstanceMesh/MultiInstanceMeshComponent.ts +2 -2
- package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Mesh/MeshComponent.ts +2 -2
- package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Mesh/Sprite/SpriteComponent.ts +1 -1
- package/{lythreeFrame/src → src/lythreeframe}/Object/Components/SceneComponent.ts +10 -8
- package/{lythreeFrame/src → src/lythreeframe}/Object/Controller/Controller.ts +2 -2
- package/{lythreeFrame/src → src/lythreeframe}/Object/Pawn/CameraStatus.ts +1 -1
- package/src/lythreeframe/Object/Pawn/FirstPerson.ts +230 -0
- package/src/lythreeframe/Object/Pawn/Oribital.ts +276 -0
- package/src/lythreeframe/Object/Pawn/PawnBase.ts +189 -0
- package/src/lythreeframe/Object/Pawn/TopView.ts +205 -0
- package/src/lythreeframe/Object/Pawn/TransformControl.ts +215 -0
- package/src/lythreeframe/Object/Pawn/staticCamera.ts +80 -0
- package/{lythreeFrame/src → src/lythreeframe}/Object/PawnV2/FirstPerson.ts +3 -3
- package/{lythreeFrame/src → src/lythreeframe}/Object/PawnV2/Oribital.ts +2 -2
- package/{lythreeFrame/src → src/lythreeframe}/Object/PawnV2/Pawn.ts +1 -1
- package/{lythreeFrame/src → src/lythreeframe}/Object/PawnV2/TransformControl.ts +6 -5
- package/{lythreeFrame/src → src/lythreeframe}/PostProcess/Param/DOF.ts +1 -2
- package/{lythreeFrame/src → src/lythreeframe}/PostProcess/PostProcessParam.ts +5 -5
- package/{lythreeFrame/src → src/lythreeframe}/ThreeJsApp.ts +4 -4
- package/tsconfig.json +105 -0
- package/lythreeFrame/index.js +0 -48
- package/lythreeFrame/src/Library/MaterialLibrary.ts +0 -288
- package/lythreeFrame/src/Object/Actors/Shape/TubeActor.ts +0 -37
- package/lythreeFrame/src/Object/Pawn/FirstPerson.ts +0 -230
- package/lythreeFrame/src/Object/Pawn/Oribital.ts +0 -276
- package/lythreeFrame/src/Object/Pawn/PawnBase.ts +0 -189
- package/lythreeFrame/src/Object/Pawn/TopView.ts +0 -205
- package/lythreeFrame/src/Object/Pawn/TransformControl.ts +0 -215
- package/lythreeFrame/src/Object/Pawn/staticCamera.ts +0 -80
- /package/{lythreeFrame/src → src/lythreeframe}/AssetManagement/AssetDefines.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/AssetManagement/Task/Task.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Container/SmartPointer.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Defines.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Delegate.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Factory/CameraFactory.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Factory/RendererFactory.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Geometry/PlaneGeometry.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Geometry/TriangleGeometry.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Library/ContainerLibrary.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Library/ResourceLibrary.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Object/Actors/Shape/CurveActor.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Object/BaseObject.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Light/DirectionalLight/DirectionalLightComponent.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Mesh/InstanceMesh/InstanceMeshComponent.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Mesh/Line/CurveComponent.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Mesh/Shape/BoxComponent.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Mesh/Shape/PlaneComponent.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Object/Components/Mesh/Shape/SphereComponent.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/PostProcess/Param/Bloom.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/PostProcess/Param/Denoise.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/PostProcess/Param/GTAO.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/PostProcess/Param/LensFlare.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/PostProcess/Param/MotionBlur.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/PostProcess/Param/Outline.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/PostProcess/Param/SSR.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/PostProcess/Param/ToneMapping.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/PostProcess/WebGPUPostProcessFactory.ts +0 -0
- /package/{lythreeFrame/src → src/lythreeframe}/Shader/Postprocess/ColorShader.ts +0 -0
|
@@ -1,230 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,276 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
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
|
-
}
|