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