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