From eb08d4f8d88750ad0fc40b421d92bd1ccd9dae8d Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Fri, 19 Apr 2024 22:02:28 -0400 Subject: [PATCH] create newScene function first version --- src/index.js | 1 + src/street-utils.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/street-utils.js diff --git a/src/index.js b/src/index.js index a0b3fc41a..52c69bfee 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,7 @@ if (typeof VERSION !== 'undefined') { console.log(`3DStreet Version: ${VERSION}` var streetmixParsers = require('./aframe-streetmix-parsers'); var streetmixUtils = require('./tested/streetmix-utils'); require('./json-utils_1.1.js'); +require('./street-utils.js'); require('./components/gltf-part'); require('./components/ocean'); require('./components/svg-extruder.js'); diff --git a/src/street-utils.js b/src/street-utils.js new file mode 100644 index 000000000..7a78accce --- /dev/null +++ b/src/street-utils.js @@ -0,0 +1,45 @@ +/* global AFRAME, THREE */ +/* 3DStreet utils functions */ + +/* +clear old scene elements and data. Create blank scene +*/ +function newScene() { + + const streetContainerEl = document.querySelector("#street-container"); + const environmentEl = document.querySelector("#environment"); + const referenceLayersEl = document.querySelector("#reference-layers"); + + // clear street-container element + while (streetContainerEl.firstChild) { + streetContainerEl.removeChild(streetContainerEl.lastChild); + } + // streetContainerEl.innerHTML = ''; + // create default-street element + const defaultStreet = document.createElement("a-entity"); + defaultStreet.id = "default-street"; + streetContainerEl.appendChild(defaultStreet); + + // clear environment element + while (environmentEl.firstChild) { + environmentEl.removeChild(environmentEl.lastChild); + } + // set default preset:day + environmentEl.setAttribute('street-environment', 'preset', 'day'); + + // clear reference layers + while (referenceLayersEl.firstChild) { + referenceLayersEl.removeChild(referenceLayersEl.lastChild); + } + + // clear metadata + AFRAME.scenes[0].setAttribute('metadata', 'sceneId', ''); + AFRAME.scenes[0].setAttribute('metadata', 'sceneTitle', ''); + + // clear url hash + setTimeout(function () { + window.location.hash = ''; + }); +} + +STREET.utils.newScene = newScene;