@next2d/webgl 3.14.0 → 3.15.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/webgl",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.15.0",
|
|
4
4
|
"description": "Next2D Webgl Package",
|
|
5
5
|
"author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "git+https://github.com/Next2D/Player.git"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@next2d/texture-packer": "3.
|
|
28
|
-
"@next2d/render-queue": "3.
|
|
27
|
+
"@next2d/texture-packer": "3.15.0",
|
|
28
|
+
"@next2d/render-queue": "3.15.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -3,6 +3,15 @@ import type { IPath } from "../../interface/IPath";
|
|
|
3
3
|
* @description 塗りのメッシュを生成する
|
|
4
4
|
* Generate a fill mesh
|
|
5
5
|
*
|
|
6
|
+
* パスの 1 点ごとに三角形を 1 つ出力する (曲線は制御点を挟む 3 点、直線は始点からの扇形)。
|
|
7
|
+
* 図形を初めて描くときに全頂点を書き込むため、要素を 1 つずつ代入すると頂点数に比例して
|
|
8
|
+
* 時間がかかる。色と行列はひな形から複写し、頂点ごとに異なる値だけを書く。
|
|
9
|
+
*
|
|
10
|
+
* Emits one triangle per path point (three points around the control point for a curve,
|
|
11
|
+
* a fan from the first point for a line). Every vertex is written the first time a shape is
|
|
12
|
+
* drawn, so assigning the values one by one costs time in proportion to the vertex count.
|
|
13
|
+
* Color and matrix are copied from the template and only per-vertex values are written.
|
|
14
|
+
*
|
|
6
15
|
* @param {IPath} vertex
|
|
7
16
|
* @param {Float32Array} buffer
|
|
8
17
|
* @param {number} index
|
|
@@ -1,7 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 1頂点あたりの要素数 (座標 2 + ベジェ係数 2 + 色 4 + 行列 9)
|
|
3
|
+
* Values per vertex (position 2, Bezier coefficients 2, color 4, matrix 9)
|
|
4
|
+
*
|
|
5
|
+
* @type {number}
|
|
6
|
+
* @const
|
|
7
|
+
*/
|
|
8
|
+
const VERTEX_SIZE = 17;
|
|
9
|
+
/**
|
|
10
|
+
* @description 三角形 1 つあたりの要素数
|
|
11
|
+
* Values per triangle
|
|
12
|
+
*
|
|
13
|
+
* @type {number}
|
|
14
|
+
* @const
|
|
15
|
+
*/
|
|
16
|
+
const TRIANGLE_SIZE = VERTEX_SIZE * 3;
|
|
17
|
+
/**
|
|
18
|
+
* @description 三角形 1 つ分のひな形。色と行列は 3 頂点とも同じ値なので、呼び出しごとに 1 度だけ
|
|
19
|
+
* ここへ書き、三角形ごとにまとめて複写する。座標とベジェ係数だけを後から書き込む。
|
|
20
|
+
* Template for one triangle. Color and matrix are the same for all three vertices, so they
|
|
21
|
+
* are written here once per call and copied in one go per triangle; only the positions and
|
|
22
|
+
* Bezier coefficients are written afterwards.
|
|
23
|
+
*
|
|
24
|
+
* @type {Float32Array}
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
const $template = new Float32Array(TRIANGLE_SIZE);
|
|
1
28
|
/**
|
|
2
29
|
* @description 塗りのメッシュを生成する
|
|
3
30
|
* Generate a fill mesh
|
|
4
31
|
*
|
|
32
|
+
* パスの 1 点ごとに三角形を 1 つ出力する (曲線は制御点を挟む 3 点、直線は始点からの扇形)。
|
|
33
|
+
* 図形を初めて描くときに全頂点を書き込むため、要素を 1 つずつ代入すると頂点数に比例して
|
|
34
|
+
* 時間がかかる。色と行列はひな形から複写し、頂点ごとに異なる値だけを書く。
|
|
35
|
+
*
|
|
36
|
+
* Emits one triangle per path point (three points around the control point for a curve,
|
|
37
|
+
* a fan from the first point for a line). Every vertex is written the first time a shape is
|
|
38
|
+
* drawn, so assigning the values one by one costs time in proportion to the vertex count.
|
|
39
|
+
* Color and matrix are copied from the template and only per-vertex values are written.
|
|
40
|
+
*
|
|
5
41
|
* @param {IPath} vertex
|
|
6
42
|
* @param {Float32Array} buffer
|
|
7
43
|
* @param {number} index
|
|
@@ -20,176 +56,65 @@
|
|
|
20
56
|
* @protected
|
|
21
57
|
*/
|
|
22
58
|
export const execute = (vertex, buffer, index, a, b, c, d, tx, ty, red, green, blue, alpha) => {
|
|
59
|
+
const template = $template;
|
|
60
|
+
for (let offset = 0; offset < TRIANGLE_SIZE; offset += VERTEX_SIZE) {
|
|
61
|
+
template[offset + 4] = red;
|
|
62
|
+
template[offset + 5] = green;
|
|
63
|
+
template[offset + 6] = blue;
|
|
64
|
+
template[offset + 7] = alpha;
|
|
65
|
+
template[offset + 8] = a;
|
|
66
|
+
template[offset + 9] = b;
|
|
67
|
+
template[offset + 10] = 0;
|
|
68
|
+
template[offset + 11] = c;
|
|
69
|
+
template[offset + 12] = d;
|
|
70
|
+
template[offset + 13] = 0;
|
|
71
|
+
template[offset + 14] = tx;
|
|
72
|
+
template[offset + 15] = ty;
|
|
73
|
+
template[offset + 16] = 0;
|
|
74
|
+
}
|
|
23
75
|
const length = vertex.length - 5;
|
|
76
|
+
const limit = buffer.length - TRIANGLE_SIZE;
|
|
24
77
|
for (let idx = 3; idx < length; idx += 3) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
buffer
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
buffer[position++] = blue;
|
|
35
|
-
buffer[position++] = alpha;
|
|
36
|
-
buffer[position++] = a;
|
|
37
|
-
buffer[position++] = b;
|
|
38
|
-
buffer[position++] = 0;
|
|
39
|
-
buffer[position++] = c;
|
|
40
|
-
buffer[position++] = d;
|
|
41
|
-
buffer[position++] = 0;
|
|
42
|
-
buffer[position++] = tx;
|
|
43
|
-
buffer[position++] = ty;
|
|
44
|
-
buffer[position++] = 0;
|
|
45
|
-
// 座標B
|
|
46
|
-
buffer[position++] = vertex[idx];
|
|
47
|
-
buffer[position++] = vertex[idx + 1];
|
|
48
|
-
buffer[position++] = 0.5;
|
|
49
|
-
buffer[position++] = 0;
|
|
50
|
-
buffer[position++] = red;
|
|
51
|
-
buffer[position++] = green;
|
|
52
|
-
buffer[position++] = blue;
|
|
53
|
-
buffer[position++] = alpha;
|
|
54
|
-
buffer[position++] = a;
|
|
55
|
-
buffer[position++] = b;
|
|
56
|
-
buffer[position++] = 0;
|
|
57
|
-
buffer[position++] = c;
|
|
58
|
-
buffer[position++] = d;
|
|
59
|
-
buffer[position++] = 0;
|
|
60
|
-
buffer[position++] = tx;
|
|
61
|
-
buffer[position++] = ty;
|
|
62
|
-
buffer[position++] = 0;
|
|
63
|
-
// 座標C
|
|
64
|
-
buffer[position++] = vertex[idx + 3];
|
|
65
|
-
buffer[position++] = vertex[idx + 4];
|
|
66
|
-
buffer[position++] = 1;
|
|
67
|
-
buffer[position++] = 1;
|
|
68
|
-
buffer[position++] = red;
|
|
69
|
-
buffer[position++] = green;
|
|
70
|
-
buffer[position++] = blue;
|
|
71
|
-
buffer[position++] = alpha;
|
|
72
|
-
buffer[position++] = a;
|
|
73
|
-
buffer[position++] = b;
|
|
74
|
-
buffer[position++] = 0;
|
|
75
|
-
buffer[position++] = c;
|
|
76
|
-
buffer[position++] = d;
|
|
77
|
-
buffer[position++] = 0;
|
|
78
|
-
buffer[position++] = tx;
|
|
79
|
-
buffer[position++] = ty;
|
|
80
|
-
buffer[position++] = 0;
|
|
78
|
+
const position = index * VERTEX_SIZE;
|
|
79
|
+
// 色と行列を 3 頂点分まとめて複写する (バッファに収まらない場合は入る分だけ書く)
|
|
80
|
+
if (position <= limit) {
|
|
81
|
+
buffer.set(template, position);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
for (let offset = 0; offset < TRIANGLE_SIZE; ++offset) {
|
|
85
|
+
buffer[position + offset] = template[offset];
|
|
86
|
+
}
|
|
81
87
|
}
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
buffer[position
|
|
85
|
-
buffer[position
|
|
86
|
-
buffer[position
|
|
87
|
-
buffer[position
|
|
88
|
-
buffer[position
|
|
89
|
-
buffer[position
|
|
90
|
-
buffer[position
|
|
91
|
-
buffer[position
|
|
92
|
-
buffer[position
|
|
93
|
-
buffer[position
|
|
94
|
-
buffer[position
|
|
95
|
-
buffer[position
|
|
96
|
-
buffer[position++] = d;
|
|
97
|
-
buffer[position++] = 0;
|
|
98
|
-
buffer[position++] = tx;
|
|
99
|
-
buffer[position++] = ty;
|
|
100
|
-
buffer[position++] = 0;
|
|
101
|
-
// 座標B
|
|
102
|
-
buffer[position++] = vertex[idx];
|
|
103
|
-
buffer[position++] = vertex[idx + 1];
|
|
104
|
-
buffer[position++] = 0.5;
|
|
105
|
-
buffer[position++] = 0.5;
|
|
106
|
-
buffer[position++] = red;
|
|
107
|
-
buffer[position++] = green;
|
|
108
|
-
buffer[position++] = blue;
|
|
109
|
-
buffer[position++] = alpha;
|
|
110
|
-
buffer[position++] = a;
|
|
111
|
-
buffer[position++] = b;
|
|
112
|
-
buffer[position++] = 0;
|
|
113
|
-
buffer[position++] = c;
|
|
114
|
-
buffer[position++] = d;
|
|
115
|
-
buffer[position++] = 0;
|
|
116
|
-
buffer[position++] = tx;
|
|
117
|
-
buffer[position++] = ty;
|
|
118
|
-
buffer[position++] = 0;
|
|
119
|
-
// 座標C
|
|
120
|
-
buffer[position++] = vertex[idx + 6];
|
|
121
|
-
buffer[position++] = vertex[idx + 7];
|
|
122
|
-
buffer[position++] = 0.5;
|
|
123
|
-
buffer[position++] = 0.5;
|
|
124
|
-
buffer[position++] = red;
|
|
125
|
-
buffer[position++] = green;
|
|
126
|
-
buffer[position++] = blue;
|
|
127
|
-
buffer[position++] = alpha;
|
|
128
|
-
buffer[position++] = a;
|
|
129
|
-
buffer[position++] = b;
|
|
130
|
-
buffer[position++] = 0;
|
|
131
|
-
buffer[position++] = c;
|
|
132
|
-
buffer[position++] = d;
|
|
133
|
-
buffer[position++] = 0;
|
|
134
|
-
buffer[position++] = tx;
|
|
135
|
-
buffer[position++] = ty;
|
|
136
|
-
buffer[position++] = 0;
|
|
88
|
+
if (vertex[idx + 2]) {
|
|
89
|
+
// 曲線: 始点 (0, 0)、制御点 (0.5, 0)、終点 (1, 1)
|
|
90
|
+
buffer[position] = vertex[idx - 3];
|
|
91
|
+
buffer[position + 1] = vertex[idx - 2];
|
|
92
|
+
buffer[position + 2] = 0;
|
|
93
|
+
buffer[position + 3] = 0;
|
|
94
|
+
buffer[position + 17] = vertex[idx];
|
|
95
|
+
buffer[position + 18] = vertex[idx + 1];
|
|
96
|
+
buffer[position + 19] = 0.5;
|
|
97
|
+
buffer[position + 20] = 0;
|
|
98
|
+
buffer[position + 34] = vertex[idx + 3];
|
|
99
|
+
buffer[position + 35] = vertex[idx + 4];
|
|
100
|
+
buffer[position + 36] = 1;
|
|
101
|
+
buffer[position + 37] = 1;
|
|
137
102
|
}
|
|
138
103
|
else {
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
buffer[position
|
|
142
|
-
buffer[position
|
|
143
|
-
buffer[position
|
|
144
|
-
buffer[position
|
|
145
|
-
buffer[position
|
|
146
|
-
buffer[position
|
|
147
|
-
buffer[position
|
|
148
|
-
buffer[position
|
|
149
|
-
buffer[position
|
|
150
|
-
buffer[position
|
|
151
|
-
buffer[position
|
|
152
|
-
buffer[position
|
|
153
|
-
buffer[position++] = 0;
|
|
154
|
-
buffer[position++] = tx;
|
|
155
|
-
buffer[position++] = ty;
|
|
156
|
-
buffer[position++] = 0;
|
|
157
|
-
// 座標B
|
|
158
|
-
buffer[position++] = vertex[idx];
|
|
159
|
-
buffer[position++] = vertex[idx + 1];
|
|
160
|
-
buffer[position++] = 0.5;
|
|
161
|
-
buffer[position++] = 0.5;
|
|
162
|
-
buffer[position++] = red;
|
|
163
|
-
buffer[position++] = green;
|
|
164
|
-
buffer[position++] = blue;
|
|
165
|
-
buffer[position++] = alpha;
|
|
166
|
-
buffer[position++] = a;
|
|
167
|
-
buffer[position++] = b;
|
|
168
|
-
buffer[position++] = 0;
|
|
169
|
-
buffer[position++] = c;
|
|
170
|
-
buffer[position++] = d;
|
|
171
|
-
buffer[position++] = 0;
|
|
172
|
-
buffer[position++] = tx;
|
|
173
|
-
buffer[position++] = ty;
|
|
174
|
-
buffer[position++] = 0;
|
|
175
|
-
// 座標C
|
|
176
|
-
buffer[position++] = vertex[idx + 3];
|
|
177
|
-
buffer[position++] = vertex[idx + 4];
|
|
178
|
-
buffer[position++] = 0.5;
|
|
179
|
-
buffer[position++] = 0.5;
|
|
180
|
-
buffer[position++] = red;
|
|
181
|
-
buffer[position++] = green;
|
|
182
|
-
buffer[position++] = blue;
|
|
183
|
-
buffer[position++] = alpha;
|
|
184
|
-
buffer[position++] = a;
|
|
185
|
-
buffer[position++] = b;
|
|
186
|
-
buffer[position++] = 0;
|
|
187
|
-
buffer[position++] = c;
|
|
188
|
-
buffer[position++] = d;
|
|
189
|
-
buffer[position++] = 0;
|
|
190
|
-
buffer[position++] = tx;
|
|
191
|
-
buffer[position++] = ty;
|
|
192
|
-
buffer[position++] = 0;
|
|
104
|
+
// 直線: 先頭の点からの扇形。次の点が制御点なら、その先の終点と結ぶ
|
|
105
|
+
const next = vertex[idx + 5] ? idx + 6 : idx + 3;
|
|
106
|
+
buffer[position] = vertex[0];
|
|
107
|
+
buffer[position + 1] = vertex[1];
|
|
108
|
+
buffer[position + 2] = 0.5;
|
|
109
|
+
buffer[position + 3] = 0.5;
|
|
110
|
+
buffer[position + 17] = vertex[idx];
|
|
111
|
+
buffer[position + 18] = vertex[idx + 1];
|
|
112
|
+
buffer[position + 19] = 0.5;
|
|
113
|
+
buffer[position + 20] = 0.5;
|
|
114
|
+
buffer[position + 34] = vertex[next];
|
|
115
|
+
buffer[position + 35] = vertex[next + 1];
|
|
116
|
+
buffer[position + 36] = 0.5;
|
|
117
|
+
buffer[position + 37] = 0.5;
|
|
193
118
|
}
|
|
194
119
|
index += 3;
|
|
195
120
|
}
|
|
@@ -4,6 +4,16 @@ import type { IPoint } from "../../interface/IPoint";
|
|
|
4
4
|
* @description カーブの矩形を計算する
|
|
5
5
|
* Calculate curve rectangle
|
|
6
6
|
*
|
|
7
|
+
* 曲線を 32 区間に分割し、各区間を左右へ thickness だけずらした輪郭を返す。
|
|
8
|
+
* 線の輪郭は図形を初めて描くときに曲線ごとに計算されるため、点や区間ごとに
|
|
9
|
+
* オブジェクトや配列を作ると、その確保と回収が描画の停止として現れる。
|
|
10
|
+
* ここでは作業領域を使い回し、結果の配列だけを作る。
|
|
11
|
+
*
|
|
12
|
+
* Splits the curve into 32 segments and returns the outline offset by thickness on both sides.
|
|
13
|
+
* Outlines are computed per curve the first time a shape is drawn, so allocating an object or
|
|
14
|
+
* an array per point or segment shows up as a stall. Work buffers are reused here and only
|
|
15
|
+
* the result array is allocated.
|
|
16
|
+
*
|
|
7
17
|
* @param {IPoint} start_point
|
|
8
18
|
* @param {IPoint} control_point
|
|
9
19
|
* @param {IPoint} end_point
|
|
@@ -1,9 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description 2次ベジェ曲線を半分に分割する回数。分割後の区間数は 2 の SPLIT_COUNT 乗。
|
|
3
|
+
* Number of times a quadratic Bezier curve is halved. The curve ends up in 2 ** SPLIT_COUNT segments.
|
|
4
|
+
*
|
|
5
|
+
* @type {number}
|
|
6
|
+
* @const
|
|
7
|
+
*/
|
|
8
|
+
const SPLIT_COUNT = 5;
|
|
9
|
+
/**
|
|
10
|
+
* @description 分割後の区間数
|
|
11
|
+
* Number of segments after splitting
|
|
12
|
+
*
|
|
13
|
+
* @type {number}
|
|
14
|
+
* @const
|
|
15
|
+
*/
|
|
16
|
+
const SEGMENT_COUNT = 1 << SPLIT_COUNT;
|
|
17
|
+
/**
|
|
18
|
+
* @description 分割中の区間 (1区間 = 始点・制御点・終点の x, y で 6 要素)。2 本を交互に使う。
|
|
19
|
+
* Segments being split (six values per segment: x, y of the start, control and end points).
|
|
20
|
+
* The two buffers are used alternately.
|
|
21
|
+
*
|
|
22
|
+
* @type {Float64Array}
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
let $segments = new Float64Array(SEGMENT_COUNT * 6);
|
|
26
|
+
let $nextSegments = new Float64Array(SEGMENT_COUNT * 6);
|
|
27
|
+
/**
|
|
28
|
+
* @description 右側の輪郭の点 (1区間 = t=0, 0.5, 1 の x, y で 6 要素)。逆順に並べるため一旦ためる。
|
|
29
|
+
* Points of the right outline (six values per segment: x, y at t = 0, 0.5 and 1).
|
|
30
|
+
* Kept until the end because they are emitted in reverse order.
|
|
31
|
+
*
|
|
32
|
+
* @type {Float64Array}
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
const $rightPoints = new Float64Array(SEGMENT_COUNT * 6);
|
|
36
|
+
/**
|
|
37
|
+
* @description $offsetPoint の結果
|
|
38
|
+
* Result of $offsetPoint
|
|
39
|
+
*
|
|
40
|
+
* @type {number}
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
let $offsetX = 0;
|
|
44
|
+
let $offsetY = 0;
|
|
45
|
+
/**
|
|
46
|
+
* @description 2次ベジェ曲線上の t の点を、法線方向へ offset だけずらした点を $offsetX / $offsetY に求める。
|
|
47
|
+
* (MeshGetQuadraticBezierPointService / MeshGetQuadraticBezierTangentService /
|
|
48
|
+
* MeshCalculateNormalizeBezierService と同じ計算を、オブジェクトを作らずに行う)
|
|
49
|
+
* Computes into $offsetX / $offsetY the point at t on a quadratic Bezier curve, moved by
|
|
50
|
+
* offset along the normal. Same arithmetic as the three services above, without allocating objects.
|
|
51
|
+
*
|
|
52
|
+
* @param {number} t
|
|
53
|
+
* @param {number} x0
|
|
54
|
+
* @param {number} y0
|
|
55
|
+
* @param {number} x1
|
|
56
|
+
* @param {number} y1
|
|
57
|
+
* @param {number} x2
|
|
58
|
+
* @param {number} y2
|
|
59
|
+
* @param {number} offset
|
|
60
|
+
* @return {void}
|
|
61
|
+
* @method
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
const $offsetPoint = (t, x0, y0, x1, y1, x2, y2, offset) => {
|
|
65
|
+
const positionX = (1 - t) ** 2 * x0 + 2 * (1 - t) * t * x1 + t ** 2 * x2;
|
|
66
|
+
const positionY = (1 - t) ** 2 * y0 + 2 * (1 - t) * t * y1 + t ** 2 * y2;
|
|
67
|
+
const tangentX = 2 * (1 - t) * (x1 - x0) + 2 * t * (x2 - x1);
|
|
68
|
+
const tangentY = 2 * (1 - t) * (y1 - y0) + 2 * t * (y2 - y1);
|
|
69
|
+
// 接線を 90 度回した法線を正規化する
|
|
70
|
+
const normalX = -tangentY;
|
|
71
|
+
const normalY = tangentX;
|
|
72
|
+
const length = Math.sqrt(normalX * normalX + normalY * normalY);
|
|
73
|
+
if (length === 0) {
|
|
74
|
+
$offsetX = positionX + 0 * offset;
|
|
75
|
+
$offsetY = positionY + 0 * offset;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
$offsetX = positionX + normalX / length * offset;
|
|
79
|
+
$offsetY = positionY + normalY / length * offset;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
3
82
|
/**
|
|
4
83
|
* @description カーブの矩形を計算する
|
|
5
84
|
* Calculate curve rectangle
|
|
6
85
|
*
|
|
86
|
+
* 曲線を 32 区間に分割し、各区間を左右へ thickness だけずらした輪郭を返す。
|
|
87
|
+
* 線の輪郭は図形を初めて描くときに曲線ごとに計算されるため、点や区間ごとに
|
|
88
|
+
* オブジェクトや配列を作ると、その確保と回収が描画の停止として現れる。
|
|
89
|
+
* ここでは作業領域を使い回し、結果の配列だけを作る。
|
|
90
|
+
*
|
|
91
|
+
* Splits the curve into 32 segments and returns the outline offset by thickness on both sides.
|
|
92
|
+
* Outlines are computed per curve the first time a shape is drawn, so allocating an object or
|
|
93
|
+
* an array per point or segment shows up as a stall. Work buffers are reused here and only
|
|
94
|
+
* the result array is allocated.
|
|
95
|
+
*
|
|
7
96
|
* @param {IPoint} start_point
|
|
8
97
|
* @param {IPoint} control_point
|
|
9
98
|
* @param {IPoint} end_point
|
|
@@ -13,39 +102,88 @@ import { execute as meshApproximateOffsetQuadraticUseCase } from "./MeshApproxim
|
|
|
13
102
|
* @protected
|
|
14
103
|
*/
|
|
15
104
|
export const execute = (start_point, control_point, end_point, thickness) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
105
|
+
// 曲線を半分に分割することを SPLIT_COUNT 回繰り返す (De Casteljau、t = 0.5)
|
|
106
|
+
let segments = $segments;
|
|
107
|
+
let nextSegments = $nextSegments;
|
|
108
|
+
segments[0] = start_point.x;
|
|
109
|
+
segments[1] = start_point.y;
|
|
110
|
+
segments[2] = control_point.x;
|
|
111
|
+
segments[3] = control_point.y;
|
|
112
|
+
segments[4] = end_point.x;
|
|
113
|
+
segments[5] = end_point.y;
|
|
114
|
+
let count = 1;
|
|
115
|
+
for (let split = 0; split < SPLIT_COUNT; ++split) {
|
|
116
|
+
for (let idx = 0; idx < count; ++idx) {
|
|
117
|
+
const source = idx * 6;
|
|
118
|
+
const x0 = segments[source];
|
|
119
|
+
const y0 = segments[source + 1];
|
|
120
|
+
const x1 = segments[source + 2];
|
|
121
|
+
const y1 = segments[source + 3];
|
|
122
|
+
const x2 = segments[source + 4];
|
|
123
|
+
const y2 = segments[source + 5];
|
|
124
|
+
const m0x = x0 + (x1 - x0) * 0.5;
|
|
125
|
+
const m0y = y0 + (y1 - y0) * 0.5;
|
|
126
|
+
const m1x = x1 + (x2 - x1) * 0.5;
|
|
127
|
+
const m1y = y1 + (y2 - y1) * 0.5;
|
|
128
|
+
const m01x = m0x + (m1x - m0x) * 0.5;
|
|
129
|
+
const m01y = m0y + (m1y - m0y) * 0.5;
|
|
130
|
+
const target = idx * 12;
|
|
131
|
+
nextSegments[target] = x0;
|
|
132
|
+
nextSegments[target + 1] = y0;
|
|
133
|
+
nextSegments[target + 2] = m0x;
|
|
134
|
+
nextSegments[target + 3] = m0y;
|
|
135
|
+
nextSegments[target + 4] = m01x;
|
|
136
|
+
nextSegments[target + 5] = m01y;
|
|
137
|
+
nextSegments[target + 6] = m01x;
|
|
138
|
+
nextSegments[target + 7] = m01y;
|
|
139
|
+
nextSegments[target + 8] = m1x;
|
|
140
|
+
nextSegments[target + 9] = m1y;
|
|
141
|
+
nextSegments[target + 10] = x2;
|
|
142
|
+
nextSegments[target + 11] = y2;
|
|
143
|
+
}
|
|
144
|
+
const swap = segments;
|
|
145
|
+
segments = nextSegments;
|
|
146
|
+
nextSegments = swap;
|
|
147
|
+
count *= 2;
|
|
36
148
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
149
|
+
$segments = segments;
|
|
150
|
+
$nextSegments = nextSegments;
|
|
151
|
+
// 左側の輪郭: 最初の区間の始点、続けて各区間の中間点 (制御点) と終点
|
|
152
|
+
$offsetPoint(0, segments[0], segments[1], segments[2], segments[3], segments[4], segments[5], +thickness);
|
|
153
|
+
const paths = [$offsetX, $offsetY, false];
|
|
154
|
+
const rightPoints = $rightPoints;
|
|
155
|
+
for (let idx = 0; idx < count; ++idx) {
|
|
156
|
+
const source = idx * 6;
|
|
157
|
+
const x0 = segments[source];
|
|
158
|
+
const y0 = segments[source + 1];
|
|
159
|
+
const x1 = segments[source + 2];
|
|
160
|
+
const y1 = segments[source + 3];
|
|
161
|
+
const x2 = segments[source + 4];
|
|
162
|
+
const y2 = segments[source + 5];
|
|
163
|
+
$offsetPoint(0.5, x0, y0, x1, y1, x2, y2, +thickness);
|
|
164
|
+
const controlX = $offsetX;
|
|
165
|
+
const controlY = $offsetY;
|
|
166
|
+
$offsetPoint(1, x0, y0, x1, y1, x2, y2, +thickness);
|
|
167
|
+
paths.push(controlX, controlY, true, $offsetX, $offsetY, false);
|
|
168
|
+
// 右側の輪郭は逆順に出力するので、ここではためておく
|
|
169
|
+
$offsetPoint(0, x0, y0, x1, y1, x2, y2, -thickness);
|
|
170
|
+
rightPoints[source] = $offsetX;
|
|
171
|
+
rightPoints[source + 1] = $offsetY;
|
|
172
|
+
$offsetPoint(0.5, x0, y0, x1, y1, x2, y2, -thickness);
|
|
173
|
+
rightPoints[source + 2] = $offsetX;
|
|
174
|
+
rightPoints[source + 3] = $offsetY;
|
|
175
|
+
if (idx === count - 1) {
|
|
176
|
+
$offsetPoint(1, x0, y0, x1, y1, x2, y2, -thickness);
|
|
177
|
+
rightPoints[source + 4] = $offsetX;
|
|
178
|
+
rightPoints[source + 5] = $offsetY;
|
|
179
|
+
}
|
|
41
180
|
}
|
|
42
|
-
//
|
|
43
|
-
const
|
|
44
|
-
paths.push(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
paths.push(curves[1].x, curves[1].y, true, curves[2].x, curves[2].y, false);
|
|
181
|
+
// 右側の輪郭: 最後の区間の終点から始め、区間を逆順に (中間点、始点) とたどる
|
|
182
|
+
const last = (count - 1) * 6;
|
|
183
|
+
paths.push(rightPoints[last + 4], rightPoints[last + 5], false);
|
|
184
|
+
for (let idx = count - 1; idx >= 0; --idx) {
|
|
185
|
+
const source = idx * 6;
|
|
186
|
+
paths.push(rightPoints[source + 2], rightPoints[source + 3], true, rightPoints[source], rightPoints[source + 1], false);
|
|
49
187
|
}
|
|
50
188
|
return paths;
|
|
51
189
|
};
|