three-base 2.0.75 → 2.0.77
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/ApngTexture.d.ts +13 -13
- package/ApngTexture.js +61 -61
- package/ApngTextureManage.d.ts +18 -18
- package/ApngTextureManage.js +87 -87
- package/EventMesh.d.ts +18 -18
- package/EventMesh.js +59 -59
- package/ExtrudeMesh.d.ts +111 -111
- package/ExtrudeMesh.js +363 -363
- package/FPScontrol.d.ts +45 -45
- package/FPScontrol.js +171 -171
- package/Fire/Fire.d.ts +28 -28
- package/Fire/Fire.js +79 -79
- package/Fire/FireGromtry.d.ts +9 -9
- package/Fire/FireGromtry.js +40 -40
- package/Fire/FireMaterial.d.ts +28 -28
- package/Fire/FireMaterial.js +32 -32
- package/InstancedMeshBase.d.ts +32 -32
- package/InstancedMeshBase.js +229 -236
- package/InstancedMeshBase.ts +12 -22
- package/KeyFrameAnimation.d.ts +25 -25
- package/KeyFrameAnimation.js +78 -78
- package/MeshBase.d.ts +34 -34
- package/MeshBase.js +187 -187
- package/Mirror.d.ts +25 -25
- package/Mirror.js +139 -139
- package/PlaneModal1/PlaneModal1.d.ts +31 -31
- package/PlaneModal1/PlaneModal1.js +105 -105
- package/PlaneModal1/index.d.ts +1 -1
- package/PlaneModal1/index.js +1 -1
- package/PlaneText.d.ts +44 -44
- package/PlaneText.js +30 -30
- package/PlaneWithHtml.d.ts +11 -11
- package/PlaneWithHtml.js +68 -68
- package/PointLight/PointLight.d.ts +13 -13
- package/PointLight/PointLight.js +64 -64
- package/PointLight/index.d.ts +1 -1
- package/PointLight/index.js +1 -1
- package/Sky/Sky.d.ts +13 -13
- package/Sky/Sky.js +28 -28
- package/Sky/index.d.ts +1 -1
- package/Sky/index.js +1 -1
- package/SpriteModal1/SpriteModal1.d.ts +30 -30
- package/SpriteModal1/SpriteModal1.js +110 -110
- package/SpriteModal1/index.d.ts +1 -1
- package/SpriteModal1/index.js +1 -1
- package/SpriteText.d.ts +45 -45
- package/SpriteText.js +163 -163
- package/SpriteText2.d.ts +47 -47
- package/SpriteText2.js +198 -198
- package/SpriteWithHtml.d.ts +7 -7
- package/SpriteWithHtml.js +49 -49
- package/Text3D/Text3D.d.ts +20 -20
- package/Text3D/Text3D.js +62 -62
- package/Text3D/fontController.d.ts +59 -59
- package/Text3D/fontController.js +200 -200
- package/Text3D/index.d.ts +1 -1
- package/Text3D/index.js +1 -1
- package/ThreeBase.d.ts +92 -92
- package/ThreeBase.js +619 -619
- package/ThreeMouse.d.ts +39 -39
- package/ThreeMouse.js +359 -359
- package/Transition.d.ts +40 -40
- package/Transition.js +207 -207
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/keyContorls.d.ts +25 -25
- package/keyContorls.js +98 -98
- package/package.json +1 -1
- package/pass/FullScreenQuad.d.ts +7 -7
- package/pass/FullScreenQuad.js +25 -25
- package/pass/glow_pass.d.ts +2 -2
- package/pass/glow_pass.js +236 -236
- package/pass/stroke_pass.d.ts +2 -2
- package/pass/stroke_pass.js +202 -202
- package/shaders/FXAAShaderMaterial.d.ts +3 -3
- package/shaders/FXAAShaderMaterial.js +21 -21
- package/shaders.d.ts +17 -17
- package/shaders.js +99 -99
- package/threeLoader.d.ts +26 -26
- package/threeLoader.js +189 -189
- package/threeUtils.d.ts +47 -47
- package/threeUtils.js +266 -266
package/InstancedMeshBase.js
CHANGED
|
@@ -1,236 +1,229 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2024-02-05 09:31:57
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2024-06-07 22:14:53
|
|
6
|
-
*/
|
|
7
|
-
import { throttle } from "lodash";
|
|
8
|
-
import { Euler, InstancedBufferAttribute, InstancedMesh, Matrix4, Quaternion, Vector3 } from "three";
|
|
9
|
-
import MeshBase from "./MeshBase";
|
|
10
|
-
import threeUtils from "./threeUtils";
|
|
11
|
-
import threeLoader from "./threeLoader";
|
|
12
|
-
// 实例模型组对象
|
|
13
|
-
export default class InstancedMeshBase extends MeshBase {
|
|
14
|
-
constructor(url) {
|
|
15
|
-
super(url);
|
|
16
|
-
}
|
|
17
|
-
isInstancedGroupMesh = true;
|
|
18
|
-
count = 0;
|
|
19
|
-
size = new Vector3(1, 1, 1);
|
|
20
|
-
meshCollect = {};
|
|
21
|
-
instanceCollect = {};
|
|
22
|
-
colorMap = new Map();
|
|
23
|
-
static _position = new Vector3();
|
|
24
|
-
static _scale = new Vector3(1, 1, 1);
|
|
25
|
-
static _rotation = new Euler();
|
|
26
|
-
static _Quaternion = new Quaternion();
|
|
27
|
-
static _matrix = new Matrix4();
|
|
28
|
-
instanceMatrix = new InstancedBufferAttribute(new Float32Array(0 * 16), 16);
|
|
29
|
-
instanceColor = new InstancedBufferAttribute(new Float32Array(0 * 3), 3);
|
|
30
|
-
// 重构加载模型的方法
|
|
31
|
-
async loadModel(url, filename = "") {
|
|
32
|
-
this.url = url;
|
|
33
|
-
if (!url) {
|
|
34
|
-
this.clear();
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
this.loaded = false;
|
|
38
|
-
// 没有模型并且没有加载任务时就去加载模型
|
|
39
|
-
if (!MeshBase.models.get(url) && !MeshBase.loadModeling.get(url)) {
|
|
40
|
-
MeshBase.loadModeling.set(url, true);
|
|
41
|
-
// 万能加载器
|
|
42
|
-
let modal = await threeLoader.loadModel(url, filename);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
// this.add(
|
|
67
|
-
// }
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
mesh.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
mesh.
|
|
78
|
-
mesh
|
|
79
|
-
mesh.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
obj.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
instancedMesh
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// 加载完成事件
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.
|
|
135
|
-
this.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
instanceMesh.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
InstancedMeshBase._matrix.
|
|
183
|
-
InstancedMeshBase._matrix.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
super.
|
|
225
|
-
this.children.map(mesh => {
|
|
226
|
-
mesh.
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
removeEventListener(name, callback) {
|
|
231
|
-
super.removeEventListener(name, callback);
|
|
232
|
-
this.children.map(mesh => {
|
|
233
|
-
mesh.removeEventListener(name, callback);
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2024-02-05 09:31:57
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2024-06-07 22:14:53
|
|
6
|
+
*/
|
|
7
|
+
import { throttle } from "lodash";
|
|
8
|
+
import { Euler, InstancedBufferAttribute, InstancedMesh, Matrix4, Quaternion, Vector3 } from "three";
|
|
9
|
+
import MeshBase from "./MeshBase";
|
|
10
|
+
import threeUtils from "./threeUtils";
|
|
11
|
+
import threeLoader from "./threeLoader";
|
|
12
|
+
// 实例模型组对象
|
|
13
|
+
export default class InstancedMeshBase extends MeshBase {
|
|
14
|
+
constructor(url) {
|
|
15
|
+
super(url);
|
|
16
|
+
}
|
|
17
|
+
isInstancedGroupMesh = true;
|
|
18
|
+
count = 0;
|
|
19
|
+
size = new Vector3(1, 1, 1);
|
|
20
|
+
meshCollect = {};
|
|
21
|
+
instanceCollect = {};
|
|
22
|
+
colorMap = new Map();
|
|
23
|
+
static _position = new Vector3();
|
|
24
|
+
static _scale = new Vector3(1, 1, 1);
|
|
25
|
+
static _rotation = new Euler();
|
|
26
|
+
static _Quaternion = new Quaternion();
|
|
27
|
+
static _matrix = new Matrix4();
|
|
28
|
+
instanceMatrix = new InstancedBufferAttribute(new Float32Array(0 * 16), 16);
|
|
29
|
+
instanceColor = new InstancedBufferAttribute(new Float32Array(0 * 3), 3);
|
|
30
|
+
// 重构加载模型的方法
|
|
31
|
+
async loadModel(url, filename = "") {
|
|
32
|
+
this.url = url;
|
|
33
|
+
if (!url) {
|
|
34
|
+
this.clear();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.loaded = false;
|
|
38
|
+
// 没有模型并且没有加载任务时就去加载模型
|
|
39
|
+
if (!MeshBase.models.get(url) && !MeshBase.loadModeling.get(url)) {
|
|
40
|
+
MeshBase.loadModeling.set(url, true);
|
|
41
|
+
// 万能加载器
|
|
42
|
+
let modal = await threeLoader.loadModel(url, filename);
|
|
43
|
+
MeshBase.models.set(url, modal);
|
|
44
|
+
MeshBase.loadModeling.set(url, false);
|
|
45
|
+
}
|
|
46
|
+
// 如果模型还在加载中, 就等待模型加载完成
|
|
47
|
+
do {
|
|
48
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
49
|
+
} while (MeshBase.loadModeling.get(url));
|
|
50
|
+
if (MeshBase.models.get(url)) {
|
|
51
|
+
this.clear();
|
|
52
|
+
const mesh = MeshBase.models.get(url);
|
|
53
|
+
// // 判断是否有动画
|
|
54
|
+
// this.hasAnimation = mesh.animations.length > 0;
|
|
55
|
+
// if (this.hasAnimation) {
|
|
56
|
+
// const model = SkeletonUtils.clone(mesh);
|
|
57
|
+
// this.mixer = new AnimationMixer(model);
|
|
58
|
+
// this.animationActions = {};
|
|
59
|
+
// mesh.animations.map(animation => {
|
|
60
|
+
// const animationAction = this.mixer!.clipAction(animation).play();
|
|
61
|
+
// animationAction.weight = 0;
|
|
62
|
+
// this.animationActions[animation.name] = animationAction;
|
|
63
|
+
// });
|
|
64
|
+
// this.add(model);
|
|
65
|
+
// } else {
|
|
66
|
+
// this.add(mesh.clone(true));
|
|
67
|
+
// }
|
|
68
|
+
this.size.copy(threeUtils.getSize(mesh));
|
|
69
|
+
const { meshCollect, instanceCollect } = this;
|
|
70
|
+
mesh.updateMatrixWorld(true);
|
|
71
|
+
// collect all mesh counts, in case there are more than one copy of the same mesh in this group
|
|
72
|
+
mesh.traverse((obj) => {
|
|
73
|
+
const mesh = obj;
|
|
74
|
+
if (mesh.isMesh) {
|
|
75
|
+
mesh.matrixWorld.decompose(mesh.position, mesh.quaternion, mesh.scale);
|
|
76
|
+
mesh.rotation.setFromQuaternion(mesh.quaternion);
|
|
77
|
+
mesh.updateMatrix();
|
|
78
|
+
// same geometry and same material consider as the same mesh
|
|
79
|
+
const uuid = mesh.geometry.uuid + '/' + mesh.material.uuid;
|
|
80
|
+
if (meshCollect[uuid]) {
|
|
81
|
+
meshCollect[uuid].push(mesh);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
meshCollect[uuid] = [mesh];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
obj.position.set(0, 0, 0);
|
|
89
|
+
obj.scale.set(1, 1, 1);
|
|
90
|
+
obj.rotation.set(0, 0, 0);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// create all instances
|
|
94
|
+
Object.keys(meshCollect).forEach(uuid => {
|
|
95
|
+
const meshes = meshCollect[uuid];
|
|
96
|
+
const mesh = meshes[0];
|
|
97
|
+
const instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, meshes.length * this.count);
|
|
98
|
+
instancedMesh.name = mesh.name;
|
|
99
|
+
instancedMesh.frustumCulled = false;
|
|
100
|
+
instanceCollect[uuid] = instancedMesh;
|
|
101
|
+
this.add(instancedMesh);
|
|
102
|
+
});
|
|
103
|
+
// 加载完成事件
|
|
104
|
+
await new Promise(resolve => setTimeout(resolve, 30));
|
|
105
|
+
// 加载完成事件
|
|
106
|
+
this.loaded = true;
|
|
107
|
+
this.dispatchEvent({ type: "loaded" });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// 更新包围盒
|
|
111
|
+
computeBoundingSphere = throttle(() => {
|
|
112
|
+
this.children.map(instancedMesh => {
|
|
113
|
+
instancedMesh.computeBoundingSphere();
|
|
114
|
+
});
|
|
115
|
+
}, 1000);
|
|
116
|
+
//初始实例矩阵的数量
|
|
117
|
+
async setCount(count = 0) {
|
|
118
|
+
if (this.count === count) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
await this.awaitLoaded();
|
|
122
|
+
const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
|
|
123
|
+
const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
|
|
124
|
+
for (let i = 0; i < count; i++) {
|
|
125
|
+
instanceMatrix.set(InstancedMeshBase._matrix.identity().toArray(), i * 16);
|
|
126
|
+
instanceColor.set([1, 1, 1], i * 3);
|
|
127
|
+
}
|
|
128
|
+
for (let i = 0; i < this.count; i++) {
|
|
129
|
+
instanceMatrix.copyAt(i, this.instanceMatrix, i);
|
|
130
|
+
instanceColor.copyAt(i, this.instanceColor, i);
|
|
131
|
+
}
|
|
132
|
+
this.instanceMatrix = instanceMatrix;
|
|
133
|
+
this.instanceColor = instanceColor;
|
|
134
|
+
this.count = count;
|
|
135
|
+
this.children.map((instanceMesh) => {
|
|
136
|
+
const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
|
|
137
|
+
const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
|
|
138
|
+
for (let i = 0; i < count; i++) {
|
|
139
|
+
instanceMatrix.set(InstancedMeshBase._matrix.identity().toArray(), i * 16);
|
|
140
|
+
instanceColor.set([1, 1, 1], i * 3);
|
|
141
|
+
}
|
|
142
|
+
for (let i = 0; i < instanceMesh.count; i++) {
|
|
143
|
+
instanceMatrix.copyAt(i, instanceMesh.instanceMatrix, i);
|
|
144
|
+
instanceColor.copyAt(i, instanceMesh.instanceColor, i);
|
|
145
|
+
}
|
|
146
|
+
instanceMesh.instanceMatrix = instanceMatrix;
|
|
147
|
+
instanceMesh.instanceColor = instanceColor;
|
|
148
|
+
instanceMesh.count = count;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// 设置矩阵
|
|
152
|
+
async setMatrixAt(index, matrix = new Matrix4().identity()) {
|
|
153
|
+
await this.awaitLoaded();
|
|
154
|
+
Object.keys(this.meshCollect).forEach(uuid => {
|
|
155
|
+
const instancedMesh = this.instanceCollect[uuid];
|
|
156
|
+
const collect = this.meshCollect[uuid];
|
|
157
|
+
collect.forEach((mesh, i) => {
|
|
158
|
+
InstancedMeshBase._matrix.copy(mesh.matrix);
|
|
159
|
+
InstancedMeshBase._matrix.premultiply(matrix);
|
|
160
|
+
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
161
|
+
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
this.computeBoundingSphere();
|
|
165
|
+
}
|
|
166
|
+
//设置移动旋转缩放
|
|
167
|
+
async setTRS(index, { position, rotation, scale }) {
|
|
168
|
+
await this.awaitLoaded();
|
|
169
|
+
Object.keys(this.meshCollect).forEach(uuid => {
|
|
170
|
+
const instancedMesh = this.instanceCollect[uuid];
|
|
171
|
+
const collect = this.meshCollect[uuid];
|
|
172
|
+
collect.forEach((mesh, i) => {
|
|
173
|
+
//获取对应的模型的矩阵
|
|
174
|
+
instancedMesh.getMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
175
|
+
InstancedMeshBase._matrix.premultiply(mesh.matrix.clone().invert());
|
|
176
|
+
InstancedMeshBase._matrix.decompose(InstancedMeshBase._position, InstancedMeshBase._Quaternion, InstancedMeshBase._scale);
|
|
177
|
+
InstancedMeshBase._rotation.setFromQuaternion(InstancedMeshBase._Quaternion);
|
|
178
|
+
position && InstancedMeshBase._position.copy(position);
|
|
179
|
+
rotation && InstancedMeshBase._rotation.copy(rotation);
|
|
180
|
+
scale && InstancedMeshBase._scale.copy(scale);
|
|
181
|
+
InstancedMeshBase._Quaternion.setFromEuler(InstancedMeshBase._rotation);
|
|
182
|
+
InstancedMeshBase._matrix.compose(InstancedMeshBase._position, InstancedMeshBase._Quaternion, InstancedMeshBase._scale);
|
|
183
|
+
InstancedMeshBase._matrix.premultiply(mesh.matrix);
|
|
184
|
+
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
185
|
+
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
this.computeBoundingSphere();
|
|
189
|
+
}
|
|
190
|
+
// 设置颜色
|
|
191
|
+
async setColorAt(index, color) {
|
|
192
|
+
await this.awaitLoaded();
|
|
193
|
+
Object.keys(this.meshCollect).forEach(uuid => {
|
|
194
|
+
const instancedMesh = this.instanceCollect[uuid];
|
|
195
|
+
const collect = this.meshCollect[uuid];
|
|
196
|
+
collect.forEach((mesh, i) => {
|
|
197
|
+
const c = color(instancedMesh);
|
|
198
|
+
if (c) {
|
|
199
|
+
instancedMesh.setColorAt(collect.length * index + i, c);
|
|
200
|
+
instancedMesh.instanceColor.needsUpdate = true;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// 同步属性
|
|
206
|
+
updateMatrixWorld(force) {
|
|
207
|
+
super.updateMatrixWorld(force);
|
|
208
|
+
const { cursor, enableEvent } = this.userData;
|
|
209
|
+
this.traverse(obj => {
|
|
210
|
+
Object.assign(obj.userData, { cursor, enableEvent });
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
// 事件监听
|
|
214
|
+
async addEventListener(name, callback) {
|
|
215
|
+
super.addEventListener(name, callback);
|
|
216
|
+
await this.awaitLoaded();
|
|
217
|
+
super.addEventListener(name, callback);
|
|
218
|
+
this.children.map(mesh => {
|
|
219
|
+
mesh.addEventListener(name, callback);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
// 取消事件的监听
|
|
223
|
+
removeEventListener(name, callback) {
|
|
224
|
+
super.removeEventListener(name, callback);
|
|
225
|
+
this.children.map(mesh => {
|
|
226
|
+
mesh.removeEventListener(name, callback);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
package/InstancedMeshBase.ts
CHANGED
|
@@ -59,9 +59,6 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
59
59
|
// 万能加载器
|
|
60
60
|
let modal = await threeLoader.loadModel(url, filename);
|
|
61
61
|
|
|
62
|
-
threeUtils.center(modal);
|
|
63
|
-
modal.updateMatrixWorld(true);
|
|
64
|
-
|
|
65
62
|
MeshBase.models.set(url, modal);
|
|
66
63
|
MeshBase.loadModeling.set(url, false);
|
|
67
64
|
}
|
|
@@ -139,8 +136,8 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
139
136
|
// 加载完成事件
|
|
140
137
|
await new Promise(resolve => setTimeout(resolve, 30));
|
|
141
138
|
// 加载完成事件
|
|
142
|
-
this.dispatchEvent({ type: "loaded" } as never);
|
|
143
139
|
this.loaded = true;
|
|
140
|
+
this.dispatchEvent({ type: "loaded" } as never);
|
|
144
141
|
}
|
|
145
142
|
|
|
146
143
|
}
|
|
@@ -178,7 +175,6 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
178
175
|
this.count = count;
|
|
179
176
|
|
|
180
177
|
this.children.map((instanceMesh: InstancedMesh) => {
|
|
181
|
-
|
|
182
178
|
const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
|
|
183
179
|
const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
|
|
184
180
|
|
|
@@ -200,15 +196,14 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
200
196
|
}
|
|
201
197
|
|
|
202
198
|
// 设置矩阵
|
|
203
|
-
async setMatrixAt(index: number, matrix: Matrix4) {
|
|
204
|
-
const new_matrix = matrix.clone();
|
|
199
|
+
async setMatrixAt(index: number, matrix: Matrix4 = new Matrix4().identity()) {
|
|
205
200
|
await this.awaitLoaded();
|
|
206
201
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
207
|
-
const instancedMesh = this.instanceCollect[uuid]
|
|
202
|
+
const instancedMesh = this.instanceCollect[uuid];
|
|
208
203
|
const collect = this.meshCollect[uuid]
|
|
209
204
|
collect.forEach((mesh: Mesh, i: number) => {
|
|
210
|
-
InstancedMeshBase._matrix.copy(mesh.matrix)
|
|
211
|
-
InstancedMeshBase._matrix.premultiply(
|
|
205
|
+
InstancedMeshBase._matrix.copy(mesh.matrix);
|
|
206
|
+
InstancedMeshBase._matrix.premultiply(matrix);
|
|
212
207
|
|
|
213
208
|
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
214
209
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
@@ -222,20 +217,17 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
222
217
|
async setTRS(
|
|
223
218
|
index: number,
|
|
224
219
|
{
|
|
225
|
-
position
|
|
226
|
-
rotation
|
|
227
|
-
scale
|
|
220
|
+
position,
|
|
221
|
+
rotation,
|
|
222
|
+
scale
|
|
228
223
|
}: {
|
|
229
224
|
position?: Vector3;
|
|
230
225
|
rotation?: Euler;
|
|
231
226
|
scale?: Vector3
|
|
232
227
|
}
|
|
233
228
|
) {
|
|
234
|
-
const new_position = position.clone();
|
|
235
|
-
const new_rotation = rotation.clone();
|
|
236
|
-
const new_scale = scale.clone();
|
|
237
229
|
await this.awaitLoaded();
|
|
238
|
-
|
|
230
|
+
|
|
239
231
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
240
232
|
const instancedMesh = this.instanceCollect[uuid]
|
|
241
233
|
const collect = this.meshCollect[uuid]
|
|
@@ -243,7 +235,6 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
243
235
|
|
|
244
236
|
//获取对应的模型的矩阵
|
|
245
237
|
instancedMesh.getMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
246
|
-
|
|
247
238
|
InstancedMeshBase._matrix.premultiply(mesh.matrix.clone().invert());
|
|
248
239
|
|
|
249
240
|
InstancedMeshBase._matrix.decompose(
|
|
@@ -252,9 +243,9 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
252
243
|
InstancedMeshBase._scale
|
|
253
244
|
);
|
|
254
245
|
InstancedMeshBase._rotation.setFromQuaternion(InstancedMeshBase._Quaternion);
|
|
255
|
-
InstancedMeshBase._position.copy(
|
|
256
|
-
InstancedMeshBase._rotation.copy(
|
|
257
|
-
InstancedMeshBase._scale.copy(
|
|
246
|
+
position && InstancedMeshBase._position.copy(position);
|
|
247
|
+
rotation && InstancedMeshBase._rotation.copy(rotation);
|
|
248
|
+
scale && InstancedMeshBase._scale.copy(scale);
|
|
258
249
|
InstancedMeshBase._Quaternion.setFromEuler(InstancedMeshBase._rotation);
|
|
259
250
|
|
|
260
251
|
InstancedMeshBase._matrix.compose(
|
|
@@ -264,7 +255,6 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
264
255
|
);
|
|
265
256
|
|
|
266
257
|
InstancedMeshBase._matrix.premultiply(mesh.matrix);
|
|
267
|
-
|
|
268
258
|
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
269
259
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
270
260
|
})
|
package/KeyFrameAnimation.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { Euler, Line, LineBasicMaterial, Object3D, Vector3 } from "three";
|
|
2
|
-
export type Keyframe = {
|
|
3
|
-
position: Vector3;
|
|
4
|
-
scale: Vector3;
|
|
5
|
-
rotation: Euler;
|
|
6
|
-
timeTemp: number;
|
|
7
|
-
};
|
|
8
|
-
export type KeyframeAnimationProps = {
|
|
9
|
-
speedScale?: number;
|
|
10
|
-
object3d: Object3D;
|
|
11
|
-
keyframes: Array<Keyframe>;
|
|
12
|
-
};
|
|
13
|
-
export default class KeyframeAnimation extends Object3D {
|
|
14
|
-
constructor(props: KeyframeAnimationProps);
|
|
15
|
-
speedScale: number;
|
|
16
|
-
object3d: Object3D;
|
|
17
|
-
halperLine: Line<any, LineBasicMaterial>;
|
|
18
|
-
keyframes: Array<Keyframe>;
|
|
19
|
-
setObject3D(object3d: Object3D): void;
|
|
20
|
-
getKeyframe(i: number): Keyframe;
|
|
21
|
-
setKeyframe(i: number, keyframe: Keyframe): void;
|
|
22
|
-
setKeyframes(keyframes: Array<Keyframe>): void;
|
|
23
|
-
update(): void;
|
|
24
|
-
updateMatrix(): void;
|
|
25
|
-
}
|
|
1
|
+
import { Euler, Line, LineBasicMaterial, Object3D, Vector3 } from "three";
|
|
2
|
+
export type Keyframe = {
|
|
3
|
+
position: Vector3;
|
|
4
|
+
scale: Vector3;
|
|
5
|
+
rotation: Euler;
|
|
6
|
+
timeTemp: number;
|
|
7
|
+
};
|
|
8
|
+
export type KeyframeAnimationProps = {
|
|
9
|
+
speedScale?: number;
|
|
10
|
+
object3d: Object3D;
|
|
11
|
+
keyframes: Array<Keyframe>;
|
|
12
|
+
};
|
|
13
|
+
export default class KeyframeAnimation extends Object3D {
|
|
14
|
+
constructor(props: KeyframeAnimationProps);
|
|
15
|
+
speedScale: number;
|
|
16
|
+
object3d: Object3D;
|
|
17
|
+
halperLine: Line<any, LineBasicMaterial>;
|
|
18
|
+
keyframes: Array<Keyframe>;
|
|
19
|
+
setObject3D(object3d: Object3D): void;
|
|
20
|
+
getKeyframe(i: number): Keyframe;
|
|
21
|
+
setKeyframe(i: number, keyframe: Keyframe): void;
|
|
22
|
+
setKeyframes(keyframes: Array<Keyframe>): void;
|
|
23
|
+
update(): void;
|
|
24
|
+
updateMatrix(): void;
|
|
25
|
+
}
|