three-base 1.129.1 → 1.129.2
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/index.js +34 -0
- package/index.ts +5 -1
- package/lib/{ApngTexture.ts → ApngTexture.js} +11 -41
- package/lib/{ApngTextureManage.ts → ApngTextureManage.js} +13 -56
- package/lib/EventMesh.js +59 -0
- package/lib/{ExtrudeMesh.ts → ExtrudeMesh.js} +77 -284
- package/lib/{FPScontrol.ts → FPScontrol.js} +25 -64
- package/lib/InstancedGroupMesh.js +63 -0
- package/lib/{KeyFrameAnimation.ts → KeyFrameAnimation.js} +19 -63
- package/lib/{PlaneText.ts → PlaneText.js} +5 -34
- package/lib/{PointLight.ts → PointLight.js} +4 -18
- package/lib/Sky/{Sky.ts → Sky.js} +4 -12
- package/lib/Text3D/Text3D.js +60 -0
- package/lib/Text3D/fontController.js +200 -0
- package/lib/Text3D/gentilis.json +811 -0
- package/lib/{ThreeBase.ts → ThreeBase.js} +75 -131
- package/lib/{ThreeMouse.ts → ThreeMouse.js} +61 -168
- package/lib/{Transition.ts → Transition.js} +30 -101
- package/lib/index.d.ts +22 -0
- package/lib/{keyContorls.ts → keyContorls.js} +11 -40
- package/lib/lib/ApngTexture.d.ts +13 -0
- package/lib/lib/ApngTextureManage.d.ts +18 -0
- package/lib/lib/EventMesh.d.ts +18 -0
- package/lib/lib/ExtrudeMesh.d.ts +111 -0
- package/lib/lib/FPScontrol.d.ts +44 -0
- package/lib/lib/InstancedGroupMesh.d.ts +10 -0
- package/lib/lib/KeyFrameAnimation.d.ts +25 -0
- package/lib/lib/PlaneText.d.ts +37 -0
- package/lib/lib/PointLight.d.ts +13 -0
- package/lib/lib/Sky/Sky.d.ts +13 -0
- package/lib/lib/Text3D/Text3D.d.ts +20 -0
- package/lib/lib/Text3D/fontController.d.ts +59 -0
- package/lib/lib/ThreeBase.d.ts +59 -0
- package/lib/lib/ThreeMouse.d.ts +39 -0
- package/lib/lib/Transition.d.ts +45 -0
- package/lib/lib/keyContorls.d.ts +25 -0
- package/lib/lib/planeModal1/PlaneModal1.d.ts +32 -0
- package/lib/lib/shaders.d.ts +17 -0
- package/lib/lib/spriteModal1/SpriteModal1.d.ts +31 -0
- package/lib/lib/threeLoader.d.ts +20 -0
- package/lib/lib/threeUtils.d.ts +41 -0
- package/lib/lib/type.d.ts +0 -0
- package/lib/planeModal1/{PlaneModal1.ts → PlaneModal1.js} +33 -77
- package/lib/{shaders.ts → shaders.js} +19 -38
- package/lib/spriteModal1/{SpriteModal1.ts → SpriteModal1.js} +33 -80
- package/lib/{threeLoader.ts → threeLoader.js} +19 -45
- package/lib/{threeUtils.ts → threeUtils.js} +81 -82
- package/lib/{type.ts → type.js} +1 -4
- package/package.json +7 -6
- package/lib/EventMesh.ts +0 -79
- package/lib/InstancedGroupMesh.ts +0 -80
- package/lib/text/Text2D.ts +0 -41
- package/lib/text/Text3D.ts +0 -20
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2022-05-04 23:01:36
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-04 23:01:36
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2022-06-06 13:32:08
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
import { Camera, Clock, EventDispatcher, Object3D, Vector3 } from "three";
|
|
7
|
+
import { Clock, EventDispatcher, Vector3 } from "three";
|
|
9
8
|
import { Capsule } from "three/examples/jsm/math/Capsule";
|
|
10
9
|
import { Octree } from "three/examples/jsm/math/Octree";
|
|
11
10
|
import { clamp, degToRad } from "three/src/math/MathUtils";
|
|
12
|
-
|
|
13
|
-
|
|
14
11
|
/**
|
|
15
12
|
* 第一人称控制器
|
|
16
13
|
*
|
|
@@ -19,49 +16,33 @@ import { clamp, degToRad } from "three/src/math/MathUtils";
|
|
|
19
16
|
* @extends {EventDispatcher}
|
|
20
17
|
*/
|
|
21
18
|
export default class FPScontrol extends EventDispatcher {
|
|
22
|
-
|
|
23
|
-
canvas
|
|
24
|
-
|
|
25
|
-
constructor(camera: Camera, canvas: HTMLCanvasElement) {
|
|
19
|
+
canvas;
|
|
20
|
+
constructor(camera, canvas) {
|
|
26
21
|
super();
|
|
27
|
-
|
|
28
22
|
// 相机对象
|
|
29
23
|
this.camera = camera;
|
|
30
|
-
|
|
31
24
|
this.camera.rotation.order = 'YXZ';
|
|
32
|
-
|
|
33
25
|
this.canvas = canvas;
|
|
34
|
-
|
|
35
26
|
this.init(canvas);
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
// 是否启用
|
|
39
29
|
enable = false;
|
|
40
|
-
|
|
41
30
|
GRAVITY = 30; // 重力
|
|
42
31
|
STEPS_PER_FRAME = 5; // 速度
|
|
43
|
-
|
|
44
|
-
camera!: Camera;
|
|
45
|
-
|
|
32
|
+
camera;
|
|
46
33
|
// 世界八叉树对象
|
|
47
34
|
worldOctree = new Octree();
|
|
48
|
-
|
|
49
35
|
// 用户自己的碰撞体积
|
|
50
36
|
playerCollider = new Capsule(new Vector3(0, 0.35, 0), new Vector3(0, 1, 0), 0.35);
|
|
51
|
-
|
|
52
37
|
// 时钟对象
|
|
53
38
|
clock = new Clock();
|
|
54
|
-
|
|
55
39
|
playerVelocity = new Vector3();
|
|
56
40
|
playerDirection = new Vector3();
|
|
57
|
-
|
|
58
41
|
playerOnFloor = false;
|
|
59
42
|
mouseTime = 0;
|
|
60
43
|
isMousedown = false;
|
|
61
|
-
keyStates
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
init(canvas: HTMLCanvasElement) {
|
|
44
|
+
keyStates = {};
|
|
45
|
+
init(canvas) {
|
|
65
46
|
this.playerCollider.end.set(0, 1, 0);
|
|
66
47
|
document.addEventListener('keydown', this.keydown);
|
|
67
48
|
document.addEventListener('keyup', this.keyup);
|
|
@@ -70,46 +51,36 @@ export default class FPScontrol extends EventDispatcher {
|
|
|
70
51
|
document.body.addEventListener('pointermove', this.mousemove);
|
|
71
52
|
this.enable = true;
|
|
72
53
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
keydown = (event: KeyboardEvent) => {
|
|
54
|
+
keydown = (event) => {
|
|
76
55
|
this.keyStates[event.code] = true;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
keyup = (event: KeyboardEvent) => {
|
|
56
|
+
};
|
|
57
|
+
keyup = (event) => {
|
|
80
58
|
this.keyStates[event.code] = false;
|
|
81
|
-
}
|
|
82
|
-
|
|
59
|
+
};
|
|
83
60
|
mousedown = () => {
|
|
84
61
|
this.isMousedown = true;
|
|
85
62
|
this.mouseTime = performance.now();
|
|
86
|
-
}
|
|
87
|
-
|
|
63
|
+
};
|
|
88
64
|
mouseup = () => {
|
|
89
65
|
this.isMousedown = false;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
mousemove = (event: MouseEvent) => {
|
|
66
|
+
};
|
|
67
|
+
mousemove = (event) => {
|
|
93
68
|
if (this.enable && this.isMousedown) {
|
|
94
69
|
this.camera.rotation.y -= event.movementX / 500;
|
|
95
70
|
this.camera.rotation.x -= event.movementY / 500;
|
|
96
|
-
|
|
97
71
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
72
|
+
};
|
|
100
73
|
// 设置 八叉树 节点
|
|
101
|
-
fromGraphNode(object3d
|
|
74
|
+
fromGraphNode(object3d) {
|
|
102
75
|
this.worldOctree.fromGraphNode(object3d);
|
|
103
76
|
}
|
|
104
|
-
|
|
105
77
|
// 获取前进的向量
|
|
106
78
|
getForwardVector = () => {
|
|
107
79
|
this.camera.getWorldDirection(this.playerDirection);
|
|
108
80
|
this.playerDirection.y = 0;
|
|
109
81
|
this.playerDirection.normalize();
|
|
110
82
|
return this.playerDirection;
|
|
111
|
-
}
|
|
112
|
-
|
|
83
|
+
};
|
|
113
84
|
// 获取 后退的向量
|
|
114
85
|
getSideVector = () => {
|
|
115
86
|
this.camera.getWorldDirection(this.playerDirection);
|
|
@@ -117,10 +88,9 @@ export default class FPScontrol extends EventDispatcher {
|
|
|
117
88
|
this.playerDirection.normalize();
|
|
118
89
|
this.playerDirection.cross(this.camera.up);
|
|
119
90
|
return this.playerDirection;
|
|
120
|
-
}
|
|
121
|
-
|
|
91
|
+
};
|
|
122
92
|
// 玩家移动控制器
|
|
123
|
-
controls = (deltaTime
|
|
93
|
+
controls = (deltaTime) => {
|
|
124
94
|
const speedDelta = deltaTime * (this.playerOnFloor ? 25 : 8);
|
|
125
95
|
if (this.keyStates['KeyW']) {
|
|
126
96
|
this.playerVelocity.add(this.getForwardVector().multiplyScalar(speedDelta));
|
|
@@ -134,17 +104,14 @@ export default class FPScontrol extends EventDispatcher {
|
|
|
134
104
|
if (this.keyStates['KeyD']) {
|
|
135
105
|
this.playerVelocity.add(this.getSideVector().multiplyScalar(speedDelta));
|
|
136
106
|
}
|
|
137
|
-
|
|
138
107
|
if (this.playerOnFloor) {
|
|
139
108
|
if (this.keyStates['Space']) {
|
|
140
109
|
this.playerVelocity.y = 15;
|
|
141
110
|
}
|
|
142
111
|
}
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
112
|
+
};
|
|
146
113
|
// 更新玩家的位置
|
|
147
|
-
updatePlayer = (deltaTime
|
|
114
|
+
updatePlayer = (deltaTime) => {
|
|
148
115
|
let damping = Math.exp(-4 * deltaTime) - 1;
|
|
149
116
|
if (!this.playerOnFloor) {
|
|
150
117
|
this.playerVelocity.y -= this.GRAVITY * deltaTime;
|
|
@@ -157,8 +124,7 @@ export default class FPScontrol extends EventDispatcher {
|
|
|
157
124
|
this.camera.position.copy(this.playerCollider.end);
|
|
158
125
|
this.camera.position.y += 1;
|
|
159
126
|
this.camera.rotation.x = clamp(this.camera.rotation.x, degToRad(-20), degToRad(20));
|
|
160
|
-
}
|
|
161
|
-
|
|
127
|
+
};
|
|
162
128
|
// 玩家的碰撞检测
|
|
163
129
|
playerCollisions() {
|
|
164
130
|
const result = this.worldOctree.capsuleIntersect(this.playerCollider);
|
|
@@ -167,7 +133,6 @@ export default class FPScontrol extends EventDispatcher {
|
|
|
167
133
|
this.playerOnFloor = result.normal.y > 0;
|
|
168
134
|
if (!this.playerOnFloor) {
|
|
169
135
|
this.playerVelocity.addScaledVector(result.normal, -result.normal.dot(this.playerVelocity));
|
|
170
|
-
|
|
171
136
|
}
|
|
172
137
|
this.playerCollider.translate(result.normal.multiplyScalar(result.depth));
|
|
173
138
|
}
|
|
@@ -181,8 +146,7 @@ export default class FPScontrol extends EventDispatcher {
|
|
|
181
146
|
this.camera.position.copy(this.playerCollider.end);
|
|
182
147
|
// this.camera.position.set(0, 3, 0);
|
|
183
148
|
}
|
|
184
|
-
}
|
|
185
|
-
|
|
149
|
+
};
|
|
186
150
|
// 更新
|
|
187
151
|
update() {
|
|
188
152
|
if (this.enable) {
|
|
@@ -194,7 +158,6 @@ export default class FPScontrol extends EventDispatcher {
|
|
|
194
158
|
}
|
|
195
159
|
}
|
|
196
160
|
}
|
|
197
|
-
|
|
198
161
|
// 销毁事件
|
|
199
162
|
disposer() {
|
|
200
163
|
this.enable = false;
|
|
@@ -204,6 +167,4 @@ export default class FPScontrol extends EventDispatcher {
|
|
|
204
167
|
document.removeEventListener('pointerup', this.mouseup);
|
|
205
168
|
document.body.removeEventListener('pointermove', this.mousemove);
|
|
206
169
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-02-21 09:55:52
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-02-26 14:42:21
|
|
6
|
+
*/
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
// 模型组转成 实例对象
|
|
9
|
+
export default class InstancedGroupMesh extends THREE.Mesh {
|
|
10
|
+
isInstancedGroupMesh = true;
|
|
11
|
+
count = 0;
|
|
12
|
+
meshCollect = {};
|
|
13
|
+
instanceCollect = {};
|
|
14
|
+
static matrix = new THREE.Matrix4();
|
|
15
|
+
constructor(group, count) {
|
|
16
|
+
super();
|
|
17
|
+
this.count = count;
|
|
18
|
+
const { meshCollect, instanceCollect } = this;
|
|
19
|
+
group.updateMatrixWorld(true);
|
|
20
|
+
// collect all mesh counts, in case there are more than one copy of the same mesh in this group
|
|
21
|
+
group.traverse((obj) => {
|
|
22
|
+
const mesh = obj;
|
|
23
|
+
if (mesh.isMesh) {
|
|
24
|
+
mesh.matrixWorld.decompose(mesh.position, mesh.quaternion, mesh.scale);
|
|
25
|
+
mesh.rotation.setFromQuaternion(mesh.quaternion);
|
|
26
|
+
mesh.updateMatrix();
|
|
27
|
+
// same geometry and same material consider as the same mesh
|
|
28
|
+
const uuid = mesh.geometry.uuid + '/' + mesh.material.uuid;
|
|
29
|
+
if (meshCollect[uuid]) {
|
|
30
|
+
meshCollect[uuid].push(mesh);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
meshCollect[uuid] = [mesh];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
obj.position.set(0, 0, 0);
|
|
38
|
+
obj.scale.set(1, 1, 1);
|
|
39
|
+
obj.rotation.set(0, 0, 0);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
// create all instances
|
|
43
|
+
Object.keys(meshCollect).forEach(uuid => {
|
|
44
|
+
const meshes = meshCollect[uuid];
|
|
45
|
+
const mesh = meshes[0];
|
|
46
|
+
const instancedMesh = new THREE.InstancedMesh(mesh.geometry, mesh.material, meshes.length * count);
|
|
47
|
+
instanceCollect[uuid] = instancedMesh;
|
|
48
|
+
this.add(instancedMesh);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
setMatrixAt(index, matrix) {
|
|
52
|
+
Object.keys(this.meshCollect).forEach(uuid => {
|
|
53
|
+
const instancedMesh = this.instanceCollect[uuid];
|
|
54
|
+
const collect = this.meshCollect[uuid];
|
|
55
|
+
collect.forEach((mesh, i) => {
|
|
56
|
+
InstancedGroupMesh.matrix.copy(mesh.matrix);
|
|
57
|
+
InstancedGroupMesh.matrix.premultiply(matrix);
|
|
58
|
+
instancedMesh.setMatrixAt(collect.length * index + i, InstancedGroupMesh.matrix);
|
|
59
|
+
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,85 +1,54 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2023-02-16 00:22:31
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-02-16 00:22:31
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2023-02-16 19:08:55
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import { last } from "lodash";
|
|
9
|
-
import { BufferAttribute,
|
|
8
|
+
import { BufferAttribute, Line, LineBasicMaterial, Object3D } from "three";
|
|
10
9
|
import threeUtils from "./threeUtils";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// 关键帧类型
|
|
14
|
-
export type Keyframe = {
|
|
15
|
-
position: Vector3;
|
|
16
|
-
scale: Vector3;
|
|
17
|
-
rotation: Euler;
|
|
18
|
-
timeTemp: number; //时间节点 单位毫秒.
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export type KeyframeAnimationProps = {
|
|
23
|
-
speedScale?: number; // 速度调整
|
|
24
|
-
object3d: Object3D; // 需要移动的对象
|
|
25
|
-
keyframes: Array<Keyframe>,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
10
|
// 关键帧动画对象
|
|
29
11
|
export default class KeyframeAnimation extends Object3D {
|
|
30
|
-
|
|
31
|
-
constructor(props: KeyframeAnimationProps) {
|
|
12
|
+
constructor(props) {
|
|
32
13
|
super();
|
|
33
|
-
|
|
34
14
|
// 速度调整
|
|
35
15
|
this.speedScale = props.speedScale || 1;
|
|
36
|
-
|
|
37
16
|
// 设置关键帧对象数组
|
|
38
17
|
this.setKeyframes(props.keyframes);
|
|
39
|
-
|
|
40
|
-
|
|
41
18
|
// 设置对象
|
|
42
19
|
this.setObject3D(props.object3d);
|
|
43
|
-
|
|
44
20
|
}
|
|
45
|
-
|
|
46
21
|
// 速度调整
|
|
47
22
|
speedScale = 1;
|
|
48
|
-
|
|
49
23
|
// 需要需要移动的对象
|
|
50
|
-
object3d
|
|
51
|
-
|
|
24
|
+
object3d;
|
|
52
25
|
//路径辅助线
|
|
53
26
|
halperLine = new Line(undefined, new LineBasicMaterial({ color: "#f00" }));
|
|
54
|
-
|
|
55
27
|
// 关键帧数组
|
|
56
|
-
keyframes
|
|
57
|
-
|
|
28
|
+
keyframes = [];
|
|
58
29
|
// 设置需要移动的对象
|
|
59
|
-
setObject3D(object3d
|
|
30
|
+
setObject3D(object3d) {
|
|
60
31
|
this.object3d = object3d;
|
|
61
32
|
if (threeUtils.isDev) {
|
|
62
33
|
this.children = [object3d, this.halperLine];
|
|
63
|
-
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
64
36
|
this.children = [object3d];
|
|
65
37
|
}
|
|
66
38
|
}
|
|
67
|
-
|
|
68
39
|
// 获取单个关键帧
|
|
69
|
-
getKeyframe(i
|
|
40
|
+
getKeyframe(i) {
|
|
70
41
|
return this.keyframes[i];
|
|
71
42
|
}
|
|
72
|
-
|
|
73
43
|
// 设置单个关键帧
|
|
74
|
-
setKeyframe(i
|
|
44
|
+
setKeyframe(i, keyframe) {
|
|
75
45
|
this.keyframes[i] = keyframe;
|
|
76
46
|
this.setKeyframes(this.keyframes);
|
|
77
47
|
}
|
|
78
|
-
|
|
79
48
|
//设置全部关键帧
|
|
80
|
-
setKeyframes(keyframes
|
|
49
|
+
setKeyframes(keyframes) {
|
|
81
50
|
this.keyframes = keyframes;
|
|
82
|
-
const position
|
|
51
|
+
const position = [];
|
|
83
52
|
keyframes.map(k => {
|
|
84
53
|
position.push(k.position.x);
|
|
85
54
|
position.push(k.position.y);
|
|
@@ -87,36 +56,23 @@ export default class KeyframeAnimation extends Object3D {
|
|
|
87
56
|
});
|
|
88
57
|
this.halperLine.geometry.setAttribute("position", new BufferAttribute(new Float32Array(position), 3, false));
|
|
89
58
|
}
|
|
90
|
-
|
|
91
59
|
// 更具关键帧的信息更新 对象的位置
|
|
92
60
|
update() {
|
|
93
|
-
const {
|
|
94
|
-
const maxtimetemp = last(this.keyframes)
|
|
95
|
-
const currentTime =
|
|
96
|
-
|
|
61
|
+
const { _timeTemp } = threeUtils;
|
|
62
|
+
const maxtimetemp = last(this.keyframes).timeTemp;
|
|
63
|
+
const currentTime = _timeTemp % maxtimetemp;
|
|
97
64
|
const currentKeyframeIndex = this.keyframes.findIndex(k => currentTime < k.timeTemp);
|
|
98
|
-
|
|
99
65
|
const startKeyframe = this.keyframes[currentKeyframeIndex - 1];
|
|
100
66
|
const endKeyframe = this.keyframes[currentKeyframeIndex];
|
|
101
67
|
const progress = (currentTime - startKeyframe.timeTemp) / (endKeyframe.timeTemp - startKeyframe.timeTemp);
|
|
102
|
-
|
|
103
68
|
this.object3d.position.copy(endKeyframe.position).sub(startKeyframe.position).multiplyScalar(progress).add(startKeyframe.position);
|
|
104
69
|
this.object3d.scale.copy(endKeyframe.scale).sub(startKeyframe.scale).multiplyScalar(progress).add(startKeyframe.scale);
|
|
105
|
-
|
|
106
|
-
this.object3d.rotation.set(
|
|
107
|
-
(endKeyframe.rotation.x - startKeyframe.rotation.x) * progress + startKeyframe.rotation.x,
|
|
108
|
-
(endKeyframe.rotation.y - startKeyframe.rotation.y) * progress + startKeyframe.rotation.y,
|
|
109
|
-
(endKeyframe.rotation.z - startKeyframe.rotation.z) * progress + startKeyframe.rotation.z,
|
|
110
|
-
);
|
|
111
|
-
|
|
70
|
+
this.object3d.rotation.set((endKeyframe.rotation.x - startKeyframe.rotation.x) * progress + startKeyframe.rotation.x, (endKeyframe.rotation.y - startKeyframe.rotation.y) * progress + startKeyframe.rotation.y, (endKeyframe.rotation.z - startKeyframe.rotation.z) * progress + startKeyframe.rotation.z);
|
|
112
71
|
this.dispatchEvent({ type: "update" });
|
|
113
72
|
}
|
|
114
|
-
|
|
115
73
|
//更新关键帧的实例矩阵
|
|
116
|
-
updateMatrix()
|
|
74
|
+
updateMatrix() {
|
|
117
75
|
this.update();
|
|
118
76
|
super.updateMatrix();
|
|
119
77
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
78
|
+
}
|
|
@@ -1,59 +1,30 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2022-05-23 13:53:06
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-23 13:53:06
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2022-05-23 19:38:24
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import { DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, Vector3 } from "three";
|
|
9
8
|
import SpriteText from "three-spritetext";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type Props = {
|
|
14
|
-
text?: string;
|
|
15
|
-
textHeight?: number;
|
|
16
|
-
color?: string;
|
|
17
|
-
backgroundColor?: string;
|
|
18
|
-
fontFace?: string;
|
|
19
|
-
fontSize?: number;
|
|
20
|
-
fontWeight?: string;
|
|
21
|
-
padding?: number | [number, number];
|
|
22
|
-
borderWidth?: number;
|
|
23
|
-
borderRadius?: number;
|
|
24
|
-
borderColor?: string;
|
|
25
|
-
strokeWidth?: number;
|
|
26
|
-
strokeColor?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
9
|
export default class PlaneText extends Mesh {
|
|
30
|
-
|
|
31
|
-
constructor(text: string = "planeText") {
|
|
10
|
+
constructor(text = "planeText") {
|
|
32
11
|
super(PlaneText.geometry);
|
|
33
12
|
this.set({ text });
|
|
34
13
|
}
|
|
35
|
-
|
|
36
14
|
type = "PlaneText";
|
|
37
|
-
|
|
38
15
|
static geometry = new PlaneGeometry(1, 1, 1, 1);
|
|
39
|
-
|
|
40
16
|
spriteText = new SpriteText("");
|
|
41
|
-
|
|
42
17
|
material = new MeshBasicMaterial({ transparent: true, side: DoubleSide, map: this.spriteText.material.map });
|
|
43
|
-
|
|
44
|
-
set(parame: Props) {
|
|
18
|
+
set(parame) {
|
|
45
19
|
for (let key in parame) {
|
|
46
20
|
//@ts-ignore
|
|
47
21
|
this.spriteText[key] = parame[key];
|
|
48
22
|
}
|
|
49
|
-
|
|
50
23
|
this.scale.copy(this.spriteText.scale);
|
|
51
24
|
this.scale.max(new Vector3(1, 1, 1));
|
|
52
25
|
this.material.map = this.spriteText.material.map;
|
|
53
26
|
}
|
|
54
|
-
|
|
55
|
-
get(prop: keyof SpriteText) {
|
|
27
|
+
get(prop) {
|
|
56
28
|
return this.spriteText[prop];
|
|
57
29
|
}
|
|
58
|
-
|
|
59
30
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2022-05-18 16:02:55
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-18 16:02:55
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2022-06-23 21:02:45
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import { Mesh, MeshBasicMaterial, PointLight as THREEPointLight, SphereGeometry } from "three";
|
|
9
8
|
import threeSpritetext from "three-spritetext";
|
|
10
9
|
import threeUtils from "./threeUtils";
|
|
11
|
-
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* 点光源
|
|
15
12
|
* @export
|
|
@@ -17,21 +14,16 @@ import threeUtils from "./threeUtils";
|
|
|
17
14
|
* @extends {THREEPointLight}
|
|
18
15
|
*/
|
|
19
16
|
export default class PointLight extends THREEPointLight {
|
|
20
|
-
|
|
21
|
-
constructor(color = "#fff", intensity?: number, distance?: number, decay?: number) {
|
|
17
|
+
constructor(color = "#fff", intensity, distance, decay) {
|
|
22
18
|
super(color, intensity, distance, decay);
|
|
23
|
-
|
|
24
19
|
if (threeUtils.isDev) {
|
|
25
20
|
if (this.label) {
|
|
26
21
|
this.label.borderColor = color;
|
|
27
22
|
this.label.color = color;
|
|
28
23
|
this.label.scale.multiplyScalar(0.03);
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
sphere = threeUtils.isDev && (() => {
|
|
36
28
|
// 点光源辅助小球
|
|
37
29
|
const sphere = new SphereGeometry(0.1, 10, 10);
|
|
@@ -40,26 +32,21 @@ export default class PointLight extends THREEPointLight {
|
|
|
40
32
|
wireframe: true
|
|
41
33
|
});
|
|
42
34
|
const mesh = new Mesh(sphere, materils);
|
|
43
|
-
|
|
44
35
|
mesh.userData = {
|
|
45
36
|
cursor: "pointer"
|
|
46
37
|
};
|
|
47
|
-
|
|
48
38
|
mesh.addEventListener("mouseenter", () => {
|
|
49
39
|
if (this.label) {
|
|
50
40
|
this.label.visible = true;
|
|
51
41
|
}
|
|
52
42
|
});
|
|
53
|
-
|
|
54
43
|
mesh.addEventListener("mouseleave", () => {
|
|
55
44
|
if (this.label) {
|
|
56
45
|
this.label.visible = false;
|
|
57
46
|
}
|
|
58
47
|
});
|
|
59
|
-
|
|
60
48
|
this.add(mesh);
|
|
61
49
|
})();
|
|
62
|
-
|
|
63
50
|
label = threeUtils.isDev && (() => {
|
|
64
51
|
const label = new threeSpritetext("点光源");
|
|
65
52
|
label.renderOrder = Infinity;
|
|
@@ -74,5 +61,4 @@ export default class PointLight extends THREEPointLight {
|
|
|
74
61
|
this.add(label);
|
|
75
62
|
return label;
|
|
76
63
|
})();
|
|
77
|
-
|
|
78
|
-
}
|
|
64
|
+
}
|
|
@@ -1,36 +1,28 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2022-05-20 18:03:58
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-20 18:03:58
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2022-12-27 09:54:23
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import { DoubleSide, Mesh, MeshBasicMaterial, SphereGeometry } from "three";
|
|
9
8
|
import threeLoader from "../threeLoader";
|
|
10
|
-
|
|
11
9
|
import blueskyJPG from "./blueSky.jpg";
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* 天空球
|
|
15
12
|
*/
|
|
16
13
|
export default class Sky extends Mesh {
|
|
17
|
-
|
|
18
14
|
constructor() {
|
|
19
15
|
super(Sky.geometry);
|
|
20
16
|
}
|
|
21
|
-
|
|
22
17
|
static geometry = new SphereGeometry(500000, 100, 100);
|
|
23
|
-
|
|
24
18
|
material = new MeshBasicMaterial({
|
|
25
19
|
side: DoubleSide,
|
|
26
20
|
map: threeLoader.getTexture(blueskyJPG)
|
|
27
21
|
});
|
|
28
|
-
|
|
29
22
|
/**
|
|
30
23
|
*设置贴图
|
|
31
24
|
*/
|
|
32
|
-
setMap(src
|
|
25
|
+
setMap(src) {
|
|
33
26
|
this.material.map = threeLoader.getTexture(src);
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-06-14 09:48:00
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-04-04 19:26:36
|
|
6
|
+
*/
|
|
7
|
+
import { Mesh, MeshStandardMaterial, TextGeometry } from "three";
|
|
8
|
+
import fontContorller from "./fontController";
|
|
9
|
+
// 3D文字模型
|
|
10
|
+
export default class Text3D extends Mesh {
|
|
11
|
+
constructor(text = "new Text3D()") {
|
|
12
|
+
super();
|
|
13
|
+
this.setText({ text });
|
|
14
|
+
}
|
|
15
|
+
// 字体的存储路径 例如 : "http://drm.gitee.io/three-base-font/simhei/字.js"
|
|
16
|
+
static path = "http://drm.gitee.io/three-base-font/";
|
|
17
|
+
material = new MeshStandardMaterial({
|
|
18
|
+
metalness: 0.8,
|
|
19
|
+
roughness: 0.5, // 粗糙度,值为0到1
|
|
20
|
+
});
|
|
21
|
+
// 配置
|
|
22
|
+
_config = {
|
|
23
|
+
text: "",
|
|
24
|
+
fontType: "simhei",
|
|
25
|
+
size: 1,
|
|
26
|
+
curveSegments: 10,
|
|
27
|
+
height: 0.1,
|
|
28
|
+
bevelEnabled: true,
|
|
29
|
+
bevelThickness: 0.02,
|
|
30
|
+
bevelSize: 0.015,
|
|
31
|
+
bevelOffset: 0,
|
|
32
|
+
bevelSegments: 3, //斜角分段
|
|
33
|
+
};
|
|
34
|
+
// 设置文字
|
|
35
|
+
setText(text3DProps) {
|
|
36
|
+
if (Object.keys(text3DProps).some(key => text3DProps[key] !== this._config[key])) {
|
|
37
|
+
Object.assign(this._config, text3DProps);
|
|
38
|
+
fontContorller.loadText({
|
|
39
|
+
fontBasePath: Text3D.path,
|
|
40
|
+
text: this._config.text,
|
|
41
|
+
fontType: this._config.fontType,
|
|
42
|
+
callback: THREEFont => {
|
|
43
|
+
this.geometry.dispose();
|
|
44
|
+
this.geometry = new TextGeometry(this._config.text, {
|
|
45
|
+
font: THREEFont,
|
|
46
|
+
size: this._config.size,
|
|
47
|
+
curveSegments: this._config.curveSegments,
|
|
48
|
+
height: this._config.height,
|
|
49
|
+
bevelEnabled: this._config.bevelEnabled,
|
|
50
|
+
bevelThickness: this._config.bevelThickness,
|
|
51
|
+
bevelSize: this._config.bevelSize,
|
|
52
|
+
bevelOffset: this._config.bevelOffset,
|
|
53
|
+
bevelSegments: this._config.bevelSegments, //斜角分段
|
|
54
|
+
});
|
|
55
|
+
this.geometry.center();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|