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;