From 4242dbec4d14708e238cb7faa5c594187a62425d Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Fri, 29 Dec 2023 17:17:31 -0300 Subject: [PATCH 01/23] fix save/load mapbox scene - move environment and cameraRig to a-acene parent - fix saving mapbox component data --- mapbox.html | 107 ++++++++-------------------------------------- src/json-utils.js | 17 ++++++-- 2 files changed, 31 insertions(+), 93 deletions(-) diff --git a/mapbox.html b/mapbox.html index 194a9a2e0..ba1621781 100644 --- a/mapbox.html +++ b/mapbox.html @@ -98,17 +98,17 @@ streetmix-loader="streetmixStreetURL: https://streetmix.net/scott/31/south-van-ness-idea-short-term; showBuildings: false;" > - - - - - - - - + + + + + + + + - diff --git a/src/json-utils.js b/src/json-utils.js index 05d471845..d81083aa0 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -108,7 +108,7 @@ function getAttributes (entity) { if (isEmpty(modifiedProperty)) { elemObj['components'][componentName] = ''; } else { - elemObj['components'][componentName] = toPropString(modifiedProperty); + elemObj['components'][componentName] = toPropString(componentName, modifiedProperty); } } } @@ -116,7 +116,14 @@ function getAttributes (entity) { return elemObj; } -function toPropString (propData) { +// properties or attributes that should be stored as a string in saved JSON +const propsToString = ["mapbox"]; + +function toPropString (componentName, propData) { + if (propsToString.includes(componentName)) { + // return a string if key is an attribute or property listed in the propsToString array + return AFRAME.utils.styleParser.stringify(propData); + } if ( typeof propData === 'string' || typeof propData === 'number' || @@ -143,7 +150,7 @@ function toPropString (propData) { return `${key}: ${value}`; } } else { - return `${key}: ${toPropString(value)}`; + return `${key}: ${toPropString(key, value)}`; } }) .join('; '); @@ -184,6 +191,10 @@ function filterJSONstreet (removeProps, renameProps, streetJSON) { } let stringJSON = JSON.stringify(streetJSON, function replacer (key, value) { + if (propsToString.includes(key)) { + // don't parse if key is an attribute or property listed in the propsToString array + return value; + } const compAttributes = AFRAME.utils.styleParser.parse(value); for (var removeKey in removeProps) { // check for removing components From 6473fd54247b32b57d99afb58c771481a232bf3d Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Tue, 16 Jan 2024 19:22:46 -0300 Subject: [PATCH 02/23] save streetmix URLs as strings also add additional comment --- src/json-utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/json-utils.js b/src/json-utils.js index d81083aa0..5e0c42383 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -117,7 +117,8 @@ function getAttributes (entity) { } // properties or attributes that should be stored as a string in saved JSON -const propsToString = ["mapbox"]; +// to prevent parsing and splitting URL +const propsToString = ["mapbox", "streetmixStreetURL", "streetmixAPIURL"]; function toPropString (componentName, propData) { if (propsToString.includes(componentName)) { From 2eea31e48d6b716145a56c115e36819f61505674 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Tue, 16 Jan 2024 19:23:56 -0300 Subject: [PATCH 03/23] remove unnecessary checkings --- src/json-utils.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/json-utils.js b/src/json-utils.js index 5e0c42383..ce33a07a2 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -116,15 +116,7 @@ function getAttributes (entity) { return elemObj; } -// properties or attributes that should be stored as a string in saved JSON -// to prevent parsing and splitting URL -const propsToString = ["mapbox", "streetmixStreetURL", "streetmixAPIURL"]; - function toPropString (componentName, propData) { - if (propsToString.includes(componentName)) { - // return a string if key is an attribute or property listed in the propsToString array - return AFRAME.utils.styleParser.stringify(propData); - } if ( typeof propData === 'string' || typeof propData === 'number' || @@ -183,6 +175,10 @@ const renameProps = { intersection: 'not-intersection' }; +// properties or attributes that should be stored as a string in saved JSON +// to prevent parsing and splitting URL +const propsToString = ["mapbox", "streetmixStreetURL", "streetmixAPIURL"]; + function filterJSONstreet (removeProps, renameProps, streetJSON) { function removeValueCheck (removeVal, value) { if (AFRAME.utils.deepEqual(removeVal, value) || removeVal === '*') { From 881e6992d89bd5b33344d8a9b50cb64706d45de6 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Tue, 16 Jan 2024 20:23:50 -0300 Subject: [PATCH 04/23] fixed the filterJSON code --- src/json-utils.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/json-utils.js b/src/json-utils.js index ce33a07a2..17024ce7f 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -188,14 +188,11 @@ function filterJSONstreet (removeProps, renameProps, streetJSON) { } let stringJSON = JSON.stringify(streetJSON, function replacer (key, value) { - if (propsToString.includes(key)) { - // don't parse if key is an attribute or property listed in the propsToString array - return value; - } - const compAttributes = AFRAME.utils.styleParser.parse(value); + let compAttributes; for (var removeKey in removeProps) { // check for removing components if (key === removeKey) { + compAttributes = AFRAME.utils.styleParser.parse(value); const removeVal = removeProps[removeKey]; // check for deleting component's attribute if (typeof removeVal === 'object' && !isEmpty(removeVal)) { @@ -218,7 +215,7 @@ function filterJSONstreet (removeProps, renameProps, streetJSON) { } } - return compAttributes; + return compAttributes ?? value; }); // rename components for (var renameKey in renameProps) { From d4f5806f41048acbc6176c7747852dc84ae5c3fb Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Wed, 17 Jan 2024 19:07:11 -0300 Subject: [PATCH 05/23] remove unnecessary variables --- src/json-utils.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/json-utils.js b/src/json-utils.js index 17024ce7f..abb274c1f 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -108,7 +108,7 @@ function getAttributes (entity) { if (isEmpty(modifiedProperty)) { elemObj['components'][componentName] = ''; } else { - elemObj['components'][componentName] = toPropString(componentName, modifiedProperty); + elemObj['components'][componentName] = toPropString(modifiedProperty); } } } @@ -116,7 +116,7 @@ function getAttributes (entity) { return elemObj; } -function toPropString (componentName, propData) { +function toPropString (propData) { if ( typeof propData === 'string' || typeof propData === 'number' || @@ -143,7 +143,7 @@ function toPropString (componentName, propData) { return `${key}: ${value}`; } } else { - return `${key}: ${toPropString(key, value)}`; + return `${key}: ${toPropString(value)}`; } }) .join('; '); @@ -175,10 +175,6 @@ const renameProps = { intersection: 'not-intersection' }; -// properties or attributes that should be stored as a string in saved JSON -// to prevent parsing and splitting URL -const propsToString = ["mapbox", "streetmixStreetURL", "streetmixAPIURL"]; - function filterJSONstreet (removeProps, renameProps, streetJSON) { function removeValueCheck (removeVal, value) { if (AFRAME.utils.deepEqual(removeVal, value) || removeVal === '*') { From 6304ffe5147f2f56a59b542b96d889e9ec58062e Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Sun, 28 Jan 2024 22:10:59 -0300 Subject: [PATCH 06/23] save src instead of id for external assets --- src/json-utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/json-utils.js b/src/json-utils.js index 05d471845..e3e09c8fb 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -137,8 +137,12 @@ function toPropString (propData) { return Object.entries(propData) .map(([key, value]) => { if (key == 'src') { - if (value.id) { + if (value.id && value.src.includes('assets.3dstreet.app')) { + // asset came from 3dstreet return `${key}: #${value.id}`; + } else if (value.src && !value.src.includes('assets.3dstreet.app')) { + // asset came from external sources + return `${key}: ${value.src}`; } else { return `${key}: ${value}`; } From d46c4231173021da89415f35ef83d39c90d346be Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Mon, 29 Jan 2024 14:09:02 -0300 Subject: [PATCH 07/23] always save assets url in the street-assets --- src/assets.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/assets.js b/src/assets.js index f59bbeb68..8f9b45580 100644 --- a/src/assets.js +++ b/src/assets.js @@ -1,7 +1,7 @@ /* global AFRAME, customElements */ function buildAssetHTML (assetUrl, categories) { - if (!assetUrl) assetUrl = 'https://assets.3dstreet.app/'; + //if (!assetUrl) assetUrl = 'https://assets.3dstreet.app/'; console.log('[street]', 'Using street assets from', assetUrl); const surfacesRoughness = 0.8; var assetsObj = { @@ -295,7 +295,12 @@ class StreetAssets extends AFRAME.ANode { const self = this; var categories = this.getAttribute('categories'); var assetUrl = this.getAttribute('url'); + if (!assetUrl) { + assetUrl = 'https://assets.3dstreet.app/'; + this.setAttribute('url', assetUrl); + } const assetsHTML = buildAssetHTML(assetUrl, categories); + this.insertAdjacentHTML('afterend', assetsHTML); AFRAME.ANode.prototype.load.call(self); From 2e579fcae797d516d7c9b64492c0e25d68118d5c Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Mon, 29 Jan 2024 15:00:19 -0300 Subject: [PATCH 08/23] get assetsUrl during saving JSON --- src/json-utils.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/json-utils.js b/src/json-utils.js index e3e09c8fb..d49e4de5f 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -2,6 +2,7 @@ /* version: 1.0 */ var STREET = {}; +var assetsUrl; STREET.utils = {}; function getSceneUuidFromURLHash () { @@ -43,6 +44,9 @@ function convertDOMElToObject (entity) { const referenceEntities = document.querySelector('#reference-layers'); const sceneEntities = [entity, environmentElement, referenceEntities]; + // get assets url address + assetsUrl = document.querySelector('street-assets').getAttribute('url'); + for (const entry of sceneEntities) { const entityData = getElementData(entry); if (entityData) { @@ -137,10 +141,10 @@ function toPropString (propData) { return Object.entries(propData) .map(([key, value]) => { if (key == 'src') { - if (value.id && value.src.includes('assets.3dstreet.app')) { + if (value.id && value.src.includes(assetsUrl)) { // asset came from 3dstreet return `${key}: #${value.id}`; - } else if (value.src && !value.src.includes('assets.3dstreet.app')) { + } else if (value.src && !value.src.includes(assetsUrl)) { // asset came from external sources return `${key}: ${value.src}`; } else { From 6539209a81ecc5a3615f460f9cb608d842af9b3d Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Wed, 31 Jan 2024 22:25:54 -0300 Subject: [PATCH 09/23] call json-utils.js from index.js move functions used elsewhere from json-utils to a global STREET object --- index.html | 5 +---- src/index.js | 1 + src/json-utils.js | 12 +++++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index da6d15622..469d843a2 100644 --- a/index.html +++ b/index.html @@ -10,9 +10,6 @@ - - - @@ -123,7 +120,7 @@