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.
- package/lib/ApngTexture.js +107 -40
- package/lib/ApngTextureManage.js +100 -51
- package/lib/EventMesh.js +42 -22
- package/lib/ExtrudeMesh.js +178 -147
- package/lib/FPScontrol.js +133 -116
- package/lib/InstancedGroupMesh.js +45 -25
- package/lib/KeyFrameAnimation.js +54 -37
- package/lib/PlaneText.js +34 -14
- package/lib/PlaneWithHtml.js +126 -48
- package/lib/PointLight/PointLight.js +65 -45
- package/lib/Sky/Sky.js +30 -11
- package/lib/SpriteText2.js +166 -90
- package/lib/Text3D/Text3D.js +61 -40
- package/lib/Text3D/fontController.js +284 -149
- package/lib/ThreeBase.js +341 -204
- package/lib/ThreeMouse.js +203 -244
- package/lib/Transition.js +161 -95
- package/lib/keyContorls.js +102 -74
- package/lib/planeModal1/PlaneModal1.js +162 -90
- package/lib/shaders.js +36 -178
- package/lib/spriteModal1/SpriteModal1.js +165 -93
- package/lib/threeLoader.js +89 -66
- package/lib/threeUtils.js +84 -59
- package/package.json +1 -1
package/lib/threeUtils.js
CHANGED
|
@@ -4,82 +4,104 @@
|
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2023-03-16 14:34:49
|
|
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 { Box3, BufferGeometry, Clock, EventDispatcher, Object3D, Vector3 } from "three";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
var ThreeUtils = /** @class */ (function (_super) {
|
|
24
|
+
__extends(ThreeUtils, _super);
|
|
25
|
+
function ThreeUtils() {
|
|
26
|
+
var _this = _super.call(this) || this;
|
|
27
|
+
//@ts-ignore
|
|
28
|
+
_this.isProd = (process.env.NODE_ENV === "production");
|
|
29
|
+
//@ts-ignore
|
|
30
|
+
_this.isDev = (process.env.NODE_ENV === "development");
|
|
31
|
+
_this._timeTemp = performance.now();
|
|
32
|
+
_this._accumulate = 0; // 事件分发次数
|
|
33
|
+
_this._box3 = new Box3();
|
|
34
|
+
_this._size = new Vector3();
|
|
35
|
+
_this._center = new Vector3();
|
|
36
|
+
_this._clock = new Clock();
|
|
37
|
+
// 需要保持宽高比的元素列表
|
|
38
|
+
_this._keepZoomDoms = [];
|
|
39
|
+
_this.workList = [];
|
|
40
|
+
// 时钟对象
|
|
41
|
+
_this.clock = new Clock();
|
|
42
|
+
_this.requestAnimationFrame();
|
|
43
|
+
return _this;
|
|
12
44
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//@ts-ignore
|
|
16
|
-
isDev = (process.env.NODE_ENV === "development");
|
|
17
|
-
_timeTemp = performance.now();
|
|
18
|
-
_accumulate = 0; // 事件分发次数
|
|
19
|
-
_box3 = new Box3();
|
|
20
|
-
_size = new Vector3();
|
|
21
|
-
_center = new Vector3();
|
|
22
|
-
_clock = new Clock();
|
|
23
|
-
requestAnimationFrame() {
|
|
45
|
+
ThreeUtils.prototype.requestAnimationFrame = function () {
|
|
46
|
+
var _this = this;
|
|
24
47
|
this._accumulate += 1;
|
|
25
|
-
|
|
48
|
+
var timeTemp = this._timeTemp = performance.now();
|
|
26
49
|
this.dispatchEvent({
|
|
27
50
|
type: "requestAnimationFrame",
|
|
28
|
-
timeTemp,
|
|
51
|
+
timeTemp: timeTemp,
|
|
29
52
|
accumulate: this._accumulate
|
|
30
53
|
});
|
|
31
54
|
this._computerDomZoom();
|
|
32
55
|
//执行一个计划任务
|
|
33
|
-
|
|
56
|
+
var work = this.workList.splice(0, 1)[0];
|
|
34
57
|
work && work();
|
|
35
|
-
setTimeout(()
|
|
36
|
-
|
|
58
|
+
setTimeout(function () {
|
|
59
|
+
_this.requestAnimationFrame();
|
|
37
60
|
}, 45 - this._clock.getDelta());
|
|
38
|
-
}
|
|
39
|
-
// 需要保持宽高比的元素列表
|
|
40
|
-
_keepZoomDoms = [];
|
|
61
|
+
};
|
|
41
62
|
/**
|
|
42
63
|
*计算需要保持比例的元素
|
|
43
64
|
*/
|
|
44
|
-
_computerDomZoom() {
|
|
65
|
+
ThreeUtils.prototype._computerDomZoom = function () {
|
|
66
|
+
var _this = this;
|
|
45
67
|
//1. 踢除没有出现在页面上的 dom 元素
|
|
46
|
-
this._keepZoomDoms = this._keepZoomDoms.filter(l
|
|
68
|
+
this._keepZoomDoms = this._keepZoomDoms.filter(function (l) { return _this.inDocument(l.dom); });
|
|
47
69
|
//2.设置dom的缩放值样式
|
|
48
|
-
this._keepZoomDoms.map((item, i)
|
|
49
|
-
|
|
50
|
-
|
|
70
|
+
this._keepZoomDoms.map(function (item, i) {
|
|
71
|
+
var parentDom = item.dom.parentNode;
|
|
72
|
+
var scale = Math.min(parentDom.clientWidth / item.width, parentDom.clientHeight / item.height);
|
|
51
73
|
Object.assign(item.dom.style, {
|
|
52
74
|
position: "absolute",
|
|
53
75
|
top: "50%",
|
|
54
76
|
left: "50%",
|
|
55
|
-
transform:
|
|
56
|
-
width:
|
|
57
|
-
height:
|
|
77
|
+
transform: "translate(-50%, -50%) scale(".concat(scale, ")"),
|
|
78
|
+
width: "".concat(item.width, "px"),
|
|
79
|
+
height: "".concat(item.height, "px")
|
|
58
80
|
});
|
|
59
81
|
});
|
|
60
|
-
}
|
|
82
|
+
};
|
|
61
83
|
/**
|
|
62
84
|
* dom元素保持比例
|
|
63
85
|
*/
|
|
64
|
-
keepZoom(dom, width
|
|
86
|
+
ThreeUtils.prototype.keepZoom = function (dom, width, height) {
|
|
87
|
+
if (width === void 0) { width = 1920; }
|
|
88
|
+
if (height === void 0) { height = 1080; }
|
|
65
89
|
if (dom) {
|
|
66
90
|
// 去掉相同的dom存储的信息
|
|
67
|
-
this._keepZoomDoms = this._keepZoomDoms.filter(l
|
|
91
|
+
this._keepZoomDoms = this._keepZoomDoms.filter(function (l) { return l.dom !== dom; });
|
|
68
92
|
// 把配置加入到列表中
|
|
69
|
-
this._keepZoomDoms.push({ dom, width, height });
|
|
93
|
+
this._keepZoomDoms.push({ dom: dom, width: width, height: height });
|
|
70
94
|
dom.dataset.a = "这个元素缩放比例由 threeUtils.keepZoom 方法设置";
|
|
71
95
|
this._computerDomZoom();
|
|
72
96
|
}
|
|
73
|
-
}
|
|
74
|
-
workList = [];
|
|
75
|
-
// 时钟对象
|
|
76
|
-
clock = new Clock();
|
|
97
|
+
};
|
|
77
98
|
// 按照任务队列依次执行计划任务 性能优化
|
|
78
99
|
/**
|
|
79
100
|
* @param {() => void} [callback]
|
|
80
101
|
* @param {boolean} [first=true] 需要优先执行
|
|
81
102
|
*/
|
|
82
|
-
addWork(work, first
|
|
103
|
+
ThreeUtils.prototype.addWork = function (work, first) {
|
|
104
|
+
if (first === void 0) { first = false; }
|
|
83
105
|
// 加入任务队列
|
|
84
106
|
if (work && !this.workList.includes(work)) {
|
|
85
107
|
if (first) {
|
|
@@ -89,11 +111,11 @@ class ThreeUtils extends EventDispatcher {
|
|
|
89
111
|
this.workList.push(work);
|
|
90
112
|
}
|
|
91
113
|
}
|
|
92
|
-
}
|
|
114
|
+
};
|
|
93
115
|
/**
|
|
94
116
|
*判断一个元素是否在页面上
|
|
95
117
|
*/
|
|
96
|
-
inDocument(dom) {
|
|
118
|
+
ThreeUtils.prototype.inDocument = function (dom) {
|
|
97
119
|
if (dom === null) {
|
|
98
120
|
return false;
|
|
99
121
|
}
|
|
@@ -106,9 +128,9 @@ class ThreeUtils extends EventDispatcher {
|
|
|
106
128
|
else {
|
|
107
129
|
return this.inDocument(dom.parentNode);
|
|
108
130
|
}
|
|
109
|
-
}
|
|
131
|
+
};
|
|
110
132
|
// 获取中心点
|
|
111
|
-
getCenter(object3d) {
|
|
133
|
+
ThreeUtils.prototype.getCenter = function (object3d) {
|
|
112
134
|
if (object3d instanceof Object3D) {
|
|
113
135
|
this._box3.setFromObject(object3d);
|
|
114
136
|
this._box3.getCenter(this._center);
|
|
@@ -118,9 +140,9 @@ class ThreeUtils extends EventDispatcher {
|
|
|
118
140
|
object3d.boundingBox.getCenter(this._center);
|
|
119
141
|
}
|
|
120
142
|
return this._center;
|
|
121
|
-
}
|
|
143
|
+
};
|
|
122
144
|
// 获取模型大小
|
|
123
|
-
getSize(object3d) {
|
|
145
|
+
ThreeUtils.prototype.getSize = function (object3d) {
|
|
124
146
|
if (object3d instanceof Object3D) {
|
|
125
147
|
this._box3.setFromObject(object3d);
|
|
126
148
|
this._box3.getSize(this._size);
|
|
@@ -130,9 +152,10 @@ class ThreeUtils extends EventDispatcher {
|
|
|
130
152
|
object3d.boundingBox.getSize(this._size);
|
|
131
153
|
}
|
|
132
154
|
return this._size;
|
|
133
|
-
}
|
|
155
|
+
};
|
|
134
156
|
// 模型对齐底面
|
|
135
|
-
alignBottom(object3d, y
|
|
157
|
+
ThreeUtils.prototype.alignBottom = function (object3d, y) {
|
|
158
|
+
if (y === void 0) { y = 0; }
|
|
136
159
|
if (object3d instanceof Object3D) {
|
|
137
160
|
this._box3.setFromObject(object3d);
|
|
138
161
|
this._box3.getCenter(this._center);
|
|
@@ -145,9 +168,9 @@ class ThreeUtils extends EventDispatcher {
|
|
|
145
168
|
object3d.computeBoundingBox();
|
|
146
169
|
object3d.translate(0, -object3d.boundingBox.min.y + y, 0);
|
|
147
170
|
}
|
|
148
|
-
}
|
|
171
|
+
};
|
|
149
172
|
// 居中对象
|
|
150
|
-
centerObject3D(object3d) {
|
|
173
|
+
ThreeUtils.prototype.centerObject3D = function (object3d) {
|
|
151
174
|
if (object3d instanceof Object3D) {
|
|
152
175
|
this._box3.setFromObject(object3d);
|
|
153
176
|
this._box3.getCenter(this._center);
|
|
@@ -157,22 +180,24 @@ class ThreeUtils extends EventDispatcher {
|
|
|
157
180
|
else if (object3d instanceof BufferGeometry) {
|
|
158
181
|
object3d.center();
|
|
159
182
|
}
|
|
160
|
-
}
|
|
183
|
+
};
|
|
161
184
|
//居中对象
|
|
162
|
-
center(object3d) {
|
|
185
|
+
ThreeUtils.prototype.center = function (object3d) {
|
|
163
186
|
this.centerObject3D(object3d);
|
|
164
|
-
}
|
|
187
|
+
};
|
|
165
188
|
//缩放至指定大小
|
|
166
|
-
scaleTo(object3d, size
|
|
167
|
-
|
|
168
|
-
|
|
189
|
+
ThreeUtils.prototype.scaleTo = function (object3d, size) {
|
|
190
|
+
if (size === void 0) { size = 1; }
|
|
191
|
+
var originSize = this.getSize(object3d);
|
|
192
|
+
var scale = size / Math.max(originSize.x, originSize.y, originSize.z);
|
|
169
193
|
if (object3d instanceof Object3D) {
|
|
170
194
|
object3d.scale.multiplyScalar(scale);
|
|
171
195
|
}
|
|
172
196
|
else if (object3d instanceof BufferGeometry) {
|
|
173
197
|
object3d.scale(scale, scale, scale);
|
|
174
198
|
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
199
|
+
};
|
|
200
|
+
return ThreeUtils;
|
|
201
|
+
}(EventDispatcher));
|
|
202
|
+
var threeUtils = new ThreeUtils();
|
|
178
203
|
export default threeUtils;
|