@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/w3.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { Mat4, Vec3 } from 'cc';
|
|
2
|
+
import { copyPrimitiveDrawState, createQuadCorners, createPrimitiveDrawState, drawPrimitive, normalizeLineDash, PrimitiveEntryType, resolveCapsule, resolveCapsuleSegments, resolveCylinder, resolveCylinderSegments, resolveDiscSegments, resolveDiscRadius, resolveHalfExtents, resolveRingRadii, resolveRingSegments, resolveSphereSegments, setColor, } from './geometry.js';
|
|
3
|
+
export class Canvas3DW3Impl {
|
|
4
|
+
constructor(enqueueGeometry) {
|
|
5
|
+
this._enqueueGeometry = enqueueGeometry;
|
|
6
|
+
this._directScope = new Canvas3DW3ScopeImpl(enqueueGeometry);
|
|
7
|
+
}
|
|
8
|
+
scope(draw) {
|
|
9
|
+
draw(new Canvas3DW3ScopeImpl(this._enqueueGeometry));
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
line(options) {
|
|
13
|
+
this._drawDirect((scope) => {
|
|
14
|
+
scope.line(options);
|
|
15
|
+
});
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
box(options) {
|
|
19
|
+
this._drawDirect((scope) => {
|
|
20
|
+
scope.box(options);
|
|
21
|
+
});
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
quad(options) {
|
|
25
|
+
this._drawDirect((scope) => {
|
|
26
|
+
scope.quad(options);
|
|
27
|
+
});
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
cylinder(options) {
|
|
31
|
+
this._drawDirect((scope) => {
|
|
32
|
+
scope.cylinder(options);
|
|
33
|
+
});
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
disc(options) {
|
|
37
|
+
this._drawDirect((scope) => {
|
|
38
|
+
scope.disc(options);
|
|
39
|
+
});
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
ring(options) {
|
|
43
|
+
this._drawDirect((scope) => {
|
|
44
|
+
scope.ring(options);
|
|
45
|
+
});
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
sphere(options) {
|
|
49
|
+
this._drawDirect((scope) => {
|
|
50
|
+
scope.sphere(options);
|
|
51
|
+
});
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
capsule(options) {
|
|
55
|
+
this._drawDirect((scope) => {
|
|
56
|
+
scope.capsule(options);
|
|
57
|
+
});
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
_drawDirect(draw) {
|
|
61
|
+
draw(this._directScope);
|
|
62
|
+
}
|
|
63
|
+
_enqueueGeometry;
|
|
64
|
+
_directScope;
|
|
65
|
+
}
|
|
66
|
+
class Canvas3DW3ScopeImpl {
|
|
67
|
+
constructor(enqueueGeometry) {
|
|
68
|
+
this._enqueueGeometry = enqueueGeometry;
|
|
69
|
+
}
|
|
70
|
+
get lineWidth() {
|
|
71
|
+
return this._state.lineWidth;
|
|
72
|
+
}
|
|
73
|
+
set lineWidth(value) {
|
|
74
|
+
this._state.lineWidth = Math.max(0, value);
|
|
75
|
+
}
|
|
76
|
+
get lineJoin() {
|
|
77
|
+
return this._state.lineJoin;
|
|
78
|
+
}
|
|
79
|
+
set lineJoin(value) {
|
|
80
|
+
this._state.lineJoin = value;
|
|
81
|
+
}
|
|
82
|
+
get lineCap() {
|
|
83
|
+
return this._state.lineCap;
|
|
84
|
+
}
|
|
85
|
+
set lineCap(value) {
|
|
86
|
+
this._state.lineCap = value;
|
|
87
|
+
}
|
|
88
|
+
get lineDash() {
|
|
89
|
+
return this.getLineDash();
|
|
90
|
+
}
|
|
91
|
+
set lineDash(value) {
|
|
92
|
+
this.setLineDash(value);
|
|
93
|
+
}
|
|
94
|
+
get lineDashOffset() {
|
|
95
|
+
return this._state.lineDashOffset;
|
|
96
|
+
}
|
|
97
|
+
set lineDashOffset(value) {
|
|
98
|
+
this._state.lineDashOffset = Number.isFinite(value) ? value : 0;
|
|
99
|
+
}
|
|
100
|
+
get strokeColor() {
|
|
101
|
+
return this._state.strokeColor;
|
|
102
|
+
}
|
|
103
|
+
set strokeColor(value) {
|
|
104
|
+
this._state.strokeColor.set(value);
|
|
105
|
+
}
|
|
106
|
+
get fillColor() {
|
|
107
|
+
return this._state.fillColor;
|
|
108
|
+
}
|
|
109
|
+
set fillColor(value) {
|
|
110
|
+
this._state.fillColor.set(value);
|
|
111
|
+
}
|
|
112
|
+
color(value) {
|
|
113
|
+
setColor(this._state.fillColor, value);
|
|
114
|
+
setColor(this._state.strokeColor, value);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
depthTest(value = true) {
|
|
118
|
+
this._state.depthTest = value;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
depthWrite(value = true) {
|
|
122
|
+
this._state.depthWrite = value;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
save() {
|
|
126
|
+
const state = this._stateStack[this._stateStackDepth] ??= createPrimitiveDrawState();
|
|
127
|
+
copyPrimitiveDrawState(state, this._state);
|
|
128
|
+
this._stateStackDepth++;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
restore() {
|
|
132
|
+
if (this._stateStackDepth > 0) {
|
|
133
|
+
this._stateStackDepth--;
|
|
134
|
+
copyPrimitiveDrawState(this._state, this._stateStack[this._stateStackDepth]);
|
|
135
|
+
}
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
resetTransform() {
|
|
139
|
+
Mat4.identity(this._state.transform);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
setTransform(transform) {
|
|
143
|
+
this._state.transform.set(transform);
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
transform(transform) {
|
|
147
|
+
Mat4.multiply(this._state.transform, this._state.transform, transform);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
translate(x, y, z = 0) {
|
|
151
|
+
Mat4.transform(this._state.transform, this._state.transform, new Vec3(x, y, z));
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
scale(x, y = x, z = x) {
|
|
155
|
+
Mat4.scale(this._state.transform, this._state.transform, new Vec3(x, y, z));
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
rotate(rad, axis) {
|
|
159
|
+
Mat4.rotate(this._state.transform, this._state.transform, rad, axis);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
rotateX(rad) {
|
|
163
|
+
Mat4.rotateX(this._state.transform, this._state.transform, rad);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
rotateY(rad) {
|
|
167
|
+
Mat4.rotateY(this._state.transform, this._state.transform, rad);
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
rotateZ(rad) {
|
|
171
|
+
Mat4.rotateZ(this._state.transform, this._state.transform, rad);
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
line(options) {
|
|
175
|
+
drawPrimitive(this._enqueueGeometry, this._state, [{
|
|
176
|
+
type: PrimitiveEntryType.line,
|
|
177
|
+
from: options.from.clone(),
|
|
178
|
+
to: options.to.clone(),
|
|
179
|
+
}], options);
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
box(options) {
|
|
183
|
+
drawPrimitive(this._enqueueGeometry, this._state, [{
|
|
184
|
+
type: PrimitiveEntryType.box,
|
|
185
|
+
center: options.center.clone(),
|
|
186
|
+
halfExtents: resolveHalfExtents(options.halfExtents),
|
|
187
|
+
}], options);
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
quad(options) {
|
|
191
|
+
drawPrimitive(this._enqueueGeometry, this._state, [{
|
|
192
|
+
type: PrimitiveEntryType.quad,
|
|
193
|
+
corners: createQuadCorners(options),
|
|
194
|
+
}], options);
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
cylinder(options) {
|
|
198
|
+
const cylinder = resolveCylinder(options);
|
|
199
|
+
const segments = resolveCylinderSegments(options);
|
|
200
|
+
drawPrimitive(this._enqueueGeometry, this._state, [{
|
|
201
|
+
type: PrimitiveEntryType.cylinder,
|
|
202
|
+
from: cylinder.from,
|
|
203
|
+
to: cylinder.to,
|
|
204
|
+
radius: cylinder.radius,
|
|
205
|
+
radialSegments: segments.radialSegments,
|
|
206
|
+
wireSegments: segments.wireSegments,
|
|
207
|
+
}], options);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
disc(options) {
|
|
211
|
+
drawPrimitive(this._enqueueGeometry, this._state, [{
|
|
212
|
+
type: PrimitiveEntryType.disc,
|
|
213
|
+
center: options.center.clone(),
|
|
214
|
+
normal: options.normal.clone(),
|
|
215
|
+
radius: resolveDiscRadius(options),
|
|
216
|
+
segments: resolveDiscSegments(options),
|
|
217
|
+
}], options);
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
ring(options) {
|
|
221
|
+
const radii = resolveRingRadii(options);
|
|
222
|
+
drawPrimitive(this._enqueueGeometry, this._state, [{
|
|
223
|
+
type: PrimitiveEntryType.ring,
|
|
224
|
+
center: options.center.clone(),
|
|
225
|
+
normal: options.normal.clone(),
|
|
226
|
+
innerRadius: radii.innerRadius,
|
|
227
|
+
outerRadius: radii.outerRadius,
|
|
228
|
+
segments: resolveRingSegments(options),
|
|
229
|
+
}], options);
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
sphere(options) {
|
|
233
|
+
const segments = resolveSphereSegments(options);
|
|
234
|
+
drawPrimitive(this._enqueueGeometry, this._state, [{
|
|
235
|
+
type: PrimitiveEntryType.sphere,
|
|
236
|
+
center: options.center.clone(),
|
|
237
|
+
radius: Math.max(0, options.radius),
|
|
238
|
+
latitudeSegments: segments.latitudeSegments,
|
|
239
|
+
longitudeSegments: segments.longitudeSegments,
|
|
240
|
+
wireSegments: segments.wireSegments,
|
|
241
|
+
}], options);
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
capsule(options) {
|
|
245
|
+
const capsule = resolveCapsule(options);
|
|
246
|
+
const segments = resolveCapsuleSegments(options);
|
|
247
|
+
drawPrimitive(this._enqueueGeometry, this._state, [{
|
|
248
|
+
type: PrimitiveEntryType.capsule,
|
|
249
|
+
from: capsule.from,
|
|
250
|
+
to: capsule.to,
|
|
251
|
+
radius: capsule.radius,
|
|
252
|
+
radialSegments: segments.radialSegments,
|
|
253
|
+
wireSegments: segments.wireSegments,
|
|
254
|
+
capSegments: segments.capSegments,
|
|
255
|
+
}], options);
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
getLineDash() {
|
|
259
|
+
return this._state.lineDash.slice();
|
|
260
|
+
}
|
|
261
|
+
setLineDash(value) {
|
|
262
|
+
this._state.lineDash = normalizeLineDash(value);
|
|
263
|
+
}
|
|
264
|
+
_stateStack = [];
|
|
265
|
+
_enqueueGeometry;
|
|
266
|
+
_state = createPrimitiveDrawState();
|
|
267
|
+
_stateStackDepth = 0;
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=w3.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cyclonium/canvas-3d",
|
|
3
|
+
"version": "0.0.100",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"lib/**/*{.js,.d.ts}"
|
|
7
|
+
],
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@cyclonium/core": "0.0.100"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/node": "^25.9.2",
|
|
16
|
+
"@vitest/browser-playwright": "^4.1.5",
|
|
17
|
+
"playwright": "^1.59.1",
|
|
18
|
+
"typescript": "^6.0.2",
|
|
19
|
+
"vitest": "^4.1.5",
|
|
20
|
+
"@cyclonium/cc-test": "0.0.100",
|
|
21
|
+
"@cyclonium/types-cc": "0.0.100",
|
|
22
|
+
"@cyclonium/workflow": "0.0.100"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -b",
|
|
26
|
+
"dev": "tsc -b --watch",
|
|
27
|
+
"test:browser": "vitest --no-file-parallelism --disableConsoleIntercept",
|
|
28
|
+
"test": "npm run test:compile && npm run t",
|
|
29
|
+
"test:compile": "tsc -b test/tsconfig.json",
|
|
30
|
+
"t": "npm run test:browser -- run --browser.headless=true"
|
|
31
|
+
}
|
|
32
|
+
}
|