From b554a6818666c9ddd8e9869f1bb36a4bc0d708fe Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Thu, 4 Mar 2021 18:33:44 -0800 Subject: [PATCH] Remote page now has UI and pushes settings. --- .../android/filament/gltf/MainActivity.kt | 44 ++++++++++++------- web/samples/remote.html | 16 ++++--- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/android/samples/sample-gltf-viewer/src/main/java/com/google/android/filament/gltf/MainActivity.kt b/android/samples/sample-gltf-viewer/src/main/java/com/google/android/filament/gltf/MainActivity.kt index a6dea4766d..48a5bf5ada 100644 --- a/android/samples/sample-gltf-viewer/src/main/java/com/google/android/filament/gltf/MainActivity.kt +++ b/android/samples/sample-gltf-viewer/src/main/java/com/google/android/filament/gltf/MainActivity.kt @@ -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) } - } } } diff --git a/web/samples/remote.html b/web/samples/remote.html index e0e01595a6..b65a8ceec1 100644 --- a/web/samples/remote.html +++ b/web/samples/remote.html @@ -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; }