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