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,215 @@
|
|
|
1
|
+
import {PawnBase} from "./PawnBase";
|
|
2
|
+
import {LYThreeWorld} from "../../Frame";
|
|
3
|
+
import {Camera, Matrix4, Object3D, PerspectiveCamera} from "three";
|
|
4
|
+
import {TransformControls} from "three/examples/jsm/controls/TransformControls";
|
|
5
|
+
|
|
6
|
+
export interface TransformType
|
|
7
|
+
{
|
|
8
|
+
rotate:"X" | "Y" | "Z" | "E" | "XY" | "YZ" | "XZ" | "XYZ" | "XYZE" | null;
|
|
9
|
+
scale:"X" | "Y" | "Z" | "E" | "XY" | "YZ" | "XZ" | "XYZ" | "XYZE" | null;
|
|
10
|
+
translate:"X" | "Y" | "Z" | "E" | "XY" | "YZ" | "XZ" | "XYZ" | "XYZE" | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ITransforming
|
|
14
|
+
{
|
|
15
|
+
// onTransfroming(worldPos:Vector3, worldQuat:Quaternion, worldScale:Vector3):void
|
|
16
|
+
isTransformAllowed():boolean;
|
|
17
|
+
|
|
18
|
+
onTransforming(worldMatrix:Matrix4):void;
|
|
19
|
+
|
|
20
|
+
getMatrixInWorld():Matrix4;
|
|
21
|
+
|
|
22
|
+
getAllowedTransformType():TransformType;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class LYTransformControl extends PawnBase
|
|
26
|
+
{
|
|
27
|
+
protected onChange:Function;
|
|
28
|
+
protected onDraggingChanged:Function;
|
|
29
|
+
protected onObjectChange:Function;
|
|
30
|
+
protected onUpdateFunctions:Function[] = [];
|
|
31
|
+
protected onDraggingFunctions:Function[] = [];
|
|
32
|
+
private helperObject:Object3D = new Object3D();
|
|
33
|
+
protected targets:ITransforming[] = [];
|
|
34
|
+
protected primaryTarget:ITransforming | null = null;
|
|
35
|
+
private targetMatrixMap:Map<ITransforming, Matrix4> = new Map();
|
|
36
|
+
|
|
37
|
+
constructor(world:LYThreeWorld, camera:Camera)
|
|
38
|
+
{
|
|
39
|
+
camera = camera ? camera : new PerspectiveCamera();
|
|
40
|
+
super(world, camera, new TransformControls(camera, world.renderer.domElement));
|
|
41
|
+
world.scene?.add(this.helperObject);
|
|
42
|
+
this.onUpdateFunctions = [];
|
|
43
|
+
this.onChange = () =>
|
|
44
|
+
{
|
|
45
|
+
this.World.markRenderStateDirty();
|
|
46
|
+
};
|
|
47
|
+
this.onDraggingChanged = (event) =>
|
|
48
|
+
{
|
|
49
|
+
if (this.primaryTarget)
|
|
50
|
+
{
|
|
51
|
+
let tMatrix = this.primaryTarget.getMatrixInWorld();
|
|
52
|
+
tMatrix.decompose(this.helperObject.position, this.helperObject.quaternion, this.helperObject.scale);
|
|
53
|
+
}
|
|
54
|
+
this.onDraggingFunctions.forEach((elem) =>
|
|
55
|
+
{
|
|
56
|
+
elem(event.value);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
this.onObjectChange = () =>
|
|
60
|
+
{
|
|
61
|
+
if (this.primaryTarget)
|
|
62
|
+
{
|
|
63
|
+
const TA1 = this.primaryTarget.getMatrixInWorld();
|
|
64
|
+
this.helperObject.updateMatrixWorld(true);
|
|
65
|
+
const TA2 = this.helperObject.matrixWorld.clone();
|
|
66
|
+
// 将初始矩阵分解为位置、旋转和缩放
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
this.primaryTarget.onTransforming(TA2);
|
|
70
|
+
|
|
71
|
+
const TA1Inverse = TA1.clone().invert();
|
|
72
|
+
const transformMatrix = new Matrix4().multiplyMatrices(TA2, TA1Inverse);
|
|
73
|
+
this.targets.forEach((tar) =>
|
|
74
|
+
{
|
|
75
|
+
|
|
76
|
+
//
|
|
77
|
+
// let TB1 = tar.getMatrixInWorld(); // B 的初始世界矩阵
|
|
78
|
+
// let TB2 = new Matrix4().multiplyMatrices(transformMatrix, TB1); // B
|
|
79
|
+
//
|
|
80
|
+
// tar.onTransforming(TB2)
|
|
81
|
+
// let TB1 = tar.getMatrixInWorld();
|
|
82
|
+
// const TB_local = TB1.clone().invert().multiply(TA1);
|
|
83
|
+
|
|
84
|
+
if (tar !== this.primaryTarget)
|
|
85
|
+
{
|
|
86
|
+
let TB2 = new Matrix4().multiplyMatrices(TA2, this.targetMatrixMap.get(tar)); // B
|
|
87
|
+
|
|
88
|
+
tar.onTransforming(TB2);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// this.primaryTarget.onTransforming(this.helperObject.matrix)
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
this.onUpdateFunctions.forEach((elem) =>
|
|
97
|
+
{
|
|
98
|
+
elem();
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
this.setSize(0.5);
|
|
102
|
+
this.World.markRenderStateDirty();
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
tick(deltaTime)
|
|
107
|
+
{
|
|
108
|
+
super.tick(deltaTime);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
get Camera()
|
|
112
|
+
{
|
|
113
|
+
return this.Control.camera;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
set enable(newEnable)
|
|
117
|
+
{
|
|
118
|
+
this.Control.enabled = newEnable;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
setTarget(primaryTarget:ITransforming, multiTargets:ITransforming[], onUpdate:Function | null = null, onDragging:Function | null)
|
|
123
|
+
{
|
|
124
|
+
this.targetMatrixMap.clear();
|
|
125
|
+
let tMatrix = primaryTarget.getMatrixInWorld();
|
|
126
|
+
tMatrix.decompose(this.helperObject.position, this.helperObject.quaternion, this.helperObject.scale);
|
|
127
|
+
this.Control.attach(this.helperObject);
|
|
128
|
+
this.primaryTarget = primaryTarget;
|
|
129
|
+
this.targets = multiTargets;
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
this.targets.forEach((elem) =>
|
|
133
|
+
{
|
|
134
|
+
const tarMatrix = elem.getMatrixInWorld();
|
|
135
|
+
const TB_local = tMatrix.clone().invert().multiply(tarMatrix);
|
|
136
|
+
|
|
137
|
+
this.targetMatrixMap.set(elem, TB_local);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (onUpdate)
|
|
141
|
+
{
|
|
142
|
+
this.onUpdateFunctions.push(onUpdate);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (onUpdate)
|
|
146
|
+
{
|
|
147
|
+
this.onUpdateFunctions.push(onUpdate);
|
|
148
|
+
}
|
|
149
|
+
if (onDragging)
|
|
150
|
+
{
|
|
151
|
+
this.onDraggingFunctions.push(onDragging);
|
|
152
|
+
}
|
|
153
|
+
this.IsTickable = true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getMode():"translate" | "rotate" | "scale"
|
|
157
|
+
{
|
|
158
|
+
return this.Control.getMode();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
setMode(mode:"translate" | "rotate" | "scale"):void
|
|
162
|
+
{
|
|
163
|
+
this.Control.setMode(mode);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
setSpace(space:"world" | "local"):void
|
|
167
|
+
{
|
|
168
|
+
this.Control.setSpace(space);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
setAxis(axis:"X" | "Y" | "Z" | "E" | "XY" | "YZ" | "XZ" | "XYZ" | "XYZE" | null)
|
|
172
|
+
{
|
|
173
|
+
this.Control.showX = axis?.indexOf("X") >= 0;
|
|
174
|
+
this.Control.showY = axis?.indexOf("Y") >= 0;
|
|
175
|
+
this.Control.showZ = axis?.indexOf("Z") >= 0;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
setSize(size:number):void
|
|
179
|
+
{
|
|
180
|
+
this.Control.setSize(size);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
setCamera(newCamera)
|
|
184
|
+
{
|
|
185
|
+
super.setCamera(newCamera);
|
|
186
|
+
this.Control.camera = newCamera;
|
|
187
|
+
this.World.markRenderStateDirty();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
possess()
|
|
191
|
+
{
|
|
192
|
+
this.World.scene.add(this.Control.getHelper());
|
|
193
|
+
this.Control.addEventListener('change', this.onChange);
|
|
194
|
+
this.Control.addEventListener('dragging-changed', this.onDraggingChanged);
|
|
195
|
+
this.Control.addEventListener('objectChange', this.onObjectChange);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
unpossess()
|
|
199
|
+
{
|
|
200
|
+
this.World.scene.remove(this.Control.getHelper());
|
|
201
|
+
this.onUpdateFunctions = [];
|
|
202
|
+
this.Control.removeEventListener('change', this.onChange);
|
|
203
|
+
this.Control.removeEventListener('dragging-changed', this.onDraggingChanged);
|
|
204
|
+
this.Control.removeEventListener('objectChange', this.onObjectChange);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
destroy()
|
|
209
|
+
{
|
|
210
|
+
this.IsTickable = false;
|
|
211
|
+
this.world.scene?.remove(this.helperObject);
|
|
212
|
+
|
|
213
|
+
super.destroy();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';
|
|
2
|
+
import {Euler, PerspectiveCamera, Quaternion} from "three";
|
|
3
|
+
import {CameraStatus, PawnBase} from "./PawnBase";
|
|
4
|
+
|
|
5
|
+
export class LYStaticCamera extends PawnBase
|
|
6
|
+
{
|
|
7
|
+
protected speed: number = 3
|
|
8
|
+
protected cameraHeight: number = 15
|
|
9
|
+
protected domElement
|
|
10
|
+
|
|
11
|
+
constructor(world)
|
|
12
|
+
{
|
|
13
|
+
let ele = world.Element;
|
|
14
|
+
let camera = new PerspectiveCamera(90, ele.clientWidth / ele.clientHeight, 0.5, 7000)
|
|
15
|
+
super(world, camera, new PointerLockControls(camera, world.renderer.domElement));
|
|
16
|
+
this.domElement = world.renderer.domElement
|
|
17
|
+
|
|
18
|
+
camera.position.y = Math.max(camera.position.y, 5)
|
|
19
|
+
|
|
20
|
+
this.World.markRenderStateDirty();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
tick(deltaTime)
|
|
24
|
+
{
|
|
25
|
+
super.tick(deltaTime)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get Camera()
|
|
29
|
+
{
|
|
30
|
+
return this.Control.camera;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setCamera(newCamera)
|
|
34
|
+
{
|
|
35
|
+
super.setCamera(newCamera)
|
|
36
|
+
this.Control.camera = newCamera
|
|
37
|
+
this.World.markRenderStateDirty();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
possess()
|
|
41
|
+
{
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
unpossess()
|
|
45
|
+
{
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
focusTo(targetPos, targetQuat, distance, time = 0, onFinished = null)
|
|
50
|
+
{
|
|
51
|
+
this.Camera.position.set(targetPos.x, targetPos.y + this.cameraHeight, targetPos.z);
|
|
52
|
+
if (targetQuat instanceof Euler)
|
|
53
|
+
{
|
|
54
|
+
targetQuat = new Quaternion().setFromEuler(targetQuat)
|
|
55
|
+
}
|
|
56
|
+
this.Camera.quaternion.set(targetQuat.x, targetQuat.y, targetQuat.z, targetQuat.w)
|
|
57
|
+
this.cameraStatus.update(this.Camera.position, this.Camera.quaternion, targetPos)
|
|
58
|
+
|
|
59
|
+
if (onFinished)
|
|
60
|
+
{
|
|
61
|
+
onFinished();
|
|
62
|
+
}
|
|
63
|
+
this.World.markRenderStateDirty();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
restore(status: CameraStatus)
|
|
67
|
+
{
|
|
68
|
+
super.restore(status);
|
|
69
|
+
this.focusTo(status.targetPosition, status.cameraQuaternion, status.targetPosition.clone().sub(status.cameraPosition).length())
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
destroy()
|
|
73
|
+
{
|
|
74
|
+
if (this.Control)
|
|
75
|
+
{
|
|
76
|
+
this.Control.dispose();
|
|
77
|
+
}
|
|
78
|
+
super.destroy();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Pawn} from "./Pawn.ts";
|
|
2
|
+
import {PointerLockControls} from "three/examples/jsm/controls/PointerLockControls";
|
|
3
|
+
import {Controller} from "../../Frame/Controller.ts";
|
|
4
|
+
|
|
5
|
+
export class FirstPerson extends Pawn
|
|
6
|
+
{
|
|
7
|
+
constructor(controller:Controller)
|
|
8
|
+
{
|
|
9
|
+
super(controller);
|
|
10
|
+
this.control = new PointerLockControls(controller.camera, controller.viewPort.canvas)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {Pawn} from "./Pawn.ts";
|
|
2
|
+
|
|
3
|
+
import {Controller} from "../../Frame/Controller.ts";
|
|
4
|
+
import { OrbitControls } from "three/examples/jsm/Addons.js";
|
|
5
|
+
|
|
6
|
+
export class Orbital extends Pawn
|
|
7
|
+
{
|
|
8
|
+
override get control():OrbitControls
|
|
9
|
+
{
|
|
10
|
+
if(!this._control)
|
|
11
|
+
{
|
|
12
|
+
throw new Error("Control not initialized")
|
|
13
|
+
}
|
|
14
|
+
return this._control;
|
|
15
|
+
}
|
|
16
|
+
protected override _control:OrbitControls
|
|
17
|
+
protected changeEvent = ()=>{this.onChange()}
|
|
18
|
+
|
|
19
|
+
constructor(controller:Controller)
|
|
20
|
+
{
|
|
21
|
+
super(controller);
|
|
22
|
+
this._control = new OrbitControls(controller.camera, controller.viewPort.canvas)
|
|
23
|
+
this.control.target.set( 0, 0, 0 );
|
|
24
|
+
controller.camera.position.set( 0, 4, 4 );
|
|
25
|
+
this.control.update()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
possess()
|
|
29
|
+
{
|
|
30
|
+
super.possess()
|
|
31
|
+
this.control.addEventListener('change', this.changeEvent)
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
unpossess()
|
|
36
|
+
{
|
|
37
|
+
super.unpossess()
|
|
38
|
+
this.control.removeEventListener("change", this.changeEvent)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onChange()
|
|
42
|
+
{
|
|
43
|
+
this.controller.viewPort.markRenderStateDirty();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
import {Controller} from "../../Frame/Controller.ts";
|
|
3
|
+
|
|
4
|
+
export abstract class Pawn
|
|
5
|
+
{
|
|
6
|
+
get camera()
|
|
7
|
+
{
|
|
8
|
+
return this.controller.camera
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
set enabled(value:boolean)
|
|
12
|
+
{
|
|
13
|
+
this.control.enabled = value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get control():any
|
|
17
|
+
{
|
|
18
|
+
if(!this._control)
|
|
19
|
+
{
|
|
20
|
+
throw new Error("Control not initialized")
|
|
21
|
+
}
|
|
22
|
+
return this._control;
|
|
23
|
+
}
|
|
24
|
+
protected _control : any|null = null;
|
|
25
|
+
protected controller : Controller;
|
|
26
|
+
protected isTickEnabled: boolean = false;
|
|
27
|
+
|
|
28
|
+
protected constructor(controller:Controller)
|
|
29
|
+
{
|
|
30
|
+
this.controller = controller;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
tick(deltaTime:number)
|
|
34
|
+
{
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
possess()
|
|
38
|
+
{
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
unpossess()
|
|
42
|
+
{
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
destroy()
|
|
47
|
+
{
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Controller } from "@threeframe/LYCustomFrame.ts";
|
|
2
|
+
import {Pawn} from "./Pawn.ts";
|
|
3
|
+
import { Matrix4, Object3D } from "three";
|
|
4
|
+
import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
|
|
5
|
+
export interface TransformType
|
|
6
|
+
{
|
|
7
|
+
rotate:"X" | "Y" | "Z" | "E" | "XY" | "YZ" | "XZ" | "XYZ" | "XYZE" | null;
|
|
8
|
+
scale:"X" | "Y" | "Z" | "E" | "XY" | "YZ" | "XZ" | "XYZ" | "XYZE" | null;
|
|
9
|
+
translate:"X" | "Y" | "Z" | "E" | "XY" | "YZ" | "XZ" | "XYZ" | "XYZE" | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ITransforming
|
|
13
|
+
{
|
|
14
|
+
// onTransfroming(worldPos:Vector3, worldQuat:Quaternion, worldScale:Vector3):void
|
|
15
|
+
isTransformAllowed():boolean;
|
|
16
|
+
onTransforming(worldMatrix:Matrix4):void;
|
|
17
|
+
getMatrixInWorld():Matrix4;
|
|
18
|
+
getAllowedTransformType(): TransformType;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class TransformGizmo extends Pawn
|
|
22
|
+
{
|
|
23
|
+
override get control():TransformControls
|
|
24
|
+
{
|
|
25
|
+
if(!this._control)
|
|
26
|
+
{
|
|
27
|
+
throw new Error("Control not initialized")
|
|
28
|
+
}
|
|
29
|
+
return this._control;
|
|
30
|
+
}
|
|
31
|
+
protected override _control : TransformControls|null = null
|
|
32
|
+
private helperObject : Object3D = new Object3D();
|
|
33
|
+
private targets : ITransforming[] = [];
|
|
34
|
+
private primaryTarget : ITransforming | null = null;
|
|
35
|
+
private targetMatrixMap: Map<ITransforming, Matrix4> = new Map();
|
|
36
|
+
|
|
37
|
+
protected onDraggingChangedEvent:(param:{ value: unknown })=>void = (param:{ value: unknown })=>{this.onDraggingChanged(param)}
|
|
38
|
+
protected onObjectChangeEvent:()=>void = ()=>{this.onObjectChanged()}
|
|
39
|
+
protected onChangeEvent:()=>void = ()=>{this.onChange()};
|
|
40
|
+
|
|
41
|
+
protected onUpdateFunctions:(()=>void)[] = [];
|
|
42
|
+
protected onDraggingFunctions:((event:any)=>void)[] = [];
|
|
43
|
+
|
|
44
|
+
constructor(controller:Controller)
|
|
45
|
+
{
|
|
46
|
+
super(controller);
|
|
47
|
+
this._control = new TransformControls(controller.camera, controller.viewPort.canvas)
|
|
48
|
+
this.control.getHelper().traverse((elem)=>{
|
|
49
|
+
elem.userData["rayIgnored"] = true
|
|
50
|
+
})
|
|
51
|
+
this.helperObject.name = "TransformHelperObject"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
possess()
|
|
55
|
+
{
|
|
56
|
+
this.controller.world.scene?.add(this.helperObject);
|
|
57
|
+
this.control.attach(this.helperObject);
|
|
58
|
+
this.control.addEventListener('change', this.onChangeEvent);
|
|
59
|
+
this.control.addEventListener('dragging-changed', this.onDraggingChangedEvent);
|
|
60
|
+
this.control.addEventListener('objectChange', this.onObjectChangeEvent);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
unpossess()
|
|
64
|
+
{
|
|
65
|
+
this.control.removeEventListener('change', this.onChangeEvent);
|
|
66
|
+
this.control.removeEventListener('dragging-changed', this.onDraggingChangedEvent);
|
|
67
|
+
this.control.removeEventListener('objectChange', this.onObjectChangeEvent);
|
|
68
|
+
this.control.detach();
|
|
69
|
+
this.controller.world.scene?.remove(this.helperObject);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
onChange()
|
|
73
|
+
{
|
|
74
|
+
this.controller.viewPort.markRenderStateDirty();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onDraggingChanged(event:{value:any})
|
|
78
|
+
{
|
|
79
|
+
if (this.primaryTarget)
|
|
80
|
+
{
|
|
81
|
+
let tMatrix = this.primaryTarget.getMatrixInWorld();
|
|
82
|
+
tMatrix.decompose(this.helperObject.position, this.helperObject.quaternion, this.helperObject.scale);
|
|
83
|
+
}
|
|
84
|
+
this.onDraggingFunctions.forEach((elem) =>
|
|
85
|
+
{
|
|
86
|
+
elem(event.value);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
onObjectChanged()
|
|
91
|
+
{
|
|
92
|
+
if (this.primaryTarget)
|
|
93
|
+
{
|
|
94
|
+
//const TA1 = this.primaryTarget.getMatrixInWorld();
|
|
95
|
+
this.helperObject.updateMatrixWorld(true);
|
|
96
|
+
const TA2 = this.helperObject.matrixWorld.clone();
|
|
97
|
+
|
|
98
|
+
this.primaryTarget.onTransforming(TA2);
|
|
99
|
+
|
|
100
|
+
// const TA1Inverse = TA1.clone().invert();
|
|
101
|
+
//const transformMatrix = new Matrix4().multiplyMatrices(TA2, TA1Inverse);
|
|
102
|
+
this.targets.forEach((tar) =>
|
|
103
|
+
{
|
|
104
|
+
if (tar !== this.primaryTarget)
|
|
105
|
+
{
|
|
106
|
+
let t = this.targetMatrixMap.get(tar)
|
|
107
|
+
if(t)
|
|
108
|
+
{
|
|
109
|
+
let TB2 = new Matrix4().multiplyMatrices(TA2, t); // B
|
|
110
|
+
|
|
111
|
+
tar.onTransforming(TB2);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
this.onUpdateFunctions.forEach((elem) =>
|
|
118
|
+
{
|
|
119
|
+
elem();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
set enable(newEnable:boolean)
|
|
124
|
+
{
|
|
125
|
+
this.control.enabled = newEnable;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
setTarget(primaryTarget:ITransforming, multiTargets:ITransforming[], onUpdate:(()=>void) | null = null, onDragging:((bDragging:boolean)=>void) | null = null)
|
|
130
|
+
{
|
|
131
|
+
this.targetMatrixMap.clear();
|
|
132
|
+
let tMatrix = primaryTarget.getMatrixInWorld();
|
|
133
|
+
tMatrix.decompose(this.helperObject.position, this.helperObject.quaternion, this.helperObject.scale);
|
|
134
|
+
this.controller.world.scene?.add(this.control.getHelper());
|
|
135
|
+
// this.control.attach(this.helperObject);
|
|
136
|
+
this.primaryTarget = primaryTarget;
|
|
137
|
+
this.targets = multiTargets;
|
|
138
|
+
this.targets.forEach((elem) =>
|
|
139
|
+
{
|
|
140
|
+
const tarMatrix = elem.getMatrixInWorld();
|
|
141
|
+
const TB_local = tMatrix.clone().invert().multiply(tarMatrix);
|
|
142
|
+
this.targetMatrixMap.set(elem, TB_local);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (onUpdate)
|
|
146
|
+
{
|
|
147
|
+
this.onUpdateFunctions.push(onUpdate);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (onUpdate)
|
|
151
|
+
{
|
|
152
|
+
this.onUpdateFunctions.push(onUpdate);
|
|
153
|
+
}
|
|
154
|
+
if (onDragging)
|
|
155
|
+
{
|
|
156
|
+
this.onDraggingFunctions.push(onDragging);
|
|
157
|
+
}
|
|
158
|
+
this.isTickEnabled = true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
getMode():"translate" | "rotate" | "scale"
|
|
162
|
+
{
|
|
163
|
+
return this.control.getMode();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
setMode(mode:"translate" | "rotate" | "scale"):void
|
|
167
|
+
{
|
|
168
|
+
this.control.setMode(mode);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
setSpace(space:"world" | "local"):void
|
|
172
|
+
{
|
|
173
|
+
this.control.setSpace(space);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
setAxis(axis:"X" | "Y" | "Z" | "E" | "XY" | "YZ" | "XZ" | "XYZ" | "XYZE" | null)
|
|
177
|
+
{
|
|
178
|
+
this.control.showX = axis ? axis?.includes("X") : false;
|
|
179
|
+
this.control.showY = axis ? axis?.includes("Y") : false;
|
|
180
|
+
this.control.showZ = axis ? axis?.includes("Z") : false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
setSize(size:number):void
|
|
184
|
+
{
|
|
185
|
+
this.control.setSize(size);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
destroy()
|
|
189
|
+
{
|
|
190
|
+
this.isTickEnabled = false;
|
|
191
|
+
this.unpossess();
|
|
192
|
+
this.targetMatrixMap.clear();
|
|
193
|
+
this.targets = [];
|
|
194
|
+
this.primaryTarget = null;
|
|
195
|
+
this.onUpdateFunctions = [];
|
|
196
|
+
this.onDraggingFunctions = [];
|
|
197
|
+
this._control?.dispose();
|
|
198
|
+
this._control = null;
|
|
199
|
+
super.destroy();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DefaultDenoiseParam, DenoiseParam } from './Denoise';
|
|
2
|
+
export interface GTAOParam
|
|
3
|
+
{
|
|
4
|
+
distanceExponent: number,
|
|
5
|
+
distanceFallOff : number,
|
|
6
|
+
radius : number,
|
|
7
|
+
scale : number,
|
|
8
|
+
thickness : number,
|
|
9
|
+
denoised : boolean,
|
|
10
|
+
denoiseParam : DenoiseParam,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const DefaultGTAOParam:GTAOParam = {
|
|
14
|
+
distanceExponent:1,
|
|
15
|
+
distanceFallOff :1,
|
|
16
|
+
radius :0.25,
|
|
17
|
+
scale :1,
|
|
18
|
+
thickness :1,
|
|
19
|
+
denoised :true,
|
|
20
|
+
denoiseParam :DefaultDenoiseParam,
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface LensFlareParam {
|
|
2
|
+
threshold : number ;
|
|
3
|
+
ghostSpacing : number ;
|
|
4
|
+
ghostAttenuationFactor: number ;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const DefaultLensFlareParam: LensFlareParam = {
|
|
8
|
+
threshold : 0.5,
|
|
9
|
+
ghostSpacing : 25,
|
|
10
|
+
ghostAttenuationFactor: 0.25,
|
|
11
|
+
};
|