@cyclonium/canvas-3d 0.0.100
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/canvas-3d.d.ts +58 -0
- package/lib/canvas-3d.js +254 -0
- package/lib/geometry.d.ts +117 -0
- package/lib/geometry.js +1503 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +2 -0
- package/lib/types.d.ts +248 -0
- package/lib/types.js +19 -0
- package/lib/w2.d.ts +58 -0
- package/lib/w2.js +256 -0
- package/lib/w3.d.ts +17 -0
- package/lib/w3.js +269 -0
- package/package.json +32 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Canvas3D, Canvas3DLineCap, Canvas3DLineJoin } from './canvas-3d.js';
|
|
2
|
+
export type { Canvas3DBoxOptions, Canvas3DCapsuleOptions, Canvas3DCylinderOptions, Canvas3DDiscOptions, Canvas3DLineOptions, Canvas3DPrimitiveMode, Canvas3DPrimitiveOptions, Canvas3DQuadOptions, Canvas3DRingOptions, Canvas3DSphereOptions, Canvas3DW2, Canvas3DW3, Canvas3DW3Scope, } from './canvas-3d.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
ADDED
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import type { Color, gfx, Mat4, Material, Node, renderer, RenderingSubMesh, Vec2, Vec3 } from 'cc';
|
|
2
|
+
export interface Canvas3DOptions {
|
|
3
|
+
readonly node: Node;
|
|
4
|
+
}
|
|
5
|
+
export declare enum Canvas3DLineJoin {
|
|
6
|
+
round = "round",
|
|
7
|
+
bevel = "bevel",
|
|
8
|
+
miter = "miter"
|
|
9
|
+
}
|
|
10
|
+
export declare enum Canvas3DLineCap {
|
|
11
|
+
butt = "butt",
|
|
12
|
+
round = "round",
|
|
13
|
+
square = "square"
|
|
14
|
+
}
|
|
15
|
+
export interface SubPath {
|
|
16
|
+
readonly points: Vec3[];
|
|
17
|
+
closed: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare enum PathEntryType {
|
|
20
|
+
subPath = "subPath",
|
|
21
|
+
box = "box",
|
|
22
|
+
circle = "circle"
|
|
23
|
+
}
|
|
24
|
+
export type PathEntry = {
|
|
25
|
+
readonly type: PathEntryType.subPath;
|
|
26
|
+
readonly subPath: SubPath;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: PathEntryType.box;
|
|
29
|
+
readonly center: Vec3;
|
|
30
|
+
readonly halfExtents: Vec3;
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: PathEntryType.circle;
|
|
33
|
+
readonly center: Vec3;
|
|
34
|
+
readonly radius: number;
|
|
35
|
+
};
|
|
36
|
+
export interface MeshGeometry {
|
|
37
|
+
readonly vertices: number[];
|
|
38
|
+
readonly indices: number[];
|
|
39
|
+
}
|
|
40
|
+
export interface DrawOptions {
|
|
41
|
+
readonly depthTest: boolean;
|
|
42
|
+
readonly depthWrite: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface DrawCommand extends DrawOptions {
|
|
45
|
+
readonly geometry: MeshGeometry;
|
|
46
|
+
}
|
|
47
|
+
export interface RenderingDrawCommand {
|
|
48
|
+
readonly renderingSubMeshRecord: RenderingSubMeshRecord;
|
|
49
|
+
readonly material: Material;
|
|
50
|
+
}
|
|
51
|
+
export interface RenderingSubMeshRecord {
|
|
52
|
+
readonly renderingSubMesh: RenderingSubMesh;
|
|
53
|
+
readonly vertexBuffer: gfx.Buffer;
|
|
54
|
+
readonly indexBuffer: gfx.Buffer;
|
|
55
|
+
vertexBufferBytes: number;
|
|
56
|
+
indexBufferBytes: number;
|
|
57
|
+
indexBytesPerElement: number;
|
|
58
|
+
}
|
|
59
|
+
export interface StrokeStyle {
|
|
60
|
+
readonly lineWidth: number;
|
|
61
|
+
readonly lineJoin: Canvas3DLineJoin;
|
|
62
|
+
readonly lineCap: Canvas3DLineCap;
|
|
63
|
+
readonly miterLimit: number;
|
|
64
|
+
readonly lineDash: readonly number[];
|
|
65
|
+
readonly lineDashOffset: number;
|
|
66
|
+
}
|
|
67
|
+
export interface StrokeSegmentWriter {
|
|
68
|
+
readonly geometry: MeshGeometry;
|
|
69
|
+
readonly direction: Vec3;
|
|
70
|
+
readonly normalA: Vec3;
|
|
71
|
+
readonly normalB: Vec3;
|
|
72
|
+
vertexOffsetF: number;
|
|
73
|
+
indexOffset: number;
|
|
74
|
+
baseVertex: number;
|
|
75
|
+
}
|
|
76
|
+
export interface RenderRecord {
|
|
77
|
+
readonly renderScene: renderer.RenderScene;
|
|
78
|
+
readonly renderingSubMeshRecords: RenderingSubMeshRecord[];
|
|
79
|
+
readonly model: renderer.scene.Model;
|
|
80
|
+
}
|
|
81
|
+
export interface PrimitiveDrawState {
|
|
82
|
+
lineWidth: number;
|
|
83
|
+
lineJoin: Canvas3DLineJoin;
|
|
84
|
+
lineCap: Canvas3DLineCap;
|
|
85
|
+
miterLimit: number;
|
|
86
|
+
lineDash: readonly number[];
|
|
87
|
+
lineDashOffset: number;
|
|
88
|
+
fillColor: Color;
|
|
89
|
+
strokeColor: Color;
|
|
90
|
+
transform: Mat4;
|
|
91
|
+
depthTest: boolean;
|
|
92
|
+
depthWrite: boolean;
|
|
93
|
+
}
|
|
94
|
+
export type EnqueueGeometry = (geometry: MeshGeometry, options?: DrawOptions) => void;
|
|
95
|
+
export type Canvas3DPrimitiveMode = 'wireframe' | 'solid' | 'both';
|
|
96
|
+
export interface Canvas3DPrimitiveOptions {
|
|
97
|
+
readonly color?: Readonly<Color> | string;
|
|
98
|
+
readonly strokeColor?: Readonly<Color> | string;
|
|
99
|
+
readonly fillColor?: Readonly<Color> | string;
|
|
100
|
+
readonly lineWidth?: number;
|
|
101
|
+
readonly lineJoin?: Canvas3DLineJoin;
|
|
102
|
+
readonly lineCap?: Canvas3DLineCap;
|
|
103
|
+
readonly lineDash?: readonly number[];
|
|
104
|
+
readonly lineDashOffset?: number;
|
|
105
|
+
readonly transform?: Mat4;
|
|
106
|
+
readonly depthTest?: boolean;
|
|
107
|
+
readonly depthWrite?: boolean;
|
|
108
|
+
readonly mode?: Canvas3DPrimitiveMode;
|
|
109
|
+
}
|
|
110
|
+
export interface Canvas3DLineOptions extends Canvas3DPrimitiveOptions {
|
|
111
|
+
readonly from: Vec3;
|
|
112
|
+
readonly to: Vec3;
|
|
113
|
+
}
|
|
114
|
+
export interface Canvas3DBoxOptions extends Canvas3DPrimitiveOptions {
|
|
115
|
+
readonly center: Vec3;
|
|
116
|
+
readonly halfExtents: number | Vec3;
|
|
117
|
+
}
|
|
118
|
+
export interface Canvas3DQuadOptions extends Canvas3DPrimitiveOptions {
|
|
119
|
+
readonly center: Vec3;
|
|
120
|
+
readonly normal: Vec3;
|
|
121
|
+
readonly halfExtents: number | Vec2;
|
|
122
|
+
}
|
|
123
|
+
export interface Canvas3DCylinderOptions extends Canvas3DPrimitiveOptions {
|
|
124
|
+
readonly center: Vec3;
|
|
125
|
+
readonly radius: number;
|
|
126
|
+
readonly height: number;
|
|
127
|
+
readonly up?: Vec3;
|
|
128
|
+
readonly radialSegments?: number;
|
|
129
|
+
}
|
|
130
|
+
export interface Canvas3DDiscOptions extends Canvas3DPrimitiveOptions {
|
|
131
|
+
readonly center: Vec3;
|
|
132
|
+
readonly normal: Vec3;
|
|
133
|
+
readonly radius: number;
|
|
134
|
+
readonly segments?: number;
|
|
135
|
+
}
|
|
136
|
+
export interface Canvas3DRingOptions extends Canvas3DPrimitiveOptions {
|
|
137
|
+
readonly center: Vec3;
|
|
138
|
+
readonly normal: Vec3;
|
|
139
|
+
readonly innerRadius: number;
|
|
140
|
+
readonly outerRadius: number;
|
|
141
|
+
readonly segments?: number;
|
|
142
|
+
}
|
|
143
|
+
export interface Canvas3DSphereOptions extends Canvas3DPrimitiveOptions {
|
|
144
|
+
readonly center: Vec3;
|
|
145
|
+
readonly radius: number;
|
|
146
|
+
readonly segments?: number;
|
|
147
|
+
readonly latitudeSegments?: number;
|
|
148
|
+
readonly longitudeSegments?: number;
|
|
149
|
+
}
|
|
150
|
+
export interface Canvas3DCapsuleOptions extends Canvas3DPrimitiveOptions {
|
|
151
|
+
readonly center: Vec3;
|
|
152
|
+
readonly radius: number;
|
|
153
|
+
readonly height: number;
|
|
154
|
+
readonly up?: Vec3;
|
|
155
|
+
readonly radialSegments?: number;
|
|
156
|
+
readonly capSegments?: number;
|
|
157
|
+
}
|
|
158
|
+
export interface Canvas3DW2 {
|
|
159
|
+
get lineWidth(): number;
|
|
160
|
+
set lineWidth(value: number);
|
|
161
|
+
get strokeWidth(): number;
|
|
162
|
+
set strokeWidth(value: number);
|
|
163
|
+
get lineJoin(): Canvas3DLineJoin;
|
|
164
|
+
set lineJoin(value: Canvas3DLineJoin);
|
|
165
|
+
get lineCap(): Canvas3DLineCap;
|
|
166
|
+
set lineCap(value: Canvas3DLineCap);
|
|
167
|
+
get miterLimit(): number;
|
|
168
|
+
set miterLimit(value: number);
|
|
169
|
+
get lineDash(): number[];
|
|
170
|
+
set lineDash(value: readonly number[]);
|
|
171
|
+
get lineDashOffset(): number;
|
|
172
|
+
set lineDashOffset(value: number);
|
|
173
|
+
get strokeColor(): Color;
|
|
174
|
+
set strokeColor(value: Color);
|
|
175
|
+
get fillColor(): Color;
|
|
176
|
+
set fillColor(value: Color);
|
|
177
|
+
get strokeStyle(): Color;
|
|
178
|
+
set strokeStyle(value: Readonly<Color> | string);
|
|
179
|
+
get fillStyle(): Color;
|
|
180
|
+
set fillStyle(value: Readonly<Color> | string);
|
|
181
|
+
beginPath(): this;
|
|
182
|
+
closePath(): this;
|
|
183
|
+
moveTo(point: Vec3): this;
|
|
184
|
+
moveTo(x: number, y: number, z?: number): this;
|
|
185
|
+
lineTo(point: Vec3): this;
|
|
186
|
+
lineTo(x: number, y: number, z?: number): this;
|
|
187
|
+
rect(x: number, y: number, width: number, height: number, z?: number): this;
|
|
188
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean, z?: number): this;
|
|
189
|
+
ray(dir: Vec3, length: number): this;
|
|
190
|
+
box(center: Vec3, halfExtents: number | Vec3): this;
|
|
191
|
+
circle(center: Vec3, radius: number): this;
|
|
192
|
+
stroke(): this;
|
|
193
|
+
fill(): this;
|
|
194
|
+
getLineDash(): number[];
|
|
195
|
+
setLineDash(value: readonly number[]): void;
|
|
196
|
+
}
|
|
197
|
+
export interface Canvas3DW3 {
|
|
198
|
+
scope(draw: (w3: Canvas3DW3Scope) => void): this;
|
|
199
|
+
line(options: Canvas3DLineOptions): this;
|
|
200
|
+
box(options: Canvas3DBoxOptions): this;
|
|
201
|
+
quad(options: Canvas3DQuadOptions): this;
|
|
202
|
+
cylinder(options: Canvas3DCylinderOptions): this;
|
|
203
|
+
disc(options: Canvas3DDiscOptions): this;
|
|
204
|
+
ring(options: Canvas3DRingOptions): this;
|
|
205
|
+
sphere(options: Canvas3DSphereOptions): this;
|
|
206
|
+
capsule(options: Canvas3DCapsuleOptions): this;
|
|
207
|
+
}
|
|
208
|
+
export interface Canvas3DW3Scope {
|
|
209
|
+
get lineWidth(): number;
|
|
210
|
+
set lineWidth(value: number);
|
|
211
|
+
get lineJoin(): Canvas3DLineJoin;
|
|
212
|
+
set lineJoin(value: Canvas3DLineJoin);
|
|
213
|
+
get lineCap(): Canvas3DLineCap;
|
|
214
|
+
set lineCap(value: Canvas3DLineCap);
|
|
215
|
+
get lineDash(): number[];
|
|
216
|
+
set lineDash(value: readonly number[]);
|
|
217
|
+
get lineDashOffset(): number;
|
|
218
|
+
set lineDashOffset(value: number);
|
|
219
|
+
get strokeColor(): Color;
|
|
220
|
+
set strokeColor(value: Color);
|
|
221
|
+
get fillColor(): Color;
|
|
222
|
+
set fillColor(value: Color);
|
|
223
|
+
color(value: Readonly<Color> | string): this;
|
|
224
|
+
depthTest(value?: boolean): this;
|
|
225
|
+
depthWrite(value?: boolean): this;
|
|
226
|
+
save(): this;
|
|
227
|
+
restore(): this;
|
|
228
|
+
resetTransform(): this;
|
|
229
|
+
setTransform(transform: Mat4): this;
|
|
230
|
+
transform(transform: Mat4): this;
|
|
231
|
+
translate(x: number, y: number, z?: number): this;
|
|
232
|
+
scale(x: number, y?: number, z?: number): this;
|
|
233
|
+
rotate(rad: number, axis: Vec3): this;
|
|
234
|
+
rotateX(rad: number): this;
|
|
235
|
+
rotateY(rad: number): this;
|
|
236
|
+
rotateZ(rad: number): this;
|
|
237
|
+
line(options: Canvas3DLineOptions): this;
|
|
238
|
+
box(options: Canvas3DBoxOptions): this;
|
|
239
|
+
quad(options: Canvas3DQuadOptions): this;
|
|
240
|
+
cylinder(options: Canvas3DCylinderOptions): this;
|
|
241
|
+
disc(options: Canvas3DDiscOptions): this;
|
|
242
|
+
ring(options: Canvas3DRingOptions): this;
|
|
243
|
+
sphere(options: Canvas3DSphereOptions): this;
|
|
244
|
+
capsule(options: Canvas3DCapsuleOptions): this;
|
|
245
|
+
getLineDash(): number[];
|
|
246
|
+
setLineDash(value: readonly number[]): void;
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export var Canvas3DLineJoin;
|
|
2
|
+
(function (Canvas3DLineJoin) {
|
|
3
|
+
Canvas3DLineJoin["round"] = "round";
|
|
4
|
+
Canvas3DLineJoin["bevel"] = "bevel";
|
|
5
|
+
Canvas3DLineJoin["miter"] = "miter";
|
|
6
|
+
})(Canvas3DLineJoin || (Canvas3DLineJoin = {}));
|
|
7
|
+
export var Canvas3DLineCap;
|
|
8
|
+
(function (Canvas3DLineCap) {
|
|
9
|
+
Canvas3DLineCap["butt"] = "butt";
|
|
10
|
+
Canvas3DLineCap["round"] = "round";
|
|
11
|
+
Canvas3DLineCap["square"] = "square";
|
|
12
|
+
})(Canvas3DLineCap || (Canvas3DLineCap = {}));
|
|
13
|
+
export var PathEntryType;
|
|
14
|
+
(function (PathEntryType) {
|
|
15
|
+
PathEntryType["subPath"] = "subPath";
|
|
16
|
+
PathEntryType["box"] = "box";
|
|
17
|
+
PathEntryType["circle"] = "circle";
|
|
18
|
+
})(PathEntryType || (PathEntryType = {}));
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
package/lib/w2.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Color, Vec3 } from 'cc';
|
|
2
|
+
import { Canvas3DLineCap, Canvas3DLineJoin } from './types.js';
|
|
3
|
+
import type { Canvas3DW2, EnqueueGeometry } from './types.js';
|
|
4
|
+
export declare class Canvas3DW2Impl implements Canvas3DW2 {
|
|
5
|
+
constructor(enqueueGeometry: EnqueueGeometry);
|
|
6
|
+
get lineWidth(): number;
|
|
7
|
+
set lineWidth(value: number);
|
|
8
|
+
get strokeWidth(): number;
|
|
9
|
+
set strokeWidth(value: number);
|
|
10
|
+
get lineJoin(): Canvas3DLineJoin;
|
|
11
|
+
set lineJoin(value: Canvas3DLineJoin);
|
|
12
|
+
get lineCap(): Canvas3DLineCap;
|
|
13
|
+
set lineCap(value: Canvas3DLineCap);
|
|
14
|
+
get miterLimit(): number;
|
|
15
|
+
set miterLimit(value: number);
|
|
16
|
+
get lineDash(): number[];
|
|
17
|
+
set lineDash(value: readonly number[]);
|
|
18
|
+
get lineDashOffset(): number;
|
|
19
|
+
set lineDashOffset(value: number);
|
|
20
|
+
get strokeColor(): Color;
|
|
21
|
+
set strokeColor(value: Color);
|
|
22
|
+
get fillColor(): Color;
|
|
23
|
+
set fillColor(value: Color);
|
|
24
|
+
get strokeStyle(): Color;
|
|
25
|
+
set strokeStyle(value: Readonly<Color> | string);
|
|
26
|
+
get fillStyle(): Color;
|
|
27
|
+
set fillStyle(value: Readonly<Color> | string);
|
|
28
|
+
beginPath(): this;
|
|
29
|
+
closePath(): this;
|
|
30
|
+
moveTo(point: Vec3): this;
|
|
31
|
+
moveTo(x: number, y: number, z?: number): this;
|
|
32
|
+
lineTo(point: Vec3): this;
|
|
33
|
+
lineTo(x: number, y: number, z?: number): this;
|
|
34
|
+
rect(x: number, y: number, width: number, height: number, z?: number): this;
|
|
35
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean, z?: number): this;
|
|
36
|
+
ray(dir: Vec3, length: number): this;
|
|
37
|
+
box(center: Vec3, halfExtents: number | Vec3): this;
|
|
38
|
+
circle(center: Vec3, radius: number): this;
|
|
39
|
+
stroke(): this;
|
|
40
|
+
fill(): this;
|
|
41
|
+
getLineDash(): number[];
|
|
42
|
+
setLineDash(value: readonly number[]): void;
|
|
43
|
+
private _createStrokeStyle;
|
|
44
|
+
private _lineWidth;
|
|
45
|
+
private _lineJoin;
|
|
46
|
+
private _lineCap;
|
|
47
|
+
private _miterLimit;
|
|
48
|
+
private _lineDash;
|
|
49
|
+
private _lineDashOffset;
|
|
50
|
+
private readonly _strokeColor;
|
|
51
|
+
private readonly _fillColor;
|
|
52
|
+
private readonly _pathEntries;
|
|
53
|
+
private readonly _currentPoint;
|
|
54
|
+
private readonly _enqueueGeometry;
|
|
55
|
+
private _currentSubPath;
|
|
56
|
+
private _hasCurrentPoint;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=w2.d.ts.map
|
package/lib/w2.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { Color, Vec3 } from 'cc';
|
|
2
|
+
import { appendBoxFill, appendBoxStroke, appendCircleFill, appendCircleStroke, appendSubPathFill, appendSubPathStroke, createMeshGeometry, epsilon, normalizeArcDelta, normalizeLineDash, resolveHalfExtents, resolvePoint, roundSegmentRadians, setColor, } from './geometry.js';
|
|
3
|
+
import { Canvas3DLineCap, Canvas3DLineJoin, PathEntryType } from './types.js';
|
|
4
|
+
export class Canvas3DW2Impl {
|
|
5
|
+
constructor(enqueueGeometry) {
|
|
6
|
+
this._enqueueGeometry = enqueueGeometry;
|
|
7
|
+
}
|
|
8
|
+
get lineWidth() {
|
|
9
|
+
return this._lineWidth;
|
|
10
|
+
}
|
|
11
|
+
set lineWidth(value) {
|
|
12
|
+
this._lineWidth = Math.max(0, value);
|
|
13
|
+
}
|
|
14
|
+
get strokeWidth() {
|
|
15
|
+
return this._lineWidth;
|
|
16
|
+
}
|
|
17
|
+
set strokeWidth(value) {
|
|
18
|
+
this.lineWidth = value;
|
|
19
|
+
}
|
|
20
|
+
get lineJoin() {
|
|
21
|
+
return this._lineJoin;
|
|
22
|
+
}
|
|
23
|
+
set lineJoin(value) {
|
|
24
|
+
this._lineJoin = value;
|
|
25
|
+
}
|
|
26
|
+
get lineCap() {
|
|
27
|
+
return this._lineCap;
|
|
28
|
+
}
|
|
29
|
+
set lineCap(value) {
|
|
30
|
+
this._lineCap = value;
|
|
31
|
+
}
|
|
32
|
+
get miterLimit() {
|
|
33
|
+
return this._miterLimit;
|
|
34
|
+
}
|
|
35
|
+
set miterLimit(value) {
|
|
36
|
+
this._miterLimit = Math.max(0, value);
|
|
37
|
+
}
|
|
38
|
+
get lineDash() {
|
|
39
|
+
return this.getLineDash();
|
|
40
|
+
}
|
|
41
|
+
set lineDash(value) {
|
|
42
|
+
this.setLineDash(value);
|
|
43
|
+
}
|
|
44
|
+
get lineDashOffset() {
|
|
45
|
+
return this._lineDashOffset;
|
|
46
|
+
}
|
|
47
|
+
set lineDashOffset(value) {
|
|
48
|
+
this._lineDashOffset = Number.isFinite(value) ? value : 0;
|
|
49
|
+
}
|
|
50
|
+
get strokeColor() {
|
|
51
|
+
return this._strokeColor;
|
|
52
|
+
}
|
|
53
|
+
set strokeColor(value) {
|
|
54
|
+
this._strokeColor.set(value);
|
|
55
|
+
}
|
|
56
|
+
get fillColor() {
|
|
57
|
+
return this._fillColor;
|
|
58
|
+
}
|
|
59
|
+
set fillColor(value) {
|
|
60
|
+
this._fillColor.set(value);
|
|
61
|
+
}
|
|
62
|
+
get strokeStyle() {
|
|
63
|
+
return this.strokeColor;
|
|
64
|
+
}
|
|
65
|
+
set strokeStyle(value) {
|
|
66
|
+
setColor(this._strokeColor, value);
|
|
67
|
+
}
|
|
68
|
+
get fillStyle() {
|
|
69
|
+
return this.fillColor;
|
|
70
|
+
}
|
|
71
|
+
set fillStyle(value) {
|
|
72
|
+
setColor(this._fillColor, value);
|
|
73
|
+
}
|
|
74
|
+
beginPath() {
|
|
75
|
+
this._pathEntries.length = 0;
|
|
76
|
+
this._currentSubPath = undefined;
|
|
77
|
+
this._hasCurrentPoint = false;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
closePath() {
|
|
81
|
+
if (!this._currentSubPath) {
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
this._currentSubPath.closed = true;
|
|
85
|
+
const firstPoint = this._currentSubPath.points[0];
|
|
86
|
+
if (firstPoint) {
|
|
87
|
+
this._currentPoint.set(firstPoint);
|
|
88
|
+
this._hasCurrentPoint = true;
|
|
89
|
+
}
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
moveTo(pointOrX, y, z) {
|
|
93
|
+
const point = resolvePoint(pointOrX, y, z);
|
|
94
|
+
const subPath = {
|
|
95
|
+
points: [point],
|
|
96
|
+
closed: false,
|
|
97
|
+
};
|
|
98
|
+
this._pathEntries.push({
|
|
99
|
+
type: PathEntryType.subPath,
|
|
100
|
+
subPath,
|
|
101
|
+
});
|
|
102
|
+
this._currentSubPath = subPath;
|
|
103
|
+
this._currentPoint.set(point);
|
|
104
|
+
this._hasCurrentPoint = true;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
lineTo(pointOrX, y, z) {
|
|
108
|
+
const point = resolvePoint(pointOrX, y, z);
|
|
109
|
+
if (!this._currentSubPath) {
|
|
110
|
+
return this.moveTo(point);
|
|
111
|
+
}
|
|
112
|
+
this._currentSubPath.points.push(point);
|
|
113
|
+
this._currentPoint.set(point);
|
|
114
|
+
this._hasCurrentPoint = true;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
rect(x, y, width, height, z = 0) {
|
|
118
|
+
const subPath = {
|
|
119
|
+
points: [
|
|
120
|
+
new Vec3(x, y, z),
|
|
121
|
+
new Vec3(x + width, y, z),
|
|
122
|
+
new Vec3(x + width, y + height, z),
|
|
123
|
+
new Vec3(x, y + height, z),
|
|
124
|
+
],
|
|
125
|
+
closed: true,
|
|
126
|
+
};
|
|
127
|
+
this._pathEntries.push({
|
|
128
|
+
type: PathEntryType.subPath,
|
|
129
|
+
subPath,
|
|
130
|
+
});
|
|
131
|
+
this._currentSubPath = subPath;
|
|
132
|
+
this._currentPoint.set(subPath.points[0]);
|
|
133
|
+
this._hasCurrentPoint = true;
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
arc(x, y, radius, startAngle, endAngle, counterclockwise = false, z = 0) {
|
|
137
|
+
if (radius <= 0) {
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
const delta = normalizeArcDelta(startAngle, endAngle, counterclockwise);
|
|
141
|
+
const segmentCount = Math.max(1, Math.ceil(Math.abs(delta) / roundSegmentRadians));
|
|
142
|
+
for (let iSegment = 0; iSegment <= segmentCount; iSegment++) {
|
|
143
|
+
const angle = startAngle + delta * iSegment / segmentCount;
|
|
144
|
+
const point = new Vec3(x + Math.cos(angle) * radius, y + Math.sin(angle) * radius, z);
|
|
145
|
+
if (iSegment === 0 && !this._currentSubPath) {
|
|
146
|
+
this.moveTo(point);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.lineTo(point);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
ray(dir, length) {
|
|
155
|
+
const normalizedDir = dir.clone();
|
|
156
|
+
if (normalizedDir.lengthSqr() <= epsilon) {
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
normalizedDir.normalize();
|
|
160
|
+
const start = this._hasCurrentPoint ? this._currentPoint.clone() : Vec3.ZERO.clone();
|
|
161
|
+
const end = Vec3.scaleAndAdd(new Vec3(), start, normalizedDir, length);
|
|
162
|
+
if (!this._currentSubPath) {
|
|
163
|
+
this.moveTo(start);
|
|
164
|
+
}
|
|
165
|
+
this.lineTo(end);
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
box(center, halfExtents) {
|
|
169
|
+
this._pathEntries.push({
|
|
170
|
+
type: PathEntryType.box,
|
|
171
|
+
center: center.clone(),
|
|
172
|
+
halfExtents: resolveHalfExtents(halfExtents),
|
|
173
|
+
});
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
circle(center, radius) {
|
|
177
|
+
this._pathEntries.push({
|
|
178
|
+
type: PathEntryType.circle,
|
|
179
|
+
center: center.clone(),
|
|
180
|
+
radius: Math.max(0, radius),
|
|
181
|
+
});
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
stroke() {
|
|
185
|
+
const color = this._strokeColor.clone();
|
|
186
|
+
const strokeStyle = this._createStrokeStyle();
|
|
187
|
+
if (strokeStyle.lineWidth <= 0) {
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
const geometry = createMeshGeometry();
|
|
191
|
+
for (const entry of this._pathEntries) {
|
|
192
|
+
switch (entry.type) {
|
|
193
|
+
case PathEntryType.subPath:
|
|
194
|
+
appendSubPathStroke(geometry, entry.subPath, strokeStyle, color);
|
|
195
|
+
break;
|
|
196
|
+
case PathEntryType.box:
|
|
197
|
+
appendBoxStroke(geometry, entry.center, entry.halfExtents, strokeStyle, color);
|
|
198
|
+
break;
|
|
199
|
+
case PathEntryType.circle:
|
|
200
|
+
appendCircleStroke(geometry, entry.center, entry.radius, strokeStyle, color);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
this._enqueueGeometry(geometry);
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
fill() {
|
|
208
|
+
const color = this._fillColor.clone();
|
|
209
|
+
const geometry = createMeshGeometry();
|
|
210
|
+
for (const entry of this._pathEntries) {
|
|
211
|
+
switch (entry.type) {
|
|
212
|
+
case PathEntryType.subPath:
|
|
213
|
+
appendSubPathFill(geometry, entry.subPath, color);
|
|
214
|
+
break;
|
|
215
|
+
case PathEntryType.box:
|
|
216
|
+
appendBoxFill(geometry, entry.center, entry.halfExtents, color);
|
|
217
|
+
break;
|
|
218
|
+
case PathEntryType.circle:
|
|
219
|
+
appendCircleFill(geometry, entry.center, entry.radius, color);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
this._enqueueGeometry(geometry);
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
getLineDash() {
|
|
227
|
+
return this._lineDash.slice();
|
|
228
|
+
}
|
|
229
|
+
setLineDash(value) {
|
|
230
|
+
this._lineDash = normalizeLineDash(value);
|
|
231
|
+
}
|
|
232
|
+
_createStrokeStyle() {
|
|
233
|
+
return {
|
|
234
|
+
lineWidth: this._lineWidth,
|
|
235
|
+
lineJoin: this._lineJoin,
|
|
236
|
+
lineCap: this._lineCap,
|
|
237
|
+
miterLimit: this._miterLimit,
|
|
238
|
+
lineDash: this.getLineDash(),
|
|
239
|
+
lineDashOffset: this._lineDashOffset,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
_lineWidth = 1;
|
|
243
|
+
_lineJoin = Canvas3DLineJoin.miter;
|
|
244
|
+
_lineCap = Canvas3DLineCap.butt;
|
|
245
|
+
_miterLimit = 10;
|
|
246
|
+
_lineDash = [];
|
|
247
|
+
_lineDashOffset = 0;
|
|
248
|
+
_strokeColor = Color.WHITE.clone();
|
|
249
|
+
_fillColor = Color.WHITE.clone();
|
|
250
|
+
_pathEntries = [];
|
|
251
|
+
_currentPoint = new Vec3();
|
|
252
|
+
_enqueueGeometry;
|
|
253
|
+
_currentSubPath = undefined;
|
|
254
|
+
_hasCurrentPoint = false;
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=w2.js.map
|
package/lib/w3.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Canvas3DBoxOptions, Canvas3DCapsuleOptions, Canvas3DCylinderOptions, Canvas3DDiscOptions, Canvas3DLineOptions, Canvas3DQuadOptions, Canvas3DRingOptions, Canvas3DSphereOptions, Canvas3DW3, Canvas3DW3Scope, EnqueueGeometry } from './types.js';
|
|
2
|
+
export declare class Canvas3DW3Impl implements Canvas3DW3 {
|
|
3
|
+
constructor(enqueueGeometry: EnqueueGeometry);
|
|
4
|
+
scope(draw: (w3: Canvas3DW3Scope) => void): this;
|
|
5
|
+
line(options: Canvas3DLineOptions): this;
|
|
6
|
+
box(options: Canvas3DBoxOptions): this;
|
|
7
|
+
quad(options: Canvas3DQuadOptions): this;
|
|
8
|
+
cylinder(options: Canvas3DCylinderOptions): this;
|
|
9
|
+
disc(options: Canvas3DDiscOptions): this;
|
|
10
|
+
ring(options: Canvas3DRingOptions): this;
|
|
11
|
+
sphere(options: Canvas3DSphereOptions): this;
|
|
12
|
+
capsule(options: Canvas3DCapsuleOptions): this;
|
|
13
|
+
private _drawDirect;
|
|
14
|
+
private readonly _enqueueGeometry;
|
|
15
|
+
private readonly _directScope;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=w3.d.ts.map
|