From 304cb8f63dada05cedb9c8a75bb26bbb4d269fd0 Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 11 Mar 2024 16:29:47 +0100 Subject: [PATCH] Introduce Z-axis handling across the app This update introduces support for a third dimension (Z-axis) in scene positioning and orientation, enhancing 3D scene rendering capabilities. Changes include parsing the Z-coordinate attribute in scene elements, updating the `loadScene` function to accommodate the new axis, and extending the models to store this additional data. This pivotal enhancement allows a more refined and immersive user experience by enabling depth control in scene navigation and interactivity. The modification paves the way for future developments in 3D scene manipulation and interaction within the application. --- assets/js/scene.js | 17 +++++++---- ...efault_z_alter_scene_default_x_and_more.py | 28 ++++++++++++++++++ .../0014_teleportelement_destination_z.py | 18 ++++++++++++ quackscape/tours/models.py | 8 +++-- quackscape/tours/templates/tours/scene.html | 29 ++++++++++++++----- .../tours/templates/tours/scene_edit.html | 1 + 6 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 quackscape/tours/migrations/0013_scene_default_z_alter_scene_default_x_and_more.py create mode 100644 quackscape/tours/migrations/0014_teleportelement_destination_z.py diff --git a/assets/js/scene.js b/assets/js/scene.js index 93ac99a..13c7dd8 100644 --- a/assets/js/scene.js +++ b/assets/js/scene.js @@ -8,10 +8,15 @@ class QuackscapeScene extends HTMLElement { connectedCallback() { // When one is created, automatically load the scene this.scene = this.getAttribute("scene"); - this.x = this.getAttribute("x"); - this.y = this.getAttribute("y"); + this.x = this.getAttribute("x") | 0; + this.y = this.getAttribute("y") | 0; + this.z = this.getAttribute("z") | 0; - loadScene(this.scene, this.x, this.y, this); + console.log(this.x); + console.log(this.y); + console.log(this.z); + + loadScene(this.scene, this.x, this.y, this.z, this); } } @@ -24,7 +29,7 @@ customElements.define("quackscape-scene", QuackscapeScene); // Function to load a scene into a destination object // x and y signify the initial looking direction, -1 for the scene's default -async function loadScene(scene_id, x = -1, y = -1, destination = null) { +async function loadScene(scene_id, x = -1, y = -1, z = -1, destination = null) { // Get WebGL maximum texture size var canvas = document.createElement("canvas"); var gl = @@ -74,8 +79,8 @@ async function loadScene(scene_id, x = -1, y = -1, destination = null) { rig.setAttribute("id", "rig"); // Rotate camera if requested - if (x != -1 && y != -1) { - rig.setAttribute("rotation", x + " " + y + " " + "0"); + if (x != -1 && y != -1 && z != -1) { + rig.setAttribute("rotation", x + " " + y + " " + z); } var camera = document.createElement("a-camera"); diff --git a/quackscape/tours/migrations/0013_scene_default_z_alter_scene_default_x_and_more.py b/quackscape/tours/migrations/0013_scene_default_z_alter_scene_default_x_and_more.py new file mode 100644 index 0000000..f0beadc --- /dev/null +++ b/quackscape/tours/migrations/0013_scene_default_z_alter_scene_default_x_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.3 on 2024-03-11 15:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tours', '0012_scene_public_textelement_font_textelement_font_size_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='scene', + name='default_z', + field=models.FloatField(default=0.0), + ), + migrations.AlterField( + model_name='scene', + name='default_x', + field=models.FloatField(default=0.0), + ), + migrations.AlterField( + model_name='scene', + name='default_y', + field=models.FloatField(default=0.0), + ), + ] diff --git a/quackscape/tours/migrations/0014_teleportelement_destination_z.py b/quackscape/tours/migrations/0014_teleportelement_destination_z.py new file mode 100644 index 0000000..b622b44 --- /dev/null +++ b/quackscape/tours/migrations/0014_teleportelement_destination_z.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.3 on 2024-03-11 15:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tours', '0013_scene_default_z_alter_scene_default_x_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='teleportelement', + name='destination_z', + field=models.FloatField(default=-1.0), + ), + ] diff --git a/quackscape/tours/models.py b/quackscape/tours/models.py index 246907e..8412f11 100644 --- a/quackscape/tours/models.py +++ b/quackscape/tours/models.py @@ -171,6 +171,7 @@ class TeleportElement(ImageElement): ) destination_x = models.FloatField(default=-1.0) destination_y = models.FloatField(default=-1.0) + destination_z = models.FloatField(default=-1.0) def __str__(self): return f"{self.scene.title}: {self.label} -> {self.destination.title}" @@ -179,7 +180,7 @@ class TeleportElement(ImageElement): data = super().data() data["attributes"][ "onclick" - ] = f'window.loadScene("{self.destination.id}", {self.destination_x}, {self.destination_y})' + ] = f'window.loadScene("{self.destination.id}", {self.destination_x}, {self.destination_y}, {self.destination_z})' return data @@ -239,8 +240,9 @@ class Scene(models.Model): base_content = models.ForeignKey( OriginalMedia, related_name="scenes", on_delete=models.CASCADE ) - default_x = models.IntegerField(default=0) - default_y = models.IntegerField(default=0) + default_x = models.FloatField(default=0.0) + default_y = models.FloatField(default=0.0) + default_z = models.FloatField(default=0.0) category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True) public = models.BooleanField(default=True) diff --git a/quackscape/tours/templates/tours/scene.html b/quackscape/tours/templates/tours/scene.html index 5f0cf02..f57dfc7 100644 --- a/quackscape/tours/templates/tours/scene.html +++ b/quackscape/tours/templates/tours/scene.html @@ -1,12 +1,25 @@ {% load static %} - + {{ scene.title }} – Quackscape - - - - - - - \ No newline at end of file + + + + + + + diff --git a/quackscape/tours/templates/tours/scene_edit.html b/quackscape/tours/templates/tours/scene_edit.html index 01bda51..01e61bd 100644 --- a/quackscape/tours/templates/tours/scene_edit.html +++ b/quackscape/tours/templates/tours/scene_edit.html @@ -29,6 +29,7 @@ scene="{{ scene.id }}" x="{{ scene.default_x }}" y="{{ scene.default_y }}" + z="{{ scene.default_z }}" >