Ensure camera settings only update when necessary in Model3D (#6871)

* change reset_camera_position reactivity logic

* check for changes when resetting scene

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Hannah 2024-01-04 19:39:57 +01:00 committed by GitHub
parent 377725cbb7
commit d361a0f179
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 4 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/model3d": patch
"gradio": patch
---
fix:Ensure camera settings only update when necessary in Model3D

View File

@ -15,7 +15,8 @@
"@gradio/utils": "workspace:^",
"@types/babylon": "^6.16.6",
"babylonjs": "^4.2.1",
"babylonjs-loaders": "^4.2.1"
"babylonjs-loaders": "^4.2.1",
"dequal": "^2.0.2"
},
"main_changeset": true,
"main": "./Index.svelte",

View File

@ -7,6 +7,7 @@
import * as BABYLON from "babylonjs";
import * as BABYLON_LOADERS from "babylonjs-loaders";
import type { I18nFormatter } from "@gradio/utils";
import { dequal } from "dequal";
export let value: FileData | null;
export let clear_color: [number, number, number, number] = [0, 0, 0, 0];
@ -15,7 +16,6 @@
export let i18n: I18nFormatter;
export let zoom_speed = 1;
export let pan_speed = 1;
// alpha, beta, radius
export let camera_position: [number | null, number | null, number | null] = [
null,
@ -23,6 +23,8 @@
null
];
let current_settings = { camera_position, zoom_speed, pan_speed };
$: {
if (
BABYLON_LOADERS.OBJFileLoader != undefined &&
@ -80,8 +82,17 @@
reset_camera_position(scene, camera_position, zoom_speed, pan_speed);
}
$: if (scene)
reset_camera_position(scene, camera_position, zoom_speed, pan_speed);
$: {
if (
scene &&
(!dequal(current_settings.camera_position, camera_position) ||
current_settings.zoom_speed !== zoom_speed ||
current_settings.pan_speed !== pan_speed)
) {
reset_camera_position(scene, camera_position, zoom_speed, pan_speed);
current_settings = { camera_position, zoom_speed, pan_speed };
}
}
</script>
<BlockLabel

View File

@ -1164,6 +1164,9 @@ importers:
babylonjs-loaders:
specifier: ^4.2.1
version: 4.2.1
dequal:
specifier: ^2.0.2
version: 2.0.3
js/number:
dependencies: