fix(editor): correct TeleportElement option and improve dropdown
Correctly set the value for the Teleport option in the element creation form, ensuring that elements are correctly classified. Enhanced dynamic data fetching for scenes and categories to populate the destination dropdown based on the scene's category, improving user experience in specifying teleport destinations. Resolved an issue with event propagation by explicitly setting the button type for dropdown items, preventing form submission on selection. This change streamlines the process of creating teleport elements and selecting destinations within the editor, making it more intuitive and error-free. - Removed outdated TODO comment related to element drags handling. - Removed unused rotation input fields for a cleaner UI. - Added conversion function `thetaToCartesian` for future functionalities.
This commit is contained in:
parent
538ddd76e9
commit
c43ddfef2a
2 changed files with 58 additions and 38 deletions
|
@ -30,7 +30,6 @@ function addEventListeners(element) {
|
||||||
element.addEventListener("mouseup", function (event) {
|
element.addEventListener("mouseup", function (event) {
|
||||||
if (event.timeStamp - clickTimestamp > 200) {
|
if (event.timeStamp - clickTimestamp > 200) {
|
||||||
// Ignoring this, we only handle regular short clicks.
|
// Ignoring this, we only handle regular short clicks.
|
||||||
// TODO: Find a way to handle drags of elements
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
handleClick(event);
|
handleClick(event);
|
||||||
|
@ -73,7 +72,7 @@ function startCreateElement(event) {
|
||||||
<option selected>Select Element Type</option>
|
<option selected>Select Element Type</option>
|
||||||
<option value="MarkerElement">Marker</option>
|
<option value="MarkerElement">Marker</option>
|
||||||
<option value="ImageElement">Image</option>
|
<option value="ImageElement">Image</option>
|
||||||
<option value="ImageElement">Teleport</option>
|
<option value="TeleportElement">Teleport</option>
|
||||||
</select>
|
</select>
|
||||||
<input type="hidden" id="csrfmiddlewaretoken" value="${getCookie(
|
<input type="hidden" id="csrfmiddlewaretoken" value="${getCookie(
|
||||||
"csrftoken"
|
"csrftoken"
|
||||||
|
@ -82,6 +81,9 @@ function startCreateElement(event) {
|
||||||
</form>
|
</form>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
var scene = findParentScene(event.target);
|
||||||
|
var scene_data_request = getScene(scene.getAttribute("id"));
|
||||||
|
|
||||||
document.getElementById("resetButton").classList.remove("hide");
|
document.getElementById("resetButton").classList.remove("hide");
|
||||||
document.getElementById("buttons").classList.remove("hide");
|
document.getElementById("buttons").classList.remove("hide");
|
||||||
|
|
||||||
|
@ -90,6 +92,14 @@ function startCreateElement(event) {
|
||||||
.addEventListener("change", function () {
|
.addEventListener("change", function () {
|
||||||
var selectedType = document.getElementById("resourcetype").value;
|
var selectedType = document.getElementById("resourcetype").value;
|
||||||
createElementPropertiesForm(selectedType, event, thetaStart);
|
createElementPropertiesForm(selectedType, event, thetaStart);
|
||||||
|
|
||||||
|
scene_data_request.then((scene_data) => {
|
||||||
|
var category_data_request = getCategory(scene_data.obj.category);
|
||||||
|
|
||||||
|
category_data_request.then((category_data) => {
|
||||||
|
populateDestinationDropdown(null, category_data);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,20 +130,6 @@ function createElementPropertiesForm(elementType) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
|
||||||
<label for="rotation_x" class="form-label">Rotation</label>
|
|
||||||
<div class="row g-2">
|
|
||||||
<div class="col">
|
|
||||||
<input type="number" class="form-control" id="rotation_x" name="rotation_x" min="0" max="360" placeholder="X">
|
|
||||||
</div>
|
|
||||||
<div class="col">
|
|
||||||
<input type="number" class="form-control" id="rotation_y" name="rotation_y" min="0" max="360" placeholder="Y">
|
|
||||||
</div>
|
|
||||||
<div class="col">
|
|
||||||
<input type="number" class="form-control" id="rotation_z" name="rotation_z" min="0" max="360" placeholder="Z">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
if (elementType !== "MarkerElement") {
|
if (elementType !== "MarkerElement") {
|
||||||
inputFields += `
|
inputFields += `
|
||||||
|
@ -288,6 +284,28 @@ function cartesianToTheta(x, z) {
|
||||||
return thetaStart;
|
return thetaStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function thetaToCartesian(thetaStart, radius = 1) {
|
||||||
|
// Convert thetaStart back to the angle in degrees as used in standard Cartesian coordinates.
|
||||||
|
let angleDegrees = 90 - thetaStart;
|
||||||
|
|
||||||
|
// Normalize the angle to be within the range of 0 to 360 degrees
|
||||||
|
angleDegrees = angleDegrees % 360;
|
||||||
|
if (angleDegrees < 0) {
|
||||||
|
angleDegrees += 360;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the angle back to radians
|
||||||
|
let angleRadians = angleDegrees * (Math.PI / 180);
|
||||||
|
|
||||||
|
// Calculate the Cartesian coordinates using the angle and radius
|
||||||
|
// x = r * cos(θ)
|
||||||
|
let x = radius * Math.cos(angleRadians);
|
||||||
|
// z = r * sin(θ)
|
||||||
|
let z = radius * Math.sin(angleRadians);
|
||||||
|
|
||||||
|
return { x, z };
|
||||||
|
}
|
||||||
|
|
||||||
function latLonToXYZ(lat, lon, radius = 5) {
|
function latLonToXYZ(lat, lon, radius = 5) {
|
||||||
// Convert lat/lon to X/Y/Z coordinates on the sphere
|
// Convert lat/lon to X/Y/Z coordinates on the sphere
|
||||||
const phi = (90 - lat) * (Math.PI / 180);
|
const phi = (90 - lat) * (Math.PI / 180);
|
||||||
|
@ -337,8 +355,8 @@ function toggleDebugVisibility() {
|
||||||
debugElement.classList.toggle("hide");
|
debugElement.classList.toggle("hide");
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('keydown', function(event) {
|
document.addEventListener("keydown", function (event) {
|
||||||
if (event.ctrlKey && event.shiftKey && event.key === 'Q') {
|
if (event.ctrlKey && event.shiftKey && event.key === "Q") {
|
||||||
toggleDebugVisibility();
|
toggleDebugVisibility();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ function populateDestinationDropdown(initial, category_data) {
|
||||||
item.img = resolutions[0].file;
|
item.img = resolutions[0].file;
|
||||||
|
|
||||||
const element = document.createElement("button");
|
const element = document.createElement("button");
|
||||||
|
element.setAttribute("type", "button");
|
||||||
element.classList.add("dropdown-item");
|
element.classList.add("dropdown-item");
|
||||||
element.innerHTML = `<img src="${item.img}" alt="${item.title}"><span class="dropdown-item-text">${item.title}</span>`;
|
element.innerHTML = `<img src="${item.img}" alt="${item.title}"><span class="dropdown-item-text">${item.title}</span>`;
|
||||||
element.onclick = function () {
|
element.onclick = function () {
|
||||||
|
@ -62,6 +63,7 @@ function populateDestinationDropdown(initial, category_data) {
|
||||||
// Repopulate dropdown with filtered items
|
// Repopulate dropdown with filtered items
|
||||||
filteredItems.forEach((item) => {
|
filteredItems.forEach((item) => {
|
||||||
const element = document.createElement("button");
|
const element = document.createElement("button");
|
||||||
|
element.setAttribute("type", "button");
|
||||||
element.classList.add("dropdown-item");
|
element.classList.add("dropdown-item");
|
||||||
element.innerHTML = `<img src="${item.img}" alt="${item.title}"> ${item.title}`;
|
element.innerHTML = `<img src="${item.img}" alt="${item.title}"> ${item.title}`;
|
||||||
element.onclick = function () {
|
element.onclick = function () {
|
||||||
|
|
Loading…
Reference in a new issue