three-base 2.0.100 → 2.0.102

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/Grass/grass.jpg CHANGED
Binary file
Binary file
Binary file
Binary file
@@ -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>;
@@ -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.add(model);
97
+ this.reset(model);
94
98
  }
95
99
  else {
96
- this.add(mesh.clone(true));
100
+ this.reset(mesh.clone(true));
97
101
  }
98
102
  }
99
103
  await new Promise((resolve) => requestAnimationFrame(resolve));
Binary file
package/Sky/skyMap.png CHANGED
Binary file
Binary file
package/ThreeBase.js CHANGED
@@ -539,7 +539,6 @@ export default class ThreeBase extends EventDispatcher {
539
539
  async download(fileName = "download") {
540
540
  this.render();
541
541
  const blob = await this.getThumbBlob();
542
- const base64 = this.renderer.domElement.toDataURL("image/png");
543
542
  let saveLink = document.createElement("a");
544
543
  saveLink.download = `${fileName}.png`;
545
544
  saveLink.href = URL.createObjectURL(blob);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "2.0.100",
3
+ "version": "2.0.102",
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
+ getFilename(url: string): string;
10
11
  uuid: string;
11
12
  anisotropy: number;
12
13
  setAnisotropy(v: number): void;
package/threeLoader.js CHANGED
@@ -49,18 +49,30 @@ class ThreeLoader extends EventDispatcher {
49
49
  };
50
50
  // 资源替换
51
51
  DefaultLoadingManager.setURLModifier((url) => {
52
+ //全路径匹配资源
53
+ if (this._blobs[url]) {
54
+ return this._blobs[url];
55
+ }
52
56
  const filename = url
53
57
  .replace(`blob:${location.origin}/`, "")
54
58
  .replace(/^\.\//, "");
55
59
  let new_url = this._blobs[filename] || url;
56
60
  //如果全匹配没有匹配到资源,就尝试文件名匹配
57
61
  if (!this._blobs[filename]) {
58
- const blobKey = Object.keys(this._blobs).find((key) => new RegExp(`${key}$`).test(filename)) || "";
62
+ const blobKey = Object.keys(this._blobs).find((key) => this.getFilename(key) === this.getFilename(filename)) || "";
59
63
  new_url = this._blobs[blobKey] || url;
60
64
  }
61
65
  return new_url;
62
66
  });
63
67
  }
68
+ // 从url 中提取文件名
69
+ getFilename(url) {
70
+ // 移除URL的查询字符串和哈希部分
71
+ const path = url.split("?")[0].split("#")[0];
72
+ // 使用lastIndexOf和substring从路径中提取文件名
73
+ const filename = path.substring(path.lastIndexOf("/") + 1);
74
+ return filename;
75
+ }
64
76
  uuid = generateUUID();
65
77
  // 各向异性
66
78
  anisotropy = 16;