three-base 2.0.99 → 2.0.100
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/ThreeBase.js +4 -3
- package/package.json +1 -1
- package/threeLoader.js +10 -3
package/ThreeBase.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @Last Modified time: 2024-09-23 21:20:32
|
|
6
6
|
*/
|
|
7
7
|
import { round } from "lodash";
|
|
8
|
-
import { AxesHelper, Box3, DepthFormat, DepthTexture, EventDispatcher, GridHelper, LinearFilter, MOUSE, Mesh, NoBlending, NormalBlending, OrthographicCamera, PerspectiveCamera, RGBAFormat, Scene, TOUCH, UnsignedShortType, Vector2, Vector3, WebGLRenderTarget, WebGLRenderer, } from "three";
|
|
8
|
+
import { AxesHelper, Box3, DepthFormat, DepthTexture, EventDispatcher, GridHelper, LinearFilter, MOUSE, Mesh, NoBlending, NormalBlending, OrthographicCamera, PerspectiveCamera, RGBAFormat, SRGBColorSpace, Scene, TOUCH, UnsignedShortType, Vector2, Vector3, WebGLRenderTarget, WebGLRenderer, } from "three";
|
|
9
9
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
10
10
|
import { degToRad, generateUUID } from "three/src/math/MathUtils";
|
|
11
11
|
import ThreeMouse from "./ThreeMouse";
|
|
@@ -99,6 +99,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
99
99
|
renderer.setPixelRatio(window.devicePixelRatio);
|
|
100
100
|
renderer.autoClear = false;
|
|
101
101
|
renderer.clear();
|
|
102
|
+
renderer.outputColorSpace = SRGBColorSpace;
|
|
102
103
|
threeLoader.setAnisotropy(renderer.capabilities.getMaxAnisotropy());
|
|
103
104
|
return renderer;
|
|
104
105
|
})();
|
|
@@ -271,7 +272,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
271
272
|
return axesHelper;
|
|
272
273
|
})();
|
|
273
274
|
//TODO 设置帧频率 默认50帧
|
|
274
|
-
frame =
|
|
275
|
+
frame = 30;
|
|
275
276
|
init() { }
|
|
276
277
|
// 重置控制器的位置
|
|
277
278
|
resetLookAt({ position = this.perspectiveCamera.position, center = this.controls.target, }) {
|
|
@@ -360,7 +361,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
360
361
|
lookatObjects({ objects, duration = 1000, direction = new Vector3(0.3, 0.3, 1), offset = new Vector3(0, 0, 0), distance = 1, }) {
|
|
361
362
|
const box3 = new Box3();
|
|
362
363
|
objects.map((o) => {
|
|
363
|
-
o.
|
|
364
|
+
o.traverseVisible((oo) => {
|
|
364
365
|
box3.expandByObject(oo);
|
|
365
366
|
});
|
|
366
367
|
});
|
package/package.json
CHANGED
package/threeLoader.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2024-09-11 11:43:31
|
|
6
6
|
*/
|
|
7
|
-
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, Mesh, MeshStandardMaterial, RepeatWrapping, TextureLoader, VideoTexture, } from "three";
|
|
7
|
+
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, Mesh, MeshStandardMaterial, RepeatWrapping, SRGBColorSpace, TextureLoader, VideoTexture, } from "three";
|
|
8
8
|
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
|
9
9
|
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
10
10
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
@@ -26,6 +26,8 @@ import { isArray, isEmpty, isNull, isString, isUndefined } from "lodash";
|
|
|
26
26
|
import { generateUUID } from "three/src/math/MathUtils";
|
|
27
27
|
import dracoDecoderWASM from "./lib/draco/draco_decoder.wasm?url";
|
|
28
28
|
import threeUtils from "./threeUtils";
|
|
29
|
+
import { TGALoader } from "three/examples/jsm/Addons.js";
|
|
30
|
+
DefaultLoadingManager.addHandler(/tga$/, new TGALoader());
|
|
29
31
|
// 加载器
|
|
30
32
|
class ThreeLoader extends EventDispatcher {
|
|
31
33
|
constructor() {
|
|
@@ -76,7 +78,7 @@ class ThreeLoader extends EventDispatcher {
|
|
|
76
78
|
const canvasTexture = new CanvasTexture(src);
|
|
77
79
|
canvasTexture.wrapS = canvasTexture.wrapT = RepeatWrapping;
|
|
78
80
|
canvasTexture.anisotropy = this.anisotropy;
|
|
79
|
-
|
|
81
|
+
canvasTexture.colorSpace = SRGBColorSpace;
|
|
80
82
|
return canvasTexture;
|
|
81
83
|
}
|
|
82
84
|
let texture = this.textureMap.get(src);
|
|
@@ -110,7 +112,7 @@ class ThreeLoader extends EventDispatcher {
|
|
|
110
112
|
}
|
|
111
113
|
texture.wrapS = texture.wrapT = RepeatWrapping;
|
|
112
114
|
texture.anisotropy = this.anisotropy;
|
|
113
|
-
|
|
115
|
+
texture.colorSpace = SRGBColorSpace;
|
|
114
116
|
return texture;
|
|
115
117
|
}
|
|
116
118
|
// 资源列表
|
|
@@ -344,6 +346,11 @@ class ThreeLoader extends EventDispatcher {
|
|
|
344
346
|
if (stl) {
|
|
345
347
|
return await this.loadModel(stl);
|
|
346
348
|
}
|
|
349
|
+
//如果有zip文件就加载zip文件
|
|
350
|
+
let zipFile = Object.keys(zip.files).find((filename) => /\.stl$/.test(filename));
|
|
351
|
+
if (zipFile) {
|
|
352
|
+
return await this.loadModel(zipFile);
|
|
353
|
+
}
|
|
347
354
|
if ([obj, gltf, dae, fbx, usdz, stl].every((v) => !v)) {
|
|
348
355
|
throw new Error(`${url}压缩包里没有obj.glb.gltf.dae.fbx.usde.stl等模型文件`);
|
|
349
356
|
}
|