vgpu-render 0.1.0 → 0.3.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/README.md +101 -34
- package/dist/curve.d.ts +26 -1
- package/dist/curve.js +53 -0
- package/dist/debug-draw-3d.d.ts +3 -3
- package/dist/debug-draw-3d.js +10 -10
- package/dist/frame-draw-list-2d.d.ts +286 -0
- package/dist/frame-draw-list-2d.js +668 -0
- package/dist/{frame-recorder.d.ts → frame-draw-list.d.ts} +60 -8
- package/dist/{frame-recorder.js → frame-draw-list.js} +51 -10
- package/dist/geometry-generators.d.ts +11 -2
- package/dist/geometry-generators.js +37 -1
- package/dist/gpu-debug-draw-2d.d.ts +1 -1
- package/dist/gpu-debug-draw-2d.js +10 -2
- package/dist/gpu-debug-draw-3d.d.ts +1 -1
- package/dist/gpu-debug-draw-3d.js +4 -2
- package/dist/gpu-text-3d.d.ts +1 -1
- package/dist/gpu-text-3d.js +49 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -3
- package/dist/mesh-batch-3d.d.ts +1 -1
- package/dist/shape2d-shader.js +295 -7
- package/dist/text-atlas.d.ts +6 -4
- package/dist/text-atlas.js +9 -6
- package/dist/text-font.d.ts +48 -7
- package/dist/text-font.js +63 -11
- package/dist/text-layout.d.ts +63 -4
- package/dist/text-layout.js +58 -8
- package/dist/text-msdf-baked.d.ts +9 -4
- package/dist/text-msdf-baked.js +9 -4
- package/dist/text-msdf-font.d.ts +10 -4
- package/dist/text-msdf-font.js +9 -3
- package/dist/vector-math.d.ts +19 -0
- package/dist/vector-math.js +37 -0
- package/package.json +1 -1
- package/dist/frame-recorder-2d.d.ts +0 -177
- package/dist/frame-recorder-2d.js +0 -378
- package/dist/layout-3d.d.ts +0 -227
- package/dist/layout-3d.js +0 -226
- package/dist/scene-examples.d.ts +0 -39
- package/dist/scene-examples.js +0 -200
- package/dist/scenes-2d.d.ts +0 -18
- package/dist/scenes-2d.js +0 -160
- package/dist/scenes-3d.d.ts +0 -46
- package/dist/scenes-3d.js +0 -1994
- package/dist/text-scenes.d.ts +0 -85
- package/dist/text-scenes.js +0 -338
package/dist/scenes-2d.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* reference 2D reference pages.
|
|
3
|
-
*
|
|
4
|
-
* These are vgpu's own capability pages built on `frame.d2`, not ports of a reference: the
|
|
5
|
-
* reference has no 2D API, so the models are reference `2d_gizmos` and `2d_shapes`. That also
|
|
6
|
-
* means the coordinate convention is reference: the origin sits at the canvas centre, +y points up,
|
|
7
|
-
* and one world unit covers one canvas pixel before the 2D camera's pan and zoom.
|
|
8
|
-
*
|
|
9
|
-
* Two conventions carry over from the text pages: a page heading in the top-left corner (a
|
|
10
|
-
* screen-space block, so the labels stay put while the 2D camera pans), and one shape per column
|
|
11
|
-
* with the row meaning stated once.
|
|
12
|
-
*/
|
|
13
|
-
const TITLE = [0.92, 0.95, 1, 1];
|
|
14
|
-
const HINT = [0.55, 0.62, 0.72, 1];
|
|
15
|
-
const GRID = [0.32, 0.36, 0.44, 0.55];
|
|
16
|
-
const FILL = [0.93, 0.95, 0.98, 1];
|
|
17
|
-
const RING = [0.55, 0.72, 1, 1];
|
|
18
|
-
const WARM = [1, 0.72, 0.36, 1];
|
|
19
|
-
const COOL = [0.42, 0.86, 0.78, 1];
|
|
20
|
-
const ACCENT = [1, 0.55, 0.66, 1];
|
|
21
|
-
const ACTION = [0.98, 0.86, 0.42, 1];
|
|
22
|
-
/** Page heading: a screen-space title and note, fixed to the top-left corner. */
|
|
23
|
-
function heading(recorder, title, note) {
|
|
24
|
-
recorder.text([24, 16, 0], title, { space: "screen", fontSize: 17, anchor: "top-left", color: TITLE });
|
|
25
|
-
recorder.text([24, 38, 0], note, { space: "screen", fontSize: 12, anchor: "top-left", color: HINT });
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Dispatches the 2D pages. Returns false for every other id so `buildScene` can fall through to
|
|
29
|
-
* the 3D scenes.
|
|
30
|
-
*/
|
|
31
|
-
export function buildScene2D(id, recorder, time) {
|
|
32
|
-
switch (id) {
|
|
33
|
-
case "2d-gizmos":
|
|
34
|
-
gizmos2D(recorder, time);
|
|
35
|
-
return true;
|
|
36
|
-
case "2d-shapes":
|
|
37
|
-
shapes2D(recorder);
|
|
38
|
-
return true;
|
|
39
|
-
default:
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/** The twelve reference 2D primitives, filled in one row and outlined in the next. */
|
|
44
|
-
function shapes2D(recorder) {
|
|
45
|
-
heading(recorder, "2D Shapes", "filled row, ring row · drag to pan, scroll to zoom");
|
|
46
|
-
const d2 = recorder.d2;
|
|
47
|
-
const columns = 12;
|
|
48
|
-
const spacing = 100;
|
|
49
|
-
const startX = -((columns - 1) * spacing) / 2;
|
|
50
|
-
for (let index = 0; index < columns; index++) {
|
|
51
|
-
const x = startX + index * spacing;
|
|
52
|
-
drawShape(d2, index, [x, 110], true);
|
|
53
|
-
// The two polyline shapes have no interior to outline.
|
|
54
|
-
if (index < 10)
|
|
55
|
-
drawShape(d2, index, [x, -110], false);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/** One column of `shapes2D`, in the order reference `2d_shapes` example lists them. */
|
|
59
|
-
function drawShape(d2, shape, center, filled) {
|
|
60
|
-
const style = { fill: filled, strokeWidth: 4, color: filled ? FILL : RING };
|
|
61
|
-
const [x, y] = center;
|
|
62
|
-
switch (shape) {
|
|
63
|
-
case 0: // Circle::new(50)
|
|
64
|
-
d2.circle(center, 50, style);
|
|
65
|
-
return;
|
|
66
|
-
case 1: // CircularSector::new(50, 1.0)
|
|
67
|
-
d2.sector(center, 50, { ...style, sweep: 1.0 });
|
|
68
|
-
return;
|
|
69
|
-
case 2: // CircularSegment::new(50, 1.25)
|
|
70
|
-
d2.segment(center, 50, { ...style, sweep: 1.25 });
|
|
71
|
-
return;
|
|
72
|
-
case 3: // Ellipse::new(25, 50)
|
|
73
|
-
d2.ellipse(center, [25, 50], style);
|
|
74
|
-
return;
|
|
75
|
-
case 4: // Annulus::new(25, 50)
|
|
76
|
-
d2.annulus(center, 25, 50, style);
|
|
77
|
-
return;
|
|
78
|
-
case 5: // Capsule2d::new(25, 50)
|
|
79
|
-
d2.capsule(center, 25, 50, style);
|
|
80
|
-
return;
|
|
81
|
-
case 6: // Rhombus::new(75, 100)
|
|
82
|
-
d2.rhombus(center, [75, 100], style);
|
|
83
|
-
return;
|
|
84
|
-
case 7: // Rectangle::new(50, 100)
|
|
85
|
-
d2.rect(center, [50, 100], style);
|
|
86
|
-
return;
|
|
87
|
-
case 8: // RegularPolygon::new(50, 6)
|
|
88
|
-
d2.polygon(center, 50, 6, style);
|
|
89
|
-
return;
|
|
90
|
-
case 9: // Triangle2d::new(Vec2::Y * 50, Vec2::new(-50, -50), Vec2::new(50, -50))
|
|
91
|
-
d2.triangle([x, y + 50], [x - 50, y - 50], [x + 50, y - 50], style);
|
|
92
|
-
return;
|
|
93
|
-
case 10: // Segment2d::new(Vec2::new(-50, 50), Vec2::new(50, -50))
|
|
94
|
-
d2.line([x - 50, y + 50], [x + 50, y - 50], { width: 8, color: filled ? FILL : RING });
|
|
95
|
-
return;
|
|
96
|
-
default: // Polyline2d::new([(-50, 50), (0, -50), (50, 50)])
|
|
97
|
-
d2.lineStrip([[x - 50, y + 50], [x, y - 50], [x + 50, y + 50]], {
|
|
98
|
-
width: 8,
|
|
99
|
-
joint: "round",
|
|
100
|
-
color: filled ? FILL : RING,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/** reference `2d_gizmos` example, rebuilt with the stroke and shape primitives. */
|
|
105
|
-
function gizmos2D(recorder, time) {
|
|
106
|
-
heading(recorder, "2D Gizmos", "strokes and outlined shapes · drag to pan, scroll to zoom");
|
|
107
|
-
const d2 = recorder.d2;
|
|
108
|
-
// Background grid, drawn first so the strokes sit on top of it.
|
|
109
|
-
const cell = 60;
|
|
110
|
-
for (let index = -6; index <= 6; index++) {
|
|
111
|
-
d2.line([index * cell, -260], [index * cell, 260], { width: 1, color: GRID });
|
|
112
|
-
d2.line([-380, index * cell], [380, index * cell], { width: 1, color: GRID });
|
|
113
|
-
}
|
|
114
|
-
// line and ray.
|
|
115
|
-
d2.line([-460, 200], [-300, 200], { width: 5, color: ACTION });
|
|
116
|
-
d2.ray([-460, 140], [160, -40], { width: 5, color: COOL });
|
|
117
|
-
// Joined strip (round joints) and a dashed stroke with the same width.
|
|
118
|
-
d2.lineStrip([[-460, 60], [-410, 0], [-360, 60], [-310, 0], [-260, 60]], { width: 6, joint: "round", color: RING });
|
|
119
|
-
d2.line([-460, -20], [-260, -20], { width: 6, dash: [20, 14, 0], color: RING });
|
|
120
|
-
// Outlined boxes, one with rounded corners.
|
|
121
|
-
d2.rect([-120, 170], [120, 80], { fill: false, strokeWidth: 4, color: WARM });
|
|
122
|
-
d2.roundedRect([-120, 40], [140, 80], 26, { fill: false, strokeWidth: 4, color: WARM });
|
|
123
|
-
d2.grid([-120, -100], [4, 3], [40, 40], { width: 2, color: WARM });
|
|
124
|
-
// Circle, ellipse and an arc.
|
|
125
|
-
d2.circle([120, 170], 55, { fill: false, strokeWidth: 4, color: ACCENT });
|
|
126
|
-
d2.ellipse([120, 60], [75, 35], { fill: false, strokeWidth: 4, color: ACCENT });
|
|
127
|
-
d2.arc([120, -80], 55, { fill: false, strokeWidth: 4, startAngle: 0.4, sweep: 2.2, color: ACCENT });
|
|
128
|
-
// Cross marker.
|
|
129
|
-
for (const [x, y] of [[340, 200], [400, 200], [370, 170], [370, 230]]) {
|
|
130
|
-
d2.point([x, y], { size: 4, round: true, color: ACTION });
|
|
131
|
-
}
|
|
132
|
-
cross(d2, [340, 170], 34, ACTION);
|
|
133
|
-
cross(d2, [340, 230], 34, ACTION);
|
|
134
|
-
// Arrow: a shaft plus a filled triangle head that swings with time.
|
|
135
|
-
const angle = 1.1 + Math.sin(time * 0.9) * 0.5;
|
|
136
|
-
const origin = [330, 60];
|
|
137
|
-
const tip = [origin[0] + Math.cos(angle) * 140, origin[1] + Math.sin(angle) * 140];
|
|
138
|
-
const ux = Math.cos(angle);
|
|
139
|
-
const uy = Math.sin(angle);
|
|
140
|
-
const back = 22;
|
|
141
|
-
const spread = 11;
|
|
142
|
-
d2.line(origin, tip, { width: 5, color: ACTION });
|
|
143
|
-
d2.triangle(tip, [tip[0] - ux * back - uy * spread, tip[1] - uy * back + ux * spread], [tip[0] - ux * back + uy * spread, tip[1] - uy * back - ux * spread], { color: ACTION });
|
|
144
|
-
// A travelling sine curve, sampled into a strip.
|
|
145
|
-
const wave = [];
|
|
146
|
-
for (let step = 0; step <= 64; step++) {
|
|
147
|
-
const x = -460 + step * 12;
|
|
148
|
-
wave.push([x, -170 + Math.sin((x + time * 90) / 55) * 34]);
|
|
149
|
-
}
|
|
150
|
-
d2.lineStrip(wave, { width: 4, color: COOL });
|
|
151
|
-
// Outlined hexagon and a filled diamond, the two closed shapes reference example draws last.
|
|
152
|
-
d2.polygon([330, -170], 60, 6, { fill: false, strokeWidth: 4, color: WARM });
|
|
153
|
-
d2.rhombus([450, -170], [90, 110], { color: ACCENT });
|
|
154
|
-
}
|
|
155
|
-
/** Two crossing strokes, reference `cross_2d`. */
|
|
156
|
-
function cross(d2, center, size, color) {
|
|
157
|
-
const [x, y] = center;
|
|
158
|
-
d2.line([x - size, y], [x + size, y], { width: 3, color });
|
|
159
|
-
d2.line([x, y - size], [x, y + size], { width: 3, color });
|
|
160
|
-
}
|
package/dist/scenes-3d.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { FrameRecorder, Vec3, Color } from "./frame-recorder.js";
|
|
2
|
-
export type SceneContext = {
|
|
3
|
-
readonly time: number;
|
|
4
|
-
readonly lineJoint?: "none" | "round" | "bevel" | "miter";
|
|
5
|
-
};
|
|
6
|
-
declare function lineColumnX(column: number): number;
|
|
7
|
-
declare function lineRowZ(row: number): number;
|
|
8
|
-
declare function lineStart(column: number, row: number): Vec3;
|
|
9
|
-
declare function lineEnd(column: number, row: number): Vec3;
|
|
10
|
-
declare function referenceStripPoints(column: number, row: number): Vec3[];
|
|
11
|
-
declare function referenceLoopPoints(column: number, row: number): Vec3[];
|
|
12
|
-
declare function circleColumnX(column: number): number;
|
|
13
|
-
/** Raw reference layout data, exported so tests and future 3D labels share one source. */
|
|
14
|
-
export declare const CIRCLE_REFERENCE: {
|
|
15
|
-
readonly columns: 11;
|
|
16
|
-
readonly columnSpacing: 2;
|
|
17
|
-
readonly columnOffset: 0.5;
|
|
18
|
-
readonly rowSpacing: 0.82;
|
|
19
|
-
readonly radiusRowSpacing: 1.15;
|
|
20
|
-
readonly startZ: -0.45;
|
|
21
|
-
readonly radius: 0.32;
|
|
22
|
-
readonly baseWidth: 2;
|
|
23
|
-
readonly sceneOffset: Vec3;
|
|
24
|
-
readonly solidColor: Color;
|
|
25
|
-
readonly columnX: typeof circleColumnX;
|
|
26
|
-
readonly center: (column: number, row: number) => Vec3;
|
|
27
|
-
};
|
|
28
|
-
/** Raw reference layout data for the Line example. */
|
|
29
|
-
export declare const LINE_REFERENCE: {
|
|
30
|
-
readonly columns: 7;
|
|
31
|
-
readonly columnSpacing: 2;
|
|
32
|
-
readonly rowSpacing: 0.78;
|
|
33
|
-
readonly startZ: -0.45;
|
|
34
|
-
readonly length: 1.1;
|
|
35
|
-
readonly stripHalfDepth: 0.18;
|
|
36
|
-
readonly loopHalfDepth: 0.25;
|
|
37
|
-
readonly sceneOffset: Vec3;
|
|
38
|
-
readonly columnX: typeof lineColumnX;
|
|
39
|
-
readonly rowZ: typeof lineRowZ;
|
|
40
|
-
readonly start: typeof lineStart;
|
|
41
|
-
readonly end: typeof lineEnd;
|
|
42
|
-
readonly strip: typeof referenceStripPoints;
|
|
43
|
-
readonly loop: typeof referenceLoopPoints;
|
|
44
|
-
};
|
|
45
|
-
export declare function buildScene(id: string, recorder: FrameRecorder, time: number, lineJoint?: SceneContext["lineJoint"]): void;
|
|
46
|
-
export {};
|