tosijs-3d 0.7.2 → 0.7.4
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/CHANGELOG.md +900 -0
- package/dist/b3d-aircraft.d.ts +14 -0
- package/dist/b3d-aircraft.d.ts.map +1 -1
- package/dist/b3d-aircraft.js +45 -0
- package/dist/b3d-aircraft.js.map +1 -1
- package/dist/b3d-ambient.d.ts +12 -0
- package/dist/b3d-ambient.d.ts.map +1 -1
- package/dist/b3d-ambient.js +83 -1
- package/dist/b3d-ambient.js.map +1 -1
- package/dist/b3d-biped.d.ts +290 -0
- package/dist/b3d-biped.d.ts.map +1 -1
- package/dist/b3d-biped.js +1366 -22
- package/dist/b3d-biped.js.map +1 -1
- package/dist/b3d-collisions.d.ts.map +1 -1
- package/dist/b3d-collisions.js +45 -7
- package/dist/b3d-collisions.js.map +1 -1
- package/dist/b3d-controllable.d.ts +50 -0
- package/dist/b3d-controllable.d.ts.map +1 -1
- package/dist/b3d-controllable.js +61 -0
- package/dist/b3d-controllable.js.map +1 -1
- package/dist/b3d-death.d.ts +26 -0
- package/dist/b3d-death.d.ts.map +1 -1
- package/dist/b3d-death.js +224 -2
- package/dist/b3d-death.js.map +1 -1
- package/dist/b3d-interactive.d.ts +80 -0
- package/dist/b3d-interactive.d.ts.map +1 -0
- package/dist/b3d-interactive.js +284 -0
- package/dist/b3d-interactive.js.map +1 -0
- package/dist/b3d-library.d.ts +39 -0
- package/dist/b3d-library.d.ts.map +1 -1
- package/dist/b3d-library.js +67 -0
- package/dist/b3d-library.js.map +1 -1
- package/dist/b3d-svg-plane.d.ts +35 -0
- package/dist/b3d-svg-plane.d.ts.map +1 -1
- package/dist/b3d-svg-plane.js +96 -8
- package/dist/b3d-svg-plane.js.map +1 -1
- package/dist/b3d-water.d.ts.map +1 -1
- package/dist/b3d-water.js +32 -6
- package/dist/b3d-water.js.map +1 -1
- package/dist/buoyancy.d.ts +90 -0
- package/dist/buoyancy.d.ts.map +1 -0
- package/dist/buoyancy.js +150 -0
- package/dist/buoyancy.js.map +1 -0
- package/dist/curve-field.d.ts +39 -0
- package/dist/curve-field.d.ts.map +1 -0
- package/dist/curve-field.js +491 -0
- package/dist/curve-field.js.map +1 -0
- package/dist/curve.d.ts +241 -0
- package/dist/curve.d.ts.map +1 -0
- package/dist/curve.js +559 -0
- package/dist/curve.js.map +1 -0
- package/dist/dialog-placement.d.ts +69 -7
- package/dist/dialog-placement.d.ts.map +1 -1
- package/dist/dialog-placement.js +90 -9
- package/dist/dialog-placement.js.map +1 -1
- package/dist/embed-font.d.ts +48 -0
- package/dist/embed-font.d.ts.map +1 -0
- package/dist/embed-font.js +135 -0
- package/dist/embed-font.js.map +1 -0
- package/dist/footprint-field.d.ts +30 -0
- package/dist/footprint-field.d.ts.map +1 -0
- package/dist/footprint-field.js +256 -0
- package/dist/footprint-field.js.map +1 -0
- package/dist/frame-panel.d.ts.map +1 -1
- package/dist/frame-panel.js +15 -12
- package/dist/frame-panel.js.map +1 -1
- package/dist/glb-manifest.d.ts +75 -0
- package/dist/glb-manifest.d.ts.map +1 -0
- package/dist/glb-manifest.js +198 -0
- package/dist/glb-manifest.js.map +1 -0
- package/dist/icon-data.d.ts.map +1 -1
- package/dist/icon-data.js +20 -1
- package/dist/icon-data.js.map +1 -1
- package/dist/index.d.ts +33 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -3
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +66 -0
- package/dist/interaction.d.ts.map +1 -0
- package/dist/interaction.js +117 -0
- package/dist/interaction.js.map +1 -0
- package/dist/interactive-behavior.d.ts +105 -0
- package/dist/interactive-behavior.d.ts.map +1 -0
- package/dist/interactive-behavior.js +253 -0
- package/dist/interactive-behavior.js.map +1 -0
- package/dist/key-layout.d.ts +70 -0
- package/dist/key-layout.d.ts.map +1 -1
- package/dist/key-layout.js +122 -0
- package/dist/key-layout.js.map +1 -1
- package/dist/keyboard-gamepad.d.ts.map +1 -1
- package/dist/keyboard-gamepad.js +19 -6
- package/dist/keyboard-gamepad.js.map +1 -1
- package/dist/keyboard.d.ts +100 -1
- package/dist/keyboard.d.ts.map +1 -1
- package/dist/keyboard.js +280 -35
- package/dist/keyboard.js.map +1 -1
- package/dist/mantle.d.ts +56 -0
- package/dist/mantle.d.ts.map +1 -0
- package/dist/mantle.js +115 -0
- package/dist/mantle.js.map +1 -0
- package/dist/popup-surface.d.ts +5 -1
- package/dist/popup-surface.d.ts.map +1 -1
- package/dist/popup-surface.js +181 -14
- package/dist/popup-surface.js.map +1 -1
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +111 -15
- package/dist/surface.js.map +1 -1
- package/dist/svg-icons.d.ts.map +1 -1
- package/dist/svg-icons.js +13 -1
- package/dist/svg-icons.js.map +1 -1
- package/dist/svg-texture.d.ts.map +1 -1
- package/dist/svg-texture.js +40 -1
- package/dist/svg-texture.js.map +1 -1
- package/dist/swim-aim.d.ts +78 -0
- package/dist/swim-aim.d.ts.map +1 -0
- package/dist/swim-aim.js +140 -0
- package/dist/swim-aim.js.map +1 -0
- package/dist/theme-editor.d.ts +41 -0
- package/dist/theme-editor.d.ts.map +1 -0
- package/dist/theme-editor.js +303 -0
- package/dist/theme-editor.js.map +1 -0
- package/dist/tosi-b3d.d.ts +24 -4
- package/dist/tosi-b3d.d.ts.map +1 -1
- package/dist/tosi-b3d.js +238 -37
- package/dist/tosi-b3d.js.map +1 -1
- package/dist/vector-field.d.ts +58 -0
- package/dist/vector-field.d.ts.map +1 -0
- package/dist/vector-field.js +321 -0
- package/dist/vector-field.js.map +1 -0
- package/dist/virtual-gamepad.d.ts.map +1 -1
- package/dist/virtual-gamepad.js +46 -9
- package/dist/virtual-gamepad.js.map +1 -1
- package/dist/w3d-theme.d.ts +115 -17
- package/dist/w3d-theme.d.ts.map +1 -1
- package/dist/w3d-theme.js +311 -0
- package/dist/w3d-theme.js.map +1 -1
- package/dist/water-normal.d.ts +26 -0
- package/dist/water-normal.d.ts.map +1 -0
- package/dist/water-normal.js +105 -0
- package/dist/water-normal.js.map +1 -0
- package/dist/widgets3d-layout.d.ts +58 -0
- package/dist/widgets3d-layout.d.ts.map +1 -1
- package/dist/widgets3d-layout.js +79 -1
- package/dist/widgets3d-layout.js.map +1 -1
- package/dist/widgets3d.d.ts +51 -2
- package/dist/widgets3d.d.ts.map +1 -1
- package/dist/widgets3d.js +418 -112
- package/dist/widgets3d.js.map +1 -1
- package/dist/wreck-fall.d.ts +86 -0
- package/dist/wreck-fall.d.ts.map +1 -0
- package/dist/wreck-fall.js +129 -0
- package/dist/wreck-fall.js.map +1 -0
- package/package.json +9 -6
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/*#
|
|
2
|
+
# vector-field
|
|
3
|
+
|
|
4
|
+
**A coordinate on ONE row.** `vector3d` edits an `{x, y, z}`; `euler3d` edits an
|
|
5
|
+
orientation in degrees. Both are [[widgets3d|Widget3d]]s, so they drop into a
|
|
6
|
+
`panel3d` beside a slider or a button and work identically flat, in-scene and in
|
|
7
|
+
VR.
|
|
8
|
+
|
|
9
|
+
## Why this exists
|
|
10
|
+
|
|
11
|
+
Three stacked labelled fields is the obvious way to edit a coordinate and it is
|
|
12
|
+
the reason an inspector panel ends up three times taller than it needs to be.
|
|
13
|
+
Tonio, on the adopter that prompted it: ensemble's UI is "an utter mess right now
|
|
14
|
+
because simple things like XYZ coords take up huge amounts of space".
|
|
15
|
+
|
|
16
|
+
A coordinate is **one value**, not three, and it should occupy one row. That is
|
|
17
|
+
also why the axis letter is drawn *inside* the row rather than as its own label
|
|
18
|
+
column — a column of `x:` `y:` `z:` labels costs more width than the numbers do,
|
|
19
|
+
and every 3D tool worth using puts the letter against the field.
|
|
20
|
+
|
|
21
|
+
## Degrees, and why `euler3d` is a separate function
|
|
22
|
+
|
|
23
|
+
`euler3d` is `vector3d` with the angle rules applied, not a styling variant: it
|
|
24
|
+
**wraps** (181° is −179°, and dragging through the bottom of a turn should not
|
|
25
|
+
stop), and it is **degrees**, which per CLAUDE.md's suffix rule means the bare
|
|
26
|
+
`value` is already degrees and no conversion is implied.
|
|
27
|
+
|
|
28
|
+
Wrapping is the whole difference and it is not a detail — a wrapping value with a
|
|
29
|
+
`min`/`max` clamp fights you at exactly the angles you most want to scrub
|
|
30
|
+
through.
|
|
31
|
+
|
|
32
|
+
## Focus and typing
|
|
33
|
+
|
|
34
|
+
The fields are exposed as `fields` so a
|
|
35
|
+
[[keyboard|fieldGroup]] can wire focus traversal and an on-screen keyboard across
|
|
36
|
+
a whole panel. A vector row is three tab stops, not one, because that is what it
|
|
37
|
+
is to a person filling it in.
|
|
38
|
+
|
|
39
|
+
## Demo
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { b3d, b3dLight, panelScene, panel3d, label3d, vector3d, euler3d } from 'tosijs-3d'
|
|
43
|
+
import { elements } from 'tosijs'
|
|
44
|
+
const { div, pre } = elements
|
|
45
|
+
|
|
46
|
+
const readout = pre({ style: 'margin:8px 16px;color:#8ea;font:12px ui-monospace,monospace' }, '')
|
|
47
|
+
const state = { pos: { x: 1.5, y: 0, z: -3.25 }, rot: { x: 0, y: 45, z: 0 } }
|
|
48
|
+
const show = () => {
|
|
49
|
+
readout.textContent =
|
|
50
|
+
`position ${state.pos.x}, ${state.pos.y}, ${state.pos.z}\n` +
|
|
51
|
+
`rotation ${state.rot.x}°, ${state.rot.y}°, ${state.rot.z}°`
|
|
52
|
+
}
|
|
53
|
+
show()
|
|
54
|
+
|
|
55
|
+
// panel3d takes its widgets as REST ARGS and returns the <svg> itself — it is
|
|
56
|
+
// both the DOM view and the texture source, and `handlePointer` hangs off it.
|
|
57
|
+
const panel = panel3d(
|
|
58
|
+
{ width: 300 },
|
|
59
|
+
label3d({ text: 'position', muted: true, compact: true }),
|
|
60
|
+
vector3d({
|
|
61
|
+
value: state.pos,
|
|
62
|
+
step: 0.25,
|
|
63
|
+
scrub: 0.02,
|
|
64
|
+
onChange: (v) => { state.pos = v; show() },
|
|
65
|
+
}),
|
|
66
|
+
label3d({ text: 'rotation (degrees)', muted: true, compact: true }),
|
|
67
|
+
euler3d({
|
|
68
|
+
value: state.rot,
|
|
69
|
+
step: 5,
|
|
70
|
+
scrub: 0.5,
|
|
71
|
+
onChange: (v) => { state.rot = v; show() },
|
|
72
|
+
})
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
const { plane, sceneCreated } = panelScene({ svg: panel, target: panel, width: 2.4, camera: { radius: 3.2 } })
|
|
76
|
+
const scene = b3d({ style: 'border-radius:8px;overflow:hidden', sceneCreated }, b3dLight({ intensity: 1 }), plane)
|
|
77
|
+
|
|
78
|
+
preview.append(
|
|
79
|
+
div(
|
|
80
|
+
{ style: 'display:flex;flex-direction:column;height:100%;background:#0c0e14' },
|
|
81
|
+
div(
|
|
82
|
+
{ style: 'display:flex;gap:24px;flex:1;min-height:0;padding:16px 16px 4px' },
|
|
83
|
+
div({ style: 'color:#9ab;font:12px system-ui;display:flex;flex-direction:column;gap:6px;flex:1;min-width:0' }, 'DOM — drag a number to scrub', panel),
|
|
84
|
+
div({ style: 'color:#9ab;font:12px system-ui;display:flex;flex-direction:column;gap:6px;flex:1;min-width:0' }, '3D texture — same widget', scene)
|
|
85
|
+
),
|
|
86
|
+
readout
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
```
|
|
90
|
+
```css
|
|
91
|
+
.preview {
|
|
92
|
+
height: 100%;
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
*/
|
|
96
|
+
/*{ "parent": "UI", "order": 250 }*/
|
|
97
|
+
import { svgElements } from 'tosijs';
|
|
98
|
+
import { inputField } from './keyboard';
|
|
99
|
+
import { w3dTheme } from './w3d-theme';
|
|
100
|
+
const { g, text } = svgElements;
|
|
101
|
+
/** Trim to `precision`, then drop trailing zeros: `1.500` reads as `1.5`. */
|
|
102
|
+
function show(n, precision) {
|
|
103
|
+
if (!Number.isFinite(n))
|
|
104
|
+
return '0';
|
|
105
|
+
const s = n.toFixed(precision);
|
|
106
|
+
return s.includes('.') ? s.replace(/\.?0+$/, '') : s;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Wrap into `(-180, 180]`.
|
|
110
|
+
*
|
|
111
|
+
* Exported because it is the entire behavioural difference between `euler3d` and
|
|
112
|
+
* `vector3d`, and a pure function with a stated range is worth pinning in a test
|
|
113
|
+
* rather than trusting a modulo written from memory. JS `%` keeps the sign of the
|
|
114
|
+
* dividend, so the naive form returns −180 for +180 and disagrees at exactly the
|
|
115
|
+
* boundary you are most likely to hit by dragging.
|
|
116
|
+
*/
|
|
117
|
+
export function wrapDegrees(deg) {
|
|
118
|
+
if (!Number.isFinite(deg))
|
|
119
|
+
return 0;
|
|
120
|
+
const wrapped = ((((deg + 180) % 360) + 360) % 360) - 180;
|
|
121
|
+
// The half-open end: +180 is the same orientation as −180, and a control that
|
|
122
|
+
// flips sign as you cross the back of a turn reads as a glitch.
|
|
123
|
+
return wrapped === -180 ? 180 : wrapped;
|
|
124
|
+
}
|
|
125
|
+
/** Shared builder — `vector3d` and `euler3d` differ only in how a value settles. */
|
|
126
|
+
function coordinateRow(config, settle) {
|
|
127
|
+
const axes = config.axes ?? ['x', 'y', 'z'];
|
|
128
|
+
const precision = config.precision ?? 3;
|
|
129
|
+
const gap = config.gap ?? Math.max(4, Math.round(w3dTheme.spacing * 0.5));
|
|
130
|
+
const fontSize = config.fontSize ?? w3dTheme.fontSize;
|
|
131
|
+
const current = { ...(config.value ?? { x: 0, y: 0, z: 0 }) };
|
|
132
|
+
const el = g();
|
|
133
|
+
const keys = ['x', 'y', 'z'];
|
|
134
|
+
/*
|
|
135
|
+
The axis letter is drawn HERE, not inside the field.
|
|
136
|
+
|
|
137
|
+
It has to sit in the row's own coordinate space so it can be positioned against
|
|
138
|
+
the field it labels, and keeping it out of `inputField` means the field stays
|
|
139
|
+
the general-purpose control it already is — a vector row is a composition, not
|
|
140
|
+
a new kind of field.
|
|
141
|
+
*/
|
|
142
|
+
const letters = axes.map((a) => text({
|
|
143
|
+
'font-family': w3dTheme.fontFamily,
|
|
144
|
+
'font-size': String(Math.round(fontSize * 0.85)),
|
|
145
|
+
fill: w3dTheme.muted,
|
|
146
|
+
}, a));
|
|
147
|
+
const fields = keys.map((key, i) => inputField({
|
|
148
|
+
type: 'number',
|
|
149
|
+
value: show(current[key], precision),
|
|
150
|
+
fontSize,
|
|
151
|
+
height: config.height,
|
|
152
|
+
step: config.step,
|
|
153
|
+
scrub: config.scrub,
|
|
154
|
+
// A wrapping value must NOT be clamped — see `euler3d`. The caller's
|
|
155
|
+
// min/max only reaches a non-wrapping row.
|
|
156
|
+
min: settle === identity ? config.min : undefined,
|
|
157
|
+
max: settle === identity ? config.max : undefined,
|
|
158
|
+
onChange: (raw) => {
|
|
159
|
+
const n = Number(raw);
|
|
160
|
+
if (!Number.isFinite(n))
|
|
161
|
+
return;
|
|
162
|
+
const v = settle(n);
|
|
163
|
+
if (v === current[key])
|
|
164
|
+
return;
|
|
165
|
+
current[key] = v;
|
|
166
|
+
// Write the settled value back when it differs from what was typed, so
|
|
167
|
+
// `190` visibly becomes `-170` rather than being silently reinterpreted.
|
|
168
|
+
if (v !== n)
|
|
169
|
+
fields[i].setValue(show(v, precision));
|
|
170
|
+
config.onChange?.({ ...current });
|
|
171
|
+
},
|
|
172
|
+
}));
|
|
173
|
+
const wraps = fields.map((f) => {
|
|
174
|
+
const wrap = g();
|
|
175
|
+
wrap.appendChild(f.el);
|
|
176
|
+
el.appendChild(wrap);
|
|
177
|
+
return wrap;
|
|
178
|
+
});
|
|
179
|
+
letters.forEach((l) => el.appendChild(l));
|
|
180
|
+
// Geometry from the last layout, so pointer routing uses exactly what was
|
|
181
|
+
// drawn — the same rule `row3d` follows, and for the same reason.
|
|
182
|
+
let cols = [];
|
|
183
|
+
let rowHeight = 0;
|
|
184
|
+
/*
|
|
185
|
+
WHICH field is focused — the row is three tab stops, not one.
|
|
186
|
+
|
|
187
|
+
The host tracks focus per WIDGET, so it can only tell this row "you are
|
|
188
|
+
focused". Forwarding that to all three fields lit all three carets at once
|
|
189
|
+
(six on a panel with a position and a rotation), and since the caret IS the
|
|
190
|
+
focus indicator, that says focus is everywhere, which is the same as saying
|
|
191
|
+
nothing. So the row keeps its own index and reflects the host's state onto
|
|
192
|
+
exactly one field.
|
|
193
|
+
*/
|
|
194
|
+
let active = 0;
|
|
195
|
+
const at = (x, y) => {
|
|
196
|
+
for (let i = 0; i < cols.length; i++) {
|
|
197
|
+
const c = cols[i];
|
|
198
|
+
if (x >= c.x && x <= c.x + c.width)
|
|
199
|
+
return { i, lx: x - c.x, ly: y };
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
};
|
|
203
|
+
return {
|
|
204
|
+
el,
|
|
205
|
+
layout(width) {
|
|
206
|
+
const letterW = Math.round(fontSize * 0.7);
|
|
207
|
+
const cell = (width - gap * 2) / 3;
|
|
208
|
+
const fieldW = Math.max(8, cell - letterW);
|
|
209
|
+
cols = [];
|
|
210
|
+
rowHeight = 0;
|
|
211
|
+
keys.forEach((_, i) => {
|
|
212
|
+
const cellX = i * (cell + gap);
|
|
213
|
+
const h = fields[i].layout(fieldW);
|
|
214
|
+
rowHeight = Math.max(rowHeight, h);
|
|
215
|
+
cols.push({ x: cellX + letterW, width: fieldW });
|
|
216
|
+
wraps[i].setAttribute('transform', `translate(${cellX + letterW}, 0)`);
|
|
217
|
+
});
|
|
218
|
+
letters.forEach((l, i) => {
|
|
219
|
+
l.setAttribute('x', String(i * (cell + gap)));
|
|
220
|
+
// Optical centring against the field, which owns its own height.
|
|
221
|
+
l.setAttribute('y', String(Math.round(rowHeight / 2 + fontSize * 0.32)));
|
|
222
|
+
});
|
|
223
|
+
return rowHeight;
|
|
224
|
+
},
|
|
225
|
+
handle(kind, x, y) {
|
|
226
|
+
const hit = at(x, y);
|
|
227
|
+
if (hit == null)
|
|
228
|
+
return;
|
|
229
|
+
// A press is what moves focus between the fields, exactly as clicking one
|
|
230
|
+
// input in a form row does.
|
|
231
|
+
if (kind === 'down')
|
|
232
|
+
active = hit.i;
|
|
233
|
+
fields[hit.i].handle?.(kind, hit.lx, hit.ly);
|
|
234
|
+
},
|
|
235
|
+
hitTest(x, y) {
|
|
236
|
+
const hit = at(x, y);
|
|
237
|
+
if (hit == null)
|
|
238
|
+
return false;
|
|
239
|
+
const f = fields[hit.i];
|
|
240
|
+
return f.hitTest ? f.hitTest(hit.lx, hit.ly) : f.handle != null;
|
|
241
|
+
},
|
|
242
|
+
setState(state) {
|
|
243
|
+
fields.forEach((f, i) => {
|
|
244
|
+
const mine = i === active;
|
|
245
|
+
f.setState?.({
|
|
246
|
+
hovered: state.hovered && mine,
|
|
247
|
+
pressed: state.pressed && mine,
|
|
248
|
+
focused: state.focused && mine,
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
/*
|
|
253
|
+
Left/right walks the axes; up/down escapes to the next row.
|
|
254
|
+
|
|
255
|
+
Returning `false` is what hands focus back to the host, so a D-pad user
|
|
256
|
+
traverses x → y → z and then leaves — rather than being trapped in a row or
|
|
257
|
+
skipping two thirds of it. Same escape contract as `BoxChild.focusMove`.
|
|
258
|
+
*/
|
|
259
|
+
focusMove(dx, dy) {
|
|
260
|
+
if (dy !== 0)
|
|
261
|
+
return false;
|
|
262
|
+
if (dx === 0)
|
|
263
|
+
return true;
|
|
264
|
+
// Entry from the host seeds at the edge it arrived from, so coming back
|
|
265
|
+
// leftwards lands on z rather than on x.
|
|
266
|
+
const next = active + (dx > 0 ? 1 : -1);
|
|
267
|
+
if (next < 0 || next > 2)
|
|
268
|
+
return false;
|
|
269
|
+
active = next;
|
|
270
|
+
return true;
|
|
271
|
+
},
|
|
272
|
+
focusClear() {
|
|
273
|
+
active = 0;
|
|
274
|
+
for (const f of fields) {
|
|
275
|
+
f.setState?.({ hovered: false, pressed: false, focused: false });
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
get value() {
|
|
279
|
+
return { ...current };
|
|
280
|
+
},
|
|
281
|
+
setValue(v) {
|
|
282
|
+
keys.forEach((key, i) => {
|
|
283
|
+
const n = settle(v[key] ?? 0);
|
|
284
|
+
current[key] = n;
|
|
285
|
+
fields[i].setValue(show(n, precision));
|
|
286
|
+
});
|
|
287
|
+
},
|
|
288
|
+
get fields() {
|
|
289
|
+
return fields;
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/** Identity settle — a plain coordinate clamps (if asked) but never wraps. */
|
|
294
|
+
function identity(n) {
|
|
295
|
+
return n;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Edit an `{x, y, z}` on one row.
|
|
299
|
+
*
|
|
300
|
+
* ```js
|
|
301
|
+
* vector3d({ value: { x: 1, y: 0, z: -3 }, step: 0.25, scrub: 0.02, onChange: (v) => … })
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
export function vector3d(config = {}) {
|
|
305
|
+
return coordinateRow(config, identity);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Edit an orientation on one row, in **degrees**.
|
|
309
|
+
*
|
|
310
|
+
* Values wrap into `(-180, 180]` rather than clamping — see `wrapDegrees`. Per
|
|
311
|
+
* the project's angle rule, the bare `value` is already degrees: there is no
|
|
312
|
+
* `Deg` sibling because there is no radian form to disambiguate from.
|
|
313
|
+
*
|
|
314
|
+
* ```js
|
|
315
|
+
* euler3d({ value: { x: 0, y: 45, z: 0 }, step: 5, scrub: 0.5, onChange: (v) => … })
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
export function euler3d(config = {}) {
|
|
319
|
+
return coordinateRow(config, wrapDegrees);
|
|
320
|
+
}
|
|
321
|
+
//# sourceMappingURL=vector-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-field.js","sourceRoot":"","sources":["../src/vector-field.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
|
package/dist/virtual-gamepad.js
CHANGED
|
@@ -266,17 +266,52 @@ export const STICK_UP_IS_POSITIVE = true;
|
|
|
266
266
|
// --- Built-in mapping presets ---
|
|
267
267
|
export function bipedMapping(pad, _dt) {
|
|
268
268
|
const input = emptyInput();
|
|
269
|
+
/*
|
|
270
|
+
GTA V LAYOUT: the left stick MOVES, the right stick TURNS.
|
|
271
|
+
|
|
272
|
+
The biped was tank-controlled — left stick X turned the body — which nobody
|
|
273
|
+
has muscle memory for any more, and it left the right stick doing camera work
|
|
274
|
+
that could not steer. Turning the BODY with the right stick makes swim
|
|
275
|
+
direction and body facing ONE thing rather than two that can disagree, which
|
|
276
|
+
is what made look-directed swimming fiddly to control.
|
|
277
|
+
|
|
278
|
+
Left stick X becomes strafe, which is worth having on land regardless.
|
|
279
|
+
*/
|
|
269
280
|
input.forward = pad.leftStickY;
|
|
270
|
-
input.
|
|
271
|
-
input.
|
|
281
|
+
input.strafe = pad.leftStickX;
|
|
282
|
+
input.turn = pad.rightStickX;
|
|
272
283
|
// Right trigger, not left bumper: movement is the LEFT stick, so a left-hand
|
|
273
284
|
// sprint modifier fights the left thumb. Right trigger frees that up.
|
|
274
285
|
input.sprint = pad.rightTrigger;
|
|
275
286
|
input.interact = pad.buttonX;
|
|
276
287
|
input.shoot = pad.buttonB;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
288
|
+
/*
|
|
289
|
+
Right stick Y is PITCH — the camera's, and while swimming the body's. There is
|
|
290
|
+
no separate camera yaw, because X turns the body and the camera follows it, so
|
|
291
|
+
the view cannot be left pointing somewhere the character is not.
|
|
292
|
+
|
|
293
|
+
It used to be zoom (Y) and a snap-back peek (X), which meant a character had
|
|
294
|
+
no aim at all: nothing to point at a thing, and — once swimming arrived —
|
|
295
|
+
nothing to point DOWN with. Zoom moved to the d-pad, which sneak vacated.
|
|
296
|
+
*/
|
|
297
|
+
input.lookY = pad.rightStickY;
|
|
298
|
+
// Signed: up zooms out, down zooms in. It was wrapped in `Math.max(0, …)`,
|
|
299
|
+
// which silently discarded the entire zoom-in half — down produced 0, not −1,
|
|
300
|
+
// so the camera could only ever retreat. Tonio: "d-pad up zooms out and I
|
|
301
|
+
// can't zoom in."
|
|
302
|
+
input.cameraZoom = pad.dpadUp - pad.dpadDown;
|
|
303
|
+
/*
|
|
304
|
+
BUMPERS for the two vertical verbs: left bumper sneak, right bumper jump.
|
|
305
|
+
|
|
306
|
+
`buttonA` deliberately does NOT jump, though it did originally and I kept it
|
|
307
|
+
as an alias on the grounds that A-to-jump is conventional. Tonio's call, and
|
|
308
|
+
the better one: the face buttons are **reserved for actions**, because they
|
|
309
|
+
are primary and secondary fire on the aircraft and a control vocabulary that
|
|
310
|
+
changes meaning per vehicle is a vocabulary you have to relearn. A convention
|
|
311
|
+
borrowed from other games is worth less than consistency within this one.
|
|
312
|
+
*/
|
|
313
|
+
input.jump = pad.rightBumper;
|
|
314
|
+
input.sneak = pad.leftBumper;
|
|
280
315
|
// Camera toggle: glass-gamepad view button, or Y (reachable on a controller).
|
|
281
316
|
input.view = Math.max(pad.view, pad.buttonY);
|
|
282
317
|
return input;
|
|
@@ -285,13 +320,15 @@ export const bipedMappingDescriptor = {
|
|
|
285
320
|
map: bipedMapping,
|
|
286
321
|
labels: {
|
|
287
322
|
leftStickY: 'move',
|
|
288
|
-
leftStickX: '
|
|
289
|
-
|
|
323
|
+
leftStickX: 'strafe',
|
|
324
|
+
rightStickX: 'turn',
|
|
325
|
+
rightBumper: 'jump',
|
|
326
|
+
leftBumper: 'sneak',
|
|
290
327
|
rightTrigger: 'sprint',
|
|
291
328
|
buttonX: 'interact',
|
|
292
329
|
buttonB: 'shoot',
|
|
293
|
-
rightStickY: '
|
|
294
|
-
|
|
330
|
+
rightStickY: 'pitch',
|
|
331
|
+
dpadUp: 'zoom',
|
|
295
332
|
},
|
|
296
333
|
};
|
|
297
334
|
export function carMapping(pad, _dt) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,CAAA;IAC7B,CAAC;IAED,UAAU,CAAC,OAAqB;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,SAAS,CAAC,MAAqB;QAC7B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;IAED,YAAY,CAAC,MAAqB;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACxC,IAAI,GAAG,GAAG,CAAC,CAAC;YAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;IAC3C,CAAC;IAED,gFAAgF;IAChF,OAAO;QACL,IAAI,MAAM,GAAG,YAAY,EAAE,CAAA;QAC3B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;QAC/C,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED,IAAI,CAAC,EAAU;QACb,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IACjC,CAAC;CACF"}
|
package/dist/w3d-theme.d.ts
CHANGED
|
@@ -6,22 +6,120 @@ export declare const cssVar: (name: string, fallback: string) => string;
|
|
|
6
6
|
* common destructure.
|
|
7
7
|
*/
|
|
8
8
|
export declare const w3dTheme: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
fontSize: number;
|
|
10
|
+
fontFamily: string;
|
|
11
|
+
text: string;
|
|
12
|
+
muted: string;
|
|
13
|
+
headingWeight: string;
|
|
14
|
+
textWeight: string;
|
|
15
|
+
panelBg: string;
|
|
16
|
+
buttonBg: string;
|
|
17
|
+
buttonHover: string;
|
|
18
|
+
buttonActive: string;
|
|
19
|
+
/**
|
|
20
|
+
* Label colour while a clickable is HELD or selected.
|
|
21
|
+
*
|
|
22
|
+
* Separate from `text` because the background under it has changed: a theme
|
|
23
|
+
* whose `buttonActive` is a strong accent needs a light label on it, and one
|
|
24
|
+
* whose active state is a subtle tint needs the ordinary text colour. Baking
|
|
25
|
+
* that choice into `text` would force every label in the panel to follow a
|
|
26
|
+
* decision that is only about buttons.
|
|
27
|
+
*/
|
|
28
|
+
buttonActiveText: string;
|
|
29
|
+
track: string;
|
|
30
|
+
accent: string;
|
|
31
|
+
rowBg: string;
|
|
32
|
+
rowHover: string;
|
|
33
|
+
info: string;
|
|
34
|
+
warning: string;
|
|
35
|
+
error: string;
|
|
36
|
+
focus: string;
|
|
37
|
+
selectedBg: string;
|
|
38
|
+
disabledBg: string;
|
|
39
|
+
disabledText: string;
|
|
40
|
+
strokeWidth: number;
|
|
41
|
+
/**
|
|
42
|
+
* Padding INSIDE a control — what makes a button or a field feel roomy or
|
|
43
|
+
* cramped. Distinct from `spacing`, which is the gap BETWEEN them: a dense
|
|
44
|
+
* inspector wants small padding and comfortable spacing, and a touch UI
|
|
45
|
+
* usually wants the opposite, so one number cannot serve both.
|
|
46
|
+
*
|
|
47
|
+
* Row height derives from it (with `fontSize` and `lineHeight`), so raising
|
|
48
|
+
* it makes controls taller as well as wider — which is what "more spacious"
|
|
49
|
+
* means and what a single width-only padding fails to deliver.
|
|
50
|
+
*/
|
|
51
|
+
padding: number;
|
|
52
|
+
roundedRadius: number;
|
|
53
|
+
spacing: number;
|
|
54
|
+
lineHeight: number;
|
|
55
|
+
codeFontFamily: string;
|
|
56
|
+
codeFontWeight: string;
|
|
57
|
+
overlay: string;
|
|
58
|
+
divider: string;
|
|
59
|
+
/** Placeholder and caret — the two field colours that were literals. */
|
|
60
|
+
placeholder: string;
|
|
61
|
+
caret: string;
|
|
26
62
|
};
|
|
63
|
+
export type W3dTheme = typeof w3dTheme;
|
|
64
|
+
/**
|
|
65
|
+
* **Override the theme at runtime.**
|
|
66
|
+
*
|
|
67
|
+
* The `--w3d-*` variables are read ONCE at load, and deliberately so: an SVG
|
|
68
|
+
* destined to be rasterised onto a texture is serialised away from the
|
|
69
|
+
* document, where `var(--w3d-text)` resolves against nothing and paints black.
|
|
70
|
+
* Baking literals is what makes the same widget work in the DOM and in a scene.
|
|
71
|
+
*
|
|
72
|
+
* The cost of that is no live cascade — restyling the page after load changes
|
|
73
|
+
* nothing. This is the way back in, and it is what a theme editor (or the demo
|
|
74
|
+
* below) needs.
|
|
75
|
+
*
|
|
76
|
+
* **Widgets read the theme when they are BUILT**, so existing ones do not
|
|
77
|
+
* repaint. Rebuild them after calling this. That is a real constraint rather
|
|
78
|
+
* than an oversight: a widget that re-read its colours every frame would have
|
|
79
|
+
* to re-resolve them per rasterised texture too, which is the cost this design
|
|
80
|
+
* exists to avoid.
|
|
81
|
+
*/
|
|
82
|
+
export declare function setW3dTheme(partial: Partial<W3dTheme>): void;
|
|
83
|
+
/**
|
|
84
|
+
* **Build something under a different theme**, then put the old one back.
|
|
85
|
+
*
|
|
86
|
+
* The theme is global — one table, read by every widget — and that is usually
|
|
87
|
+
* what you want: a palette exists so a UI looks like one UI. But an inspector
|
|
88
|
+
* beside a toolbar, a warning panel, or a preview of a theme you are editing
|
|
89
|
+
* all want to differ from their surroundings without becoming a second design
|
|
90
|
+
* system.
|
|
91
|
+
*
|
|
92
|
+
* This works because of the property that makes the global table safe in the
|
|
93
|
+
* first place: **a widget reads the theme when it is BUILT.** So a scope is
|
|
94
|
+
* just "set, build, restore" — no plumbing through every widget, no second
|
|
95
|
+
* table, and a widget built inside keeps its colours forever after, because
|
|
96
|
+
* they were baked into its attributes.
|
|
97
|
+
*
|
|
98
|
+
* ```js
|
|
99
|
+
* // `setW3dTheme` is the DEFAULT; this is the override for one panel.
|
|
100
|
+
* const warning = withTheme({ panelBg: '#6b2323', text: '#ffd7d7' }, () =>
|
|
101
|
+
* panel3d({ width: 300 }, label3d({ text: 'Careful' })))
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* **Why this rather than `panel3d({ theme })`.** A panel's children are
|
|
105
|
+
* constructed as ARGUMENTS, so they are already built by the time the panel
|
|
106
|
+
* function runs — an option on the panel could only re-colour the panel's own
|
|
107
|
+
* background while its contents kept the default, which is worse than not
|
|
108
|
+
* offering it. Wrapping the construction puts the children inside the scope,
|
|
109
|
+
* because that is when they evaluate.
|
|
110
|
+
*
|
|
111
|
+
* The unit that gets its own palette is therefore a panel, not a widget: you
|
|
112
|
+
* theme a thing you build, and a panel is the thing you build.
|
|
113
|
+
*
|
|
114
|
+
* **Synchronous only, and deliberately not enforced.** `build` must not await:
|
|
115
|
+
* the restore happens when it returns, so an async build would leak its theme
|
|
116
|
+
* into whatever ran next. Enforcing that would mean rejecting a function that
|
|
117
|
+
* merely returns a promise for an unrelated reason, and the honest constraint
|
|
118
|
+
* is "build synchronously", which is what widget construction already is.
|
|
119
|
+
*
|
|
120
|
+
* Only the keys you override are saved and restored, so nested scopes compose
|
|
121
|
+
* and an unrelated `setW3dTheme` from elsewhere is not clobbered on the way
|
|
122
|
+
* out.
|
|
123
|
+
*/
|
|
124
|
+
export declare function withTheme<T>(partial: Partial<W3dTheme>, build: () => T): T;
|
|
27
125
|
//# sourceMappingURL=w3d-theme.d.ts.map
|
package/dist/w3d-theme.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"w3d-theme.d.ts","sourceRoot":"","sources":["../src/w3d-theme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"w3d-theme.d.ts","sourceRoot":"","sources":["../src/w3d-theme.ts"],"names":[],"mappings":"AAwJA,+EAA+E;AAC/E,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,UAAU,MAAM,KAAG,MAGvD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;IAwBnB;;;;;;;;OAQG;;;;;;;;;;;;;;IAuDH;;;;;;;;;OASG;;;;;;;;;IA0BH,wEAAwE;;;CAGzE,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAA;AAsBtC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,CAE5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAc1E"}
|