three-base 2.0.100 → 2.0.101
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 +2 -1
- package/InstancedMeshBase.js +7 -2
- package/MeshBase.d.ts +1 -0
- package/MeshBase.js +8 -4
- package/Transition.d.ts +1 -1
- package/package.json +1 -1
package/InstancedMeshBase.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, Euler, InstancedBufferAttribute, InstancedMesh, Matrix4, Mesh, Quaternion, Vector3 } from "three";
|
|
1
|
+
import { Color, Euler, InstancedBufferAttribute, InstancedMesh, Matrix4, Mesh, Object3D, Quaternion, Vector3 } from "three";
|
|
2
2
|
import MeshBase from "./MeshBase";
|
|
3
3
|
export default class InstancedMeshBase extends MeshBase {
|
|
4
4
|
constructor(url?: string);
|
|
@@ -16,6 +16,7 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
16
16
|
static _matrix: Matrix4;
|
|
17
17
|
instanceMatrix: InstancedBufferAttribute;
|
|
18
18
|
instanceColor: InstancedBufferAttribute;
|
|
19
|
+
reset(...object: Object3D[]): this;
|
|
19
20
|
loadModel(url: string | File | Array<File>, filename?: string): Promise<void>;
|
|
20
21
|
computeBoundingSphere: import("lodash").DebouncedFunc<() => void>;
|
|
21
22
|
setCount(count?: number): Promise<void>;
|
package/InstancedMeshBase.js
CHANGED
|
@@ -27,6 +27,12 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
27
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
|
+
// 重置子元素
|
|
31
|
+
reset(...object) {
|
|
32
|
+
super.clear();
|
|
33
|
+
super.add(...object);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
30
36
|
// 重构加载模型的方法
|
|
31
37
|
async loadModel(url, filename = "") {
|
|
32
38
|
//获取模型文件的地址
|
|
@@ -59,7 +65,6 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
59
65
|
})();
|
|
60
66
|
this.url = modelurl || "";
|
|
61
67
|
if (!url) {
|
|
62
|
-
this.clear();
|
|
63
68
|
return;
|
|
64
69
|
}
|
|
65
70
|
this.loaded = false;
|
|
@@ -77,7 +82,6 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
77
82
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
78
83
|
} while (MeshBase.loadModeling.get(this.url));
|
|
79
84
|
if (MeshBase.models.get(this.url)) {
|
|
80
|
-
this.clear();
|
|
81
85
|
const mesh = MeshBase.models.get(this.url);
|
|
82
86
|
// // 判断是否有动画
|
|
83
87
|
// this.hasAnimation = mesh.animations.length > 0;
|
|
@@ -119,6 +123,7 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
119
123
|
obj.rotation.set(0, 0, 0);
|
|
120
124
|
}
|
|
121
125
|
});
|
|
126
|
+
this.clear();
|
|
122
127
|
// create all instances
|
|
123
128
|
Object.keys(meshCollect).forEach((uuid) => {
|
|
124
129
|
const meshes = meshCollect[uuid];
|
package/MeshBase.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export default class MeshBase extends Group {
|
|
|
11
11
|
[key: string]: AnimationAction;
|
|
12
12
|
};
|
|
13
13
|
getSuffix(filename: string): string;
|
|
14
|
+
reset(...object: Object3D[]): this;
|
|
14
15
|
loadModel(url: string | File | Array<File>, filename?: string): Promise<void>;
|
|
15
16
|
frustumCulled: boolean;
|
|
16
17
|
castShadow: boolean;
|
package/MeshBase.js
CHANGED
|
@@ -27,6 +27,12 @@ export default class MeshBase extends Group {
|
|
|
27
27
|
const match = filename.match(/\.([^\.]+)$/);
|
|
28
28
|
return match ? match[1].toLowerCase() : "";
|
|
29
29
|
}
|
|
30
|
+
// 重置子元素
|
|
31
|
+
reset(...object) {
|
|
32
|
+
super.clear();
|
|
33
|
+
super.add(...object);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
30
36
|
// 如果url 是blob地址的话,就用suffix字段来制定模型的类型
|
|
31
37
|
async loadModel(url, filename = "") {
|
|
32
38
|
//获取模型文件的地址
|
|
@@ -59,7 +65,6 @@ export default class MeshBase extends Group {
|
|
|
59
65
|
})();
|
|
60
66
|
this.url = modelurl || "";
|
|
61
67
|
if (!modelurl) {
|
|
62
|
-
this.clear();
|
|
63
68
|
return;
|
|
64
69
|
}
|
|
65
70
|
this.loaded = false;
|
|
@@ -77,7 +82,6 @@ export default class MeshBase extends Group {
|
|
|
77
82
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
78
83
|
} while (MeshBase.loadModeling.get(modelurl));
|
|
79
84
|
if (MeshBase.models.get(modelurl)) {
|
|
80
|
-
this.clear();
|
|
81
85
|
const mesh = MeshBase.models.get(modelurl);
|
|
82
86
|
// 判断是否有动画
|
|
83
87
|
this.hasAnimation = mesh.animations.length > 0;
|
|
@@ -90,10 +94,10 @@ export default class MeshBase extends Group {
|
|
|
90
94
|
animationAction.weight = 0;
|
|
91
95
|
this.animationActions[animation.name] = animationAction;
|
|
92
96
|
});
|
|
93
|
-
this.
|
|
97
|
+
this.reset(model);
|
|
94
98
|
}
|
|
95
99
|
else {
|
|
96
|
-
this.
|
|
100
|
+
this.reset(mesh.clone(true));
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
await new Promise((resolve) => requestAnimationFrame(resolve));
|
package/Transition.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export default class Transition<T extends TransitionParame, K extends Extract<ke
|
|
|
30
30
|
onChange(onChangeCall: (josn: T) => void): this;
|
|
31
31
|
onDone(onDoneCall: (josn: T) => void): this;
|
|
32
32
|
get(key: Extract<keyof T, string>): T[K];
|
|
33
|
-
set(param: T): Promise<this>;
|
|
33
|
+
set(param: Partial<T>): Promise<this>;
|
|
34
34
|
reset(param: Partial<T>): this;
|
|
35
35
|
getKeys(): Array<Extract<keyof T, string>>;
|
|
36
36
|
hasKey(key: Extract<keyof T, string>): boolean;
|