three-base 2.0.74 → 2.0.76
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 +234 -236
- package/InstancedMeshBase.ts +1 -4
- package/KeyFrameAnimation.d.ts +25 -25
- package/KeyFrameAnimation.js +78 -78
- package/MeshBase.d.ts +34 -34
- package/MeshBase.js +187 -185
- package/MeshBase.ts +15 -13
- 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/threeLoader.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2022-04-07 16:42:26
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-02-07 11:11:48
|
|
6
|
-
*/
|
|
7
|
-
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, Mesh, MeshStandardMaterial, Object3D, RepeatWrapping, TextureLoader, VideoTexture } from "three";
|
|
8
|
-
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
9
|
-
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
10
|
-
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
11
|
-
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
|
|
12
|
-
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
|
13
|
-
import { STLLoader } from "three/examples/jsm/loaders/STLLoader";
|
|
14
|
-
import { USDZLoader } from "three/examples/jsm/loaders/USDZLoader";
|
|
15
|
-
// import { IFCLoader } from 'web-ifc-three/dist/IFCLoader';
|
|
16
|
-
// import { IFCLoader } from 'web-ifc-three';
|
|
17
|
-
// import { IFCSPACE } from 'web-ifc';
|
|
18
|
-
// 引入静态资源
|
|
19
|
-
//@ts-ignore
|
|
20
|
-
import dracoWasmWrapperJS from "./lib/draco/draco_wasm_wrapper.js?url";
|
|
21
|
-
//@ts-ignore
|
|
22
|
-
import dracoDecoderJS from "./lib/draco/draco_decoder.js?url";
|
|
23
|
-
//@ts-ignore
|
|
24
|
-
import dracoDecoderWASM from "./lib/draco/draco_decoder.wasm?url";
|
|
25
|
-
import { get } from "lodash";
|
|
26
|
-
// 加载器
|
|
27
|
-
class ThreeLoader extends EventDispatcher {
|
|
28
|
-
constructor() {
|
|
29
|
-
super();
|
|
30
|
-
DefaultLoadingManager.onStart = () => {
|
|
31
|
-
this.onload = false;
|
|
32
|
-
};
|
|
33
|
-
// 有资源加载完成时通知渲染器
|
|
34
|
-
DefaultLoadingManager.onProgress = (url, loaded, total) => {
|
|
35
|
-
if (loaded < total) {
|
|
36
|
-
this.dispatchEvent({ type: "loadding" });
|
|
37
|
-
}
|
|
38
|
-
else if (loaded === total) {
|
|
39
|
-
this.dispatchEvent({ type: "onLoad" });
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
DefaultLoadingManager.onLoad = () => {
|
|
43
|
-
this.onload = true;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
// 各向异性
|
|
47
|
-
anisotropy = 16;
|
|
48
|
-
// 设置各向异性 由渲染器来调用并设置
|
|
49
|
-
setAnisotropy(v) {
|
|
50
|
-
this.anisotropy = v;
|
|
51
|
-
}
|
|
52
|
-
;
|
|
53
|
-
// 纹理对向缓存
|
|
54
|
-
textureMap = new Map();
|
|
55
|
-
// 纹理加载器
|
|
56
|
-
textureLoader = new TextureLoader();
|
|
57
|
-
// 获取地址对应的单例纹理对象
|
|
58
|
-
getTexture(src) {
|
|
59
|
-
if (src instanceof HTMLCanvasElement) {
|
|
60
|
-
const canvasTexture = new CanvasTexture(src);
|
|
61
|
-
canvasTexture.wrapS = canvasTexture.wrapT = RepeatWrapping;
|
|
62
|
-
canvasTexture.anisotropy = this.anisotropy;
|
|
63
|
-
// canvasTexture.colorSpace = SRGBColorSpace;
|
|
64
|
-
return canvasTexture;
|
|
65
|
-
}
|
|
66
|
-
let texture = this.textureMap.get(src);
|
|
67
|
-
if (!texture) {
|
|
68
|
-
if (/\.(mp4|mov)$/i.test(src)) {
|
|
69
|
-
const videoDom = document.createElement("video");
|
|
70
|
-
videoDom.autoplay = true;
|
|
71
|
-
videoDom.loop = true;
|
|
72
|
-
videoDom.muted = true;
|
|
73
|
-
videoDom.preload = "auto";
|
|
74
|
-
videoDom.playsInline = true;
|
|
75
|
-
videoDom.src = src;
|
|
76
|
-
document.addEventListener("pointerup", () => {
|
|
77
|
-
videoDom.pause();
|
|
78
|
-
videoDom.play();
|
|
79
|
-
});
|
|
80
|
-
texture = new VideoTexture(videoDom);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
texture = this.textureLoader.load(src, tex => {
|
|
84
|
-
tex.image.crossOrigin = "anonymous";
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
this.textureMap.set(src, texture);
|
|
88
|
-
}
|
|
89
|
-
texture.wrapS = texture.wrapT = RepeatWrapping;
|
|
90
|
-
texture.anisotropy = this.anisotropy;
|
|
91
|
-
// texture.colorSpace = SRGBColorSpace;
|
|
92
|
-
return texture;
|
|
93
|
-
}
|
|
94
|
-
;
|
|
95
|
-
// fbx模型加载器
|
|
96
|
-
fbxLoader = new FBXLoader();
|
|
97
|
-
//obj 加载器
|
|
98
|
-
objLoader = new OBJLoader();
|
|
99
|
-
// stl 加载器
|
|
100
|
-
stlLoader = new STLLoader();
|
|
101
|
-
// 材质加载器
|
|
102
|
-
mtlLoader = new MTLLoader();
|
|
103
|
-
// gltf 加载器
|
|
104
|
-
gltfLoader = (() => {
|
|
105
|
-
const loader = new GLTFLoader();
|
|
106
|
-
const dracoLoader = new class ThreeBaseDRACOLoader extends DRACOLoader {
|
|
107
|
-
_loadLibrary(url, responseType) {
|
|
108
|
-
//@ts-ignore
|
|
109
|
-
let urlConf = (process.env.NODE_ENV === "development") ? {
|
|
110
|
-
"draco_decoder.js": "draco_decoder.js",
|
|
111
|
-
"draco_wasm_wrapper.js": "draco_wasm_wrapper.js",
|
|
112
|
-
"draco_decoder.wasm": "draco_decoder.wasm"
|
|
113
|
-
} : {
|
|
114
|
-
"draco_decoder.js": dracoWasmWrapperJS,
|
|
115
|
-
"draco_wasm_wrapper.js": dracoDecoderJS,
|
|
116
|
-
"draco_decoder.wasm": dracoDecoderWASM
|
|
117
|
-
};
|
|
118
|
-
//@ts-ignore
|
|
119
|
-
return super._loadLibrary(urlConf[url], responseType);
|
|
120
|
-
}
|
|
121
|
-
}();
|
|
122
|
-
//@ts-ignore
|
|
123
|
-
dracoLoader.setDecoderPath((process.env.NODE_ENV === "development") ? '/node_modules/three/examples/jsm/libs/draco/' : '');
|
|
124
|
-
loader.setDRACOLoader(dracoLoader);
|
|
125
|
-
return loader;
|
|
126
|
-
})();
|
|
127
|
-
//usdz加载器
|
|
128
|
-
usdzLoader = new USDZLoader();
|
|
129
|
-
/** 加载模型支持glb,fbx,stl,obj */
|
|
130
|
-
async loadModel(url, filename = "") {
|
|
131
|
-
// 获取后缀
|
|
132
|
-
const suffix = (get((filename || url).match(/\.([^\.]+)$/), [1]) || "").toLowerCase();
|
|
133
|
-
let Object3d = new Object3D();
|
|
134
|
-
if (["fbx"].includes(suffix)) {
|
|
135
|
-
await threeLoader.fbxLoader.loadAsync(url).then(res => {
|
|
136
|
-
Object3d = res;
|
|
137
|
-
}).catch(() => {
|
|
138
|
-
console.error(`${url},加载失败`);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
else if (["gltf", "glb"].includes(suffix)) {
|
|
142
|
-
await threeLoader.gltfLoader.loadAsync(url).then(res => {
|
|
143
|
-
Object3d = res.scene;
|
|
144
|
-
Object3d.animations = res.animations;
|
|
145
|
-
}).catch(() => {
|
|
146
|
-
console.error(`${url},加载失败`);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
else if (["stl"].includes(suffix)) {
|
|
150
|
-
await threeLoader.stlLoader.loadAsync(url).then(geometry => {
|
|
151
|
-
Object3d = new Mesh(geometry, new MeshStandardMaterial({
|
|
152
|
-
color: "#f1fbff",
|
|
153
|
-
metalness: 0.79,
|
|
154
|
-
roughness: 0.56,
|
|
155
|
-
envMapIntensity: 0.4
|
|
156
|
-
}));
|
|
157
|
-
}).catch(() => {
|
|
158
|
-
console.error(`${url},加载失败`);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
else if (["usdz"].includes(suffix)) {
|
|
162
|
-
await threeLoader.usdzLoader.loadAsync(url).then(res => {
|
|
163
|
-
Object3d = res; // usdz 目前还不支持骨骼动画
|
|
164
|
-
Object3d.animations = res.animations;
|
|
165
|
-
Object3d.traverse(obj => {
|
|
166
|
-
const mesh = obj;
|
|
167
|
-
if (mesh.isMesh) {
|
|
168
|
-
mesh.material.transparent = true;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}).catch((err) => {
|
|
172
|
-
console.error(`${url},加载失败`, err);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
if (suffix) {
|
|
177
|
-
console.error(`${suffix},不支持的格式`);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
console.error(`${url},不支持的格式,请尝试使用 suffix 参数来指定一下格式`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return Object3d;
|
|
184
|
-
}
|
|
185
|
-
// 是否加载完成
|
|
186
|
-
onload = true;
|
|
187
|
-
}
|
|
188
|
-
const threeLoader = new ThreeLoader();
|
|
189
|
-
export default threeLoader;
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-04-07 16:42:26
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-02-07 11:11:48
|
|
6
|
+
*/
|
|
7
|
+
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, Mesh, MeshStandardMaterial, Object3D, RepeatWrapping, TextureLoader, VideoTexture } from "three";
|
|
8
|
+
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
9
|
+
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
10
|
+
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
11
|
+
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
|
|
12
|
+
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
|
13
|
+
import { STLLoader } from "three/examples/jsm/loaders/STLLoader";
|
|
14
|
+
import { USDZLoader } from "three/examples/jsm/loaders/USDZLoader";
|
|
15
|
+
// import { IFCLoader } from 'web-ifc-three/dist/IFCLoader';
|
|
16
|
+
// import { IFCLoader } from 'web-ifc-three';
|
|
17
|
+
// import { IFCSPACE } from 'web-ifc';
|
|
18
|
+
// 引入静态资源
|
|
19
|
+
//@ts-ignore
|
|
20
|
+
import dracoWasmWrapperJS from "./lib/draco/draco_wasm_wrapper.js?url";
|
|
21
|
+
//@ts-ignore
|
|
22
|
+
import dracoDecoderJS from "./lib/draco/draco_decoder.js?url";
|
|
23
|
+
//@ts-ignore
|
|
24
|
+
import dracoDecoderWASM from "./lib/draco/draco_decoder.wasm?url";
|
|
25
|
+
import { get } from "lodash";
|
|
26
|
+
// 加载器
|
|
27
|
+
class ThreeLoader extends EventDispatcher {
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
DefaultLoadingManager.onStart = () => {
|
|
31
|
+
this.onload = false;
|
|
32
|
+
};
|
|
33
|
+
// 有资源加载完成时通知渲染器
|
|
34
|
+
DefaultLoadingManager.onProgress = (url, loaded, total) => {
|
|
35
|
+
if (loaded < total) {
|
|
36
|
+
this.dispatchEvent({ type: "loadding" });
|
|
37
|
+
}
|
|
38
|
+
else if (loaded === total) {
|
|
39
|
+
this.dispatchEvent({ type: "onLoad" });
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
DefaultLoadingManager.onLoad = () => {
|
|
43
|
+
this.onload = true;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// 各向异性
|
|
47
|
+
anisotropy = 16;
|
|
48
|
+
// 设置各向异性 由渲染器来调用并设置
|
|
49
|
+
setAnisotropy(v) {
|
|
50
|
+
this.anisotropy = v;
|
|
51
|
+
}
|
|
52
|
+
;
|
|
53
|
+
// 纹理对向缓存
|
|
54
|
+
textureMap = new Map();
|
|
55
|
+
// 纹理加载器
|
|
56
|
+
textureLoader = new TextureLoader();
|
|
57
|
+
// 获取地址对应的单例纹理对象
|
|
58
|
+
getTexture(src) {
|
|
59
|
+
if (src instanceof HTMLCanvasElement) {
|
|
60
|
+
const canvasTexture = new CanvasTexture(src);
|
|
61
|
+
canvasTexture.wrapS = canvasTexture.wrapT = RepeatWrapping;
|
|
62
|
+
canvasTexture.anisotropy = this.anisotropy;
|
|
63
|
+
// canvasTexture.colorSpace = SRGBColorSpace;
|
|
64
|
+
return canvasTexture;
|
|
65
|
+
}
|
|
66
|
+
let texture = this.textureMap.get(src);
|
|
67
|
+
if (!texture) {
|
|
68
|
+
if (/\.(mp4|mov)$/i.test(src)) {
|
|
69
|
+
const videoDom = document.createElement("video");
|
|
70
|
+
videoDom.autoplay = true;
|
|
71
|
+
videoDom.loop = true;
|
|
72
|
+
videoDom.muted = true;
|
|
73
|
+
videoDom.preload = "auto";
|
|
74
|
+
videoDom.playsInline = true;
|
|
75
|
+
videoDom.src = src;
|
|
76
|
+
document.addEventListener("pointerup", () => {
|
|
77
|
+
videoDom.pause();
|
|
78
|
+
videoDom.play();
|
|
79
|
+
});
|
|
80
|
+
texture = new VideoTexture(videoDom);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
texture = this.textureLoader.load(src, tex => {
|
|
84
|
+
tex.image.crossOrigin = "anonymous";
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
this.textureMap.set(src, texture);
|
|
88
|
+
}
|
|
89
|
+
texture.wrapS = texture.wrapT = RepeatWrapping;
|
|
90
|
+
texture.anisotropy = this.anisotropy;
|
|
91
|
+
// texture.colorSpace = SRGBColorSpace;
|
|
92
|
+
return texture;
|
|
93
|
+
}
|
|
94
|
+
;
|
|
95
|
+
// fbx模型加载器
|
|
96
|
+
fbxLoader = new FBXLoader();
|
|
97
|
+
//obj 加载器
|
|
98
|
+
objLoader = new OBJLoader();
|
|
99
|
+
// stl 加载器
|
|
100
|
+
stlLoader = new STLLoader();
|
|
101
|
+
// 材质加载器
|
|
102
|
+
mtlLoader = new MTLLoader();
|
|
103
|
+
// gltf 加载器
|
|
104
|
+
gltfLoader = (() => {
|
|
105
|
+
const loader = new GLTFLoader();
|
|
106
|
+
const dracoLoader = new class ThreeBaseDRACOLoader extends DRACOLoader {
|
|
107
|
+
_loadLibrary(url, responseType) {
|
|
108
|
+
//@ts-ignore
|
|
109
|
+
let urlConf = (process.env.NODE_ENV === "development") ? {
|
|
110
|
+
"draco_decoder.js": "draco_decoder.js",
|
|
111
|
+
"draco_wasm_wrapper.js": "draco_wasm_wrapper.js",
|
|
112
|
+
"draco_decoder.wasm": "draco_decoder.wasm"
|
|
113
|
+
} : {
|
|
114
|
+
"draco_decoder.js": dracoWasmWrapperJS,
|
|
115
|
+
"draco_wasm_wrapper.js": dracoDecoderJS,
|
|
116
|
+
"draco_decoder.wasm": dracoDecoderWASM
|
|
117
|
+
};
|
|
118
|
+
//@ts-ignore
|
|
119
|
+
return super._loadLibrary(urlConf[url], responseType);
|
|
120
|
+
}
|
|
121
|
+
}();
|
|
122
|
+
//@ts-ignore
|
|
123
|
+
dracoLoader.setDecoderPath((process.env.NODE_ENV === "development") ? '/node_modules/three/examples/jsm/libs/draco/' : '');
|
|
124
|
+
loader.setDRACOLoader(dracoLoader);
|
|
125
|
+
return loader;
|
|
126
|
+
})();
|
|
127
|
+
//usdz加载器
|
|
128
|
+
usdzLoader = new USDZLoader();
|
|
129
|
+
/** 加载模型支持glb,fbx,stl,obj */
|
|
130
|
+
async loadModel(url, filename = "") {
|
|
131
|
+
// 获取后缀
|
|
132
|
+
const suffix = (get((filename || url).match(/\.([^\.]+)$/), [1]) || "").toLowerCase();
|
|
133
|
+
let Object3d = new Object3D();
|
|
134
|
+
if (["fbx"].includes(suffix)) {
|
|
135
|
+
await threeLoader.fbxLoader.loadAsync(url).then(res => {
|
|
136
|
+
Object3d = res;
|
|
137
|
+
}).catch(() => {
|
|
138
|
+
console.error(`${url},加载失败`);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else if (["gltf", "glb"].includes(suffix)) {
|
|
142
|
+
await threeLoader.gltfLoader.loadAsync(url).then(res => {
|
|
143
|
+
Object3d = res.scene;
|
|
144
|
+
Object3d.animations = res.animations;
|
|
145
|
+
}).catch(() => {
|
|
146
|
+
console.error(`${url},加载失败`);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else if (["stl"].includes(suffix)) {
|
|
150
|
+
await threeLoader.stlLoader.loadAsync(url).then(geometry => {
|
|
151
|
+
Object3d = new Mesh(geometry, new MeshStandardMaterial({
|
|
152
|
+
color: "#f1fbff",
|
|
153
|
+
metalness: 0.79,
|
|
154
|
+
roughness: 0.56,
|
|
155
|
+
envMapIntensity: 0.4
|
|
156
|
+
}));
|
|
157
|
+
}).catch(() => {
|
|
158
|
+
console.error(`${url},加载失败`);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
else if (["usdz"].includes(suffix)) {
|
|
162
|
+
await threeLoader.usdzLoader.loadAsync(url).then(res => {
|
|
163
|
+
Object3d = res; // usdz 目前还不支持骨骼动画
|
|
164
|
+
Object3d.animations = res.animations;
|
|
165
|
+
Object3d.traverse(obj => {
|
|
166
|
+
const mesh = obj;
|
|
167
|
+
if (mesh.isMesh) {
|
|
168
|
+
mesh.material.transparent = true;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}).catch((err) => {
|
|
172
|
+
console.error(`${url},加载失败`, err);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (suffix) {
|
|
177
|
+
console.error(`${suffix},不支持的格式`);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
console.error(`${url},不支持的格式,请尝试使用 suffix 参数来指定一下格式`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return Object3d;
|
|
184
|
+
}
|
|
185
|
+
// 是否加载完成
|
|
186
|
+
onload = true;
|
|
187
|
+
}
|
|
188
|
+
const threeLoader = new ThreeLoader();
|
|
189
|
+
export default threeLoader;
|
package/threeUtils.d.ts
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { Box3, BufferGeometry, Clock, EventDispatcher, Object3D, Vector3 } from "three";
|
|
2
|
-
declare class ThreeUtils extends EventDispatcher {
|
|
3
|
-
constructor();
|
|
4
|
-
isProd: boolean;
|
|
5
|
-
isDev: boolean;
|
|
6
|
-
_timeTemp: number;
|
|
7
|
-
_accumulate: number;
|
|
8
|
-
_box3: Box3;
|
|
9
|
-
_size: Vector3;
|
|
10
|
-
_center: Vector3;
|
|
11
|
-
_clock: Clock;
|
|
12
|
-
requestAnimationFrame(): void;
|
|
13
|
-
private _keepZoomDoms;
|
|
14
|
-
/**
|
|
15
|
-
*计算需要保持比例的元素
|
|
16
|
-
*/
|
|
17
|
-
private _computerDomZoom;
|
|
18
|
-
/**
|
|
19
|
-
* dom元素保持比例
|
|
20
|
-
*/
|
|
21
|
-
keepZoom(dom: HTMLElement | null, width?: number, height?: number): void;
|
|
22
|
-
workList: Array<() => void>;
|
|
23
|
-
clock: Clock;
|
|
24
|
-
/**
|
|
25
|
-
* @param {() => void} [callback]
|
|
26
|
-
* @param {boolean} [first=true] 需要优先执行
|
|
27
|
-
*/
|
|
28
|
-
addWork(work?: () => void, first?: boolean): void;
|
|
29
|
-
/**
|
|
30
|
-
*判断一个元素是否在页面上
|
|
31
|
-
*/
|
|
32
|
-
inDocument(dom: ParentNode | null): boolean;
|
|
33
|
-
getCenter(object3d: Object3D | BufferGeometry): Vector3;
|
|
34
|
-
getSize(object3d: Object3D | BufferGeometry): Vector3;
|
|
35
|
-
alignBottom(object3d: Object3D | BufferGeometry, y?: number): void;
|
|
36
|
-
centerObject3D(object3d: Object3D | BufferGeometry): void;
|
|
37
|
-
center(object3d: Object3D | BufferGeometry): void;
|
|
38
|
-
scaleTo(object3d: Object3D | BufferGeometry, size?: number, key?: Array<"x" | "y" | "z">): void;
|
|
39
|
-
applyAllTranstion(object3d: Object3D): void;
|
|
40
|
-
exportGLB(input: Object3D, fileName?: string): void;
|
|
41
|
-
exportUsdz(): void;
|
|
42
|
-
getVolume(geometry: BufferGeometry): number;
|
|
43
|
-
signedVolumeOfTriangle(p1: Vector3, p2: Vector3, p3: Vector3): number;
|
|
44
|
-
dipose(object3d: Object3D): void;
|
|
45
|
-
}
|
|
46
|
-
declare const threeUtils: ThreeUtils;
|
|
47
|
-
export default threeUtils;
|
|
1
|
+
import { Box3, BufferGeometry, Clock, EventDispatcher, Object3D, Vector3 } from "three";
|
|
2
|
+
declare class ThreeUtils extends EventDispatcher {
|
|
3
|
+
constructor();
|
|
4
|
+
isProd: boolean;
|
|
5
|
+
isDev: boolean;
|
|
6
|
+
_timeTemp: number;
|
|
7
|
+
_accumulate: number;
|
|
8
|
+
_box3: Box3;
|
|
9
|
+
_size: Vector3;
|
|
10
|
+
_center: Vector3;
|
|
11
|
+
_clock: Clock;
|
|
12
|
+
requestAnimationFrame(): void;
|
|
13
|
+
private _keepZoomDoms;
|
|
14
|
+
/**
|
|
15
|
+
*计算需要保持比例的元素
|
|
16
|
+
*/
|
|
17
|
+
private _computerDomZoom;
|
|
18
|
+
/**
|
|
19
|
+
* dom元素保持比例
|
|
20
|
+
*/
|
|
21
|
+
keepZoom(dom: HTMLElement | null, width?: number, height?: number): void;
|
|
22
|
+
workList: Array<() => void>;
|
|
23
|
+
clock: Clock;
|
|
24
|
+
/**
|
|
25
|
+
* @param {() => void} [callback]
|
|
26
|
+
* @param {boolean} [first=true] 需要优先执行
|
|
27
|
+
*/
|
|
28
|
+
addWork(work?: () => void, first?: boolean): void;
|
|
29
|
+
/**
|
|
30
|
+
*判断一个元素是否在页面上
|
|
31
|
+
*/
|
|
32
|
+
inDocument(dom: ParentNode | null): boolean;
|
|
33
|
+
getCenter(object3d: Object3D | BufferGeometry): Vector3;
|
|
34
|
+
getSize(object3d: Object3D | BufferGeometry): Vector3;
|
|
35
|
+
alignBottom(object3d: Object3D | BufferGeometry, y?: number): void;
|
|
36
|
+
centerObject3D(object3d: Object3D | BufferGeometry): void;
|
|
37
|
+
center(object3d: Object3D | BufferGeometry): void;
|
|
38
|
+
scaleTo(object3d: Object3D | BufferGeometry, size?: number, key?: Array<"x" | "y" | "z">): void;
|
|
39
|
+
applyAllTranstion(object3d: Object3D): void;
|
|
40
|
+
exportGLB(input: Object3D, fileName?: string): void;
|
|
41
|
+
exportUsdz(): void;
|
|
42
|
+
getVolume(geometry: BufferGeometry): number;
|
|
43
|
+
signedVolumeOfTriangle(p1: Vector3, p2: Vector3, p3: Vector3): number;
|
|
44
|
+
dipose(object3d: Object3D): void;
|
|
45
|
+
}
|
|
46
|
+
declare const threeUtils: ThreeUtils;
|
|
47
|
+
export default threeUtils;
|