three-base 2.0.72 → 2.0.73
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/InstancedMeshBase.d.ts +1 -1
- package/InstancedMeshBase.js +14 -10
- package/InstancedMeshBase.ts +15 -10
- package/ThreeBase.d.ts +1 -0
- package/ThreeBase.js +14 -6
- package/ThreeBase.ts +15 -6
- package/package.json +1 -1
package/InstancedMeshBase.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
13
13
|
static _scale: Vector3;
|
|
14
14
|
static _rotation: Euler;
|
|
15
15
|
static _Quaternion: Quaternion;
|
|
16
|
-
static
|
|
16
|
+
static _matrix: Matrix4;
|
|
17
17
|
instanceMatrix: InstancedBufferAttribute;
|
|
18
18
|
instanceColor: InstancedBufferAttribute;
|
|
19
19
|
loadModel(url: string, filename?: string): Promise<void>;
|
package/InstancedMeshBase.js
CHANGED
|
@@ -24,7 +24,7 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
24
24
|
static _scale = new Vector3(1, 1, 1);
|
|
25
25
|
static _rotation = new Euler();
|
|
26
26
|
static _Quaternion = new Quaternion();
|
|
27
|
-
static
|
|
27
|
+
static _matrix = new Matrix4();
|
|
28
28
|
instanceMatrix = new InstancedBufferAttribute(new Float32Array(0 * 16), 16);
|
|
29
29
|
instanceColor = new InstancedBufferAttribute(new Float32Array(0 * 3), 3);
|
|
30
30
|
// 重构加载模型的方法
|
|
@@ -120,6 +120,10 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
120
120
|
await this.awaitLoaded();
|
|
121
121
|
const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
|
|
122
122
|
const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
|
|
123
|
+
for (let i = 0; i < count; i++) {
|
|
124
|
+
instanceMatrix.set(InstancedMeshBase._matrix.identity().toArray(), i);
|
|
125
|
+
instanceColor.set([1, 1, 1], i);
|
|
126
|
+
}
|
|
123
127
|
for (let i = 0; i < this.count; i++) {
|
|
124
128
|
instanceMatrix.copyAt(i, this.instanceMatrix, i);
|
|
125
129
|
instanceColor.copyAt(i, this.instanceColor, i);
|
|
@@ -146,9 +150,9 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
146
150
|
const instancedMesh = this.instanceCollect[uuid];
|
|
147
151
|
const collect = this.meshCollect[uuid];
|
|
148
152
|
collect.forEach((mesh, i) => {
|
|
149
|
-
InstancedMeshBase.
|
|
150
|
-
InstancedMeshBase.
|
|
151
|
-
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase.
|
|
153
|
+
InstancedMeshBase._matrix.copy(mesh.matrix);
|
|
154
|
+
InstancedMeshBase._matrix.premultiply(matrix);
|
|
155
|
+
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
152
156
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
153
157
|
});
|
|
154
158
|
});
|
|
@@ -162,17 +166,17 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
162
166
|
const collect = this.meshCollect[uuid];
|
|
163
167
|
collect.forEach((mesh, i) => {
|
|
164
168
|
//获取对应的模型的矩阵
|
|
165
|
-
instancedMesh.getMatrixAt(collect.length * index + i, InstancedMeshBase.
|
|
166
|
-
InstancedMeshBase.
|
|
167
|
-
InstancedMeshBase.
|
|
169
|
+
instancedMesh.getMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
170
|
+
InstancedMeshBase._matrix.premultiply(mesh.matrix.clone().invert());
|
|
171
|
+
InstancedMeshBase._matrix.decompose(InstancedMeshBase._position, InstancedMeshBase._Quaternion, InstancedMeshBase._scale);
|
|
168
172
|
InstancedMeshBase._rotation.setFromQuaternion(InstancedMeshBase._Quaternion);
|
|
169
173
|
InstancedMeshBase._position.copy(position);
|
|
170
174
|
InstancedMeshBase._rotation.copy(rotation);
|
|
171
175
|
InstancedMeshBase._scale.copy(scale);
|
|
172
176
|
InstancedMeshBase._Quaternion.setFromEuler(InstancedMeshBase._rotation);
|
|
173
|
-
InstancedMeshBase.
|
|
174
|
-
InstancedMeshBase.
|
|
175
|
-
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase.
|
|
177
|
+
InstancedMeshBase._matrix.compose(InstancedMeshBase._position, InstancedMeshBase._Quaternion, InstancedMeshBase._scale);
|
|
178
|
+
InstancedMeshBase._matrix.premultiply(mesh.matrix);
|
|
179
|
+
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
176
180
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
177
181
|
});
|
|
178
182
|
});
|
package/InstancedMeshBase.ts
CHANGED
|
@@ -35,7 +35,7 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
35
35
|
static _scale: Vector3 = new Vector3(1, 1, 1);
|
|
36
36
|
static _rotation: Euler = new Euler();
|
|
37
37
|
static _Quaternion: Quaternion = new Quaternion();
|
|
38
|
-
static
|
|
38
|
+
static _matrix = new Matrix4()
|
|
39
39
|
|
|
40
40
|
instanceMatrix = new InstancedBufferAttribute(new Float32Array(0 * 16), 16);
|
|
41
41
|
|
|
@@ -160,6 +160,11 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
160
160
|
const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
|
|
161
161
|
const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
|
|
162
162
|
|
|
163
|
+
for (let i = 0; i < count; i++) {
|
|
164
|
+
instanceMatrix.set(InstancedMeshBase._matrix.identity().toArray(), i);
|
|
165
|
+
instanceColor.set([1, 1, 1], i);
|
|
166
|
+
}
|
|
167
|
+
|
|
163
168
|
for (let i = 0; i < this.count; i++) {
|
|
164
169
|
instanceMatrix.copyAt(i, this.instanceMatrix, i);
|
|
165
170
|
instanceColor.copyAt(i, this.instanceColor, i);
|
|
@@ -194,10 +199,10 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
194
199
|
const instancedMesh = this.instanceCollect[uuid]
|
|
195
200
|
const collect = this.meshCollect[uuid]
|
|
196
201
|
collect.forEach((mesh: Mesh, i: number) => {
|
|
197
|
-
InstancedMeshBase.
|
|
198
|
-
InstancedMeshBase.
|
|
202
|
+
InstancedMeshBase._matrix.copy(mesh.matrix)
|
|
203
|
+
InstancedMeshBase._matrix.premultiply(matrix)
|
|
199
204
|
|
|
200
|
-
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase.
|
|
205
|
+
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
201
206
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
202
207
|
})
|
|
203
208
|
})
|
|
@@ -226,11 +231,11 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
226
231
|
collect.forEach((mesh: Mesh, i: number) => {
|
|
227
232
|
|
|
228
233
|
//获取对应的模型的矩阵
|
|
229
|
-
instancedMesh.getMatrixAt(collect.length * index + i, InstancedMeshBase.
|
|
234
|
+
instancedMesh.getMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
230
235
|
|
|
231
|
-
InstancedMeshBase.
|
|
236
|
+
InstancedMeshBase._matrix.premultiply(mesh.matrix.clone().invert());
|
|
232
237
|
|
|
233
|
-
InstancedMeshBase.
|
|
238
|
+
InstancedMeshBase._matrix.decompose(
|
|
234
239
|
InstancedMeshBase._position,
|
|
235
240
|
InstancedMeshBase._Quaternion,
|
|
236
241
|
InstancedMeshBase._scale
|
|
@@ -241,15 +246,15 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
241
246
|
InstancedMeshBase._scale.copy(scale);
|
|
242
247
|
InstancedMeshBase._Quaternion.setFromEuler(InstancedMeshBase._rotation);
|
|
243
248
|
|
|
244
|
-
InstancedMeshBase.
|
|
249
|
+
InstancedMeshBase._matrix.compose(
|
|
245
250
|
InstancedMeshBase._position,
|
|
246
251
|
InstancedMeshBase._Quaternion,
|
|
247
252
|
InstancedMeshBase._scale
|
|
248
253
|
);
|
|
249
254
|
|
|
250
|
-
InstancedMeshBase.
|
|
255
|
+
InstancedMeshBase._matrix.premultiply(mesh.matrix);
|
|
251
256
|
|
|
252
|
-
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase.
|
|
257
|
+
instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
|
|
253
258
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
254
259
|
})
|
|
255
260
|
})
|
package/ThreeBase.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
19
19
|
setCameraType(cameraType: "perspectiveCamera" | "orthographicCamera"): void;
|
|
20
20
|
getCamera(): PerspectiveCamera | OrthographicCamera;
|
|
21
21
|
scene: Scene;
|
|
22
|
+
add(...object: Object3D[]): this;
|
|
22
23
|
threeMouse: ThreeMouse;
|
|
23
24
|
controls: OrbitControls;
|
|
24
25
|
setContainer(div: HTMLDivElement | null): Promise<void>;
|
package/ThreeBase.js
CHANGED
|
@@ -84,7 +84,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
84
84
|
perspectiveCamera = new PerspectiveCamera(45, 1, 0.01, 10000);
|
|
85
85
|
//正交相机
|
|
86
86
|
orthographicCamera = new OrthographicCamera(-1, 1, 1, -1, 0.01, 10000);
|
|
87
|
-
//相机的类型
|
|
87
|
+
//相机的类型 有透视相机和正交相机
|
|
88
88
|
cameraType = "perspectiveCamera";
|
|
89
89
|
setCameraType(cameraType) {
|
|
90
90
|
if (this.cameraType !== cameraType) {
|
|
@@ -101,14 +101,22 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
101
101
|
}
|
|
102
102
|
//获取当前使用的的相机
|
|
103
103
|
getCamera() {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
switch (this.cameraType) {
|
|
105
|
+
case "orthographicCamera":
|
|
106
|
+
return this.orthographicCamera;
|
|
107
|
+
case "perspectiveCamera":
|
|
108
|
+
default:
|
|
109
|
+
return this.perspectiveCamera;
|
|
110
|
+
}
|
|
109
111
|
}
|
|
110
112
|
// 场景对象
|
|
111
113
|
scene = new Scene();
|
|
114
|
+
// 这个方法等效 this.scene.add
|
|
115
|
+
// 想少写2个字母就用这个方法
|
|
116
|
+
add(...object) {
|
|
117
|
+
this.scene.add(...object);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
112
120
|
///鼠标事件对象
|
|
113
121
|
threeMouse = new ThreeMouse(this.renderer, this.perspectiveCamera, this.scene);
|
|
114
122
|
// 轨道控制器
|
package/ThreeBase.ts
CHANGED
|
@@ -99,7 +99,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
99
99
|
//正交相机
|
|
100
100
|
orthographicCamera = new OrthographicCamera(- 1, 1, 1, - 1, 0.01, 10000);
|
|
101
101
|
|
|
102
|
-
//相机的类型
|
|
102
|
+
//相机的类型 有透视相机和正交相机
|
|
103
103
|
cameraType: "perspectiveCamera" | "orthographicCamera" = "perspectiveCamera";
|
|
104
104
|
setCameraType(cameraType: "perspectiveCamera" | "orthographicCamera") {
|
|
105
105
|
if (this.cameraType !== cameraType) {
|
|
@@ -115,16 +115,25 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
115
115
|
}
|
|
116
116
|
//获取当前使用的的相机
|
|
117
117
|
getCamera() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
switch (this.cameraType) {
|
|
119
|
+
case "orthographicCamera":
|
|
120
|
+
return this.orthographicCamera;
|
|
121
|
+
case "perspectiveCamera":
|
|
122
|
+
default:
|
|
123
|
+
return this.perspectiveCamera;
|
|
124
|
+
}
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
// 场景对象
|
|
126
128
|
scene = new Scene();
|
|
127
129
|
|
|
130
|
+
// 这个方法等效 this.scene.add
|
|
131
|
+
// 想少写2个字母就用这个方法
|
|
132
|
+
add(...object: Object3D[]) {
|
|
133
|
+
this.scene.add(...object);
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
|
|
128
137
|
///鼠标事件对象
|
|
129
138
|
threeMouse = new ThreeMouse(this.renderer, this.perspectiveCamera, this.scene);
|
|
130
139
|
|