three-base 2.0.86 → 2.0.88

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.86",
3
+ "version": "2.0.88",
4
4
  "description": "three 3d three-base",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -18,7 +18,7 @@
18
18
  "module": "index.js",
19
19
  "types": "",
20
20
  "files": [
21
- "/**/*.ts",
21
+ "/**/*.d.ts",
22
22
  "/**/*.js",
23
23
  "/**/*.tsx",
24
24
  "/**/*.css",
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
  // 设置各向异性 由渲染器来调用并设置
package/ApngTexture.ts DELETED
@@ -1,91 +0,0 @@
1
-
2
-
3
- import parseAPNG, { APNG } from "apng-js";
4
- import Player from "apng-js/types/library/player";
5
- import axios from "axios";
6
- import { CanvasTexture } from "three";
7
- import threeUtils from "./threeUtils";
8
-
9
-
10
- export default class ApngTexture extends CanvasTexture {
11
-
12
- constructor(url: string) {
13
- super(document.createElement("canvas"));
14
- this.loadApng(url);
15
- }
16
- // 获取时间戳
17
- static TimeTemp = performance.now();
18
-
19
- // 上一次更新时间
20
- preUpdate = 0;
21
-
22
- player?: Player;
23
-
24
- // apng 对象
25
- apng?: APNG;
26
-
27
- // 更新纹理
28
- onUpdate = () => {
29
-
30
- if (this.preUpdate === ApngTexture.TimeTemp) {
31
- return;
32
- }
33
-
34
- this.preUpdate = ApngTexture.TimeTemp;
35
-
36
- if (this.player) {
37
- this.player.renderNextFrame();
38
- }
39
- };
40
-
41
- // 获取当前帧id
42
- getUuid() {
43
-
44
- if (this.apng) {
45
-
46
- let currentTime = ApngTexture.TimeTemp % this.apng.playTime;
47
-
48
- let i = 0;
49
- while (this.apng.frames[i] && currentTime > this.apng.frames[i].delay) {
50
- currentTime -= this.apng.frames[i].delay;
51
- i++;
52
- }
53
-
54
- return this.apng.frames[i].delay;
55
-
56
- } else {
57
-
58
- return "";
59
-
60
- }
61
-
62
- }
63
-
64
- // 加载apng图片
65
- async loadApng(url: string) {
66
-
67
- const res = await axios.get(url, { method: "post", responseType: "blob" });
68
-
69
- const blob = new Blob([res.data]);
70
-
71
- const reader = new FileReader();
72
-
73
- await new Promise<void>((resolve) => {
74
- reader.onload = () => resolve();
75
- reader.readAsArrayBuffer(blob);
76
- });
77
-
78
- const apng = (parseAPNG(reader.result as ArrayBuffer) as APNG);
79
-
80
- this.dispose();
81
- this.image.width = apng.width;
82
- this.image.height = apng.height;
83
- this.player = await apng.getPlayer(this.image.getContext("2d")!);
84
- }
85
-
86
- }
87
-
88
- // 定时更新时间戳
89
- threeUtils.addEventListener("requestAnimationFrame", (e: any) => {
90
- ApngTexture.TimeTemp = e.timeTemp;
91
- });
@@ -1,130 +0,0 @@
1
-
2
-
3
- import parseAPNG, { APNG } from "apng-js";
4
- import axios from "axios";
5
- import { isEmpty } from "lodash";
6
- import { MirroredRepeatWrapping, Texture, TextureLoader } from "three";
7
- import threeUtils from "./threeUtils";
8
-
9
-
10
-
11
- /**
12
- * apng 纹理管理对象
13
- */
14
- class apngTextureManage {
15
-
16
- constructor() {
17
-
18
- // 初始化定时更新时间戳
19
- if (apngTextureManage.isInit) {
20
- apngTextureManage.isInit = false;
21
- threeUtils.addEventListener("requestAnimationFrame5000", (e: any) => {
22
- apngTextureManage.TimeTemp = e.timeTemp;
23
- });
24
- }
25
-
26
- }
27
-
28
- static TextureLoader = new TextureLoader();
29
-
30
- static isInit = true;
31
-
32
- // 获取时间戳
33
- static TimeTemp = performance.now();
34
-
35
- // 每个动态纹理的播放总时长
36
- playTimes = new Map();
37
-
38
- // 保存所有的动态纹理
39
- anpgTextList: { [key: string]: Texture[] } = {};
40
-
41
- // 获取动态纹理 需要每帧都获取一下
42
- getTexture(path: string) {
43
- // 如果 没有这个纹理就返回空同时开始加载这个纹理
44
- if (!this.anpgTextList[path]) {
45
- this.anpgTextList[path] = [];
46
-
47
- this.loadApng(path);
48
-
49
- return null;
50
-
51
- } else if (isEmpty(this.anpgTextList[path])) {
52
-
53
- return null;
54
-
55
- } else {
56
-
57
- const playTime = this.playTimes.get(path);
58
- let currentTime = apngTextureManage.TimeTemp % playTime;
59
-
60
- let i = 0;
61
- while (this.anpgTextList[path][i] && currentTime > Number(this.anpgTextList[path][i].name)) {
62
- currentTime -= Number(this.anpgTextList[path][i].name);
63
- i++;
64
- }
65
-
66
- this.anpgTextList[path][i].needsUpdate = true;
67
-
68
- return this.anpgTextList[path][i];
69
- }
70
- }
71
-
72
- // 加载apng图片
73
- async loadApng(url: string) {
74
-
75
- const res = await axios.get(url, { method: "post", responseType: "blob" });
76
-
77
- const blob = new Blob([res.data]);
78
-
79
- const reader = new FileReader();
80
-
81
- await new Promise<void>((resolve) => {
82
- reader.onload = () => resolve();
83
- reader.readAsArrayBuffer(blob);
84
- });
85
-
86
- const apng = (parseAPNG(reader.result as ArrayBuffer) as APNG);
87
-
88
- // 存储播放时长
89
- this.playTimes.set(url, apng.playTime);
90
-
91
- // for (let i = 0; i < apng.frames.length; i++) {
92
- // const frame = apng.frames[i];
93
- // frame.createImage();
94
- // await new Promise(resolve => frame.imageElement!.onload = resolve);
95
- // }
96
-
97
- for (let i = 0; i < apng.frames.length; i++) {
98
- const frame = apng.frames[i];
99
-
100
- var blobUrl = URL.createObjectURL(frame.imageData!);
101
-
102
- const texture = apngTextureManage.TextureLoader.load(blobUrl);
103
-
104
- texture.anisotropy = 16;
105
-
106
- texture.wrapS = texture.wrapT = MirroredRepeatWrapping;
107
-
108
- // export const RepeatWrapping: Wrapping;
109
- // export const ClampToEdgeWrapping: Wrapping;
110
- // export const MirroredRepeatWrapping: Wrapping;
111
-
112
- // magFilter: TextureFilter;
113
- // minFilter: TextureFilter;
114
-
115
-
116
- texture.name = String(frame.delay);
117
- texture.center.set(0.5, 0.5);
118
- texture.repeat.set(apng.width / frame.width, apng.height / frame.height);
119
- // texture.needsUpdate = true;
120
- this.anpgTextList[url].push(texture);
121
- }
122
-
123
- }
124
-
125
-
126
- }
127
-
128
- const ApngTextureManage = new apngTextureManage();
129
-
130
- export default ApngTextureManage;
package/EventMesh.ts DELETED
@@ -1,79 +0,0 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2022-03-20 12:55:37
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2023-02-07 11:19:56
6
- */
7
-
8
- import { BoxGeometry, BufferGeometry, CylinderGeometry, DoubleSide, FrontSide, Material, Mesh, MeshBasicMaterial, MeshNormalMaterial } from "three";
9
- import threeUtils from "./threeUtils";
10
-
11
- // 碰撞的形状
12
- export enum CollisionShaere {
13
- cube = "cube", // 正方体
14
- cylinder = "cylinder" // 圆柱体
15
- }
16
-
17
- /**
18
- * 碰撞检测用的模型
19
- */
20
- export default class EventMesh extends Mesh<BufferGeometry, Material> {
21
-
22
- constructor(type: CollisionShaere = CollisionShaere.cube) {
23
- super();
24
-
25
- this.material = EventMesh.material;
26
-
27
- this.setType(type);
28
-
29
- // 生产环境 不用渲染
30
- if (threeUtils.isProd) {
31
- this.material = new MeshBasicMaterial({
32
- side: DoubleSide,
33
- transparent: true,
34
- opacity: 0.25,
35
- alphaTest: 1
36
- });
37
- }
38
- }
39
-
40
- static type = CollisionShaere;
41
-
42
- static material = new MeshNormalMaterial({
43
- side: DoubleSide,
44
- transparent: true,
45
- opacity: 0.3,
46
- });
47
-
48
- renderOrder = 99;
49
-
50
- // 正方体 网格模型
51
- static cubeGeo = new BoxGeometry(1, 1, 1, 1, 1, 1);
52
-
53
- // 圆柱体 网格模型
54
- static cylinderGeo = new CylinderGeometry(1, 1, 1, 50, 1, false, 0, Math.PI * 2);
55
-
56
- // 是否是碰撞检测专用的模型
57
- isEventMesh = true;
58
-
59
- setType(type: CollisionShaere) {
60
-
61
- switch (type) {
62
- case EventMesh.type.cube:
63
- this.geometry = EventMesh.cubeGeo;
64
- break;
65
-
66
- case EventMesh.type.cylinder:
67
- this.geometry = EventMesh.cylinderGeo;
68
- break;
69
-
70
- default:
71
- break;
72
- }
73
-
74
- this.geometry.computeVertexNormals();
75
-
76
-
77
- }
78
-
79
- }