@next2d/webgpu 3.17.1 → 3.18.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 +3 -3
- package/src/Context.d.ts +14 -0
- package/src/Context.js +20 -0
- package/src/Mesh/usecase/MeshFillGenerateUseCase.js +12 -0
- package/src/NativeShape.d.ts +49 -0
- package/src/NativeShape.js +33 -0
- package/src/PathCommand.d.ts +21 -0
- package/src/PathCommand.js +73 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/webgpu",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.18.0",
|
|
4
4
|
"description": "Next2D WebGPU 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.18.0",
|
|
28
|
+
"@next2d/render-queue": "3.18.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/Context.d.ts
CHANGED
|
@@ -298,6 +298,20 @@ export declare class Context {
|
|
|
298
298
|
* @return {void}
|
|
299
299
|
*/
|
|
300
300
|
arc(x: number, y: number, radius: number): void;
|
|
301
|
+
/**
|
|
302
|
+
* @description 描画命令の並びのうち、index から続く経路の命令をまとめて処理する。
|
|
303
|
+
* 実行環境が経路の実装を提供していればそれを使い、次に処理する命令の位置を返す。
|
|
304
|
+
* 使えないときは -1 を返すので、呼び出し側が moveTo などを 1 つずつ呼ぶ。
|
|
305
|
+
* Processes the run of path commands starting at index in one go. Uses the
|
|
306
|
+
* runtime's path implementation when it provides one and returns the position of
|
|
307
|
+
* the next command. Returns -1 when unavailable, in which case the caller issues
|
|
308
|
+
* moveTo and the like one by one.
|
|
309
|
+
*
|
|
310
|
+
* @param {Float32Array} commands
|
|
311
|
+
* @param {number} index
|
|
312
|
+
* @return {number}
|
|
313
|
+
*/
|
|
314
|
+
pathCommands(commands: Float32Array, index: number): number;
|
|
301
315
|
/**
|
|
302
316
|
* @description 3次ベジェ曲線を描画
|
|
303
317
|
* Draw a cubic Bézier curve
|
package/src/Context.js
CHANGED
|
@@ -660,6 +660,26 @@ export class Context {
|
|
|
660
660
|
arc(x, y, radius) {
|
|
661
661
|
this.pathCommand.arc(x, y, radius);
|
|
662
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* @description 描画命令の並びのうち、index から続く経路の命令をまとめて処理する。
|
|
665
|
+
* 実行環境が経路の実装を提供していればそれを使い、次に処理する命令の位置を返す。
|
|
666
|
+
* 使えないときは -1 を返すので、呼び出し側が moveTo などを 1 つずつ呼ぶ。
|
|
667
|
+
* Processes the run of path commands starting at index in one go. Uses the
|
|
668
|
+
* runtime's path implementation when it provides one and returns the position of
|
|
669
|
+
* the next command. Returns -1 when unavailable, in which case the caller issues
|
|
670
|
+
* moveTo and the like one by one.
|
|
671
|
+
*
|
|
672
|
+
* @param {Float32Array} commands
|
|
673
|
+
* @param {number} index
|
|
674
|
+
* @return {number}
|
|
675
|
+
*/
|
|
676
|
+
pathCommands(commands, index) {
|
|
677
|
+
// 曲線の座標 1 単位が画面上で何ピクセルになるか (bezierCurveTo と同じ計算)
|
|
678
|
+
const matrix = this.$matrix;
|
|
679
|
+
const scaleX = matrix[0] * matrix[0] + matrix[1] * matrix[1];
|
|
680
|
+
const scaleY = matrix[3] * matrix[3] + matrix[4] * matrix[4];
|
|
681
|
+
return this.pathCommand.pathCommands(commands, index, Math.sqrt(scaleX > scaleY ? scaleX : scaleY));
|
|
682
|
+
}
|
|
663
683
|
/**
|
|
664
684
|
* @description 3次ベジェ曲線を描画
|
|
665
685
|
* Draw a cubic Bézier curve
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execute as meshFillGenerateService } from "../service/MeshFillGenerateService";
|
|
2
|
+
import { $nativeShape, $nativeFillSize, $NATIVE_FILL_PATH } from "../../NativeShape";
|
|
2
3
|
/**
|
|
3
4
|
* @description メッシュ生成用の再利用可能な一時バッファ(GC回避)
|
|
4
5
|
*/
|
|
@@ -30,6 +31,17 @@ const $upperPowerOfTwo = (v) => {
|
|
|
30
31
|
* @protected
|
|
31
32
|
*/
|
|
32
33
|
export const execute = (vertices) => {
|
|
34
|
+
// 経路が実行環境の側にあるときは、メッシュもそちらで作る
|
|
35
|
+
if (vertices === $NATIVE_FILL_PATH && $nativeShape) {
|
|
36
|
+
if ($meshTempBuffer.length < $nativeFillSize) {
|
|
37
|
+
$meshTempBuffer = new Float32Array($upperPowerOfTwo($nativeFillSize));
|
|
38
|
+
}
|
|
39
|
+
const indexCount = $nativeShape.fill($meshTempBuffer);
|
|
40
|
+
return {
|
|
41
|
+
"buffer": $meshTempBuffer.subarray(0, indexCount * 4),
|
|
42
|
+
"indexCount": indexCount
|
|
43
|
+
};
|
|
44
|
+
}
|
|
33
45
|
// 頂点数を計算(各パスの三角形数 × 3)
|
|
34
46
|
let totalVertices = 0;
|
|
35
47
|
for (const vertex of vertices) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { IPath } from "./interface/IPath";
|
|
2
|
+
/**
|
|
3
|
+
* @description 実行環境が提供する、図形の「経路の組み立て」と「塗りのメッシュの生成」の実装 (WebGPU 用)。
|
|
4
|
+
* JIT が使えない実行環境 (ゲーム機向けのホスト) が、グローバルの __next2dShape.webgpu に置く。
|
|
5
|
+
* 無い環境 (ブラウザ) では null で、すべて JavaScript で処理する。結果はどちらも同じ。
|
|
6
|
+
*
|
|
7
|
+
* The implementation of path building and fill mesh generation provided by the runtime
|
|
8
|
+
* (for WebGPU). Runtimes without a JIT (hosts for game consoles) put it on the global
|
|
9
|
+
* as __next2dShape.webgpu. Where it is absent (browsers) this is null and everything
|
|
10
|
+
* runs in JavaScript. Both produce the same result.
|
|
11
|
+
*/
|
|
12
|
+
export interface INativeShape {
|
|
13
|
+
path(commands: Float32Array, index: number, pixel_scale: number): number;
|
|
14
|
+
fillSize(): number;
|
|
15
|
+
fill(target: Float32Array): number;
|
|
16
|
+
exportPath(stroke: boolean): Float64Array;
|
|
17
|
+
reset(): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @type {INativeShape | null}
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare const $nativeShape: INativeShape | null;
|
|
24
|
+
/**
|
|
25
|
+
* @description 経路が実行環境の側にあることを表す目印。PathCommand.$getVertices がこれを返したら、
|
|
26
|
+
* MeshFillGenerateUseCase はメッシュを実行環境の側で作る。中身は使わない。
|
|
27
|
+
* A marker meaning that the path lives on the runtime side. When PathCommand.$getVertices
|
|
28
|
+
* returns it, MeshFillGenerateUseCase generates the mesh on the runtime side. Its content
|
|
29
|
+
* is not used.
|
|
30
|
+
*
|
|
31
|
+
* @type {IPath[]}
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export declare const $NATIVE_FILL_PATH: IPath[];
|
|
35
|
+
/**
|
|
36
|
+
* @description $NATIVE_FILL_PATH を返したときの、塗りのメッシュの要素数
|
|
37
|
+
* Element count of the fill mesh at the time $NATIVE_FILL_PATH was returned
|
|
38
|
+
*
|
|
39
|
+
* @type {number}
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare let $nativeFillSize: number;
|
|
43
|
+
/**
|
|
44
|
+
* @param {number} size
|
|
45
|
+
* @return {void}
|
|
46
|
+
* @method
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare const $setNativeFillSize: (size: number) => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type {INativeShape | null}
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export const $nativeShape = globalThis.__next2dShape?.webgpu || null;
|
|
6
|
+
/**
|
|
7
|
+
* @description 経路が実行環境の側にあることを表す目印。PathCommand.$getVertices がこれを返したら、
|
|
8
|
+
* MeshFillGenerateUseCase はメッシュを実行環境の側で作る。中身は使わない。
|
|
9
|
+
* A marker meaning that the path lives on the runtime side. When PathCommand.$getVertices
|
|
10
|
+
* returns it, MeshFillGenerateUseCase generates the mesh on the runtime side. Its content
|
|
11
|
+
* is not used.
|
|
12
|
+
*
|
|
13
|
+
* @type {IPath[]}
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export const $NATIVE_FILL_PATH = [[]];
|
|
17
|
+
/**
|
|
18
|
+
* @description $NATIVE_FILL_PATH を返したときの、塗りのメッシュの要素数
|
|
19
|
+
* Element count of the fill mesh at the time $NATIVE_FILL_PATH was returned
|
|
20
|
+
*
|
|
21
|
+
* @type {number}
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export let $nativeFillSize = 0;
|
|
25
|
+
/**
|
|
26
|
+
* @param {number} size
|
|
27
|
+
* @return {void}
|
|
28
|
+
* @method
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export const $setNativeFillSize = (size) => {
|
|
32
|
+
$nativeFillSize = size;
|
|
33
|
+
};
|
package/src/PathCommand.d.ts
CHANGED
|
@@ -38,6 +38,12 @@ export declare class PathCommand {
|
|
|
38
38
|
* Start Y coordinate of current sub-path
|
|
39
39
|
*/
|
|
40
40
|
private $startY;
|
|
41
|
+
/**
|
|
42
|
+
* @description 経路を実行環境の側で組み立てているかどうか。true の間、こちらの経路は空。
|
|
43
|
+
* Whether the path is being built on the runtime side. While true, the path held
|
|
44
|
+
* here is empty.
|
|
45
|
+
*/
|
|
46
|
+
private $native;
|
|
41
47
|
/**
|
|
42
48
|
* @constructor
|
|
43
49
|
*/
|
|
@@ -47,6 +53,21 @@ export declare class PathCommand {
|
|
|
47
53
|
* @return {void}
|
|
48
54
|
*/
|
|
49
55
|
beginPath(): void;
|
|
56
|
+
/**
|
|
57
|
+
* @description 描画命令の並びのうち、index から続く経路の命令をまとめて処理する。
|
|
58
|
+
* 実行環境が経路の実装を提供していればそれを使い、次に処理する命令の位置を返す。
|
|
59
|
+
* 使えないときは -1 を返すので、呼び出し側が moveTo などを 1 つずつ呼ぶ。
|
|
60
|
+
* Processes the run of path commands starting at index in one go. Uses the
|
|
61
|
+
* runtime's path implementation when it provides one and returns the position of
|
|
62
|
+
* the next command. Returns -1 when unavailable, in which case the caller issues
|
|
63
|
+
* moveTo and the like one by one.
|
|
64
|
+
*
|
|
65
|
+
* @param {Float32Array} commands
|
|
66
|
+
* @param {number} index
|
|
67
|
+
* @param {number} pixel_scale 曲線の座標 1 単位が画面上で何ピクセルになるか (bezierCurveTo と同じ)
|
|
68
|
+
* @return {number}
|
|
69
|
+
*/
|
|
70
|
+
pathCommands(commands: Float32Array, index: number, pixel_scale: number): number;
|
|
50
71
|
/**
|
|
51
72
|
* @description パスを移動
|
|
52
73
|
* @param {number} x
|
package/src/PathCommand.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { adaptiveCubicToQuad } from "./BezierConverter/BezierConverter";
|
|
2
|
+
import { $nativeShape, $NATIVE_FILL_PATH, $setNativeFillSize } from "./NativeShape";
|
|
3
|
+
/**
|
|
4
|
+
* @description 経路が 1 本も無いときに返す配列
|
|
5
|
+
* The array returned when there is no path at all
|
|
6
|
+
*/
|
|
7
|
+
const $EMPTY_VERTICES = [];
|
|
2
8
|
/**
|
|
3
9
|
* @description 3次ベジェ曲線を 1 本の2次ベジェ曲線で近似できる上限。
|
|
4
10
|
* (許容誤差 0.05 ピクセル * 36 / √3)² = 1.08。WebGL版と同じ。
|
|
@@ -19,6 +25,12 @@ export class PathCommand {
|
|
|
19
25
|
* @constructor
|
|
20
26
|
*/
|
|
21
27
|
constructor() {
|
|
28
|
+
/**
|
|
29
|
+
* @description 経路を実行環境の側で組み立てているかどうか。true の間、こちらの経路は空。
|
|
30
|
+
* Whether the path is being built on the runtime side. While true, the path held
|
|
31
|
+
* here is empty.
|
|
32
|
+
*/
|
|
33
|
+
this.$native = false;
|
|
22
34
|
/**
|
|
23
35
|
* @description フラットネス閾値(スケールに応じて調整可能)
|
|
24
36
|
* Flatness threshold for adaptive tessellation
|
|
@@ -37,6 +49,10 @@ export class PathCommand {
|
|
|
37
49
|
* @return {void}
|
|
38
50
|
*/
|
|
39
51
|
beginPath() {
|
|
52
|
+
if (this.$native) {
|
|
53
|
+
this.$native = false;
|
|
54
|
+
$nativeShape.reset();
|
|
55
|
+
}
|
|
40
56
|
this.$currentPath = [];
|
|
41
57
|
this.$vertices = [];
|
|
42
58
|
this.$currentX = 0;
|
|
@@ -44,6 +60,33 @@ export class PathCommand {
|
|
|
44
60
|
this.$startX = 0;
|
|
45
61
|
this.$startY = 0;
|
|
46
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* @description 描画命令の並びのうち、index から続く経路の命令をまとめて処理する。
|
|
65
|
+
* 実行環境が経路の実装を提供していればそれを使い、次に処理する命令の位置を返す。
|
|
66
|
+
* 使えないときは -1 を返すので、呼び出し側が moveTo などを 1 つずつ呼ぶ。
|
|
67
|
+
* Processes the run of path commands starting at index in one go. Uses the
|
|
68
|
+
* runtime's path implementation when it provides one and returns the position of
|
|
69
|
+
* the next command. Returns -1 when unavailable, in which case the caller issues
|
|
70
|
+
* moveTo and the like one by one.
|
|
71
|
+
*
|
|
72
|
+
* @param {Float32Array} commands
|
|
73
|
+
* @param {number} index
|
|
74
|
+
* @param {number} pixel_scale 曲線の座標 1 単位が画面上で何ピクセルになるか (bezierCurveTo と同じ)
|
|
75
|
+
* @return {number}
|
|
76
|
+
*/
|
|
77
|
+
pathCommands(commands, index, pixel_scale) {
|
|
78
|
+
if (!$nativeShape) {
|
|
79
|
+
return -1;
|
|
80
|
+
}
|
|
81
|
+
if (!this.$native) {
|
|
82
|
+
// こちらで経路を作り始めていたら、混ぜない
|
|
83
|
+
if (this.$currentPath.length || this.$vertices.length) {
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
86
|
+
this.$native = true;
|
|
87
|
+
}
|
|
88
|
+
return $nativeShape.path(commands, index, pixel_scale);
|
|
89
|
+
}
|
|
47
90
|
/**
|
|
48
91
|
* @description パスを移動
|
|
49
92
|
* @param {number} x
|
|
@@ -190,6 +233,15 @@ export class PathCommand {
|
|
|
190
233
|
* @return {IPath[]}
|
|
191
234
|
*/
|
|
192
235
|
get $getVertices() {
|
|
236
|
+
// 経路が実行環境の側にあるときは、目印を返す (メッシュは MeshFillGenerateUseCase が実行環境の側で作る)
|
|
237
|
+
if (this.$native) {
|
|
238
|
+
const size = $nativeShape.fillSize();
|
|
239
|
+
if (size < 0) {
|
|
240
|
+
return $EMPTY_VERTICES;
|
|
241
|
+
}
|
|
242
|
+
$setNativeFillSize(size);
|
|
243
|
+
return $NATIVE_FILL_PATH;
|
|
244
|
+
}
|
|
193
245
|
const vertices = [...this.$vertices];
|
|
194
246
|
// fill用は3点以上(9要素)が必要
|
|
195
247
|
if (this.$currentPath.length >= 9) {
|
|
@@ -203,6 +255,23 @@ export class PathCommand {
|
|
|
203
255
|
* @return {IPath[]}
|
|
204
256
|
*/
|
|
205
257
|
getVerticesForStroke() {
|
|
258
|
+
// 線の生成はこちらで行うので、実行環境の側の経路を取り出す
|
|
259
|
+
if (this.$native) {
|
|
260
|
+
const data = $nativeShape.exportPath(true);
|
|
261
|
+
const paths = [];
|
|
262
|
+
const count = data[0];
|
|
263
|
+
let offset = 1;
|
|
264
|
+
for (let idx = 0; idx < count; ++idx) {
|
|
265
|
+
const size = data[offset++];
|
|
266
|
+
const path = [];
|
|
267
|
+
for (let position = 0; position < size; position += 3) {
|
|
268
|
+
path.push(data[offset + position], data[offset + position + 1], data[offset + position + 2] !== 0);
|
|
269
|
+
}
|
|
270
|
+
offset += size;
|
|
271
|
+
paths.push(path);
|
|
272
|
+
}
|
|
273
|
+
return paths;
|
|
274
|
+
}
|
|
206
275
|
const vertices = [...this.$vertices];
|
|
207
276
|
if (this.$currentPath.length >= 6) {
|
|
208
277
|
vertices.push(this.$currentPath);
|
|
@@ -214,6 +283,10 @@ export class PathCommand {
|
|
|
214
283
|
* @return {void}
|
|
215
284
|
*/
|
|
216
285
|
reset() {
|
|
286
|
+
if (this.$native) {
|
|
287
|
+
this.$native = false;
|
|
288
|
+
$nativeShape.reset();
|
|
289
|
+
}
|
|
217
290
|
this.$currentPath = [];
|
|
218
291
|
this.$vertices = [];
|
|
219
292
|
this.$currentX = 0;
|