Skip to content

Commit 5416b3f

Browse files
authored
Merge pull request #156 from jolicaD/math_keyboard
This PR modernizes the virtual keyboard by refactoring the layout logic and improving render stability in XR.
2 parents 58e9a76 + 8563aa7 commit 5416b3f

7 files changed

Lines changed: 235 additions & 285 deletions

File tree

.vscode/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.vscode/extensions.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

demos/math3d/Math3D.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,27 @@ export class Math3D extends xb.Script {
9292
light.position.set(-0.5, 4, 1.0);
9393
this.add(light);
9494

95-
this.panel.position.set(0, 1.9, -1.0);
95+
this.panel.position.set(0, 2.0, -1.0);
9696

9797
this.keyboard = new Keyboard();
9898
this.add(this.keyboard);
9999
this.keyboard.position.set(0, -0.3, 0);
100100

101+
const startFn = this.mathObjects[0].functionText;
102+
103+
this.keyboard.setText?.(startFn) || (this.keyboard.keyText = startFn);
104+
101105
this.keyboard.onEnterPressed = (newFunctionText) => {
102106
this.mathObjects[this.descriptionPagerState.currentPage].functionText =
103107
newFunctionText;
104108
this.updateGraph(newFunctionText);
105109
};
106110

107111
this.keyboard.onTextChanged = (currentText) => {
108-
if (this.functionDisplay) {
109-
this.functionDisplay.text = currentText;
112+
const index = this.descriptionPagerState.currentPage;
113+
const currentDisplay = this.descriptionPager.children[index].children[0];
114+
if (currentDisplay && currentDisplay.setText) {
115+
currentDisplay.setText(currentText);
110116
}
111117
};
112118

@@ -174,11 +180,24 @@ export class Math3D extends xb.Script {
174180
var yMin = -5,
175181
yMax = 5,
176182
yRange = yMax - yMin;
183+
184+
const Z_LIMIT = 25; // Maximum absolute value for z to prevent extreme spikes in the graph
177185
var zFunction = Parser.parse(zFunctionText).toJSFunction(['x', 'y']);
178-
var parametricFunction = function (x, y, target) {
179-
var x = xRange * x + xMin;
180-
var y = yRange * y + yMin;
181-
var z = zFunction(x, y);
186+
var parametricFunction = (u, v, target) => {
187+
const x = xRange * u + xMin;
188+
const y = yRange * v + yMin;
189+
190+
let z;
191+
try {
192+
z = zFunction(x, y);
193+
// Clamp the value to stay between -Z_LIMIT and Z_LIMIT
194+
z = xb.clamp(z, -Z_LIMIT, Z_LIMIT);
195+
196+
// Handle cases where the math results in NaN (not a number)
197+
if (isNaN(z)) z = 0;
198+
} catch (e) {
199+
z = 0;
200+
}
182201

183202
target.set(x, y, z);
184203
};

src/addons/netblocks/samples/basic/chat/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class ChatSample extends NetSample {
237237
};
238238
session.events.emit('chat-message', payload);
239239
this._appendLine(payload, true);
240-
keyboard.clearText();
240+
keyboard.setText('');
241241
};
242242
}
243243
}

src/addons/netblocks/samples/integration/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ class IntegrationSample extends NetSample {
588588
};
589589
session.events.emit('chat-message', payload);
590590
this._appendLine(payload, true);
591-
keyboard.clearText();
591+
keyboard.setText('');
592592
};
593593
}
594594

0 commit comments

Comments
 (0)