Remote page now has UI and pushes settings.
This commit is contained in:
@@ -223,6 +223,28 @@ class MainActivity : Activity() {
|
||||
choreographer.removeFrameCallback(frameScheduler)
|
||||
}
|
||||
|
||||
fun loadModelData(message: RemoteServer.ReceivedMessage) {
|
||||
Log.i(TAG, "Downloaded model ${message.label} (${message.buffer.capacity()} bytes)")
|
||||
clearStatusText()
|
||||
titlebarHint.text = message.label
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
if (message.label.endsWith(".zip")) {
|
||||
loadZip(message)
|
||||
} else {
|
||||
loadGlb(message)
|
||||
}
|
||||
} catch (exc: IOException) {
|
||||
setStatusText("URL fetch failed.")
|
||||
Log.e(TAG, "URL fetch failed", exc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadSettings(message: RemoteServer.ReceivedMessage) {
|
||||
Log.i(TAG, "Downloaded settings JSON (${message.buffer.capacity()} bytes)")
|
||||
}
|
||||
|
||||
inner class FrameCallback : Choreographer.FrameCallback {
|
||||
private val startTime = System.nanoTime()
|
||||
override fun doFrame(frameTimeNanos: Long) {
|
||||
@@ -239,30 +261,18 @@ class MainActivity : Activity() {
|
||||
modelViewer.render(frameTimeNanos)
|
||||
|
||||
val label = remoteServer?.peekIncomingLabel()
|
||||
if (label != null) {
|
||||
if (label != null && !label.endsWith(".json")) {
|
||||
Log.i(TAG, "Downloading $label")
|
||||
setStatusText("Downloading $label")
|
||||
}
|
||||
|
||||
val message = remoteServer?.acquireReceivedMessage()
|
||||
if (message != null) {
|
||||
Log.i(TAG, "Downloaded ${message.label} ${message.buffer.capacity()}")
|
||||
clearStatusText()
|
||||
titlebarHint.text = message.label
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
if (message.label.endsWith(".zip")) {
|
||||
loadZip(message)
|
||||
} else {
|
||||
loadGlb(message)
|
||||
}
|
||||
} catch (exc: IOException) {
|
||||
setStatusText("URL fetch failed.")
|
||||
Log.e(TAG, "URL fetch failed", exc)
|
||||
}
|
||||
if (message.label.endsWith(".json")) {
|
||||
loadSettings(message)
|
||||
} else {
|
||||
loadModelData(message)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ class App {
|
||||
resize();
|
||||
|
||||
const dropbox = this.dropbox;
|
||||
const upload = this.uploadFile.bind(this);
|
||||
|
||||
dropbox.addEventListener("dragover", dragEvent => {
|
||||
dropbox.classList.add("bad");
|
||||
@@ -193,7 +194,7 @@ class App {
|
||||
if (!is_glb && !is_zip) return;
|
||||
if (is_zip) fileType = "zip";
|
||||
const files = event.dataTransfer.files;
|
||||
([...files]).forEach(this.uploadFile);
|
||||
([...files]).forEach(upload);
|
||||
}, false);
|
||||
|
||||
this.startSocket();
|
||||
@@ -201,10 +202,11 @@ class App {
|
||||
}
|
||||
|
||||
uploadFile(file) {
|
||||
if (websocket) {
|
||||
const connection = this.websocket;
|
||||
if (connection && connection.readyState == connection.OPEN) {
|
||||
console.info(`Uploading ${file.name}`);
|
||||
this.websocket.send(file.name);
|
||||
this.websocket.send(file);
|
||||
connection.send(file.name);
|
||||
connection.send(file);
|
||||
} else {
|
||||
this.pendingFile = file;
|
||||
}
|
||||
@@ -273,7 +275,11 @@ class App {
|
||||
const settingsJson = this.serializer.writeJson(this.simpleViewer.getSettings()).slice();
|
||||
|
||||
if (this.previousSettingsJson != settingsJson) {
|
||||
console.info("Settings have changed.");
|
||||
const connection = this.websocket;
|
||||
if (connection && connection.readyState == connection.OPEN) {
|
||||
connection.send("setttings.json");
|
||||
connection.send(settingsJson);
|
||||
}
|
||||
this.previousSettingsJson = settingsJson;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user