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/ExtrudeMesh.js
CHANGED
|
@@ -4,6 +4,30 @@
|
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2022-09-30 00:12:19
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
23
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
24
|
+
if (ar || !(i in from)) {
|
|
25
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
26
|
+
ar[i] = from[i];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
30
|
+
};
|
|
7
31
|
import { clamp, cloneDeep, filter, first, get, isNumber, last } from "lodash";
|
|
8
32
|
import { BufferAttribute, BufferGeometry, Matrix4, Mesh, Vector2, Vector3 } from "three";
|
|
9
33
|
/**
|
|
@@ -14,45 +38,35 @@ import { BufferAttribute, BufferGeometry, Matrix4, Mesh, Vector2, Vector3 } from
|
|
|
14
38
|
* @class ExtrudeMesh
|
|
15
39
|
* @extends {Mesh<BufferGeometry, Material>}
|
|
16
40
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
static temp2Vector3 = new Vector3();
|
|
26
|
-
static temp3Vector3 = new Vector3();
|
|
27
|
-
// 临时使用的矩阵
|
|
28
|
-
static temp1Matrix4 = new Matrix4();
|
|
29
|
-
static temp2Matrix4 = new Matrix4();
|
|
30
|
-
static temp3Matrix4 = new Matrix4();
|
|
31
|
-
constructor(props, material) {
|
|
32
|
-
super(undefined, material);
|
|
33
|
-
this.updateGeometry(props);
|
|
41
|
+
var ExtrudeMesh = /** @class */ (function (_super) {
|
|
42
|
+
__extends(ExtrudeMesh, _super);
|
|
43
|
+
function ExtrudeMesh(props, material) {
|
|
44
|
+
var _this = _super.call(this, undefined, material) || this;
|
|
45
|
+
// 通过 props.paths 和圆角属性 计算出来的 最终路径
|
|
46
|
+
_this.pointerWidthRadius = [];
|
|
47
|
+
_this.updateGeometry(props);
|
|
48
|
+
return _this;
|
|
34
49
|
}
|
|
35
|
-
// 通过 props.paths 和圆角属性 计算出来的 最终路径
|
|
36
|
-
pointerWidthRadius = [];
|
|
37
50
|
// 通过2个顶点和缩放值计算矩阵
|
|
38
|
-
computerMatrix(vector1, vector2, scale) {
|
|
51
|
+
ExtrudeMesh.prototype.computerMatrix = function (vector1, vector2, scale) {
|
|
52
|
+
var _a;
|
|
39
53
|
ExtrudeMesh.temp1Matrix4.identity();
|
|
40
54
|
ExtrudeMesh.temp1Matrix4.multiply(ExtrudeMesh.temp2Matrix4.lookAt(ExtrudeMesh.temp1Vector3.set(vector1[0], vector1[1], vector1[2]), ExtrudeMesh.temp2Vector3.set(vector2[0], vector1[1], vector2[2]), ExtrudeMesh.temp3Vector3.set(0, 1, 0)));
|
|
41
|
-
ExtrudeMesh.temp1Matrix4.scale(ExtrudeMesh.temp1Vector3.set(
|
|
55
|
+
ExtrudeMesh.temp1Matrix4.scale((_a = ExtrudeMesh.temp1Vector3).set.apply(_a, scale));
|
|
42
56
|
return ExtrudeMesh.temp1Matrix4.transpose().toArray();
|
|
43
|
-
}
|
|
57
|
+
};
|
|
44
58
|
/**
|
|
45
59
|
* @计算渐变值 computerGradient([3,2,4], 0.3);
|
|
46
60
|
* @渐变区间 values:number[]
|
|
47
61
|
* @百分比 percentage:number
|
|
48
62
|
*/
|
|
49
|
-
computerGradient(values, percentage) {
|
|
63
|
+
ExtrudeMesh.prototype.computerGradient = function (values, percentage) {
|
|
50
64
|
// 过滤有效数字类型
|
|
51
|
-
values = filter(values, v
|
|
65
|
+
values = filter(values, function (v) { return isNumber(v); });
|
|
52
66
|
// 限定取值范围
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
for (
|
|
67
|
+
var P = clamp(percentage, 0, 1);
|
|
68
|
+
var VL = values.length;
|
|
69
|
+
for (var i = (VL - 1); i >= 0; i--) {
|
|
56
70
|
if (P === (i / (VL - 1))) {
|
|
57
71
|
return values[i];
|
|
58
72
|
}
|
|
@@ -63,9 +77,11 @@ export default class ExtrudeMesh extends Mesh {
|
|
|
63
77
|
}
|
|
64
78
|
}
|
|
65
79
|
return 0;
|
|
66
|
-
}
|
|
80
|
+
};
|
|
67
81
|
// 计算圆角路径 并存到 this.pointerWidthRadius 上
|
|
68
|
-
computerPointerWidthRadius(paths, closed) {
|
|
82
|
+
ExtrudeMesh.prototype.computerPointerWidthRadius = function (paths, closed) {
|
|
83
|
+
var _a;
|
|
84
|
+
var _this = this;
|
|
69
85
|
// 路径小于2个就不执行计算
|
|
70
86
|
if (paths.length < 2) {
|
|
71
87
|
return;
|
|
@@ -79,75 +95,74 @@ export default class ExtrudeMesh extends Mesh {
|
|
|
79
95
|
paths = cloneDeep(paths);
|
|
80
96
|
// 如果是闭合路径的话就头尾相连
|
|
81
97
|
if (closed) {
|
|
82
|
-
Object.defineProperties(paths, {
|
|
83
|
-
[-1]
|
|
98
|
+
Object.defineProperties(paths, (_a = {},
|
|
99
|
+
_a[-1] = {
|
|
84
100
|
value: last(paths),
|
|
85
101
|
configurable: false,
|
|
86
102
|
enumerable: false,
|
|
87
103
|
writable: false // 此属性的值能否修改
|
|
88
104
|
},
|
|
89
|
-
[paths.length]
|
|
105
|
+
_a[paths.length] = {
|
|
90
106
|
value: first(paths),
|
|
91
107
|
configurable: false,
|
|
92
108
|
enumerable: false,
|
|
93
109
|
writable: false // 此属性的值能否修改
|
|
94
|
-
}
|
|
95
|
-
|
|
110
|
+
},
|
|
111
|
+
_a));
|
|
96
112
|
}
|
|
97
|
-
paths.map((P, i)
|
|
98
|
-
|
|
113
|
+
paths.map(function (P, i) {
|
|
114
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
115
|
+
var vector3 = P.vector3, _o = P.radius, radius = _o === void 0 ? 0.1 : _o, _p = P.segments, segments = _p === void 0 ? 0 : _p, _q = P.scale, scale = _q === void 0 ? { x: 1, y: 1 } : _q;
|
|
99
116
|
//当前点位置前后都有点时就可以做圆角计算
|
|
100
117
|
if (paths[i - 1] && paths[i + 1]) {
|
|
101
118
|
// 第一个向量
|
|
102
|
-
|
|
103
|
-
.set(
|
|
104
|
-
.sub(ExtrudeMesh.tempVector3.set(...paths[i - 1].vector3))
|
|
119
|
+
var v1 = (_a = ExtrudeMesh.temp1Vector3)
|
|
120
|
+
.set.apply(_a, vector3).sub((_b = ExtrudeMesh.tempVector3).set.apply(_b, paths[i - 1].vector3))
|
|
105
121
|
.normalize()
|
|
106
122
|
.clone();
|
|
107
123
|
// 第二个向量
|
|
108
|
-
|
|
109
|
-
.set(
|
|
110
|
-
.sub(ExtrudeMesh.tempVector3.set(...vector3))
|
|
124
|
+
var v2 = (_c = ExtrudeMesh.temp2Vector3)
|
|
125
|
+
.set.apply(_c, paths[i + 1].vector3).sub((_d = ExtrudeMesh.tempVector3).set.apply(_d, vector3))
|
|
111
126
|
.normalize()
|
|
112
127
|
.clone();
|
|
113
128
|
// 夹角
|
|
114
|
-
|
|
129
|
+
var innerAngle = v1.clone().multiplyScalar(-1).angleTo(v2);
|
|
115
130
|
// 边长
|
|
116
|
-
|
|
131
|
+
var sideLength = radius / Math.tan(innerAngle / 2);
|
|
117
132
|
// 圆角的起点
|
|
118
|
-
|
|
133
|
+
var startP = new (Vector3.bind.apply(Vector3, __spreadArray([void 0], vector3, false)))().sub(v1.clone().multiplyScalar(sideLength));
|
|
119
134
|
// 圆角的终点
|
|
120
|
-
|
|
135
|
+
var endP = new (Vector3.bind.apply(Vector3, __spreadArray([void 0], vector3, false)))().add(v2.clone().multiplyScalar(sideLength));
|
|
121
136
|
// 圆角起点到终点的向量
|
|
122
|
-
|
|
137
|
+
var StoE = endP.clone().sub(startP);
|
|
123
138
|
// 弦长
|
|
124
|
-
|
|
139
|
+
var chordLength = radius / Math.sin(innerAngle / 2);
|
|
125
140
|
// 圆心位置
|
|
126
|
-
|
|
141
|
+
var circleCenter = v2
|
|
127
142
|
.clone()
|
|
128
143
|
.add(v1)
|
|
129
144
|
.multiplyScalar(0.5)
|
|
130
145
|
.sub(v1)
|
|
131
146
|
.setLength(chordLength)
|
|
132
|
-
.add(ExtrudeMesh.tempVector3.set(
|
|
147
|
+
.add((_e = ExtrudeMesh.tempVector3).set.apply(_e, vector3));
|
|
133
148
|
//向量2是否在 向量1的左边
|
|
134
|
-
|
|
149
|
+
var v2Inv1Left = ExtrudeMesh.temp1Vector3
|
|
135
150
|
.set(-v1.z, 0, v1.x)
|
|
136
151
|
.angleTo(ExtrudeMesh.temp2Vector3.set(v2.x, 0, v2.z))
|
|
137
152
|
< (Math.PI / 2);
|
|
138
153
|
// XZ平面上的夹角
|
|
139
|
-
|
|
154
|
+
var innerAngleXZ = ExtrudeMesh.temp1Vector3
|
|
140
155
|
.set(v1.x, 0, v1.z)
|
|
141
156
|
.angleTo(ExtrudeMesh.temp2Vector3.set(v2.x, 0, v2.z));
|
|
142
157
|
// 如果当前点的位置在前后2点的连线上,就不进行分段计算 并且应用上一个点的矩阵
|
|
143
158
|
if (innerAngleXZ === 0) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
vector3,
|
|
159
|
+
var _r = scale.x, x = _r === void 0 ? 1 : _r, _s = scale.y, y = _s === void 0 ? 1 : _s;
|
|
160
|
+
var lastPointMatrix = last(_this.pointerWidthRadius).matrix;
|
|
161
|
+
_this.pointerWidthRadius.push({
|
|
162
|
+
vector3: vector3,
|
|
148
163
|
matrix: ExtrudeMesh.temp1Matrix4
|
|
149
164
|
.identity()
|
|
150
|
-
.extractRotation(ExtrudeMesh.temp2Matrix4.set(
|
|
165
|
+
.extractRotation((_f = ExtrudeMesh.temp2Matrix4).set.apply(_f, lastPointMatrix))
|
|
151
166
|
.multiply(ExtrudeMesh.temp3Matrix4
|
|
152
167
|
.identity()
|
|
153
168
|
.scale(ExtrudeMesh.temp1Vector3.set(1, y, x)))
|
|
@@ -156,38 +171,38 @@ export default class ExtrudeMesh extends Mesh {
|
|
|
156
171
|
});
|
|
157
172
|
}
|
|
158
173
|
else if (segments === 0) { // 分段数为0时不分段
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
vector3,
|
|
162
|
-
matrix:
|
|
174
|
+
var _t = scale.x, x = _t === void 0 ? 1 : _t, _u = scale.y, y = _u === void 0 ? 1 : _u;
|
|
175
|
+
_this.pointerWidthRadius.push({
|
|
176
|
+
vector3: vector3,
|
|
177
|
+
matrix: _this.computerMatrix((v2Inv1Left ? circleCenter.toArray() : vector3), (v2Inv1Left ? vector3 : circleCenter.toArray()), [1, y, x])
|
|
163
178
|
});
|
|
164
179
|
}
|
|
165
180
|
else {
|
|
166
|
-
for (
|
|
181
|
+
for (var ii = 0; ii <= segments; ii++) {
|
|
167
182
|
// 圆角计算的低n个点的角度
|
|
168
|
-
|
|
183
|
+
var Aa = ii * ((Math.PI - innerAngle) / segments);
|
|
169
184
|
//半径对角
|
|
170
|
-
|
|
185
|
+
var Cc = Math.PI - Aa - (innerAngle / 2);
|
|
171
186
|
//圆角分段的弦长
|
|
172
|
-
|
|
187
|
+
var a = radius * Math.sin(Aa) / Math.sin(Cc);
|
|
173
188
|
// 每段圆角的弦长
|
|
174
|
-
|
|
189
|
+
var StoEvector = StoE.clone().setLength(a).add(startP);
|
|
175
190
|
// 当前点的位置
|
|
176
|
-
|
|
191
|
+
var ridiusP = StoEvector
|
|
177
192
|
.clone()
|
|
178
193
|
.sub(circleCenter)
|
|
179
194
|
.setLength(radius)
|
|
180
195
|
.add(circleCenter);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
196
|
+
var _v = get(paths[i - 1], ["scale"]) || {}, _w = _v.x, preX = _w === void 0 ? 1 : _w, _x = _v.y, preY = _x === void 0 ? 1 : _x;
|
|
197
|
+
var _y = get(paths[i + 1], ["scale"]) || {}, _z = _y.x, nextX = _z === void 0 ? 1 : _z, _0 = _y.y, nextY = _0 === void 0 ? 1 : _0;
|
|
198
|
+
var _1 = scale.x, x = _1 === void 0 ? 1 : _1, _2 = scale.y, y = _2 === void 0 ? 1 : _2;
|
|
184
199
|
// 缩放值过渡计算
|
|
185
|
-
x =
|
|
186
|
-
y =
|
|
200
|
+
x = _this.computerGradient([(preX + x) / 2, x, (x + nextX) / 2], ii / segments);
|
|
201
|
+
y = _this.computerGradient([(preY + y) / 2, y, (y + nextY) / 2], ii / segments);
|
|
187
202
|
// 添加一个带矩阵的点
|
|
188
|
-
|
|
203
|
+
_this.pointerWidthRadius.push({
|
|
189
204
|
vector3: ridiusP.toArray(),
|
|
190
|
-
matrix:
|
|
205
|
+
matrix: _this.computerMatrix((v2Inv1Left ? circleCenter.toArray() : ridiusP.toArray()), (v2Inv1Left ? ridiusP.toArray() : circleCenter.toArray()), [1, y, x])
|
|
191
206
|
});
|
|
192
207
|
}
|
|
193
208
|
}
|
|
@@ -197,41 +212,39 @@ export default class ExtrudeMesh extends Mesh {
|
|
|
197
212
|
if (i === paths.length - 1) {
|
|
198
213
|
// 如果是闭合的话 就把第一个点的位置加入最后后面
|
|
199
214
|
if (closed) {
|
|
200
|
-
|
|
215
|
+
_this.pointerWidthRadius.push(first(_this.pointerWidthRadius));
|
|
201
216
|
}
|
|
202
217
|
else {
|
|
203
218
|
// 如果路径未闭合并且遍历到最后一个时特殊处理
|
|
204
|
-
|
|
219
|
+
var lastPoint = last(_this.pointerWidthRadius);
|
|
205
220
|
// 在没有闭合的情况下添加第一个点的位置
|
|
206
|
-
|
|
207
|
-
.set(
|
|
208
|
-
.sub(ExtrudeMesh.temp3Vector3.set(...lastPoint.vector3))
|
|
221
|
+
var v = (_g = ExtrudeMesh.temp1Vector3)
|
|
222
|
+
.set.apply(_g, vector3).sub((_h = ExtrudeMesh.temp3Vector3).set.apply(_h, lastPoint.vector3))
|
|
209
223
|
.normalize();
|
|
210
|
-
|
|
224
|
+
var lookAtPoint = ExtrudeMesh.temp2Vector3
|
|
211
225
|
.set(v.z, 0, -v.x)
|
|
212
|
-
.add(ExtrudeMesh.temp3Vector3.set(
|
|
226
|
+
.add((_j = ExtrudeMesh.temp3Vector3).set.apply(_j, vector3))
|
|
213
227
|
.toArray();
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
vector3,
|
|
217
|
-
matrix:
|
|
228
|
+
var _3 = scale.x, x = _3 === void 0 ? 1 : _3, _4 = scale.y, y = _4 === void 0 ? 1 : _4;
|
|
229
|
+
_this.pointerWidthRadius.push({
|
|
230
|
+
vector3: vector3,
|
|
231
|
+
matrix: _this.computerMatrix(vector3, lookAtPoint, [1, y, x])
|
|
218
232
|
});
|
|
219
233
|
}
|
|
220
234
|
}
|
|
221
235
|
else {
|
|
222
|
-
|
|
236
|
+
var _5 = scale.x, x = _5 === void 0 ? 1 : _5, _6 = scale.y, y = _6 === void 0 ? 1 : _6;
|
|
223
237
|
// 在没有闭合的情况下添加第一个点的位置
|
|
224
|
-
|
|
225
|
-
.set(
|
|
226
|
-
.sub(ExtrudeMesh.temp2Vector3.set(...vector3))
|
|
238
|
+
var v2 = (_k = ExtrudeMesh.temp1Vector3)
|
|
239
|
+
.set.apply(_k, paths[i + 1].vector3).sub((_l = ExtrudeMesh.temp2Vector3).set.apply(_l, vector3))
|
|
227
240
|
.normalize();
|
|
228
|
-
|
|
241
|
+
var lookAtPoint = ExtrudeMesh.temp1Vector3
|
|
229
242
|
.set(v2.z, 0, -v2.x)
|
|
230
|
-
.add(ExtrudeMesh.temp2Vector3.set(
|
|
243
|
+
.add((_m = ExtrudeMesh.temp2Vector3).set.apply(_m, vector3))
|
|
231
244
|
.toArray();
|
|
232
|
-
|
|
233
|
-
vector3,
|
|
234
|
-
matrix:
|
|
245
|
+
_this.pointerWidthRadius.push({
|
|
246
|
+
vector3: vector3,
|
|
247
|
+
matrix: _this.computerMatrix(vector3, lookAtPoint, [1, y, x])
|
|
235
248
|
});
|
|
236
249
|
}
|
|
237
250
|
} // else
|
|
@@ -248,21 +261,22 @@ export default class ExtrudeMesh extends Mesh {
|
|
|
248
261
|
// this.pointerWidthRadius.splice(i, 1);
|
|
249
262
|
// }
|
|
250
263
|
// }
|
|
251
|
-
}
|
|
264
|
+
};
|
|
252
265
|
// 计算三维路径的总长度
|
|
253
|
-
computerPathLength(points) {
|
|
254
|
-
|
|
255
|
-
points.map((p, index)
|
|
266
|
+
ExtrudeMesh.prototype.computerPathLength = function (points) {
|
|
267
|
+
var length = 0;
|
|
268
|
+
points.map(function (p, index) {
|
|
269
|
+
var _a, _b;
|
|
256
270
|
if (index < points.length - 1) {
|
|
257
|
-
ExtrudeMesh.temp1Vector3.set(
|
|
258
|
-
ExtrudeMesh.temp2Vector3.set(
|
|
271
|
+
(_a = ExtrudeMesh.temp1Vector3).set.apply(_a, p);
|
|
272
|
+
(_b = ExtrudeMesh.temp2Vector3).set.apply(_b, points[index + 1]);
|
|
259
273
|
length += ExtrudeMesh.temp1Vector3.distanceTo(ExtrudeMesh.temp2Vector3);
|
|
260
274
|
}
|
|
261
275
|
});
|
|
262
276
|
return length;
|
|
263
|
-
}
|
|
277
|
+
};
|
|
264
278
|
// 通过一条线段计算挤出模型的各个顶点的位置和 uv坐标
|
|
265
|
-
setExtrudeMesh(startP, // 起点位置
|
|
279
|
+
ExtrudeMesh.prototype.setExtrudeMesh = function (startP, // 起点位置
|
|
266
280
|
startMatrix4, // 起点位置的矩阵
|
|
267
281
|
endP, // 终点位置
|
|
268
282
|
endMatrix4, // 终点位置的矩阵
|
|
@@ -270,15 +284,17 @@ export default class ExtrudeMesh extends Mesh {
|
|
|
270
284
|
shapePath) {
|
|
271
285
|
// // 反转路径, 这样uv 坐标看起来习惯一些
|
|
272
286
|
// shapePath = cloneDeep(shapePath).reverse();
|
|
287
|
+
var _this = this;
|
|
273
288
|
// 计算二维路径的总长度 作为uv坐标的边长
|
|
274
|
-
|
|
289
|
+
var shapePathLength = this.computerPathLength(shapePath.map(function (p) { return __spreadArray(__spreadArray([], p, true), [0], false); }));
|
|
275
290
|
// 挤出长度
|
|
276
|
-
|
|
291
|
+
var extrudeLength = this.computerPathLength([startP, endP]);
|
|
277
292
|
// 网格模型每个点
|
|
278
|
-
|
|
293
|
+
var geometryPoint = [];
|
|
279
294
|
// 网格模型每个点对应的uv坐标
|
|
280
|
-
|
|
281
|
-
shapePath.map((P, index)
|
|
295
|
+
var uvPoint = [];
|
|
296
|
+
shapePath.map(function (P, index) {
|
|
297
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
282
298
|
if (index < shapePath.length - 1) {
|
|
283
299
|
// 计算出矩形面的4个顶点
|
|
284
300
|
//[pa....Pd]
|
|
@@ -286,28 +302,28 @@ export default class ExtrudeMesh extends Mesh {
|
|
|
286
302
|
//[. .]
|
|
287
303
|
//[. .]
|
|
288
304
|
//[Pb....Pc]
|
|
289
|
-
|
|
305
|
+
var Pa = ExtrudeMesh.tempVector3
|
|
290
306
|
.set(0, P[1], -P[0])
|
|
291
|
-
.applyMatrix4(ExtrudeMesh.temp1Matrix4.set(
|
|
292
|
-
.add(ExtrudeMesh.temp1Vector3.set(
|
|
307
|
+
.applyMatrix4((_a = ExtrudeMesh.temp1Matrix4).set.apply(_a, startMatrix4))
|
|
308
|
+
.add((_b = ExtrudeMesh.temp1Vector3).set.apply(_b, startP))
|
|
293
309
|
.toArray();
|
|
294
|
-
|
|
310
|
+
var Pb = ExtrudeMesh.tempVector3
|
|
295
311
|
.set(0, shapePath[index + 1][1], -shapePath[index + 1][0])
|
|
296
|
-
.applyMatrix4(ExtrudeMesh.temp1Matrix4.set(
|
|
297
|
-
.add(ExtrudeMesh.temp1Vector3.set(
|
|
312
|
+
.applyMatrix4((_c = ExtrudeMesh.temp1Matrix4).set.apply(_c, startMatrix4))
|
|
313
|
+
.add((_d = ExtrudeMesh.temp1Vector3).set.apply(_d, startP))
|
|
298
314
|
.toArray();
|
|
299
|
-
|
|
315
|
+
var Pc = ExtrudeMesh.tempVector3
|
|
300
316
|
.set(0, shapePath[index + 1][1], -shapePath[index + 1][0])
|
|
301
|
-
.applyMatrix4(ExtrudeMesh.temp1Matrix4.set(
|
|
302
|
-
.add(ExtrudeMesh.temp1Vector3.set(
|
|
317
|
+
.applyMatrix4((_e = ExtrudeMesh.temp1Matrix4).set.apply(_e, endMatrix4))
|
|
318
|
+
.add((_f = ExtrudeMesh.temp1Vector3).set.apply(_f, endP))
|
|
303
319
|
.toArray();
|
|
304
|
-
|
|
320
|
+
var Pd = ExtrudeMesh.tempVector3
|
|
305
321
|
.set(0, P[1], -P[0])
|
|
306
|
-
.applyMatrix4(ExtrudeMesh.temp1Matrix4.set(
|
|
307
|
-
.add(ExtrudeMesh.temp1Vector3.set(
|
|
322
|
+
.applyMatrix4((_g = ExtrudeMesh.temp1Matrix4).set.apply(_g, endMatrix4))
|
|
323
|
+
.add((_h = ExtrudeMesh.temp1Vector3).set.apply(_h, endP))
|
|
308
324
|
.toArray();
|
|
309
325
|
// 组成矩形的2个三角面
|
|
310
|
-
geometryPoint.push(
|
|
326
|
+
geometryPoint.push.apply(geometryPoint, __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], Pa, false), Pb, false), Pc, false), Pa, false), Pc, false), Pd, false));
|
|
311
327
|
// 计算出矩形面的4个顶点的uv坐标
|
|
312
328
|
//[Pauv..Pcuv]
|
|
313
329
|
//[. .]
|
|
@@ -315,49 +331,64 @@ export default class ExtrudeMesh extends Mesh {
|
|
|
315
331
|
//[. .]
|
|
316
332
|
//[Pbuv..Pduv]
|
|
317
333
|
// 当前位置的 uv.y 位置
|
|
318
|
-
|
|
334
|
+
var currentUvy = _this.computerPathLength(__spreadArray([first(shapePath)], shapePath.slice(0, index + 1), true).map(function (sP) { return __spreadArray(__spreadArray([], sP, true), [0], false); })) / shapePathLength;
|
|
319
335
|
// 下一个坐标的 uv.y 位置
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
uvPoint.push(
|
|
336
|
+
var nextUvy = _this.computerPathLength(__spreadArray([first(shapePath)], shapePath.slice(0, index + 2), true).map(function (sP) { return __spreadArray(__spreadArray([], sP, true), [0], false); })) / shapePathLength;
|
|
337
|
+
var Pauv = [uvx / shapePathLength, currentUvy];
|
|
338
|
+
var Pbuv = [uvx / shapePathLength, nextUvy];
|
|
339
|
+
var Pcuv = [(uvx + extrudeLength) / shapePathLength, nextUvy];
|
|
340
|
+
var Pduv = [(uvx + extrudeLength) / shapePathLength, currentUvy];
|
|
341
|
+
uvPoint.push.apply(uvPoint, __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], Pauv, false), Pbuv, false), Pcuv, false), Pauv, false), Pcuv, false), Pduv, false));
|
|
326
342
|
}
|
|
327
343
|
});
|
|
328
|
-
return { geometryPoint, uvPoint };
|
|
329
|
-
}
|
|
344
|
+
return { geometryPoint: geometryPoint, uvPoint: uvPoint };
|
|
345
|
+
};
|
|
330
346
|
//设置模型
|
|
331
|
-
updateGeometry(props) {
|
|
332
|
-
|
|
347
|
+
ExtrudeMesh.prototype.updateGeometry = function (props) {
|
|
348
|
+
var paths = props.paths, shapePath = props.shapePath, closed = props.closed;
|
|
333
349
|
// 计算圆角路径
|
|
334
350
|
this.computerPointerWidthRadius(paths, closed);
|
|
335
351
|
//网格模型的每个顶点位置
|
|
336
|
-
|
|
352
|
+
var geometryPoint = [];
|
|
337
353
|
// 网格模型每个点对应的uv坐标
|
|
338
|
-
|
|
339
|
-
for (
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
354
|
+
var uvPoint = [];
|
|
355
|
+
for (var i = 0; i < this.pointerWidthRadius.length - 1; i++) {
|
|
356
|
+
var Point1 = this.pointerWidthRadius[i];
|
|
357
|
+
var Point2 = this.pointerWidthRadius[i + 1];
|
|
358
|
+
var uvx = this.computerPathLength(this.pointerWidthRadius.slice(0, i + 1).map(function (p) { return p.vector3; }));
|
|
359
|
+
var _a = this.setExtrudeMesh(Point1.vector3, Point1.matrix, Point2.vector3, Point2.matrix, uvx, shapePath), geo = _a.geometryPoint, uv_1 = _a.uvPoint;
|
|
344
360
|
// 把挤出的网格模型的顶点收集起来
|
|
345
|
-
geometryPoint.push(
|
|
361
|
+
geometryPoint.push.apply(geometryPoint, geo);
|
|
346
362
|
// 把挤出的网格模型顶点的uv坐标收集起来
|
|
347
|
-
uvPoint.push(
|
|
363
|
+
uvPoint.push.apply(uvPoint, uv_1);
|
|
348
364
|
}
|
|
349
|
-
|
|
365
|
+
var geometry = new BufferGeometry();
|
|
350
366
|
// 修改模型
|
|
351
|
-
|
|
352
|
-
|
|
367
|
+
var positionArray = new Float32Array(geometryPoint);
|
|
368
|
+
var position = new BufferAttribute(positionArray, 3, false);
|
|
353
369
|
geometry.setAttribute("position", position);
|
|
354
|
-
|
|
355
|
-
|
|
370
|
+
var uvArray = new Float32Array(uvPoint);
|
|
371
|
+
var uv = new BufferAttribute(uvArray, 2, false);
|
|
356
372
|
geometry.setAttribute("uv", uv);
|
|
357
373
|
// 计算顶点法线
|
|
358
374
|
geometry.computeVertexNormals();
|
|
359
375
|
this.geometry.dispose();
|
|
360
376
|
this.geometry = geometry;
|
|
361
377
|
this.dispatchEvent({ type: "loaded" });
|
|
362
|
-
}
|
|
363
|
-
|
|
378
|
+
};
|
|
379
|
+
// 临时使用的二维顶点对象
|
|
380
|
+
ExtrudeMesh.temp1Vector2 = new Vector2();
|
|
381
|
+
ExtrudeMesh.temp2Vector2 = new Vector2();
|
|
382
|
+
ExtrudeMesh.temp3Vector2 = new Vector2();
|
|
383
|
+
// 临时使用的3维顶点对象
|
|
384
|
+
ExtrudeMesh.tempVector3 = new Vector3();
|
|
385
|
+
ExtrudeMesh.temp1Vector3 = new Vector3();
|
|
386
|
+
ExtrudeMesh.temp2Vector3 = new Vector3();
|
|
387
|
+
ExtrudeMesh.temp3Vector3 = new Vector3();
|
|
388
|
+
// 临时使用的矩阵
|
|
389
|
+
ExtrudeMesh.temp1Matrix4 = new Matrix4();
|
|
390
|
+
ExtrudeMesh.temp2Matrix4 = new Matrix4();
|
|
391
|
+
ExtrudeMesh.temp3Matrix4 = new Matrix4();
|
|
392
|
+
return ExtrudeMesh;
|
|
393
|
+
}(Mesh));
|
|
394
|
+
export default ExtrudeMesh;
|