three-base 2.0.55 → 2.0.57
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/MeshBase.d.ts +3 -0
- package/MeshBase.js +26 -0
- package/MeshBase.ts +29 -1
- package/package.json +1 -1
- package/threeLoader.d.ts +2 -0
- package/threeLoader.js +3 -0
- package/threeLoader.ts +4 -0
- package/threeUtils.d.ts +1 -0
- package/threeUtils.js +3 -0
- package/threeUtils.ts +5 -0
package/MeshBase.d.ts
CHANGED
|
@@ -19,6 +19,9 @@ export default class MeshBase extends Group {
|
|
|
19
19
|
setClipActionWeight(weights?: {
|
|
20
20
|
[key: string]: number;
|
|
21
21
|
}): Promise<void>;
|
|
22
|
+
getAnimas(): string[];
|
|
23
|
+
play(anima?: string): void;
|
|
24
|
+
stop(): void;
|
|
22
25
|
updateMatrix(): void;
|
|
23
26
|
getSize(): Promise<Vector3>;
|
|
24
27
|
center(): Promise<void>;
|
package/MeshBase.js
CHANGED
|
@@ -46,6 +46,20 @@ export default class MeshBase extends Group {
|
|
|
46
46
|
console.error(`${url},加载失败`);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
+
else if (/\.(usdz)$/i.test(suffix || url)) {
|
|
50
|
+
await threeLoader.usdzLoader.loadAsync(url).then(res => {
|
|
51
|
+
modal = res; // usdz 目前还不支持骨骼动画
|
|
52
|
+
modal.animations = res.animations;
|
|
53
|
+
modal.traverse(obj => {
|
|
54
|
+
const mesh = obj;
|
|
55
|
+
if (mesh.isMesh) {
|
|
56
|
+
mesh.material.transparent = true;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}).catch(() => {
|
|
60
|
+
console.error(`${url},加载失败`);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
49
63
|
else {
|
|
50
64
|
if (suffix) {
|
|
51
65
|
console.error(`${suffix},不支持的格式`);
|
|
@@ -119,6 +133,18 @@ export default class MeshBase extends Group {
|
|
|
119
133
|
this.animationActions[key].weight = weights[key] || 0;
|
|
120
134
|
}
|
|
121
135
|
}
|
|
136
|
+
//获取动画列表
|
|
137
|
+
getAnimas() {
|
|
138
|
+
return Object.keys(this.animationActions);
|
|
139
|
+
}
|
|
140
|
+
//播放指定动画
|
|
141
|
+
play(anima = "") {
|
|
142
|
+
this.setClipActionWeight({ [anima]: 1 });
|
|
143
|
+
}
|
|
144
|
+
//停止所有动画
|
|
145
|
+
stop() {
|
|
146
|
+
this.setClipActionWeight();
|
|
147
|
+
}
|
|
122
148
|
updateMatrix() {
|
|
123
149
|
//播放动画
|
|
124
150
|
if (this.mixer) {
|
package/MeshBase.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { AnimationAction, AnimationMixer, Clock, DoubleSide, Group, Mesh, MeshStandardMaterial, Object3D, Vector3 } from "three";
|
|
2
|
+
import { AnimationAction, AnimationMixer, Clock, DoubleSide, Group, Material, Mesh, MeshStandardMaterial, Object3D, Vector3 } from "three";
|
|
3
3
|
import threeUtils from "./threeUtils";
|
|
4
4
|
import threeLoader from "./threeLoader";
|
|
5
5
|
import * as SkeletonUtils from 'three/examples/jsm/utils/SkeletonUtils';
|
|
@@ -57,6 +57,19 @@ export default class MeshBase extends Group {
|
|
|
57
57
|
}).catch(() => {
|
|
58
58
|
console.error(`${url},加载失败`);
|
|
59
59
|
})
|
|
60
|
+
} else if (/\.(usdz)$/i.test(suffix || url)) {
|
|
61
|
+
await threeLoader.usdzLoader.loadAsync(url).then(res => {
|
|
62
|
+
modal = res; // usdz 目前还不支持骨骼动画
|
|
63
|
+
modal.animations = res.animations;
|
|
64
|
+
modal.traverse(obj => {
|
|
65
|
+
const mesh = (obj as Mesh);
|
|
66
|
+
if (mesh.isMesh) {
|
|
67
|
+
(mesh.material as Material).transparent = true;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}).catch(() => {
|
|
71
|
+
console.error(`${url},加载失败`);
|
|
72
|
+
})
|
|
60
73
|
} else {
|
|
61
74
|
if (suffix) {
|
|
62
75
|
console.error(`${suffix},不支持的格式`);
|
|
@@ -148,6 +161,21 @@ export default class MeshBase extends Group {
|
|
|
148
161
|
}
|
|
149
162
|
}
|
|
150
163
|
|
|
164
|
+
//获取动画列表
|
|
165
|
+
getAnimas() {
|
|
166
|
+
return Object.keys(this.animationActions);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//播放指定动画
|
|
170
|
+
play(anima: string = "") {
|
|
171
|
+
this.setClipActionWeight({ [anima]: 1 });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//停止所有动画
|
|
175
|
+
stop() {
|
|
176
|
+
this.setClipActionWeight();
|
|
177
|
+
}
|
|
178
|
+
|
|
151
179
|
updateMatrix(): void {
|
|
152
180
|
//播放动画
|
|
153
181
|
if (this.mixer) {
|
package/package.json
CHANGED
package/threeLoader.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
|
4
4
|
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
5
5
|
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
|
|
6
6
|
import { STLLoader } from "three/examples/jsm/loaders/STLLoader";
|
|
7
|
+
import { USDZLoader } from "three/examples/jsm/loaders/USDZLoader";
|
|
7
8
|
declare class ThreeLoader extends EventDispatcher {
|
|
8
9
|
constructor();
|
|
9
10
|
anisotropy: number;
|
|
@@ -16,6 +17,7 @@ declare class ThreeLoader extends EventDispatcher {
|
|
|
16
17
|
stlLoader: STLLoader;
|
|
17
18
|
mtlLoader: MTLLoader;
|
|
18
19
|
gltfLoader: GLTFLoader;
|
|
20
|
+
usdzLoader: USDZLoader;
|
|
19
21
|
/** 加载模型支持glb,fbx,stl,obj */
|
|
20
22
|
loadModal(url: string): Promise<Object3D<import("three").Object3DEventMap>>;
|
|
21
23
|
onload: boolean;
|
package/threeLoader.js
CHANGED
|
@@ -11,6 +11,7 @@ import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
|
11
11
|
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
|
|
12
12
|
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
|
13
13
|
import { STLLoader } from "three/examples/jsm/loaders/STLLoader";
|
|
14
|
+
import { USDZLoader } from "three/examples/jsm/loaders/USDZLoader";
|
|
14
15
|
// 引入静态资源
|
|
15
16
|
//@ts-ignore
|
|
16
17
|
import dracoWasmWrapperJS from "./lib/draco/draco_wasm_wrapper.js?url";
|
|
@@ -119,6 +120,8 @@ class ThreeLoader extends EventDispatcher {
|
|
|
119
120
|
loader.setDRACOLoader(dracoLoader);
|
|
120
121
|
return loader;
|
|
121
122
|
})();
|
|
123
|
+
//usdz加载器
|
|
124
|
+
usdzLoader = new USDZLoader();
|
|
122
125
|
/** 加载模型支持glb,fbx,stl,obj */
|
|
123
126
|
async loadModal(url) {
|
|
124
127
|
let Object3d = new Object3D();
|
package/threeLoader.ts
CHANGED
|
@@ -12,6 +12,8 @@ import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
|
12
12
|
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
|
|
13
13
|
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
|
14
14
|
import { STLLoader } from "three/examples/jsm/loaders/STLLoader";
|
|
15
|
+
import { USDZLoader } from "three/examples/jsm/loaders/USDZLoader";
|
|
16
|
+
|
|
15
17
|
|
|
16
18
|
// 引入静态资源
|
|
17
19
|
//@ts-ignore
|
|
@@ -145,6 +147,8 @@ class ThreeLoader extends EventDispatcher {
|
|
|
145
147
|
return loader;
|
|
146
148
|
})()
|
|
147
149
|
|
|
150
|
+
//usdz加载器
|
|
151
|
+
usdzLoader = new USDZLoader();
|
|
148
152
|
|
|
149
153
|
/** 加载模型支持glb,fbx,stl,obj */
|
|
150
154
|
async loadModal(url: string) {
|
package/threeUtils.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ declare class ThreeUtils extends EventDispatcher {
|
|
|
38
38
|
scaleTo(object3d: Object3D | BufferGeometry, size?: number, key?: Array<"x" | "y" | "z">): void;
|
|
39
39
|
applyAllTranstion(object3d: Object3D): void;
|
|
40
40
|
exportGLB(input: Object3D, fileName?: string): void;
|
|
41
|
+
exportUsdz(): void;
|
|
41
42
|
getVolume(geometry: BufferGeometry): number;
|
|
42
43
|
signedVolumeOfTriangle(p1: Vector3, p2: Vector3, p3: Vector3): number;
|
|
43
44
|
}
|
package/threeUtils.js
CHANGED