Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change street component parameters #512

Merged
merged 14 commits into from
Jul 3, 2024
Merged

Conversation

Algorush
Copy link
Collaborator

@Algorush Algorush commented May 3, 2024

Added the ability to change the parameters of the street component (showGround, showVehicles, showStriping) without reloading the scene. It remains to add globalAnimated. So this PR not ready yet.
Also, now there is no need to rename street to not-street, like streetmix-loader and intersection. I added a check that the scene is loaded from jsonFile and do not run the update function in these components

Copy link

netlify bot commented May 3, 2024

Deploy Preview for 3dstreet-core-builds ready!

Name Link
🔨 Latest commit 4fc7a90
🔍 Latest deploy log https://app.netlify.com/sites/3dstreet-core-builds/deploys/66354ccc5d63e30008c5295b
😎 Deploy Preview https://deploy-preview-512--3dstreet-core-builds.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

# Conflicts:
#	src/lib/aframe-loader-3dtiles-component.js
#	src/lib/aframe-loader-3dtiles-component.min.js
src/index.js Outdated
this.toggleEntitiesVisibillity(vehicleEntities, showVehicles);
},
toggleGround: function (showGround) {
const groundEntities = Array.from(document.querySelectorAll('.ground-left, .ground-right'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.from is not needed.

@Algorush
Copy link
Collaborator Author

Updated this PR to the latest version of the 3dstreet repository. This issue has now been fixed: #673

Copy link
Collaborator

@kfarr kfarr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a new property to street component such as synchronized true/false

if synchronized is true (it should be true by default at the start) then it will create children entities; after creating children entities for the first time synchronized should be set to false; then use that instead of the global STREET.sourceType

@@ -78,6 +78,8 @@ AFRAME.registerComponent('streetplan-loader', {
return;
}

STREET.sourceType = 'streetplanURL'; // it also could be jsonFile/streetmixURL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Algorush there will be more than 1 street per scene so I don't understand why this needs to be set ?

Copy link
Collaborator Author

@Algorush Algorush Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought about more than 1 street per scene and was tested with this case also. STREET.sourceType refers to the currently loaded street. And global STREET is not good place for it, yeah...
And yes, maybe its not good idea, but I didn’t find a better option when was thinking about it.

src/index.js Outdated
// fired once at start and at each subsequent change of a schema value
var data = this.data;
// do not call the update function when the component is initially loaded and sourceType is jsonFile
if (STREET.sourceType === 'jsonFile' && this._initLoad) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Algorush we should not be using a global for sourceType that describes this specific entity; multiple streets may be loading from different types of sources on the same scene;

src/index.js Outdated
const el = this.el;

// do not call update function while loading scene from JSON file
if (STREET.sourceType === 'jsonFile') return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same feedback, not a global

@Algorush
Copy link
Collaborator Author

please add a new property to street component such as synchronized true/false

if synchronized is true (it should be true by default at the start) then it will create children entities; after creating children entities for the first time synchronized should be set to false; then use that instead of the global STREET.sourceType

Ok, it works good, when I added synchronized flag for streetmix-loader and stretplan-loader too. But I dont understand the logic why synchronized should be true by default?

@Algorush
Copy link
Collaborator Author

Algorush commented Jul 1, 2024

question: should visibility options showGround, showStripping, showVehicles be saved in JSON or should they only be valid during the session?
I have now made that these parameters are updated without reloading the scene. The reason for this was that if the user changed one of these parameters, the entire street would be reloaded and all his changes would be lost.

Copy link
Collaborator

@vincentfretin vincentfretin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

synchronized means the entities are recreated each time from streetmix json.
If we don't want the behavior, we set synchronized to false after loading the json the first time.

src/index.js Outdated
@@ -185,6 +228,8 @@ AFRAME.registerComponent('streetmix-loader', {
JSON.stringify({ streetmixSegmentsMetric: streetmixSegments })
);
el.emit('streetmix-loader-street-loaded');
// the streetmix data has been loaded, set the synchronized flag
data.synchronized = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't set it like that, otherwise the change won't be properly exported. Use
this.el.setAttribute('street', 'synchronized', true}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code may work on aframe 1.5.0 but I think it won't work on aframe 1.6.0 or master because of internals restructuring, calling getAttribute('street') won't return the modified data object.

Copy link
Collaborator Author

@Algorush Algorush Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying. Yes, I have read the documentation why it is better to use setAttribute. But in general it would be better to use an internal variable of the component in these cases, which is saved in JSON, but will not be displayed in the editor. There is no such mechanism in the component implementation, but it could be done using __innerAttrName and internal get/set functions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Algorush it's ok for this variable to be exposed to the end-user

src/index.js Outdated
@@ -171,7 +214,7 @@ AFRAME.registerComponent('streetmix-loader', {
);
}

el.setAttribute('data-layer-name', 'Streetmix ' + streetmixName);
el.setAttribute('data-layer-name', 'Streetmix ' + streetmixName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unicode issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, something strange with my code editor. Will fix in next commit too

src/index.js Outdated
@@ -86,6 +123,8 @@ AFRAME.registerComponent('street', {
);
this.el.append(buildingsEl);
}
// the scene has been loaded, set the synchronized flag
this.data.synchronized = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use setAttribute

@kfarr
Copy link
Collaborator

kfarr commented Jul 1, 2024

@Algorush sorry for the miscommunication, this is close but the logic is inverted.

Instead of "this.data.synchronized = true;" we would like to have synchronize be the variable and the default is true. If the value of synchronize is true, then please yes do the actual element creation; if it is false, then do not. Effectively this is the opposite logic of what you have implemented.

For the avoidance of doubt, after the objects are created initially, then set synchronize to false.

@kfarr
Copy link
Collaborator

kfarr commented Jul 3, 2024

test

  • import a streetmix scene
  • save / reload that 3dstreet scene
  • ensure that the scene is only loaded once per "synchronize" flag
  • see if we see props panel
  • if we are able to use the component properites -- great! that's a bonus

@kfarr kfarr merged commit 3517f96 into main Jul 3, 2024
1 check passed
@kfarr kfarr deleted the change-street-component-parameters branch July 3, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants