three-base 1.0.81 → 1.0.82

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.
@@ -1,34 +1,82 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
1
52
  import parseAPNG from "apng-js";
2
53
  import axios from "axios";
3
54
  import { CanvasTexture } from "three";
4
55
  import threeUtils from "./threeUtils";
5
- export default class ApngTexture extends CanvasTexture {
6
- constructor(url) {
7
- super(document.createElement("canvas"));
8
- this.loadApng(url);
56
+ var ApngTexture = /** @class */ (function (_super) {
57
+ __extends(ApngTexture, _super);
58
+ function ApngTexture(url) {
59
+ var _this = _super.call(this, document.createElement("canvas")) || this;
60
+ // 上一次更新时间
61
+ _this.preUpdate = 0;
62
+ // 更新纹理
63
+ _this.onUpdate = function () {
64
+ if (_this.preUpdate === ApngTexture.TimeTemp) {
65
+ return;
66
+ }
67
+ _this.preUpdate = ApngTexture.TimeTemp;
68
+ if (_this.player) {
69
+ _this.player.renderNextFrame();
70
+ }
71
+ };
72
+ _this.loadApng(url);
73
+ return _this;
9
74
  }
10
- // 获取时间戳
11
- static TimeTemp = performance.now();
12
- // 上一次更新时间
13
- preUpdate = 0;
14
- player;
15
- // apng 对象
16
- apng;
17
- // 更新纹理
18
- onUpdate = () => {
19
- if (this.preUpdate === ApngTexture.TimeTemp) {
20
- return;
21
- }
22
- this.preUpdate = ApngTexture.TimeTemp;
23
- if (this.player) {
24
- this.player.renderNextFrame();
25
- }
26
- };
27
75
  // 获取当前帧id
28
- getUuid() {
76
+ ApngTexture.prototype.getUuid = function () {
29
77
  if (this.apng) {
30
- let currentTime = ApngTexture.TimeTemp % this.apng.playTime;
31
- let i = 0;
78
+ var currentTime = ApngTexture.TimeTemp % this.apng.playTime;
79
+ var i = 0;
32
80
  while (this.apng.frames[i] && currentTime > this.apng.frames[i].delay) {
33
81
  currentTime -= this.apng.frames[i].delay;
34
82
  i++;
@@ -38,24 +86,43 @@ export default class ApngTexture extends CanvasTexture {
38
86
  else {
39
87
  return "";
40
88
  }
41
- }
89
+ };
42
90
  // 加载apng图片
43
- async loadApng(url) {
44
- const res = await axios.get(url, { method: "post", responseType: "blob" });
45
- const blob = new Blob([res.data]);
46
- const reader = new FileReader();
47
- await new Promise((resolve) => {
48
- reader.onload = () => resolve();
49
- reader.readAsArrayBuffer(blob);
91
+ ApngTexture.prototype.loadApng = function (url) {
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ var res, blob, reader, apng, _a;
94
+ return __generator(this, function (_b) {
95
+ switch (_b.label) {
96
+ case 0: return [4 /*yield*/, axios.get(url, { method: "post", responseType: "blob" })];
97
+ case 1:
98
+ res = _b.sent();
99
+ blob = new Blob([res.data]);
100
+ reader = new FileReader();
101
+ return [4 /*yield*/, new Promise(function (resolve) {
102
+ reader.onload = function () { return resolve(); };
103
+ reader.readAsArrayBuffer(blob);
104
+ })];
105
+ case 2:
106
+ _b.sent();
107
+ apng = parseAPNG(reader.result);
108
+ this.dispose();
109
+ this.image.width = apng.width;
110
+ this.image.height = apng.height;
111
+ _a = this;
112
+ return [4 /*yield*/, apng.getPlayer(this.image.getContext("2d"))];
113
+ case 3:
114
+ _a.player = _b.sent();
115
+ return [2 /*return*/];
116
+ }
117
+ });
50
118
  });
51
- const apng = parseAPNG(reader.result);
52
- this.dispose();
53
- this.image.width = apng.width;
54
- this.image.height = apng.height;
55
- this.player = await apng.getPlayer(this.image.getContext("2d"));
56
- }
57
- }
119
+ };
120
+ // 获取时间戳
121
+ ApngTexture.TimeTemp = performance.now();
122
+ return ApngTexture;
123
+ }(CanvasTexture));
124
+ export default ApngTexture;
58
125
  // 定时更新时间戳
59
- threeUtils.addEventListener("requestAnimationFrame", (e) => {
126
+ threeUtils.addEventListener("requestAnimationFrame", function (e) {
60
127
  ApngTexture.TimeTemp = e.timeTemp;
61
128
  });
@@ -1,3 +1,39 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
1
37
  import parseAPNG from "apng-js";
2
38
  import axios from "axios";
3
39
  import { isEmpty } from "lodash";
@@ -6,26 +42,22 @@ import threeUtils from "./threeUtils";
6
42
  /**
7
43
  * apng 纹理管理对象
8
44
  */
9
- class apngTextureManage {
10
- constructor() {
45
+ var apngTextureManage = /** @class */ (function () {
46
+ function apngTextureManage() {
47
+ // 每个动态纹理的播放总时长
48
+ this.playTimes = new Map();
49
+ // 保存所有的动态纹理
50
+ this.anpgTextList = {};
11
51
  // 初始化定时更新时间戳
12
52
  if (apngTextureManage.isInit) {
13
53
  apngTextureManage.isInit = false;
14
- threeUtils.addEventListener("requestAnimationFrame5000", (e) => {
54
+ threeUtils.addEventListener("requestAnimationFrame5000", function (e) {
15
55
  apngTextureManage.TimeTemp = e.timeTemp;
16
56
  });
17
57
  }
18
58
  }
19
- static TextureLoader = new TextureLoader();
20
- static isInit = true;
21
- // 获取时间戳
22
- static TimeTemp = performance.now();
23
- // 每个动态纹理的播放总时长
24
- playTimes = new Map();
25
- // 保存所有的动态纹理
26
- anpgTextList = {};
27
59
  // 获取动态纹理 需要每帧都获取一下
28
- getTexture(path) {
60
+ apngTextureManage.prototype.getTexture = function (path) {
29
61
  // 如果 没有这个纹理就返回空同时开始加载这个纹理
30
62
  if (!this.anpgTextList[path]) {
31
63
  this.anpgTextList[path] = [];
@@ -36,9 +68,9 @@ class apngTextureManage {
36
68
  return null;
37
69
  }
38
70
  else {
39
- const playTime = this.playTimes.get(path);
40
- let currentTime = apngTextureManage.TimeTemp % playTime;
41
- let i = 0;
71
+ var playTime = this.playTimes.get(path);
72
+ var currentTime = apngTextureManage.TimeTemp % playTime;
73
+ var i = 0;
42
74
  while (this.anpgTextList[path][i] && currentTime > Number(this.anpgTextList[path][i].name)) {
43
75
  currentTime -= Number(this.anpgTextList[path][i].name);
44
76
  i++;
@@ -46,42 +78,59 @@ class apngTextureManage {
46
78
  this.anpgTextList[path][i].needsUpdate = true;
47
79
  return this.anpgTextList[path][i];
48
80
  }
49
- }
81
+ };
50
82
  // 加载apng图片
51
- async loadApng(url) {
52
- const res = await axios.get(url, { method: "post", responseType: "blob" });
53
- const blob = new Blob([res.data]);
54
- const reader = new FileReader();
55
- await new Promise((resolve) => {
56
- reader.onload = () => resolve();
57
- reader.readAsArrayBuffer(blob);
83
+ apngTextureManage.prototype.loadApng = function (url) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var res, blob, reader, apng, i, frame, blobUrl, texture;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0: return [4 /*yield*/, axios.get(url, { method: "post", responseType: "blob" })];
89
+ case 1:
90
+ res = _a.sent();
91
+ blob = new Blob([res.data]);
92
+ reader = new FileReader();
93
+ return [4 /*yield*/, new Promise(function (resolve) {
94
+ reader.onload = function () { return resolve(); };
95
+ reader.readAsArrayBuffer(blob);
96
+ })];
97
+ case 2:
98
+ _a.sent();
99
+ apng = parseAPNG(reader.result);
100
+ // 存储播放时长
101
+ this.playTimes.set(url, apng.playTime);
102
+ // for (let i = 0; i < apng.frames.length; i++) {
103
+ // const frame = apng.frames[i];
104
+ // frame.createImage();
105
+ // await new Promise(resolve => frame.imageElement!.onload = resolve);
106
+ // }
107
+ for (i = 0; i < apng.frames.length; i++) {
108
+ frame = apng.frames[i];
109
+ blobUrl = URL.createObjectURL(frame.imageData);
110
+ texture = apngTextureManage.TextureLoader.load(blobUrl);
111
+ texture.anisotropy = 16;
112
+ texture.wrapS = texture.wrapT = MirroredRepeatWrapping;
113
+ // export const RepeatWrapping: Wrapping;
114
+ // export const ClampToEdgeWrapping: Wrapping;
115
+ // export const MirroredRepeatWrapping: Wrapping;
116
+ // magFilter: TextureFilter;
117
+ // minFilter: TextureFilter;
118
+ texture.name = String(frame.delay);
119
+ texture.center.set(0.5, 0.5);
120
+ texture.repeat.set(apng.width / frame.width, apng.height / frame.height);
121
+ // texture.needsUpdate = true;
122
+ this.anpgTextList[url].push(texture);
123
+ }
124
+ return [2 /*return*/];
125
+ }
126
+ });
58
127
  });
59
- const apng = parseAPNG(reader.result);
60
- // 存储播放时长
61
- this.playTimes.set(url, apng.playTime);
62
- // for (let i = 0; i < apng.frames.length; i++) {
63
- // const frame = apng.frames[i];
64
- // frame.createImage();
65
- // await new Promise(resolve => frame.imageElement!.onload = resolve);
66
- // }
67
- for (let i = 0; i < apng.frames.length; i++) {
68
- const frame = apng.frames[i];
69
- var blobUrl = URL.createObjectURL(frame.imageData);
70
- const texture = apngTextureManage.TextureLoader.load(blobUrl);
71
- texture.anisotropy = 16;
72
- texture.wrapS = texture.wrapT = MirroredRepeatWrapping;
73
- // export const RepeatWrapping: Wrapping;
74
- // export const ClampToEdgeWrapping: Wrapping;
75
- // export const MirroredRepeatWrapping: Wrapping;
76
- // magFilter: TextureFilter;
77
- // minFilter: TextureFilter;
78
- texture.name = String(frame.delay);
79
- texture.center.set(0.5, 0.5);
80
- texture.repeat.set(apng.width / frame.width, apng.height / frame.height);
81
- // texture.needsUpdate = true;
82
- this.anpgTextList[url].push(texture);
83
- }
84
- }
85
- }
86
- const ApngTextureManage = new apngTextureManage();
128
+ };
129
+ apngTextureManage.TextureLoader = new TextureLoader();
130
+ apngTextureManage.isInit = true;
131
+ // 获取时间戳
132
+ apngTextureManage.TimeTemp = performance.now();
133
+ return apngTextureManage;
134
+ }());
135
+ var ApngTextureManage = new apngTextureManage();
87
136
  export default ApngTextureManage;
package/lib/EventMesh.js CHANGED
@@ -4,6 +4,21 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2023-02-07 11:19:56
6
6
  */
7
+ var __extends = (this && this.__extends) || (function () {
8
+ var extendStatics = function (d, b) {
9
+ extendStatics = Object.setPrototypeOf ||
10
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
12
+ return extendStatics(d, b);
13
+ };
14
+ return function (d, b) {
15
+ if (typeof b !== "function" && b !== null)
16
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17
+ extendStatics(d, b);
18
+ function __() { this.constructor = d; }
19
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
20
+ };
21
+ })();
7
22
  import { BoxGeometry, CylinderGeometry, DoubleSide, Mesh, MeshBasicMaterial, MeshNormalMaterial } from "three";
8
23
  import threeUtils from "./threeUtils";
9
24
  // 碰撞的形状
@@ -15,35 +30,28 @@ export var CollisionShaere;
15
30
  /**
16
31
  * 碰撞检测用的模型
17
32
  */
18
- export default class EventMesh extends Mesh {
19
- constructor(type = CollisionShaere.cube) {
20
- super();
21
- this.material = EventMesh.material;
22
- this.setType(type);
33
+ var EventMesh = /** @class */ (function (_super) {
34
+ __extends(EventMesh, _super);
35
+ function EventMesh(type) {
36
+ if (type === void 0) { type = CollisionShaere.cube; }
37
+ var _this = _super.call(this) || this;
38
+ _this.renderOrder = 99;
39
+ // 是否是碰撞检测专用的模型
40
+ _this.isEventMesh = true;
41
+ _this.material = EventMesh.material;
42
+ _this.setType(type);
23
43
  // 生产环境 不用渲染
24
44
  if (threeUtils.isProd) {
25
- this.material = new MeshBasicMaterial({
45
+ _this.material = new MeshBasicMaterial({
26
46
  side: DoubleSide,
27
47
  transparent: true,
28
48
  opacity: 0.25,
29
49
  alphaTest: 1
30
50
  });
31
51
  }
52
+ return _this;
32
53
  }
33
- static type = CollisionShaere;
34
- static material = new MeshNormalMaterial({
35
- side: DoubleSide,
36
- transparent: true,
37
- opacity: 0.3,
38
- });
39
- renderOrder = 99;
40
- // 正方体 网格模型
41
- static cubeGeo = new BoxGeometry(1, 1, 1, 1, 1, 1);
42
- // 圆柱体 网格模型
43
- static cylinderGeo = new CylinderGeometry(1, 1, 1, 50, 1, false, 0, Math.PI * 2);
44
- // 是否是碰撞检测专用的模型
45
- isEventMesh = true;
46
- setType(type) {
54
+ EventMesh.prototype.setType = function (type) {
47
55
  switch (type) {
48
56
  case EventMesh.type.cube:
49
57
  this.geometry = EventMesh.cubeGeo;
@@ -55,5 +63,17 @@ export default class EventMesh extends Mesh {
55
63
  break;
56
64
  }
57
65
  this.geometry.computeVertexNormals();
58
- }
59
- }
66
+ };
67
+ EventMesh.type = CollisionShaere;
68
+ EventMesh.material = new MeshNormalMaterial({
69
+ side: DoubleSide,
70
+ transparent: true,
71
+ opacity: 0.3,
72
+ });
73
+ // 正方体 网格模型
74
+ EventMesh.cubeGeo = new BoxGeometry(1, 1, 1, 1, 1, 1);
75
+ // 圆柱体 网格模型
76
+ EventMesh.cylinderGeo = new CylinderGeometry(1, 1, 1, 50, 1, false, 0, Math.PI * 2);
77
+ return EventMesh;
78
+ }(Mesh));
79
+ export default EventMesh;