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
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
src/editor/lib/TransformControls.js
src/lib/
public
dist
.storybook/
6 changes: 4 additions & 2 deletions src/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,16 @@ function buildAssetHTML(assetUrl, categories) {
<a-asset-item id="fence-model" src="${assetUrl}sets/fences/gltf-exports/draco/fence4.glb"></a-asset-item>
<a-mixin shadow id="fence" gltf-model="#fence-model" scale="0.1 0.1 0.1"></a-mixin>
`,
'loud-bicycle': `
<!-- loud-bicycle-game -->
cyclists: `
<a-mixin shadow id="cyclist-cargo" gltf-model="url(${assetUrl}sets/cargo-bike-animation/gltf-exports/draco/cargo_bike_animation_v1.glb)"></a-mixin>
<a-mixin shadow id="cyclist1" gltf-model="url(${assetUrl}sets/cyclist-animation/gltf-exports/draco/cyclist-1-animation-v1.glb)"></a-mixin>
<a-mixin shadow id="cyclist2" gltf-model="url(${assetUrl}sets/cyclist-animation/gltf-exports/draco/cyclist-2-animation-v1.glb)"></a-mixin>
<a-mixin shadow id="cyclist3" gltf-model="url(${assetUrl}sets/cyclist-animation/gltf-exports/draco/cyclist-3-animation-v1.glb)"></a-mixin>
<a-mixin shadow id="cyclist-kid" gltf-model="url(${assetUrl}sets/cyclist-animation/gltf-exports/draco/Kid_cyclist_animation_v01.glb)"></a-mixin>
<a-mixin shadow id="cyclist-dutch" gltf-model="url(${assetUrl}sets/cyclist-animation/gltf-exports/draco/Dutch_cyclist_animation_v01.glb)"></a-mixin>
`,
'loud-bicycle': `
<!-- loud-bicycle-game -->
<a-mixin shadow id="loud-bicycle-mini" gltf-model="url(${assetUrl}sets/cycle-horn/gltf-exports/draco/loud-bicycle-mini-horn.glb)"></a-mixin>
<a-mixin shadow id="loud-bicycle-classic" gltf-model="url(${assetUrl}sets/cycle-horn/gltf-exports/draco/loud-bicycle-classic-horn.glb)"></a-mixin>
<a-mixin shadow id="building-school" gltf-model="url(${assetUrl}sets/school-building/gltf-exports/draco/school-building.glb)"></a-mixin>
Expand Down
2 changes: 2 additions & 0 deletions src/components/streetplan-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.


var request = new XMLHttpRequest();
console.log('[streetplan-loader]', 'GET ' + data.streetplanAPIURL);

Expand Down
61 changes: 54 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (typeof VERSION !== 'undefined') {
var streetmixParsers = require('./aframe-streetmix-parsers');
var streetmixUtils = require('./tested/streetmix-utils');
require('./json-utils_1.1.js');
require('./street-utils.js');
var streetUtils = require('./street-utils.js');
require('./components/gltf-part');
require('./components/ocean');
require('./components/svg-extruder.js');
Expand All @@ -34,9 +34,50 @@ AFRAME.registerComponent('street', {
globalAnimated: { default: false },
length: { default: 60 } // new default of 60 from 0.4.4
},
init: function () {
// flag to determine init component load
this._initLoad = true;
},
toggleEntitiesVisibillity: function (entitiesArray, visible) {
entitiesArray.forEach((entity) => entity.setAttribute('visible', visible));
},
toggleVehicles: function (showVehicles) {
const vehicleEntities = streetUtils.getVehicleEntities();
this.toggleEntitiesVisibillity(vehicleEntities, showVehicles);
},
toggleGround: function (showGround) {
const groundEntities = Array.from(
document.querySelectorAll('.ground-left, .ground-right')
);
this.toggleEntitiesVisibillity(groundEntities, showGround);
},
toggleStriping: function (showStriping) {
const stripingEntities = streetUtils.getStripingEntities();
this.toggleEntitiesVisibillity(stripingEntities, showStriping);
},
update: function (oldData) {
// 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;

this._initLoad = false;
return;
}

const data = this.data;

if (data.showGround !== oldData.showGround) {
this.toggleGround(data.showGround);
return;
}

if (data.showVehicles !== oldData.showVehicles) {
this.toggleVehicles(data.showVehicles);
return;
}

if (data.showStriping !== oldData.showStriping) {
this.toggleStriping(data.showStriping);
return;
}

if (data.JSON.length === 0) {
if (oldData.JSON !== undefined && oldData.JSON.length === 0) {
Expand Down Expand Up @@ -101,8 +142,11 @@ AFRAME.registerComponent('streetmix-loader', {
// fired at start and at each subsequent change of any schema value
// This method may fire a few times when viewing a streetmix street in 3dstreet:
// First to find the proper path, once to actually load the street, and then subsequent updates such as street name
var data = this.data;
var el = this.el;
const data = this.data;
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


// if the loader has run once already, and upon update neither URL has changed, do not take action
if (
Expand Down Expand Up @@ -134,7 +178,7 @@ AFRAME.registerComponent('streetmix-loader', {
return;
}

var request = new XMLHttpRequest();
const request = new XMLHttpRequest();
console.log('[streetmix-loader]', 'GET ' + data.streetmixAPIURL);

request.open('GET', data.streetmixAPIURL, true);
Expand Down Expand Up @@ -171,7 +215,7 @@ AFRAME.registerComponent('streetmix-loader', {
);
}

el.setAttribute('data-layer-name', 'Streetmix ' + streetmixName);
el.setAttribute('data-layer-name', 'Streetmix ? ' + streetmixName);

if (data.showBuildings) {
el.setAttribute('street', 'right', streetData.rightBuildingVariant);
Expand Down Expand Up @@ -220,6 +264,9 @@ AFRAME.registerComponent('intersection', {
var data = this.data;
var el = this.el;

// do not call init method while loading scene from JSON file
if (STREET.sourceType === 'jsonFile') return;

// remove all child nodes if exists
while (el.firstChild) {
el.removeChild(el.lastChild);
Expand Down
7 changes: 4 additions & 3 deletions src/json-utils_1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ const removeProps = {
};
// a list of component_name:new_component_name pairs to rename in JSON string
const renameProps = {
'streetmix-loader': 'not-streetmix-loader',
street: 'not-street',
intersection: 'not-intersection'
};

function filterJSONstreet(streetJSON) {
Expand Down Expand Up @@ -637,6 +634,8 @@ function inputStreetmix() {
// clearMetadata = true, clearUrlHash = false
STREET.utils.newScene(true, false);

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

setTimeout(function () {
window.location.hash = streetmixURL;
});
Expand Down Expand Up @@ -674,6 +673,8 @@ function createElementsFromJSON(streetJSON) {
// clearMetadata = true, clearUrlHash = true, addDefaultStreet = false
STREET.utils.newScene(true, true, false);

STREET.sourceType = 'jsonFile'; // it also could be streetmix/streetplan

const sceneTitle = streetObject.title;
if (sceneTitle) {
console.log('sceneTitle from createElementsFromJSON', sceneTitle);
Expand Down
21 changes: 21 additions & 0 deletions src/street-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,24 @@ function newScene(
}

STREET.utils.newScene = newScene;

function getVehicleEntities() {
return getEntitiesByCategories(['vehicles', 'vehicles-rigged', 'vehicles-transit', 'cyclists']);
}

module.exports.getVehicleEntities = getVehicleEntities;

function getStripingEntities() {
return getEntitiesByCategories(['lane-separator']);
}

module.exports.getStripingEntities = getStripingEntities;

function getEntitiesByCategories(categoriesArray) {
// get entity Nodes by array of their mixin categories
const queryForCategoriesMixins = categoriesArray.map(categoryName => `a-mixin[category="${categoryName}"]`).join(',');
const allCategoriesMixins = document.querySelectorAll(queryForCategoriesMixins);
const categoriesMixinIds = Array.from(allCategoriesMixins).map(el => el.id);
const queryForAllElements = categoriesMixinIds.map(mixinId => `a-entity[mixin~="${mixinId}"]`).join(',');
return document.querySelectorAll(queryForAllElements);
}
Loading