three-base 2.0.85 → 2.0.87

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "2.0.85",
3
+ "version": "2.0.87",
4
4
  "description": "three 3d three-base",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
package/threeLoader.d.ts CHANGED
@@ -7,6 +7,7 @@ import { STLLoader } from "three/examples/jsm/loaders/STLLoader";
7
7
  import { USDZLoader } from "three/examples/jsm/loaders/USDZLoader";
8
8
  declare class ThreeLoader extends EventDispatcher {
9
9
  constructor();
10
+ uuid: string;
10
11
  anisotropy: number;
11
12
  setAnisotropy(v: number): void;
12
13
  textureMap: Map<string, Texture>;
package/threeLoader.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author: xiaosihan
3
3
  * @Date: 2022-04-07 16:42:26
4
4
  * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2023-02-07 11:11:48
5
+ * @Last Modified time: 2024-09-11 11:43:31
6
6
  */
7
7
  import { CanvasTexture, DefaultLoadingManager, EventDispatcher, Mesh, MeshStandardMaterial, RepeatWrapping, TextureLoader, VideoTexture, } from "three";
8
8
  import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
@@ -24,6 +24,7 @@ import dracoDecoderJS from "./lib/draco/draco_decoder.js?url";
24
24
  import axios from "axios";
25
25
  import dracoDecoderWASM from "./lib/draco/draco_decoder.wasm?url";
26
26
  import threeUtils from "./threeUtils";
27
+ import { generateUUID } from "three/src/math/MathUtils";
27
28
  // 加载器
28
29
  class ThreeLoader extends EventDispatcher {
29
30
  constructor() {
@@ -57,6 +58,7 @@ class ThreeLoader extends EventDispatcher {
57
58
  return new_url;
58
59
  });
59
60
  }
61
+ uuid = generateUUID();
60
62
  // 各向异性
61
63
  anisotropy = 16;
62
64
  // 设置各向异性 由渲染器来调用并设置
@@ -317,6 +319,29 @@ class ThreeLoader extends EventDispatcher {
317
319
  .catch((err) => {
318
320
  console.log(`${url},加载失败`, err);
319
321
  });
322
+ case "obj":
323
+ const objObject3d = await this.objLoader.loadAsync(url);
324
+ objObject3d.traverse((obj) => {
325
+ const mesh = obj;
326
+ if (mesh.isMesh) {
327
+ // 如果obj没有材质就给默认的材质
328
+ if (!this.objLoader.materials) {
329
+ mesh.material = new MeshStandardMaterial({
330
+ metalness: 0.5,
331
+ roughness: 0.5,
332
+ });
333
+ }
334
+ const uv = mesh.geometry.getAttribute("uv");
335
+ if (uv) {
336
+ for (let i = 0; i < uv.count; i++) {
337
+ uv.setY(i, 1 - uv.getY(i));
338
+ }
339
+ }
340
+ // obj只翻转uv不翻转贴图
341
+ this.setFlipYIsFalse(mesh.material);
342
+ }
343
+ });
344
+ return objObject3d;
320
345
  default:
321
346
  if (suffix) {
322
347
  console.log(`${suffix},不支持的格式`);
package/threeLoader.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author: xiaosihan
3
3
  * @Date: 2022-04-07 16:42:26
4
4
  * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2023-02-07 11:11:48
5
+ * @Last Modified time: 2024-09-11 11:43:31
6
6
  */
7
7
 
8
8
  import {
@@ -38,6 +38,7 @@ import dracoDecoderJS from "./lib/draco/draco_decoder.js?url";
38
38
  import axios from "axios";
39
39
  import dracoDecoderWASM from "./lib/draco/draco_decoder.wasm?url";
40
40
  import threeUtils from "./threeUtils";
41
+ import { generateUUID } from "three/src/math/MathUtils";
41
42
 
42
43
  // 加载器
43
44
  class ThreeLoader extends EventDispatcher {
@@ -83,6 +84,8 @@ class ThreeLoader extends EventDispatcher {
83
84
  });
84
85
  }
85
86
 
87
+ uuid = generateUUID();
88
+
86
89
  // 各向异性
87
90
  anisotropy = 16;
88
91
 
@@ -399,6 +402,32 @@ class ThreeLoader extends EventDispatcher {
399
402
  console.log(`${url},加载失败`, err);
400
403
  });
401
404
 
405
+ case "obj":
406
+ const objObject3d = await this.objLoader.loadAsync(url);
407
+ objObject3d.traverse((obj) => {
408
+ const mesh = obj as Mesh;
409
+
410
+ if (mesh.isMesh) {
411
+ // 如果obj没有材质就给默认的材质
412
+ if (!this.objLoader.materials) {
413
+ mesh.material = new MeshStandardMaterial({
414
+ metalness: 0.5,
415
+ roughness: 0.5,
416
+ });
417
+ }
418
+
419
+ const uv = mesh.geometry.getAttribute("uv");
420
+ if (uv) {
421
+ for (let i = 0; i < uv.count; i++) {
422
+ uv.setY(i, 1 - uv.getY(i));
423
+ }
424
+ }
425
+ // obj只翻转uv不翻转贴图
426
+ this.setFlipYIsFalse(mesh.material);
427
+ }
428
+ });
429
+ return objObject3d;
430
+
402
431
  default:
403
432
  if (suffix) {
404
433
  console.log(`${suffix},不支持的格式`);